use of org.entando.entando.aps.system.exception.ResourceNotFoundException in project entando-core by entando.
the class DataTypeController method getDataType.
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/dataTypes/{dataTypeCode}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SimpleRestResponse<DataTypeDto>> getDataType(@PathVariable String dataTypeCode) throws JsonProcessingException {
logger.debug("Requested data type -> {}", dataTypeCode);
if (!this.getDataTypeValidator().existType(dataTypeCode)) {
throw new ResourceNotFoundException(DataTypeValidator.ERRCODE_ENTITY_TYPE_DOES_NOT_EXIST, "Data Type", dataTypeCode);
}
DataTypeDto dto = this.getDataObjectService().getDataType(dataTypeCode);
logger.debug("Main Response -> {}", dto);
return new ResponseEntity<>(new SimpleRestResponse<>(dto), HttpStatus.OK);
}
use of org.entando.entando.aps.system.exception.ResourceNotFoundException in project entando-core by entando.
the class FileBrowserValidator method validate.
@Override
public void validate(Object target, Errors errors) {
FileBrowserRequest request = (FileBrowserRequest) target;
String path = request.getPath();
if (path.endsWith("/")) {
if (request instanceof FileBrowserFileRequest) {
errors.rejectValue("path", ERRCODE_INVALID_PATH, new String[] { path }, "fileBrowser.filename.invalidPath");
return;
} else {
path = path.substring(0, path.length() - 1);
}
}
if (!path.contains("/")) {
return;
}
try {
String directory = path.substring(0, path.lastIndexOf("/"));
if (!this.getStorageManager().exists(directory, request.isProtectedFolder())) {
throw new ResourceNotFoundException(FileBrowserValidator.ERRCODE_RESOURCE_DOES_NOT_EXIST, "parent folder", path);
}
if (request instanceof FileBrowserFileRequest) {
FileBrowserFileRequest fileRequest = (FileBrowserFileRequest) target;
String extractedFileName = path.substring(path.lastIndexOf("/") + 1, path.length());
if (!extractedFileName.equalsIgnoreCase(fileRequest.getFilename())) {
errors.rejectValue("filename", ERRCODE_FILENAME_MISMATCH, new String[] { fileRequest.getFilename(), extractedFileName }, "fileBrowser.filename.body.mismatch");
throw new ValidationConflictException((BindingResult) errors);
}
}
} catch (ValidationConflictException vce) {
throw vce;
} catch (ResourceNotFoundException e) {
throw e;
} catch (Exception e) {
logger.error("Error checking path {} , protected {} ", path, request.isProtectedFolder(), e);
throw new RestServerError("error checking path", e);
}
}
use of org.entando.entando.aps.system.exception.ResourceNotFoundException in project entando-core by entando.
the class GuiFragmentController method updateGuiFragment.
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{fragmentCode}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SimpleRestResponse<GuiFragmentDto>> updateGuiFragment(@PathVariable String fragmentCode, @Valid @RequestBody GuiFragmentRequestBody guiFragmentRequest, BindingResult bindingResult) {
// field validations
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
int result = this.getGuiFragmentValidator().validateBody(fragmentCode, guiFragmentRequest, bindingResult);
if (bindingResult.hasErrors()) {
if (404 == result) {
throw new ResourceNotFoundException(GuiFragmentValidator.ERRCODE_FRAGMENT_DOES_NOT_EXISTS, "fragment", fragmentCode);
} else {
throw new ValidationGenericException(bindingResult);
}
}
GuiFragmentDto fragment = this.getGuiFragmentService().updateGuiFragment(guiFragmentRequest);
return new ResponseEntity<>(new SimpleRestResponse<>(fragment), HttpStatus.OK);
}
use of org.entando.entando.aps.system.exception.ResourceNotFoundException in project entando-core by entando.
the class ProfileController method getUserProfile.
@RestAccessControl(permission = Permission.MANAGE_USER_PROFILES)
@RequestMapping(value = "/userProfiles/{username}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SimpleRestResponse<EntityDto>> getUserProfile(@PathVariable String username) throws JsonProcessingException {
logger.debug("Requested profile -> {}", username);
EntityDto dto;
if (!this.getProfileValidator().existProfile(username)) {
if (userExists(username)) {
// if the user exists but the profile doesn't, creates an empty profile
IUserProfile userProfile = createNewEmptyUserProfile(username);
dto = new EntityDto(userProfile);
} else {
throw new ResourceNotFoundException(EntityValidator.ERRCODE_ENTITY_DOES_NOT_EXIST, "Profile", username);
}
} else {
dto = this.getUserProfileService().getUserProfile(username);
}
logger.debug("Main Response -> {}", dto);
return new ResponseEntity<>(new SimpleRestResponse<>(dto), HttpStatus.OK);
}
use of org.entando.entando.aps.system.exception.ResourceNotFoundException in project entando-core by entando.
the class GuiFragmentService method updateGuiFragment.
@Override
public GuiFragmentDto updateGuiFragment(GuiFragmentRequestBody guiFragmentRequest) {
String code = guiFragmentRequest.getCode();
try {
GuiFragment fragment = this.getGuiFragmentManager().getGuiFragment(code);
if (null == fragment) {
throw new ResourceNotFoundException(GuiFragmentValidator.ERRCODE_FRAGMENT_DOES_NOT_EXISTS, "fragment", code);
}
fragment.setGui(guiFragmentRequest.getGuiCode());
this.getGuiFragmentManager().updateGuiFragment(fragment);
return this.getDtoBuilder().convert(fragment);
} catch (ResourceNotFoundException e) {
throw e;
} catch (ApsSystemException e) {
logger.error("Error updating fragment {}", code, e);
throw new RestServerError("error in update fragment", e);
}
}
Aggregations