Search in sources :

Example 6 with EmptyPropertyToken

use of org.structr.common.error.EmptyPropertyToken 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 7 with EmptyPropertyToken

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

the class ValidatedNode method nonNull.

protected boolean nonNull(Property property, ErrorBuffer errorBuffer) {
    Object value = getProperty(property);
    boolean valid = true;
    if (value == null) {
        errorBuffer.add(new EmptyPropertyToken(getClass().getSimpleName(), property));
        valid = false;
    }
    return valid;
}
Also used : EmptyPropertyToken(org.structr.common.error.EmptyPropertyToken)

Aggregations

EmptyPropertyToken (org.structr.common.error.EmptyPropertyToken)7 ErrorBuffer (org.structr.common.error.ErrorBuffer)3 FrameworkException (org.structr.common.error.FrameworkException)3 App (org.structr.core.app.App)2 StructrApp (org.structr.core.app.StructrApp)2 PropertyMap (org.structr.core.property.PropertyMap)2 RestMethodResult (org.structr.rest.RestMethodResult)2 File (java.io.File)1 Date (java.util.Date)1 Matcher (java.util.regex.Matcher)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 SecurityContext (org.structr.common.SecurityContext)1 ThreadLocalMatcher (org.structr.common.ThreadLocalMatcher)1 NullPropertyToken (org.structr.common.error.NullPropertyToken)1 TooShortToken (org.structr.common.error.TooShortToken)1 GraphObject (org.structr.core.GraphObject)1 Relation (org.structr.core.entity.Relation)1 NodeInterface (org.structr.core.graph.NodeInterface)1 RelationshipInterface (org.structr.core.graph.RelationshipInterface)1 Tx (org.structr.core.graph.Tx)1