use of org.structr.common.error.CompoundToken in project structr by structr.
the class ValidationHelper method areValidCompoundUniqueProperties.
public static synchronized boolean areValidCompoundUniqueProperties(final GraphObject object, final ErrorBuffer errorBuffer, final PropertyKey... keys) {
if (keys != null && keys.length > 0) {
final PropertyMap properties = new PropertyMap();
List<GraphObject> result = null;
Class type = null;
for (final PropertyKey key : keys) {
properties.put(key, object.getProperty(key));
if (type != null) {
// set type on first iteration
type = key.getDeclaringClass();
}
}
if (type == null) {
// fallback: object type
type = object.getClass();
}
try {
if (object instanceof NodeInterface) {
result = StructrApp.getInstance().nodeQuery(type).and(properties).disableSorting().getAsList();
} else {
result = StructrApp.getInstance().relationshipQuery(type).and(properties).disableSorting().getAsList();
}
} catch (FrameworkException fex) {
logger.warn("", fex);
}
if (result != null) {
for (final GraphObject foundNode : result) {
if (foundNode.getId() != object.getId()) {
// validation is aborted when the first validation failure occurs, so
// we can assume that the object currently exmained is the first
// existing object, hence all others get the error message with the
// UUID of the first one.
errorBuffer.add(new CompoundToken(object.getType(), keys, object.getUuid()));
// error!
return false;
}
}
}
}
// no error
return true;
}
Aggregations