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;
}
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();
}
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);
}
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;
}
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);
}
Aggregations