Search in sources :

Example 56 with IPage

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);
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) Page(com.agiletec.aps.system.services.page.Page) IPage(com.agiletec.aps.system.services.page.IPage) PagesStatus(com.agiletec.aps.system.services.page.PagesStatus) Date(java.util.Date) Cache(org.springframework.cache.Cache)

Example 57 with IPage

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);
    }
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage)

Example 58 with IPage

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);
    }
}
Also used : PageMetadata(com.agiletec.aps.system.services.page.PageMetadata) IPage(com.agiletec.aps.system.services.page.IPage) Widget(com.agiletec.aps.system.services.page.Widget) Page(com.agiletec.aps.system.services.page.Page) IPage(com.agiletec.aps.system.services.page.IPage) PagesStatus(com.agiletec.aps.system.services.page.PagesStatus) Date(java.util.Date) Cache(org.springframework.cache.Cache)

Example 59 with IPage

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);
}
Also used : IPageDAO(com.agiletec.aps.system.services.page.IPageDAO) Arrays(java.util.Arrays) Page(com.agiletec.aps.system.services.page.Page) Logger(org.slf4j.Logger) Cache(org.springframework.cache.Cache) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) PageRecord(com.agiletec.aps.system.services.page.PageRecord) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) AbstractCacheWrapper(com.agiletec.aps.system.common.AbstractCacheWrapper) HashMap(java.util.HashMap) ArrayUtils(org.apache.commons.lang3.ArrayUtils) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) PagesStatus(com.agiletec.aps.system.services.page.PagesStatus) IPage(com.agiletec.aps.system.services.page.IPage) PageMetadata(com.agiletec.aps.system.services.page.PageMetadata) List(java.util.List) Widget(com.agiletec.aps.system.services.page.Widget) Map(java.util.Map) Collections(java.util.Collections) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) IPage(com.agiletec.aps.system.services.page.IPage) Page(com.agiletec.aps.system.services.page.Page) IPage(com.agiletec.aps.system.services.page.IPage) ArrayList(java.util.ArrayList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) PagesStatus(com.agiletec.aps.system.services.page.PagesStatus) Date(java.util.Date) Cache(org.springframework.cache.Cache)

Example 60 with IPage

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);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IPage(com.agiletec.aps.system.services.page.IPage) HttpServletResponse(javax.servlet.http.HttpServletResponse) Lang(com.agiletec.aps.system.services.lang.Lang)

Aggregations

IPage (com.agiletec.aps.system.services.page.IPage)253 Widget (com.agiletec.aps.system.services.page.Widget)55 ArrayList (java.util.ArrayList)41 Page (com.agiletec.aps.system.services.page.Page)37 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)30 PageMetadata (com.agiletec.aps.system.services.page.PageMetadata)25 HashMap (java.util.HashMap)23 ApsProperties (com.agiletec.aps.util.ApsProperties)20 List (java.util.List)20 RestServerError (org.entando.entando.aps.system.exception.RestServerError)18 IPageManager (com.agiletec.aps.system.services.page.IPageManager)16 UserDetails (com.agiletec.aps.system.services.user.UserDetails)16 ResourceNotFoundException (org.entando.entando.aps.system.exception.ResourceNotFoundException)16 RequestContext (com.agiletec.aps.system.RequestContext)15 PageModel (com.agiletec.aps.system.services.pagemodel.PageModel)15 WidgetType (org.entando.entando.aps.system.services.widgettype.WidgetType)15 Test (org.junit.Test)14 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)13 Lang (com.agiletec.aps.system.services.lang.Lang)12 ResultActions (org.springframework.test.web.servlet.ResultActions)12