use of org.structr.core.property.PropertyMap in project structr by structr.
the class AbstractRelationship method getDynamicProperties.
public PropertyMap getDynamicProperties() {
final PropertyMap propertyMap = new PropertyMap();
final Class type = getClass();
for (final PropertyKey key : StructrApp.getConfiguration().getPropertySet(type, PropertyView.All)) {
// include all dynamic keys in definition
if (key.isDynamic() || key.isCMISProperty()) {
// only include primitives here
final PropertyType dataType = key.getDataType();
if (dataType != null) {
propertyMap.put(key, getProperty(key));
}
}
}
return propertyMap;
}
use of org.structr.core.property.PropertyMap in project structr by structr.
the class AbstractRelationship method setSourceNodeId.
@Override
public final void setSourceNodeId(final String sourceNodeId) throws FrameworkException {
// Do nothing if new id equals old
if (getSourceNodeId().equals(sourceNodeId)) {
return;
}
final App app = StructrApp.getInstance(securityContext);
final NodeInterface newStartNode = app.getNodeById(sourceNodeId);
final NodeInterface endNode = getTargetNode();
final Class relationType = getClass();
final PropertyMap _props = getProperties();
final String type = this.getClass().getSimpleName();
if (newStartNode == null) {
throw new FrameworkException(404, "Node with ID " + sourceNodeId + " not found", new IdNotFoundToken(type, sourceNodeId));
}
// delete this as the new rel will be the container afterwards
app.delete(this);
// create new relationship
app.create(newStartNode, endNode, relationType, _props);
}
use of org.structr.core.property.PropertyMap in project structr by structr.
the class AbstractRelationship method setTargetNodeId.
@Override
public final void setTargetNodeId(final String targetNodeId) throws FrameworkException {
// Do nothing if new id equals old
if (getTargetNodeId().equals(targetNodeId)) {
return;
}
final App app = StructrApp.getInstance(securityContext);
final NodeInterface newTargetNode = app.getNodeById(targetNodeId);
final NodeInterface startNode = getSourceNode();
final Class relationType = getClass();
final PropertyMap _props = getProperties();
final String type = this.getClass().getSimpleName();
if (newTargetNode == null) {
throw new FrameworkException(404, "Node with ID " + targetNodeId + " not found", new IdNotFoundToken(type, targetNodeId));
}
// delete this as the new rel will be the container afterwards
app.delete(this);
// create new relationship and store here
app.create(startNode, newTargetNode, relationType, _props);
}
use of org.structr.core.property.PropertyMap in project structr by structr.
the class SchemaRelationshipNode method onModification.
@Override
public void onModification(SecurityContext securityContext, final ErrorBuffer errorBuffer, final ModificationQueue modificationQueue) throws FrameworkException {
super.onModification(securityContext, errorBuffer, modificationQueue);
checkClassName();
checkAndRenameSourceAndTargetJsonNames();
final PropertyMap map = new PropertyMap();
// store old property names
map.put(previousSourceJsonName, getProperty(sourceJsonName));
map.put(previousTargetJsonName, getProperty(targetJsonName));
setProperties(securityContext, map);
// register transaction post processing that recreates the schema information
TransactionCommand.postProcess("reloadSchema", new ReloadSchema());
}
use of org.structr.core.property.PropertyMap in project structr by structr.
the class ManyEndpoint method set.
@Override
public Object set(final SecurityContext securityContext, final NodeInterface sourceNode, final Iterable<T> collection) throws FrameworkException {
final App app = StructrApp.getInstance(securityContext);
final List<Relation> createdRelationships = new LinkedList<>();
final PropertyMap properties = new PropertyMap();
final T actualSourceNode = (T) unwrap(securityContext, relation.getClass(), sourceNode, properties);
final Set<T> toBeDeleted = new LinkedHashSet<>(Iterables.toList(get(securityContext, actualSourceNode, null)));
final Set<T> toBeCreated = new LinkedHashSet<>();
if (collection != null) {
Iterables.addAll(toBeCreated, collection);
}
// create intersection of both sets
final Set<T> intersection = new HashSet<>(toBeCreated);
intersection.retainAll(toBeDeleted);
// intersection needs no change
toBeCreated.removeAll(intersection);
toBeDeleted.removeAll(intersection);
if (actualSourceNode != null) {
// remove existing relationships
for (T targetNode : toBeDeleted) {
for (Iterator<AbstractRelationship> it = actualSourceNode.getOutgoingRelationships(relation.getClass()).iterator(); it.hasNext(); ) {
final AbstractRelationship rel = it.next();
if (actualSourceNode.equals(targetNode)) {
logger.warn("Preventing deletion of self relationship {}-[{}]->{}. If you experience issue with this, please report to team@structr.com.", new Object[] { actualSourceNode, rel.getRelType(), targetNode });
// skip self relationships
continue;
}
if (rel.getTargetNode().equals(targetNode)) {
app.delete(rel);
}
}
}
// create new relationships
for (T targetNode : toBeCreated) {
if (targetNode != null) {
properties.clear();
final NodeInterface actualTargetNode = (NodeInterface) unwrap(securityContext, relation.getClass(), targetNode, properties);
relation.ensureCardinality(securityContext, actualSourceNode, actualTargetNode);
final PropertyMap notionProperties = getNotionProperties(securityContext, relation.getClass(), actualSourceNode.getName() + relation.name() + actualTargetNode.getName());
if (notionProperties != null) {
properties.putAll(notionProperties);
}
createdRelationships.add(app.create(actualSourceNode, actualTargetNode, relation.getClass(), properties));
}
}
}
return createdRelationships;
}
Aggregations