📄 contentmanagementservices.java
字号:
package org.ofbiz.content;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Locale;
import java.io.IOException;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilDateTime;
import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.base.util.UtilProperties;
import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.GenericPK;
import org.ofbiz.entity.condition.EntityCondition;
import org.ofbiz.entity.condition.EntityConditionList;
import org.ofbiz.entity.condition.EntityExpr;
import org.ofbiz.entity.condition.EntityOperator;
import org.ofbiz.entity.util.ByteWrapper;
import org.ofbiz.security.Security;
import org.ofbiz.service.DispatchContext;
import org.ofbiz.service.ServiceUtil;
import org.ofbiz.service.GenericServiceException;
import org.ofbiz.service.LocalDispatcher;
import org.ofbiz.service.ModelService;
import org.ofbiz.content.ContentManagementWorker;
import org.ofbiz.content.content.ContentServices;
import org.ofbiz.content.data.DataServices;
import org.ofbiz.content.content.ContentWorker;
/**
* ContentManagementServices Class
*
* @author <a href="mailto:byersa@automationgroups.com">Al Byers</a>
* @version $Revision: 1.7 $
* @since 3.0
*
*
*/
public class ContentManagementServices {
public static final String module = ContentManagementServices.class.getName();
/**
* getSubContent
* Finds the related subContent given the template Content and the mapKey.
* This service calls a same-named method in ContentWorker to do the work.
*/
public static Map getSubContent(DispatchContext dctx, Map context) {
Map results = new HashMap();
Security security = dctx.getSecurity();
GenericDelegator delegator = dctx.getDelegator();
LocalDispatcher dispatcher = dctx.getDispatcher();
String contentId = (String) context.get("contentId");
String subContentId = (String) context.get("subContentId");
String mapKey = (String) context.get("mapKey");
GenericValue userLogin = (GenericValue)context.get("userLogin");
Timestamp fromDate = (Timestamp)context.get("fromDate");
List assocTypes = (List) context.get("assocTypes");
GenericValue content = null;
GenericValue view = null;
//Debug.logVerbose("in getSubContent(svc), contentId:" + contentId, "");
//Debug.logVerbose("in getSubContent(svc), subContentId:" + subContentId, "");
//Debug.logVerbose("in getSubContent(svc), mapKey:" + mapKey, "");
try {
view = ContentWorker.getSubContent( delegator,
contentId, mapKey, subContentId, userLogin, assocTypes, fromDate);
content = ContentWorker.getContentFromView(view);
} catch(IOException e) {
return ServiceUtil.returnError(e.getMessage());
}
results.put("view", view);
results.put("content", content);
return results;
}
/**
* addMostRecent
* A service for adding the most recently used of an entity class to the cache.
* Entities make it to the most recently used list primarily by being selected for editing,
* either by being created or being selected from a list.
*/
public static Map addMostRecent(DispatchContext dctx, Map context) {
Map results = new HashMap();
Security security = dctx.getSecurity();
GenericDelegator delegator = dctx.getDelegator();
LocalDispatcher dispatcher = dctx.getDispatcher();
HttpServletRequest request = (HttpServletRequest)context.get("request");
Debug.logVerbose("in addMostRecentEntity(svc2), request:" +request, "");
String suffix = (String) context.get("suffix");
GenericValue val = (GenericValue)context.get("pk");
GenericPK pk = val.getPrimaryKey();
HttpSession session = (HttpSession)context.get("session");
ContentManagementWorker.mruAdd(session, pk, suffix);
return results;
}
/**
* persistContentAndAssoc
* A combination method that will create or update all or one of the following
* a Content entity, a ContentAssoc related to the Content and
* the ElectronicText that may be associated with the Content.
* The keys for determining if each entity is created is the presence
* of the contentTypeId, contentAssocTypeId and dataResourceTypeId.
*/
public static Map persistContentAndAssoc(DispatchContext dctx, Map context) throws GenericServiceException{
//Debug.logVerbose("CREATING CONTENTANDASSOC:" + context, null);
HashMap result = new HashMap();
Security security = dctx.getSecurity();
GenericDelegator delegator = dctx.getDelegator();
LocalDispatcher dispatcher = dctx.getDispatcher();
Map permContext = new HashMap();
GenericValue content = delegator.makeValue("Content", null);
content.setPKFields(context);
content.setNonPKFields(context);
String contentId = (String)content.get("contentId");
String contentTypeId = (String)content.get("contentTypeId");
String origDataResourceId = (String)content.get("dataResourceId");
GenericValue dataResource = delegator.makeValue("DataResource", null);
dataResource.setPKFields(context);
dataResource.setNonPKFields(context);
String dataResourceId = (String)dataResource.get("dataResourceId");
String dataResourceTypeId = (String)dataResource.get("dataResourceTypeId");
GenericValue electronicText = delegator.makeValue("ElectronicText", null);
electronicText.setPKFields(context);
electronicText.setNonPKFields(context);
String textData = (String)electronicText.get("textData");
ByteWrapper byteWrapper = (ByteWrapper)context.get("imageData");
// get user info for multiple use
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();
// Do update and create permission checks on DataResource if warranted.
boolean updatePermOK = false;
boolean createPermOK = false;
if (UtilValidate.isNotEmpty(dataResourceTypeId)
|| UtilValidate.isNotEmpty(textData) ) {
List targetOperations = new ArrayList();
if (UtilValidate.isNotEmpty(dataResourceId) ) {
permContext.put("entityOperation", "_UPDATE");
targetOperations.add("UPDATE_CONTENT");
updatePermOK = true;
} else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -