List of usage examples for org.apache.commons.collections4 Predicate Predicate
Predicate
From source file:org.apache.syncope.fit.core.SearchITCase.java
@Test public void member() { PagedResult<GroupTO> groups = groupService.search(new AnyQuery.Builder().realm("/") .fiql(SyncopeClient.getGroupSearchConditionBuilder().withMembers("rossini").query()).build()); assertNotNull(groups);/*from w w w.ja v a 2s . c o m*/ assertTrue(IterableUtils.matchesAny(groups.getResult(), new Predicate<GroupTO>() { @Override public boolean evaluate(final GroupTO group) { return "root".equals(group.getName()); } })); assertTrue(IterableUtils.matchesAny(groups.getResult(), new Predicate<GroupTO>() { @Override public boolean evaluate(final GroupTO group) { return "otherchild".equals(group.getName()); } })); }
From source file:org.apache.syncope.fit.core.SyncTaskITCase.java
@Test public void sync() throws Exception { removeTestUsers();//from w w w .jav a 2 s .c o m // ----------------------------- // Create a new user ... it should be updated applying sync policy // ----------------------------- UserTO inUserTO = new UserTO(); inUserTO.setRealm(SyncopeConstants.ROOT_REALM); inUserTO.setPassword("password123"); String userName = "test9"; inUserTO.setUsername(userName); inUserTO.getPlainAttrs().add(attrTO("firstname", "nome9")); inUserTO.getPlainAttrs().add(attrTO("surname", "cognome")); inUserTO.getPlainAttrs().add(attrTO("ctype", "a type")); inUserTO.getPlainAttrs().add(attrTO("fullname", "nome cognome")); inUserTO.getPlainAttrs().add(attrTO("userId", "puccini@syncope.apache.org")); inUserTO.getPlainAttrs().add(attrTO("email", "puccini@syncope.apache.org")); inUserTO.getAuxClasses().add("csv"); inUserTO.getDerAttrs().add(attrTO("csvuserid", null)); inUserTO = createUser(inUserTO).getAny(); assertNotNull(inUserTO); assertFalse(inUserTO.getResources().contains(RESOURCE_NAME_CSV)); // ----------------------------- try { int usersPre = userService .list(new AnySearchQuery.Builder().realm(SyncopeConstants.ROOT_REALM).page(1).size(1).build()) .getTotalCount(); assertNotNull(usersPre); execProvisioningTask(taskService, SYNC_TASK_ID, 50, false); // after execution of the sync task the user data should have been synced from CSV // and processed by user template UserTO userTO = userService.read(inUserTO.getKey()); assertNotNull(userTO); assertEquals(userName, userTO.getUsername()); assertEquals(ActivitiDetector.isActivitiEnabledForUsers(syncopeService) ? "active" : "created", userTO.getStatus()); assertEquals("test9@syncope.apache.org", userTO.getPlainAttrMap().get("email").getValues().get(0)); assertEquals("test9@syncope.apache.org", userTO.getPlainAttrMap().get("userId").getValues().get(0)); assertTrue(Integer.valueOf(userTO.getPlainAttrMap().get("fullname").getValues().get(0)) <= 10); assertTrue(userTO.getResources().contains(RESOURCE_NAME_TESTDB)); assertTrue(userTO.getResources().contains(RESOURCE_NAME_WS2)); // Matching --> Update (no link) assertFalse(userTO.getResources().contains(RESOURCE_NAME_CSV)); // check for user template userTO = readUser("test7"); assertNotNull(userTO); assertEquals("TYPE_OTHER", userTO.getPlainAttrMap().get("ctype").getValues().get(0)); assertEquals(3, userTO.getResources().size()); assertTrue(userTO.getResources().contains(RESOURCE_NAME_TESTDB)); assertTrue(userTO.getResources().contains(RESOURCE_NAME_WS2)); assertEquals(1, userTO.getMemberships().size()); assertEquals(8, userTO.getMemberships().get(0).getRightKey()); // Unmatching --> Assign (link) - SYNCOPE-658 assertTrue(userTO.getResources().contains(RESOURCE_NAME_CSV)); assertEquals(1, IterableUtils.countMatches(userTO.getDerAttrs(), new Predicate<AttrTO>() { @Override public boolean evaluate(final AttrTO attributeTO) { return "csvuserid".equals(attributeTO.getSchema()); } })); userTO = readUser("test8"); assertNotNull(userTO); assertEquals("TYPE_8", userTO.getPlainAttrMap().get("ctype").getValues().get(0)); // Check for ignored user - SYNCOPE-663 try { readUser("test2"); fail(); } catch (SyncopeClientException e) { assertEquals(Response.Status.NOT_FOUND, e.getType().getResponseStatus()); } // check for sync results int usersPost = userService .list(new AnySearchQuery.Builder().realm(SyncopeConstants.ROOT_REALM).page(1).size(1).build()) .getTotalCount(); assertNotNull(usersPost); assertEquals(usersPre + 8, usersPost); // Check for issue 215: // * expected disabled user test1 // * expected enabled user test2 userTO = readUser("test1"); assertNotNull(userTO); assertEquals("suspended", userTO.getStatus()); userTO = readUser("test3"); assertNotNull(userTO); assertEquals("active", userTO.getStatus()); Set<Long> otherSyncTaskKeys = new HashSet<>(); otherSyncTaskKeys.add(25L); otherSyncTaskKeys.add(26L); execProvisioningTasks(taskService, otherSyncTaskKeys, 50, false); // Matching --> UNLINK assertFalse(readUser("test9").getResources().contains(RESOURCE_NAME_CSV)); assertFalse(readUser("test7").getResources().contains(RESOURCE_NAME_CSV)); } finally { removeTestUsers(); } }
From source file:org.apache.syncope.fit.core.SyncTaskITCase.java
@Test public void reconcileFromScriptedSQL() { // 0. reset sync token and set MappingItemTransformer ResourceTO resource = resourceService.read(RESOURCE_NAME_DBSCRIPTED); ResourceTO originalResource = SerializationUtils.clone(resource); ProvisionTO provision = resource.getProvision("PRINTER"); assertNotNull(provision);/*from ww w . j a va 2 s . co m*/ try { provision.setSyncToken(null); MappingItemTO mappingItem = IterableUtils.find(provision.getMapping().getItems(), new Predicate<MappingItemTO>() { @Override public boolean evaluate(final MappingItemTO object) { return "location".equals(object.getIntAttrName()); } }); assertNotNull(mappingItem); mappingItem.getMappingItemTransformerClassNames().clear(); mappingItem.getMappingItemTransformerClassNames().add(PrefixMappingItemTransformer.class.getName()); resourceService.update(resource); // 1. create printer on external resource AnyObjectTO anyObjectTO = AnyObjectITCase.getSampleTO("sync"); String originalLocation = anyObjectTO.getPlainAttrMap().get("location").getValues().get(0); assertFalse(originalLocation.startsWith(PrefixMappingItemTransformer.PREFIX)); anyObjectTO = createAnyObject(anyObjectTO).getAny(); assertNotNull(anyObjectTO); // 2. verify that PrefixMappingItemTransformer was applied during propagation // (location starts with given prefix on external resource) ConnObjectTO connObjectTO = resourceService.readConnObject(RESOURCE_NAME_DBSCRIPTED, anyObjectTO.getType(), anyObjectTO.getKey()); assertFalse(anyObjectTO.getPlainAttrMap().get("location").getValues().get(0) .startsWith(PrefixMappingItemTransformer.PREFIX)); assertTrue(connObjectTO.getPlainAttrMap().get("location").getValues().get(0) .startsWith(PrefixMappingItemTransformer.PREFIX)); // 3. unlink any existing printer and delete from Syncope (printer is now only on external resource) PagedResult<AnyObjectTO> matchingPrinters = anyObjectService.search(new AnySearchQuery.Builder() .realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient .getAnyObjectSearchConditionBuilder("PRINTER").is("location").equalTo("sync*").query()) .build()); assertTrue(matchingPrinters.getSize() > 0); for (AnyObjectTO printer : matchingPrinters.getResult()) { DeassociationPatch deassociationPatch = new DeassociationPatch(); deassociationPatch.setKey(printer.getKey()); deassociationPatch.setAction(ResourceDeassociationAction.UNLINK); deassociationPatch.getResources().add(RESOURCE_NAME_DBSCRIPTED); anyObjectService.deassociate(deassociationPatch); anyObjectService.delete(printer.getKey()); } // 4. synchronize execProvisioningTask(taskService, 28L, 50, false); // 5. verify that printer was re-created in Syncope (implies that location does not start with given prefix, // hence PrefixMappingItemTransformer was applied during sync) matchingPrinters = anyObjectService.search(new AnySearchQuery.Builder() .realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient .getAnyObjectSearchConditionBuilder("PRINTER").is("location").equalTo("sync*").query()) .build()); assertTrue(matchingPrinters.getSize() > 0); // 6. verify that synctoken was updated assertNotNull(resourceService.read(RESOURCE_NAME_DBSCRIPTED).getProvision(anyObjectTO.getType()) .getSyncToken()); } finally { resourceService.update(originalResource); } }
From source file:org.broadleafcommerce.core.order.service.OrderTest.java
/** * From the list of all Skus in the database, gets a Sku that is active * @return//from w w w. j a v a 2 s. c o m */ public Sku getFirstActiveSku() { List<Sku> skus = skuDao.readAllSkus(); return CollectionUtils.find(skus, new Predicate<Sku>() { @Override public boolean evaluate(Sku sku) { return sku.isActive(); } }); }
From source file:org.craftercms.commons.audit.TestAuditServiceImpl.java
@Override public List<T> getAuditLogs(final Date from, final Date to) { if (memoryPersistence.values() == null) { return null; }//from w ww . j a v a 2s. c om List<T> valueSet = new ArrayList(memoryPersistence.values()); CollectionUtils.filter(valueSet, new Predicate<Object>() { @Override public boolean evaluate(final Object object) { if (object instanceof AuditModel) { final Date auditDate = ((AuditModel) object).getAuditDate(); return (auditDate.before(from)) || (auditDate.after(from) && auditDate.before(to)); } return false; } }); return valueSet; }
From source file:org.craftercms.engine.targeting.impl.TargetedContentStoreAdapter.java
protected boolean containsItem(final List<Item> list, final Item item) { int idx = ListUtils.indexOf(list, new Predicate<Item>() { @Override// w ww . j av a 2 s . com public boolean evaluate(Item it) { return it.getName().equals(item.getName()); } }); return idx >= 0; }
From source file:org.craftercms.profile.services.impl.ProfileServiceImpl.java
protected AttributeDefinition findAttributeDefinition(final List<AttributeDefinition> attributeDefinitions, final String name) { return CollectionUtils.find(attributeDefinitions, new Predicate<AttributeDefinition>() { @Override/*from w w w .j av a2 s . c o m*/ public boolean evaluate(AttributeDefinition definition) { return definition.getName().equals(name); } }); }
From source file:org.efaps.tests.ci.digester.CIFormField.java
/** * Gets the property./*www . ja v a 2 s. com*/ * * @param _name the name * @return the property */ public CIFormFieldProperty getProperty(final String _name) { return IterableUtils.find(getProperties(), new Predicate<CIFormFieldProperty>() { @Override public boolean evaluate(final CIFormFieldProperty _object) { return _object.getName().equals(_name); } }); }
From source file:org.efaps.tests.ci.digester.CITableField.java
/** * Gets the property./*ww w. j av a2s . c o m*/ * * @param _name the name * @return the property */ public CITableFieldProperty getProperty(final String _name) { return IterableUtils.find(getProperties(), new Predicate<CITableFieldProperty>() { @Override public boolean evaluate(final CITableFieldProperty _object) { return _object.getName().equals(_name); } }); }
From source file:org.jasig.cas.support.oauth.OAuthTokenUtils.java
/** * Attempt to locate and return an existing refresh token. * * @param centralAuthenticationService the central authentication service * @param clientId the client id/* w w w . j a va 2 s.c o m*/ * @param principal the principal * @return TicketGrantingTicket refresh token or null */ public static TicketGrantingTicket getRefreshToken( final CentralAuthenticationService centralAuthenticationService, final String clientId, final Principal principal) { final Collection<Ticket> tickets = centralAuthenticationService.getTickets(new Predicate() { @Override public boolean evaluate(final Object currentTicket) { if (currentTicket instanceof TicketGrantingTicket) { final TicketGrantingTicket currentTicketGrantingTicket = (TicketGrantingTicket) currentTicket; final Principal currentPrincipal = currentTicketGrantingTicket.getAuthentication() .getPrincipal(); final Map<String, Object> currentAttributes = currentTicketGrantingTicket.getAuthentication() .getAttributes(); if ((currentAttributes.containsKey(OAuthCredential.AUTHENTICATION_ATTRIBUTE_OAUTH) && (Boolean) currentAttributes.get(OAuthCredential.AUTHENTICATION_ATTRIBUTE_OAUTH)) && (currentAttributes.containsKey(OAuthConstants.CLIENT_ID) && currentAttributes.get(OAuthConstants.CLIENT_ID).equals(clientId)) && currentPrincipal.getId().equals(principal.getId())) { return !currentTicketGrantingTicket.isExpired(); } } return false; } }); if (tickets.size() == 1) { return (TicketGrantingTicket) tickets.iterator().next(); } return null; }