Search in sources :

Example 1 with NodeService

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;
}
Also used : ErrorBuffer(org.structr.common.error.ErrorBuffer) DatabaseService(org.structr.api.DatabaseService) NodeService(org.structr.core.graph.NodeService) ExecutorService(java.util.concurrent.ExecutorService) Service(org.structr.api.service.Service) RunnableService(org.structr.api.service.RunnableService) SchemaService(org.structr.schema.SchemaService)

Example 2 with NodeService

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 });
            }
        }
    }
}
Also used : AbstractNode(org.structr.core.entity.AbstractNode) NodeService(org.structr.core.graph.NodeService) Node(org.structr.api.graph.Node) AbstractNode(org.structr.core.entity.AbstractNode) AbstractRelationship(org.structr.core.entity.AbstractRelationship) AbstractRelationship(org.structr.core.entity.AbstractRelationship) Relationship(org.structr.api.graph.Relationship) GraphObject(org.structr.core.GraphObject) AbstractCypherIndex(org.structr.bolt.index.AbstractCypherIndex) Index(org.structr.api.index.Index)

Aggregations

NodeService (org.structr.core.graph.NodeService)2 ExecutorService (java.util.concurrent.ExecutorService)1 DatabaseService (org.structr.api.DatabaseService)1 Node (org.structr.api.graph.Node)1 Relationship (org.structr.api.graph.Relationship)1 Index (org.structr.api.index.Index)1 RunnableService (org.structr.api.service.RunnableService)1 Service (org.structr.api.service.Service)1 AbstractCypherIndex (org.structr.bolt.index.AbstractCypherIndex)1 ErrorBuffer (org.structr.common.error.ErrorBuffer)1 GraphObject (org.structr.core.GraphObject)1 AbstractNode (org.structr.core.entity.AbstractNode)1 AbstractRelationship (org.structr.core.entity.AbstractRelationship)1 SchemaService (org.structr.schema.SchemaService)1