📄 contentmanagementworker.java
字号:
if (webSitePublishPoint == null) { webSitePublishPoint = delegator.makeValue("WebSitePublishPoint", UtilMisc.toMap("contentId", contentId)); } webSitePublishPoint = overrideStaticValues(delegator, webSitePublishPoint); cachedWebSitePublishPoints.put(contentId, webSitePublishPoint); }*/ return webSitePublishPoint; } public static List getPublishedLinks(GenericDelegator delegator, String targContentId, String rootPubId, GenericValue userLogin, Security security, String permittedAction, String permittedOperations , String passedRoles) throws GeneralException { // Set up one map with all the top-level publish points (to which only one sub point can be attached to) // and another map (publishPointMapAll) that points to one of the top-level points. List allPublishPointList = getAllPublishPoints( delegator, rootPubId ); //if (Debug.infoOn()) Debug.logInfo("in getPublishLinks, allPublishPointList:" + allPublishPointList, module); List publishPointList = getPermittedPublishPoints( delegator, allPublishPointList, userLogin, security , permittedAction, permittedOperations, passedRoles ); Map publishPointMap = new HashMap(); Map publishPointMapAll = new HashMap(); Iterator it = publishPointList.iterator(); while (it.hasNext()) { //GenericValue webSitePublishPoint = (GenericValue)it.next(); //String contentId = (String)webSitePublishPoint.get("contentId"); //String description = (String)webSitePublishPoint.get("description"); String [] arr = (String [])it.next(); String contentId = (String)arr[0]; String description = (String)arr[1]; List subPointList = new ArrayList(); Object nullObj = null; Object [] subArr = {contentId, subPointList, description, nullObj}; publishPointMap.put(contentId, subArr); publishPointMapAll.put(contentId, contentId); List subPublishPointList = getAllPublishPoints( delegator, contentId ); Iterator it2 = subPublishPointList.iterator(); while (it2.hasNext()) { //String [] arr2 = (String [])it2.next(); //String contentId2 = (String)arr2[0]; //String description2 = (String)arr2[1]; GenericValue webSitePublishPoint2 = (GenericValue)it2.next(); String contentId2 = (String)webSitePublishPoint2.get("contentId"); String description2 = (String)webSitePublishPoint2.get("templateTitle"); publishPointMapAll.put(contentId2, contentId); Timestamp obj = null; Object [] subArr2 = {contentId2, description2, obj}; subPointList.add(subArr2); } }/* */ List assocValueList = null; try { List rawAssocValueList = delegator.findByAndCache("ContentAssoc", UtilMisc.toMap("contentId", targContentId, "contentAssocTypeId", "PUBLISH_LINK")); assocValueList = EntityUtil.filterByDate(rawAssocValueList); } catch(GenericEntityException e) { throw new GeneralException(e.getMessage()); } Map publishedLinkMap = new HashMap(); Iterator it4 = assocValueList.iterator(); while (it4.hasNext()) { GenericValue contentAssoc = (GenericValue)it4.next(); String contentIdTo = contentAssoc.getString("contentIdTo"); String topContentId = (String)publishPointMapAll.get(contentIdTo); Object [] subArr = (Object [])publishPointMap.get(topContentId); //if (Debug.infoOn()) Debug.logInfo("in getPublishLinks, subArr:" + Arrays.asList(subArr) , module); if (contentIdTo.equals(topContentId)) { subArr[3] = contentAssoc.get("fromDate"); } else { if (subArr != null) { List subPointList = (List)subArr[1]; Iterator it5 = subPointList.iterator(); Object [] subArr2 = null; while (it5.hasNext()) { subArr2 = (Object [])it5.next(); String contentId5 = (String)subArr2[0]; if (contentId5.equals(contentIdTo)) break; } subArr2[2] = contentAssoc.get("fromDate"); } } } List publishedLinkList = new ArrayList(); Set keySet = publishPointMap.keySet(); Iterator it3 = keySet.iterator(); while (it3.hasNext()) { String contentId = (String)it3.next(); Object [] subPointArr = (Object [])publishPointMap.get(contentId); publishedLinkList.add(subPointArr); } return publishedLinkList; } public static GenericValue getAuthorContent(GenericDelegator delegator, String contentId) { GenericValue authorContent = null; try { List assocTypes = UtilMisc.toList("AUTHOR"); List contentTypes = null; String fromDate = null; String thruDate = null; Map results = ContentServicesComplex.getAssocAndContentAndDataResourceCacheMethod(delegator, contentId, null, "To", null, null, assocTypes, contentTypes, new Boolean(true), null); List valueList = (List)results.get("entityList"); if (valueList.size() > 0) { GenericValue value = (GenericValue)valueList.get(0); authorContent = delegator.makeValue("Content", null); authorContent.setPKFields(value); authorContent.setNonPKFields(value); //if (Debug.infoOn()) Debug.logInfo("in getAuthorContent, authorContent:" + authorContent, module); } } catch(GenericEntityException e) { } catch(MiniLangException e2) { } return authorContent; } public static List getPermittedDepartmentPoints(GenericDelegator delegator, List allDepartmentPoints, GenericValue userLogin, Security security, String permittedAction, String permittedOperations, String passedRoles) throws GeneralException { List permittedDepartmentPointList = new ArrayList(); // Check that user has permission to admin sites Iterator it = allDepartmentPoints.iterator(); while(it.hasNext()) { GenericValue content = (GenericValue)it.next(); String contentId = (String)content.get("contentId"); String contentName = (String)content.get("contentName"); String statusId = null; String entityAction = permittedAction; if (entityAction == null) entityAction = "_ADMIN"; List passedPurposes = UtilMisc.toList("ARTICLE"); List roles = StringUtil.split(passedRoles, "|"); List targetOperationList = new ArrayList(); if (UtilValidate.isEmpty(permittedOperations)) { targetOperationList.add("CONTENT" + entityAction); } else { targetOperationList = StringUtil.split(permittedOperations, "|"); } Map results = null; //if (Debug.infoOn()) Debug.logInfo("in getPermittedDepartmentPoints, content:" + content, module); results = EntityPermissionChecker.checkPermission(content, statusId, userLogin, passedPurposes, targetOperationList, roles, delegator, security, entityAction); String permissionStatus = (String)results.get("permissionStatus"); if (permissionStatus != null && permissionStatus.equalsIgnoreCase("granted")) { String [] arr = {contentId,contentName}; permittedDepartmentPointList.add(arr); } } return permittedDepartmentPointList; } /** Returns a list of "department" (having ContentAssoc of type "DEPARTMENT") Content entities that are children of parentPubPt @param parentPubPt The parent publish point. */ public static List getAllDepartmentContent(GenericDelegator delegator, String parentPubPt) throws GeneralException { GenericValue rootContent = null; List relatedPubPts = null; try { rootContent = delegator.findByPrimaryKeyCache("Content", UtilMisc.toMap("contentId", parentPubPt)); //relatedPubPts = delegator.findByAndCache("ContentAssoc", UtilMisc.toMap("contentIdTo", parentPubPt)); relatedPubPts = delegator.findByAndCache("ContentAssoc", UtilMisc.toMap("contentIdTo", parentPubPt, "contentAssocTypeId", "DEPARTMENT")); } catch(GenericEntityException e) { throw new GeneralException(e.getMessage()); } List allDepartmentPoints = new ArrayList(); GenericValue departmentContent = null; GenericValue contentAssoc = null; Iterator it = relatedPubPts.iterator(); while (it.hasNext()) { contentAssoc = (GenericValue)it.next(); String pub = (String)contentAssoc.get("contentId"); departmentContent = delegator.findByPrimaryKeyCache("Content", UtilMisc.toMap("contentId", pub)); allDepartmentPoints.add(departmentContent); } return allDepartmentPoints; } public static String getUserName(HttpServletRequest request, String userLoginId) throws GenericEntityException { String userName = null; GenericDelegator delegator = (GenericDelegator)request.getAttribute("delegator"); GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", userLoginId)); GenericValue person = userLogin.getRelatedOneCache("Person"); userName = person.getString("firstName") + " " + person.getString("lastName"); return userName; } public static int updateStatsTopDown(GenericDelegator delegator, String contentId, List typeList) throws GenericEntityException { int subLeafCount = 0; GenericValue thisContent = delegator.findByPrimaryKey("Content", UtilMisc.toMap("contentId", contentId)); if (thisContent == null) throw new RuntimeException("No entity found for id=" + contentId); 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 conditionMain = null; if (condList.size() > 0 ) { EntityCondition conditionType = new EntityConditionList(condList, EntityOperator.OR); conditionMain = new EntityConditionList(UtilMisc.toList( new EntityExpr("contentIdTo", EntityOperator.EQUALS, contentId), conditionType), EntityOperator.AND); } else { conditionMain = new EntityExpr("contentIdTo", EntityOperator.EQUALS, contentId); } 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"); subLeafCount += updateStatsTopDown(delegator, subContentId, typeList); } // If no children, count this as a leaf if (subLeafCount == 0) subLeafCount = 1; thisContent.put("childBranchCount", new Long(listFiltered.size())); thisContent.put("childLeafCount", new Long(subLeafCount)); thisContent.store(); return subLeafCount; } public static void updateStatsBottomUp(GenericDelegator delegator, String contentId, List typeList, int branchChangeAmount, int leafChangeAmount) throws GenericEntityException { GenericValue thisContent = delegator.findByPrimaryKey("Content", UtilMisc.toMap("contentId", contentId)); if (thisContent == null) throw new RuntimeException("No entity found for id=" + contentId); 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, contentId), 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 contentIdTo = contentAssoc.getString("contentIdTo"); GenericValue contentTo = delegator.findByPrimaryKey("Content", UtilMisc.toMap("contentId", contentIdTo)); int intLeafCount = 0; Long leafCount = (Long)contentTo.get("childLeafCount"); if (leafCount != null) { intLeafCount = leafCount.intValue(); } contentTo.set("childLeafCount", new Long(intLeafCount + leafChangeAmount)); if (branchChangeAmount != 0) { int intBranchCount = 0; Long branchCount = (Long)contentTo.get("childBranchCount"); if (branchCount != null) { intBranchCount = branchCount.intValue(); } contentTo.set("childBranchCount", new Long(intBranchCount + branchChangeAmount)); } contentTo.store(); updateStatsBottomUp(delegator, contentIdTo, typeList, 0, leafChangeAmount); } return ; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -