Search in sources :

Example 46 with ResourceNotFoundException

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

the class GroupService method updateGroup.

@Override
public GroupDto updateGroup(String groupCode, String descr) {
    Group group = this.getGroupManager().getGroup(groupCode);
    if (null == group) {
        throw new ResourceNotFoundException(GroupValidator.ERRCODE_GROUP_NOT_FOUND, "group", groupCode);
    }
    group.setDescription(descr);
    try {
        this.getGroupManager().updateGroup(group);
        return this.getDtoBuilder().convert(group);
    } catch (ApsSystemException e) {
        logger.error("Error updating group {}", groupCode, e);
        throw new RestServerError("error in update group", e);
    }
}
Also used : Group(com.agiletec.aps.system.services.group.Group) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException)

Example 47 with ResourceNotFoundException

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

the class PageService method updateWidgetConfiguration.

@Override
public WidgetConfigurationDto updateWidgetConfiguration(String pageCode, int frameId, WidgetConfigurationRequest widgetReq) {
    try {
        IPage page = this.loadPage(pageCode, STATUS_DRAFT);
        if (null == page) {
            throw new ResourceNotFoundException(ERRCODE_PAGE_NOT_FOUND, "page", pageCode);
        }
        if (page.getWidgets() == null || frameId > page.getWidgets().length) {
            throw new ResourceNotFoundException(ERRCODE_FRAME_INVALID, "frame", String.valueOf(frameId));
        }
        if (null == this.getWidgetType(widgetReq.getCode())) {
            throw new ResourceNotFoundException(ERRCODE_WIDGET_INVALID, "widget", String.valueOf(widgetReq.getCode()));
        }
        BeanPropertyBindingResult validation = this.getWidgetValidatorFactory().get(widgetReq.getCode()).validate(widgetReq, page);
        if (null != validation && validation.hasErrors()) {
            throw new ValidationConflictException(validation);
        }
        ApsProperties properties = (ApsProperties) this.getWidgetProcessorFactory().get(widgetReq.getCode()).buildConfiguration(widgetReq);
        WidgetType widgetType = this.getWidgetType(widgetReq.getCode());
        Widget widget = new Widget();
        widget.setType(widgetType);
        widget.setConfig(properties);
        this.getPageManager().joinWidget(pageCode, widget, frameId);
        ApsProperties outProperties = this.getWidgetProcessorFactory().get(widgetReq.getCode()).extractConfiguration(widget.getConfig());
        return new WidgetConfigurationDto(widget.getType().getCode(), outProperties);
    } catch (ApsSystemException e) {
        logger.error("Error in update widget configuration {}", pageCode, e);
        throw new RestServerError("error in update widget configuration", e);
    }
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) WidgetConfigurationDto(org.entando.entando.aps.system.services.page.model.WidgetConfigurationDto) RestServerError(org.entando.entando.aps.system.exception.RestServerError) Widget(com.agiletec.aps.system.services.page.Widget) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 48 with ResourceNotFoundException

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

the class PageService method getPage.

@Override
public PageDto getPage(String pageCode, String status) {
    IPage page = this.loadPage(pageCode, status);
    if (null == page) {
        logger.warn("no page found with code {} and status {}", pageCode, status);
        DataBinder binder = new DataBinder(pageCode);
        BindingResult bindingResult = binder.getBindingResult();
        String errorCode = status.equals(STATUS_DRAFT) ? ERRCODE_PAGE_NOT_FOUND : ERRCODE_PAGE_ONLY_DRAFT;
        bindingResult.reject(errorCode, new String[] { pageCode, status }, "page.NotFound");
        throw new ResourceNotFoundException(bindingResult);
    }
    String token = this.getPageTokenManager().encrypt(pageCode);
    PageDto pageDto = this.getDtoBuilder().convert(page);
    pageDto.setToken(token);
    pageDto.setReferences(this.getReferencesInfo(page));
    return pageDto;
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) BindingResult(org.springframework.validation.BindingResult) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) PageDto(org.entando.entando.aps.system.services.page.model.PageDto) DataBinder(org.springframework.validation.DataBinder) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException)

Example 49 with ResourceNotFoundException

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

the class PageService method applyDefaultWidgets.

@Override
public PageConfigurationDto applyDefaultWidgets(String pageCode) {
    try {
        IPage page = this.loadPage(pageCode, STATUS_DRAFT);
        if (null == page) {
            throw new ResourceNotFoundException(ERRCODE_PAGE_NOT_FOUND, "page", pageCode);
        }
        PageModel pageModel = page.getModel();
        Widget[] defaultWidgets = pageModel.getDefaultWidget();
        if (null == defaultWidgets) {
            logger.info("no default widget configuration for model {}", pageModel.getCode());
            return new PageConfigurationDto(page, STATUS_DRAFT);
        }
        Widget[] widgets = mergePageConfiguration(page, defaultWidgets);
        page.setWidgets(widgets);
        this.getPageManager().updatePage(page);
        return new PageConfigurationDto(page, STATUS_DRAFT);
    } catch (ApsSystemException e) {
        logger.error("Error setting default widgets for page {}", pageCode, e);
        throw new RestServerError("Error setting default widgets for page " + pageCode, e);
    }
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) RestServerError(org.entando.entando.aps.system.exception.RestServerError) Widget(com.agiletec.aps.system.services.page.Widget) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) PageConfigurationDto(org.entando.entando.aps.system.services.page.model.PageConfigurationDto)

Example 50 with ResourceNotFoundException

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

the class PageService method updatePageStatus.

@Override
public PageDto updatePageStatus(String pageCode, String status) {
    IPage currentPage = this.getPageManager().getDraftPage(pageCode);
    BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(pageCode, "page");
    if (null == currentPage) {
        throw new ResourceNotFoundException(ERRCODE_PAGE_NOT_FOUND, "page", pageCode);
    }
    if (status.equals(STATUS_DRAFT) && null == this.getPageManager().getOnlinePage(pageCode)) {
        return this.getDtoBuilder().convert(currentPage);
    }
    try {
        IPage newPage = null;
        if (status.equals(STATUS_ONLINE)) {
            IPage publicParent = this.getPageManager().getOnlinePage(currentPage.getParentCode());
            if (null == publicParent) {
                bindingResult.reject(PageValidator.ERRCODE_PAGE_WITH_NO_PUBLIC_PARENT, new String[] { pageCode, currentPage.getParentCode() }, "page.status.parent.unpublished");
                throw new ValidationGenericException(bindingResult);
            }
            this.getPageManager().setPageOnline(pageCode);
            newPage = this.getPageManager().getOnlinePage(pageCode);
        } else if (status.equals(STATUS_DRAFT)) {
            String[] childCodes = currentPage.getChildrenCodes();
            for (String childCode : childCodes) {
                IPage publicChild = this.getPageManager().getOnlinePage(childCode);
                if (null != publicChild) {
                    bindingResult.reject(PageValidator.ERRCODE_PAGE_WITH_PUBLIC_CHILD, new String[] { pageCode }, "page.status.publicChild");
                    throw new ValidationGenericException(bindingResult);
                }
            }
            Map<String, PageServiceUtilizer> beans = applicationContext.getBeansOfType(PageServiceUtilizer.class);
            if (null != beans) {
                Iterator<PageServiceUtilizer> iter = beans.values().iterator();
                while (iter.hasNext()) {
                    PageServiceUtilizer serviceUtilizer = iter.next();
                    List utilizer = serviceUtilizer.getPageUtilizer(pageCode);
                    if (null != utilizer && utilizer.size() > 0) {
                        bindingResult.reject(PageValidator.ERRCODE_REFERENCED_ONLINE_PAGE, new String[] { pageCode }, "page.status.invalid.online.ref");
                        throw new ValidationGenericException(bindingResult);
                    }
                }
            }
            this.getPageManager().setPageOffline(pageCode);
            newPage = this.getPageManager().getDraftPage(pageCode);
        }
        return this.getDtoBuilder().convert(newPage);
    } catch (ValidationGenericException e) {
        throw e;
    } 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) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RestServerError(org.entando.entando.aps.system.exception.RestServerError) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) Map(java.util.Map) HashMap(java.util.HashMap)

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