use of io.crnk.core.engine.filter.ResourceModificationFilter in project crnk-framework by crnk-project.
the class ResourceDeleteTest method onGivenRequestResourceGetShouldHandleIt.
@Test
public void onGivenRequestResourceGetShouldHandleIt() throws Exception {
// GIVEN
JsonPath jsonPath = pathBuilder.build("/tasks/1");
ResourceDelete sut = new ResourceDelete(resourceRegistry, new ArrayList<ResourceModificationFilter>());
// WHEN
Response response = sut.handle(jsonPath, emptyTaskQuery, null, null);
// THEN
assertThat(response.getDocument()).isNull();
}
use of io.crnk.core.engine.filter.ResourceModificationFilter in project crnk-framework by crnk-project.
the class ResourceDeleteTest method onValidRequestShouldAcceptIt.
@Test
public void onValidRequestShouldAcceptIt() {
// GIVEN
JsonPath jsonPath = pathBuilder.build("tasks/1");
ResourceRegistry resourceRegistry = mock(ResourceRegistry.class);
ResourceDelete sut = new ResourceDelete(resourceRegistry, new ArrayList<ResourceModificationFilter>());
// WHEN
boolean result = sut.isAcceptable(jsonPath, REQUEST_TYPE);
// THEN
assertThat(result).isTrue();
}
use of io.crnk.core.engine.filter.ResourceModificationFilter in project crnk-framework by crnk-project.
the class ResourceDeleteTest method onNonRelationRequestShouldDenyIt.
@Test
public void onNonRelationRequestShouldDenyIt() {
// GIVEN
JsonPath jsonPath = new ResourcePath("tasks/1/relationships/project");
ResourceRegistry resourceRegistry = mock(ResourceRegistry.class);
ResourceDelete sut = new ResourceDelete(resourceRegistry, new ArrayList<ResourceModificationFilter>());
// WHEN
boolean result = sut.isAcceptable(jsonPath, REQUEST_TYPE);
// THEN
assertThat(result).isFalse();
}
use of io.crnk.core.engine.filter.ResourceModificationFilter in project crnk-framework by crnk-project.
the class ResourceUpsert method setAttribute.
private void setAttribute(ResourceInformation resourceInformation, Object instance, String attributeName, JsonNode valueNode) {
ResourceField field = resourceInformation.findAttributeFieldByName(attributeName);
if (canModifyField(resourceInformation, attributeName, field)) {
try {
if (field != null) {
Type valueType = field.getGenericType();
Object value;
if (valueNode != null) {
JavaType jacksonValueType = objectMapper.getTypeFactory().constructType(valueType);
ObjectReader reader = objectMapper.reader().forType(jacksonValueType);
value = reader.readValue(valueNode);
} else {
value = null;
}
for (ResourceModificationFilter filter : modificationFilters) {
value = filter.modifyAttribute(instance, field, attributeName, value);
}
field.getAccessor().setValue(instance, value);
} else if (resourceInformation.getAnyFieldAccessor() != null) {
AnyResourceFieldAccessor anyFieldAccessor = resourceInformation.getAnyFieldAccessor();
Object value = objectMapper.reader().forType(Object.class).readValue(valueNode);
for (ResourceModificationFilter filter : modificationFilters) {
value = filter.modifyAttribute(instance, field, attributeName, value);
}
anyFieldAccessor.setValue(instance, attributeName, value);
}
} catch (IOException e) {
throw new ResourceException(String.format("Exception while setting %s.%s=%s due to %s", instance, attributeName, valueNode, e.getMessage()), e);
}
}
}
use of io.crnk.core.engine.filter.ResourceModificationFilter in project crnk-framework by crnk-project.
the class RelationshipsResourcePost method processToOneRelationship.
@Override
protected void processToOneRelationship(Object resource, ResourceInformation targetResourceInformation, ResourceField relationshipField, ResourceIdentifier resourceId, QueryAdapter queryAdapter, RelationshipRepositoryAdapter relationshipRepositoryForClass) {
for (ResourceModificationFilter filter : modificationFilters) {
resourceId = filter.modifyOneRelationship(resource, relationshipField, resourceId);
}
Serializable parsedId = null;
if (resourceId != null) {
parsedId = targetResourceInformation.parseIdString(resourceId.getId());
}
// noinspection unchecked
relationshipRepositoryForClass.setRelation(resource, parsedId, relationshipField, queryAdapter);
}
Aggregations