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

📄 contentmanagementservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    public static Map updateSiteRolesDyn(DispatchContext dctx, Map context) {      LocalDispatcher dispatcher = dctx.getDispatcher();      GenericDelegator delegator = dctx.getDelegator();      Map results = new HashMap();      Map serviceContext = new HashMap();      // siteContentId will equal "ADMIN_MASTER", "AGINC_MASTER", etc.      // Remember that this service is called in the "multi" mode,      // with a new siteContentId each time.      // siteContentId could also have been name deptContentId, since this same      // service is used for updating department roles, too.      String siteContentId = (String)context.get("contentId");      String partyId = (String)context.get("partyId");      serviceContext.put("partyId", partyId);      serviceContext.put("contentId", siteContentId);      //Debug.logInfo("updateSiteRoles, serviceContext(0):" + serviceContext, module);      //Debug.logInfo("updateSiteRoles, context(0):" + context, module);      List siteRoles = null;      try {            siteRoles = delegator.findByAndCache("RoleType", UtilMisc.toMap("parentTypeId", "BLOG"));      } catch(GenericEntityException e) {          return ServiceUtil.returnError( e.getMessage());      }      Iterator siteRoleIter = siteRoles.iterator();      while (siteRoleIter.hasNext()) {            GenericValue roleType = (GenericValue)siteRoleIter.next();          String siteRole = (String)roleType.get("roleTypeId"); // BLOG_EDITOR, BLOG_ADMIN, etc.          String cappedSiteRole = ModelUtil.dbNameToVarName(siteRole);          //if (Debug.infoOn()) Debug.logInfo("updateSiteRoles, cappediteRole(1):" + cappedSiteRole, module);          String siteRoleVal = (String)context.get(cappedSiteRole);          Object fromDate = context.get(cappedSiteRole + "FromDate");          serviceContext.put("roleTypeId", siteRole);          if (siteRoleVal != null && siteRoleVal.equalsIgnoreCase("Y")) {                  // for now, will assume that any error is due to duplicates - ignore                  //return ServiceUtil.returnError(e.getMessage());              if (fromDate == null ) {                  try {                      serviceContext.put("fromDate", UtilDateTime.nowTimestamp());                      if (Debug.infoOn()) Debug.logInfo("updateSiteRoles, serviceContext(1):" + serviceContext, module);                      addRoleToUser(delegator, dispatcher, serviceContext);                      Map permResults = dispatcher.runSync("createContentRole", serviceContext);                  } catch (GenericServiceException e) {                      Debug.logError(e, e.getMessage(), module);                  } catch (Exception e2) {                      Debug.logError(e2, e2.getMessage(), module);                  }              }          } else {              if (fromDate != null ) {                      // for now, will assume that any error is due to non-existence - ignore                      //return ServiceUtil.returnError(e.getMessage());                  try {Debug.logInfo("updateSiteRoles, serviceContext(2):" + serviceContext, module);                      //Timestamp thruDate = UtilDateTime.nowTimestamp();                      //serviceContext.put("thruDate", thruDate);                      //serviceContext.put("fromDate", fromDate);                      Map newContext = new HashMap();                      newContext.put("contentId", serviceContext.get("contentId"));                      newContext.put("partyId", serviceContext.get("partyId"));                      newContext.put("roleTypeId", serviceContext.get("roleTypeId"));                      Map permResults = dispatcher.runSync("deactivateAllContentRoles", newContext);                  } catch (GenericServiceException e) {                      Debug.logError(e, e.getMessage(), module);                  } catch (Exception e2) {                      Debug.logError(e2, e2.getMessage(), module);                  }              }          }      }      return results;  }    public static Map updateOrRemove(DispatchContext dctx, Map context) {        Map results = new HashMap();        GenericDelegator delegator = dctx.getDelegator();        String entityName = (String)context.get("entityName");        String action = (String)context.get("action");        String pkFieldCount = (String)context.get("pkFieldCount");        Map pkFields = new HashMap();        int fieldCount = Integer.parseInt(pkFieldCount);        for (int i=0; i<fieldCount; i++) {            String fieldName = (String)context.get("fieldName" + i);            String fieldValue = (String)context.get("fieldValue" + i);            if (UtilValidate.isEmpty(fieldValue)) {                // It may be the case that the last row in a form is "empty" waiting for                // someone to enter a value, in which case we do not want to throw an                // error, we just want to ignore it.                return results;            }            pkFields.put(fieldName, fieldValue);        }        boolean doLink = (action != null && action.equalsIgnoreCase("Y")) ? true : false;        if (Debug.infoOn()) Debug.logInfo("in updateOrRemove, context:" + context, module);        try {            GenericValue entityValuePK = delegator.makeValue(entityName, pkFields);            if (Debug.infoOn()) Debug.logInfo("in updateOrRemove, entityValuePK:" + entityValuePK, module);            GenericValue entityValueExisting = delegator.findByPrimaryKeyCache(entityName, entityValuePK);            if (Debug.infoOn()) Debug.logInfo("in updateOrRemove, entityValueExisting:" + entityValueExisting, module);            if (entityValueExisting == null) {                if (doLink) {                    entityValuePK.create();                    if (Debug.infoOn()) Debug.logInfo("in updateOrRemove, entityValuePK: CREATED", module);                }            } else {                if (!doLink) {                    entityValueExisting.remove();                    if (Debug.infoOn()) Debug.logInfo("in updateOrRemove, entityValueExisting: REMOVED", module);                }            }                    } catch (GenericEntityException e) {            Debug.logError(e, module);            return ServiceUtil.returnError(e.getMessage());        }        return results;     }        public static Map resequence(DispatchContext dctx, Map context) throws GenericServiceException{        HashMap result = new HashMap();        GenericDelegator delegator = dctx.getDelegator();        String contentIdTo = (String)context.get("contentIdTo");        Integer seqInc = (Integer)context.get("seqInc");        if (seqInc == null)            seqInc = new Integer(100);        int seqIncrement = seqInc.intValue();        List typeList = (List)context.get("typeList");        if (typeList == null) typeList = new ArrayList();        String contentAssocTypeId = (String)context.get("contentAssocTypeId");        if (UtilValidate.isNotEmpty(contentAssocTypeId)) typeList.add(contentAssocTypeId);        if (UtilValidate.isEmpty(typeList)) typeList = UtilMisc.toList("PUBLISH_LINK", "SUB_CONTENT");        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("contentIdTo", EntityOperator.EQUALS, contentIdTo), conditionType), EntityOperator.AND);         try {             List listAll = delegator.findByCondition("ContentAssoc", conditionMain, null, UtilMisc.toList("sequenceNum", "fromDate", "createdDate"));             List listFiltered = EntityUtil.filterByDate(listAll);             String contentId = (String)context.get("contentId");             String dir = (String)context.get("dir");             int seqNum = seqIncrement;             String thisContentId = null;             for (int i=0; i < listFiltered.size(); i++) {                 GenericValue contentAssoc = (GenericValue)listFiltered.get(i);                 if (UtilValidate.isNotEmpty(contentId) && UtilValidate.isNotEmpty(dir)) {                     // move targeted entry up or down                     thisContentId = contentAssoc.getString("contentId");                     if (contentId.equals(thisContentId)) {                         if (dir.startsWith("up")) {                             if (i > 0) {                                 // Swap with previous entry                                  try {                                     GenericValue prevValue = (GenericValue)listFiltered.get(i-1);                                     Long prevSeqNum = (Long)prevValue.get("sequenceNum");                                     prevValue.put("sequenceNum", new Long(seqNum));                                     prevValue.store();                                     contentAssoc.put("sequenceNum", prevSeqNum);                                     contentAssoc.store();                                 } catch (Exception e) {                                     return ServiceUtil.returnError(e.getMessage());                                              }                             }                         } else {                             if (i < listFiltered.size()) {                                 // Swap with next entry                                  GenericValue nextValue = (GenericValue)listFiltered.get(i+1);                                 nextValue.put("sequenceNum", new Long(seqNum));                                 nextValue.store();                                 seqNum += seqIncrement;                                 contentAssoc.put("sequenceNum", new Long(seqNum));                                 contentAssoc.store();                                 i++; // skip next one                             }                         }                     } else {                         contentAssoc.put("sequenceNum", new Long(seqNum));                         contentAssoc.store();                     }                 } else {                     contentAssoc.put("sequenceNum", new Long(seqNum));                     contentAssoc.store();                 }                 seqNum += seqIncrement;             }        } catch(GenericEntityException e) {            Debug.logError(e, module);            return ServiceUtil.returnError(e.getMessage());                      }                        return result;    }        public static Map changeLeafToNode(DispatchContext dctx, Map context) throws GenericServiceException{        Map result = new HashMap();        GenericDelegator delegator = dctx.getDelegator();        LocalDispatcher dispatcher = dctx.getDispatcher();        String contentId = (String)context.get("contentId");        GenericValue userLogin = (GenericValue)context.get("userLogin");        String userLoginId = userLogin.getString("userLoginId");        //int seqNum = 9999;        try {            GenericValue content = delegator.findByPrimaryKey("Content", UtilMisc.toMap("contentId", contentId));            if (content == null) {                Debug.logError("content was null", module);                return ServiceUtil.returnError("content was null");            }            String dataResourceId = content.getString("dataResourceId");            //String contentTypeIdTo = content.getString("contentTypeId");            /* this does not seem to be correct or needed            if (UtilValidate.isNotEmpty(contentTypeIdTo)) {                if (contentTypeIdTo.equals("OUTLINE_NODE")) {                    content.put("contentTypeId", "OUTLINE_NODE");                } else if (contentTypeIdTo.equals("PAGE_NODE")) {                    content.put("contentTypeId", "SUBPAGE_NODE");                } else                    content.put("contentTypeId", "PAGE_NODE");            }            */            content.set("dataResourceId", null);            content.set("lastModifiedDate", UtilDateTime.nowTimestamp());            content.set("lastModifiedByUserLogin", userLoginId);            content.store();                        if (UtilValidate.isNotEmpty(dataResourceId)) {                // add previous DataResource as part of new subcontent                GenericValue contentClone = (GenericValue)content.clone();                contentClone.set("dataResourceId", dataResourceId);                content.set("lastModifiedDate", UtilDateTime.nowTimestamp());                content.set("lastModifiedByUserLogin", userLoginId);                content.set("createdDate", UtilDateTime.nowTimestamp());                content.set("createdByUserLogin", userLoginId);                                contentClone.set("contentId", null);                ModelService modelService = dctx.getModelService("persistContentAndAssoc");                Map serviceIn = modelService.makeValid(contentClone, "IN");                serviceIn.put("userLogin", userLogin);                serviceIn.put("contentIdTo", contentId);                serviceIn.put("contentAssocTypeId", "SUB_CONTENT");                serviceIn.put("sequenceNum", new Long(50));                try {                    Map thisResult = dispatcher.runSync("persistContentAndAssoc", serviceIn);                } catch(ServiceAuthException e) {                    return ServiceUtil.returnError(e.getMessage());                             }

⌨️ 快捷键说明

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