⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 contentworker.java

📁 国外的一套开源CRM
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                        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");
               FreeMarkerWorker.traceNodeTrail("11",nodeTrail);
        int sz = nodeTrail.size();
        if (Debug.verboseOn()) Debug.logVerbose("sz(traverseSubContent):" + sz,null);
        if (sz == 0) 
            return false;

        Map currentNode = (Map)nodeTrail.get(sz - 1);
        List kids = (List)currentNode.get("kids");
        //if (Debug.verboseOn()) Debug.logVerbose("currentNode(traverseSubContent):" + currentNode,null);
        if (kids != null && kids.size() > 0) {
            int idx = 0;
            while (idx < kids.size()) {
                currentNode = (Map)kids.get(idx);
                Boolean isFollow = (Boolean)currentNode.get("isFollow");
                if (isFollow == null || !isFollow.booleanValue()) {
                    idx++;
                    continue;
                }
                nodeTrail.add(currentNode);
                FreeMarkerWorker.traceNodeTrail("12",nodeTrail);
                Boolean isPick = (Boolean)currentNode.get("isPick");
                inProgress = true;
                selectKids(currentNode, ctx);
                FreeMarkerWorker.traceNodeTrail("14",nodeTrail);
                break;
            }
        } 

        if (!inProgress) {
            // look for next sibling
            while (sz > 1) {
                currentNode = (Map)nodeTrail.remove(--sz);
                FreeMarkerWorker.traceNodeTrail("15",nodeTrail);
                Map parentNode = (Map)nodeTrail.get(sz - 1);
                kids = (List)parentNode.get("kids");
                if (kids == null)
                    continue;

                int idx = kids.indexOf(currentNode);
                if (Debug.verboseOn()) Debug.logVerbose("idx(traverseSubContent):" + idx,null);
                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);
               FreeMarkerWorker.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);
               FreeMarkerWorker.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 void selectKids(Map currentNode, Map ctx) {
        
        GenericValue parentContent = (GenericValue)currentNode.get("value");
        String parentContentAssocTypeId = (String)currentNode.get("assocContentTypeId");
        String parentContentTypeId = (String)currentNode.get("contentTypeId");
        String parentContentId = (String) parentContent.get("contentId");
        if (Debug.verboseOn()) Debug.logVerbose("traverse, parentContentId:" + parentContentId,null);
        if (Debug.verboseOn()) Debug.logVerbose("traverse, parentContentAssocTypeId:" + parentContentAssocTypeId,null);
        Map whenMap = (Map)ctx.get("whenMap");
        Map context = new HashMap();
        context.put("content", parentContent);
        context.put("contentAssocTypeId", parentContentAssocTypeId);
        List purposes = getPurposes(parentContent);
        context.put("purposes", purposes);
        List contentTypeAncestry = new ArrayList();
        GenericDelegator delegator = (GenericDelegator)ctx.get("delegator");
        try {
            getContentTypeAncestry(delegator, parentContentTypeId, contentTypeAncestry);
        } catch(GenericEntityException e) {
            if (Debug.verboseOn()) Debug.logVerbose("Error in getting contentTypeAncestry:" + e.getMessage(), "");
        }
        context.put("typeAncestry", contentTypeAncestry);
        boolean isReturnAfter = checkReturnWhen(context, (String)whenMap.get("returnAfterPickWhen"));
        if (isReturnAfter) 
            return;

        List kids = new ArrayList();
        currentNode.put("kids", kids);
        try {
            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 relatedAssocs = getContentAssocsWithId(delegator, parentContentId, fromDate, thruDate, direction, new ArrayList());
            if (Debug.verboseOn()) Debug.logVerbose("traverse, relatedAssocs:" + relatedAssocs,null);
            Iterator it = relatedAssocs.iterator();
            while (it.hasNext()) {
                GenericValue assocValue = (GenericValue) it.next();
                if (Debug.verboseOn()) Debug.logVerbose("assocValue, Id:" + assocValue.get("contentId") + " To:" + assocValue.get("contentIdTo") + " AssocTypeId:" + assocValue.get("contentAssocTypeId"), null);
                String contentAssocTypeId = (String) assocValue.get("contentAssocTypeId");
                String assocContentId = null;
              
                if (direction != null && direction.equalsIgnoreCase("From")) {
                    assocContentId = (String) assocValue.get("contentId");
                } else {
                    assocContentId = (String) assocValue.get("contentIdTo");
                }
                Map assocContext = buildPickContext(delegator, contentAssocTypeId, assocContentId, direction, null);
                assocContext.put("related", relatedAssocs);
                boolean isReturnBefore = checkReturnWhen(assocContext, (String)whenMap.get("returnBeforePickWhen"));
                if (Debug.verboseOn()) Debug.logVerbose("isReturnBefore(traverse):" + isReturnBefore,null);
                if (!isReturnBefore) {
                    Map thisNode = new HashMap();
                    GenericValue thisContent = (GenericValue)assocContext.get("content");
                    thisNode.put("value", thisContent);
                    thisNode.put("contentId", thisContent.get("contentId"));
                    thisNode.put("contentTypeId", thisContent.get("contentTypeId"));
                    thisNode.put("contentAssocTypeId", contentAssocTypeId);
                    thisNode.put("direction", direction);
                    if (Debug.verboseOn()) Debug.logVerbose("thisNode(traverse):" + thisNode,null);
                    kids = (List) currentNode.get("kids");
                    if (kids == null) {
                        kids = new ArrayList();
                        currentNode.put("kids", kids);
                    }
                    kids.add(thisNode);
                    String pickWhen = (String)whenMap.get("pickWhen");
                    if (Debug.verboseOn()) Debug.logVerbose("pickWhen(traverse):" + pickWhen,null);
                    if (Debug.verboseOn()) Debug.logVerbose("assocContext(traverse):" + assocContext,null);
                    boolean isPick = checkWhen(assocContext, (String)whenMap.get("pickWhen"));
                    if (Debug.verboseOn()) Debug.logVerbose("isPick(selectKids):" + isPick,null);
                    if (isPick) {
                        thisNode.put("isPick", new Boolean(true));
                        Integer count = (Integer) currentNode.get("count");
                        if (count == null) {
                            count = new Integer(1);
                        } else {
                            count = new Integer(count.intValue() + 1);
                        }
                        currentNode.put("count", count);
                    }
                    String followWhen = (String)whenMap.get("followWhen");
                    if (Debug.verboseOn()) Debug.logVerbose("followWhen(traverse):" + followWhen,null);
                    boolean isFollow = checkWhen(assocContext, (String)whenMap.get("followWhen"));
                    if (Debug.verboseOn()) Debug.logVerbose("isFollow(traverse):" + isFollow,null);
                    if (isFollow) {
                        thisNode.put("isFollow", new Boolean(true));
                    }
                }
            }
        } catch (GenericEntityException e) {
            Debug.logError("Entity Error:" + e.getMessage(), null);
        }
        return;
    }

    public static boolean checkWhen(Map context, String whenStr) {
        //if (Debug.verboseOn()) Debug.logVerbose("whenStr:" + whenStr,null);
        boolean isWhen = true; //opposite default from checkReturnWhen
        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);
            }
        }
        return isWhen;
    }

    public static boolean checkReturnWhen(Map context, String whenStr) {
        //if (Debug.verboseOn()) Debug.logVerbose("checkReturnWhen:" + whenStr,null);
        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);
            }
        }
        return isWhen;
    }

    public static List getAssociatedContent(GenericValue currentContent, String linkDir, List assocTypes, List contentTypes, String fromDate, String thruDate)
        throws GenericEntityException {

        GenericDelegator delegator = currentContent.getDelegator();
        List assocList = getAssociations(currentContent, linkDir, assocTypes, fromDate, thruDate);

        List contentList = new ArrayList();
        String contentIdName = "contentId";
        if (linkDir != null && linkDir.equalsIgnoreCase("TO")) {
            contentIdName.concat("To");
        }
        GenericValue assoc = null;
        GenericValue content = null;
        String contentTypeId = null;
        Iterator assocIt = assocList.iterator();
        while (assocIt.hasNext()) {
            assoc = (GenericValue) assocIt.next();
            String contentId = (String) assoc.get(contentIdName);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -