Search in sources :

Example 6 with ResourceNotFoundException

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

the class ProfileTypeController method updateUserProfileType.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/profileTypes/{profileTypeCode}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SimpleRestResponse<UserProfileTypeDto>> updateUserProfileType(@PathVariable String profileTypeCode, @Valid @RequestBody ProfileTypeDtoRequest request, BindingResult bindingResult) throws JsonProcessingException {
    int result = this.getProfileTypeValidator().validateBodyName(profileTypeCode, request, bindingResult);
    if (bindingResult.hasErrors()) {
        if (result == 404) {
            throw new ResourceNotFoundException(AbstractEntityTypeValidator.ERRCODE_ENTITY_TYPE_DOES_NOT_EXIST, "profile type", profileTypeCode);
        } else {
            throw new ValidationGenericException(bindingResult);
        }
    }
    UserProfileTypeDto dto = this.getUserProfileTypeService().updateUserProfileType(request, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    logger.debug("Main Response -> {}", dto);
    return new ResponseEntity<>(new SimpleRestResponse<>(dto), HttpStatus.OK);
}
Also used : UserProfileTypeDto(org.entando.entando.aps.system.services.userprofile.model.UserProfileTypeDto) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl)

Example 7 with ResourceNotFoundException

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

the class PageService method restorePageConfiguration.

@Override
public PageConfigurationDto restorePageConfiguration(String pageCode) {
    try {
        IPage pageD = this.loadPage(pageCode, STATUS_DRAFT);
        if (null == pageD) {
            throw new ResourceNotFoundException(ERRCODE_PAGE_NOT_FOUND, "page", pageCode);
        }
        IPage pageO = this.loadPage(pageCode, STATUS_ONLINE);
        if (null == pageO) {
            DataBinder binder = new DataBinder(pageCode);
            BindingResult bindingResult = binder.getBindingResult();
            bindingResult.reject(ERRCODE_STATUS_INVALID, new String[] { pageCode }, "page.status.invalid");
            throw new ValidationGenericException(bindingResult);
        }
        pageD.setMetadata(pageO.getMetadata());
        pageD.setWidgets(pageO.getWidgets());
        this.getPageManager().updatePage(pageD);
        PageConfigurationDto pageConfigurationDto = new PageConfigurationDto(pageO, STATUS_ONLINE);
        return pageConfigurationDto;
    } catch (ApsSystemException e) {
        logger.error("Error restoring page {} configuration", pageCode, e);
        throw new RestServerError("error in restoring page configuration", e);
    }
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) BindingResult(org.springframework.validation.BindingResult) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) DataBinder(org.springframework.validation.DataBinder) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) PageConfigurationDto(org.entando.entando.aps.system.services.page.model.PageConfigurationDto)

Example 8 with ResourceNotFoundException

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

the class PageService method getWidgetConfiguration.

@Override
public WidgetConfigurationDto getWidgetConfiguration(String pageCode, int frameId, String status) {
    IPage page = this.loadPage(pageCode, status);
    if (null == page) {
        throw new ResourceNotFoundException(ERRCODE_PAGE_NOT_FOUND, "page", pageCode);
    }
    if (frameId > page.getWidgets().length) {
        throw new ResourceNotFoundException(ERRCODE_FRAME_INVALID, "frame", String.valueOf(frameId));
    }
    Widget widget = page.getWidgets()[frameId];
    if (null == widget) {
        return null;
    }
    return new WidgetConfigurationDto(widget);
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) WidgetConfigurationDto(org.entando.entando.aps.system.services.page.model.WidgetConfigurationDto) Widget(com.agiletec.aps.system.services.page.Widget) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException)

Example 9 with ResourceNotFoundException

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

the class PageService method updatePage.

@Override
public PageDto updatePage(String pageCode, PageRequest pageRequest) {
    IPage oldPage = this.getPageManager().getDraftPage(pageCode);
    if (null == oldPage) {
        throw new ResourceNotFoundException(null, "page", pageCode);
    }
    this.validateRequest(pageRequest);
    if (!oldPage.getGroup().equals(pageRequest.getOwnerGroup())) {
        BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(oldPage, "page");
        bindingResult.reject(PageValidator.ERRCODE_GROUP_MISMATCH, new String[] { oldPage.getGroup(), pageRequest.getOwnerGroup() }, "page.update.group.invalid");
        throw new ValidationGenericException(bindingResult);
    }
    try {
        if (!oldPage.getParentCode().equals(pageRequest.getParentCode())) {
            PagePositionRequest pagePositionRequest = new PagePositionRequest();
            pagePositionRequest.setParentCode(pageRequest.getParentCode());
            pagePositionRequest.setCode(pageCode);
            int position = this.getPages(pageCode).size() + 1;
            pagePositionRequest.setPosition(position);
            this.movePage(pageCode, pagePositionRequest);
            oldPage = this.getPageManager().getDraftPage(pageCode);
        }
        IPage newPage = this.updatePage(oldPage, pageRequest);
        this.getPageManager().updatePage(newPage);
        IPage updatePage = this.getPageManager().getDraftPage(pageCode);
        PageDto page = this.getDtoBuilder().convert(updatePage);
        page.setPosition(oldPage.getPosition());
        return page;
    } catch (ApsSystemException e) {
        logger.error("Error updating page {}", pageCode, e);
        throw new RestServerError("error in update page", e);
    }
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) PageDto(org.entando.entando.aps.system.services.page.model.PageDto) PagePositionRequest(org.entando.entando.web.page.model.PagePositionRequest) 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 10 with ResourceNotFoundException

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

the class PageService method getPageReferences.

@Override
public PagedMetadata<?> getPageReferences(String pageCode, String managerName, RestListRequest requestList) {
    IPage page = this.getPageManager().getDraftPage(pageCode);
    if (null == page) {
        logger.warn("no page found with code {}", pageCode);
        throw new ResourceNotFoundException(ERRCODE_PAGE_NOT_FOUND, "page", pageCode);
    }
    PageServiceUtilizer<?> utilizer = this.getPageServiceUtilizer(managerName);
    if (null == utilizer) {
        logger.warn("no references found for {}", managerName);
        throw new ResourceNotFoundException(ERRCODE_PAGE_REFERENCES, "reference", managerName);
    }
    List<?> dtoList = utilizer.getPageUtilizer(pageCode);
    List<?> subList = requestList.getSublist(dtoList);
    SearcherDaoPaginatedResult<?> pagedResult = new SearcherDaoPaginatedResult<>(dtoList.size(), subList);
    PagedMetadata<Object> pagedMetadata = new PagedMetadata<>(requestList, pagedResult);
    pagedMetadata.setBody((List<Object>) subList);
    return pagedMetadata;
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException)

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