use of io.crnk.core.engine.http.HttpMethod in project crnk-framework by crnk-project.
the class ResourceUpsert method canModifyField.
/**
* Allows to check whether the given field can be written.
*
* @param field from the information model or null if is a dynamic field (like JsonAny).
*/
protected boolean canModifyField(ResourceInformation resourceInformation, String fieldName, ResourceField field) {
if (field == null) {
return true;
}
HttpMethod method = getHttpMethod();
ResourceFieldAccess access = field.getAccess();
boolean modifiable = method == HttpMethod.POST ? access.isPostable() : access.isPatchable();
FilterBehavior filterBehavior = modifiable ? FilterBehavior.NONE : getDefaultFilterBehavior();
filterBehavior = filterBehavior.merge(resourceFilterDirectory.get(field, method));
if (filterBehavior == FilterBehavior.NONE) {
return true;
} else if (filterBehavior == FilterBehavior.FORBIDDEN) {
throw new ForbiddenException("field '" + fieldName + "' cannot be modified");
} else {
PreconditionUtil.assertEquals("unknown behavior", FilterBehavior.IGNORED, filterBehavior);
return false;
}
}
use of io.crnk.core.engine.http.HttpMethod in project crnk-framework by crnk-project.
the class ResourceRepositoryStubImpl method executeUpdate.
private Object executeUpdate(String requestUrl, T resource, boolean create) {
JsonApiResponse response = new JsonApiResponse();
response.setEntity(resource);
ClientDocumentMapper documentMapper = client.getDocumentMapper();
final Document requestDocument = documentMapper.toDocument(response, null);
final ObjectMapper objectMapper = client.getObjectMapper();
String requestBodyValue = ExceptionUtil.wrapCatchedExceptions(new Callable<String>() {
@Override
public String call() throws Exception {
return objectMapper.writeValueAsString(requestDocument);
}
});
HttpMethod method = create || client.getPushAlways() ? HttpMethod.POST : HttpMethod.PATCH;
return execute(requestUrl, ResponseType.RESOURCE, method, requestBodyValue);
}
Aggregations