use of org.structr.core.graph.NodeService in project structr by structr.
the class Services method command.
/**
* Creates and returns a command of the given <code>type</code>. If a command is
* found, the corresponding service will be discovered and activated.
*
* @param <T>
* @param securityContext
* @param commandType the runtime type of the desired command
* @return the command
*/
public <T extends Command> T command(final SecurityContext securityContext, final Class<T> commandType) {
try {
final T command = commandType.newInstance();
final Class serviceClass = command.getServiceClass();
// inject security context first
command.setArgument("securityContext", securityContext);
if ((serviceClass != null) && configuredServiceClasses.contains(serviceClass.getSimpleName())) {
// search for already running service..
Service service = serviceCache.get(serviceClass);
if (service == null) {
// start service
startService(serviceClass);
// reload service
service = serviceCache.get(serviceClass);
if (serviceClass.equals(NodeService.class)) {
logger.debug("(Re-)Started NodeService, (re-)compiling dynamic schema");
SchemaService.reloadSchema(new ErrorBuffer(), null);
}
}
if (service != null) {
logger.debug("Initializing command ", commandType.getName());
service.injectArguments(command);
}
}
command.initialized();
return command;
} catch (Throwable t) {
logger.error("Exception while creating command {}", commandType.getName());
}
return null;
}
use of org.structr.core.graph.NodeService in project structr by structr.
the class Property method index.
@Override
public void index(final GraphObject entity, final Object value) {
if (entity instanceof AbstractNode) {
final NodeService nodeService = Services.getInstance().getService(NodeService.class);
final AbstractNode node = (AbstractNode) entity;
final Node dbNode = node.getNode();
final Index<Node> index = nodeService.getNodeIndex();
if (index != null) {
try {
index.remove(dbNode, dbName);
if (value != null || isIndexedWhenEmpty()) {
index.add(dbNode, dbName, value, valueType());
}
} catch (Throwable t) {
logger.info("Unable to index property with dbName {} and value {} of type {} on {}: {}", new Object[] { dbName, value, this.getClass().getSimpleName(), entity, t });
logger.warn("", t);
}
}
} else if (entity instanceof AbstractRelationship) {
final NodeService nodeService = Services.getInstance().getService(NodeService.class);
final AbstractRelationship rel = (AbstractRelationship) entity;
final Relationship dbRel = rel.getRelationship();
final Index<Relationship> index = nodeService.getRelationshipIndex();
if (index != null) {
try {
index.remove(dbRel, dbName);
if (value != null || isIndexedWhenEmpty()) {
index.add(dbRel, dbName, value, valueType());
}
} catch (Throwable t) {
logger.info("Unable to index property with dbName {} and value {} of type {} on {}: {}", new Object[] { dbName, value, this.getClass().getSimpleName(), entity, t });
}
}
}
}
Aggregations