use of io.crnk.core.exception.BadRequestException in project crnk-framework by crnk-project.
the class ActivitiRepositoryBase method checkFilter.
protected void checkFilter(Object resource, boolean applyAsDefault) {
QuerySpec enforcementSpec = new QuerySpec((String) null);
for (FilterSpec baseFilter : baseFilters) {
enforcementSpec.addFilter(baseFilter);
// apply as default if possible
List<String> attributePath = baseFilter.getAttributePath();
if (attributePath.size() == 1 && baseFilter.getOperator() == FilterOperator.EQ) {
String attributeName = baseFilter.getAttributePath().get(0);
Object actualValue = PropertyUtils.getProperty(resource, attributeName);
Object expectedValue = baseFilter.getValue();
if (actualValue == null) {
PropertyUtils.setProperty(resource, attributeName, expectedValue);
}
}
}
if (enforcementSpec.apply(Arrays.asList(resource)).isEmpty()) {
throw new BadRequestException("resource does not belong to this repository");
}
}
Aggregations