Search in sources :

Example 1 with PageUtilizer

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

the class AbstractPageActionHelper method getReferencingObjects.

@Override
public Map getReferencingObjects(IPage page, HttpServletRequest request) throws ApsSystemException {
    Map<String, List> references = new HashMap<>();
    try {
        String[] defNames = ApsWebApplicationUtils.getWebApplicationContext(request).getBeanNamesForType(PageUtilizer.class);
        for (int i = 0; i < defNames.length; i++) {
            Object service = null;
            try {
                service = ApsWebApplicationUtils.getWebApplicationContext(request).getBean(defNames[i]);
            } catch (Throwable t) {
                logger.error("error in hasReferencingObjects", t);
                service = null;
            }
            if (service != null) {
                PageUtilizer pageUtilizer = (PageUtilizer) service;
                List utilizers = pageUtilizer.getPageUtilizers(page.getCode());
                if (utilizers != null && !utilizers.isEmpty()) {
                    references.put(pageUtilizer.getName() + "Utilizers", utilizers);
                }
            }
        }
    } catch (Throwable t) {
        throw new ApsSystemException("Error extracting Referencing Objects", t);
    }
    return references;
}
Also used : PageUtilizer(com.agiletec.aps.system.services.page.PageUtilizer) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 2 with PageUtilizer

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

the class PageAction method validate.

@Override
public void validate() {
    super.validate();
    try {
        if (this.getStrutsAction() != ApsAdminSystemConstants.EDIT) {
            return;
        }
        IContentManager contentManager = (IContentManager) ApsWebApplicationUtils.getBean(JacmsSystemConstants.CONTENT_MANAGER, this.getRequest());
        IPage page = this.createTempPage();
        Collection<Content> contents = this.getPublishedContents(this.getPageCode());
        for (Content content : contents) {
            if (null != content && !CmsPageUtil.isContentPublishableOnPageDraft(content, page)) {
                List<String> contentGroups = new ArrayList<String>();
                contentGroups.add(content.getMainGroup());
                if (null != content.getGroups()) {
                    contentGroups.addAll(content.getGroups());
                }
                this.addFieldError("extraGroups", this.getText("error.page.extraGoups.invalidGroupsForPublishedContent", new String[] { contentGroups.toString(), content.getId(), content.getDescription() }));
            }
        }
        List<String> linkingContentsVo = ((PageUtilizer) contentManager).getPageUtilizers(this.getPageCode());
        if (null != linkingContentsVo) {
            for (int i = 0; i < linkingContentsVo.size(); i++) {
                String contentId = linkingContentsVo.get(i);
                Content linkingContent = contentManager.loadContent(contentId, true);
                if (null != linkingContent && !CmsPageUtil.isPageLinkableByContentDraft(page, linkingContent)) {
                    this.addFieldError("extraGroups", this.getText("error.page.extraGoups.pageHasToBeFree", new String[] { linkingContent.getId(), linkingContent.getDescription() }));
                }
            }
        }
    } catch (Throwable t) {
        _logger.error("Error on validate page", t);
        throw new RuntimeException("Error on validate page", t);
    }
}
Also used : PageUtilizer(com.agiletec.aps.system.services.page.PageUtilizer) IPage(com.agiletec.aps.system.services.page.IPage) IContentManager(com.agiletec.plugins.jacms.aps.system.services.content.IContentManager) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) ArrayList(java.util.ArrayList)

Example 3 with PageUtilizer

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

the class PageService method getReferencesInfo.

private Map<String, Boolean> getReferencesInfo(IPage page) {
    Map<String, Boolean> references = new HashMap<>();
    try {
        String[] defNames = applicationContext.getBeanNamesForType(PageUtilizer.class);
        for (String defName : defNames) {
            Object service = null;
            try {
                service = applicationContext.getBean(defName);
            } catch (Throwable t) {
                logger.error("error in hasReferencingObjects", t);
                service = null;
            }
            if (service != null) {
                PageUtilizer pageUtilizer = (PageUtilizer) service;
                List<?> utilizers = pageUtilizer.getPageUtilizers(page.getCode());
                if (utilizers != null && !utilizers.isEmpty()) {
                    references.put(pageUtilizer.getName(), true);
                } else {
                    references.put(pageUtilizer.getName(), false);
                }
            }
        }
    } catch (ApsSystemException ex) {
        logger.error("error loading references for page {}", page.getCode(), ex);
        throw new RestServerError("error in getReferencingObjects ", ex);
    }
    return references;
}
Also used : PageUtilizer(com.agiletec.aps.system.services.page.PageUtilizer) HashMap(java.util.HashMap) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 4 with PageUtilizer

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

the class PageServiceTest method mockPagedMetadata.

/**
 * init mock for a multipaged request
 */
private void mockPagedMetadata(Page page, PageDto pageDto, String[] utilizers, int currPage, int lastPage, int pageSize, int totalSize) {
    try {
        when(pageManager.getDraftPage(page.getCode())).thenReturn(page);
        when(pageTokenManager.encrypt(page.getCode())).thenReturn(PageMockHelper.TOKEN);
        when(dtoBuilder.convert(any(IPage.class))).thenReturn(pageDto);
        when(applicationContext.getBeanNamesForType((Class<?>) any())).thenReturn(PageMockHelper.UTILIZERS);
        when(applicationContext.getBean(anyString())).thenReturn(pageUtilizer);
        when(pageUtilizer.getPageUtilizers(page.getCode())).thenReturn(Arrays.asList(PageMockHelper.UTILIZERS));
        when(pageUtilizer.getName()).thenReturn(PageMockHelper.UTILIZER_1).thenReturn(PageMockHelper.UTILIZER_2);
        PageSearchRequest pageSearchRequest = new PageSearchRequest(PageMockHelper.PAGE_CODE);
        pageSearchRequest.setPageSize(pageSize);
        PageSearchDto pageSearchDto = new PageSearchDto(pageSearchRequest, Collections.singletonList(pageDto));
        pageSearchDto.setPageSize(pageSize);
        pageSearchDto.imposeLimits();
        List<ComponentUsageEntity> componentUsageEntityList = Arrays.stream(utilizers).map(child -> new ComponentUsageEntity(ComponentUsageEntity.TYPE_PAGE, child)).collect(Collectors.toList());
        if (pageDto.getStatus().equals(IPageService.STATUS_ONLINE) && currPage == lastPage) {
            componentUsageEntityList.add(new ComponentUsageEntity(ComponentUsageEntity.TYPE_PAGE, page.getCode()));
        }
        PagedMetadata pagedMetadata = new PagedMetadata(pageSearchRequest, componentUsageEntityList, totalSize);
        pagedMetadata.setPageSize(pageSize);
        pagedMetadata.setPage(currPage);
        pagedMetadata.imposeLimits();
        when(pagedMetadataMapper.getPagedResult(any(), any())).thenReturn(pagedMetadata);
    } catch (Exception e) {
        Assert.fail("Mock Exception");
    }
}
Also used : PageSearchRequest(org.entando.entando.web.page.model.PageSearchRequest) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) IntStream(java.util.stream.IntStream) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) java.util(java.util) Page(com.agiletec.aps.system.services.page.Page) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel) PageUtilizer(com.agiletec.aps.system.services.page.PageUtilizer) Group(com.agiletec.aps.system.services.group.Group) PageAssertionHelper(org.entando.entando.aps.system.services.assertionhelper.PageAssertionHelper) IPage(com.agiletec.aps.system.services.page.IPage) PageDto(org.entando.entando.aps.system.services.page.model.PageDto) PageSearchDto(org.entando.entando.aps.system.services.page.model.PageSearchDto) IGroupManager(com.agiletec.aps.system.services.group.IGroupManager) IPageManager(com.agiletec.aps.system.services.page.IPageManager) PageMockHelper(org.entando.entando.aps.system.services.mockhelper.PageMockHelper) PagedMetadataMapper(org.entando.entando.web.common.assembler.PagedMetadataMapper) PageSearchMapper(org.entando.entando.web.common.assembler.PageSearchMapper) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) PageSearchRequest(org.entando.entando.web.page.model.PageSearchRequest) PageRequest(org.entando.entando.web.page.model.PageRequest) ComponentUsageEntity(org.entando.entando.web.component.ComponentUsageEntity) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) Assertions.fail(org.assertj.core.api.Assertions.fail) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) IPageModelManager(com.agiletec.aps.system.services.pagemodel.IPageModelManager) Assert(org.junit.Assert) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) IDtoBuilder(org.entando.entando.aps.system.services.IDtoBuilder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) IPage(com.agiletec.aps.system.services.page.IPage) PageSearchDto(org.entando.entando.aps.system.services.page.model.PageSearchDto) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) ComponentUsageEntity(org.entando.entando.web.component.ComponentUsageEntity) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException)

Aggregations

PageUtilizer (com.agiletec.aps.system.services.page.PageUtilizer)4 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)2 IPage (com.agiletec.aps.system.services.page.IPage)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Group (com.agiletec.aps.system.services.group.Group)1 IGroupManager (com.agiletec.aps.system.services.group.IGroupManager)1 IPageManager (com.agiletec.aps.system.services.page.IPageManager)1 Page (com.agiletec.aps.system.services.page.Page)1 IPageModelManager (com.agiletec.aps.system.services.pagemodel.IPageModelManager)1 PageModel (com.agiletec.aps.system.services.pagemodel.PageModel)1 IContentManager (com.agiletec.plugins.jacms.aps.system.services.content.IContentManager)1 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)1 java.util (java.util)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.fail (org.assertj.core.api.Assertions.fail)1 ResourceNotFoundException (org.entando.entando.aps.system.exception.ResourceNotFoundException)1