Search in sources :

Example 86 with PropertyMap

use of org.structr.core.property.PropertyMap in project structr by structr.

the class OneEndpoint method set.

@Override
public Object set(final SecurityContext securityContext, final NodeInterface sourceNode, final T targetNode) throws FrameworkException {
    final PropertyMap properties = new PropertyMap();
    final NodeInterface actualTargetNode = (NodeInterface) unwrap(securityContext, relation.getClass(), targetNode, properties);
    final T actualSourceNode = (T) unwrap(securityContext, relation.getClass(), sourceNode, properties);
    // let relation check multiplicity
    relation.ensureCardinality(securityContext, actualSourceNode, actualTargetNode);
    if (actualSourceNode != null && actualTargetNode != null) {
        final String storageKey = actualSourceNode.getName() + relation.name() + actualTargetNode.getName();
        final PropertyMap notionProperties = getNotionProperties(securityContext, relation.getClass(), storageKey);
        if (notionProperties != null) {
            properties.putAll(notionProperties);
        }
        // create new relationship
        return StructrApp.getInstance(securityContext).create(actualSourceNode, actualTargetNode, relation.getClass(), properties);
    }
    return null;
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) NodeInterface(org.structr.core.graph.NodeInterface)

Example 87 with PropertyMap

use of org.structr.core.property.PropertyMap in project structr by structr.

the class LinkedTreeNodeImpl method treeReplaceChild.

@Override
public void treeReplaceChild(final T newChild, final T oldChild) throws FrameworkException {
    // save old position
    int oldPosition = treeGetChildPosition(oldChild);
    // remove old node
    unlinkNodes(getChildLinkType(), (T) this, oldChild);
    // insert new node with position from old node
    PropertyMap properties = new PropertyMap();
    properties.put(getPositionProperty(), oldPosition);
    linkNodes(getChildLinkType(), (T) this, newChild, properties);
    // replace element in linked list as well
    listInsertBefore(oldChild, newChild);
    listRemove(oldChild);
    ensureCorrectChildPositions();
}
Also used : PropertyMap(org.structr.core.property.PropertyMap)

Example 88 with PropertyMap

use of org.structr.core.property.PropertyMap in project structr by structr.

the class StructrApp method create.

@Override
public <T extends NodeInterface> T create(final Class<T> type, final PropertyMap source) throws FrameworkException {
    if (type == null) {
        throw new FrameworkException(422, "Empty type (null). Please supply a valid class name in the type property.");
    }
    final CreateNodeCommand<T> command = command(CreateNodeCommand.class);
    final PropertyMap properties = new PropertyMap(source);
    String finalType = type.getSimpleName();
    // try to identify the actual type from input set (creation wouldn't work otherwise anyway)
    final String typeFromInput = properties.get(NodeInterface.type);
    if (typeFromInput != null) {
        Class actualType = StructrApp.getConfiguration().getNodeEntityClass(typeFromInput);
        if (actualType == null) {
            // overwrite type information when creating a node (adhere to type specified by resource!)
            properties.put(AbstractNode.type, type.getSimpleName());
        } else if (actualType.isInterface() || Modifier.isAbstract(actualType.getModifiers())) {
            throw new FrameworkException(422, "Invalid abstract type " + type.getSimpleName() + ", please supply a non-abstract class name in the type property");
        } else {
            finalType = actualType.getSimpleName();
        }
    }
    // set type
    properties.put(AbstractNode.type, finalType);
    return command.execute(properties);
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) FrameworkException(org.structr.common.error.FrameworkException)

Example 89 with PropertyMap

use of org.structr.core.property.PropertyMap in project structr by structr.

the class TextSearchModuleTest method createTestNodes.

protected <T extends AbstractNode> List<T> createTestNodes(final Class<T> type, final int number, final long delay) throws FrameworkException {
    try (final Tx tx = app.tx()) {
        final PropertyMap properties = new PropertyMap();
        final List<T> nodes = new LinkedList<>();
        properties.put(NodeInterface.visibleToAuthenticatedUsers, false);
        properties.put(NodeInterface.visibleToPublicUsers, false);
        properties.put(NodeInterface.deleted, false);
        properties.put(NodeInterface.hidden, false);
        for (int i = 0; i < number; i++) {
            nodes.add(app.create(type, properties));
            try {
                Thread.sleep(delay);
            } catch (InterruptedException ex) {
            }
        }
        tx.success();
        return nodes;
    } catch (Throwable t) {
        logger.warn("", t);
    }
    return null;
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) Tx(org.structr.core.graph.Tx) LinkedList(java.util.LinkedList)

Example 90 with PropertyMap

use of org.structr.core.property.PropertyMap in project structr by structr.

the class StructrPaymentModuleTest method createTestNode.

protected <T extends AbstractNode> T createTestNode(final Class<T> type, final String name) throws FrameworkException {
    final PropertyMap map = new PropertyMap();
    map.put(AbstractNode.name, name);
    return (T) createTestNode(type, map);
}
Also used : PropertyMap(org.structr.core.property.PropertyMap)

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