private URI uri( EntityRepresentation representation ) { return URI.create( assemble( representation.selfUri() ) ); }
@GET @Path( PATH_LABELS ) public Response getAllLabels( @QueryParam( "in_use" ) @DefaultValue( "true" ) boolean inUse ) { return output.ok( actions.getAllLabels( inUse ) ); }
public final <REPR extends Representation & EntityRepresentation> Response conflict( REPR representation ) { return response( Response.status( Status.CONFLICT ), representation ); }
private ResponseBuilder formatRepresentation( ResponseBuilder response, final Representation representation ) { representationWriteHandler.onRepresentationStartWriting(); boolean mustFail = representation instanceof ExceptionRepresentation; if ( format instanceof StreamingFormat ) { return response.entity( stream( representation, (StreamingFormat) format, mustFail ) ); } else { return response.entity( toBytes( assemble( representation ), mustFail ) ); } }
private Map<String, Object> serializeToStringThenParseAsToMap( CypherResultRepresentation repr ) throws Exception { OutputFormat format = new OutputFormat( new JsonFormat(), new URI( "http://localhost/" ), null ); return jsonToMap( format.assemble( repr ) ); } }
public OutputFormat outputFormat( List<MediaType> acceptable, URI baseUri, MultivaluedMap<String,String> requestHeaders ) { RepresentationFormat format = forHeaders( acceptable, requestHeaders ); if ( format == null ) { format = forMediaTypes( acceptable ); } if ( format == null ) { format = useDefault( acceptable ); } return new OutputFormat( format, baseUri, getExtensionManager() ); }
@POST @Path( PATH_SCHEMA_CONSTRAINT_LABEL_UNIQUENESS ) public Response createPropertyUniquenessConstraint( @PathParam( "label" ) String labelName, String body ) { try { Map<String, Object> data = input.readMap( body, "property_keys" ); Iterable<String> singlePropertyKey = singleOrList( data, "property_keys" ); if ( singlePropertyKey == null ) { return output.badRequest( new IllegalArgumentException( "Supply single property key or list of property keys" ) ); } return output.ok( actions.createPropertyUniquenessConstraint( labelName, singlePropertyKey ) ); } catch ( UnsupportedOperationException | BadInputException e ) { return output.badRequest( e ); } catch ( org.neo4j.graphdb.ConstraintViolationException e ) { return output.conflict( e ); } }
"end" ) ), getMapOrNull( entityBody, "properties" ) ); return result.other() ? output.created( result.first() ) : output.ok( result.first() ); if ( result.other() ) return output.created( result.first() ); return output.conflict( result.first() ); return output.created( result.first() ); return output.conflict( result.first() ); return output.created( actions.addToRelationshipIndex( indexName, String.valueOf( entityBody.get( "key" ) ), String.valueOf( entityBody.get( "value" ) ), extractRelationshipId( entityBody.get( "uri" return output.methodNotAllowed( e ); return output.badRequest( e ); return output.serverError( e );
if ( principal == null || !principal.getName().equals( username ) ) return output.notFound(); return output.response( BAD_REQUEST, new ExceptionRepresentation( new Neo4jError( Status.Request.InvalidFormat, e.getMessage() ) ) ); if ( o == null ) return output.response( UNPROCESSABLE, new ExceptionRepresentation( new Neo4jError( Status.Request.InvalidFormat, String.format( "Required parameter '%s' is missing.", PASSWORD ) ) ) ); return output.response( UNPROCESSABLE, new ExceptionRepresentation( new Neo4jError( Status.Request.InvalidFormat, String.format( "Expected '%s' to be a string.", PASSWORD ) ) ) ); if ( loginContext == null ) return output.notFound(); return output.serverErrorWithoutLegacyStacktrace( e ); return output.response( UNPROCESSABLE, new ExceptionRepresentation( new Neo4jError( e.status(), e.getMessage() ) ) ); return output.ok();
getOrCreateValue, extractNodeIdOrNull( getStringOrNull( entityBody, "uri" ) ), getMapOrNull( entityBody, "properties" ) ); return result.other() ? output.created( result.first() ) : output.okIncludeLocation( result.first() ); if ( result.other() ) return output.created( result.first() ); return output.conflict( result.first() ); return output.created( result.first() ); return output.conflict( result.first() ); return output.created( actions.addToNodeIndex( indexName, String.valueOf( entityBody.get( "key" ) ), value, extractNodeId( entityBody.get( "uri" ) return output.methodNotAllowed( e ); return output.badRequest( e ); return output.serverError( e );
@Test public void shouldReturnAbsoluteURIForSeeOther() throws Exception { URI relativeURI = new URI( "/test/path" ); OutputFormat outputFormat = new OutputFormat( new JsonFormat(), new URI( "http://base.local:8765/" ), null ); Response response = outputFormat.seeOther( relativeURI ); assertEquals( 303, response.getStatus() ); assertEquals( new URI( "http://base.local:8765/test/path" ), response.getMetadata().getFirst( "Location" ) ); } }
@POST @Path( PATH_NODE_PATHS ) public Response allPaths( @PathParam( "nodeId" ) long startNode, String body ) { final Map<String, Object> description; final long endNode; try { description = input.readMap( body ); endNode = extractNodeId( (String) description.get( "to" ) ); return output.ok( actions.findPaths( startNode, endNode, description ) ); } catch ( BadInputException | ClassCastException e ) { return output.badRequest( e ); } }
@DELETE @Path( PATH_SCHEMA_INDEX_LABEL_PROPERTY ) public Response dropSchemaIndex( @PathParam( "label" ) String labelName, @PathParam( "property" ) AmpersandSeparatedCollection properties ) { // TODO assumption, only a single property key if ( properties.size() != 1 ) { return output.badRequest( new IllegalArgumentException( "Single property key assumed" ) ); } String property = Iterables.single( properties ); try { if ( actions.dropSchemaIndex( labelName, property ) ) { return nothing(); } else { return output.notFound(); } } catch ( org.neo4j.graphdb.ConstraintViolationException e ) { return output.conflict( e ); } }
@POST @Path( PATH_NODE_PATH ) public Response singlePath( @PathParam( "nodeId" ) long startNode, String body ) { final Map<String, Object> description; final long endNode; try { description = input.readMap( body ); endNode = extractNodeId( (String) description.get( "to" ) ); return output.ok( actions.findSinglePath( startNode, endNode, description ) ); } catch ( BadInputException | ClassCastException e ) { return output.badRequest( e ); } catch ( NotFoundException e ) { return output.notFound( e ); } }
@DELETE @Path( PATH_RELATIONSHIP_PROPERTIES ) public Response deleteAllRelationshipProperties( @PathParam( "relationshipId" ) long relationshipId ) { try { actions.removeAllRelationshipProperties( relationshipId ); } catch ( RelationshipNotFoundException e ) { return output.notFound( e ); } catch ( PropertyValueException e ) { return output.badRequest( e ); } return nothing(); }