📄 dataservices.java
字号:
String dataResourceTypeId = (String) context.get("dataResourceTypeId");
if (dataResourceTypeId != null && dataResourceTypeId.equals("ELECTRONIC_TEXT")) {
thisResult = updateElectronicText(dctx, context);
if (thisResult.get(ModelService.RESPONSE_MESSAGE) != null) {
return ServiceUtil.returnError((String) thisResult.get(ModelService.ERROR_MESSAGE));
}
}
}
return result;
}
/**
* A service wrapper for the updateDataResourceMethod method. Forces permissions to be checked.
*/
public static Map updateDataResource(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 = updateDataResourceMethod(dctx, context);
return result;
}
public static Map updateDataResourceMethod(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 = DataResourceWorker.callDataResourcePermissionCheck(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 DataResource and return dataResourceId
String dataResourceId = (String) context.get("dataResourceId");
try {
dataResource = delegator.findByPrimaryKey("DataResource", UtilMisc.toMap("dataResourceId", dataResourceId));
} 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());
}
}
result.put("dataResource", dataResource);
return result;
}
/**
* A service wrapper for the updateElectronicTextMethod method. Forces permissions to be checked.
*/
public static Map updateElectronicText(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 = updateElectronicTextMethod(dctx, context);
return result;
}
public static Map updateElectronicTextMethod(DispatchContext dctx, Map context) {
HashMap result = new HashMap();
GenericDelegator delegator = dctx.getDelegator();
LocalDispatcher dispatcher = dctx.getDispatcher();
GenericValue electronicText = null;
//Locale locale = (Locale) context.get("locale");
String permissionStatus = DataResourceWorker.callDataResourcePermissionCheck(delegator, dispatcher, context);
if (permissionStatus != null && permissionStatus.equalsIgnoreCase("granted")) {
String dataResourceId = (String) context.get("dataResourceId");
String textData = (String) context.get("textData");
if (textData != null && textData.length() > 0) {
try {
electronicText = delegator.findByPrimaryKey("ElectronicText", UtilMisc.toMap("dataResourceId", dataResourceId));
electronicText.put("textData", textData);
electronicText.store();
} catch (GenericEntityException e) {
Debug.logWarning(e, module);
return ServiceUtil.returnError("electronicText.update.read_failure" + e.getMessage());
}
}
}
return result;
}
/**
* A service wrapper for the updateFileMethod method. Forces permissions to be checked.
*/
public static Map updateFile(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 = null;
try {
result = updateFileMethod(dctx, context);
} catch (GenericServiceException e) {
return ServiceUtil.returnError(e.getMessage());
}
return result;
}
public static Map updateFileMethod(DispatchContext dctx, Map context) throws GenericServiceException {
HashMap result = new HashMap();
GenericDelegator delegator = dctx.getDelegator();
LocalDispatcher dispatcher = dctx.getDispatcher();
//GenericValue fileText = null;
//Locale locale = (Locale) context.get("locale");
String permissionStatus = DataResourceWorker.callDataResourcePermissionCheck(delegator, dispatcher, context);
if (permissionStatus != null && permissionStatus.equalsIgnoreCase("granted")) {
GenericValue dataResource = (GenericValue) context.get("dataResource");
//String dataResourceId = (String) dataResource.get("dataResourceId");
String dataResourceTypeId = (String) dataResource.get("dataResourceTypeId");
String objectInfo = (String) dataResource.get("objectInfo");
String textData = (String) context.get("textData");
String prefix = "";
File file = null;
String fileName = "";
String sep = "";
try {
if (UtilValidate.isEmpty(dataResourceTypeId) || dataResourceTypeId.equals("LOCAL_FILE")) {
fileName = prefix + sep + objectInfo;
file = new File(fileName);
if (file == null) {
throw new GenericServiceException("File: " + fileName + " is null.");
}
if (!file.isAbsolute()) {
throw new GenericServiceException("File: " + fileName + " is not absolute.");
}
} else if (dataResourceTypeId.equals("OFBIZ_FILE")) {
prefix = System.getProperty("ofbiz.home");
if (objectInfo.indexOf("/") != 0 && prefix.lastIndexOf("/") != (prefix.length() - 1)) {
sep = "/";
}
file = new File(prefix + sep + objectInfo);
} else if (dataResourceTypeId.equals("CONTEXT_FILE")) {
prefix = (String) context.get("rootDir");
if (objectInfo.indexOf("/") != 0 && prefix.lastIndexOf("/") != (prefix.length() - 1)) {
sep = "/";
}
file = new File(prefix + sep + objectInfo);
}
if (file == null) {
throw new IOException("File: " + file + " is null");
}
FileWriter out = new FileWriter(file);
out.write(textData);
out.close();
} catch (IOException e) {
Debug.logWarning(e, module);
throw new GenericServiceException(e.getMessage());
}
}
return result;
}
public static void renderDataResourceAsText(DispatchContext dctx, Map context) throws GeneralException, IOException {
//Map results = new HashMap();
GenericDelegator delegator = dctx.getDelegator();
//LocalDispatcher dispatcher = dctx.getDispatcher();
Writer out = (Writer) context.get("outWriter");
Map templateContext = (Map) context.get("templateContext");
//GenericValue userLogin = (GenericValue) context.get("userLogin");
String dataResourceId = (String) context.get("dataResourceId");
if (templateContext != null && UtilValidate.isEmpty(dataResourceId)) {
dataResourceId = (String) templateContext.get("dataResourceId");
}
String mimeTypeId = (String) context.get("mimeTypeId");
if (templateContext != null && UtilValidate.isEmpty(mimeTypeId)) {
mimeTypeId = (String) templateContext.get("mimeTypeId");
}
Locale locale = (Locale) context.get("locale");
if (templateContext == null) {
templateContext = new HashMap();
}
GenericValue view = (GenericValue) context.get("subContentDataResourceView");
DataResourceWorker.renderDataResourceAsText(delegator, dataResourceId, out, templateContext, view, locale, mimeTypeId);
return;
}
/**
* A service wrapper for the updateImageMethod method. Forces permissions to be checked.
*/
public static Map updateImage(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 = updateImageMethod(dctx, context);
return result;
}
public static Map updateImageMethod(DispatchContext dctx, Map context) {
HashMap result = new HashMap();
GenericDelegator delegator = dctx.getDelegator();
LocalDispatcher dispatcher = dctx.getDispatcher();
GenericValue image = null;
//Locale locale = (Locale) context.get("locale");
String permissionStatus = DataResourceWorker.callDataResourcePermissionCheck(delegator, dispatcher, context);
if (permissionStatus != null && permissionStatus.equalsIgnoreCase("granted")) {
String dataResourceId = (String) context.get("dataResourceId");
ByteWrapper byteWrapper = (ByteWrapper)context.get("imageData");
if (byteWrapper != null) {
byte[] imageBytes = byteWrapper.getBytes();
try {
GenericValue imageDataResource = delegator.findByPrimaryKey("ImageDataResource", UtilMisc.toMap("dataResourceId", dataResourceId));
imageDataResource.set("imageData", imageBytes);
imageDataResource.store();
} catch (GenericEntityException e) {
return ServiceUtil.returnError(e.getMessage());
}
}
}
return result;
}
/**
* A service wrapper for the createImageMethod method. Forces permissions to be checked.
*/
public static Map createImage(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 = createImageMethod(dctx, context);
return result;
}
public static Map createImageMethod(DispatchContext dctx, Map context) {
HashMap result = new HashMap();
GenericDelegator delegator = dctx.getDelegator();
LocalDispatcher dispatcher = dctx.getDispatcher();
String permissionStatus = DataResourceWorker.callDataResourcePermissionCheck(delegator, dispatcher, context);
if (permissionStatus != null && permissionStatus.equalsIgnoreCase("granted")) {
String dataResourceId = (String) context.get("dataResourceId");
ByteWrapper byteWrapper = (ByteWrapper)context.get("imageData");
if (byteWrapper != null) {
byte[] imageBytes = byteWrapper.getBytes();
try {
GenericValue imageDataResource = delegator.makeValue("ImageDataResource", UtilMisc.toMap("dataResourceId", dataResourceId));
imageDataResource.set("imageData", imageBytes);
imageDataResource.create();
} catch (GenericEntityException e) {
return ServiceUtil.returnError(e.getMessage());
}
}
}
return result;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -