📄 contentservices.java
字号:
return result; } /** * Create a Content method. The work is done in this separate method so that complex services that need this functionality do not need to incur the * reflection performance penalty. */ public static Map createContentMethod(DispatchContext dctx, Map context) { context.put("entityOperation", "_CREATE"); List targetOperationList = ContentWorker.prepTargetOperationList(context, "_CREATE"); if (Debug.infoOn()) Debug.logInfo("in createContentMethod, targetOperationList: " + targetOperationList, null); List contentPurposeList = ContentWorker.prepContentPurposeList(context); context.put("targetOperationList", targetOperationList); context.put("contentPurposeList", contentPurposeList); Timestamp nowTimestamp = UtilDateTime.nowTimestamp(); Map result = new HashMap(); GenericDelegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); String contentId = (String) context.get("contentId"); //String contentTypeId = (String) context.get("contentTypeId"); if (UtilValidate.isEmpty(contentId)) { contentId = delegator.getNextSeqId("Content"); } GenericValue content = delegator.makeValue("Content", UtilMisc.toMap("contentId", contentId)); content.setNonPKFields(context); GenericValue userLogin = (GenericValue) context.get("userLogin"); String userLoginId = (String) userLogin.get("userLoginId"); content.put("createdByUserLogin", userLoginId); content.put("lastModifiedByUserLogin", userLoginId); content.put("createdDate", nowTimestamp); content.put("lastModifiedDate", nowTimestamp); context.put("currentContent", content); if (Debug.infoOn()) Debug.logInfo("in createContentMethod, context: " + context, null); Map permResults = ContentWorker.callContentPermissionCheckResult(delegator, dispatcher, context); String permissionStatus = (String) permResults.get("permissionStatus"); if (permissionStatus != null && permissionStatus.equalsIgnoreCase("granted")) { try { content.create(); } catch (GenericEntityException e) { return ServiceUtil.returnError(e.getMessage()); } catch (Exception e2) { return ServiceUtil.returnError(e2.getMessage()); } result.put("contentId", contentId); } else { String errorMsg = (String) permResults.get(ModelService.ERROR_MESSAGE); result.put(ModelService.ERROR_MESSAGE, errorMsg); return ServiceUtil.returnFailure(errorMsg); } context.remove("currentContent"); return result; } /** * Create a ContentAssoc service. The work is done in a separate method so that complex services that need this functionality do not need to incur the * reflection performance penalty. */ public static Map createContentAssoc(DispatchContext dctx, Map context) { context.put("entityOperation", "_CREATE"); List targetOperationList = ContentWorker.prepTargetOperationList(context, "_CREATE"); List contentPurposeList = ContentWorker.prepContentPurposeList(context); context.put("targetOperationList", targetOperationList); context.put("contentPurposeList", contentPurposeList); context.put("skipPermissionCheck", null); Map result = null; try { result = createContentAssocMethod(dctx, context); } catch (GenericServiceException e) { return ServiceUtil.returnError(e.getMessage()); } catch (GenericEntityException e2) { return ServiceUtil.returnError(e2.getMessage()); } catch (Exception e3) { return ServiceUtil.returnError(e3.getMessage()); } return result; } /** * Create a ContentAssoc method. The work is done in this separate method so that complex services that need this functionality do not need to incur the * reflection performance penalty. */ public static Map createContentAssocMethod(DispatchContext dctx, Map context) throws GenericServiceException, GenericEntityException { List targetOperationList = ContentWorker.prepTargetOperationList(context, "_CREATE"); List contentPurposeList = ContentWorker.prepContentPurposeList(context); context.put("targetOperationList", targetOperationList); context.put("contentPurposeList", contentPurposeList); GenericDelegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); Map result = new HashMap(); // This section guesses how contentId should be used (From or To) if // only a contentIdFrom o contentIdTo is passed in String contentIdFrom = (String) context.get("contentIdFrom"); String contentIdTo = (String) context.get("contentIdTo"); String contentId = (String) context.get("contentId"); int contentIdCount = 0; if (UtilValidate.isNotEmpty(contentIdFrom)) contentIdCount++; if (UtilValidate.isNotEmpty(contentIdTo)) contentIdCount++; if (UtilValidate.isNotEmpty(contentId)) contentIdCount++; if (contentIdCount < 2) { Debug.logError("Not 2 out of ContentId/To/From.", "ContentServices"); return ServiceUtil.returnError("Not 2 out of ContentId/To/From"); } if (UtilValidate.isNotEmpty(contentIdFrom)) { if (UtilValidate.isEmpty(contentIdTo)) contentIdTo = contentId; } if (UtilValidate.isNotEmpty(contentIdTo)) { if (UtilValidate.isEmpty(contentIdFrom)) contentIdFrom = contentId; } /* String deactivateExisting = (String) context.get("deactivateExisting"); if (deactivateExisting != null && deactivateExisting.equalsIgnoreCase("true")) { Map andMap = new HashMap(); andMap.put("contentIdTo", contentIdTo); andMap.put("contentAssocTypeId", context.get("contentAssocTypeId")); String mapKey = (String) context.get("mapKey"); if (UtilValidate.isNotEmpty(mapKey)) { andMap.put("mapKey", mapKey); } if (Debug.infoOn()) Debug.logInfo("DEACTIVATING CONTENTASSOC andMap: " + andMap, null); List assocList = delegator.findByAnd("ContentAssoc", andMap); Iterator iter = assocList.iterator(); while (iter.hasNext()) { GenericValue val = (GenericValue) iter.next(); if (Debug.infoOn()) Debug.logInfo("DEACTIVATING CONTENTASSOC val: " + val, null); val.set("thruDate", UtilDateTime.nowTimestamp()); val.store(); } } */ GenericValue contentAssoc = delegator.makeValue("ContentAssoc", new HashMap()); contentAssoc.put("contentId", contentIdFrom); contentAssoc.put("contentIdTo", contentIdTo); contentAssoc.put("contentAssocTypeId", context.get("contentAssocTypeId")); contentAssoc.put("contentAssocPredicateId", context.get("contentAssocPredicateIdFrom")); contentAssoc.put("dataSourceId", context.get("dataSourceId")); Timestamp fromDate = (Timestamp) context.get("fromDate"); if (fromDate == null) { contentAssoc.put("fromDate", UtilDateTime.nowTimestamp()); } else { contentAssoc.put("fromDate", fromDate); } Timestamp thruDate = (Timestamp) context.get("thruDate"); if (thruDate == null) { contentAssoc.put("thruDate", null); } else { contentAssoc.put("thruDate", thruDate); } contentAssoc.put("sequenceNum", context.get("sequenceNum")); contentAssoc.put("mapKey", context.get("mapKey")); String upperCoordinateStr = (String) context.get("upperCoordinate"); if (UtilValidate.isEmpty(upperCoordinateStr)) { contentAssoc.put("upperCoordinate", null); } else { contentAssoc.put("upperCoordinate", upperCoordinateStr); } String leftCoordinateStr = (String) context.get("leftCoordinate"); if (UtilValidate.isEmpty(leftCoordinateStr)) { contentAssoc.put("leftCoordinate", null); } else { contentAssoc.put("leftCoordinate", leftCoordinateStr); } GenericValue userLogin = (GenericValue) context.get("userLogin"); String userLoginId = (String) userLogin.get("userLoginId"); String createdByUserLogin = userLoginId; String lastModifiedByUserLogin = userLoginId; Timestamp createdDate = UtilDateTime.nowTimestamp(); Timestamp lastModifiedDate = UtilDateTime.nowTimestamp(); contentAssoc.put("createdByUserLogin", createdByUserLogin); contentAssoc.put("lastModifiedByUserLogin", lastModifiedByUserLogin); contentAssoc.put("createdDate", createdDate); contentAssoc.put("lastModifiedDate", lastModifiedDate); Map serviceInMap = new HashMap(); String permissionStatus = null; serviceInMap.put("userLogin", context.get("userLogin")); serviceInMap.put("targetOperationList", targetOperationList); serviceInMap.put("contentPurposeList", contentPurposeList); serviceInMap.put("entityOperation", context.get("entityOperation")); serviceInMap.put("contentAssocPredicateId", context.get("contentAssocPredicateId")); serviceInMap.put("contentIdTo", contentIdTo); serviceInMap.put("contentIdFrom", contentIdFrom); serviceInMap.put("statusId", context.get("statusId")); serviceInMap.put("privilegeEnumId", context.get("privilegeEnumId")); serviceInMap.put("roleTypeList", context.get("roleTypeList")); serviceInMap.put("displayFailCond", context.get("displayFailCond")); Map permResults = null; permResults = dispatcher.runSync("checkAssocPermission", serviceInMap); permissionStatus = (String) permResults.get("permissionStatus"); if (permissionStatus != null && permissionStatus.equals("granted")) { contentAssoc.create(); } else { String errorMsg = (String)permResults.get(ModelService.ERROR_MESSAGE); result.put(ModelService.ERROR_MESSAGE, errorMsg); return ServiceUtil.returnFailure(errorMsg); } result.put("contentIdTo", contentIdTo); result.put("contentIdFrom", contentIdFrom); result.put("fromDate", contentAssoc.get("fromDate")); result.put("contentAssocTypeId", contentAssoc.get("contentAssocTypeId")); //Debug.logInfo("result:" + result, module); //Debug.logInfo("contentAssoc:" + contentAssoc, module); return result; } /** * A service wrapper for the updateContentMethod method. Forces permissions to be checked. */ public static Map updateContent(DispatchContext dctx, Map context) { context.put("entityOperation", "_UPDATE"); List targetOperationList = ContentWorker.prepTargetOperationList(context, "_UPDATE"); List contentPurposeList = ContentWorker.prepContentPurposeList(context); context.put("targetOperationList", targetOperationList); context.put("contentPurposeList", contentPurposeList); context.put("skipPermissionCheck", null); Map result = updateContentMethod(dctx, context); return result; } /** * Update a Content method. The work is done in this separate method so that complex services that need this functionality do not need to incur the * reflection performance penalty of calling a service. */ public static Map updateContentMethod(DispatchContext dctx, Map context) { GenericDelegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); Map result = new HashMap();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -