List of usage examples for org.apache.commons.collections4 CollectionUtils find
@Deprecated public static <T> T find(final Iterable<T> collection, final Predicate<? super T> predicate)
From source file:com.github.rvesse.airline.model.MetadataLoader.java
protected static void buildGroupsHierarchy(List<CommandGroupMetadata> commandGroups, Map<String, CommandGroupMetadata> subGroups) { // Add sub-groups into hierarchy as appropriate for (String subGroupPath : subGroups.keySet()) { CommandGroupMetadata subGroup = subGroups.get(subGroupPath); String[] groups = StringUtils.split(subGroupPath); CommandGroupMetadata parentGroup = null; for (int i = 0; i < groups.length - 1; i++) { if (i == 0) { // Should be a top level group parentGroup = CollectionUtils.find(commandGroups, new GroupFinder(groups[i])); if (parentGroup == null) { // Top level parent group does not exist so create empty // top level group parentGroup = new CommandGroupMetadata(groups[i], "", false, Collections.<OptionMetadata>emptyList(), Collections.<CommandGroupMetadata>emptyList(), null, Collections.<CommandMetadata>emptyList()); commandGroups.add(parentGroup); }// w ww . j a v a 2 s .co m } else { // Should be a sub-group of the current parent CommandGroupMetadata nextParent = CollectionUtils.find(parentGroup.getSubGroups(), new GroupFinder(groups[i])); if (nextParent == null) { // Next parent group does not exist so create empty // group nextParent = new CommandGroupMetadata(groups[i], "", false, Collections.<OptionMetadata>emptyList(), Collections.<CommandGroupMetadata>emptyList(), null, Collections.<CommandMetadata>emptyList()); } parentGroup.addSubGroup(nextParent); nextParent.setParent(parentGroup); parentGroup = nextParent; } } if (parentGroup == null) throw new IllegalStateException("Failed to resolve sub-group path"); parentGroup.addSubGroup(subGroup); subGroup.setParent(parentGroup); } }
From source file:net.tirasa.blog.ilgrosso.syncopecustompolicyrules.sample.App.java
public static void main(final String[] args) { // 1. configure the custom account rule and create an account policy using it CustomAccountRuleConf customAccountRuleConf = new CustomAccountRuleConf(); customAccountRuleConf.setRequiredSubString(ACCOUNT_REQUIRED_SUBSTRING); AccountPolicyTO accountPolicy = new AccountPolicyTO(); accountPolicy.setDescription("Account Policy with custom rules"); accountPolicy.getRuleConfs().add(customAccountRuleConf); accountPolicy = createPolicy(accountPolicy); // 2. create a password policy using a custom password rule with no configuration options PasswordPolicyTO passwordPolicy = new PasswordPolicyTO(); passwordPolicy.setDescription("Password Policy with custom rules"); passwordPolicy.getRuleConfs().add(new CustomPasswordRuleConf()); passwordPolicy = createPolicy(passwordPolicy); // 3. set the account and password policies above for root realm List<RealmTO> realms = client.getService(RealmService.class).list(); RealmTO rootRealm = CollectionUtils.find(realms, new Predicate<RealmTO>() { @Override/*from w w w . j ava2s . c o m*/ public boolean evaluate(final RealmTO realm) { return SyncopeConstants.ROOT_REALM.equals(realm.getFullPath()); } }); rootRealm.setAccountPolicy(accountPolicy.getKey()); rootRealm.setPasswordPolicy(passwordPolicy.getKey()); client.getService(RealmService.class).update(rootRealm); // 4. obtain sample user: should fail both account and password policy verification UserTO userTO = getSampleTO("sample@tirasa.net"); // 5. attempt to create user -> password policy fails because it has the same value as security answer try { client.getService(UserService.class).create(userTO); fail(); } catch (SyncopeClientException e) { assertEquals(ClientExceptionType.InvalidUser, e.getType()); assertTrue(e.getElements().iterator().next().startsWith("InvalidPassword")); } // 6. change security answer to comply with password policy userTO.setSecurityAnswer("another value"); // 7. attempt to create user -> account policy fails because username doesn't contain ACCOUNT_REQUIRED_SUBSTRING try { client.getService(UserService.class).create(userTO); fail(); } catch (SyncopeClientException e) { assertEquals(ClientExceptionType.InvalidUser, e.getType()); assertTrue(e.getElements().iterator().next().startsWith("InvalidUsername")); } // 8. change username to comply with account policy userTO.setUsername("pre" + ACCOUNT_REQUIRED_SUBSTRING + "post"); // 9. finally succeed :-) client.getService(UserService.class).create(userTO); }
From source file:org.apache.syncope.common.lib.types.SyncPolicySpec.java
public SyncPolicySpecItem getItem(final String anyTypeKey) { return CollectionUtils.find(items, new Predicate<SyncPolicySpecItem>() { @Override//w ww . j av a 2s . co m public boolean evaluate(final SyncPolicySpecItem item) { return anyTypeKey != null && anyTypeKey.equals(item.getAnyTypeKey()); } }); }
From source file:org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAAnyObject.java
@Override public ARelationship getRelationship(final RelationshipType relationshipType) { return CollectionUtils.find(getRelationships(), new Predicate<ARelationship>() { @Override/*from w w w . ja v a 2 s. c om*/ public boolean evaluate(final ARelationship relationship) { return relationshipType != null && relationshipType.equals(relationship.getType()); } }); }
From source file:org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAAnyObject.java
@Override public ARelationship getRelationship(final Long anyObjectKey) { return CollectionUtils.find(getRelationships(), new Predicate<ARelationship>() { @Override//from ww w . j av a 2 s .c o m public boolean evaluate(final ARelationship relationship) { return anyObjectKey != null && anyObjectKey.equals(relationship.getRightEnd().getKey()); } }); }
From source file:org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAAnyObject.java
@Override public AMembership getMembership(final Long groupKey) { return CollectionUtils.find(getMemberships(), new Predicate<AMembership>() { @Override/*w w w. ja va 2s .c o m*/ public boolean evaluate(final AMembership membership) { return groupKey != null && groupKey.equals(membership.getRightEnd().getKey()); } }); }
From source file:org.apache.syncope.core.persistence.jpa.entity.task.JPASyncTask.java
@Override public AnyTemplate getTemplate(final AnyType anyType) { return CollectionUtils.find(templates, new Predicate<AnyTemplate>() { @Override/* ww w.j a v a2s.c o m*/ public boolean evaluate(final AnyTemplate template) { return anyType != null && anyType.equals(template.getAnyType()); } }); }
From source file:org.apache.syncope.core.persistence.jpa.entity.user.JPAUser.java
@Override public URelationship getRelationship(final RelationshipType relationshipType) { return CollectionUtils.find(getRelationships(), new Predicate<URelationship>() { @Override// w w w. jav a 2 s .c o m public boolean evaluate(final URelationship relationship) { return relationshipType != null && relationshipType.equals(relationship.getType()); } }); }
From source file:org.apache.syncope.core.persistence.jpa.entity.user.JPAUser.java
@Override public URelationship getRelationship(final Long anyObjectKey) { return CollectionUtils.find(getRelationships(), new Predicate<URelationship>() { @Override//from www. j av a 2 s. c om public boolean evaluate(final URelationship relationship) { return anyObjectKey != null && anyObjectKey.equals(relationship.getRightEnd().getKey()); } }); }
From source file:org.apache.syncope.core.persistence.jpa.entity.user.JPAUser.java
@Override public UMembership getMembership(final Long groupKey) { return CollectionUtils.find(getMemberships(), new Predicate<UMembership>() { @Override// w ww . j ava 2 s . c o m public boolean evaluate(final UMembership membership) { return groupKey != null && groupKey.equals(membership.getRightEnd().getKey()); } }); }