Package org.apache.olio.webapp.model

Examples of org.apache.olio.webapp.model.ModelFacade


        String friendUserName = request.getParameter(FRIEND_USER_NAME_PARAM);

        logger.finer("***** PERSON-REST-ACTION:addFriend: " + USER_NAME_PARAM + "=" + userName +
                " and " + FRIEND_USER_NAME_PARAM + "=" + friendUserName);

        ModelFacade mf = (ModelFacade) context.getAttribute(MF_KEY);
        Person person = mf.addFriend(userName, friendUserName);

        logger.log(Level.FINER, "Person " + userName + " has been updated to add friend=" + friendUserName);
        return person;
    }
View Full Code Here


    }

    public String process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String path = request.getPathInfo();
        logger.finer("\n*** pathinfo = " + path);
        ModelFacade modelFacade = (ModelFacade) context.getAttribute(MF_KEY);
        if (path.equals("/event")) {
            // This is not really rest
        } else if (path.equals("/event/updateRating")) {
            updateSocialEventRating(request, response, modelFacade);
        } else if (path.equals("/event/getComments")) {
View Full Code Here

        return securityHandler;
    }
   
   
    public Person login(ServletContext servletContext, HttpServletRequest request, HttpServletResponse response, String userName, String password) {
         ModelFacade mf=(ModelFacade)servletContext.getAttribute(WebConstants.MF_KEY);
         Person person=mf.getPerson(userName);
         // person will be null if there is an error
         person=login(person, userName, password);
         if(person != null) {
            setLoggedInPerson(request, person);
         }
View Full Code Here

        String lastName = request.getParameter(LAST_NAME_PARAM);
        String summary = request.getParameter(SUMMARY_PARAM);


        String actionType = request.getParameter(ACTION_TYPE_PARAM);
        ModelFacade mf = (ModelFacade) context.getAttribute(MF_KEY);
        String returnURL = null;
        String path = request.getPathInfo();
        if (path != null && path.equals("/login")) {
            String fUrl = "/site.jsp";
            String user_name = request.getParameter("user_name");
            UserBean userBean = (UserBean) request.getSession(true).getAttribute("userBean");
            if (userBean == null) {
                userBean = new UserBean();
                userBean.setModelFacade(mf);
                request.getSession().setAttribute("userBean", userBean);
            }
            if (user_name != null && password != null) {
                Person p = mf.login(user_name, password);
                if (p != null) {
                    userBean.setDisplayMessage("Successfully logged in");
                    userBean.setLoggedInPerson(p);
                }
            } else {
                userBean.setDisplayMessage("Log in failed for user_name = " + user_name +
                        " password = " + password);
            }
            fUrl = userBean.getForwardingUrl();
            if (fUrl == null) {
                fUrl = request.getContextPath() + "/event/list";
            } else {
                fUrl = request.getContextPath() + fUrl;
            // We will do a redirect rather than a forward so that refreshing the browser
            // does not cause issues
            }
            response.sendRedirect(fUrl);
            return null;
        }

        if (actionType != null) {
            if (actionType.equalsIgnoreCase("display_person")) {
                String username = request.getParameter("user_name");
                Person displayUser = mf.findPerson(username);
                if (displayUser != null) {
                    //get posted events
                    Collection<SocialEvent> userEvents = mf.getPostedEvents(displayUser);
                    request.setAttribute("userEvents", userEvents);
                    //logger.finer("the size of the incoming friendships is "+ displayUser.getIncomingInvitations().size());
                    request.setAttribute("displayPerson", displayUser);
                    returnURL = "/site.jsp?page=personContent.jsp";
                }
            } else if (actionType.equalsIgnoreCase("display_friends")) {
                String username = request.getParameter("user_name");
                Person displayUser = mf.findPerson(username);
                request.setAttribute("displayPerson", displayUser);
                //addition here for pages
                 int index = WebappUtil.getIntProperty(request.getParameter("index"));
                
            List<Person> list = (List)displayUser.getFriends();
               
            if (list != null) {
                List friendList = WebappUtil.getPagedList(list, index);               
                request.setAttribute("numPages", WebappUtil.getNumPages(list));
                request.setAttribute("pageUrl", request.getContextPath() + "/person?user_name="+username+"&page=friends.jsp&actionType=display_friends");
                request.setAttribute("itemList", friendList);
                request.setAttribute("index", index);
            }
         
                returnURL = "/site.jsp?page=friends.jsp";

            } else if (actionType.equalsIgnoreCase("add_person")) {
                //should not go here - we are doing this via PersonRestAction
                //this.addPerson(request, response);
                returnURL = "/site.jsp?page=addPerson.jsp";

            } else if (actionType.equalsIgnoreCase("edit_person")) {
                request.setAttribute("isEditable", Boolean.TRUE);
                returnURL = "/site.jsp?page=addPerson.jsp";
            } else if (actionType.equalsIgnoreCase("display_myPostedEvents")) {
                String username = request.getParameter("user_name");
                Person displayUser = mf.findPerson(username);
                if (displayUser != null) {
                    //get posted events
                    Collection<SocialEvent> myPostedEvents = mf.getPostedEvents(displayUser);
                    logger.finer("the size of myPostedEvents is " + myPostedEvents.size());
                    request.setAttribute("myPostedEvents", myPostedEvents);
                }
                returnURL = "/site.jsp?page=eventsPostedByUser.jsp";
            } else if (actionType.equalsIgnoreCase("Search")) {
                String query = request.getParameter("query");
                //need to specify max results
                Collection<Person> searchResults = mf.searchUsers(query, 0);
                //have all of the users - now get the friends
                Person requestor = mf.findPerson(userName);
                UserBean userBean = (UserBean) request.getSession().getAttribute("userBean");
                Person loggedInPerson = userBean.getLoggedInPerson();
                String loggedInPersonUsername = loggedInPerson.getUserName();
                Collection<Person> friends = loggedInPerson.getFriends();
                logger.finer("the size of the loggedInPerson's friends  " + loggedInPerson.getUserName() + " is " + friends.size());
                //invitations
                Collection<Invitation> invites = loggedInPerson.getIncomingInvitations();
                logger.finer("the size of the invitations list is " + invites.size());

                //iterate through and remove the friends from the list
                //need to remove loggedInPerson too since you cannot have yourself as a friend
                Iterator<Person> it = searchResults.iterator();
                while (it.hasNext()) {
                    Person person = it.next();

                    Iterator<Person> friendIterator = friends.iterator();
                    Iterator<Invitation> invitationIter = invites.iterator();

                    while (friendIterator.hasNext()) {
                        String fUsername = friendIterator.next().getUserName();
                        if (fUsername.equalsIgnoreCase(person.getUserName()) || fUsername.equalsIgnoreCase(loggedInPerson.getUserName())) {
                            it.remove();
                        }
                    }
                    //determine whether they are received their invitation already
                    while (invitationIter.hasNext()) {
                        Invitation inv = invitationIter.next();
                        if (inv.getCandidate().getUserName().equalsIgnoreCase(person.getUserName())) {
                            person.setHasReceivedInvitation(true);
                        }
                    }
                }
                //logger.finer("after sorting, the size of the collection is " + searchResults.size());

                //not in session request.getSession().setAttribute("searchResults", searchResults);
                loggedInPerson.setNonFriendList(searchResults);


                if (searchResults != null) {
                    request.setAttribute("searchResults", searchResults);
                }
                returnURL = "/site.jsp?page=searchUsers.jsp";
            } else if (actionType.equalsIgnoreCase("addDeleteFriend")) {
                String query = request.getParameter("query");
                String friendUsername = request.getParameter("friend");
                //this is returning null - SecurityHandler.getInstance().getLoggedInPerson(request);
                UserBean userBean = (UserBean) request.getSession().getAttribute("userBean");
                Person loggedInPerson = userBean.getLoggedInPerson();
                Collection<Person> previousSearchResults = loggedInPerson.getNonFriendList();
                ///add or delete
                String flag = request.getParameter("flag");
                logger.finer("*** flag is " + flag);
                if (flag.equals("add")) {
                    Person friend = mf.findPerson(friendUsername);
                    Invitation invitation = new Invitation(loggedInPerson, friend);
                    mf.addInvitation(loggedInPerson, invitation);
                    //iterate through and set new added friend's hasReceivedInvitation to true
                    Iterator<Person> searchIter = previousSearchResults.iterator();
                    while (searchIter.hasNext()) {
                        Person eachPerson = searchIter.next();
                        if (eachPerson.getUserName().equalsIgnoreCase(friendUsername)) {
                            eachPerson.setHasReceivedInvitation(true);
                            logger.finer("user " + eachPerson.getUserName() + " status is " + eachPerson.isHasReceivedInvitation());
                        }
                    }

                } else if (flag.equals("delete")) {
                    Invitation inv = mf.findInvitation(loggedInPerson.getUserName(), friendUsername);
                    mf.deleteInvitation(loggedInPerson, inv);
                    //iterate through and set new added friend's hasReceivedInvitation to false

                    Iterator<Person> searchIter = previousSearchResults.iterator();
                    while (searchIter.hasNext()) {
                        Person eachPerson = searchIter.next();
View Full Code Here

                " first_name=*" + firstName +
                " last_name" + lastName +
                " summary" + summary);

        Person person = new Person(userName, password, firstName, lastName, summary, email, telephone, imageURL, thumbImage, timezone, address);
        ModelFacade mf = (ModelFacade) context.getAttribute(MF_KEY);
        //do not really need username since you set this value, not sure why it is returned
        //String userName = mf.addPerson(person, userSignOn);
        //changed above line to this since username already a variable name
        //userName = mf.addPerson(person, userSignOn);

        userName = mf.addPerson(person);
        logger.finer("Person " + userName + " has been persisted");
        // retrieve again ???
        //person=mf.getPerson(userName);
        // login person
        SecurityHandler.getInstance().setLoggedInPerson(request, person);
View Full Code Here

        this.context = con;
    }

    public String process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String path = request.getPathInfo();
        ModelFacade mf= (ModelFacade) context.getAttribute(MF_KEY);
        if (path.equals("/display")) {
            String tag = request.getParameter("tag");
            if (tag == null)
                return null;
            int index = WebappUtil.getIntProperty(request.getParameter("index"));
            List<SocialEvent> list = mf.getSocialEventsByTag(tag);
            if (list != null) {
                List<SocialEvent> slist = WebappUtil.getPagedList(list, index);
                request.setAttribute("numPages", WebappUtil.getNumPages(list));
                request.setAttribute("pageUrl", request.getContextPath() + "/tag/display?tag="+tag);
                request.setAttribute("itemList", slist);
View Full Code Here

        if (actionType == null) { // treat it as a read
            // need to check for fileupload.  Will not have an action because it is in multi-part mime format
            String path = request.getPathInfo();
            logger.finer("\n*** pathinfo = " + path);

            ModelFacade modelFacade = (ModelFacade) context.getAttribute(MF_KEY);
            if (path.equals("/person/fileuploadPerson")) {
                // file upload
                FileUploadHandler fuh = new FileUploadHandler();
                Hashtable<String, String> htUpload = fuh.getInitialParams(request, response);

                // file is upload check for error and then write to database
                if (htUpload != null) {
                    /*
                    StringBuilder sb = new StringBuilder();
                    for (String key : htUpload.keySet()) {
                        sb.append(key);
                        sb.append(",");
                    }
                    */
                    //logger.finer("\n***elements  = " + sb.toString());

                    //createUser(request, htUpload);
                    // just for now comment out the above line
                    // need to check if fileupload is complete
                    Person newEditPerson = null;
                    boolean isEditable = Boolean.parseBoolean(request.getParameter("isEditable"));

                    if (isEditable) {
                        newEditPerson = getPerson(request);
                    } else {
                        newEditPerson = createUser(request, htUpload, fuh);
                    }

                    logger.log(Level.FINER, "A new Person has been added and persisted");
                    request.setAttribute("displayPerson", newEditPerson);

                    String id = String.valueOf(newEditPerson.getUserID());
                    htUpload = fuh.handleFileUpload(id, request, response);

                    updateUser(newEditPerson, htUpload);
                }
                return "/site.jsp?page=personContent.jsp";


            } else if (path.equals("/person/fileuploadPersonFinal")) {
                // file upload status request
                FileUploadHandler.handleFileUploadFinal(request, response);
                return null;
            } else if (path.equals("/person/fileuploadStatusPerson")) {
                // file upload status request
                FileUploadHandler.handleFileStatus(request, response);
                return null;
            } else {
                if (method.equals("GET")) // default to a read action
                {
                    actionType = AT_READ_PARAMVALUE;
                }
            }
        } else {
            ModelFacade modelFacade = (ModelFacade) context.getAttribute(MF_KEY);
            UserBean userBean = (UserBean) request.getSession().getAttribute("userBean");
            Person loggedInPerson = userBean.getLoggedInPerson();
            if (loggedInPerson == null) {
                userBean.setDisplayMessage("Log in to manage invitations");
                return null;
            }
            String requestorUsername = request.getParameter(USER_NAME_PARAM);
            String friendUsername = request.getParameter(FRIEND_PARAM);

            if (actionType.equals(GET_FRIENDS)) {
                Person p = getPerson(request);
                if (p != null) {
                    out.write(p.getFriendsAsJson());
                }
                out.close();
                return null;
            } else if (actionType.equals(GET_POSTED_EVENTS)) {
                Person p = getPerson(request);
                if (p != null) {
                    out.write(modelFacade.getPostedEventsAsJson(p));
                }
                out.close();
                return null;
            } else if (actionType.equals(GET_ATTEND_EVENTS)) {
                Person p = getPerson(request);
                if (p != null) {
                    out.write(p.getAttendEventsAsJson());
                }
                out.close();
                return null;
            } else if (actionType.equals(REVOKE_INVITE)) {
                //Person p = getPerson(request);
                //Person friend = getFriend(request);
                //String requestorUsername = request.getParameter(USER_NAME_PARAM);
                //String friendUsername = request.getParameter(FRIEND_PARAM);
                Invitation inv = modelFacade.findInvitation(loggedInPerson.getUserName(), friendUsername);
                if (inv != null) {
                    modelFacade.deleteInvitation(loggedInPerson, inv);
                }
                //update outgoing invitation list
                //out.write(loggedInPerson.getOutgoingInvitationsAsJson());
                response.setContentType("application/json;charset=UTF-8");
                response.setHeader("Cache-Control", "no-cache");
                response.getWriter().write(this.OutgoingInvitationsAsJson(loggedInPerson, "revokeInvite"));
                response.flushBuffer();
                out.close();


            } else if (actionType.equals(APPROVE_FRIEND)) {
                Invitation acceptedInv = modelFacade.findInvitation(friendUsername, loggedInPerson.getUserName());
                modelFacade.addFriend(loggedInPerson.getUserName(), friendUsername);
                modelFacade.deleteInvitation(loggedInPerson, acceptedInv);

            } else if (actionType.equals(REJECT_INVITE)) {
                //this is an incoming friendship request so the friend is the requestor
                //Invitation revokedInv = modelFacade.findInvitation(friendUsername, loggedInPerson.getUserName());               
                //let do this in memory

                // Invitation foundInv = null;
                Collection<Invitation> invs = loggedInPerson.getIncomingInvitations();
                Iterator<Invitation> invsIter = invs.iterator();
                Invitation revokedInv = null;
                while (invsIter.hasNext()) {
                    revokedInv = invsIter.next();
                    //incoming
                    if ((revokedInv.getRequestor().getUserName().equalsIgnoreCase(friendUsername)) && (revokedInv.getCandidate().getUserName().equalsIgnoreCase(requestorUsername))) {
                        break;
                    }
                }
                modelFacade.deleteInvitation(loggedInPerson, revokedInv);

            }
        }

        response.setContentType("application/json;charset=UTF-8");
View Full Code Here

TOP

Related Classes of org.apache.olio.webapp.model.ModelFacade

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.