Search in sources :

Example 1 with PageRecord

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

the class PageManagerCacheWrapper method initCache.

@Override
public void initCache(IPageDAO pageDao) throws ApsSystemException {
    PagesStatus status = new PagesStatus();
    IPage newDraftRoot = null;
    IPage newOnLineRoot = null;
    try {
        Cache cache = this.getCache();
        this.releaseCachedObjects(cache);
        List<PageRecord> pageRecordList = pageDao.loadPageRecords();
        Map<String, IPage> newFullMap = new HashMap<String, IPage>(pageRecordList.size());
        Map<String, IPage> newOnlineMap = new HashMap<String, IPage>();
        List<IPage> pageListO = new ArrayList<>();
        List<IPage> pageListD = new ArrayList<>();
        for (int i = 0; i < pageRecordList.size(); i++) {
            PageRecord pageRecord = pageRecordList.get(i);
            IPage pageD = pageRecord.createDraftPage();
            IPage pageO = pageRecord.createOnlinePage();
            pageListD.add(pageD);
            newFullMap.put(pageD.getCode(), pageD);
            if (pageD.getCode().equals(pageD.getParentCode())) {
                newDraftRoot = pageD;
                newOnLineRoot = pageO;
            }
            this.buildPagesStatus(status, pageD);
            if (pageD.isOnline()) {
                newOnlineMap.put(pageO.getCode(), pageO);
                pageListO.add(pageO);
            }
        }
        for (int i = 0; i < pageListD.size(); i++) {
            this.buildTreeHierarchy(newDraftRoot, newFullMap, pageListD.get(i));
        }
        for (int i = 0; i < pageListO.size(); i++) {
            this.buildTreeHierarchy(newOnLineRoot, newOnlineMap, pageListO.get(i));
        }
        if (newDraftRoot == null) {
            throw new ApsSystemException("Error in the page tree: root page undefined");
        }
        this.insertObjectsOnCache(cache, status, newDraftRoot, newOnLineRoot, pageListD, pageListO);
    } catch (ApsSystemException e) {
        throw e;
    } catch (Throwable t) {
        _logger.error("Error while building the tree of pages", t);
        throw new ApsSystemException("Error while building the tree of pages", t);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) IPage(com.agiletec.aps.system.services.page.IPage) PageRecord(com.agiletec.aps.system.services.page.PageRecord) PagesStatus(com.agiletec.aps.system.services.page.PagesStatus) Cache(org.springframework.cache.Cache)

Aggregations

ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)1 IPage (com.agiletec.aps.system.services.page.IPage)1 PageRecord (com.agiletec.aps.system.services.page.PageRecord)1 PagesStatus (com.agiletec.aps.system.services.page.PagesStatus)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Cache (org.springframework.cache.Cache)1