use of org.structr.core.property.PropertyKey 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;
}
use of org.structr.core.property.PropertyKey in project structr by structr.
the class CompoundToken method toJSON.
@Override
public JsonObject toJSON() {
final JsonObject token = new JsonObject();
final JsonArray array = new JsonArray();
// add all keys that form the compound index
for (final PropertyKey key : keys) {
array.add(new JsonPrimitive(key.jsonName()));
}
token.add("type", getStringOrNull(getType()));
token.add("properties", array);
token.add("token", getStringOrNull(getToken()));
// optional
addIfNonNull(token, "detail", getObjectOrNull(getDetail()));
return token;
}
use of org.structr.core.property.PropertyKey in project structr by structr.
the class GraphObject method setProperties.
/**
* Sets the given properties.
*
* @param securityContext
* @param properties
* @throws FrameworkException
*/
default void setProperties(final SecurityContext securityContext, final PropertyMap properties) throws FrameworkException {
final CreationContainer container = new CreationContainer(this);
boolean atLeastOnePropertyChanged = false;
for (final Entry<PropertyKey, Object> attr : properties.entrySet()) {
final PropertyKey key = attr.getKey();
final Object value = attr.getValue();
if (key.indexable(value)) {
final Object oldValue = getProperty(key);
if (!value.equals(oldValue)) {
atLeastOnePropertyChanged = true;
// bulk set possible, store in container
key.setProperty(securityContext, container, value);
if (isNode()) {
if (!key.isUnvalidated()) {
TransactionCommand.nodeModified(securityContext.getCachedUser(), (AbstractNode) this, key, getProperty(key), value);
}
if (key instanceof TypeProperty) {
if (this instanceof NodeInterface) {
final Class type = StructrApp.getConfiguration().getNodeEntityClass((String) value);
TypeProperty.updateLabels(StructrApp.getInstance().getDatabaseService(), (NodeInterface) this, type, true);
}
}
} else if (isRelationship()) {
if (!key.isUnvalidated()) {
TransactionCommand.relationshipModified(securityContext.getCachedUser(), (AbstractRelationship) this, key, getProperty(key), value);
}
if (key instanceof TypeProperty) {
if (this instanceof NodeInterface) {
final Class type = StructrApp.getConfiguration().getNodeEntityClass((String) value);
TypeProperty.updateLabels(StructrApp.getInstance().getDatabaseService(), (NodeInterface) this, type, true);
}
}
}
}
} else {
// bulk set NOT possible, set on entity
if (key.isSystemInternal()) {
unlockSystemPropertiesOnce();
}
setProperty(key, value);
}
}
if (atLeastOnePropertyChanged) {
// set primitive values directly for better performance
getPropertyContainer().setProperties(container.getData());
}
}
use of org.structr.core.property.PropertyKey in project structr by structr.
the class GraphObjectMap method toMap.
public Map<String, Object> toMap() {
final Map<String, Object> newMap = new LinkedHashMap<>();
for (final Entry<PropertyKey, Object> entry : properties.entrySet()) {
final PropertyKey key = entry.getKey();
final Object value = entry.getValue();
if (value instanceof GraphObjectMap) {
newMap.put(key.jsonName(), ((GraphObjectMap) value).toMap());
} else {
newMap.put(key.jsonName(), value);
}
}
return newMap;
}
use of org.structr.core.property.PropertyKey in project structr by structr.
the class PathResolvingComparator method resolve.
// ----- private methods -----
private Comparable resolve(final GraphObject obj, final String path) {
final ConfigurationProvider config = StructrApp.getConfiguration();
final String[] parts = path.split("[\\.]+");
GraphObject current = obj;
int pos = 0;
for (final String part : parts) {
final Class type = current.getEntityType();
final PropertyKey key = config.getPropertyKeyForJSONName(type, part, false);
if (key == null) {
logger.warn("Unknown key {} while resolving path {} for sorting.", part, path);
return null;
}
final Object value = current.getProperty(key);
if (value != null) {
// last part of path?
if (++pos == parts.length) {
if (value instanceof Comparable) {
return (Comparable) value;
}
logger.warn("Path evaluation result of component {} of type {} in {} cannot be used for sorting.", part, value.getClass().getSimpleName(), path);
return null;
}
if (value instanceof GraphObject) {
current = (GraphObject) value;
} else {
logger.warn("Path component {} of type {} in {} cannot be evaluated further.", part, value.getClass().getSimpleName(), path);
return null;
}
}
}
return null;
}
Aggregations