Search in sources :

Example 11 with ErrorBuffer

use of org.structr.common.error.ErrorBuffer in project structr by structr.

the class DeleteNodeCommand method doDeleteNode.

private void doDeleteNode(final NodeInterface node) {
    if (TransactionCommand.isDeleted(node.getNode())) {
        return;
    }
    try {
        if (!deletedNodes.contains(node) && node.getUuid() == null) {
            logger.warn("Will not delete node which has no UUID, dumping stack.");
            Thread.dumpStack();
            return;
        }
    } catch (java.lang.IllegalStateException ise) {
        logger.warn("Trying to delete a node which is already deleted", ise.getMessage());
        return;
    } catch (org.structr.api.NotFoundException nfex) {
    // exception can be ignored, node is already deleted
    }
    deletedNodes.add(node);
    App app = StructrApp.getInstance(securityContext);
    try {
        List<NodeInterface> nodesToCheckAfterDeletion = new LinkedList<>();
        // by relationships which are marked with DELETE_OUTGOING
        for (AbstractRelationship rel : node.getOutgoingRelationships()) {
            // deleted rels can be null..
            if (rel != null) {
                int cascadeDelete = rel.cascadeDelete();
                NodeInterface endNode = rel.getTargetNode();
                if ((cascadeDelete & Relation.CONSTRAINT_BASED) == Relation.CONSTRAINT_BASED) {
                    nodesToCheckAfterDeletion.add(endNode);
                }
                if (!deletedNodes.contains(endNode) && ((cascadeDelete & Relation.SOURCE_TO_TARGET) == Relation.SOURCE_TO_TARGET)) {
                    // remove end node from index
                    endNode.removeFromIndex();
                    doDeleteNode(endNode);
                }
            }
        }
        // by relationships which are marked with DELETE_INCOMING
        for (AbstractRelationship rel : node.getIncomingRelationships()) {
            // deleted rels can be null
            if (rel != null) {
                final int cascadeDelete = rel.cascadeDelete();
                final NodeInterface startNode = rel.getSourceNode();
                if ((cascadeDelete & Relation.CONSTRAINT_BASED) == Relation.CONSTRAINT_BASED) {
                    nodesToCheckAfterDeletion.add(startNode);
                }
                if (!deletedNodes.contains(startNode) && ((cascadeDelete & Relation.TARGET_TO_SOURCE) == Relation.TARGET_TO_SOURCE)) {
                    // remove start node from index
                    startNode.removeFromIndex();
                    doDeleteNode(startNode);
                }
            }
        }
        // deletion callback, must not prevent node deletion!
        node.onNodeDeletion();
        // Delete any relationship (this is PASSIVE DELETION)
        for (AbstractRelationship r : node.getRelationships()) {
            if (r != null) {
                app.delete(r);
            }
        }
        // still valid after node deletion
        for (NodeInterface nodeToCheck : nodesToCheckAfterDeletion) {
            ErrorBuffer errorBuffer = new ErrorBuffer();
            if (!deletedNodes.contains(nodeToCheck) && !nodeToCheck.isValid(errorBuffer)) {
                // remove end node from index
                nodeToCheck.removeFromIndex();
                doDeleteNode(nodeToCheck);
            }
        }
    } catch (Throwable t) {
        t.printStackTrace();
        logger.warn("Exception while deleting node {}: {}", node, t.getMessage());
    }
    return;
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) AbstractRelationship(org.structr.core.entity.AbstractRelationship) LinkedList(java.util.LinkedList) ErrorBuffer(org.structr.common.error.ErrorBuffer)

Example 12 with ErrorBuffer

use of org.structr.common.error.ErrorBuffer in project structr by structr.

the class Widget method expandWidget.

public static void expandWidget(final SecurityContext securityContext, final Page page, final DOMNode parent, final String baseUrl, final Map<String, Object> parameters, final boolean processDeploymentInfo) throws FrameworkException {
    String _source = (String) parameters.get("source");
    ErrorBuffer errorBuffer = new ErrorBuffer();
    if (_source == null) {
        errorBuffer.add(new EmptyPropertyToken(Widget.class.getSimpleName(), source));
    } else {
        // check source for mandatory parameters
        Matcher matcher = threadLocalTemplateMatcher.get();
        // initialize with source
        matcher.reset(_source);
        while (matcher.find()) {
            final String group = matcher.group();
            final String source = group.substring(1, group.length() - 1);
            final ReplacementInfo info = new ReplacementInfo(source);
            String key = info.getKey();
            Object value = parameters.get(key);
            if (value != null) {
                // replace and restart matching process
                _source = _source.replace(group, value.toString());
                matcher.reset(_source);
            }
        }
    }
    if (!errorBuffer.hasError()) {
        Importer importer = new Importer(securityContext, _source, baseUrl, null, false, false);
        if (processDeploymentInfo) {
            importer.setIsDeployment(true);
            importer.setCommentHandler(new DeploymentCommentHandler());
        }
        importer.parse(true);
        importer.createChildNodes(parent, page, true);
    } else {
        // report error to ui
        throw new FrameworkException(422, "Unable to import the given source code", errorBuffer);
    }
}
Also used : DeploymentCommentHandler(org.structr.web.maintenance.deploy.DeploymentCommentHandler) EmptyPropertyToken(org.structr.common.error.EmptyPropertyToken) ErrorBuffer(org.structr.common.error.ErrorBuffer) FrameworkException(org.structr.common.error.FrameworkException) Matcher(java.util.regex.Matcher) ThreadLocalMatcher(org.structr.common.ThreadLocalMatcher) Importer(org.structr.web.importer.Importer)

Example 13 with ErrorBuffer

use of org.structr.common.error.ErrorBuffer in project structr by structr.

the class TypeResource method doPost.

@Override
public RestMethodResult doPost(final Map<String, Object> propertySet) throws FrameworkException {
    // virtual type?
    if (virtualType != null) {
        virtualType.transformInput(securityContext, entityClass, propertySet);
    }
    if (isNode) {
        final RestMethodResult result = new RestMethodResult(HttpServletResponse.SC_CREATED);
        final NodeInterface newNode = createNode(propertySet);
        if (newNode != null) {
            result.addHeader("Location", buildLocationHeader(newNode));
            result.addContent(newNode);
        }
        result.serializeAsPrimitiveArray(true);
        // finally: return 201 Created
        return result;
    } else {
        final App app = StructrApp.getInstance(securityContext);
        final Relation template = getRelationshipTemplate();
        final ErrorBuffer errorBuffer = new ErrorBuffer();
        if (template != null) {
            final NodeInterface sourceNode = identifyStartNode(template, propertySet);
            final NodeInterface targetNode = identifyEndNode(template, propertySet);
            final PropertyMap properties = PropertyMap.inputTypeToJavaType(securityContext, entityClass, propertySet);
            RelationshipInterface newRelationship = null;
            if (sourceNode == null) {
                errorBuffer.add(new EmptyPropertyToken(entityClass.getSimpleName(), template.getSourceIdProperty()));
            }
            if (targetNode == null) {
                errorBuffer.add(new EmptyPropertyToken(entityClass.getSimpleName(), template.getTargetIdProperty()));
            }
            if (errorBuffer.hasError()) {
                throw new FrameworkException(422, "Source node ID and target node ID of relationsips must be set", errorBuffer);
            }
            template.ensureCardinality(securityContext, sourceNode, targetNode);
            newRelationship = app.create(sourceNode, targetNode, entityClass, properties);
            RestMethodResult result = new RestMethodResult(HttpServletResponse.SC_CREATED);
            if (newRelationship != null) {
                result.addHeader("Location", buildLocationHeader(newRelationship));
                result.addContent(newRelationship);
            }
            result.serializeAsPrimitiveArray(true);
            // finally: return 201 Created
            return result;
        }
        // shouldn't happen
        throw new NotFoundException("Type" + rawType + " does not exist");
    }
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) EmptyPropertyToken(org.structr.common.error.EmptyPropertyToken) Relation(org.structr.core.entity.Relation) ErrorBuffer(org.structr.common.error.ErrorBuffer) PropertyMap(org.structr.core.property.PropertyMap) FrameworkException(org.structr.common.error.FrameworkException) RelationshipInterface(org.structr.core.graph.RelationshipInterface) NotFoundException(org.structr.rest.exception.NotFoundException) RestMethodResult(org.structr.rest.RestMethodResult) NodeInterface(org.structr.core.graph.NodeInterface)

Example 14 with ErrorBuffer

use of org.structr.common.error.ErrorBuffer in project structr by structr.

the class SchemaProperty method getIntPropertyParser.

public IntPropertyParser getIntPropertyParser() {
    if (intPropertyParser == null) {
        try {
            intPropertyParser = new IntPropertyParser(new ErrorBuffer(), getName(), this);
            intPropertyParser.getPropertySource(new StringBuilder(), getProperty(SchemaProperty.schemaNode));
        } catch (FrameworkException fex) {
            logger.warn("", fex);
        }
    }
    return intPropertyParser;
}
Also used : ErrorBuffer(org.structr.common.error.ErrorBuffer) FrameworkException(org.structr.common.error.FrameworkException) IntPropertyParser(org.structr.schema.parser.IntPropertyParser)

Example 15 with ErrorBuffer

use of org.structr.common.error.ErrorBuffer in project structr by structr.

the class SchemaProperty method getNotionPropertyParser.

public NotionPropertyParser getNotionPropertyParser() {
    if (notionPropertyParser == null) {
        try {
            notionPropertyParser = new NotionPropertyParser(new ErrorBuffer(), getName(), this);
            notionPropertyParser.getPropertySource(new StringBuilder(), getProperty(SchemaProperty.schemaNode));
        } catch (FrameworkException fex) {
            logger.warn("", fex);
        }
    }
    return notionPropertyParser;
}
Also used : ErrorBuffer(org.structr.common.error.ErrorBuffer) FrameworkException(org.structr.common.error.FrameworkException) NotionPropertyParser(org.structr.schema.parser.NotionPropertyParser)

Aggregations

ErrorBuffer (org.structr.common.error.ErrorBuffer)16 FrameworkException (org.structr.common.error.FrameworkException)13 App (org.structr.core.app.App)4 StructrApp (org.structr.core.app.StructrApp)4 EmptyPropertyToken (org.structr.common.error.EmptyPropertyToken)3 LinkedList (java.util.LinkedList)2 DatabaseService (org.structr.api.DatabaseService)2 AbstractRelationship (org.structr.core.entity.AbstractRelationship)2 PropertyMap (org.structr.core.property.PropertyMap)2 RestMethodResult (org.structr.rest.RestMethodResult)2 GraphQLOutputType (graphql.schema.GraphQLOutputType)1 GraphQLScalarType (graphql.schema.GraphQLScalarType)1 BufferedInputStream (java.io.BufferedInputStream)1 DataInputStream (java.io.DataInputStream)1 EOFException (java.io.EOFException)1 File (java.io.File)1 DecimalFormat (java.text.DecimalFormat)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1