Example usage for org.apache.commons.lang ObjectUtils toString

List of usage examples for org.apache.commons.lang ObjectUtils toString

Introduction

In this page you can find the example usage for org.apache.commons.lang ObjectUtils toString.

Prototype

public static String toString(Object obj) 

Source Link

Document

Gets the toString of an Object returning an empty string ("") if null input.

 ObjectUtils.toString(null)         = "" ObjectUtils.toString("")           = "" ObjectUtils.toString("bat")        = "bat" ObjectUtils.toString(Boolean.TRUE) = "true" 

Usage

From source file:org.medici.bia.common.util.ListBeanUtils.java

/**
 * Method to obtains a list of a specific field contained in input list
 * inputObject. This method is able to manage simple property and nested
 * property (first level only ndr).  //  ww w.j a  va 2  s . c om
 * 
 * @param inputList
 *            List object containing beans having the field to extract.
 * @param fieldName Field name to extract
 * @return List<Object> Result list containing the specific input field of input list.
 **/
@SuppressWarnings({ "rawtypes", "unchecked" })
public static List<?> transformList(List inputList, String fieldName) {
    if (inputList == null || inputList.size() == 0) {
        return new ArrayList<Object>(0);
    }

    List retValue = new ArrayList(inputList.size());

    if (!StringUtils.contains(fieldName, ".")) {
        PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(inputList.get(0).getClass(), fieldName);
        Method method = pd.getReadMethod();

        for (int i = 0; i < inputList.size(); i++) {
            try {
                retValue.add(i, method.invoke(inputList.get(i), (Object[]) null));
                if ((ObjectUtils.toString(retValue.get(i)).equals("0"))
                        || ((ObjectUtils.toString(retValue.get(i)).equals("")))) {
                    retValue.set(i, "");
                }
            } catch (IllegalAccessException iaex) {
                retValue.set(i, null);
            } catch (InvocationTargetException itex) {
                retValue.set(i, null);
            }
        }
    }

    return retValue;
}

From source file:org.medici.bia.common.util.PersonUtils.java

/**
 * /*from   ww w  . ja  v  a  2  s  . com*/
 * @param people
 * @return
 */
public static String generateMapNameLf(People people) {
    if (people == null) {
        return "";
    }

    StringBuilder stringBuilder = new StringBuilder(0);
    if (!ObjectUtils.toString(people.getLast()).equals("")) {
        stringBuilder.append(people.getLast());
        if (!ObjectUtils.toString(people.getFirst()).equals("")
                || !ObjectUtils.toString(people.getSucNum()).equals("")
                || !ObjectUtils.toString(people.getMidPrefix()).equals("")
                || !ObjectUtils.toString(people.getMiddle()).equals("")
                || !ObjectUtils.toString(people.getLastPrefix()).equals("")) {
            stringBuilder.append(',');
        }
    }
    if (!ObjectUtils.toString(people.getFirst()).equals("")) {
        stringBuilder.append(' ');
        stringBuilder.append(people.getFirst());
    }
    if (!ObjectUtils.toString(people.getSucNum()).equals("")) {
        stringBuilder.append(' ');
        stringBuilder.append(people.getSucNum());
    }
    if (!ObjectUtils.toString(people.getMidPrefix()).equals("")) {
        stringBuilder.append(' ');
        stringBuilder.append(people.getMidPrefix());
    }
    if (!ObjectUtils.toString(people.getMiddle()).equals("")) {
        stringBuilder.append(' ');
        stringBuilder.append(people.getMiddle());
    }
    if (!ObjectUtils.toString(people.getLastPrefix()).equals("")) {
        stringBuilder.append(' ');
        stringBuilder.append(people.getLastPrefix());
    }
    if (!ObjectUtils.toString(people.getPostLast()).equals("")) {
        stringBuilder.append(" (");
        if (!ObjectUtils.toString(people.getPostLastPrefix()).equals("")) {
            stringBuilder.append(people.getPostLastPrefix() + " ");
        }
        stringBuilder.append(people.getPostLast());
        stringBuilder.append(')');
    }

    return stringBuilder.toString();
}

From source file:org.medici.bia.common.util.VolumeUtils.java

/**
 * This method return a string in format volNum + volLetExt.
 * /*from w w  w.  j a va2 s  .co m*/
 * @param volNum Volume Number
 * @param volLetExt Volume Letter Extension
 * @return
 */
public static String toMDPFormat(Integer volNum, String volLetExt) {
    String returnValue = ObjectUtils.toString(volNum);

    if (!StringUtils.isEmpty(volLetExt)) {
        returnValue += volLetExt;
    }

    return returnValue;
}

From source file:org.medici.bia.controller.community.ShowForumController.java

/**
 * /*w w  w .  ja  v  a 2 s . c o m*/
 * @param request
 * @param model
 * @return
 */
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.GET)
public ModelAndView setupForm(@ModelAttribute("command") ShowForumCommand command, HttpSession httpSession) {
    Map<String, Object> model = new HashMap<String, Object>(0);
    Forum forum = new Forum();

    try {
        User userInformation = (User) httpSession.getAttribute("user");

        // RR (March 12th, 2014): we filter forum access in this controller so ShowForum.jsp is maintained pretty compact.
        // --> First we calculate the user authorities (none for anonymous user) and then we filter what to show or we
        // redirect to 'accessDenied' page.
        Set<Authority> userAuthorities = null;

        if (userInformation != null) {
            model.put("account", userInformation.getAccount());
            userAuthorities = getUserAuthorities(userInformation);
            if (userInformation.getForumJoinedDate() == null) {
                userInformation = getCommunityService().joinUserOnForum();
                httpSession.setAttribute("user", userInformation);
            }
        }

        if (command.getForumId() == null) {
            forum = getCommunityService().getFirstCategory();
        } else {
            forum = getCommunityService().findForum(command.getForumId());
            if (Boolean.TRUE.equals(forum.getLogicalDelete()) || (SubType.COURSE.equals(forum.getSubType())
                    && !Type.CATEGORY.equals(forum.getForumParent().getType())
                    && !getTeachingService().isForumInActiveCourse(command.getForumId()))) {
                // the forum to show was deleted or it is correspondent to a deactivated course
                return new ModelAndView("404", model);
            }
            // we can update forum access informations
            forum = getCommunityService().getForumForView(command.getForumId());
        }

        if (forum.getType().equals(Type.CATEGORY)) {
            model.put("category", forum);

            if (forum.getOption().getCanHaveSubCategory()) {
                List<Forum> subCategories = getCommunityService()
                        .getSubCategories(new Forum(forum.getForumId()));
                // We filter forums with special access credentials
                List<Forum> visibleSubcategories = filterForumsForCurrentUser(subCategories, userAuthorities);
                model.put("subCategories", visibleSubcategories);

                //SubForums are extracted only if category is enabled to subForum...
                List<Integer> subCategoriesIdsEnabledToSubForums = new ArrayList<Integer>(0);
                for (Forum category : visibleSubcategories) {
                    if (category.getOption().getCanHaveSubForum()) {
                        subCategoriesIdsEnabledToSubForums.add(category.getForumId());
                    }
                }

                Map<Integer, List<Forum>> forumsHashMap = getCommunityService()
                        .getForumsGroupByCategory(subCategoriesIdsEnabledToSubForums);
                //MD: To show the number of subforums that have one or more topics for the document forum
                model.put("documentSubForumsWithTopics", getCommunityService().getSubForumsNumberWithTopics(5));

                model.put("forumsBySubCategories", forumsHashMap);

                if (forum.getOption().getCanHaveSubForum()) {
                    PaginationFilter paginationFilterForum = getPaginationFilter(command,
                            forum.getOption().getPageLength() != null ? forum.getOption().getPageLength()
                                    : DEFAULT_ROWS_PER_PAGE,
                            "dispositionOrder", true, true);
                    Page page = getCommunityService().getSubForums(forum.getForumId(), paginationFilterForum);
                    model.put("subForumsPage", page);
                }
            }
        } else if (forum.getType().equals(Type.FORUM)) {

            if (canAccessToForum(forum, userAuthorities)) {

                model.put("forum", forum);
                //MD: Prepare the Manuscript Viewer
                if (forum.getDocument() != null && !SubType.COURSE.equals(forum.getSubType())) {
                    Document document = forum.getDocument();
                    if (getManuscriptViewerService().findDocumentImageThumbnail(document) != null) {
                        DocumentExplorer documentExplorer = new DocumentExplorer(document.getEntryId(),
                                document.getVolume().getVolNum(), document.getVolume().getVolLetExt());
                        documentExplorer.setImage(new Image());
                        documentExplorer.getImage().setInsertNum(document.getInsertNum());
                        documentExplorer.getImage().setInsertLet(document.getInsertLet());
                        documentExplorer.getImage().setImageProgTypeNum(document.getFolioNum());
                        documentExplorer.getImage().setMissedNumbering(document.getFolioMod());
                        documentExplorer.getImage()
                                .setImageRectoVerso(document.getFolioRectoVerso() == null ? null
                                        : Image.ImageRectoVerso
                                                .convertFromString(document.getFolioRectoVerso().toString()));
                        documentExplorer.getImage().setImageType(ImageType.C);
                        documentExplorer.setTotal(null);

                        try {
                            documentExplorer = getManuscriptViewerService()
                                    .getDocumentExplorer(documentExplorer);
                            model.put("documentExplorer", documentExplorer);
                        } catch (ApplicationThrowable applicationThrowable) {
                            model.put("applicationThrowable", applicationThrowable);
                            return new ModelAndView("error/ShowForum", model);
                        }
                    } else {
                        model.put("documentExplorer", null);
                    }
                } else if (forum.getVolume() != null) {
                    Volume volume = forum.getVolume();
                    if (volume.getDigitized()) {
                        VolumeExplorer volumeExplorer = new VolumeExplorer(volume.getSummaryId(),
                                volume.getVolNum(), volume.getVolLetExt());
                        if (getManuscriptViewerService().findVolumeImageSpine(volume.getVolNum(),
                                volume.getVolLetExt()) != null) {
                            volumeExplorer.setImage(getManuscriptViewerService()
                                    .findVolumeImageSpine(volume.getVolNum(), volume.getVolLetExt()));
                        } else {
                            volumeExplorer.setImage(new Image());
                            volumeExplorer.getImage().setImageOrder(1);
                            volumeExplorer.getImage().setImageType(ImageType.C);
                        }
                        volumeExplorer.setTotal(null);

                        try {
                            volumeExplorer = getManuscriptViewerService().getVolumeExplorer(volumeExplorer);
                            model.put("volumeExplorer", volumeExplorer);
                        } catch (ApplicationThrowable applicationThrowable) {
                            model.put("applicationThrowable", applicationThrowable);
                            return new ModelAndView("error/ShowForum", model);
                        }
                    } else {
                        model.put("volumeExplorer", null);
                    }
                }

                if (forum.getOption().getCanHaveSubForum()) {
                    // All forum have group by excepted document...
                    if (forum.getOption().getGroupBySubForum()) {
                        PaginationFilter paginationFilterForum = null;
                        Page page = null;
                        if (SubType.COURSE.equals(forum.getSubType())) {
                            paginationFilterForum = getPaginationFilter(command,
                                    forum.getOption().getPageLength() != null
                                            ? forum.getOption().getPageLength()
                                            : DEFAULT_ROWS_PER_PAGE,
                                    "courseForum.lastPost", false, true);
                            page = getTeachingService().getCoursesElements(forum.getForumId(),
                                    paginationFilterForum);
                        } else {
                            paginationFilterForum = getPaginationFilter(command,
                                    forum.getOption().getPageLength() != null
                                            ? forum.getOption().getPageLength()
                                            : DEFAULT_ROWS_PER_PAGE,
                                    "lastPost", false, true);
                            page = getCommunityService().getSubForums(forum.getForumId(),
                                    paginationFilterForum);
                        }
                        model.put("subForumsPage", page);
                    } else {
                        // paginationFilter to manage topics results..
                        PaginationFilter paginationFilterTopic = getPaginationFilter(command,
                                forum.getOption().getPageLength() != null ? forum.getOption().getPageLength()
                                        : DEFAULT_ROWS_PER_PAGE,
                                "lastPost", false, false);
                        Page topicPage = getCommunityService().getForumTopicsByParentForum(forum,
                                paginationFilterTopic);
                        model.put("subForumsTopicsPage", topicPage);
                    }
                }
            } else {
                // TODO
                return new ModelAndView("403", model);
            }

        }

        if (forum.getOption().getCanHaveTopics()) {
            // paginationFilter to manage topics results..
            PaginationFilter paginationFilterTopic = getPaginationFilter(command,
                    forum.getOption().getPageLength() != null ? forum.getOption().getPageLength()
                            : DEFAULT_ROWS_PER_PAGE,
                    "lastUpdate", false, false);
            Page topicPage = getCommunityService().getForumTopics(forum, paginationFilterTopic);
            model.put("topicsPage", topicPage);

            if (SubType.COURSE.equals(forum.getSubType())) {
                Map<Integer, CourseTopicMode> topicsMap = getTeachingService()
                        .getCourseTopicsMode((List<ForumTopic>) topicPage.getList());
                model.put("topicsMap", topicsMap);
                if (topicsMap.containsValue(CourseTopicMode.I) || topicsMap.containsValue(CourseTopicMode.R)
                        || topicsMap.containsValue(CourseTopicMode.C)) {
                    // the topicsMap contains a course transcription (the help resources does not contain transcriptions)
                    model.put("containsTranscriptionTopic", true);
                }
            }
        }

        Map<String, Object> statisticsHashMap = getCommunityService().getForumsStatistics();
        model.put("statisticsHashMap", statisticsHashMap);

        Map<String, Object> whoIsOnlineHashMap = getCommunityService().getForumWhoIsOnline();
        model.put("whoIsOnlineHashMap", whoIsOnlineHashMap);
    } catch (ApplicationThrowable applicationThrowable) {
        model.put("applicationThrowable", applicationThrowable);
        return new ModelAndView("error/ShowForum", model);
    }

    if (ObjectUtils.toString(command.getCompleteDOM()).equals(Boolean.TRUE.toString())) {
        return new ModelAndView("community/ShowForumCompleteDOM", model);
    } else {
        return new ModelAndView("community/ShowForum", model);
    }
}

From source file:org.medici.bia.controller.community.ShowMessagesByCategoryController.java

/**
 * //  ww  w .  jav a 2s.c  o  m
 * @param request
 * @param model
 * @return
 */
@RequestMapping(method = RequestMethod.GET)
public ModelAndView setupForm(@ModelAttribute("command") ShowMessagesByCategoryCommand command) {
    Map<String, Object> model = new HashMap<String, Object>(0);
    // This number is used to generate an unique id for new search 
    UUID uuid = UUID.randomUUID();
    command.setSearchUUID(uuid.toString());
    model.put("searchUUID", uuid.toString());

    // Add outputFields;
    List<String> outputFields = getOutputFields(command.getUserMessageCategory());
    model.put("outputFields", outputFields);

    if (ObjectUtils.toString(command.getCompleteDOM()).equals(Boolean.TRUE.toString())) {
        return new ModelAndView("community/ShowMessagesByCategoryCompleteDOM", model);
    } else {
        return new ModelAndView("community/ShowMessagesByCategory", model);
    }
}

From source file:org.medici.bia.controller.community.ShowMyForumPostController.java

/**
 * //w ww . j  a v a  2  s  . c om
 * @param request
 * @param model
 * @return
 */
@RequestMapping(method = RequestMethod.GET)
public ModelAndView setupForm(@ModelAttribute("command") ShowMyForumPostCommand command,
        HttpSession httpSession) {
    Map<String, Object> model = new HashMap<String, Object>(0);

    try {
        User user = (User) httpSession.getAttribute("user");

        if (user != null) {
            if (user.getForumJoinedDate() == null) {
                user = getCommunityService().joinUserOnForum();
                httpSession.setAttribute("user", user);
            }
        }

        // secondo paginationFilter to manage topics results..
        PaginationFilter paginationFilter = new PaginationFilter();
        if (command.getPostsForPage() != null) {
            paginationFilter.setElementsForPage(command.getPostsForPage());
        } else {
            paginationFilter.setElementsForPage(new Integer(10));
            command.setPostsForPage(paginationFilter.getElementsForPage());
        }
        if (command.getPostPageNumber() != null) {
            paginationFilter.setThisPage(command.getPostPageNumber());
        } else {
            paginationFilter.setThisPage(new Integer(1));
            command.setPostPageNumber(paginationFilter.getThisPage());
        }
        if (command.getPostPageTotal() != null) {
            paginationFilter.setPageTotal(command.getPostPageTotal());
        } else {
            paginationFilter.setPageTotal(null);
        }
        paginationFilter.addSortingCriteria("postId", "asc");

        AdvancedSearchForum advancedSearchForum = new AdvancedSearchForum();
        advancedSearchForum
                .setAuthor(((UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal())
                        .getUsername());
        advancedSearchForum.setDisplayResults("ForumPost");

        Page postsPage = getCommunityService().searchForumPosts(advancedSearchForum, paginationFilter);
        model.put("postsPage", postsPage);
        if (postsPage.getList().size() == 0) {
            model.put("isEmpty", true);
        }
    } catch (ApplicationThrowable applicationThrowable) {
        model.put("applicationThrowable", applicationThrowable);
        return new ModelAndView("error/ShowTopicForum", model);
    }

    if (ObjectUtils.toString(command.getCompleteDOM()).equals(Boolean.TRUE.toString())) {
        return new ModelAndView("community/ShowTopicForumCompleteDOM", model);
    } else {
        return new ModelAndView("community/ShowTopicForum", model);
    }
}

From source file:org.medici.bia.controller.community.ShowMyMessageBoxController.java

/**
 * /*from w  w  w. j  a  v  a 2 s. c  o m*/
 * @param request
 * @param model
 * @return
 */
@RequestMapping(method = RequestMethod.GET)
public ModelAndView setupForm(@ModelAttribute("command") ShowMyMessageBoxCommand command) {
    Map<String, Object> model = new HashMap<String, Object>(0);

    PaginationFilter paginationFilter = new PaginationFilter();
    if (command.getResultsForPage() != null) {
        paginationFilter.setElementsForPage(command.getResultsForPage());
    } else {
        paginationFilter.setElementsForPage(new Integer(10));
        command.setResultsForPage(new Integer(10));
    }
    if (command.getResultPageNumber() != null) {
        paginationFilter.setThisPage(command.getResultPageNumber());
    } else {
        paginationFilter.setThisPage(new Integer(1));
        command.setResultPageNumber(paginationFilter.getThisPage());
    }
    if (command.getResultPageTotal() != null) {
        paginationFilter.setPageTotal(command.getResultPageTotal());
    } else {
        paginationFilter.setPageTotal(null);
    }

    Page page = new Page(paginationFilter);

    UserMessageSearch userMessageSearch = new UserMessageSearch();
    //      userMessageSearch.setRecipient(((UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername());
    if (command.getCategory() != null) {
        if (command.getCategory().equalsIgnoreCase("inbox")) {
            userMessageSearch.setUserMessageCategory(UserMessageCategory.INBOX);
            paginationFilter.addSortingCriteria("messageSendedDate", "desc");
        } else if (command.getCategory().equalsIgnoreCase("outbox")) {
            userMessageSearch.setUserMessageCategory(UserMessageCategory.OUTBOX);
            paginationFilter.addSortingCriteria("messageSendedDate", "desc");
        }
    } else {
        userMessageSearch.setUserMessageCategory(UserMessageCategory.INBOX);
    }

    try {
        page = getCommunityService().searchMessages(userMessageSearch, paginationFilter);
    } catch (ApplicationThrowable applicationThrowable) {
        model.put("applicationThrowable", applicationThrowable);
        page = new Page(paginationFilter);
    }

    model.put("messageboxPage", page);
    model.put("category", userMessageSearch.getUserMessageCategory());

    if (ObjectUtils.toString(command.getCompleteDOM()).equals(Boolean.TRUE.toString())) {
        return new ModelAndView("community/ShowMyMessageBoxCompleteDOM", model);
    } else {
        return new ModelAndView("community/ShowMyMessageBox", model);
    }
}

From source file:org.medici.bia.controller.community.ShowTopicForumController.java

/**
 * //from  w ww .  ja va  2  s . c om
 * @param request
 * @param model
 * @return
 */
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.GET)
public ModelAndView setupForm(@ModelAttribute("command") ShowTopicForumCommand command, BindingResult result,
        HttpServletRequest httpServletRequest) {
    Map<String, Object> model = new HashMap<String, Object>(0);

    try {
        User user = (User) httpServletRequest.getSession().getAttribute("user");
        //httpSession.getAttribute("user");

        if (user != null) {
            if (user.getForumJoinedDate() == null) {
                user = getCommunityService().joinUserOnForum();
                httpServletRequest.getSession().setAttribute("user", user);
            }
        }

        // Control to anonymous access
        if (SecurityContextHolder.getContext().getAuthentication().getPrincipal().getClass().getName()
                .equals("java.lang.String")) {
            model.put("account", null);
        } else {
            model.put("account",
                    ((UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal())
                            .getUsername());
        }

        PaginationFilter paginationFilterTopic = new PaginationFilter();
        if (command.getPostsForPage() != null) {
            paginationFilterTopic.setElementsForPage(command.getPostsForPage());
        } else {
            paginationFilterTopic.setElementsForPage(new Integer(10));
            command.setPostsForPage(paginationFilterTopic.getElementsForPage());
        }
        if (command.getPostPageNumber() != null) {
            paginationFilterTopic.setThisPage(command.getPostPageNumber());
        } else {
            paginationFilterTopic.setThisPage(new Integer(1));
            command.setPostPageNumber(paginationFilterTopic.getThisPage());
        }
        if (command.getPostPageTotal() != null) {
            paginationFilterTopic.setPageTotal(command.getPostPageTotal());
        } else {
            paginationFilterTopic.setPageTotal(null);
        }
        paginationFilterTopic.addSortingCriteria("postId", "asc");

        ForumTopic forumTopic = getCommunityService().getForumTopicForView(command.getTopicId());
        model.put("topic", forumTopic);

        boolean isTeachingTopic = getTeachingService().isForumInCourse(forumTopic.getForum().getForumId());
        model.put("isTeachingTopic", isTeachingTopic);

        if ((isTeachingTopic && model.get("account") == null) || (isTeachingTopic
                && !(getTeachingService().canAccess(command.getTopicId(), (String) model.get("account"))))) {
            // anonymous user cannot view the course topic
            return new ModelAndView("403", model);
        }

        model.put("subscribed", getCommunityService().ifTopicSubscribed(forumTopic.getTopicId()));

        if (forumTopic.getDocument() != null || forumTopic.getForum().getDocument() != null) {
            //MD: Prepare the Manuscript Viewer
            Document document = forumTopic.getDocument() != null ? forumTopic.getDocument()
                    : forumTopic.getForum().getDocument();
            if (getManuscriptViewerService().findDocumentImageThumbnail(document) != null) {
                DocumentExplorer documentExplorer = new DocumentExplorer(document.getEntryId(),
                        document.getVolume().getVolNum(), document.getVolume().getVolLetExt());
                documentExplorer.setImage(new Image());
                documentExplorer.getImage().setInsertNum(document.getInsertNum());
                documentExplorer.getImage().setInsertLet(document.getInsertLet());
                documentExplorer.getImage().setImageProgTypeNum(document.getFolioNum());
                documentExplorer.getImage().setMissedNumbering(document.getFolioMod());
                documentExplorer.getImage().setImageRectoVerso(document.getFolioRectoVerso() == null ? null
                        : Image.ImageRectoVerso.convertFromString(document.getFolioRectoVerso().toString()));
                documentExplorer.getImage().setImageType(ImageType.C);
                documentExplorer.setTotal(null);

                try {
                    documentExplorer = getManuscriptViewerService().getDocumentExplorer(documentExplorer);
                    model.put("documentExplorer", documentExplorer);
                } catch (ApplicationThrowable applicationThrowable) {
                    model.put("applicationThrowable", applicationThrowable);
                    return new ModelAndView("error/ShowTopicForum", model);
                }
            } else {
                model.put("documentExplorer", null);
            }

        } else if (forumTopic.getAnnotation() != null) {
            Annotation annotation = forumTopic.getAnnotation();
            Image image = new Image();
            image = getManuscriptViewerService().findImage(annotation.getImage().getImageId());
            VolumeExplorer volumeExplorer = new VolumeExplorer(image.getVolNum(), image.getVolLetExt());
            volumeExplorer.setSummaryId(null);
            volumeExplorer.setImage(new Image());
            volumeExplorer.getImage().setImageOrder(image.getImageOrder());
            volumeExplorer.getImage().setStoragePath(image.getStoragePath());
            try {
                volumeExplorer = getManuscriptViewerService().getVolumeExplorer(volumeExplorer);
                model.put("volumeExplorer", volumeExplorer);
            } catch (ApplicationThrowable applicationThrowable) {
                model.put("applicationThrowable", applicationThrowable);
                return new ModelAndView("error/ShowTopic", model);
            }
        }

        if (isTeachingTopic) {
            CourseTopicOption option = getTeachingService()
                    .getCourseTranscriptionTopicOption(forumTopic.getForum().getForumId());
            if (option != null) {
                model.put("courseTranscriptionURL", CourseUtils.getCourseTranscriptionURL(option));
            }
            Course course = getTeachingService().getCourseFromCourseTopic(forumTopic.getTopicId());
            model.put("isCoursePerson",
                    getTeachingService().isPersonInCourse(course.getCourseId(), user.getAccount()));

        }

        Page postsPage = getCommunityService().getForumPostsFromTopic(forumTopic, paginationFilterTopic);
        model.put("postsPage", postsPage);

        Set<String> accounts = new HashSet<String>();

        for (ForumPost post : ((List<ForumPost>) postsPage.getList())) {
            accounts.add(post.getUser().getAccount());
        }
        Map<String, UserAuthority> maxAuthorities = accounts.size() > 0
                ? getCommunityService().findUsersMaximumAuthority(accounts)
                : new HashMap<String, UserAuthority>();
        model.put("maxAuthorities", maxAuthorities);

        model.put("onlineUsers", applicationAccessContainer.getCommunityOnlineUsers());
    } catch (ApplicationThrowable applicationThrowable) {
        model.put("applicationThrowable", applicationThrowable);
        return new ModelAndView("error/ShowTopicForum", model);
    }

    if (ObjectUtils.toString(command.getCompleteDOM()).equals(Boolean.TRUE.toString())) {
        return new ModelAndView("community/ShowTopicForumCompleteDOM", model);
    } else {
        return new ModelAndView("community/ShowTopicForum", model);
    }
}

From source file:org.medici.bia.controller.community.ShowUserForumPostController.java

/**
 * //from  w w  w  . j  a v a  2s.c o m
 * @param request
 * @param model
 * @return
 */
@RequestMapping(method = RequestMethod.GET)
public ModelAndView setupForm(@ModelAttribute("command") ShowUserForumPostCommand command,
        HttpSession httpSession) {
    Map<String, Object> model = new HashMap<String, Object>(0);

    try {
        User user = (User) httpSession.getAttribute("user");

        if (user != null) {
            if (user.getForumJoinedDate() == null) {
                user = getCommunityService().joinUserOnForum();
                httpSession.setAttribute("user", user);
            }
        }

        // secondo paginationFilter to manage topics results..
        PaginationFilter paginationFilter = new PaginationFilter();
        if (command.getPostsForPage() != null) {
            paginationFilter.setElementsForPage(command.getPostsForPage());
        } else {
            paginationFilter.setElementsForPage(new Integer(10));
            command.setPostsForPage(paginationFilter.getElementsForPage());
        }
        if (command.getPostPageNumber() != null) {
            paginationFilter.setThisPage(command.getPostPageNumber());
        } else {
            paginationFilter.setThisPage(new Integer(1));
            command.setPostPageNumber(paginationFilter.getThisPage());
        }
        if (command.getPostPageTotal() != null) {
            paginationFilter.setPageTotal(command.getPostPageTotal());
        } else {
            paginationFilter.setPageTotal(null);
        }
        paginationFilter.addSortingCriteria("postId", "asc");

        AdvancedSearchForum advancedSearchForum = new AdvancedSearchForum();
        advancedSearchForum.setAuthor(command.getAccount());
        advancedSearchForum.setDisplayResults("ForumPost");

        Page postsPage = getCommunityService().searchForumPosts(advancedSearchForum, paginationFilter);
        model.put("postsPage", postsPage);
        if (postsPage.getList().size() == 0) {
            model.put("isEmpty", true);
        }
    } catch (ApplicationThrowable applicationThrowable) {
        model.put("applicationThrowable", applicationThrowable);
        return new ModelAndView("error/ShowTopicForum", model);
    }

    if (ObjectUtils.toString(command.getCompleteDOM()).equals(Boolean.TRUE.toString())) {
        return new ModelAndView("community/ShowTopicForumCompleteDOM", model);
    } else {
        return new ModelAndView("community/ShowTopicForum", model);
    }
}

From source file:org.medici.bia.controller.community.ShowUserProfileForumController.java

/**
 * /*from   ww  w.j  a  v a 2s  . c  om*/
 * @param request
 * @param model
 * @return
 */
@RequestMapping(method = RequestMethod.GET)
public ModelAndView setupForm(@ModelAttribute("command") ShowUserProfileForumCommand command,
        HttpSession httpSession) {
    Map<String, Object> model = new HashMap<String, Object>(0);

    try {
        User user = null;
        if (command.getAccount() == null) {
            user = getUserService().findUser(
                    ((UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal())
                            .getUsername());
        } else {
            user = getUserService().findUser(command.getAccount());
        }

        //         if (user != null) {
        //            if (user.getForumJoinedDate() == null) {
        //               user = getCommunityService().joinUserOnForum();
        //            }
        //         }

        model.put("mostActiveForum", getCommunityService().getMostActiveForumByUser(user));
        model.put("mostActiveDiscussion", getCommunityService().getMostActiveTopicByUser(user));

        model.put("userProfile", user);
        model.put("userGroup",
                UserRoleUtils.getMostSignificantRole(new ArrayList<UserRole>(user.getUserRoles())));
    } catch (ApplicationThrowable applicationThrowable) {
        model.put("applicationThrowable", applicationThrowable);
        return new ModelAndView("error/ShowUserProfileForum", model);
    }

    if (command.getCompleteDOM() != null
            && ObjectUtils.toString(command.getCompleteDOM()).equals(Boolean.TRUE.toString())) {
        return new ModelAndView("community/ShowUserProfileForumCompleteDOM", model);
    } else {
        return new ModelAndView("community/ShowUserProfileForum", model);
    }
}