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