[OFBiz] SVN: r6466 - in trunk/applications/content: script/org/ofbiz/content script/org/ofbiz/content/compdoc servicedef src/org/ofbiz/content src/org/ofbiz/content/content
byersa@svn.ofbiz.org
byersa at svn.ofbiz.org
Wed Jan 4 01:36:37 CST 2006
Author: byersa
Date: 2006-01-04 01:36:28 -0600 (Wed, 04 Jan 2006)
New Revision: 6466
Added:
trunk/applications/content/script/org/ofbiz/content/compdoc/
trunk/applications/content/script/org/ofbiz/content/compdoc/CompDocServices.xml
Modified:
trunk/applications/content/servicedef/services.xml
trunk/applications/content/src/org/ofbiz/content/ContentManagementServices.java
trunk/applications/content/src/org/ofbiz/content/content/ContentServices.java
Log:
Added a bunch of ContentApproval and ContentRevision/Item CRUD services.
One for updating both ContentRevision/Item and incrementing the contentRevisionSeqId.
Added persistContentWithRevision to automatically do revisioning.
Added findContentParents to find head of CompDoc tree (or other Content trees).
Added: trunk/applications/content/script/org/ofbiz/content/compdoc/CompDocServices.xml
===================================================================
--- trunk/applications/content/script/org/ofbiz/content/compdoc/CompDocServices.xml 2006-01-04 06:42:36 UTC (rev 6465)
+++ trunk/applications/content/script/org/ofbiz/content/compdoc/CompDocServices.xml 2006-01-04 07:36:28 UTC (rev 6466)
@@ -0,0 +1,144 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ * Copyright (c) 2001-2004 The Open For Business Project and repective authors.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
+ * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * @author <a href="mailto:byersa at automationgroups.com">Al Byers</a>
+ * @author <a href="mailto:jabster at juno.com">Jim Byers</a>
+ * @version 0
+ * Created on Jan 2, 2006
+ -->
+
+<simple-methods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="http://www.ofbiz.org/dtds/simple-methods.xsd">
+
+
+ <!-- Methods for ContentApproval -->
+ <simple-method method-name="createContentApproval" short-description="Create ContentApproval">
+ <log level="always" message="got into createContentApproval(4)"></log>
+ <check-permission action="_CREATE" permission="CONTENTMGR">
+ <fail-message message="Security Error: to run createContentApproval you must have the CONTENTMGR_CREATE or CONTENTMGR_ADMIN permission"/>
+ </check-permission>
+ <check-errors/>
+ <make-value entity-name="ContentApproval" value-name="newEntity"/>
+ <set-nonpk-fields map-name="parameters" value-name="newEntity"/>
+ <set-pk-fields map-name="parameters" value-name="newEntity"/>
+ <create-value value-name="newEntity"/>
+ </simple-method>
+ <simple-method method-name="updateContentApproval" short-description="Update ContentApproval">
+ <log level="always" message="got into updateContentApproval(4)"></log>
+ <check-permission action="_UPDATE" permission="CONTENTMGR">
+ <fail-message message="Security Error: to run updateContentApproval you must have the CONTENTMGR_UPDATE or CONTENTMGR_ADMIN permission"/>
+ </check-permission>
+ <check-errors/>
+ <make-value entity-name="ContentApproval" value-name="lookupKeyValue"/>
+ <set-pk-fields map-name="parameters" value-name="lookupKeyValue"/>
+ <find-by-primary-key entity-name="ContentApproval" map-name="lookupKeyValue" value-name="lookedUpValue"/>
+ <set-nonpk-fields map-name="parameters" value-name="lookedUpValue"/>
+ <store-value value-name="lookedUpValue"/>
+ </simple-method>
+ <simple-method method-name="removeContentApproval" short-description="Remove ContentApproval">
+ <check-permission action="_DELETE" permission="CONTENTMGR">
+ <fail-message message="Security Error: to run removeContentApproval you must have the CONTENTMGR_DELETE or CONTENTMGR_ADMIN permission"/>
+ </check-permission>
+ <check-errors/>
+ <make-value entity-name="ContentApproval" value-name="lookupKeyValue"/>
+ <set-pk-fields map-name="parameters" value-name="lookupKeyValue"/>
+ <find-by-primary-key entity-name="ContentApproval" map-name="lookupKeyValue" value-name="lookedUpValue"/>
+ <remove-value value-name="lookedUpValue"/>
+ </simple-method>
+
+ <!-- Methods for ContentRevision -->
+ <simple-method method-name="createContentRevision" short-description="Create ContentRevision">
+ <check-permission action="_CREATE" permission="CONTENTMGR">
+ <fail-message message="Security Error: to run createContentRevision you must have the CONTENTMGR_CREATE or CONTENTMGR_ADMIN permission"/>
+ </check-permission>
+ <check-errors/>
+ <make-value entity-name="ContentRevision" value-name="newEntity"/>
+ <set-nonpk-fields map-name="parameters" value-name="newEntity"/>
+ <set-pk-fields map-name="parameters" value-name="newEntity"/>
+ <create-value value-name="newEntity"/>
+ </simple-method>
+ <simple-method method-name="updateContentRevision" short-description="Update ContentRevision">
+ <check-permission action="_UPDATE" permission="CONTENTMGR">
+ <fail-message message="Security Error: to run updateContentRevision you must have the CONTENTMGR_UPDATE or CONTENTMGR_ADMIN permission"/>
+ </check-permission>
+ <check-errors/>
+ <make-value entity-name="ContentRevision" value-name="lookupKeyValue"/>
+ <set-pk-fields map-name="parameters" value-name="lookupKeyValue"/>
+ <find-by-primary-key entity-name="ContentRevision" map-name="lookupKeyValue" value-name="lookedUpValue"/>
+ <set-nonpk-fields map-name="parameters" value-name="lookedUpValue"/>
+ <store-value value-name="lookedUpValue"/>
+ </simple-method>
+ <simple-method method-name="removeContentRevision" short-description="Remove ContentRevision">
+ <check-permission action="_DELETE" permission="CONTENTMGR">
+ <fail-message message="Security Error: to run removeContentRevision you must have the CONTENTMGR_DELETE or CONTENTMGR_ADMIN permission"/>
+ </check-permission>
+ <check-errors/>
+ <make-value entity-name="ContentRevision" value-name="lookupKeyValue"/>
+ <set-pk-fields map-name="parameters" value-name="lookupKeyValue"/>
+ <find-by-primary-key entity-name="ContentRevision" map-name="lookupKeyValue" value-name="lookedUpValue"/>
+ <remove-value value-name="lookedUpValue"/>
+ </simple-method>
+
+ <!-- Methods for ContentRevisionItem -->
+ <simple-method method-name="createContentRevisionItem" short-description="Create ContentRevisionItem">
+ <check-permission action="_CREATE" permission="CONTENTMGR">
+ <fail-message message="Security Error: to run createContentRevisionItem you must have the CONTENTMGR_CREATE or CONTENTMGR_ADMIN permission"/>
+ </check-permission>
+ <check-errors/>
+ <make-value entity-name="ContentRevisionItem" value-name="newEntity"/>
+ <set-nonpk-fields map-name="parameters" value-name="newEntity"/>
+ <set-pk-fields map-name="parameters" value-name="newEntity"/>
+ <create-value value-name="newEntity"/>
+ </simple-method>
+ <simple-method method-name="updateContentRevisionItem" short-description="Update ContentRevisionItem">
+ <check-permission action="_UPDATE" permission="CONTENTMGR">
+ <fail-message message="Security Error: to run updateContentRevisionItem you must have the CONTENTMGR_UPDATE or CONTENTMGR_ADMIN permission"/>
+ </check-permission>
+ <check-errors/>
+ <make-value entity-name="ContentRevisionItem" value-name="lookupKeyValue"/>
+ <set-pk-fields map-name="parameters" value-name="lookupKeyValue"/>
+ <find-by-primary-key entity-name="ContentRevisionItem" map-name="lookupKeyValue" value-name="lookedUpValue"/>
+ <set-nonpk-fields map-name="parameters" value-name="lookedUpValue"/>
+ <store-value value-name="lookedUpValue"/>
+ </simple-method>
+ <simple-method method-name="removeContentRevisionItem" short-description="Remove ContentRevisionItem">
+ <check-permission action="_DELETE" permission="CONTENTMGR">
+ <fail-message message="Security Error: to run removeContentRevisionItem you must have the CONTENTMGR_DELETE or CONTENTMGR_ADMIN permission"/>
+ </check-permission>
+ <check-errors/>
+ <make-value entity-name="ContentRevisionItem" value-name="lookupKeyValue"/>
+ <set-pk-fields map-name="parameters" value-name="lookupKeyValue"/>
+ <find-by-primary-key entity-name="ContentRevisionItem" map-name="lookupKeyValue" value-name="lookedUpValue"/>
+ <remove-value value-name="lookedUpValue"/>
+ </simple-method>
+
+ <!-- Methods for ContentRevision and ContentRevisionItem -->
+ <simple-method method-name="updateContentRevisionAndItem" short-description="Update ContentRevision and ContentRevisionItem">
+ <make-value entity-name="ContentRevision" value-name="newEntity"/>
+ <set-nonpk-fields map-name="parameters" value-name="newEntity"/>
+ <set-pk-fields map-name="parameters" value-name="newEntity"/>
+ <create-value value-name="newEntity"/>
+ <make-value entity-name="ContentRevisionItem" value-name="newEntity"/>
+ <set-nonpk-fields map-name="parameters" value-name="newEntity"/>
+ <set-pk-fields map-name="parameters" value-name="newEntity"/>
+ <create-value value-name="newEntity"/>
+ </simple-method>
+</simple-methods>
Modified: trunk/applications/content/servicedef/services.xml
===================================================================
--- trunk/applications/content/servicedef/services.xml 2006-01-04 06:42:36 UTC (rev 6465)
+++ trunk/applications/content/servicedef/services.xml 2006-01-04 07:36:28 UTC (rev 6466)
@@ -1401,6 +1401,39 @@
<attribute mode="IN" name="displayFailCond" optional="true" type="Boolean"/>
<attribute mode="INOUT" name="roleTypeList" optional="true" type="List"/>
</service>
+
+ <service name="persistContentWithRevision" engine="java"
+ transaction-timout="72000"
+ location="org.ofbiz.content.ContentManagementServices" invoke="persistContentWithRevision" auth="true">
+ <implements service="persistContentAndAssoc"/>
+ <attribute mode="IN" name="masterRevisionContentId" optional="false" type="String"/>
+ </service>
+
+ <!--
+ <service name="persistSurveyContent" engine="java"
+ transaction-timout="72000"
+ location="org.ofbiz.content.ContentManagementServices" invoke="persistSurveyContent" auth="true">
+ <implements service="createSurveyResponse"/>
+
+ </service>
+
+ <service name="persistSurveyContentWithRevision" engine="java"
+ transaction-timout="72000"
+ location="org.ofbiz.content.ContentManagementServices" invoke="persistSurveyContentWithRevision" auth="true">
+ <implements service="persistSurveyContent"/>
+ <attribute mode="IN" name="masterRevisionContentId" optional="false" type="String"/>
+ </service>
+ -->
+
+ <service name="findContentParents" engine="java"
+ transaction-timout="72000"
+ location="org.ofbiz.content.ContentManagementServices" invoke="findContentParents" auth="true">
+ <attribute mode="IN" name="contentId" optional="false" type="String"/>
+ <attribute mode="IN" name="contentAssocTypeId" optional="false" type="String"/>
+ <attribute mode="IN" name="direction" optional="true" type="String"/>
+ <attribute mode="OUT" name="parentList" optional="true" type="List"/>
+ </service>
+
<service name="deactivateAssocs" engine="java"
location="org.ofbiz.content.content.ContentServices" invoke="deactivateAssocs" auth="true">
<description>Supply thruDate to all ContentAssoc that come "before" current one</description>
@@ -1700,6 +1733,93 @@
<attribute name="fmPrefixMap" type="java.util.Map" mode="IN" optional="true" string-map-prefix="CTX_"/>
<attribute name="pdfByteWrapper" type="org.ofbiz.entity.util.ByteWrapper" mode="OUT" optional="true"/>
</service>
+
+ <!-- Content Revision services -->
+ <service name="createContentRevision" engine="simple"
+ location="org/ofbiz/content/compdoc/CompDocServices.xml"
+ invoke="createContentRevision"
+ default-entity-name="ContentRevision" auth="true">
+ <description>Create a ContentRevision</description>
+ <auto-attributes include="pk" mode="IN" optional="true"/>
+ <auto-attributes include="nonpk" mode="IN" optional="true"/>
+ </service>
+ <service name="updateContentRevision" engine="simple"
+ location="org/ofbiz/content/compdoc/CompDocServices.xml"
+ invoke="updateContentRevision"
+ default-entity-name="ContentRevision" auth="true">
+ <description>Update a ContentRevision</description>
+ <auto-attributes include="pk" mode="IN" optional="false"/>
+ <auto-attributes include="nonpk" mode="IN" optional="true"/>
+ </service>
+ <service name="removeContentRevision" engine="simple"
+ location="org/ofbiz/content/compdoc/CompDocServices.xml"
+ invoke="removeContentRevision"
+ default-entity-name="ContentRevision" auth="true">
+ <description>Remove ContentRevision</description>
+ <auto-attributes include="pk" mode="IN" optional="false"/>
+ </service>
+
+ <!-- Content Revision Item services -->
+ <service name="createContentRevisionItem" engine="simple"
+ location="org/ofbiz/content/compdoc/CompDocServices.xml"
+ invoke="createContentRevisionItem"
+ default-entity-name="ContentRevisionItem" auth="true">
+ <description>Create a ContentRevisionItem</description>
+ <auto-attributes include="pk" mode="IN" optional="true"/>
+ <auto-attributes include="nonpk" mode="IN" optional="true"/>
+ </service>
+ <service name="updateContentRevisionItem" engine="simple"
+ location="org/ofbiz/content/compdoc/CompDocServices.xml"
+ invoke="updateContentRevisionItem"
+ default-entity-name="ContentRevisionItem" auth="true">
+ <description>Update a ContentRevisionItem</description>
+ <auto-attributes include="pk" mode="IN" optional="false"/>
+ <auto-attributes include="nonpk" mode="IN" optional="true"/>
+ </service>
+ <service name="removeContentRevisionItem" engine="simple"
+ location="org/ofbiz/content/compdoc/CompDocServices.xml"
+ invoke="removeContentRevisionItem"
+ default-entity-name="ContentRevisionItem" auth="true">
+ <description>Remove ContentRevisionItem</description>
+ <auto-attributes include="pk" mode="IN" optional="false"/>
+ </service>
+
+ <!-- Content Approval services -->
+ <service name="createContentApproval" engine="simple"
+ location="org/ofbiz/content/compdoc/CompDocServices.xml"
+ invoke="createContentApproval"
+ default-entity-name="ContentApproval" auth="true">
+ <description>Create a ContentApproval</description>
+ <auto-attributes include="pk" mode="IN" optional="true"/>
+ <auto-attributes include="nonpk" mode="IN" optional="true"/>
+ </service>
+ <service name="updateContentApproval" engine="simple"
+ location="org/ofbiz/content/compdoc/CompDocServices.xml"
+ invoke="updateContentApproval"
+ default-entity-name="ContentApproval" auth="true">
+ <description>Update a ContentApproval</description>
+ <auto-attributes include="pk" mode="IN" optional="false"/>
+ <auto-attributes include="nonpk" mode="IN" optional="true"/>
+ </service>
+ <service name="removeContentApproval" engine="simple"
+ location="org/ofbiz/content/compdoc/CompDocServices.xml"
+ invoke="removeContentApproval"
+ default-entity-name="ContentApproval" auth="true">
+ <description>Remove ContentApproval</description>
+ <auto-attributes include="pk" mode="IN" optional="false"/>
+ </service>
+
+ <!-- ================ CompDoc Requests ================= -->
+ <service name="updateContentRevisionAndItem" engine="simple"
+ location="org/ofbiz/content/compdoc/CompDocServices.xml"
+ invoke="updateContentRevisionAndItem" auth="false">
+ <description>Update a ContentRevision and ContentRevisionItem</description>
+ <auto-attributes entity-name="ContentRevision" include="all" mode="IN" optional="true">
+ </auto-attributes>
+ <auto-attributes entity-name="ContentRevisionItem" include="all" mode="IN" optional="true">
+ </auto-attributes>
+ </service>
+
<service name="convertDocument" auth="false" engine="java" transaction-timout="72000"
location="org.ofbiz.content.openoffice.OpenOfficeServices" invoke="convertDocument">
<description>Use OpenOffice to convert between document types</description>
@@ -1708,7 +1828,7 @@
<attribute name="filenameFrom" type="String" mode="IN" optional="false"/>
<attribute name="filenameTo" type="String" mode="IN" optional="false"/>
<attribute name="convertFilterName" type="String" mode="IN" optional="true"/>
- </service>
+ </service>
<service name="convertDocumentFileToFile" auth="false" engine="java" transaction-timout="72000"
location="org.ofbiz.content.openoffice.OpenOfficeServices" invoke="convertDocumentFileToFile">
<description>Use OpenOffice to convert between document types</description>
@@ -1718,7 +1838,7 @@
<attribute name="filenameTo" type="String" mode="IN" optional="false"/>
<attribute name="inputMimeType" type="String" mode="IN" optional="true"/>
<attribute name="outputMimeType" type="String" mode="IN" optional="true"/>
- </service>
+ </service>
<service name="compareDocuments" auth="false" engine="java" transaction-timout="72000"
location="org.ofbiz.content.openoffice.OpenOfficeServices" invoke="compareDocuments">
<description>Use OpenOffice to compare two documents</description>
@@ -1727,5 +1847,5 @@
<attribute name="filenameFrom" type="String" mode="IN" optional="false"/>
<attribute name="filenameOriginal" type="String" mode="IN" optional="false"/>
<attribute name="filenameOut" type="String" mode="IN" optional="false"/>
- </service>
+ </service>
</services>
Modified: trunk/applications/content/src/org/ofbiz/content/ContentManagementServices.java
===================================================================
--- trunk/applications/content/src/org/ofbiz/content/ContentManagementServices.java 2006-01-04 06:42:36 UTC (rev 6465)
+++ trunk/applications/content/src/org/ofbiz/content/ContentManagementServices.java 2006-01-04 07:36:28 UTC (rev 6466)
@@ -175,16 +175,24 @@
* 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.
+ * This service tries to handle DataResource and ContentAssoc fields with and
+ * without "dr" and "ca" prefixes.
+ * Assumes binary data is always in field, "imageData".
*/
public static Map persistContentAndAssoc(DispatchContext dctx, Map context) throws GenericServiceException {
HashMap result = new HashMap();
- Security security = dctx.getSecurity();
GenericDelegator delegator = dctx.getDelegator();
LocalDispatcher dispatcher = dctx.getDispatcher();
+
+ // Knowing why a request fails permission check is one of the more difficult
+ // aspects of content management. Setting "displayFailCond" to true will
+ // put an html table in result.errorMessage that will show what tests were performed
Boolean bDisplayFailCond = (Boolean)context.get("displayFailCond");
- Map permContext = new HashMap();
String mapKey = (String) context.get("mapKey");
+
+ // If "deactivateExisting" is set, other Contents that are tied to the same
+ // contentIdTo will be deactivated (thruDate set to now)
String deactivateExisting = (String) context.get("deactivateExisting");
if (UtilValidate.isEmpty(deactivateExisting)) {
if (UtilValidate.isEmpty(mapKey))
@@ -194,21 +202,20 @@
}
if (Debug.infoOn()) Debug.logInfo("in persist... mapKey(0):" + mapKey, null);
+ // ContentPurposes can get passed in as a delimited string or a list. Combine.
List contentPurposeList = (List)context.get("contentPurposeList");
if (contentPurposeList == null)
contentPurposeList = new ArrayList();
-
String contentPurposeString = (String)context.get("contentPurposeString");
if (UtilValidate.isNotEmpty(contentPurposeString)) {
List tmpPurposes = StringUtil.split(contentPurposeString, "|");
contentPurposeList.addAll(tmpPurposes);
}
-
if (contentPurposeList != null ) {
context.put("contentPurposeList", contentPurposeList);
context.put("contentPurposeString", null);
}
- //if (Debug.infoOn()) Debug.logInfo("in persist... contentPurposeList(0):" + contentPurposeList, null);
+ if (Debug.infoOn()) Debug.logInfo("in persist... contentPurposeList(0):" + contentPurposeList, null);
if (Debug.infoOn()) Debug.logInfo("in persist... textData(0):" + context.get("textData"), null);
@@ -245,7 +252,6 @@
String contentTypeId = (String)content.get("contentTypeId");
String origContentId = (String)content.get("contentId");
String origDataResourceId = (String)content.get("dataResourceId");
- String origContentTypeId = (String)content.get("contentTypeId");
if (Debug.infoOn()) Debug.logInfo("in persist... contentId(0):" + contentId, null);
@@ -280,151 +286,152 @@
boolean dataResourceExists = true;
if (Debug.infoOn()) Debug.logInfo("in persist... dataResourceTypeId(0):" + dataResourceTypeId, null);
if (UtilValidate.isNotEmpty(dataResourceTypeId) ) {
- context.put("skipPermissionCheck", "granted"); // TODO: a temp hack because I don't want to bother with DataResource permissions at this time.
- if (UtilValidate.isEmpty(dataResourceId)) {
- dataResourceExists = false;
- } else {
- try {
- GenericValue val = delegator.findByPrimaryKey("DataResource", UtilMisc.toMap("dataResourceId", dataResourceId));
- if (val == null)
- dataResourceExists = false;
- } catch(GenericEntityException e) {
- return ServiceUtil.returnError(e.getMessage());
- }
+ context.put("skipPermissionCheck", "granted"); // TODO: a temp hack because I don't want to bother with DataResource permissions at this time.
+ if (UtilValidate.isEmpty(dataResourceId)) {
+ dataResourceExists = false;
+ } else {
+ try {
+ GenericValue val = delegator.findByPrimaryKey("DataResource", UtilMisc.toMap("dataResourceId", dataResourceId));
+ if (val == null)
+ dataResourceExists = false;
+ } catch(GenericEntityException e) {
+ return ServiceUtil.returnError(e.getMessage());
}
- Map newDrContext = new HashMap();
- ModelService dataResourceModel = dispatcher.getDispatchContext().getModelService("updateDataResource");
- Map ctx = dataResourceModel.makeValid(dataResource, "IN");
- newDrContext.putAll(ctx);
- newDrContext.put("userLogin", userLogin);
- newDrContext.put("skipPermissionCheck", context.get("skipPermissionCheck"));
- ByteWrapper byteWrapper = (ByteWrapper)context.get("imageData");
- String mimeTypeId = (String) newDrContext.get("mimeTypeId");
- if (byteWrapper != null && (mimeTypeId == null || (mimeTypeId.indexOf("image") >= 0))) {
- mimeTypeId = (String) context.get("_imageData_contentType");
- String fileName = (String) context.get("_imageData_fileName");
- newDrContext.put("objectInfo", fileName);
- newDrContext.put("mimeTypeId", mimeTypeId);
+ }
+ Map newDrContext = new HashMap();
+ ModelService dataResourceModel = dispatcher.getDispatchContext().getModelService("updateDataResource");
+ Map ctx = dataResourceModel.makeValid(dataResource, "IN");
+ newDrContext.putAll(ctx);
+ newDrContext.put("userLogin", userLogin);
+ newDrContext.put("skipPermissionCheck", context.get("skipPermissionCheck"));
+ // Assumes binary data is always in field, "imageData"
+ ByteWrapper byteWrapper = (ByteWrapper)context.get("imageData");
+ String mimeTypeId = (String) newDrContext.get("mimeTypeId");
+ if (byteWrapper != null && (mimeTypeId == null || (mimeTypeId.indexOf("image") >= 0))) {
+ mimeTypeId = (String) context.get("_imageData_contentType");
+ String fileName = (String) context.get("_imageData_fileName");
+ newDrContext.put("objectInfo", fileName);
+ newDrContext.put("mimeTypeId", mimeTypeId);
+ }
+ if (!dataResourceExists) {
+ Map thisResult = dispatcher.runSync("createDataResource", newDrContext);
+ String errorMsg = ServiceUtil.getErrorMessage(thisResult);
+ if (UtilValidate.isNotEmpty(errorMsg)) {
+ return ServiceUtil.returnError(errorMsg);
+ }
+ dataResourceId = (String)thisResult.get("dataResourceId");
+ if (Debug.infoOn()) Debug.logInfo("in persist... dataResourceId(0):" + dataResourceId, null);
+ dataResource = (GenericValue)thisResult.get("dataResource");
+ Map fileContext = new HashMap();
+ fileContext.put("userLogin", userLogin);
+ if ( dataResourceTypeId.indexOf("_FILE") >=0) {
+ boolean hasData = false;
+ if (textData != null) {
+ fileContext.put("textData", textData);
+ hasData = true;
}
- if (!dataResourceExists) {
- Map thisResult = dispatcher.runSync("createDataResource", newDrContext);
- String errorMsg = ServiceUtil.getErrorMessage(thisResult);
- if (UtilValidate.isNotEmpty(errorMsg)) {
+ if (byteWrapper != null) {
+ fileContext.put("binData", byteWrapper);
+ hasData = true;
+ }
+ if (hasData) {
+ fileContext.put("rootDir", context.get("rootDir"));
+ fileContext.put("dataResourceTypeId", dataResourceTypeId);
+ fileContext.put("objectInfo", dataResource.get("objectInfo"));
+ thisResult = dispatcher.runSync("createFile", fileContext);
+ errorMsg = ServiceUtil.getErrorMessage(thisResult);
+ if (UtilValidate.isNotEmpty(errorMsg)) {
return ServiceUtil.returnError(errorMsg);
+ }
}
- dataResourceId = (String)thisResult.get("dataResourceId");
- if (Debug.infoOn()) Debug.logInfo("in persist... dataResourceId(0):" + dataResourceId, null);
- dataResource = (GenericValue)thisResult.get("dataResource");
- Map fileContext = new HashMap();
- fileContext.put("userLogin", userLogin);
- if ( dataResourceTypeId.indexOf("_FILE") >=0) {
- boolean hasData = false;
- if (textData != null) {
- fileContext.put("textData", textData);
- hasData = true;
+ } else if (dataResourceTypeId.equals("IMAGE_OBJECT")) {
+ if (byteWrapper != null) {
+ fileContext.put("dataResourceId", dataResourceId);
+ fileContext.put("imageData", byteWrapper);
+ thisResult = dispatcher.runSync("createImage", fileContext);
+ errorMsg = ServiceUtil.getErrorMessage(thisResult);
+ if (UtilValidate.isNotEmpty(errorMsg)) {
+ return ServiceUtil.returnError(errorMsg);
}
- if (byteWrapper != null) {
- fileContext.put("binData", byteWrapper);
- hasData = true;
- }
- if (hasData) {
- fileContext.put("rootDir", context.get("rootDir"));
- fileContext.put("dataResourceTypeId", dataResourceTypeId);
- fileContext.put("objectInfo", dataResource.get("objectInfo"));
- thisResult = dispatcher.runSync("createFile", fileContext);
- errorMsg = ServiceUtil.getErrorMessage(thisResult);
- if (UtilValidate.isNotEmpty(errorMsg)) {
- return ServiceUtil.returnError(errorMsg);
- }
- }
- } else if (dataResourceTypeId.equals("IMAGE_OBJECT")) {
- if (byteWrapper != null) {
- fileContext.put("dataResourceId", dataResourceId);
- fileContext.put("imageData", byteWrapper);
- thisResult = dispatcher.runSync("createImage", fileContext);
- errorMsg = ServiceUtil.getErrorMessage(thisResult);
- if (UtilValidate.isNotEmpty(errorMsg)) {
- return ServiceUtil.returnError(errorMsg);
- }
- } else {
- return ServiceUtil.returnError("'byteWrapper' empty when trying to create database image.");
- }
- } else if (dataResourceTypeId.equals("SHORT_TEXT")) {
} else {
- // assume ELECTRONIC_TEXT
- if (UtilValidate.isNotEmpty(textData)) {
- fileContext.put("dataResourceId", dataResourceId);
- fileContext.put("textData", textData);
- thisResult = dispatcher.runSync("createElectronicText", fileContext);
- errorMsg = ServiceUtil.getErrorMessage(thisResult);
- if (UtilValidate.isNotEmpty(errorMsg)) {
- return ServiceUtil.returnError(errorMsg);
- }
- }
+ return ServiceUtil.returnError("'byteWrapper' empty when trying to create database image.");
}
+ } else if (dataResourceTypeId.equals("SHORT_TEXT")) {
} else {
- Map thisResult = dispatcher.runSync("updateDataResource", newDrContext);
- String errorMsg = ServiceUtil.getErrorMessage(thisResult);
- if (UtilValidate.isNotEmpty(errorMsg)) {
- return ServiceUtil.returnError(errorMsg);
+ // assume ELECTRONIC_TEXT
+ if (UtilValidate.isNotEmpty(textData)) {
+ fileContext.put("dataResourceId", dataResourceId);
+ fileContext.put("textData", textData);
+ thisResult = dispatcher.runSync("createElectronicText", fileContext);
+ errorMsg = ServiceUtil.getErrorMessage(thisResult);
+ if (UtilValidate.isNotEmpty(errorMsg)) {
+ return ServiceUtil.returnError(errorMsg);
+ }
}
- //Map thisResult = DataServices.updateDataResourceMethod(dctx, context);
- if (Debug.infoOn()) Debug.logInfo("in persist... thisResult.permissionStatus(0):" + thisResult.get("permissionStatus"), null);
- //thisResult = DataServices.updateElectronicTextMethod(dctx, context);
- Map fileContext = new HashMap();
- fileContext.put("userLogin", userLogin);
- String forceElectronicText = (String)context.get("forceElectronicText");
- if (dataResourceTypeId.indexOf("_FILE") >=0) {
- boolean hasData = false;
- if (textData != null) {
- fileContext.put("textData", textData);
- hasData = true;
+ }
+ } else {
+ Map thisResult = dispatcher.runSync("updateDataResource", newDrContext);
+ String errorMsg = ServiceUtil.getErrorMessage(thisResult);
+ if (UtilValidate.isNotEmpty(errorMsg)) {
+ return ServiceUtil.returnError(errorMsg);
+ }
+ //Map thisResult = DataServices.updateDataResourceMethod(dctx, context);
+ if (Debug.infoOn()) Debug.logInfo("in persist... thisResult.permissionStatus(0):" + thisResult.get("permissionStatus"), null);
+ //thisResult = DataServices.updateElectronicTextMethod(dctx, context);
+ Map fileContext = new HashMap();
+ fileContext.put("userLogin", userLogin);
+ String forceElectronicText = (String)context.get("forceElectronicText");
+ if (dataResourceTypeId.indexOf("_FILE") >=0) {
+ boolean hasData = false;
+ if (textData != null) {
+ fileContext.put("textData", textData);
+ hasData = true;
+ }
+ if (byteWrapper != null) {
+ fileContext.put("binData", byteWrapper);
+ hasData = true;
+ }
+ if (hasData || "true".equalsIgnoreCase(forceElectronicText)) {
+ fileContext.put("rootDir", context.get("rootDir"));
+ fileContext.put("dataResourcetype", dataResourceTypeId);
+ fileContext.put("objectInfo", dataResource.get("objectInfo"));
+ thisResult = dispatcher.runSync("updateFile", fileContext);
+ errorMsg = ServiceUtil.getErrorMessage(thisResult);
+ if (UtilValidate.isNotEmpty(errorMsg)) {
+ return ServiceUtil.returnError(errorMsg);
}
- if (byteWrapper != null) {
- fileContext.put("binData", byteWrapper);
- hasData = true;
+ }
+ } else if (dataResourceTypeId.equals("IMAGE_OBJECT")) {
+ if (byteWrapper != null || "true".equalsIgnoreCase(forceElectronicText)) {
+ fileContext.put("dataResourceId", dataResourceId);
+ fileContext.put("imageData", byteWrapper);
+ thisResult = dispatcher.runSync("updateImage", fileContext);
+ errorMsg = ServiceUtil.getErrorMessage(thisResult);
+ if (UtilValidate.isNotEmpty(errorMsg)) {
+ return ServiceUtil.returnError(errorMsg);
}
- if (hasData || "true".equalsIgnoreCase(forceElectronicText)) {
- fileContext.put("rootDir", context.get("rootDir"));
- fileContext.put("dataResourcetype", dataResourceTypeId);
- fileContext.put("objectInfo", dataResource.get("objectInfo"));
- thisResult = dispatcher.runSync("updateFile", fileContext);
- errorMsg = ServiceUtil.getErrorMessage(thisResult);
- if (UtilValidate.isNotEmpty(errorMsg)) {
- return ServiceUtil.returnError(errorMsg);
- }
- }
- } else if (dataResourceTypeId.equals("IMAGE_OBJECT")) {
- if (byteWrapper != null || "true".equalsIgnoreCase(forceElectronicText)) {
- fileContext.put("dataResourceId", dataResourceId);
- fileContext.put("imageData", byteWrapper);
- thisResult = dispatcher.runSync("updateImage", fileContext);
- errorMsg = ServiceUtil.getErrorMessage(thisResult);
- if (UtilValidate.isNotEmpty(errorMsg)) {
- return ServiceUtil.returnError(errorMsg);
- }
- } else {
- //return ServiceUtil.returnError("'byteWrapper' empty when trying to create database image.");
- }
- } else if (dataResourceTypeId.equals("SHORT_TEXT")) {
} else {
- if (UtilValidate.isNotEmpty(textData) || "true".equalsIgnoreCase(forceElectronicText)) {
- fileContext.put("dataResourceId", dataResourceId);
- fileContext.put("textData", textData);
- thisResult = dispatcher.runSync("updateElectronicText", fileContext);
- errorMsg = ServiceUtil.getErrorMessage(thisResult);
- if (UtilValidate.isNotEmpty(errorMsg)) {
- return ServiceUtil.returnError(errorMsg);
- }
+ //return ServiceUtil.returnError("'byteWrapper' empty when trying to create database image.");
+ }
+ } else if (dataResourceTypeId.equals("SHORT_TEXT")) {
+ } else {
+ if (UtilValidate.isNotEmpty(textData) || "true".equalsIgnoreCase(forceElectronicText)) {
+ fileContext.put("dataResourceId", dataResourceId);
+ fileContext.put("textData", textData);
+ thisResult = dispatcher.runSync("updateElectronicText", fileContext);
+ errorMsg = ServiceUtil.getErrorMessage(thisResult);
+ if (UtilValidate.isNotEmpty(errorMsg)) {
+ return ServiceUtil.returnError(errorMsg);
}
}
}
+ }
- result.put("dataResourceId", dataResourceId);
- result.put("drDataResourceId", dataResourceId);
- context.put("dataResourceId", dataResourceId);
- content.put("dataResourceId", dataResourceId);
- context.put("drDataResourceId", dataResourceId);
+ result.put("dataResourceId", dataResourceId);
+ result.put("drDataResourceId", dataResourceId);
+ context.put("dataResourceId", dataResourceId);
+ content.put("dataResourceId", dataResourceId);
+ context.put("drDataResourceId", dataResourceId);
}
// Do update and create permission checks on Content if warranted.
@@ -1614,5 +1621,74 @@
return result;
}
+ /**
+ */
+ public static Map persistContentWithRevision(DispatchContext dctx, Map context) {
+ Map result = null;
+ boolean dataResourceExists = false;
+ GenericDelegator delegator = dctx.getDelegator();
+ LocalDispatcher dispatcher = dctx.getDispatcher();
+ GenericValue dataResource = null;
+ String masterRevisionContentId = (String)context.get("masterRevisionContentId");
+ String oldDataResourceId = (String)context.get("drDataResourceId");
+ if (UtilValidate.isEmpty(oldDataResourceId)) {
+ oldDataResourceId = (String)context.get("dataResourceId");
+ }
+ if (UtilValidate.isNotEmpty(oldDataResourceId)) {
+ try {
+ dataResource = delegator.findByPrimaryKey("DataResource", UtilMisc.toMap("dataResourceId", oldDataResourceId));
+ } catch(GenericEntityException e) {
+ Debug.logError(e.getMessage(), module);
+ return ServiceUtil.returnError(e.getMessage());
+ }
+ }
+
+ try {
+ ModelService persistContentAndAssocModel = dispatcher.getDispatchContext().getModelService("persistContentAndAssoc");
+ Map ctx = persistContentAndAssocModel.makeValid(context, "IN");
+ if (dataResource != null) {
+ ctx.remove("dataResourceId");
+ ctx.remove("drDataResourceId");
+ }
+ result = dispatcher.runSync("persistContentAndAssoc", ctx);
+ String errorMsg = ServiceUtil.getErrorMessage(result);
+ if (UtilValidate.isNotEmpty(errorMsg)) {
+ return ServiceUtil.returnError(errorMsg);
+ }
+ String contentId = (String)result.get("contentId");
+ List parentList = new ArrayList();
+ if (UtilValidate.isEmpty(masterRevisionContentId)) {
+ Map traversMap = new HashMap();
+ traversMap.put("contentId", contentId);
+ traversMap.put("direction", "To");
+ traversMap.put("contentAssocTypeId", "COMPDOC_PART");
+ Map traversResult = dispatcher.runSync("traverseContent", traversMap);
+ parentList = (List)traversResult.get("parentList");
+ } else {
+ parentList.add(masterRevisionContentId);
+ }
+
+ // Update ContentRevision and ContentRevisonItem
+ Map contentRevisionMap = new HashMap();
+ contentRevisionMap.put("itemContentId", contentId);
+ contentRevisionMap.put("newDataResourceId", result.get("dataResourceId"));
+ contentRevisionMap.put("oldDataResourceId", result.get("oldDataResourceId"));
+ // need committedByPartyId
+ for (int i=0; i < parentList.size(); i++) {
+ String thisContentId = (String)parentList.get(i);
+ contentRevisionMap.put("contentId", thisContentId);
+ result = dispatcher.runSync("updateContentRevisionAndItem", contentRevisionMap);
+ errorMsg = ServiceUtil.getErrorMessage(result);
+ if (UtilValidate.isNotEmpty(errorMsg)) {
+ return ServiceUtil.returnError(errorMsg);
+ }
+ }
+
+ } catch (GenericServiceException e) {
+ Debug.logError(e.getMessage(), module);
+ return ServiceUtil.returnError(e.getMessage());
+ }
+ return result;
+ }
}
Modified: trunk/applications/content/src/org/ofbiz/content/content/ContentServices.java
===================================================================
--- trunk/applications/content/src/org/ofbiz/content/content/ContentServices.java 2006-01-04 06:42:36 UTC (rev 6465)
+++ trunk/applications/content/src/org/ofbiz/content/content/ContentServices.java 2006-01-04 07:36:28 UTC (rev 6466)
@@ -146,10 +146,52 @@
results.put("contentList", permittedList);
return results;
}
-
/**
* This is a generic service for traversing a Content tree, typical of a blog response tree. It calls the ContentWorker.traverse method.
*/
+ public static Map findContentParents(DispatchContext dctx, Map context) {
+ HashMap results = new HashMap();
+ List parentList = new ArrayList();
+ results.put("parentList", parentList);
+ LocalDispatcher dispatcher = dctx.getDispatcher();
+ String contentId = (String)context.get("contentId");
+ String contentAssocTypeId = (String)context.get("contentAssocTypeId");
+ String direction = (String)context.get("direction");
+ if (UtilValidate.isEmpty(direction)) direction="To";
+ Map traversMap = new HashMap();
+ traversMap.put("contentId", contentId);
+ traversMap.put("direction", direction);
+ traversMap.put("contentAssocTypeId", contentAssocTypeId);
+ try {
+ Map thisResults = dispatcher.runSync("traverseContent", traversMap);
+ String errorMsg = ServiceUtil.getErrorMessage(thisResults);
+ if (UtilValidate.isNotEmpty(errorMsg) ) {
+ Debug.logError( "Problem in traverseContent. " + errorMsg, module);
+ return ServiceUtil.returnError(errorMsg);
+ }
+ Map nodeMap = (Map)thisResults.get("nodeMap");
+ walkParentTree(nodeMap, parentList);
+ } catch (GenericServiceException e) {
+ return ServiceUtil.returnFailure(e.getMessage());
+ }
+ return results;
+ }
+
+ private static void walkParentTree(Map nodeMap, List parentList) {
+ List kids = (List)nodeMap.get("kids");
+ if (kids == null || kids.size() == 0) {
+ parentList.add(nodeMap.get("contentId"));
+ } else {
+ Iterator iter = kids.iterator();
+ while (iter.hasNext()) {
+ Map node = (Map) iter.next();
+ walkParentTree(node, parentList);
+ }
+ }
+ }
+ /**
+ * This is a generic service for traversing a Content tree, typical of a blog response tree. It calls the ContentWorker.traverse method.
+ */
public static Map traverseContent(DispatchContext dctx, Map context) {
GenericDelegator delegator = dctx.getDelegator();
HashMap results = new HashMap();
More information about the Svn
mailing list