List of usage examples for org.apache.commons.collections CollectionUtils filter
public static void filter(Collection collection, Predicate predicate)
From source file:org.squashtest.tm.service.internal.requirement.CustomRequirementVersionManagerServiceImpl.java
private void filterLockedAndPlannedStatus(Collection<Milestone> milestones) { CollectionUtils.filter(milestones, new Predicate() { @Override// w w w. j av a 2 s . co m public boolean evaluate(Object milestone) { return ((Milestone) milestone).getStatus() != MilestoneStatus.LOCKED && ((Milestone) milestone).getStatus() != MilestoneStatus.PLANNED; } }); }
From source file:org.squashtest.tm.web.internal.controller.campaign.CampaignModificationController.java
@RequestMapping(value = "/milestones/panel", method = RequestMethod.GET) public String getMilestonesPanel(@PathVariable(CAMPAIGN_ID) Long campaignId, Model model) { MilestonePanelConfiguration conf = new MilestonePanelConfiguration(); Campaign camp = campaignModService.findById(campaignId); // build the needed data Collection<Milestone> allMilestones = campaignModService.findAllMilestones(campaignId); List<?> currentModel = buildMilestoneModel(new ArrayList<>(allMilestones), "0").getAaData(); Map<String, String> identity = new HashMap<>(); identity.put("restype", "campaigns"); identity.put("resid", campaignId.toString()); String rootPath = "/campaigns/" + campaignId.toString(); Boolean editable = permissionService.hasRole("ROLE_ADMIN") || permissionService.hasRole("ROLE_TM_PROJECT_MANAGER"); List<Milestone> mil = camp.getProject().getMilestones(); CollectionUtils.filter(mil, new Predicate() { @Override/*from www . j a v a 2 s. c om*/ public boolean evaluate(Object milestone) { return ((Milestone) milestone).getStatus().isBindableToObject(); } }); Boolean isMilestoneInProject = !mil.isEmpty(); // add them to the model conf.setNodeType("campaign"); conf.setRootPath(rootPath); conf.setIdentity(identity); conf.setCurrentModel(currentModel); conf.setEditable(editable); conf.setMultilines(false); conf.setIsMilestoneInProject(isMilestoneInProject); model.addAttribute("conf", conf); return "milestones/milestones-tab.html"; }
From source file:org.squashtest.tm.web.internal.controller.requirement.RequirementVersionModificationController.java
@RequestMapping(value = "/milestones/panel", method = RequestMethod.GET) public String getMilestonesPanel(@PathVariable("requirementVersionId") Long requirementVersionId, Model model) { MilestonePanelConfiguration conf = new MilestonePanelConfiguration(); RequirementVersion version = requirementVersionManager.findById(requirementVersionId); // build the needed data Collection<Milestone> allMilestones = requirementVersionManager.findAllMilestones(requirementVersionId); List<?> currentModel = buildMilestoneModel(new ArrayList<>(allMilestones), "0").getAaData(); Map<String, String> identity = new HashMap<>(); identity.put("restype", "requirements"); identity.put("resid", version.getRequirement().getId().toString()); String rootPath = "/requirement-versions/" + requirementVersionId.toString(); Boolean editable = permissionService.hasRoleOrPermissionOnObject("ROLE_ADMIN", "LINK", version); List<Milestone> mil = version.getProject().getMilestones(); CollectionUtils.filter(mil, new Predicate() { @Override/*ww w .j a v a2 s .c o m*/ public boolean evaluate(Object milestone) { return ((Milestone) milestone).getStatus().isBindableToObject(); } }); Boolean isMilestoneInProject = !mil.isEmpty(); // add them to the model conf.setNodeType("requirement-version"); conf.setRootPath(rootPath); conf.setIdentity(identity); conf.setCurrentModel(currentModel); conf.setEditable(editable); conf.setIsMilestoneInProject(isMilestoneInProject); model.addAttribute("conf", conf); return "milestones/milestones-tab.html"; }
From source file:org.squashtest.tm.web.internal.controller.testcase.steps.TestStepViewFromExec.java
private void removeDeletedSteps(List<ExecutionStep> allSteps) { CollectionUtils.filter(allSteps, NOT_DELETED); }
From source file:org.squashtest.tm.web.internal.controller.testcase.TestCaseModificationController.java
@RequestMapping(value = "/milestones/panel", method = RequestMethod.GET) public String getMilestonesPanel(@PathVariable Long testCaseId, Model model) { MilestonePanelConfiguration conf = new MilestonePanelConfiguration(); TestCase tc = testCaseModificationService.findById(testCaseId); // build the needed data Collection<Milestone> allMilestones = testCaseModificationService.findAllMilestones(testCaseId); List<?> currentModel = buildMilestoneTableModel(testCaseId, allMilestones, "0").getAaData(); Map<String, String> identity = new HashMap<>(); identity.put("restype", "test-cases"); identity.put("resid", testCaseId.toString()); String rootPath = "/test-cases/" + testCaseId.toString(); Boolean editable = permissionService.hasRoleOrPermissionOnObject("ROLE_ADMIN", "LINK", tc); List<Milestone> mil = tc.getProject().getMilestones(); CollectionUtils.filter(mil, new Predicate() { @Override/*from ww w . ja va 2 s .c om*/ public boolean evaluate(Object milestone) { return ((Milestone) milestone).getStatus().isBindableToObject(); } }); // add them to the model Boolean isMilestoneInProject = !mil.isEmpty(); conf.setNodeType("testcase"); conf.setRootPath(rootPath); conf.setIdentity(identity); conf.setCurrentModel(currentModel); conf.setEditable(editable); conf.setIsMilestoneInProject(isMilestoneInProject); model.addAttribute("conf", conf); return "milestones/milestones-tab.html"; }
From source file:org.squashtest.tm.web.internal.wizard.WorkspaceWizardManagerImpl.java
private Collection<WorkspaceWizard> filterWizards(Collection<WorkspaceWizard> wizards, Predicate predicate) { Collection<WorkspaceWizard> res = new ArrayList<>(wizards); // 'wizards' is immutable CollectionUtils.filter(res, predicate); return res;//ww w . j a v a 2 s .c o m }
From source file:org.tonguetied.web.KeywordController.java
@Override protected Object formBackingObject(HttpServletRequest request) throws Exception { final Long id = RequestUtils.getLongParameter(request, KEYWORD_ID); Keyword keyword;//from w w w . ja va 2 s.co m if (id == null) { final String creationType = request.getParameter("creationType"); final Bundle bundle = keywordService.getDefaultBundle(); if (LANGUAGE.equals(creationType)) { keyword = KeywordFactory.createKeyword(keywordService.getLanguages(), keywordService.getCountry(CountryCode.DEFAULT), bundle); } else if (COUNTRY.equals(creationType)) { keyword = KeywordFactory.createKeyword(keywordService.getCountries(), keywordService.getLanguage(LanguageCode.DEFAULT), bundle); } else { // catch all if neither is specified. This is a rare occurence // and generally will not occur. This case is only to prevent // NPE when rendering the form keyword = new Keyword(); } } else { keyword = keywordService.getKeyword(id); final boolean isFilterApplied = isFilterApplied(request.getSession()); if (isFilterApplied) { keyword = keyword.deepClone(); final PreferenceFilter filter = new PreferenceFilter(viewPreferences); // do a deep copy of keywords to detach from Hibernate session CollectionUtils.filter(keyword.getTranslations(), filter); } } return keyword; }
From source file:org.tonguetied.web.KeywordController.java
/** * Save changes to the current {@link Keyword}. * //from w ww .ja v a 2s .c o m * @param keyword the current keyword * @param isFilterApplied flag indicating if the view filter should be * applied to the translations * @return the ModelAndView to render */ private ModelAndView saveKeyword(HttpServletRequest request, HttpServletResponse response, Keyword keyword, BindException errors, final boolean isFilterApplied) throws Exception { Set<Long> origIds = new HashSet<Long>(); if (isFilterApplied) { for (Translation translation : keyword.getTranslations()) { origIds.add(translation.getId()); } mergeFilteredTranslations(keyword, errors); } ModelAndView mav; if (!errors.hasErrors()) { keywordService.saveOrUpdate(keyword); mav = new ModelAndView(getSuccessView()); } else { if (isFilterApplied) { final TranslationIdPredicate predicate = new TranslationIdPredicate(origIds); CollectionUtils.filter(keyword.getTranslations(), predicate); } mav = showForm(request, response, errors); } return mav; }
From source file:org.tonguetied.web.MainController.java
/** * Filters out the translations that the user selected in the * {@link PreferenceForm}./*from w w w . j a v a 2 s . c o m*/ * * @param keywords the list of {@link Keyword}s to apply the filter to * @throws CloneNotSupportedException if one of the objects in the list is * not cloneable */ private PaginatedList<Keyword> applyViewPreferences(final PaginatedList<Keyword> keywords) throws CloneNotSupportedException { final PreferenceFilter filter = new PreferenceFilter(viewPreferences); // do a deep copy of keywords to detach from hibernate session PaginatedList<Keyword> clone = keywords.deepClone(); for (final Keyword keyword : clone) { CollectionUtils.filter(keyword.getTranslations(), filter); } return clone; }
From source file:org.wildfly.swarm.microprofile.openapi.runtime.util.JandexUtil.java
/** * Returns all annotations configured for a single parameter of a method. * @param method/*from w w w . jav a 2 s .c o m*/ * @param paramPosition */ public static List<AnnotationInstance> getParameterAnnotations(MethodInfo method, short paramPosition) { List<AnnotationInstance> annotations = new ArrayList<>(method.annotations()); CollectionUtils.filter(annotations, new Predicate() { @Override public boolean evaluate(Object object) { AnnotationInstance annotation = (AnnotationInstance) object; AnnotationTarget target = annotation.target(); return target != null && target.kind() == Kind.METHOD_PARAMETER && target.asMethodParameter().position() == paramPosition; } }); return annotations; }