use of org.structr.core.entity.AbstractRelationship in project structr by structr.
the class AbstractPrimitiveProperty method setProperty.
@Override
public Object setProperty(final SecurityContext securityContext, final GraphObject obj, final T value) throws FrameworkException {
final PropertyConverter converter = databaseConverter(securityContext, PropertyMap.unwrap(obj));
Object convertedValue = value;
if (converter != null) {
convertedValue = converter.convert(value);
}
// use transformators from property
for (final String fqcn : transformators) {
// first test, use caching here later..
final Transformer transformator = getTransformator(fqcn);
if (transformator != null) {
convertedValue = transformator.setProperty(PropertyMap.unwrap(obj), this, convertedValue);
}
}
final PropertyContainer propertyContainer = obj.getPropertyContainer();
if (propertyContainer != null) {
if (!TransactionCommand.inTransaction()) {
throw new NotInTransactionException("setProperty outside of transaction");
}
boolean internalSystemPropertiesUnlocked = (obj instanceof CreationContainer);
// collect modified properties
if (obj instanceof AbstractNode) {
if (!unvalidated) {
TransactionCommand.nodeModified(securityContext.getCachedUser(), (AbstractNode) obj, AbstractPrimitiveProperty.this, propertyContainer.hasProperty(dbName()) ? propertyContainer.getProperty(dbName()) : null, value);
}
internalSystemPropertiesUnlocked = ((AbstractNode) obj).internalSystemPropertiesUnlocked;
} else if (obj instanceof AbstractRelationship) {
if (!unvalidated) {
TransactionCommand.relationshipModified(securityContext.getCachedUser(), (AbstractRelationship) obj, AbstractPrimitiveProperty.this, propertyContainer.hasProperty(dbName()) ? propertyContainer.getProperty(dbName()) : null, value);
}
internalSystemPropertiesUnlocked = ((AbstractRelationship) obj).internalSystemPropertiesUnlocked;
}
// catch all sorts of errors and wrap them in a FrameworkException
try {
// save space
if (convertedValue == null) {
propertyContainer.removeProperty(dbName());
} else {
if (!isSystemInternal() || internalSystemPropertiesUnlocked) {
propertyContainer.setProperty(dbName(), convertedValue);
} else {
logger.warn("Tried to set internal system property {} to {}. Action was denied.", new Object[] { dbName(), convertedValue });
}
}
updateAccessInformation(securityContext, propertyContainer);
} catch (final RetryException rex) {
// don't catch RetryException here
throw rex;
} catch (Throwable t) {
// throw FrameworkException with the given cause
final FrameworkException fex = new FrameworkException(500, "Unable to set property " + jsonName() + " on entity with ID " + obj.getUuid() + ": " + t.toString());
fex.initCause(t);
throw fex;
}
if (isIndexed()) {
// work
if (!isPassivelyIndexed()) {
index(obj, convertedValue);
}
}
}
return null;
}
use of org.structr.core.entity.AbstractRelationship in project structr by structr.
the class GetOutgoingRelationshipsFunction method apply.
@Override
public Object apply(final ActionContext ctx, final Object caller, final Object[] sources) throws FrameworkException {
final List<AbstractRelationship> list = new ArrayList<>();
if (arrayHasMinLengthAndMaxLengthAndAllElementsNotNull(sources, 2, 3)) {
final Object source = sources[0];
final Object target = sources[1];
AbstractNode sourceNode = null;
AbstractNode targetNode = null;
if (source instanceof AbstractNode && target instanceof AbstractNode) {
sourceNode = (AbstractNode) source;
targetNode = (AbstractNode) target;
} else {
logger.warn("Error: entities are not nodes. Parameters: {}", getParametersAsString(sources));
return "Error: entities are not nodes.";
}
if (sources.length == 2) {
for (final AbstractRelationship rel : sourceNode.getOutgoingRelationships()) {
final NodeInterface s = rel.getSourceNode();
final NodeInterface t = rel.getTargetNode();
// We need to check if current user can see source and target node which is often not the case for OWNS or SECURITY rels
if (s != null && t != null && s.equals(sourceNode) && t.equals(targetNode)) {
list.add(rel);
}
}
} else if (sources.length == 3) {
// dont try to create the relClass because we would need to do that both ways!!! otherwise it just fails if the nodes are in the "wrong" order (see tests:890f)
final String relType = (String) sources[2];
for (final AbstractRelationship rel : sourceNode.getOutgoingRelationships()) {
final NodeInterface s = rel.getSourceNode();
final NodeInterface t = rel.getTargetNode();
// We need to check if current user can see source and target node which is often not the case for OWNS or SECURITY rels
if (s != null && t != null && rel.getRelType().name().equals(relType) && s.equals(sourceNode) && t.equals(targetNode)) {
list.add(rel);
}
}
}
} else {
logParameterError(caller, sources, ctx.isJavaScriptContext());
}
return list;
}
use of org.structr.core.entity.AbstractRelationship in project structr by structr.
the class GetRelationshipsFunction method apply.
@Override
public Object apply(final ActionContext ctx, final Object caller, final Object[] sources) throws FrameworkException {
final List<AbstractRelationship> list = new ArrayList<>();
if (arrayHasMinLengthAndMaxLengthAndAllElementsNotNull(sources, 2, 3)) {
final Object source = sources[0];
final Object target = sources[1];
NodeInterface sourceNode = null;
NodeInterface targetNode = null;
if (source instanceof NodeInterface && target instanceof NodeInterface) {
sourceNode = (NodeInterface) source;
targetNode = (NodeInterface) target;
} else {
logger.warn("Error: entities are not nodes. Parameters: {}", getParametersAsString(sources));
return "Error: Entities are not nodes.";
}
if (sources.length == 2) {
for (final AbstractRelationship rel : sourceNode.getRelationships()) {
final NodeInterface s = rel.getSourceNode();
final NodeInterface t = rel.getTargetNode();
// We need to check if current user can see source and target node which is often not the case for OWNS or SECURITY rels
if (s != null && t != null && ((s.equals(sourceNode) && t.equals(targetNode)) || (s.equals(targetNode) && t.equals(sourceNode)))) {
list.add(rel);
}
}
} else if (sources.length == 3) {
// dont try to create the relClass because we would need to do that both ways!!! otherwise it just fails if the nodes are in the "wrong" order (see tests:890f)
final String relType = (String) sources[2];
for (final AbstractRelationship rel : sourceNode.getRelationships()) {
final NodeInterface s = rel.getSourceNode();
final NodeInterface t = rel.getTargetNode();
// We need to check if current user can see source and target node which is often not the case for OWNS or SECURITY rels
if (s != null && t != null && rel.getRelType().name().equals(relType) && ((s.equals(sourceNode) && t.equals(targetNode)) || (s.equals(targetNode) && t.equals(sourceNode)))) {
list.add(rel);
}
}
}
} else {
logParameterError(caller, sources, ctx.isJavaScriptContext());
}
return list;
}
use of org.structr.core.entity.AbstractRelationship in project structr by structr.
the class HasRelationshipFunction method apply.
@Override
public Object apply(final ActionContext ctx, final Object caller, final Object[] sources) throws FrameworkException {
if (arrayHasMinLengthAndMaxLengthAndAllElementsNotNull(sources, 2, 3)) {
final Object source = sources[0];
final Object target = sources[1];
AbstractNode sourceNode = null;
AbstractNode targetNode = null;
if (source instanceof AbstractNode && target instanceof AbstractNode) {
sourceNode = (AbstractNode) source;
targetNode = (AbstractNode) target;
} else {
logger.warn("Error: entities are not nodes. Parameters: {}", getParametersAsString(sources));
return "Error: entities are not nodes.";
}
if (sources.length == 2) {
for (final AbstractRelationship rel : sourceNode.getRelationships()) {
final NodeInterface s = rel.getSourceNode();
final NodeInterface t = rel.getTargetNode();
// We need to check if current user can see source and target node which is often not the case for OWNS or SECURITY rels
if (s != null & t != null && ((s.equals(sourceNode) && t.equals(targetNode)) || (s.equals(targetNode) && t.equals(sourceNode)))) {
return true;
}
}
} else if (sources.length == 3) {
// dont try to create the relClass because we would need to do that both ways!!! otherwise it just fails if the nodes are in the "wrong" order (see tests:890f)
final String relType = (String) sources[2];
for (final AbstractRelationship rel : sourceNode.getRelationships()) {
final NodeInterface s = rel.getSourceNode();
final NodeInterface t = rel.getTargetNode();
// We need to check if current user can see source and target node which is often not the case for OWNS or SECURITY rels
if (s != null & t != null && rel.getRelType().name().equals(relType) && ((s.equals(sourceNode) && t.equals(targetNode)) || (s.equals(targetNode) && t.equals(sourceNode)))) {
return true;
}
}
}
} else {
logParameterError(caller, sources, ctx.isJavaScriptContext());
}
return false;
}
use of org.structr.core.entity.AbstractRelationship in project structr by structr.
the class BasicTest method cascadeRel.
// ----- private methods -----
private AbstractRelationship cascadeRel(final Class type1, final Class type2, final int cascadeDeleteFlag) throws FrameworkException {
try (final Tx tx = app.tx()) {
NodeInterface start = createTestNode(type1);
NodeInterface end = createTestNode(type2);
AbstractRelationship rel = createTestRelationship(start, end, NodeHasLocation.class);
rel.setProperty(AbstractRelationship.cascadeDelete, cascadeDeleteFlag);
tx.success();
return rel;
}
}
Aggregations