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;
}
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);
}
}
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;
}
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");
}
}
Aggregations