Skip to content

Commit

Permalink
One more generalization of uniqueness ensuring methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Sep 9, 2014
1 parent dbb1a29 commit 6114646
Showing 1 changed file with 22 additions and 8 deletions.
Expand Up @@ -515,6 +515,20 @@ public <T> boolean isUniquePropertyValue(ObjectType objectType, String propertyP
private <T> boolean isUniquePropertyValue(final ObjectType objectType, ItemPath propertyPath, T propertyValue, OperationResult result)
throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException,
SecurityViolationException {
List<? extends ObjectType> conflictingObjects = getObjectsInConflictOnPropertyValue(objectType, propertyPath, propertyValue, false, result);
return conflictingObjects.isEmpty();
}

public <O extends ObjectType, T> List<O> getObjectsInConflictOnPropertyValue(O objectType, String propertyPathString, T propertyValue, boolean getAllConflicting) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException {
Validate.notEmpty(propertyPathString, "Empty property path");
OperationResult result = getCurrentResult(MidpointFunctions.class.getName()+".getObjectsInConflictOnPropertyValue");
ItemPath propertyPath = new XPathHolder(propertyPathString).toItemPath();
return getObjectsInConflictOnPropertyValue(objectType, propertyPath, propertyValue, getAllConflicting, result);
}

private <O extends ObjectType, T> List<O> getObjectsInConflictOnPropertyValue(final O objectType, ItemPath propertyPath, T propertyValue, final boolean getAllConflicting, OperationResult result)
throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException,
SecurityViolationException {
Validate.notNull(objectType, "Null object");
Validate.notNull(propertyPath, "Null property path");
Validate.notNull(propertyValue, "Null property value");
Expand All @@ -525,30 +539,30 @@ private <T> boolean isUniquePropertyValue(final ObjectType objectType, ItemPath
LOGGER.trace("Determining uniqueness of property {} using query:\n{}", propertyPath, query.debugDump());
}

final Holder<Boolean> isUniqueHolder = new Holder<Boolean>(true);
ResultHandler<ObjectType> handler = new ResultHandler<ObjectType>() {
final List<O> conflictingObjects = new ArrayList<>();
ResultHandler<O> handler = new ResultHandler<O>() {
@Override
public boolean handle(PrismObject<ObjectType> object, OperationResult parentResult) {
public boolean handle(PrismObject<O> object, OperationResult parentResult) {
if (objectType.getOid() == null) {
// We have found a conflicting object
isUniqueHolder.setValue(false);
return false;
conflictingObjects.add(object.asObjectable());
return getAllConflicting;
} else {
if (objectType.getOid().equals(object.getOid())) {
// We have found ourselves. No conflict (yet). Just go on.
return true;
} else {
// We have found someone else. Conflict.
isUniqueHolder.setValue(false);
return false;
conflictingObjects.add(object.asObjectable());
return getAllConflicting;
}
}
}
};

modelObjectResolver.searchIterative((Class) objectType.getClass(), query, null, handler, result);

return isUniqueHolder.getValue();
return conflictingObjects;
}

public <T> boolean isUniqueAccountValue(ResourceType resourceType, ShadowType shadowType, String attributeName, T attributeValue) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException {
Expand Down

0 comments on commit 6114646

Please sign in to comment.