📄 contentmanagementworker.java
字号:
Object oCached = null; String ky = (String)keyIt.next(); oPassed = passedPK.get(ky); if(oPassed != null) { sPassed = oPassed.toString(); if(UtilValidate.isEmpty(sPassed)){ // If any part of passed key is not available, it can't be used usePassed = false; } else { oCached = cachedPK.get(ky); if(oCached != null) { sCached = oCached.toString(); if(UtilValidate.isEmpty(sCached)){ useCached = false; } else { } } else { useCached = false; } } } else { //useCached = false; usePassed = false; } } } GenericPK currentPK = null; if (usePassed && useCached) { currentPK = passedPK; } else if (usePassed && !useCached) { currentPK = passedPK; } else if (!usePassed && useCached) { currentPK = cachedPK; } if (currentPK != null) { request.setAttribute("currentPK", currentPK); GenericValue currentValue = null; try { currentValue = delegator.findByPrimaryKey(currentPK.getPrimaryKey()); } catch(GenericEntityException e) { } request.setAttribute("currentValue", currentValue); } } public static List getPermittedPublishPoints(GenericDelegator delegator, List allPublishPoints, GenericValue userLogin, Security security, String permittedAction, String permittedOperations, String passedRoles) throws GeneralException { List permittedPublishPointList = new ArrayList(); // Check that user has permission to admin sites Iterator it = allPublishPoints.iterator(); while(it.hasNext()) { GenericValue webSitePP = (GenericValue)it.next(); String contentId = (String)webSitePP.get("contentId"); String templateTitle = (String)webSitePP.get("templateTitle"); GenericValue content = delegator.makeValue("Content", UtilMisc.toMap("contentId", contentId)); 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 getPermittedPublishPoints, 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,templateTitle}; permittedPublishPointList.add(arr); } } return permittedPublishPointList; } /** Returns a list of WebSitePublishPoint entities that are children of parentPubPt The name should be "getAllTopLevelPublishPoints" or "getAllChildPublishPoints" @param parentPubPt The parent publish point. */ public static List getAllPublishPoints(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", "SUBSITE")); } catch(GenericEntityException e) { throw new GeneralException(e.getMessage()); } List allPublishPoints = new ArrayList(); GenericValue webSitePublishPoint = null; GenericValue rootWebSitePublishPoint = null; GenericValue currentWebSitePublishPoint = null; GenericValue contentAssoc = null; Iterator it = relatedPubPts.iterator(); while (it.hasNext()) { contentAssoc = (GenericValue)it.next(); String pub = (String)contentAssoc.get("contentId"); //webSitePublishPoint = delegator.findByPrimaryKeyCache("WebSitePublishPoint", UtilMisc.toMap("contentId", pub)); webSitePublishPoint = getWebSitePublishPoint(delegator, pub, false); allPublishPoints.add(webSitePublishPoint); } return allPublishPoints; } public static Map getPublishPointMap(GenericDelegator delegator, String pubPtId ) throws GeneralException { List publishPointList = getAllPublishPoints( delegator, pubPtId ); Map publishPointMap = new HashMap(); Iterator it = publishPointList.iterator(); while (it.hasNext()) { GenericValue webSitePublishPoint = (GenericValue)it.next(); String pub = (String)webSitePublishPoint.get("contentId"); publishPointMap.put(pub, webSitePublishPoint); } return publishPointMap; } public static void getAllPublishPointMap(GenericDelegator delegator, String pubPtId, Map publishPointMap ) throws GeneralException { List publishPointList = getAllPublishPoints( delegator, pubPtId ); Iterator it = publishPointList.iterator(); while (it.hasNext()) { GenericValue webSitePublishPoint = (GenericValue)it.next(); String pub = (String)webSitePublishPoint.get("contentId"); publishPointMap.put(pub, webSitePublishPoint); getAllPublishPointMap(delegator, pub, publishPointMap); } return; } public static Map getPublishPointMap(GenericDelegator delegator, List publishPointList ) { Map publishPointMap = new HashMap(); Iterator it = publishPointList.iterator(); while (it.hasNext()) { GenericValue webSitePublishPoint = (GenericValue)it.next(); String pub = (String)webSitePublishPoint.get("contentId"); publishPointMap.put(pub, webSitePublishPoint); } return publishPointMap; } public static List getStaticValues(GenericDelegator delegator, String parentPlaceholderId, List permittedPublishPointList) throws GeneralException { List assocValueList = null; try { assocValueList = delegator.findByAndCache("Content", UtilMisc.toMap("contentTypeId", parentPlaceholderId)); } catch(GenericEntityException e) { throw new GeneralException(e.getMessage()); } List staticValueList = new ArrayList(); Iterator it = assocValueList.iterator(); int counter = 0; while(it.hasNext()) { GenericValue content = (GenericValue)it.next(); String contentId = (String)content.get("contentId"); String contentName = (String)content.get("contentName"); String description = (String)content.get("description"); Map map = new HashMap(); map.put("contentId", contentId); map.put("contentName", contentName); map.put("description", description); Iterator it2 = permittedPublishPointList.iterator(); while (it2.hasNext()) { String [] publishPointArray = (String [])it2.next(); String publishPointId = (String)publishPointArray[0]; //fieldName = "_" + Integer.toString(counter) + "_" + publishPointId; String fieldName = publishPointId; List contentAssocList = content.getRelatedByAnd("ToContentAssoc", UtilMisc.toMap("contentId", publishPointId)); List filteredList = EntityUtil.filterByDate(contentAssocList); if (filteredList.size() > 0) { map.put(fieldName, "Y"); GenericValue assoc = (GenericValue)filteredList.get(0); Timestamp fromDate = (Timestamp)assoc.get("fromDate"); map.put(fieldName + "FromDate", fromDate); } else { map.put(fieldName, "N"); } } staticValueList.add(map); counter++; } return staticValueList; } public static GenericValue getWebSitePublishPoint(GenericDelegator delegator, String contentId) throws GenericEntityException { return getWebSitePublishPoint(delegator, contentId, false); } public static GenericValue getWebSitePublishPoint(GenericDelegator delegator, String contentId, boolean ignoreCache) throws GenericEntityException { GenericValue webSitePublishPoint = null; if (!ignoreCache) webSitePublishPoint = (GenericValue)cachedWebSitePublishPoints.get(contentId); if (webSitePublishPoint == null) { webSitePublishPoint = delegator.findByPrimaryKey("WebSitePublishPoint", UtilMisc.toMap("contentId", contentId)); // If no webSitePublishPoint exists, still try to look for parent by making a dummy value if (webSitePublishPoint == null) { webSitePublishPoint = delegator.makeValue("WebSitePublishPoint", UtilMisc.toMap("contentId", contentId)); } //if (Debug.infoOn()) Debug.logInfo("in getWebSitePublishPoint, contentId:" + contentId, module); webSitePublishPoint = overrideWebSitePublishPoint(delegator, webSitePublishPoint); cachedWebSitePublishPoints.put(contentId, webSitePublishPoint); } return webSitePublishPoint; } public static GenericValue overrideWebSitePublishPoint(GenericDelegator delegator, GenericValue passedValue) throws GenericEntityException { String contentId = passedValue.getString("contentId"); GenericValue webSitePublishPoint = passedValue; String contentIdTo = getParentWebSitePublishPointId(delegator, contentId); //if (Debug.infoOn()) Debug.logInfo("in overrideWebSitePublishPoint, contentIdTo:" + contentIdTo, module); if (contentIdTo != null) { //webSitePublishPoint = getWebSitePublishPoint(delegator, contentIdTo, false); webSitePublishPoint = delegator.findByPrimaryKeyCache("WebSitePublishPoint", UtilMisc.toMap("contentId", contentIdTo)); if (webSitePublishPoint != null) { webSitePublishPoint = GenericValue.create(webSitePublishPoint); webSitePublishPoint = overrideWebSitePublishPoint(delegator, webSitePublishPoint); webSitePublishPoint.setNonPKFields(passedValue, false); webSitePublishPoint.setPKFields(passedValue, false); passedValue.setNonPKFields(webSitePublishPoint); } } return webSitePublishPoint; } public static GenericValue getParentWebSitePublishPointValue(GenericDelegator delegator, String contentId) throws GenericEntityException { String contentIdTo = getParentWebSitePublishPointId(delegator, contentId); GenericValue content = delegator.findByPrimaryKeyCache("Content", UtilMisc.toMap("contentId", contentIdTo)); return content; } public static String getParentWebSitePublishPointId(GenericDelegator delegator, String contentId) throws GenericEntityException { String contentIdTo = null; List contentAssocList = delegator.findByAndCache("ContentAssoc", UtilMisc.toMap("contentId", contentId, "contentAssocTypeId", "SUBSITE")); List filteredContentAssocList = EntityUtil.filterByDate(contentAssocList); if (filteredContentAssocList.size() > 0) { GenericValue contentAssoc = (GenericValue)filteredContentAssocList.get(0); if (contentAssoc != null) contentIdTo = contentAssoc.getString("contentIdTo"); } return contentIdTo; } public static GenericValue getStaticValue(GenericDelegator delegator, String parentPlaceholderId, String webSitePublishPointId, boolean ignoreCache) throws GenericEntityException { GenericValue webSitePublishPoint = null; GenericValue staticValue = null; if (!ignoreCache) { Map subStaticValueMap = (GenericValue)cachedStaticValues.get(parentPlaceholderId); if (subStaticValueMap == null) { subStaticValueMap = new HashMap(); cachedStaticValues.put(parentPlaceholderId, subStaticValueMap); } //Map staticValueMap = (GenericValue)cachedStaticValues.get(web); }/* if (webSitePublishPoint == null) { webSitePublishPoint = delegator.findByPrimaryKey("WebSitePublishPoint", UtilMisc.toMap("contentId", contentId)); // If no webSitePublishPoint exists, still try to look for parent by making a dummy value
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -