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

📄 contentworker.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        GenericDelegator delegator = currentContent.getDelegator();        List assocList = getAssociations(currentContent, linkDir, assocTypes, fromDate, thruDate);        if (assocList == null || assocList.size() == 0)            return assocList;        if (Debug.infoOn()) Debug.logInfo("assocList:" + assocList.size() + " contentId:" + currentContent.getString("contentId"), "");        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);            if (Debug.infoOn()) Debug.logInfo("contentId:" + contentId, "");            content = delegator.findByPrimaryKey("Content", UtilMisc.toMap("contentId", contentId));            if (contentTypes != null && contentTypes.size() > 0) {                contentTypeId = (String) content.get("contentTypeId");                if (contentTypes.contains(contentTypeId)) {                    contentList.add(content);                }            } else {                contentList.add(content);            }        }        if (Debug.infoOn()) Debug.logInfo("contentList:" + contentList.size() , "");        return contentList;    }    public static List getAssociatedContentView(GenericValue currentContent, String linkDir, List assocTypes, List contentTypes, String fromDate, String thruDate) throws GenericEntityException {        List contentList = new ArrayList();        List exprListAnd = new ArrayList();        String origContentId = (String) currentContent.get("contentId");        String contentIdName = "contentId";        String contentAssocViewName = "contentAssocView";        if (linkDir != null && linkDir.equalsIgnoreCase("TO")) {            contentIdName.concat("To");            contentAssocViewName.concat("To");        }        EntityExpr expr = new EntityExpr(contentIdName, EntityOperator.EQUALS, origContentId);        exprListAnd.add(expr);        if (contentTypes.size() > 0) {            List exprListOr = new ArrayList();            Iterator it = contentTypes.iterator();            while (it.hasNext()) {                String contentType = (String) it.next();                expr = new EntityExpr("contentTypeId", EntityOperator.EQUALS, contentType);                exprListOr.add(expr);            }            EntityConditionList contentExprList = new EntityConditionList(exprListOr, EntityOperator.OR);            exprListAnd.add(contentExprList);        }        if (assocTypes.size() > 0) {            List exprListOr = new ArrayList();            Iterator it = assocTypes.iterator();            while (it.hasNext()) {                String assocType = (String) it.next();                expr = new EntityExpr("contentAssocTypeId", EntityOperator.EQUALS, assocType);                exprListOr.add(expr);            }            EntityConditionList assocExprList = new EntityConditionList(exprListOr, EntityOperator.OR);            exprListAnd.add(assocExprList);        }        if (fromDate != null) {            Timestamp tsFrom = UtilDateTime.toTimestamp(fromDate);            expr = new EntityExpr("fromDate", EntityOperator.GREATER_THAN_EQUAL_TO, tsFrom);            exprListAnd.add(expr);        }        if (thruDate != null) {            Timestamp tsThru = UtilDateTime.toTimestamp(thruDate);            expr = new EntityExpr("thruDate", EntityOperator.LESS_THAN, tsThru);            exprListAnd.add(expr);        }        EntityConditionList contentCondList = new EntityConditionList(exprListAnd, EntityOperator.AND);        GenericDelegator delegator = currentContent.getDelegator();        contentList = delegator.findByCondition(contentAssocViewName, contentCondList, null, null);        return contentList;    }    public static List getAssociations(GenericValue currentContent, String linkDir, List assocTypes, String strFromDate, String strThruDate) throws GenericEntityException {        GenericDelegator delegator = currentContent.getDelegator();        String origContentId = (String) currentContent.get("contentId");        Timestamp fromDate = null;        if (strFromDate != null) {            fromDate = UtilDateTime.toTimestamp(strFromDate);        }        Timestamp thruDate = null;        if (strThruDate != null) {            thruDate = UtilDateTime.toTimestamp(strThruDate);        }        List assocs = getContentAssocsWithId(delegator, origContentId, fromDate, thruDate, linkDir, assocTypes);        //if (Debug.infoOn()) Debug.logInfo(" origContentId:" + origContentId + " linkDir:" + linkDir + " assocTypes:" + assocTypes, "");        return assocs;    }    public static List getContentAssocsWithId(GenericDelegator delegator, String contentId, Timestamp fromDate, Timestamp thruDate, String direction, List assocTypes) throws GenericEntityException {        List exprList = new ArrayList();        EntityExpr joinExpr = null;        EntityExpr expr = null;        if (direction != null && direction.equalsIgnoreCase("From")) {            joinExpr = new EntityExpr("contentIdTo", EntityOperator.EQUALS, contentId);        } else {            joinExpr = new EntityExpr("contentId", EntityOperator.EQUALS, contentId);        }        exprList.add(joinExpr);        if (assocTypes != null && assocTypes.size() > 0) {            List exprListOr = new ArrayList();            Iterator it = assocTypes.iterator();            while (it.hasNext()) {                String assocType = (String) it.next();                expr = new EntityExpr("contentAssocTypeId", EntityOperator.EQUALS, assocType);                exprListOr.add(expr);            }            EntityConditionList assocExprList = new EntityConditionList(exprListOr, EntityOperator.OR);            exprList.add(assocExprList);        }        if (fromDate != null) {            EntityExpr fromExpr = new EntityExpr("fromDate", EntityOperator.GREATER_THAN_EQUAL_TO, fromDate);            exprList.add(fromExpr);        }        if (thruDate != null) {            List thruList = new ArrayList();            //thruDate = UtilDateTime.getDayStart(thruDate, daysLater);            EntityExpr thruExpr = new EntityExpr("thruDate", EntityOperator.LESS_THAN, thruDate);            thruList.add(thruExpr);            EntityExpr thruExpr2 = new EntityExpr("thruDate", EntityOperator.EQUALS, null);            thruList.add(thruExpr2);            EntityConditionList thruExprList = new EntityConditionList(thruList, EntityOperator.OR);            exprList.add(thruExprList);        } else if (fromDate != null) {            List thruList = new ArrayList();            EntityExpr thruExpr = new EntityExpr("thruDate", EntityOperator.GREATER_THAN, fromDate);            thruList.add(thruExpr);            EntityExpr thruExpr2 = new EntityExpr("thruDate", EntityOperator.EQUALS, null);            thruList.add(thruExpr2);            EntityConditionList thruExprList = new EntityConditionList(thruList, EntityOperator.OR);            exprList.add(thruExprList);        } else {            EntityExpr thruExpr2 = new EntityExpr("thruDate", EntityOperator.EQUALS, null);            exprList.add(thruExpr2);        }        EntityConditionList assocExprList = new EntityConditionList(exprList, EntityOperator.AND);        //if (Debug.infoOn()) Debug.logInfo(" assocExprList:" + assocExprList , "");        List relatedAssocs = delegator.findByCondition("ContentAssoc", assocExprList, new ArrayList(), UtilMisc.toList("-fromDate"));        //if (Debug.infoOn()) Debug.logInfo(" relatedAssoc:" + relatedAssocs.size() , "");        //for (int i = 0; i < relatedAssocs.size(); i++) {            //GenericValue a = (GenericValue) relatedAssocs.get(i);        //}        return relatedAssocs;    }    public static void getContentTypeAncestry(GenericDelegator delegator, String contentTypeId, List contentTypes) throws GenericEntityException {        contentTypes.add(contentTypeId);        GenericValue contentTypeValue = delegator.findByPrimaryKey("ContentType", UtilMisc.toMap("contentTypeId", contentTypeId));        if (contentTypeValue == null)            return;        String parentTypeId = (String) contentTypeValue.get("parentTypeId");        if (parentTypeId != null) {            getContentTypeAncestry(delegator, parentTypeId, contentTypes);        }        return;    }    public static void getContentAncestry(GenericDelegator delegator, String contentId, String contentAssocTypeId, String direction, List contentAncestorList) throws GenericEntityException {        String contentIdField = null;        String contentIdOtherField = null;        if (direction != null && direction.equalsIgnoreCase("to")) {            contentIdField = "contentId";            contentIdOtherField = "contentIdTo";        } else {            contentIdField = "contentIdTo";            contentIdOtherField = "contentId";        }                if (Debug.infoOn()) Debug.logInfo("getContentAncestry, contentId:" + contentId, "");        if (Debug.infoOn()) Debug.logInfo("getContentAncestry, contentAssocTypeId:" + contentAssocTypeId, "");        Map andMap = null;        if (UtilValidate.isEmpty(contentAssocTypeId)) {            andMap = UtilMisc.toMap(contentIdField, contentId);        } else {            andMap = UtilMisc.toMap(contentIdField, contentId, "contentAssocTypeId", contentAssocTypeId);        }        try {            List lst = delegator.findByAndCache("ContentAssoc", andMap);            //if (Debug.infoOn()) Debug.logInfo("getContentAncestry, lst:" + lst, "");            List lst2 = EntityUtil.filterByDate(lst);            //if (Debug.infoOn()) Debug.logInfo("getContentAncestry, lst2:" + lst2, "");            if (lst2.size() > 0) {                GenericValue contentAssoc = (GenericValue)lst2.get(0);                getContentAncestry(delegator, contentAssoc.getString(contentIdOtherField), contentAssocTypeId, direction, contentAncestorList);                contentAncestorList.add(contentAssoc.getString(contentIdOtherField));            }        } catch(GenericEntityException e) {            Debug.logError(e,module);             return;        }        return;    }        public static void getContentAncestryAll(GenericDelegator delegator, String contentId, String passedContentTypeId, String direction, List contentAncestorList) {        String contentIdField = null;        String contentIdOtherField = null;        if (direction != null && direction.equalsIgnoreCase("to")) {            contentIdField = "contentId";            contentIdOtherField = "contentIdTo";        } else {            contentIdField = "contentIdTo";            contentIdOtherField = "contentId";        }                if (Debug.infoOn()) Debug.logInfo("getContentAncestry, contentId:" + contentId, "");        Map andMap = UtilMisc.toMap(contentIdField, contentId);        try {            List lst = delegator.findByAndCache("ContentAssoc", andMap);            //if (Debug.infoOn()) Debug.logInfo("getContentAncestry, lst:" + lst, "");            List lst2 = EntityUtil.filterByDate(lst);            //if (Debug.infoOn()) Debug.logInfo("getContentAncestry, lst2:" + lst2, "");            Iterator iter = lst2.iterator();            while (iter.hasNext()) {                GenericValue contentAssoc = (GenericValue)iter.next();                String contentIdOther = contentAssoc.getString(contentIdOtherField);                if (!contentAncestorList.contains(contentIdOther)) {                    getContentAncestryAll(delegator, contentIdOther, passedContentTypeId, direction, contentAncestorList);                    if (!contentAncestorList.contains(contentIdOther)) {                        GenericValue contentTo = delegator.findByPrimaryKeyCache("Content", UtilMisc.toMap("contentId", contentIdOther));                        String contentTypeId = contentTo.getString("contentTypeId");                        if (contentTypeId != null && contentTypeId.equals(passedContentTypeId))                            contentAncestorList.add(contentIdOther );                    }                }            }        } catch(GenericEntityException e) {            Debug.logError(e,module);             return;        }        return;    }    public static List getContentAncestryNodeTrail(GenericDelegator delegator, String contentId, String contentAssocTypeId, String direction) throws GenericEntityException {         List contentAncestorList = new ArrayList();         List nodeTrail = new ArrayList();         getContentAncestry(delegator, contentId, contentAssocTypeId, direction, contentAncestorList);         Iterator contentAncestorListIter = contentAncestorList.iterator();          while (contentAncestorListIter.hasNext()) {             GenericValue value = (GenericValue) contentAncestorListIter.next();             Map thisNode = ContentWorker.makeNode(value);             nodeTrail.add(thisNode);         }

⌨️ 快捷键说明

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