Search in sources :

Example 81 with PropertyMap

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;
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) PropertyType(org.apache.chemistry.opencmis.commons.enums.PropertyType) PropertyKey(org.structr.core.property.PropertyKey)

Example 82 with 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);
}
Also used : App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) PropertyMap(org.structr.core.property.PropertyMap) FrameworkException(org.structr.common.error.FrameworkException) IdNotFoundToken(org.structr.common.error.IdNotFoundToken) NodeInterface(org.structr.core.graph.NodeInterface)

Example 83 with PropertyMap

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);
}
Also used : App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) PropertyMap(org.structr.core.property.PropertyMap) FrameworkException(org.structr.common.error.FrameworkException) IdNotFoundToken(org.structr.common.error.IdNotFoundToken) NodeInterface(org.structr.core.graph.NodeInterface)

Example 84 with PropertyMap

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());
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) ReloadSchema(org.structr.schema.ReloadSchema)

Example 85 with PropertyMap

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;
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) LinkedHashSet(java.util.LinkedHashSet) PropertyMap(org.structr.core.property.PropertyMap) LinkedList(java.util.LinkedList) NodeInterface(org.structr.core.graph.NodeInterface) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

PropertyMap (org.structr.core.property.PropertyMap)233 FrameworkException (org.structr.common.error.FrameworkException)100 Tx (org.structr.core.graph.Tx)93 Test (org.junit.Test)60 App (org.structr.core.app.App)34 StructrApp (org.structr.core.app.StructrApp)34 PropertyKey (org.structr.core.property.PropertyKey)34 LinkedList (java.util.LinkedList)28 NodeInterface (org.structr.core.graph.NodeInterface)25 SchemaProperty (org.structr.core.entity.SchemaProperty)23 SecurityContext (org.structr.common.SecurityContext)22 StructrUiTest (org.structr.web.StructrUiTest)21 GraphObject (org.structr.core.GraphObject)20 Result (org.structr.core.Result)19 File (org.structr.web.entity.File)19 DOMNode (org.structr.web.entity.dom.DOMNode)19 TestOne (org.structr.core.entity.TestOne)17 AbstractNode (org.structr.core.entity.AbstractNode)16 Folder (org.structr.web.entity.Folder)15 Page (org.structr.web.entity.dom.Page)15