[OFBiz] SVN: r4671 - in trunk/applications/workeffort: script/org/ofbiz/workeffort/workeffort servicedef src/org/ofbiz/workeffort/workeffort

jonesde at svn.ofbiz.org jonesde at svn.ofbiz.org
Tue Mar 15 22:00:00 EST 2005


Author: jonesde
Date: 2005-03-15 20:59:32 -0600 (Tue, 15 Mar 2005)
New Revision: 4671

Modified:
   trunk/applications/workeffort/script/org/ofbiz/workeffort/workeffort/WorkEffortSimpleServices.xml
   trunk/applications/workeffort/servicedef/services.xml
   trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortPartyAssignmentServices.java
Log:
Added changes from Anil Patel, plus some cleanups and completions.

Modified: trunk/applications/workeffort/script/org/ofbiz/workeffort/workeffort/WorkEffortSimpleServices.xml
===================================================================
--- trunk/applications/workeffort/script/org/ofbiz/workeffort/workeffort/WorkEffortSimpleServices.xml	2005-03-15 14:18:02 UTC (rev 4670)
+++ trunk/applications/workeffort/script/org/ofbiz/workeffort/workeffort/WorkEffortSimpleServices.xml	2005-03-16 02:59:32 UTC (rev 4671)
@@ -27,6 +27,7 @@
 
 <simple-methods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xsi:noNamespaceSchemaLocation="http://www.ofbiz.org/dtds/simple-methods.xsd">
+		
     <simple-method method-name="createWorkEffort" short-description="Create Work Effort">
         <make-value value-name="newEntity" entity-name="WorkEffort"/>
         <sequenced-id-to-env sequence-name="WorkEffort" env-name="workEffortId"/>
@@ -143,19 +144,83 @@
 
     <!-- communication event workeffort -->
     <simple-method method-name="makeCommunicationEventWorkEffort" short-description="Make a Communication Event WorkEffort">
-    	<make-value entity-name="CommunicationEventWorkEff" value-name="lookupMap"/>
-    	<set-pk-fields map-name="parameters" value-name="lookupMap"/>
-    	<find-by-primary-key entity-name="CommunicationEventWorkEff" map-name="lookupMap" value-name="eventWe"/>
-    	<if-not-empty field-name="workEffortId" map-name="eventWe">
-    		<set-nonpk-fields map-name="parameters" value-name="eventWe"/>
-    		<store-value value-name="eventWe"/>
-    	</if-not-empty>
-    	<if-empty field-name="workEffortId" map-name="eventWe">
-    		<set-nonpk-fields map-name="parameters" value-name="lookupMap"/>
-    		<create-value value-name="lookupMap"/>
-    	</if-empty>
+        <make-value entity-name="CommunicationEventWorkEff" value-name="lookupMap"/>
+        <set-pk-fields map-name="parameters" value-name="lookupMap"/>
+        <find-by-primary-key entity-name="CommunicationEventWorkEff" map-name="lookupMap" value-name="eventWe"/>
+        <if-not-empty field-name="workEffortId" map-name="eventWe">
+            <set-nonpk-fields map-name="parameters" value-name="eventWe"/>
+            <store-value value-name="eventWe"/>
+        </if-not-empty>
+        <if-empty field-name="workEffortId" map-name="eventWe">
+            <set-nonpk-fields map-name="parameters" value-name="lookupMap"/>
+            <create-value value-name="lookupMap"/>
+        </if-empty>
     </simple-method>
-    
+
+    <!-- WorkEffortPartyAssignment -->    
+    <simple-method method-name="assignPartyToWorkEffort" short-description="Assign Party to Work Effort">
+        <now-timestamp-to-env env-name="nowTimestamp"/>
+
+        <make-value value-name="newEntity" entity-name="WorkEffortPartyAssignment"/>
+
+        <set-pk-fields map-name="parameters" value-name="newEntity"/>
+        <set-nonpk-fields map-name="parameters" value-name="newEntity"/>
+
+        <if-empty field-name="fromDate" map-name="newEntity">
+	        <env-to-env env-name="nowTimestamp" to-env-name="newEntity.fromDate"/>
+        </if-empty>
+        <field-to-result field-name="fromDate" map-name="newValue"/>
+
+        <if-not-empty field-name="parameters.statusId">
+	        <env-to-env env-name="nowTimestamp" to-env-name="newEntity.statusDateTime"/>
+	        <call-class-method class-name="org.ofbiz.workeffort.workeffort.WorkEffortPartyAssignmentServices" method-name="updateWorkflowEngine">
+				<field field-name="newEntity" type="org.ofbiz.entity.GenericValue"/>
+				<field field-name="userLogin" type="org.ofbiz.entity.GenericValue"/>
+			    <field field-name="dispatcher" type="org.ofbiz.service.LocalDispatcher"/>
+		    </call-class-method>
+        </if-not-empty>
+        <create-value value-name="newEntity"/>
+    </simple-method>
+    <simple-method method-name="updatePartyToWorkEffortAssignment" short-description="Update WorkEffortPartyAssignment entity">
+		<make-value value-name="lookupPKMap" entity-name="WorkEffortPartyAssignment"/>
+        <set-pk-fields map-name="parameters" value-name="lookupPKMap"/>
+        <find-by-primary-key map-name="lookupPKMap" value-name="workEffortPartyAssignment"/>
+		
+		<if-compare-field field-name="userLogin.partyId" operator="not-equals" to-field-name="workEffortPartyAssignment.partyId">                
+			<check-permission permission="WORKEFFORTMGR" action="_UPDATE">
+				<fail-message message="You cannot update this Work Effort Party Assignment, you must either be associated with it or have administration permission."/>
+		   	</check-permission>
+			<check-errors/>
+        </if-compare-field>
+		
+		<field-to-env field-name="statusId" map-name="workEffortPartyAssignment" env-name="oldStatusId" />
+        <set-nonpk-fields map-name="parameters" value-name="workEffortPartyAssignment"/>
+        <now-timestamp-to-env env-name="nowTimestamp"/>
+		
+        <if-compare-field field-name="parameters.statusId" operator="not-equals" to-field-name="oldStatusId">
+	        <env-to-env env-name="nowTimestamp" to-env-name="workEffortPartyAssignment.statusDateTime"/>
+	        <call-class-method class-name="org.ofbiz.workeffort.workeffort.WorkEffortPartyAssignmentServices" method-name="updateWorkflowEngine" >
+				<field field-name="workEffortPartyAssignment" type="org.ofbiz.entity.GenericValue"/>
+				<field field-name="userLogin" type="org.ofbiz.entity.GenericValue"/>
+			    <field field-name="dispatcher" type="org.ofbiz.service.LocalDispatcher"/>
+            </call-class-method>
+        </if-compare-field>
+        <store-value value-name="workEffortPartyAssignment"/>
+    </simple-method>
+    <simple-method method-name="unassignPartyFromWorkEffort" short-description="Service that deletes a WorkEffortPartyAssignment entity">
+        <make-value value-name="lookupPKMap" entity-name="WorkEffortPartyAssignment"/>
+        <set-pk-fields map-name="parameters" value-name="lookupPKMap"/>
+        <find-by-primary-key map-name="lookupPKMap" value-name="workEffortPartyAssignment"/>
+		<if-compare-field field-name="userLogin.partyId" operator="not-equals" to-field-name="workEffortPartyAssignment.partyId">                
+            <check-permission permission="WORKEFFORTMGR" action="_DELETE">
+                <fail-message message="You cannot delete this Work Effort Party Assignment, you must either be associated with it or have administration permission."/>
+            </check-permission>
+            <check-errors/>
+        </if-compare-field>
+        <remove-value value-name="workEffortPartyAssignment"/>
+    </simple-method>
+
+    <!-- Create a WorkEffortContactMech -->
     <simple-method method-name="createWorkEffortContactMech" short-description="Create a WorkEffortContactMech">
         <check-permission permission="WORKEFFORTMGR" action="_CREATE"><fail-message message="You do not have permission to perform this operation for this work effort."/></check-permission>
         <check-errors/>

Modified: trunk/applications/workeffort/servicedef/services.xml
===================================================================
--- trunk/applications/workeffort/servicedef/services.xml	2005-03-15 14:18:02 UTC (rev 4670)
+++ trunk/applications/workeffort/servicedef/services.xml	2005-03-16 02:59:32 UTC (rev 4671)
@@ -73,8 +73,8 @@
     </service>
 
     <!-- WorkEffortPartyAssignment services -->
-    <service name="assignPartyToWorkEffort" default-entity-name="WorkEffortPartyAssignment" engine="java"
-            location="org.ofbiz.workeffort.workeffort.WorkEffortPartyAssignmentServices" invoke="assignPartyToWorkEffort">
+    <service name="assignPartyToWorkEffort" default-entity-name="WorkEffortPartyAssignment" engine="simple"
+            location="org/ofbiz/workeffort/workeffort/WorkEffortSimpleServices.xml" invoke="assignPartyToWorkEffort">
         <description>Create a WorkEffortPartyAssignment Entity</description>
         <auto-attributes mode="IN" include="pk" optional="false"/>
         <auto-attributes mode="IN" include="nonpk" optional="true">
@@ -83,16 +83,16 @@
         <override name="fromDate" mode="INOUT" optional="true"/>
         <override name="statusId" optional="false"/>
     </service>
-    <service name="updatePartyToWorkEffortAssignment" default-entity-name="WorkEffortPartyAssignment" engine="java"
-            location="org.ofbiz.workeffort.workeffort.WorkEffortPartyAssignmentServices" invoke="updatePartyToWorkEffortAssignment">
+    <service name="updatePartyToWorkEffortAssignment" default-entity-name="WorkEffortPartyAssignment" engine="simple"
+            location="org/ofbiz/workeffort/workeffort/WorkEffortSimpleServices.xml" invoke="updatePartyToWorkEffortAssignment">
         <description>Update a WorkEffortPartyAssignment Entity</description>
         <auto-attributes mode="IN" include="pk" optional="false"/>
         <auto-attributes mode="IN" include="nonpk" optional="true">
             <exclude field-name="statusDateTime"/>
         </auto-attributes>
     </service>
-    <service name="unassignPartyFromWorkEffort" default-entity-name="WorkEffortPartyAssignment" engine="java"
-            location="org.ofbiz.workeffort.workeffort.WorkEffortPartyAssignmentServices" invoke="unassignPartyFromWorkEffort">
+    <service name="unassignPartyFromWorkEffort" default-entity-name="WorkEffortPartyAssignment" engine="simple"
+            location="org/ofbiz/workeffort/workeffort/WorkEffortSimpleServices.xml" invoke="unassignPartyFromWorkEffort">
         <description>Delete a WorkEffortPartyAssignment Entity</description>
         <auto-attributes mode="IN" include="pk" optional="false"/>
     </service>

Modified: trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortPartyAssignmentServices.java
===================================================================
--- trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortPartyAssignmentServices.java	2005-03-15 14:18:02 UTC (rev 4670)
+++ trunk/applications/workeffort/src/org/ofbiz/workeffort/workeffort/WorkEffortPartyAssignmentServices.java	2005-03-16 02:59:32 UTC (rev 4671)
@@ -24,21 +24,13 @@
  */
 package org.ofbiz.workeffort.workeffort;
 
-import java.sql.Timestamp;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
 import java.util.Map;
 
 import org.ofbiz.base.util.Debug;
-import org.ofbiz.base.util.UtilDateTime;
 import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.entity.GenericDelegator;
 import org.ofbiz.entity.GenericEntityException;
 import org.ofbiz.entity.GenericValue;
-import org.ofbiz.entity.transaction.TransactionUtil;
-import org.ofbiz.security.Security;
-import org.ofbiz.service.DispatchContext;
 import org.ofbiz.service.GenericServiceException;
 import org.ofbiz.service.LocalDispatcher;
 import org.ofbiz.service.ModelService;
@@ -55,208 +47,6 @@
     
     public static final String module = WorkEffortPartyAssignmentServices.class.getName();
 
-    /**
-     * Service that creates a WorkEffortPartyAssignment entity
-     * @param ctx The DispatchContext that this service is operating in
-     * @param context Map containing the input parameters
-     * @return Map with the result of the service, the output parameters
-     */
-    public static Map assignPartyToWorkEffort(DispatchContext ctx, Map context) {
-        Map result = new HashMap();
-        GenericDelegator delegator = ctx.getDelegator();
-        Security security = ctx.getSecurity();
-        GenericValue userLogin = (GenericValue) context.get("userLogin");
-
-        Timestamp nowStamp = UtilDateTime.nowTimestamp();
-        GenericValue newWorkEffortPartyAssignment = null;
-
-        newWorkEffortPartyAssignment = delegator.makeValue("WorkEffortPartyAssignment", null);
-        List toBeStored = new LinkedList();
-
-        toBeStored.add(newWorkEffortPartyAssignment);
-
-        newWorkEffortPartyAssignment.setPKFields(context);
-        if (newWorkEffortPartyAssignment.get("fromDate") == null) {
-            newWorkEffortPartyAssignment.set("fromDate", nowStamp);
-        }
-        newWorkEffortPartyAssignment.setNonPKFields(context);
-
-        // if necessary create new status entry, and set statusDateTime date
-        String statusId = (String) context.get("statusId");
-
-        if (statusId != null) {
-            // set the current status & timestamp
-            newWorkEffortPartyAssignment.set("statusId", statusId);
-            newWorkEffortPartyAssignment.set("statusDateTime", nowStamp);
-            updateWorkflowEngine(newWorkEffortPartyAssignment, userLogin, ctx.getDispatcher());
-        }
-
-        try {
-            delegator.storeAll(toBeStored);
-        } catch (GenericEntityException e) {
-            Debug.logWarning("[WorkEffortPartyAssignmentEvents.updateWorkEffortPartyAssignment] Could not create WorkEffortPartyAssignment (write error)", module);
-            Debug.logWarning(e, module);
-            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
-            result.put(ModelService.ERROR_MESSAGE, "Could not create new WorkEffortPartyAssignment (write error)");
-            return result;
-        }
-
-        result.put("fromDate", nowStamp);
-        result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
-
-        return result;
-    }
-
-    /**
-     * Service that updates a WorkEffortPartyAssignment entity
-     * @param ctx The DispatchContext that this service is operating in
-     * @param context Map containing the input parameters
-     * @return Map with the result of the service, the output parameters
-     */
-    public static Map updatePartyToWorkEffortAssignment(DispatchContext ctx, Map context) {
-        Map result = new HashMap();
-        GenericDelegator delegator = ctx.getDelegator();
-        Security security = ctx.getSecurity();
-        GenericValue userLogin = (GenericValue) context.get("userLogin");
-
-        // do a findByPrimary key to see if the entity exists, and other things later
-        GenericValue workEffortPartyAssignment = null;
-
-        try {
-            workEffortPartyAssignment = delegator.findByPrimaryKey("WorkEffortPartyAssignment",
-                        UtilMisc.toMap("workEffortId", context.get("workEffortId"), "partyId", context.get("partyId"),
-                            "roleTypeId", context.get("roleTypeId"), "fromDate", context.get("fromDate")));
-        } catch (GenericEntityException e) {
-            Debug.logWarning(e, module);
-        }
-
-        if (workEffortPartyAssignment == null) {
-            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
-            result.put(ModelService.ERROR_MESSAGE, "Could not update this Work Effort Party Assignment, does not exist.");
-            return result;
-        }
-
-        // check permissions before moving on:
-        // 1) if create, no permission necessary
-        // 2) if update or delete logged in user must be associated OR have the corresponding UPDATE or DELETE permissions
-        boolean associatedWith = (userLogin.getString("partyId") != null && userLogin.getString("partyId").equals(workEffortPartyAssignment.getString("partyId")));
-
-        if (!associatedWith && !security.hasEntityPermission("WORKEFFORTMGR", "_UPDATE", userLogin)) {
-            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
-            result.put(ModelService.ERROR_MESSAGE, "You cannot update this Work Effort Party Assignment, you must either be associated with it or have administration permission.");
-            return result;
-        }
-
-        GenericValue newWorkEffortPartyAssignment = (GenericValue) workEffortPartyAssignment.clone();              
-
-        // if necessary create new status entry, and set statusDateTime date
-        String lastStatusId = workEffortPartyAssignment.getString("statusId");
-        String statusId = (String) context.get("statusId");
-        
-        Timestamp nowStamp = UtilDateTime.nowTimestamp();
-        workEffortPartyAssignment.setNonPKFields(context);
-        
-        if (statusId != null && !statusId.equals(lastStatusId)) {
-            // set the current status & timestamp
-            workEffortPartyAssignment.set("statusId", statusId);
-            workEffortPartyAssignment.set("statusDateTime", nowStamp);
-            updateWorkflowEngine(workEffortPartyAssignment, userLogin, ctx.getDispatcher());
-        }
-
-        // if nothing has changed, return
-        if (workEffortPartyAssignment != null && newWorkEffortPartyAssignment.equals(workEffortPartyAssignment)) {
-            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
-            result.put(ModelService.SUCCESS_MESSAGE, "No changes made, not saving.");
-            return result;
-        }
-
-        try {
-            workEffortPartyAssignment.store();            
-        } catch (GenericEntityException e) {
-            Debug.logWarning("[WorkEffortPartyAssignmentEvents.updateWorkEffortPartyAssignment] Could not update WorkEffortPartyAssignment (write error)", module);
-            Debug.logWarning(e, module);
-            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
-            result.put(ModelService.ERROR_MESSAGE, "Could not update WorkEffortPartyAssignment (write error)");
-            return result;
-        }
-
-        result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
-        return result;
-    }
-
-    /**
-     * Service that deletes a WorkEffortPartyAssignment entity
-     * @param ctx The DispatchContext that this service is operating in
-     * @param context Map containing the input parameters
-     * @return Map with the result of the service, the output parameters
-     */
-    public static Map unassignPartyFromWorkEffort(DispatchContext ctx, Map context) {
-        Map result = new HashMap();
-        GenericDelegator delegator = ctx.getDelegator();
-        Security security = ctx.getSecurity();
-        List errorMessageList = new LinkedList();
-        GenericValue userLogin = (GenericValue) context.get("userLogin");
-        GenericValue workEffort = null;
-
-        // do a findByPrimary key to see if the entity exists, and other things later
-        GenericValue workEffortPartyAssignment = null;
-
-        try {
-            workEffortPartyAssignment = delegator.findByPrimaryKey("WorkEffortPartyAssignment",
-                        UtilMisc.toMap("workEffortId", context.get("workEffortId"), "partyId", context.get("partyId"),
-                            "roleTypeId", context.get("roleTypeId"), "fromDate", context.get("fromDate")));
-        } catch (GenericEntityException e) {
-            Debug.logWarning(e, module);
-        }
-
-        if (workEffortPartyAssignment == null) {
-            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
-            result.put(ModelService.ERROR_MESSAGE, "Could not delete this Work Effort Party Assignment, does not exist.");
-            return result;
-        }
-
-        // check permissions before moving on:
-        // 1) if create, no permission necessary
-        // 2) if update or delete logged in user must be associated OR have the corresponding UPDATE or DELETE permissions
-        boolean associatedWith = (userLogin.getString("partyId") != null && userLogin.getString("partyId").equals(workEffortPartyAssignment.getString("partyId")));
-
-        if (!associatedWith && !security.hasEntityPermission("WORKEFFORTMGR", "_UPDATE", userLogin)) {
-            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
-            result.put(ModelService.ERROR_MESSAGE, "You cannot delete this Work Effort Party Assignment, you must either be associated with it or have administration permission.");
-            return result;
-        }
-
-        // TODO: if WorkEffortPartyAssignment deleted, let the Workflow engine know...
-
-        try {
-            TransactionUtil.begin();
-
-            // Remove associated/dependent entries from other tables here
-
-            // Delete actual main entity last, just in case database is set up to do a cascading delete, caches won't get cleared
-            workEffortPartyAssignment.remove();
-
-            TransactionUtil.commit();
-        } catch (GenericEntityException e) {
-            errorMessageList.add("Could not delete WorkEffortPartyAssignment: " + e.getMessage());
-
-            try {
-                TransactionUtil.rollback();
-            } catch (GenericEntityException e2) {
-                errorMessageList.add("Could not rollback delete of WorkEffortPartyAssignment: " + e2.getMessage());
-            }
-        }
-
-        if (errorMessageList.size() > 0) {
-            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
-            result.put(ModelService.ERROR_MESSAGE_LIST, errorMessageList);
-        } else {
-            result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
-        }
-
-        return result;
-    }
-
     public static void updateWorkflowEngine(GenericValue wepa, GenericValue userLogin, LocalDispatcher dispatcher) {
         // if the WorkEffort is an ACTIVITY, check for accept or complete new status...
         GenericDelegator delegator = wepa.getDelegator();



More information about the Svn mailing list