use of org.structr.common.error.UniqueToken in project structr by structr.
the class ValidationHelper method isValidGloballyUniqueProperty.
public static synchronized boolean isValidGloballyUniqueProperty(final GraphObject object, final PropertyKey key, final ErrorBuffer errorBuffer) {
if (key != null) {
final Object value = object.getProperty(key);
List<? extends GraphObject> result = null;
try {
if (object instanceof NodeInterface) {
result = StructrApp.getInstance().nodeQuery(NodeInterface.class).and(key, value).disableSorting().getAsList();
} else if (object instanceof RelationshipInterface) {
result = StructrApp.getInstance().relationshipQuery(RelationshipInterface.class).and(key, value).disableSorting().getAsList();
} else {
logger.error("GraphObject is neither NodeInterface nor RelationshipInterface");
return false;
}
} catch (FrameworkException fex) {
logger.warn("Unable to fetch list of nodes for uniqueness check", fex);
// handle error
}
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 UniqueToken(object.getType(), key, object.getUuid()));
// error!
return false;
}
}
}
}
// no error
return true;
}
use of org.structr.common.error.UniqueToken in project structr by structr.
the class AbstractFile method validatePath.
static boolean validatePath(final AbstractFile thisFile, final SecurityContext securityContext, final ErrorBuffer errorBuffer) throws FrameworkException {
final PropertyKey<String> pathKey = StructrApp.key(AbstractFile.class, "path");
final String filePath = thisFile.getProperty(pathKey);
if (filePath != null) {
final List<AbstractFile> files = StructrApp.getInstance().nodeQuery(AbstractFile.class).and(pathKey, filePath).getAsList();
for (final AbstractFile file : files) {
if (!file.getUuid().equals(thisFile.getUuid())) {
if (errorBuffer != null) {
final UniqueToken token = new UniqueToken(AbstractFile.class.getSimpleName(), pathKey, file.getUuid());
token.setValue(filePath);
errorBuffer.add(token);
}
return false;
}
}
}
return true;
}
use of org.structr.common.error.UniqueToken in project structr by structr.
the class ValidationHelper method isValidUniqueProperty.
public static synchronized boolean isValidUniqueProperty(final GraphObject object, final PropertyKey key, final ErrorBuffer errorBuffer) {
if (key != null) {
final Object value = object.getProperty(key);
if (value != null) {
// validation will only be executed for non-null values
List<GraphObject> result = null;
// use declaring class for inheritance-aware uniqueness
Class type = key.getDeclaringClass();
if (type == null || (AbstractNode.name.equals(key) && NodeInterface.class.equals(type))) {
// fallback: object type
type = object.getClass();
}
try {
if (object instanceof NodeInterface) {
result = StructrApp.getInstance().nodeQuery(type).and(key, value).getAsList();
} else {
result = StructrApp.getInstance().relationshipQuery(type).and(key, value).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 UniqueToken(object.getType(), key, object.getUuid()));
// error!
return false;
}
}
}
}
}
// no error
return true;
}
Aggregations