Search in sources :

Example 6 with IPage

use of com.agiletec.aps.system.services.page.IPage in project entando-core by entando.

the class PageService method movePage.

@Override
public PageDto movePage(String pageCode, PagePositionRequest pageRequest) {
    IPage parent = this.getPageManager().getDraftPage(pageRequest.getParentCode()), page = this.getPageManager().getDraftPage(pageCode);
    boolean moved = true;
    int iterations = Math.abs(page.getPosition() - pageRequest.getPosition());
    boolean moveUp = page.getPosition() > pageRequest.getPosition();
    try {
        if (page.getParentCode().equals(parent.getCode())) {
            while (iterations-- > 0 && (moved = this.getPageManager().movePage(pageCode, moveUp))) ;
        } else {
            moved = this.getPageManager().movePage(page, parent);
        }
        page = this.getPageManager().getDraftPage(pageCode);
    } catch (ApsSystemException e) {
        logger.error("Error moving page {}", pageCode, e);
        throw new RestServerError("error in moving page", e);
    }
    return this.getDtoBuilder().convert(page);
}
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 7 with IPage

use of com.agiletec.aps.system.services.page.IPage in project entando-core by entando.

the class PageService method updatePage.

private IPage updatePage(IPage oldPage, PageRequest pageRequest) {
    Page page = new Page();
    page.setCode(pageRequest.getCode());
    page.setShowable(pageRequest.isDisplayedInMenu());
    if (oldPage.getModel().getCode().equals(pageRequest.getPageModel())) {
        PageModel model = this.getPageModelManager().getPageModel(pageRequest.getPageModel());
        page.setModel(model);
    }
    page.setCharset(pageRequest.getCharset());
    page.setMimeType(pageRequest.getContentType());
    page.setParentCode(pageRequest.getParentCode());
    page.setUseExtraTitles(pageRequest.isSeo());
    Optional<Map<String, String>> titles = Optional.ofNullable(pageRequest.getTitles());
    ApsProperties apsTitles = new ApsProperties();
    titles.ifPresent(values -> values.keySet().forEach((lang) -> {
        apsTitles.put(lang, values.get(lang));
    }));
    page.setTitles(apsTitles);
    page.setGroup(pageRequest.getOwnerGroup());
    Optional<List<String>> groups = Optional.ofNullable(pageRequest.getJoinGroups());
    groups.ifPresent(values -> values.forEach((group) -> {
        page.addExtraGroup(group);
    }));
    page.setParentCode(pageRequest.getParentCode());
    PageMetadata metadata = oldPage.getMetadata();
    if (metadata == null) {
        metadata = new PageMetadata();
    }
    this.valueMetadataFromRequest(metadata, pageRequest);
    page.setMetadata(metadata);
    return page;
}
Also used : Arrays(java.util.Arrays) Page(com.agiletec.aps.system.services.page.Page) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) ApsProperties(com.agiletec.aps.util.ApsProperties) IWidgetTypeManager(org.entando.entando.aps.system.services.widgettype.IWidgetTypeManager) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) IPage(com.agiletec.aps.system.services.page.IPage) PageConfigurationDto(org.entando.entando.aps.system.services.page.model.PageConfigurationDto) PageDto(org.entando.entando.aps.system.services.page.model.PageDto) RestServerError(org.entando.entando.aps.system.exception.RestServerError) IGroupManager(com.agiletec.aps.system.services.group.IGroupManager) IPageManager(com.agiletec.aps.system.services.page.IPageManager) WidgetValidatorFactory(org.entando.entando.aps.system.services.widgettype.validators.WidgetValidatorFactory) Widget(com.agiletec.aps.system.services.page.Widget) Map(java.util.Map) IManager(com.agiletec.aps.system.common.IManager) PagePositionRequest(org.entando.entando.web.page.model.PagePositionRequest) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) WidgetConfigurationRequest(org.entando.entando.web.page.model.WidgetConfigurationRequest) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) GroupServiceUtilizer(org.entando.entando.aps.system.services.group.GroupServiceUtilizer) Logger(org.slf4j.Logger) PageRequest(org.entando.entando.web.page.model.PageRequest) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) PageMetadata(com.agiletec.aps.system.services.page.PageMetadata) List(java.util.List) GroupUtilizer(com.agiletec.aps.system.services.group.GroupUtilizer) WidgetProcessorFactory(org.entando.entando.aps.system.services.widgettype.validators.WidgetProcessorFactory) Optional(java.util.Optional) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) IPageModelManager(com.agiletec.aps.system.services.pagemodel.IPageModelManager) WidgetConfigurationDto(org.entando.entando.aps.system.services.page.model.WidgetConfigurationDto) IDtoBuilder(org.entando.entando.aps.system.services.IDtoBuilder) PageMetadata(com.agiletec.aps.system.services.page.PageMetadata) Page(com.agiletec.aps.system.services.page.Page) IPage(com.agiletec.aps.system.services.page.IPage) ArrayList(java.util.ArrayList) List(java.util.List) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel) Map(java.util.Map) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 8 with IPage

use of com.agiletec.aps.system.services.page.IPage 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 RestRourceNotFoundException(ERRCODE_PAGE_NOT_FOUND, "page", pageCode);
    }
    if (frameId > page.getWidgets().length) {
        throw new RestRourceNotFoundException(ERRCODE_FRAME_INVALID, "frame", String.valueOf(frameId));
    }
    Widget widget = page.getWidgets()[frameId];
    if (null == widget) {
        return null;
    }
    return new WidgetConfigurationDto(widget);
}
Also used : RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) 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)

Example 9 with IPage

use of com.agiletec.aps.system.services.page.IPage in project entando-core by entando.

the class PageService method getPages.

@Override
public List<PageDto> getPages(String parentCode) {
    List<PageDto> res = new ArrayList<>();
    IPage parent = this.getPageManager().getDraftPage(parentCode);
    Optional.ofNullable(parent).ifPresent(root -> Optional.ofNullable(parent.getChildrenCodes()).ifPresent(children -> Arrays.asList(children).forEach(childCode -> {
        IPage childO = this.getPageManager().getOnlinePage(childCode), childD = this.getPageManager().getDraftPage(childCode);
        PageDto child = null;
        if (childO != null) {
            child = dtoBuilder.convert(childO);
            if (childO.isChanged()) {
                child.setStatus(STATUS_DRAFT);
            }
        } else {
            child = dtoBuilder.convert(childD);
            child.setStatus(STATUS_UNPUBLISHED);
        }
        child.setChildren(Arrays.asList(childD.getChildrenCodes()));
        res.add(child);
    })));
    return res;
}
Also used : Arrays(java.util.Arrays) Page(com.agiletec.aps.system.services.page.Page) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) ApsProperties(com.agiletec.aps.util.ApsProperties) IWidgetTypeManager(org.entando.entando.aps.system.services.widgettype.IWidgetTypeManager) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) IPage(com.agiletec.aps.system.services.page.IPage) PageConfigurationDto(org.entando.entando.aps.system.services.page.model.PageConfigurationDto) PageDto(org.entando.entando.aps.system.services.page.model.PageDto) RestServerError(org.entando.entando.aps.system.exception.RestServerError) IGroupManager(com.agiletec.aps.system.services.group.IGroupManager) IPageManager(com.agiletec.aps.system.services.page.IPageManager) WidgetValidatorFactory(org.entando.entando.aps.system.services.widgettype.validators.WidgetValidatorFactory) Widget(com.agiletec.aps.system.services.page.Widget) Map(java.util.Map) IManager(com.agiletec.aps.system.common.IManager) PagePositionRequest(org.entando.entando.web.page.model.PagePositionRequest) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) WidgetConfigurationRequest(org.entando.entando.web.page.model.WidgetConfigurationRequest) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) GroupServiceUtilizer(org.entando.entando.aps.system.services.group.GroupServiceUtilizer) Logger(org.slf4j.Logger) PageRequest(org.entando.entando.web.page.model.PageRequest) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) PageMetadata(com.agiletec.aps.system.services.page.PageMetadata) List(java.util.List) GroupUtilizer(com.agiletec.aps.system.services.group.GroupUtilizer) WidgetProcessorFactory(org.entando.entando.aps.system.services.widgettype.validators.WidgetProcessorFactory) Optional(java.util.Optional) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) IPageModelManager(com.agiletec.aps.system.services.pagemodel.IPageModelManager) WidgetConfigurationDto(org.entando.entando.aps.system.services.page.model.WidgetConfigurationDto) IDtoBuilder(org.entando.entando.aps.system.services.IDtoBuilder) IPage(com.agiletec.aps.system.services.page.IPage) PageDto(org.entando.entando.aps.system.services.page.model.PageDto) ArrayList(java.util.ArrayList)

Example 10 with IPage

use of com.agiletec.aps.system.services.page.IPage in project entando-core by entando.

the class PageService method deleteWidgetConfiguration.

@Override
public void deleteWidgetConfiguration(String pageCode, int frameId) {
    try {
        IPage page = this.loadPage(pageCode, STATUS_DRAFT);
        if (null == page) {
            throw new RestRourceNotFoundException(ERRCODE_PAGE_NOT_FOUND, "page", pageCode);
        }
        if (frameId > page.getWidgets().length) {
            throw new RestRourceNotFoundException(ERRCODE_FRAME_INVALID, "frame", String.valueOf(frameId));
        }
        this.pageManager.removeWidget(pageCode, frameId);
    } catch (ApsSystemException e) {
        logger.error("Error in delete widget configuration for page {} and frame {}", pageCode, frameId, e);
        throw new RestServerError("error in delete widget configuration", e);
    }
}
Also used : RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) IPage(com.agiletec.aps.system.services.page.IPage) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Aggregations

IPage (com.agiletec.aps.system.services.page.IPage)209 Widget (com.agiletec.aps.system.services.page.Widget)43 ArrayList (java.util.ArrayList)33 Page (com.agiletec.aps.system.services.page.Page)21 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)20 PageMetadata (com.agiletec.aps.system.services.page.PageMetadata)18 ApsProperties (com.agiletec.aps.util.ApsProperties)16 RequestContext (com.agiletec.aps.system.RequestContext)15 List (java.util.List)14 WidgetType (org.entando.entando.aps.system.services.widgettype.WidgetType)14 Lang (com.agiletec.aps.system.services.lang.Lang)12 IPageManager (com.agiletec.aps.system.services.page.IPageManager)12 PageModel (com.agiletec.aps.system.services.pagemodel.PageModel)12 HashMap (java.util.HashMap)12 RestServerError (org.entando.entando.aps.system.exception.RestServerError)11 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)10 UserDetails (com.agiletec.aps.system.services.user.UserDetails)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)8 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)8 WidgetConfigurationDto (org.entando.entando.aps.system.services.page.model.WidgetConfigurationDto)8