use of org.entando.entando.aps.system.exception.ResourceNotFoundException in project entando-core by entando.
the class RoleService method updateRole.
@Override
public RoleDto updateRole(RoleRequest roleRequest) {
try {
Role role = this.getRoleManager().getRole(roleRequest.getCode());
if (null == role) {
logger.warn("no role found with code {}", roleRequest.getCode());
throw new ResourceNotFoundException(RoleValidator.ERRCODE_ROLE_NOT_FOUND, "role", roleRequest.getCode());
}
role.setDescription(roleRequest.getName());
role.getPermissions().clear();
if (null != roleRequest.getPermissions()) {
roleRequest.getPermissions().entrySet().stream().filter(entry -> null != entry.getValue() && entry.getValue().booleanValue()).forEach(i -> role.addPermission(i.getKey()));
}
BeanPropertyBindingResult validationResult = this.validateRoleForUpdate(role);
if (validationResult.hasErrors()) {
throw new ValidationGenericException(validationResult);
}
this.getRoleManager().updateRole(role);
RoleDto dto = this.getDtoBuilder().toDto(role, this.getRoleManager().getPermissionsCodes());
return dto;
} catch (ApsSystemException e) {
logger.error("Error updating a role", e);
throw new RestServerError("error in update role", e);
}
}
use of org.entando.entando.aps.system.exception.ResourceNotFoundException in project entando-core by entando.
the class RoleService method getRoleReferences.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public PagedMetadata<UserDto> getRoleReferences(String roleCode, RestListRequest restRequest) {
Role role = this.getRoleManager().getRole(roleCode);
if (null == role) {
logger.warn("no role found with code {}", roleCode);
throw new ResourceNotFoundException(RoleValidator.ERRCODE_ROLE_NOT_FOUND, "role", roleCode);
}
List<UserDto> dtoList = this.getAuthorizationService().getRoleUtilizer(roleCode);
List<UserDto> subList = restRequest.getSublist(dtoList);
SearcherDaoPaginatedResult<UserDto> pagedResult = new SearcherDaoPaginatedResult(dtoList.size(), subList);
PagedMetadata<UserDto> pagedMetadata = new PagedMetadata<>(restRequest, pagedResult);
pagedMetadata.setBody(subList);
return pagedMetadata;
}
use of org.entando.entando.aps.system.exception.ResourceNotFoundException in project entando-core by entando.
the class RoleService method getRole.
@Override
public RoleDto getRole(String roleCode) {
Role role = this.getRoleManager().getRole(roleCode);
if (null == role) {
logger.warn("no role found with code {}", roleCode);
throw new ResourceNotFoundException(RoleValidator.ERRCODE_ROLE_NOT_FOUND, "role", roleCode);
}
RoleDto dto = this.getDtoBuilder().toDto(role, this.getRoleManager().getPermissionsCodes());
return dto;
}
use of org.entando.entando.aps.system.exception.ResourceNotFoundException in project entando-core by entando.
the class PageServiceTest method getPageUsageDetailsWithInvalidCodeShouldThrowResourceNotFoundException.
@Test
public void getPageUsageDetailsWithInvalidCodeShouldThrowResourceNotFoundException() {
PageDto pageDto = PageMockHelper.mockPageDto();
mockForSinglePage(PageMockHelper.mockTestPage(PageMockHelper.PAGE_CODE), pageDto, PageMockHelper.UTILIZERS);
Arrays.stream(new String[] { "not existing", null, "" }).forEach(code -> {
try {
pageService.getComponentUsageDetails(code, new PageSearchRequest(PageMockHelper.PAGE_CODE));
fail("ResourceNotFoundException NOT thrown with code " + code);
} catch (Exception e) {
assertTrue(e instanceof ResourceNotFoundException);
}
});
}
use of org.entando.entando.aps.system.exception.ResourceNotFoundException in project entando-core by entando.
the class CategoryValidator method validatePutReferences.
public void validatePutReferences(String categoryCode, CategoryDto request, BindingResult bindingResult) {
if (!StringUtils.equals(categoryCode, request.getCode())) {
bindingResult.rejectValue("code", ERRCODE_URINAME_MISMATCH, new String[] { categoryCode, request.getCode() }, "category.code.mismatch");
throw new ValidationGenericException(bindingResult);
}
Category category = this.getCategoryManager().getCategory(request.getCode());
if (null == category) {
bindingResult.reject(ERRCODE_CATEGORY_NOT_FOUND, new String[] { request.getCode() }, "category.notexists");
throw new ResourceNotFoundException(bindingResult);
}
Category parent = this.getCategoryManager().getCategory(request.getParentCode());
if (null == parent) {
bindingResult.reject(ERRCODE_PARENT_CATEGORY_NOT_FOUND, new String[] { request.getCode() }, "category.parent.notexists");
throw new ResourceNotFoundException(bindingResult);
} else if (!parent.getCode().equals(category.getParentCode())) {
bindingResult.reject(ERRCODE_PARENT_CATEGORY_CANNOT_BE_CHANGED, new String[] {}, "category.parent.cannotBeChanged");
}
}
Aggregations