use of org.structr.core.entity.AbstractNode in project structr by structr.
the class IdRequestParameterGraphDataSource method getData.
@Override
public Iterable<GraphObject> getData(final RenderContext renderContext, final DOMNode referenceNode) throws FrameworkException {
final SecurityContext securityContext = renderContext.getSecurityContext();
if (securityContext != null && securityContext.getRequest() != null) {
String nodeId = securityContext.getRequest().getParameter(parameterName);
if (nodeId != null) {
AbstractNode node = (AbstractNode) StructrApp.getInstance(securityContext).getNodeById(nodeId);
if (node != null) {
List<GraphObject> graphData = new LinkedList<>();
graphData.add(node);
return graphData;
}
}
}
return null;
}
use of org.structr.core.entity.AbstractNode 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.AbstractNode in project structr by structr.
the class AggregatorProperty method getProperty.
@Override
public List<T> getProperty(SecurityContext securityContext, GraphObject currentObject, boolean applyConverter, final Predicate<GraphObject> predicate) {
if (currentObject != null && currentObject instanceof AbstractNode) {
NodeInterface sourceNode = (NodeInterface) currentObject;
List<NodeInterface> nodes = new LinkedList<>();
// 1. step: add all nodes
for (Property property : aggregation.getAggregationProperties()) {
Object obj = sourceNode.getProperty(property);
if (obj != null && obj instanceof Collection) {
nodes.addAll((Collection) obj);
}
}
// 2. step: sort nodes according to comparator
Comparator<NodeInterface> comparator = aggregation.getComparator();
if (nodes.isEmpty() && comparator != null) {
Collections.sort(nodes, comparator);
}
// 3. step: apply notions depending on type
List results = new LinkedList();
try {
for (NodeInterface node : nodes) {
Notion notion = aggregation.getNotionForType(node.getClass());
if (notion != null) {
results.add(notion.getAdapterForGetter(securityContext).adapt(node));
} else {
results.add(node);
}
}
} catch (Throwable t) {
logger.warn("", t);
}
return results;
}
return Collections.emptyList();
}
use of org.structr.core.entity.AbstractNode in project structr by structr.
the class CollectionNotionProperty method getSearchAttribute.
@Override
public SearchAttribute getSearchAttribute(SecurityContext securityContext, Occurrence occur, List<T> searchValues, boolean exactMatch, final Query query) {
final Predicate<GraphObject> predicate = query != null ? query.toPredicate() : null;
final SourceSearchAttribute attr = new SourceSearchAttribute(occur);
final Set<GraphObject> intersectionResult = new LinkedHashSet<>();
boolean alreadyAdded = false;
try {
if (searchValues != null && !searchValues.isEmpty()) {
final PropertyKey key = notion.getPrimaryPropertyKey();
final PropertyConverter inputConverter = key.inputConverter(securityContext);
final List<Object> transformedValues = new LinkedList<>();
boolean allBlank = true;
// transform search values using input convert of notion property
for (T searchValue : searchValues) {
if (inputConverter != null) {
transformedValues.add(inputConverter.convert(searchValue));
} else {
transformedValues.add(searchValue);
}
}
// iterate over transformed values
for (Object searchValue : transformedValues) {
// check if the list contains non-empty search values
if (StringUtils.isBlank(searchValue.toString())) {
continue;
} else {
allBlank = false;
}
final App app = StructrApp.getInstance(securityContext);
if (exactMatch) {
Result<AbstractNode> result = app.nodeQuery(collectionProperty.relatedType()).and(notion.getPrimaryPropertyKey(), searchValue).getResult();
for (AbstractNode node : result.getResults()) {
switch(occur) {
case REQUIRED:
if (!alreadyAdded) {
// the first result is the basis of all subsequent intersections
intersectionResult.addAll(collectionProperty.getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
// the next additions are intersected with this one
alreadyAdded = true;
} else {
intersectionResult.retainAll(collectionProperty.getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
}
break;
case OPTIONAL:
intersectionResult.addAll(collectionProperty.getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
break;
case FORBIDDEN:
break;
}
}
} else {
Result<AbstractNode> result = app.nodeQuery(collectionProperty.relatedType()).and(notion.getPrimaryPropertyKey(), searchValue, false).getResult();
// loose search behaves differently, all results must be combined
for (AbstractNode node : result.getResults()) {
intersectionResult.addAll(collectionProperty.getRelatedNodesReverse(securityContext, node, declaringClass, predicate));
}
}
}
if (allBlank) {
// value in the given field
return new EmptySearchAttribute(this, Collections.emptyList());
} else {
attr.setResult(intersectionResult);
}
} else {
// value in the given field
return new EmptySearchAttribute(this, Collections.emptyList());
}
} catch (FrameworkException fex) {
logger.warn("", fex);
}
return attr;
}
use of org.structr.core.entity.AbstractNode in project structr by structr.
the class HyperRelationProperty method getProperty.
@Override
public List<T> getProperty(SecurityContext securityContext, GraphObject obj, boolean applyConverter, final Predicate<GraphObject> predicate) {
List<S> connectors = obj.getProperty(step1);
List<T> endNodes = new LinkedList<>();
if (connectors != null) {
for (AbstractNode node : connectors) {
endNodes.add(node.getProperty(step2));
}
}
return endNodes;
}
Aggregations