use of com.agiletec.aps.system.services.page.IPage in project entando-core by entando.
the class PageManagerCacheWrapper method addDraftPage.
@Override
public void addDraftPage(IPage page) {
Cache cache = this.getCache();
this.addCodeFromCachedList(cache, DRAFT_PAGE_CODES_CACHE_NAME, page.getCode());
((Page) page).setChildrenCodes(new String[0]);
IPage parent = this.getDraftPage(page.getParentCode());
String[] childCodes = parent.getChildrenCodes();
boolean containsChild = Arrays.stream(childCodes).anyMatch(page.getCode()::equals);
if (!containsChild) {
childCodes = ArrayUtils.add(childCodes, page.getCode());
((Page) parent).setChildrenCodes(childCodes);
cache.put(DRAFT_PAGE_CACHE_NAME_PREFIX + parent.getCode(), parent);
}
cache.put(DRAFT_PAGE_CACHE_NAME_PREFIX + page.getCode(), page);
this.checkRootModification(page, false, cache);
this.checkRootModification(parent, false, cache);
this.cleanLocalCache(cache);
PagesStatus status = this.getPagesStatus();
status.setLastUpdate(new Date());
status.setUnpublished(status.getUnpublished() + 1);
cache.put(PAGE_STATUS_CACHE_NAME, status);
}
use of com.agiletec.aps.system.services.page.IPage in project entando-core by entando.
the class PageManagerCacheWrapper method updatePositionAndParent.
private void updatePositionAndParent(String pageCode, int newPosition, String newParent, boolean draft, Cache cache) {
IPage page = (draft) ? this.getDraftPage(pageCode) : this.getOnlinePage(pageCode);
if (null != page) {
page.setPosition(newPosition);
if (null != newParent) {
page.setParentCode(newParent);
}
cache.put(((draft) ? DRAFT_PAGE_CACHE_NAME_PREFIX : ONLINE_PAGE_CACHE_NAME_PREFIX) + page.getCode(), page);
}
}
use of com.agiletec.aps.system.services.page.IPage in project entando-core by entando.
the class PageManagerCacheWrapper method updateDraftPage.
@Override
public void updateDraftPage(IPage page) {
IPage onlinepage = this.getOnlinePage(page.getCode());
PageMetadata onlineMeta = (null != onlinepage) ? onlinepage.getMetadata() : null;
Widget[] widgetsOnline = (null != onlinepage) ? onlinepage.getWidgets() : new Widget[0];
((Page) page).setOnline(null != onlineMeta);
boolean isChanged = (null != onlinepage) && this.isChanged(page.getMetadata(), onlineMeta, page.getWidgets(), widgetsOnline);
((Page) page).setChanged(isChanged);
Cache cache = this.getCache();
cache.put(DRAFT_PAGE_CACHE_NAME_PREFIX + page.getCode(), page);
this.checkRootModification(page, false, cache);
this.cleanLocalCache(cache);
if (isChanged) {
PagesStatus status = this.getPagesStatus();
status.setLastUpdate(new Date());
status.setOnlineWithChanges(status.getOnlineWithChanges() + 1);
status.setOnline(status.getOnline() - 1);
cache.put(PAGE_STATUS_CACHE_NAME, status);
}
}
use of com.agiletec.aps.system.services.page.IPage in project entando-core by entando.
the class PageManagerCacheWrapper method setPageOnline.
@Override
public void setPageOnline(String pageCode) {
Cache cache = this.getCache();
IPage page = this.getDraftPage(pageCode);
if (null != page) {
this.addCodeFromCachedList(cache, ONLINE_PAGE_CODES_CACHE_NAME, page.getCode());
IPage onlinepage = this.getOnlinePage(page.getCode());
boolean alreadyOnline = null != onlinepage;
boolean changed = (alreadyOnline && this.isChanged(page.getMetadata(), onlinepage.getMetadata(), page.getWidgets(), onlinepage.getWidgets()));
((Page) page).setOnline(true);
((Page) page).setChanged(false);
IPage newOnlinePage = page.clone();
((Page) newOnlinePage).setOnlineInstance(true);
List<String> totalOnlineCodes = (List<String>) this.get(cache, ONLINE_PAGE_CODES_CACHE_NAME, List.class);
List<String> onLineCodes = Arrays.asList(newOnlinePage.getChildrenCodes()).stream().filter(code -> null != this.getOnlinePage(code) && totalOnlineCodes.contains(code)).collect(Collectors.toList());
((Page) newOnlinePage).setChildrenCodes(onLineCodes.toArray(new String[onLineCodes.size()]));
cache.put(ONLINE_PAGE_CACHE_NAME_PREFIX + newOnlinePage.getCode(), newOnlinePage);
this.checkRootModification(newOnlinePage, true, cache);
cache.put(DRAFT_PAGE_CACHE_NAME_PREFIX + page.getCode(), page);
this.checkRootModification(page, false, cache);
if (!alreadyOnline) {
IPage parentOnLine = this.getOnlinePage(newOnlinePage.getParentCode());
if (null != parentOnLine && !parentOnLine.getCode().equals(pageCode)) {
IPage parentDraft = this.getDraftPage(newOnlinePage.getParentCode());
List<String> draftChildrenCodes = Arrays.asList(parentDraft.getChildrenCodes());
List<String> newOnLineCodesForParent = draftChildrenCodes.stream().filter(code -> null != this.getOnlinePage(code) && totalOnlineCodes.contains(code)).collect(Collectors.toList());
((Page) parentOnLine).setChildrenCodes(newOnLineCodesForParent.toArray(new String[newOnLineCodesForParent.size()]));
cache.put(ONLINE_PAGE_CACHE_NAME_PREFIX + parentOnLine.getCode(), parentOnLine);
this.checkRootModification(parentOnLine, true, cache);
}
}
if (!alreadyOnline || changed) {
PagesStatus status = this.getPagesStatus();
status.setLastUpdate(new Date());
if (!alreadyOnline) {
status.setOnline(status.getOnline() + 1);
status.setUnpublished(status.getUnpublished() - 1);
} else if (changed) {
status.setOnlineWithChanges(status.getOnlineWithChanges() + 1);
status.setOnline(status.getOnline() - 1);
}
cache.put(PAGE_STATUS_CACHE_NAME, status);
}
}
this.cleanLocalCache(cache);
}
use of com.agiletec.aps.system.services.page.IPage in project entando-core by entando.
the class URLManager method getURLString.
/**
* Crea un URL completo ad una pagina del portale a partire dalle
* informazioni essenziali contenute nell'oggetto pageUrl passato come
* parametro.<br>
* In questa implementazione, l'URL è costruito come concatenazione dei
* seguenti elementi:
* <ul>
* <li>parametro di configurazione PAR_APPL_BASE_URL, che rappresenta l'URL
* base della web application così come viene visto dall'esterno; deve
* comprendere la stringa "http://" e deve terminare con "/";</li>
* <li>codice della lingua impostata nell'oggetto pageUrl, oppure la lingua
* corrente, oppure la lingua di default;</li>
* <li>se il parametro "urlStyle" è settato a "classic", codice della pagina
* corrente impostata nell'oggetto pageUrl seguito dal suffisso ".page",
* altrimenti, se il parametro "urlStyle" è settato a "breadcrumbs",
* "/pages/" seguito dal'insieme del codici pagina dalla root alla pagina
* corrente separati da "/";</li>
* <li>eventuale query string se sull'oggetto pageUrl sono stati impostati
* parametri.</li>
* </ul>
*
* @param pageUrl L'oggetto contenente le informazioni da tradurre in URL.
* @param reqCtx Il contesto della richiesta.
* @return La Stringa contenente l'URL.
* @see com.agiletec.aps.system.services.url.AbstractURLManager#getURLString(com.agiletec.aps.system.services.url.PageURL,
* com.agiletec.aps.system.RequestContext)
*/
@Override
public String getURLString(PageURL pageUrl, RequestContext reqCtx) {
try {
String langCode = pageUrl.getLangCode();
Lang lang = this.getLangManager().getLang(langCode);
if (lang == null && null != reqCtx) {
lang = (Lang) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG);
}
if (lang == null) {
lang = this.getLangManager().getDefaultLang();
}
String pageCode = pageUrl.getPageCode();
IPage page = this.getPageManager().getOnlinePage(pageCode);
if (page == null && null != reqCtx) {
page = (IPage) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_PAGE);
}
if (page == null) {
page = this.getPageManager().getOnlineRoot();
}
HttpServletRequest request = (null != reqCtx) ? reqCtx.getRequest() : null;
String url = this.createURL(page, lang, pageUrl.getParams(), pageUrl.isEscapeAmp(), request);
if (null != reqCtx && this.useJsessionId()) {
HttpServletResponse resp = reqCtx.getResponse();
String encUrl = resp.encodeURL(url.toString());
return encUrl;
} else {
return url;
}
} catch (Throwable t) {
_logger.error("Error creating url", t);
throw new RuntimeException("Error creating url", t);
}
}
Aggregations