📄 contentworker.java
字号:
GenericValue assocValue = (GenericValue) it.next(); contentAssocTypeId = (String) assocValue.get("contentAssocTypeId"); assocContext.put("contentAssocTypeId", contentAssocTypeId); //assocContext.put("contentTypeId", assocValue.get("contentTypeId") ); assocContext.put("parentContent", content); String assocRelation = null; // This needs to be the opposite String relatedDirection = null; if (direction != null && direction.equalsIgnoreCase("From")) { assocContext.put("contentIdFrom", assocValue.get("contentId")); assocRelation = "ToContent"; relatedDirection = "From"; } else { assocContext.put("contentIdTo", assocValue.get("contentId")); assocRelation = "FromContent"; relatedDirection = "To"; } boolean isFollow = checkWhen(assocContext, (String) whenMap.get("followWhen")); if (isFollow) { GenericValue thisContent = assocValue.getRelatedOne(assocRelation); traverse(delegator, thisContent, fromDate, thruDate, whenMap, depthIdx + 1, thisNode, contentAssocTypeId, pickList, relatedDirection); } } } } catch (GenericEntityException e) { Debug.logError("Entity Error:" + e.getMessage(), null); } return; } public static boolean traverseSubContent(Map ctx) { boolean inProgress = false; List nodeTrail = (List)ctx.get("nodeTrail"); ContentWorker.traceNodeTrail("11",nodeTrail); int sz = nodeTrail.size(); if (sz == 0) { return false; } Map currentNode = (Map)nodeTrail.get(sz - 1); Boolean isReturnAfter = (Boolean)currentNode.get("isReturnAfter"); if (isReturnAfter != null && isReturnAfter.booleanValue()) { return false; } List kids = (List)currentNode.get("kids"); if (kids != null && kids.size() > 0) { int idx = 0; while (idx < kids.size()) { currentNode = (Map)kids.get(idx); ContentWorker.traceNodeTrail("12",nodeTrail); Boolean isPick = (Boolean)currentNode.get("isPick"); if (isPick != null && isPick.booleanValue()) { nodeTrail.add(currentNode); inProgress = true; selectKids(currentNode, ctx); ContentWorker.traceNodeTrail("14",nodeTrail); break; } else { Boolean isFollow = (Boolean)currentNode.get("isFollow"); if (isFollow != null || isFollow.booleanValue()) { nodeTrail.add(currentNode); boolean foundPick = traverseSubContent(ctx); if (foundPick) { inProgress = true; break; } } } idx++; } } if (!inProgress) { // look for next sibling while (sz > 1) { currentNode = (Map)nodeTrail.remove(--sz); ContentWorker.traceNodeTrail("15",nodeTrail); Map parentNode = (Map)nodeTrail.get(sz - 1); kids = (List)parentNode.get("kids"); if (kids == null) { continue; } int idx = kids.indexOf(currentNode); while (idx < (kids.size() - 1)) { currentNode = (Map)kids.get(idx + 1); Boolean isFollow = (Boolean)currentNode.get("isFollow"); if (isFollow == null || !isFollow.booleanValue()) { idx++; continue; } String contentAssocTypeId = (String)currentNode.get("contentAssocTypeId"); nodeTrail.add(currentNode); ContentWorker.traceNodeTrail("16",nodeTrail); Boolean isPick = (Boolean)currentNode.get("isPick"); if (isPick == null || !isPick.booleanValue()) { // If not a "pick" node, look at kids inProgress = traverseSubContent(ctx); ContentWorker.traceNodeTrail("17",nodeTrail); if (inProgress) { break; } } else { inProgress = true; break; } idx++; } if (inProgress) { break; } } } return inProgress; } public static List getPurposes(GenericValue content) { List purposes = new ArrayList(); try { List purposeValueList = content.getRelatedCache("ContentPurpose"); for (int i = 0; i < purposeValueList.size(); i++) { GenericValue purposeValue = (GenericValue) purposeValueList.get(i); purposes.add(purposeValue.get("contentPurposeTypeId")); } } catch (GenericEntityException e) { Debug.logError("Entity Error:" + e.getMessage(), null); } return purposes; } public static List getSections(GenericValue content) { List sections = new ArrayList(); try { List sectionValueList = content.getRelatedCache("FromContentAssoc"); for (int i = 0; i < sectionValueList.size(); i++) { GenericValue sectionValue = (GenericValue) sectionValueList.get(i); String contentAssocPredicateId = (String)sectionValue.get("contentAssocPredicateId"); if (contentAssocPredicateId != null && contentAssocPredicateId.equals("categorizes")) { sections.add(sectionValue.get("contentIdTo")); } } } catch (GenericEntityException e) { Debug.logError("Entity Error:" + e.getMessage(), null); } return sections; } public static List getTopics(GenericValue content) { List topics = new ArrayList(); try { List topicValueList = content.getRelatedCache("FromContentAssoc"); for (int i = 0; i < topicValueList.size(); i++) { GenericValue topicValue = (GenericValue) topicValueList.get(i); String contentAssocPredicateId = (String)topicValue.get("contentAssocPredicateId"); if (contentAssocPredicateId != null && contentAssocPredicateId.equals("topifies")) topics.add(topicValue.get("contentIdTo")); } } catch (GenericEntityException e) { Debug.logError("Entity Error:" + e.getMessage(), null); } return topics; } public static void selectKids(Map currentNode, Map ctx) { GenericDelegator delegator = (GenericDelegator) ctx.get("delegator"); GenericValue parentContent = (GenericValue) currentNode.get("value"); String contentAssocTypeId = (String) ctx.get("contentAssocTypeId"); String contentTypeId = (String) ctx.get("contentTypeId"); String mapKey = (String) ctx.get("mapKey"); String parentContentId = (String) parentContent.get("contentId"); //if (Debug.infoOn()) Debug.logInfo("traverse, contentAssocTypeId:" + contentAssocTypeId,null); Map whenMap = (Map) ctx.get("whenMap"); Map context = new HashMap(); List kids = new ArrayList(); currentNode.put("kids", kids); String direction = (String) ctx.get("direction"); if (UtilValidate.isEmpty(direction)) direction = "From"; Timestamp fromDate = (Timestamp) ctx.get("fromDate"); Timestamp thruDate = (Timestamp) ctx.get("thruDate"); List assocTypeList = StringUtil.split(contentAssocTypeId, " "); List contentTypeList = StringUtil.split(contentTypeId, " "); String contentAssocPredicateId = null; Boolean nullThruDatesOnly = new Boolean(true); Map results = null; try { results = ContentServicesComplex.getAssocAndContentAndDataResourceCacheMethod(delegator, parentContentId, mapKey, direction, null, null, assocTypeList, contentTypeList, nullThruDatesOnly, contentAssocPredicateId); } catch (GenericEntityException e) { throw new RuntimeException(e.getMessage()); } catch (MiniLangException e2) { throw new RuntimeException(e2.getMessage()); } List relatedViews = (List) results.get("entityList"); //if (Debug.infoOn()) Debug.logInfo("traverse, relatedViews:" + relatedViews,null); Iterator it = relatedViews.iterator(); while (it.hasNext()) { GenericValue assocValue = (GenericValue) it.next(); Map thisNode = ContentWorker.makeNode(assocValue); checkConditions(delegator, thisNode, null, whenMap); boolean isReturnBeforePick = booleanDataType(thisNode.get("isReturnBeforePick")); boolean isReturnAfterPick = booleanDataType(thisNode.get("isReturnAfterPick")); boolean isPick = booleanDataType(thisNode.get("isPick")); boolean isFollow = booleanDataType(thisNode.get("isFollow")); kids.add(thisNode); if (isPick) { Integer count = (Integer) currentNode.get("count"); if (count == null) { count = new Integer(1); } else { count = new Integer(count.intValue() + 1); } currentNode.put("count", count); } } return; } public static boolean checkWhen(Map context, String whenStr) { boolean isWhen = true; //opposite default from checkReturnWhen if (whenStr != null && whenStr.length() > 0) { FlexibleStringExpander fse = new FlexibleStringExpander(whenStr); String newWhen = fse.expandString(context); //if (Debug.infoOn()) Debug.logInfo("newWhen:" + newWhen,null); //if (Debug.infoOn()) Debug.logInfo("context:" + context,null); try { Boolean isWhenObj = (Boolean) BshUtil.eval(newWhen, context); isWhen = isWhenObj.booleanValue(); } catch (EvalError e) { Debug.logError("Error in evaluating :" + whenStr + " : " + e.getMessage(), null); throw new RuntimeException(e.getMessage()); } } //if (Debug.infoOn()) Debug.logInfo("isWhen:" + isWhen,null); return isWhen; } public static boolean checkReturnWhen(Map context, String whenStr) { boolean isWhen = false; //opposite default from checkWhen if (whenStr != null && whenStr.length() > 0) { FlexibleStringExpander fse = new FlexibleStringExpander(whenStr); String newWhen = fse.expandString(context); try { Boolean isWhenObj = (Boolean) BshUtil.eval(newWhen, context); isWhen = isWhenObj.booleanValue(); } catch (EvalError e) { Debug.logError("Error in evaluating :" + whenStr + " : " + e.getMessage(), null); throw new RuntimeException(e.getMessage()); } } return isWhen; } public static List getAssociatedContent(GenericValue currentContent, String linkDir, List assocTypes, List contentTypes, String fromDate, String thruDate) throws GenericEntityException {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -