use of org.structr.core.graph.NodeInterface in project structr by structr.
the class StructrApiModuleTest method createTestRelationships.
protected <T extends Relation> List<T> createTestRelationships(final Class<T> relType, final int number) throws FrameworkException {
List<GenericNode> nodes = createTestNodes(GenericNode.class, 2);
final NodeInterface startNode = nodes.get(0);
final NodeInterface endNode = nodes.get(1);
try (final Tx tx = app.tx()) {
List<T> rels = new LinkedList<>();
for (int i = 0; i < number; i++) {
rels.add((T) app.create(startNode, endNode, relType));
}
tx.success();
return rels;
}
}
use of org.structr.core.graph.NodeInterface in project structr by structr.
the class PushTransmission method doRemote.
@Override
public Boolean doRemote(final CloudConnection client) throws IOException, FrameworkException {
// reset sequence number
sequenceNumber = 0;
// send child nodes when recursive sending is requested
final Set<NodeInterface> nodes = exportSet.getNodes();
for (final NodeInterface n : nodes) {
if (n instanceof File) {
sendFile(client, (File) n, CloudService.CHUNK_SIZE);
} else {
client.send(new NodeDataContainer(n, sequenceNumber++));
}
}
// send relationships
Set<RelationshipInterface> rels = exportSet.getRelationships();
for (RelationshipInterface r : rels) {
if (nodes.contains(r.getSourceNode()) && nodes.contains(r.getTargetNode())) {
client.send(new RelationshipDataContainer(r, sequenceNumber++));
} else {
System.out.println("NOT sending relationship data container " + r + " because source or target node are not in the export set.");
}
}
client.send(new End());
// wait for end of transmission
client.waitForTransmission();
return true;
}
use of org.structr.core.graph.NodeInterface in project structr by structr.
the class PullFile method onRequest.
@Override
public void onRequest(CloudConnection serverConnection) throws IOException, FrameworkException {
final Object value = serverConnection.getValue(key + "Nodes");
if (value instanceof List) {
final List<NodeInterface> nodes = (List<NodeInterface>) value;
final NodeInterface node = nodes.get(nodeIndex);
final File file = (File) node;
serverConnection.send(new FileNodeDataContainer(file));
}
}
use of org.structr.core.graph.NodeInterface in project structr by structr.
the class PullNode method onRequest.
@Override
public void onRequest(CloudConnection serverConnection) throws IOException, FrameworkException {
final Object value = serverConnection.getValue(key + "Nodes");
if (value instanceof List) {
final List<NodeInterface> nodes = (List<NodeInterface>) value;
final NodeInterface node = nodes.get(nodeIndex);
if (node instanceof File) {
PushTransmission.sendFile(serverConnection, (File) node, CloudService.CHUNK_SIZE);
} else {
serverConnection.send(new NodeDataContainer(node, nodeIndex));
}
}
}
use of org.structr.core.graph.NodeInterface in project structr by structr.
the class OWLInstance method resolveProperties.
public void resolveProperties() throws FrameworkException {
if (instance != null && type != null) {
OWLParserv2.logger.println("#################################################################################################");
OWLParserv2.logger.println("Resolving properties of " + type.getStructrName(true) + ": " + getId());
final App app = StructrApp.getInstance();
final ConfigurationProvider config = StructrApp.getConfiguration();
final Class baseNodeType = config.getNodeEntityClass("BaseNode");
final Class localizedNameType = config.getNodeEntityClass("LocalizedName");
final PropertyKey namesKey = StructrApp.key(baseNodeType, "names");
final PropertyKey langKey = StructrApp.key(localizedNameType, "locale");
if (localizedNameType != null && namesKey != null) {
// set name(s)
final List<NodeInterface> localizedNames = new LinkedList<>();
for (final Name name : names) {
localizedNames.add(app.create(localizedNameType, new NodeAttribute<>(AbstractNode.name, name.name), new NodeAttribute<>(langKey, name.lang)));
}
instance.setProperty(namesKey, localizedNames);
}
// extract creation and modification dates
try {
setProperty(nodeType, instance, "createdAt", isoFormat.format(dateFormat.parse(createdAt)));
} catch (Throwable ignore) {
}
try {
setProperty(nodeType, instance, "modifiedAt", isoFormat.format(dateFormat.parse(modifiedAt)));
} catch (Throwable ignore) {
}
for (final OWLProperty property : type.getAllProperties()) {
final String rawPropertyName = property.getId().getFragment();
final String cleanPropertyName = property.getFragmentName(false);
if (property.multipleOccurrences()) {
final NodeList values = getElements(getElement(), rawPropertyName);
final int len = values.getLength();
final ArrayList<String> array = new ArrayList<>();
for (int i = 0; i < len; i++) {
final Object value = getValue(values.item(i));
if (value != null) {
array.add(value.toString());
}
}
final String[] value = array.toArray(new String[0]);
OWLParserv2.logger.println(cleanPropertyName + " = " + value);
setProperty(nodeType, instance, cleanPropertyName, value);
} else {
Object value = getValue(getFirstElement(getElement(), rawPropertyName));
OWLParserv2.logger.println(cleanPropertyName + " = " + value);
setProperty(nodeType, instance, cleanPropertyName, property.convertValue(value));
}
}
}
}
Aggregations