📄 contentmanagementservices.java
字号:
List typeList = UtilMisc.toList("SUB_CONTENT"); int leafCount = ContentManagementWorker.updateStatsTopDown(delegator, contentId, typeList); } } catch(GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); } return result; } public static Map updateLeafCount(DispatchContext dctx, Map context) throws GenericServiceException{ Map result = new HashMap(); GenericDelegator delegator = dctx.getDelegator(); List typeList = (List)context.get("typeList"); if (typeList == null) typeList = UtilMisc.toList("PUBLISH_LINK", "SUB_CONTENT"); String startContentId = (String)context.get("contentId"); try { int leafCount = ContentManagementWorker.updateStatsTopDown(delegator, startContentId, typeList); result.put("leafCount", new Integer(leafCount)); } catch(GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); } return result; } /* public static Map updateLeafChange(DispatchContext dctx, Map context) throws GenericServiceException{ Map result = new HashMap(); GenericDelegator delegator = dctx.getDelegator(); List typeList = (List)context.get("typeList"); if (typeList == null) typeList = UtilMisc.toList("PUBLISH_LINK", "SUB_CONTENT"); String contentId = (String)context.get("contentId"); try { GenericValue thisContent = delegator.findByPrimaryKey("Content", UtilMisc.toMap("contentId", contentId)); if (thisContent == null) throw new RuntimeException("No entity found for id=" + contentId); String thisContentId = thisContent.getString("contentId"); Long leafCount = (Long)thisContent.get("nodeLeafCount"); int subLeafCount = (leafCount == null) ? 1 : leafCount.intValue(); String mode = (String)context.get("mode"); if (mode != null && mode.equalsIgnoreCase("remove")) { subLeafCount *= -1; } else { // TODO: ??? what is this supposed to do: //subLeafCount = subLeafCount; } List condList = new ArrayList(); Iterator iterType = typeList.iterator(); while (iterType.hasNext()) { String type = (String)iterType.next(); condList.add(new EntityExpr("contentAssocTypeId", EntityOperator.EQUALS, type)); } EntityCondition conditionType = new EntityConditionList(condList, EntityOperator.OR); EntityCondition conditionMain = new EntityConditionList(UtilMisc.toList( new EntityExpr("contentId", EntityOperator.EQUALS, thisContentId), conditionType), EntityOperator.AND); List listAll = delegator.findByConditionCache("ContentAssoc", conditionMain, null, null); List listFiltered = EntityUtil.filterByDate(listAll); Iterator iter = listFiltered.iterator(); while (iter.hasNext()) { GenericValue contentAssoc = (GenericValue)iter.next(); String subContentId = contentAssoc.getString("contentId"); GenericValue contentTo = delegator.findByPrimaryKeyCache("Content", UtilMisc.toMap("contentId", subContentId)); Integer childBranchCount = (Integer)contentTo.get("childBranchCount"); int branchCount = (childBranchCount == null) ? 1 : childBranchCount.intValue(); if (mode != null && mode.equalsIgnoreCase("remove")) branchCount += -1; else branchCount += 1; // For the level just above only, update the branch count contentTo.put("childBranchCount", new Integer(branchCount)); // Start the updating of leaf counts above ContentManagementWorker.updateStatsBottomUp(delegator, subContentId, typeList, subLeafCount); } } catch(GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); } return result; } */ /** * This service changes the contentTypeId of the current content and its children depending on the pageMode. * if pageMode == "outline" then if the contentTypeId of children is not "OUTLINE_NODE" or "PAGE_NODE" * (it could be DOCUMENT or SUBPAGE_NODE) then it will get changed to PAGE_NODE.` * if pageMode == "page" then if the contentTypeId of children is not "PAGE_NODE" or "SUBPAGE_NODE" * (it could be DOCUMENT or OUTLINE_NODE) then it will get changed to SUBPAGE_NODE.` * @param delegator * @param contentId * @param pageMode */ public static Map updatePageType(DispatchContext dctx, Map context) throws GenericServiceException{ GenericDelegator delegator = dctx.getDelegator(); Map results = new HashMap(); Set visitedSet = (Set)context.get("visitedSet"); if (visitedSet == null) { visitedSet = new HashSet(); context.put("visitedSet", visitedSet); } String pageMode = (String)context.get("pageMode"); String contentId = (String)context.get("contentId"); visitedSet.add(contentId); String contentTypeId = "PAGE_NODE"; if (pageMode != null && pageMode.toLowerCase().indexOf("outline") >= 0) contentTypeId = "OUTLINE_NODE"; GenericValue thisContent = null; try { thisContent = delegator.findByPrimaryKey("Content", UtilMisc.toMap("contentId", contentId)); if (thisContent == null) ServiceUtil.returnError("No entity found for id=" + contentId); thisContent.set("contentTypeId", contentTypeId); thisContent.store(); List kids = ContentWorker.getAssociatedContent(thisContent, "from", UtilMisc.toList("SUB_CONTENT"), null, null, null); Iterator iter = kids.iterator(); while (iter.hasNext()) { GenericValue kidContent = (GenericValue)iter.next(); if (contentTypeId.equals("OUTLINE_NODE")) { updateOutlineNodeChildren(kidContent, false, context); } else { updatePageNodeChildren(kidContent, context); } } } catch(GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); } return results; } public static Map resetToOutlineMode(DispatchContext dctx, Map context) throws GenericServiceException{ GenericDelegator delegator = dctx.getDelegator(); Map results = new HashMap(); Set visitedSet = (Set)context.get("visitedSet"); if (visitedSet == null) { visitedSet = new HashSet(); context.put("visitedSet", visitedSet); } String contentId = (String)context.get("contentId"); String pageMode = (String)context.get("pageMode"); String contentTypeId = "OUTLINE_NODE"; if (pageMode != null && pageMode.toLowerCase().indexOf("page") >= 0) contentTypeId = "PAGE_NODE"; GenericValue thisContent = null; try { thisContent = delegator.findByPrimaryKey("Content", UtilMisc.toMap("contentId", contentId)); if (thisContent == null) ServiceUtil.returnError("No entity found for id=" + contentId); thisContent.set("contentTypeId", "OUTLINE_NODE"); thisContent.store(); List kids = ContentWorker.getAssociatedContent(thisContent, "from", UtilMisc.toList("SUB_CONTENT"), null, null, null); Iterator iter = kids.iterator(); while (iter.hasNext()) { GenericValue kidContent = (GenericValue)iter.next(); if (contentTypeId.equals("OUTLINE_NODE")) { updateOutlineNodeChildren(kidContent, true, context); } else { kidContent.put("contentTypeId", "PAGE_NODE"); kidContent.store(); List kids2 = ContentWorker.getAssociatedContent(kidContent, "from", UtilMisc.toList("SUB_CONTENT"), null, null, null); Iterator iter2 = kids.iterator(); while (iter2.hasNext()) { GenericValue kidContent2 = (GenericValue)iter2.next(); updatePageNodeChildren(kidContent2, context); } } } } catch(GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); } return results; } public static Map clearContentAssocViewCache(DispatchContext dctx, Map context) throws GenericServiceException{ Map results = new HashMap(); UtilCache utilCache = (UtilCache) UtilCache.utilCacheTable.get("entitycache.entity-list.default.ContentAssocViewFrom"); if (utilCache != null) { utilCache.clear(); } utilCache = (UtilCache) UtilCache.utilCacheTable.get("entitycache.entity-list.default.ContentAssocViewTo"); if (utilCache != null) { utilCache.clear(); } return results; } public static Map clearContentAssocDataResourceViewCache(DispatchContext dctx, Map context) throws GenericServiceException{ Map results = new HashMap(); UtilCache utilCache = (UtilCache) UtilCache.utilCacheTable.get("entitycache.entity-list.default.ContentAssocViewDataResourceFrom"); if (utilCache != null) { utilCache.clear(); } utilCache = (UtilCache) UtilCache.utilCacheTable.get("entitycache.entity-list.default.ContentAssocViewDataResourceTo"); if (utilCache != null) { utilCache.clear(); } return results; } public static void updatePageNodeChildren(GenericValue content, Map context) throws GenericEntityException { String contentId = content.getString("contentId"); Set visitedSet = (Set)context.get("visitedSet"); if (visitedSet == null) { visitedSet = new HashSet(); context.put("visitedSet", visitedSet); } else { if (visitedSet.contains(contentId)) { Debug.logWarning("visitedSet already contains:" + contentId, module); return; } else { visitedSet.add(contentId); } } String contentTypeId = content.getString("contentTypeId"); String newContentTypeId = "SUBPAGE_NODE";// if (contentTypeId == null || contentTypeId.equals("DOCUMENT")) {// newContentTypeId = "SUBPAGE_NODE";// } else if (contentTypeId.equals("OUTLINE_NODE")) {// newContentTypeId = "PAGE_NODE";// } content.put("contentTypeId", newContentTypeId); content.sto
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -