📄 contentservices.java
字号:
content.put("createdDate", createdDate);
content.put("lastModifiedDate", lastModifiedDate);
if (Debug.infoOn()) Debug.logInfo("in createContent, content:" + content, "");
try {
content.create();
} catch (GenericEntityException e) {
return ServiceUtil.returnError(e.getMessage());
} catch(Exception e2) {
return ServiceUtil.returnError(e2.getMessage());
}
result.put("contentId", contentId);
}
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 targetOperations = new ArrayList();
targetOperations.add("CREATE_CONTENT");
context.put("targetOperationList", targetOperations);
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 {
Map result = new HashMap();
GenericDelegator delegator = dctx.getDelegator();
LocalDispatcher dispatcher = dctx.getDispatcher();
// 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");
Debug.logVerbose("CREATING CONTENTASSOC contentIdFrom(1):" + contentIdFrom, null);
Debug.logVerbose("CREATING CONTENTASSOC contentIdTo(1):" + contentIdTo, null);
Debug.logVerbose("CREATING CONTENTASSOC contentId:" + contentId, null);
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;
}
Debug.logVerbose("CREATING CONTENTASSOC contentIdFrom(2):" + contentIdFrom, null);
Debug.logVerbose("CREATING CONTENTASSOC contentIdTo(2):" + contentIdTo, null);
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.set("fromDate", fromDate);
}
Timestamp thruDate = (Timestamp) context.get("thruDate");
if (thruDate == null) {
contentAssoc.put("thruDate", null);
} else {
contentAssoc.set("thruDate", thruDate);
}
contentAssoc.set("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.setString("upperCoordinate", upperCoordinateStr);
}
String leftCoordinateStr = (String) context.get("leftCoordinate");
if (UtilValidate.isEmpty(leftCoordinateStr)) {
contentAssoc.put("leftCoordinate", null);
} else {
contentAssoc.setString("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);
String permissionStatus = null;
Map serviceInMap = new HashMap();
serviceInMap.put("userLogin", context.get("userLogin"));
List targetOperations = new ArrayList();
targetOperations.add("ASSOC_CONTENT");
serviceInMap.put("targetOperationList", targetOperations);
serviceInMap.put("contentPurposeList", context.get("contentPurposeList"));
serviceInMap.put("entityOperation", context.get("entityOperation"));
serviceInMap.put("contentIdTo", contentIdTo);
serviceInMap.put("contentIdFrom", contentIdFrom);
Map permResults = null;
permResults = dispatcher.runSync("checkAssocPermission", serviceInMap);
permissionStatus = (String) permResults.get("permissionStatus");
//Debug.logVerbose("CREATING CONTENTASSOC:" + contentAssoc, null);
if (permissionStatus != null && permissionStatus.equals("granted")) {
contentAssoc.create();
}
result.put("contentIdTo", contentIdTo);
result.put("contentIdFrom", contentIdFrom);
result.put("fromDate", contentAssoc.get("fromDate"));
result.put("contentAssocTypeId", contentAssoc.get("contentAssocTypeId"));
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", "_CREATE");
List targetOperations = new ArrayList();
targetOperations.add("CREATE_CONTENT");
context.put("targetOperationList", targetOperations);
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) {
Map result = new HashMap();
GenericDelegator delegator = dctx.getDelegator();
LocalDispatcher dispatcher = dctx.getDispatcher();
GenericValue dataResource = null;
//Locale locale = (Locale) context.get("locale");
String permissionStatus = ContentWorker.callContentPermissionCheck(delegator, dispatcher, context);
if (permissionStatus != null && permissionStatus.equalsIgnoreCase("granted")) {
GenericValue userLogin = (GenericValue) context.get("userLogin");
String userLoginId = (String) userLogin.get("userLoginId");
String lastModifiedByUserLogin = userLoginId;
Timestamp lastModifiedDate = UtilDateTime.nowTimestamp();
// If textData exists, then create Content and return contentId
String contentId = (String) context.get("contentId");
try {
dataResource = delegator.findByPrimaryKey("Content", UtilMisc.toMap("contentId", contentId));
} catch (GenericEntityException e) {
Debug.logWarning(e, module);
return ServiceUtil.returnError("dataResource.update.read_failure" + e.getMessage());
}
dataResource.setNonPKFields(context);
dataResource.put("lastModifiedByUserLogin", lastModifiedByUserLogin);
dataResource.put("lastModifiedDate", lastModifiedDate);
try {
dataResource.store();
} catch (GenericEntityException e) {
return ServiceUtil.returnError(e.getMessage());
}
}
return result;
}
/**
* Update 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 updateContentAssoc(DispatchContext dctx, Map context) {
context.put("entityOperation", "_UPDATE");
List targetOperations = new ArrayList();
targetOperations.add("UPDATE_CONTENT");
context.put("targetOperationList", targetOperations);
context.put("skipPermissionCheck", null);
Map result = updateContentAssocMethod(dctx, context);
return result;
}
/**
* Update 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 updateContentAssocMethod(DispatchContext dctx, Map context) {
Map result = new HashMap();
GenericDelegator delegator = dctx.getDelegator();
LocalDispatcher dispatcher = dctx.getDispatcher();
// This section guesses how contentId should be used (From or To) if
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -