Search in sources :

Example 61 with SecurityContext

use of org.structr.common.SecurityContext in project structr by structr.

the class GetTypeInfoCommand method processMessage.

@Override
public void processMessage(final WebSocketMessage webSocketData) {
    final String type = (String) webSocketData.getNodeData().get("type");
    if (type == null) {
        logger.warn("Node type given not found");
        getWebSocket().send(MessageBuilder.status().code(400).build(), true);
    }
    final SecurityContext securityContext = getWebSocket().getSecurityContext();
    final App app = StructrApp.getInstance(securityContext);
    final SchemaNode typeNode;
    try {
        typeNode = app.nodeQuery(SchemaNode.class).andName(type).getFirst();
        if (typeNode != null) {
            webSocketData.setResult(Arrays.asList(typeNode));
            // send only over local connection (no broadcast)
            getWebSocket().send(webSocketData, true);
        }
    } catch (FrameworkException ex) {
        logger.error("", ex);
        getWebSocket().send(MessageBuilder.status().code(500).build(), true);
    }
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) SchemaNode(org.structr.core.entity.SchemaNode) FrameworkException(org.structr.common.error.FrameworkException) SecurityContext(org.structr.common.SecurityContext)

Example 62 with SecurityContext

use of org.structr.common.SecurityContext in project structr by structr.

the class ImportCommand method processMessage.

@Override
public void processMessage(final WebSocketMessage webSocketData) {
    final SecurityContext securityContext = getWebSocket().getSecurityContext();
    final Map<String, Object> properties = webSocketData.getNodeData();
    final String code = (String) properties.get("code");
    final String address = (String) properties.get("address");
    final String name = (String) properties.get("name");
    final boolean publicVisible = (Boolean) properties.get("publicVisible");
    final boolean authVisible = (Boolean) properties.get("authVisible");
    final boolean processDeploymentInfo = (Boolean) properties.get("processDeploymentInfo");
    try {
        final Importer pageImporter = new Importer(securityContext, code, address, name, publicVisible, authVisible);
        if (processDeploymentInfo) {
            pageImporter.setIsDeployment(true);
            pageImporter.setCommentHandler(new DeploymentCommentHandler());
        }
        final boolean parseOk = pageImporter.parse();
        if (parseOk) {
            if (address != null) {
                logger.info("Successfully parsed {}", address);
                getWebSocket().send(MessageBuilder.status().code(200).message("Successfully parsed address " + address).build(), true);
            }
            String pageId = pageImporter.readPage().getUuid();
            Map<String, Object> resultData = new HashMap();
            if (pageId != null) {
                resultData.put("id", pageId);
                getWebSocket().send(MessageBuilder.status().code(200).message("Successfully created page " + name).data(resultData).build(), true);
            } else {
                getWebSocket().send(MessageBuilder.status().code(400).message("Error while creating page " + name).data(resultData).build(), true);
            }
        }
    } catch (FrameworkException fex) {
        logger.warn("Error while importing content", fex);
        getWebSocket().send(MessageBuilder.status().code(fex.getStatus()).message(fex.getMessage()).build(), true);
    }
}
Also used : DeploymentCommentHandler(org.structr.web.maintenance.deploy.DeploymentCommentHandler) FrameworkException(org.structr.common.error.FrameworkException) HashMap(java.util.HashMap) SecurityContext(org.structr.common.SecurityContext) Importer(org.structr.web.importer.Importer)

Example 63 with SecurityContext

use of org.structr.common.SecurityContext in project structr by structr.

the class InsertCommand method processMessage.

@Override
public void processMessage(final WebSocketMessage webSocketData) {
    final SecurityContext securityContext = getWebSocket().getSecurityContext();
    final App app = StructrApp.getInstance(securityContext);
    // new node properties
    final Map<String, Object> properties = webSocketData.getNodeData();
    String parentId = (String) properties.get("id");
    final Map<String, Object> relData = webSocketData.getRelData();
    if (parentId != null) {
        DOMNode parentNode = (DOMNode) getNode(parentId);
        DOMNode nodeToInsert = null;
        try {
            PropertyMap nodeProperties = PropertyMap.inputTypeToJavaType(securityContext, properties);
            nodeToInsert = app.create(DOMNode.class, nodeProperties);
        } catch (FrameworkException fex) {
            logger.warn("Could not create node.", fex);
            getWebSocket().send(MessageBuilder.status().code(fex.getStatus()).message(fex.getMessage()).build(), true);
        }
        if ((nodeToInsert != null) && (parentNode != null)) {
            try {
                PropertyMap relProperties = PropertyMap.inputTypeToJavaType(securityContext, relData);
                app.create(parentNode, nodeToInsert, parentNode.getChildLinkType(), relProperties);
            } catch (FrameworkException t) {
                getWebSocket().send(MessageBuilder.status().code(400).message(t.getMessage()).build(), true);
            }
        } else {
            getWebSocket().send(MessageBuilder.status().code(404).build(), true);
        }
    } else {
        getWebSocket().send(MessageBuilder.status().code(400).message("Insertion of new node failed.").build(), true);
    }
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) PropertyMap(org.structr.core.property.PropertyMap) FrameworkException(org.structr.common.error.FrameworkException) SecurityContext(org.structr.common.SecurityContext) DOMNode(org.structr.web.entity.dom.DOMNode)

Example 64 with SecurityContext

use of org.structr.common.SecurityContext in project structr by structr.

the class AbstractCommand method getRelationship.

/**
 * Returns the relationship to which the uuid parameter
 * of this command refers to.
 *
 * @param id
 * @return the node
 */
public AbstractRelationship getRelationship(final String id) {
    if (id == null) {
        return null;
    }
    final SecurityContext securityContext = getWebSocket().getSecurityContext();
    final App app = StructrApp.getInstance(securityContext);
    try (final Tx tx = app.tx()) {
        final AbstractRelationship rel = (AbstractRelationship) app.getRelationshipById(id);
        tx.success();
        return rel;
    } catch (FrameworkException fex) {
        logger.warn("Unable to get relationship", fex);
    }
    return null;
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) AbstractRelationship(org.structr.core.entity.AbstractRelationship) SecurityContext(org.structr.common.SecurityContext)

Example 65 with SecurityContext

use of org.structr.common.SecurityContext in project structr by structr.

the class RelationshipFactory method instantiateWithType.

@Override
public T instantiateWithType(final Relationship relationship, final Class<T> relClass, final Relationship pathSegment, final boolean isCreation) {
    // cannot instantiate relationship without type
    if (relClass == null) {
        return null;
    }
    logger.debug("Instantiate relationship with type {}", relClass.getName());
    SecurityContext securityContext = factoryProfile.getSecurityContext();
    T newRel = null;
    try {
        newRel = relClass.newInstance();
    } catch (Throwable t) {
        logger.warn("", t);
        newRel = null;
    }
    if (newRel == null) {
        System.out.println("##################### newRel was null, using generic relationship..");
        newRel = (T) StructrApp.getConfiguration().getFactoryDefinition().createGenericRelationship();
    }
    newRel.init(securityContext, relationship, relClass);
    newRel.onRelationshipInstantiation();
    return newRel;
}
Also used : SecurityContext(org.structr.common.SecurityContext)

Aggregations

SecurityContext (org.structr.common.SecurityContext)131 FrameworkException (org.structr.common.error.FrameworkException)76 App (org.structr.core.app.App)56 StructrApp (org.structr.core.app.StructrApp)56 Tx (org.structr.core.graph.Tx)36 GraphObject (org.structr.core.GraphObject)35 PropertyKey (org.structr.core.property.PropertyKey)26 PropertyMap (org.structr.core.property.PropertyMap)26 AbstractNode (org.structr.core.entity.AbstractNode)19 IOException (java.io.IOException)18 Map (java.util.Map)17 File (org.structr.web.entity.File)14 LinkedList (java.util.LinkedList)13 DatabaseService (org.structr.api.DatabaseService)12 DOMNode (org.structr.web.entity.dom.DOMNode)12 Result (org.structr.core.Result)11 PropertyConverter (org.structr.core.converter.PropertyConverter)11 GraphObjectMap (org.structr.core.GraphObjectMap)10 Query (org.structr.core.app.Query)10 Principal (org.structr.core.entity.Principal)10