use of org.entando.entando.aps.system.exception.ResourceNotFoundException in project entando-core by entando.
the class FileBrowserService method checkResource.
protected void checkResource(String currentPath, String objectName, Boolean protectedFolder) {
if (null == protectedFolder && !StringUtils.isEmpty(currentPath)) {
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(objectName, objectName);
bindingResult.reject(FileBrowserValidator.ERRCODE_REQUIRED_FOLDER_TYPE, "fileBrowser.browser.protectedFolder.required");
throw new ValidationGenericException(bindingResult);
}
if (null == protectedFolder) {
return;
}
try {
boolean exists = this.getStorageManager().exists(currentPath, protectedFolder);
if (!exists) {
logger.warn("no resource found for path {} - type {}", currentPath, protectedFolder);
throw new ResourceNotFoundException(FileBrowserValidator.ERRCODE_RESOURCE_DOES_NOT_EXIST, objectName, currentPath);
}
} catch (ResourceNotFoundException e) {
throw e;
} catch (Exception e) {
logger.error("Error checking resource {} , protected {} ", currentPath, protectedFolder, e);
throw new RestServerError("error checking resource", e);
}
}
use of org.entando.entando.aps.system.exception.ResourceNotFoundException in project entando-core by entando.
the class WidgetService method updateWidget.
@Override
public WidgetDto updateWidget(String widgetCode, WidgetRequest widgetRequest) {
WidgetType type = this.getWidgetManager().getWidgetType(widgetCode);
if (type == null) {
throw new ResourceNotFoundException(WidgetValidator.ERRCODE_WIDGET_DOES_NOT_EXISTS, "widget", widgetCode);
}
WidgetDto widgetDto = null;
try {
if (null == this.getGroupManager().getGroup(widgetRequest.getGroup())) {
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(type, "widget");
bindingResult.reject(WidgetValidator.ERRCODE_WIDGET_GROUP_INVALID, new String[] { widgetRequest.getGroup() }, "widgettype.group.invalid");
throw new ValidationGenericException(bindingResult);
}
if (type.isUserType() && StringUtils.isBlank(widgetRequest.getCustomUi()) && !WidgetType.existsJsp(this.srvCtx, widgetCode, widgetCode)) {
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(type, "widget");
bindingResult.reject(WidgetValidator.ERRCODE_NOT_BLANK, new String[] { type.getCode() }, "widgettype.customUi.notBlank");
throw new ValidationGenericException(bindingResult);
}
this.processWidgetType(type, widgetRequest);
widgetDto = dtoBuilder.convert(type);
this.getWidgetManager().updateWidgetType(widgetCode, type.getTitles(), type.getConfig(), type.getMainGroup(), type.getConfigUi(), type.getBundleId());
if (!StringUtils.isEmpty(widgetCode)) {
GuiFragment guiFragment = this.getGuiFragmentManager().getUniqueGuiFragmentByWidgetType(widgetCode);
if (null == guiFragment) {
this.createAndAddFragment(type, widgetRequest);
} else {
guiFragment.setGui(widgetRequest.getCustomUi());
this.getGuiFragmentManager().updateGuiFragment(guiFragment);
}
}
this.addFragments(widgetDto);
} catch (ValidationGenericException vge) {
logger.error("Found an error on validation, throwing original exception", vge);
throw vge;
} catch (Throwable e) {
logger.error("failed to update widget type", e);
throw new RestServerError("Failed to update widget", e);
}
return widgetDto;
}
use of org.entando.entando.aps.system.exception.ResourceNotFoundException in project entando-core by entando.
the class AbstractPaginationValidator method validateRestListRequest.
public void validateRestListRequest(RestListRequest listRequest, Class<?> type) {
this.checkDefaultSortField(listRequest);
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(listRequest, "listRequest");
if (listRequest.getPage() < 1) {
bindingResult.reject(ERRCODE_PAGE_INVALID, new Object[] {}, "pagination.page.invalid");
throw new ValidationGenericException(bindingResult);
}
if (listRequest.getPageSize() < 0) {
bindingResult.reject(ERRCODE_PAGE_SIZE_INVALID, new Object[] {}, "pagination.page.size.invalid");
} else if (listRequest.getPage() > 1 && listRequest.getPageSize() == 0) {
bindingResult.reject(ERRCODE_NO_ITEM_ON_PAGE, new String[] { String.valueOf(listRequest.getPage()) }, "pagination.item.empty");
throw new ResourceNotFoundException(bindingResult);
}
if (null == type) {
return;
}
if (!isValidField(listRequest.getSort(), type)) {
bindingResult.reject(ERRCODE_SORTING_INVALID, new Object[] { listRequest.getSort() }, "sorting.sort.invalid");
}
if (listRequest.getFilters() != null) {
List<String> attributes = Arrays.asList(listRequest.getFilters()).stream().filter(filter -> filter.getEntityAttr() == null).map(filter -> filter.getAttributeName()).filter(attr -> !isValidField(attr, type)).collect(Collectors.toList());
if (attributes.size() > 0) {
bindingResult.reject(ERRCODE_FILTERING_ATTR_INVALID, new Object[] { attributes.get(0) }, "filtering.filter.attr.name.invalid");
}
if (Arrays.stream(FilterOperator.values()).map(FilterOperator::getValue).noneMatch(op -> Arrays.stream(listRequest.getFilters()).map(Filter::getOperator).anyMatch(op::equals))) {
bindingResult.reject(ERRCODE_FILTERING_OP_INVALID, new Object[] {}, "filtering.filter.operation.invalid");
}
Arrays.stream(listRequest.getFilters()).filter(f -> getDateFilterKeys().contains(f.getAttribute())).forEach(f -> {
try {
SimpleDateFormat sdf = new SimpleDateFormat(SystemConstants.API_DATE_FORMAT);
sdf.parse(f.getValue());
} catch (ParseException ex) {
bindingResult.reject(ERRCODE_FILTERING_OP_INVALID, new Object[] { f.getValue(), f.getAttribute() }, "filtering.filter.date.format.invalid");
}
});
}
if (!Arrays.asList(directions).contains(listRequest.getDirection())) {
bindingResult.reject(ERRCODE_DIRECTION_INVALID, new Object[] {}, "sorting.direction.invalid");
}
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
}
use of org.entando.entando.aps.system.exception.ResourceNotFoundException in project entando-core by entando.
the class DataObjectModelController method updateDataObjectModel.
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{dataModelId}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SimpleRestResponse<DataModelDto>> updateDataObjectModel(@PathVariable String dataModelId, @Valid @RequestBody DataObjectModelRequest dataObjectModelRequest, BindingResult bindingResult) throws JsonProcessingException {
logger.debug("Updating data object model -> {}", dataObjectModelRequest.getModelId());
// field validations
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
this.getDataObjectModelValidator().validateBodyName(dataModelId, dataObjectModelRequest, bindingResult);
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
int result = this.getDataObjectModelValidator().validateBody(dataObjectModelRequest, true, bindingResult);
if (bindingResult.hasErrors()) {
if (404 == result) {
if (1 == bindingResult.getFieldErrorCount("type")) {
throw new ResourceNotFoundException(DataObjectModelValidator.ERRCODE_PUT_DATAOBJECTTYPE_DOES_NOT_EXIST, "type", dataObjectModelRequest.getType());
} else {
throw new ResourceNotFoundException(DataObjectModelValidator.ERRCODE_DATAOBJECTMODEL_ALREADY_EXISTS, "modelId", dataObjectModelRequest.getModelId());
}
} else {
throw new ValidationGenericException(bindingResult);
}
}
DataModelDto dataModelDto = this.getDataObjectModelService().updateDataObjectModel(dataObjectModelRequest);
logger.debug("Main Response -> {}", dataModelDto);
return new ResponseEntity<>(new SimpleRestResponse<>(dataModelDto), HttpStatus.OK);
}
use of org.entando.entando.aps.system.exception.ResourceNotFoundException in project entando-core by entando.
the class DataObjectModelController method addDataObjectModel.
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SimpleRestResponse<DataModelDto>> addDataObjectModel(@Valid @RequestBody DataObjectModelRequest dataObjectModelRequest, BindingResult bindingResult) throws JsonProcessingException {
logger.debug("Adding data object model -> {}", dataObjectModelRequest.getModelId());
// field validations
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
// business validations
this.getDataObjectModelValidator().validate(dataObjectModelRequest, bindingResult);
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
int result = this.getDataObjectModelValidator().validateBody(dataObjectModelRequest, false, bindingResult);
if (bindingResult.hasErrors()) {
if (404 == result) {
throw new ResourceNotFoundException(DataObjectModelValidator.ERRCODE_POST_DATAOBJECTTYPE_DOES_NOT_EXIST, "type", dataObjectModelRequest.getType());
} else {
throw new ValidationGenericException(bindingResult);
}
}
DataModelDto dataModelDto = this.getDataObjectModelService().addDataObjectModel(dataObjectModelRequest);
logger.debug("Main Response -> {}", dataModelDto);
return new ResponseEntity<>(new SimpleRestResponse<>(dataModelDto), HttpStatus.OK);
}
Aggregations