Search in sources :

Example 56 with RestServerError

use of org.entando.entando.aps.system.exception.RestServerError in project entando-core by entando.

the class PageService method addPage.

@Override
public PageDto addPage(PageRequest pageRequest) {
    this.validateRequest(pageRequest);
    try {
        IPage page = this.createPage(pageRequest);
        this.getPageManager().addPage(page);
        return this.getDtoBuilder().convert(page);
    } catch (ApsSystemException e) {
        logger.error("Error adding page", e);
        throw new RestServerError("error add page", e);
    }
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 57 with RestServerError

use of org.entando.entando.aps.system.exception.RestServerError in project entando-core by entando.

the class PageService method updatePageStatus.

@Override
public PageDto updatePageStatus(String pageCode, String status) {
    IPage newPage = null;
    try {
        if (status != null && status.equals(STATUS_ONLINE)) {
            this.getPageManager().setPageOnline(pageCode);
            newPage = this.getPageManager().getOnlinePage(pageCode);
        } else if (status != null && status.equals(STATUS_DRAFT)) {
            this.getPageManager().setPageOffline(pageCode);
            newPage = this.getPageManager().getDraftPage(pageCode);
        }
        return this.getDtoBuilder().convert(newPage);
    } catch (ApsSystemException e) {
        logger.error("Error updating page {} status", pageCode, e);
        throw new RestServerError("error in update page status", e);
    }
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 58 with RestServerError

use of org.entando.entando.aps.system.exception.RestServerError in project entando-core by entando.

the class PageModelService method addPageModel.

@Override
public PageModelDto addPageModel(PageModelRequest pageModelRequest) {
    try {
        BeanPropertyBindingResult validationResult = this.validateAdd(pageModelRequest);
        if (validationResult.hasErrors()) {
            throw new ValidationConflictException(validationResult);
        }
        PageModel pageModel = this.createPageModel(pageModelRequest);
        this.getPageModelManager().addPageModel(pageModel);
        return this.getDtoBuilder().convert(pageModel);
    } catch (ApsSystemException e) {
        logger.error("Error in add pageModel", e);
        throw new RestServerError("error in add pageModel", e);
    }
}
Also used : BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException)

Example 59 with RestServerError

use of org.entando.entando.aps.system.exception.RestServerError in project entando-core by entando.

the class PageModelService method updatePageModel.

@Override
public PageModelDto updatePageModel(PageModelRequest pageModelRequest) {
    try {
        PageModel pageModel = this.getPageModelManager().getPageModel(pageModelRequest.getCode());
        if (null == pageModel) {
            throw new RestRourceNotFoundException(PageModelValidator.ERRCODE_PAGEMODEL_NOT_FOUND, "pageModel", pageModelRequest.getCode());
        }
        this.copyProperties(pageModelRequest, pageModel);
        this.getPageModelManager().updatePageModel(pageModel);
        return this.getDtoBuilder().convert(pageModel);
    } catch (ApsSystemException e) {
        logger.error("Error in update pageModel {}", pageModelRequest.getCode(), e);
        throw new RestServerError("error in update pageMdel", e);
    }
}
Also used : RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel)

Example 60 with RestServerError

use of org.entando.entando.aps.system.exception.RestServerError 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 RestRourceNotFoundException(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 ValidationConflictException(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) RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) UserDto(org.entando.entando.aps.system.services.user.model.UserDto) LoggerFactory(org.slf4j.LoggerFactory) RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) 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) 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) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException) 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) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException)

Aggregations

RestServerError (org.entando.entando.aps.system.exception.RestServerError)65 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)45 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)28 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)25 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)13 ArrayList (java.util.ArrayList)12 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)12 IPage (com.agiletec.aps.system.services.page.IPage)10 List (java.util.List)10 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)9 PagedMetadata (org.entando.entando.web.common.model.PagedMetadata)8 LoggerFactory (org.slf4j.LoggerFactory)8 FieldSearchFilter (com.agiletec.aps.system.common.FieldSearchFilter)7 RestListRequest (org.entando.entando.web.common.model.RestListRequest)7 Logger (org.slf4j.Logger)7 ApsProperties (com.agiletec.aps.util.ApsProperties)6 Group (com.agiletec.aps.system.services.group.Group)5 GroupUtilizer (com.agiletec.aps.system.services.group.GroupUtilizer)5 IDtoBuilder (org.entando.entando.aps.system.services.IDtoBuilder)5 Category (com.agiletec.aps.system.services.category.Category)4