use of com.yahoo.elide.jsonapi.parser.DeleteVisitor in project elide by yahoo.
the class JsonApiPatch method handleRemoveOp.
/**
* Remove data via patch extension.
*/
private Supplier<Pair<Integer, JsonNode>> handleRemoveOp(String path, JsonNode patchValue, PatchRequestScope requestScope) {
try {
JsonApiDocument value = requestScope.getMapper().readJsonApiPatchExtValue(patchValue);
String fullPath;
if (path.contains("relationships")) {
// Reserved keyword for relationships
fullPath = path;
} else {
Data<Resource> data = value.getData();
if (data == null || data.get() == null) {
fullPath = path;
} else {
Collection<Resource> resources = data.get();
String id = getSingleResource(resources).getId();
fullPath = path + "/" + id;
}
}
DeleteVisitor visitor = new DeleteVisitor(new PatchRequestScope(path, value, requestScope));
return visitor.visit(JsonApiParser.parse(fullPath));
} catch (IOException e) {
throw new InvalidEntityBodyException("Could not parse patch extension value: " + patchValue);
}
}
use of com.yahoo.elide.jsonapi.parser.DeleteVisitor in project elide by yahoo.
the class Elide method delete.
/**
* Handle DELETE.
*
* @param baseUrlEndPoint base URL with prefix endpoint
* @param path the path
* @param jsonApiDocument the json api document
* @param queryParams the query params
* @param requestHeaders the request headers
* @param opaqueUser the opaque user
* @param apiVersion the API version
* @param requestId the request ID
* @return Elide response object
*/
public ElideResponse delete(String baseUrlEndPoint, String path, String jsonApiDocument, MultivaluedMap<String, String> queryParams, Map<String, List<String>> requestHeaders, User opaqueUser, String apiVersion, UUID requestId) {
return handleRequest(false, opaqueUser, dataStore::beginTransaction, requestId, (tx, user) -> {
JsonApiDocument jsonApiDoc = StringUtils.isEmpty(jsonApiDocument) ? new JsonApiDocument() : mapper.readJsonApiDocument(jsonApiDocument);
RequestScope requestScope = new RequestScope(baseUrlEndPoint, path, apiVersion, jsonApiDoc, tx, user, queryParams, requestHeaders, requestId, elideSettings);
requestScope.setEntityProjection(new EntityProjectionMaker(elideSettings.getDictionary(), requestScope).parsePath(path));
BaseVisitor visitor = new DeleteVisitor(requestScope);
return visit(path, requestScope, visitor);
});
}
Aggregations