Search in sources :

Example 26 with ResourceNotFoundException

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);
    }
}
Also used : Role(com.agiletec.aps.system.services.role.Role) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) JsonPatchService(org.entando.entando.aps.system.services.jsonpatch.JsonPatchService) UserDto(org.entando.entando.aps.system.services.user.model.UserDto) LoggerFactory(org.slf4j.LoggerFactory) Role(com.agiletec.aps.system.services.role.Role) RoleValidator(org.entando.entando.web.role.validator.RoleValidator) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) RestServerError(org.entando.entando.aps.system.exception.RestServerError) IRoleManager(com.agiletec.aps.system.services.role.IRoleManager) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) JsonNode(com.fasterxml.jackson.databind.JsonNode) IAuthorizationService(com.agiletec.aps.system.services.authorization.IAuthorizationService) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RoleRequest(org.entando.entando.web.role.model.RoleRequest) Permission(com.agiletec.aps.system.services.role.Permission) Logger(org.slf4j.Logger) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) DtoBuilder(org.entando.entando.aps.system.services.DtoBuilder) Collectors(java.util.stream.Collectors) List(java.util.List) RestListRequest(org.entando.entando.web.common.model.RestListRequest) PermissionDto(org.entando.entando.aps.system.services.role.model.PermissionDto) RoleDto(org.entando.entando.aps.system.services.role.model.RoleDto) Filter(org.entando.entando.web.common.model.Filter) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) PostConstruct(javax.annotation.PostConstruct) Comparator(java.util.Comparator) IDtoBuilder(org.entando.entando.aps.system.services.IDtoBuilder) RoleDto(org.entando.entando.aps.system.services.role.model.RoleDto) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException)

Example 27 with ResourceNotFoundException

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;
}
Also used : Role(com.agiletec.aps.system.services.role.Role) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) UserDto(org.entando.entando.aps.system.services.user.model.UserDto) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException)

Example 28 with ResourceNotFoundException

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;
}
Also used : Role(com.agiletec.aps.system.services.role.Role) RoleDto(org.entando.entando.aps.system.services.role.model.RoleDto) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException)

Example 29 with ResourceNotFoundException

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);
        }
    });
}
Also used : PageSearchRequest(org.entando.entando.web.page.model.PageSearchRequest) PageDto(org.entando.entando.aps.system.services.page.model.PageDto) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) Test(org.junit.Test)

Example 30 with 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");
    }
}
Also used : Category(com.agiletec.aps.system.services.category.Category) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException)

Aggregations

ResourceNotFoundException (org.entando.entando.aps.system.exception.ResourceNotFoundException)53 RestServerError (org.entando.entando.aps.system.exception.RestServerError)27 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)20 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)16 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)15 IPage (com.agiletec.aps.system.services.page.IPage)9 RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)9 Category (com.agiletec.aps.system.services.category.Category)7 PagedMetadata (org.entando.entando.web.common.model.PagedMetadata)7 ResponseEntity (org.springframework.http.ResponseEntity)7 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)6 List (java.util.List)6 ArrayList (java.util.ArrayList)5 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)5 PageDto (org.entando.entando.aps.system.services.page.model.PageDto)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 CategoryUtilizer (com.agiletec.aps.system.services.category.CategoryUtilizer)3 Group (com.agiletec.aps.system.services.group.Group)3 Widget (com.agiletec.aps.system.services.page.Widget)3 Role (com.agiletec.aps.system.services.role.Role)3