List of usage examples for org.apache.commons.collections Predicate Predicate
Predicate
From source file:flex2.compiler.mxml.rep.MxmlDocument.java
/** * *//* w w w.j a v a 2 s . c o m*/ private final Iterator<PropertyDeclaration> getTopLevelDeclarationIterator() { return new FilterIterator(declarations.values().iterator(), new Predicate() { public boolean evaluate(Object object) { return ((PropertyDeclaration) object).getTopLevel(); } }); }
From source file:net.sourceforge.fenixedu.domain.teacher.TeacherService.java
public List<TeacherServiceComment> getTeacherServiceComments() { return (List<TeacherServiceComment>) CollectionUtils.select(getServiceItemsSet(), new Predicate() { @Override/* w ww . j av a 2 s . c o m*/ public boolean evaluate(Object arg0) { return arg0 instanceof TeacherServiceComment; } }); }
From source file:models.NotificationEvent.java
private static void filterReceivers(final NotificationEvent event) { final Project project = event.getProject(); if (project == null) { return;//from ww w.j a va2 s . c o m } final Resource resource = project.asResource(); CollectionUtils.filter(event.receivers, new Predicate() { @Override public boolean evaluate(Object obj) { User receiver = (User) obj; if (receiver.loginId == null) { return false; } if (!Watch.isWatching(receiver, resource)) { return true; } return UserProjectNotification.isEnabledNotiType(receiver, project, event.eventType); } }); }
From source file:net.sourceforge.fenixedu.domain.messaging.AnnouncementBoard.java
private List<Announcement> filterAnnouncements(Collection<Announcement> announcements, final Predicate predicate) { return (List<Announcement>) CollectionUtils.select(announcements, new Predicate() { @Override//from w w w . j a va2 s . co m public boolean evaluate(Object arg0) { Announcement announcement = (Announcement) arg0; return announcement.getApproved() && predicate.evaluate(arg0); } }); }
From source file:flex2.compiler.mxml.rep.MxmlDocument.java
/** * *///from w w w . ja va 2 s .c o m public final Iterator<Initializer> getNonStagePropertyInitializerIterator() { return new FilterIterator( new IteratorChain(root.getPropertyInitializerIterator(false), getTopLevelInitializerIterator()), new Predicate() { public boolean evaluate(Object object) { if (object instanceof NamedInitializer) return (!StandardDefs.isStageProperty(((NamedInitializer) object).getName())) && (!((NamedInitializer) object).isDesignLayer()); return true; } }); }
From source file:controllers.admin.UserManager.java
/** * Find a user using either a UID or a mail address.<br/> * The option is provided as a parameter of the form. *//*from w w w.ja va 2 s . c om*/ public Result findUser() { Form<UserSeachFormData> boundForm = userSearchForm.bindFromRequest(); if (boundForm.hasErrors()) { return badRequest(views.html.admin.usermanager.usermanager_search.render(boundForm)); } UserSeachFormData searchFormData = boundForm.get(); // Reject if search by UID but no uid if (searchFormData.searchType.equals(UID_SEARCH_OPTION) && (searchFormData.uid == null || searchFormData.uid.trim().equals("") || searchFormData.uid.indexOf('*') != -1)) { boundForm.reject("uid", Msg.get("error.required")); return badRequest(views.html.admin.usermanager.usermanager_search.render(boundForm)); } // Reject if search by UID but no uid if (searchFormData.searchType.equals(MAIL_SEARCH_OPTION) && (searchFormData.mail == null || searchFormData.mail.trim().equals("") || searchFormData.mail.indexOf('*') != -1)) { boundForm.reject("mail", Msg.get("error.required")); return badRequest(views.html.admin.usermanager.usermanager_search.render(boundForm)); } // Reject if search by full name but no full name if (searchFormData.searchType.equals(FULLNAME_SEARCH_OPTION) && (searchFormData.fullName == null || searchFormData.fullName.trim().equals(""))) { boundForm.reject("fullName", Msg.get("error.required")); return badRequest(views.html.admin.usermanager.usermanager_search.render(boundForm)); } IUserAccount foundUser = null; if (searchFormData.searchType.equals(UID_SEARCH_OPTION)) { // Search by uid try { if (log.isDebugEnabled()) { log.debug("Search user by uid with " + searchFormData.uid); } IUserAccount userAccount = getAccountManagerPlugin().getUserAccountFromUid(searchFormData.uid); if (userAccount == null || userAccount.isMarkedForDeletion() || !userAccount.isDisplayed()) { boundForm.reject("uid", Msg.get("admin.user_manager.search.not_found", searchFormData.uid)); return badRequest(views.html.admin.usermanager.usermanager_search.render(boundForm)); } foundUser = userAccount; } catch (AccountManagementException e) { return ControllersUtils.logAndReturnUnexpectedError(e, log, getConfiguration(), getI18nMessagesPlugin()); } } if (searchFormData.searchType.equals(MAIL_SEARCH_OPTION)) { // Search by e-mail try { if (log.isDebugEnabled()) { log.debug("Search user by mail with " + searchFormData.mail); } IUserAccount userAccount = getAccountManagerPlugin().getUserAccountFromEmail(searchFormData.mail); if (userAccount == null || userAccount.isMarkedForDeletion() || !userAccount.isDisplayed()) { boundForm.reject("mail", Msg.get("admin.user_manager.search.not_found", searchFormData.mail)); return badRequest(views.html.admin.usermanager.usermanager_search.render(boundForm)); } foundUser = userAccount; } catch (AccountManagementException e) { return ControllersUtils.logAndReturnUnexpectedError(e, log, getConfiguration(), getI18nMessagesPlugin()); } } if (searchFormData.searchType.equals(FULLNAME_SEARCH_OPTION)) { // Search by last name try { if (log.isDebugEnabled()) { log.debug("Search user by name with " + searchFormData.fullName); } List<IUserAccount> userAccounts = getAccountManagerPlugin() .getUserAccountsFromName(searchFormData.fullName); if (userAccounts == null || userAccounts.size() == 0) { boundForm.reject("fullName", Msg.get("admin.user_manager.search.not_found", searchFormData.fullName)); return badRequest(views.html.admin.usermanager.usermanager_search.render(boundForm)); } if (userAccounts.size() > 1) { // Filter the accounts marked for deletion CollectionUtils.filter(userAccounts, new Predicate() { @Override public boolean evaluate(Object userAccountAsObject) { IUserAccount userAccount = (IUserAccount) userAccountAsObject; try { return !userAccount.isMarkedForDeletion() && userAccount.isDisplayed(); } catch (AccountManagementException e) { return false; } } }); Table<IUserAccount> foundUserAccountsTable = tableTemplate.fill(userAccounts); // Multiple user found, display the selection list return ok( views.html.admin.usermanager.usermanager_search_results.render(foundUserAccountsTable)); } foundUser = userAccounts.get(0); // Only one user } catch (AccountManagementException e) { return ControllersUtils.logAndReturnUnexpectedError(e, log, getConfiguration(), getI18nMessagesPlugin()); } } return ok(views.html.admin.usermanager.usermanager_display .render(getAccountManagerPlugin().isAuthenticationRepositoryMasterMode(), foundUser)); }
From source file:com.ebay.cloud.cms.entmgr.entity.impl.EntityMergeTest.java
@SuppressWarnings("unchecked") @Test//from w w w .j ava 2s. c o m public void testTargetPullMergeEntityOnField() { EntityContext context = newEntityContext(); MetaClass metaClass = raptorMetaService.getMetaClass(APPLICATION_SERVICE); IEntity qEntity = new JsonEntity(metaClass); qEntity.setBranchId(MAIN_BRANCH); final String applicationId = "4fbb314fc681caf13e283a76"; final String services = "services"; qEntity.setId(applicationId); IEntity foundEntity = entityService.get(qEntity, context); IEntity givenEntity = new JsonEntity(metaClass); givenEntity.setId(applicationId); givenEntity.setBranchId(MAIN_BRANCH); final String name = "name"; // an confusion for other givenEntity.setFieldValues(name, foundEntity.getFieldValues(name)); // case 1 empty given { assertFalse(targetFieldPullMerger.mergeEntityOnField(givenEntity, services, foundEntity)); } // case 2 all to be removed { givenEntity.setFieldValues(services, foundEntity.getFieldValues(services)); assertTrue(targetFieldPullMerger.mergeEntityOnField(givenEntity, services, foundEntity)); assertTrue(givenEntity.hasField(services)); assertEquals(0, givenEntity.getFieldValues(services).size()); } // case 3 something unkown MetaClass serviceMeta = raptorMetaService.getMetaClass(SERVICE_INSTANCE); IEntity unknown = new JsonEntity(serviceMeta); unknown.setId("random-id"); givenEntity.setFieldValues(services, Arrays.asList(unknown)); assertFalse(targetFieldPullMerger.mergeEntityOnField(givenEntity, services, foundEntity)); // case 4 some yes some thing not final List<IEntity> subList = (List<IEntity>) foundEntity.getFieldValues(services).subList(0, 3); givenEntity.setFieldValues(services, subList); givenEntity.addFieldValue(services, unknown); assertTrue(targetFieldPullMerger.mergeEntityOnField(givenEntity, services, foundEntity)); assertEquals(foundEntity.getFieldValues(services).size() - subList.size(), givenEntity.getFieldValues(services).size()); // should assert the ids List<?> mergedValues = givenEntity.getFieldValues(services); CollectionUtils.filter(mergedValues, new Predicate() { @Override public boolean evaluate(Object object) { IEntity entity = (IEntity) object; for (IEntity e : subList) { if (e.getId().equals(entity.getId())) { return false; } } return true; } }); assertEquals(mergedValues.size(), givenEntity.getFieldValues(services).size()); // case 5 : normal non-many field { givenEntity.removeField(name); assertTrue(targetFieldPullMerger.mergeEntityOnField(givenEntity, name, foundEntity)); givenEntity.setFieldValues(name, foundEntity.getFieldValues(name)); // it works as just pull assertTrue(targetFieldPullMerger.mergeEntityOnField(givenEntity, name, foundEntity)); givenEntity.addFieldValue(name, "new-name"); assertTrue(targetFieldPullMerger.mergeEntityOnField(givenEntity, name, foundEntity)); } // case 6 : normal array field { final String manifest = "activeManifestRef"; givenEntity.removeField(manifest); assertFalse(targetFieldPullMerger.mergeEntityOnField(givenEntity, manifest, foundEntity)); givenEntity.setFieldValues(manifest, foundEntity.getFieldValues(manifest)); assertTrue(targetFieldPullMerger.mergeEntityOnField(givenEntity, manifest, foundEntity)); givenEntity.addFieldValue(manifest, "new-name"); assertFalse(targetFieldPullMerger.mergeEntityOnField(givenEntity, manifest, foundEntity)); givenEntity.setFieldValues(manifest, Arrays.asList("new-name")); assertFalse(targetFieldPullMerger.mergeEntityOnField(givenEntity, manifest, foundEntity)); } // case 7 : cardinality = one reference { qEntity = new JsonEntity(serviceMeta); qEntity.setBranchId(MAIN_BRANCH); final String serviceId = "4fbb314fc681caf13e283a7c"; final String compute = "runsOn"; qEntity.setId(serviceId); foundEntity = entityService.get(qEntity, context); givenEntity = new JsonEntity(serviceMeta); assertTrue(targetFieldPullMerger.mergeEntityOnField(givenEntity, compute, foundEntity)); givenEntity.setFieldValues(compute, foundEntity.getFieldValues(compute)); assertTrue(targetFieldPullMerger.mergeEntityOnField(givenEntity, compute, foundEntity)); assertFalse(givenEntity.hasField(compute)); MetaClass computeMeta = raptorMetaService.getMetaClass(COMPUTE); JsonEntity computeEntity = new JsonEntity(computeMeta); computeEntity.setId("unknown-id"); givenEntity.setFieldValues(compute, Arrays.asList(computeEntity)); assertTrue(targetFieldPullMerger.mergeEntityOnField(givenEntity, compute, foundEntity)); } }
From source file:net.sourceforge.fenixedu.domain.messaging.AnnouncementBoard.java
public List<Announcement> getActiveAnnouncementsFor(final YearMonthDay date) { return filterAnnouncements(getAnnouncementSet(), new Predicate() { @Override// w w w . j a va 2 s . co m public boolean evaluate(Object arg0) { Announcement announcement = (Announcement) arg0; DateTime announcementDate = announcement.getReferedSubjectBegin(); DateTime finalAnnouncementDate = announcement.getReferedSubjectEnd(); return announcement.isActive() && announcement.getVisible() && announcementDate != null && (announcementDate.toYearMonthDay().equals(date) || (announcementDate.toYearMonthDay().isBefore(date) && finalAnnouncementDate != null && finalAnnouncementDate.toYearMonthDay().isAfter(date))); } }); }
From source file:edu.kit.dama.rest.sharing.services.impl.SharingRestServiceImpl.java
@Override public IEntityWrapper<? extends IDefaultGrant> createGrant(String pDomain, String pDomainUniqueId, final String pUserId, String pGroupId, String pRole, HttpContext hc) { IAuthorizationContext ctx = RestUtils.authorize(hc, new GroupId(pGroupId)); try {//from w ww . j a v a 2 s. c o m SecurableResourceId resId = factoryResourceId(pDomain, pDomainUniqueId); LOGGER.debug("Checking whether grants are allowed."); if (!ResourceServiceLocal.getSingleton().grantsAllowed(resId, ctx)) { LOGGER.debug("Grants are not allowed. Enabling grants with max. role MANAGER."); //allow grants with max. role MANAGER. //@TODO check whether this should be solved in a configurable way. ResourceServiceLocal.getSingleton().allowGrants(resId, Role.MANAGER, ctx); LOGGER.debug("Grants are now allowed."); } else { LOGGER.debug("Grants are already allowed."); } LOGGER.debug("Adding grant for user {} on resource {}", resId, pUserId); //add grant ResourceServiceLocal.getSingleton().addGrant(resId, new UserId(pUserId), Role.valueOf(pRole), ctx); LOGGER.debug("Obtaining grant information for resource {} from database.", resId); //get all grants as addGrant does not return anything. List<Grant> grants = ResourceServiceLocal.getSingleton().getGrants(resId, ctx); LOGGER.debug("Searching for grantee {}.", pUserId); //search for appropriate grant Grant grant = (Grant) CollectionUtils.find(grants, new Predicate() { @Override public boolean evaluate(Object o) { return ((Grant) o).getGrantee().getUserId().equals(pUserId); } }); if (grant != null) { LOGGER.debug("Grant information successfully obtained. Returning result."); } else { LOGGER.warn("No grant information obtained. Returning empty result."); } //return RestUtils.transformObject(IMPL_CLASSES, Constants.REST_DEFAULT_OBJECT_GRAPH, new GrantWrapper(grant)); return new GrantWrapper(grant); } catch (UnauthorizedAccessAttemptException ex) { LOGGER.error("Failed to create grant", ex); throw new WebApplicationException(401); } catch (EntityNotFoundException ex) { LOGGER.error( "EntityNotFoundException caught while adding Grant. Probably, the resource " + new SecurableResourceId(pDomain, pDomainUniqueId) + " was not registered before.", ex); throw new WebApplicationException(404); } catch (EntityAlreadyExistsException ex) { LOGGER.error( "EntityAlreadyExistsException caught while adding Grant. Probably, there is already a grant for resource " + new SecurableResourceId(pDomain, pDomainUniqueId) + " and user " + pUserId + ".", ex); throw new WebApplicationException(409); } }
From source file:flex2.compiler.mxml.rep.MxmlDocument.java
/** * *//*from w ww.j av a2s .co m*/ public final Iterator<Initializer> getDesignLayerPropertyInitializerIterator() { return new FilterIterator(layerDeclarations.iterator(), new Predicate() { public boolean evaluate(Object object) { return object instanceof InitializedPropertyDeclaration; } }); }