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