svn commit: r781752 - in /ofbiz/trunk/applications/party: data/PartyTypeData.xml src/org/ofbiz/party/party/PartyServices.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r781752 - in /ofbiz/trunk/applications/party: data/PartyTypeData.xml src/org/ofbiz/party/party/PartyServices.java

hansbak-2
Author: hansbak
Date: Thu Jun  4 14:33:07 2009
New Revision: 781752

URL: http://svn.apache.org/viewvc?rev=781752&view=rev
Log:
disable related userlogins when a party is disabled, status changes makes now use of separate service, als make re-activate party possible

Modified:
    ofbiz/trunk/applications/party/data/PartyTypeData.xml
    ofbiz/trunk/applications/party/src/org/ofbiz/party/party/PartyServices.java

Modified: ofbiz/trunk/applications/party/data/PartyTypeData.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/party/data/PartyTypeData.xml?rev=781752&r1=781751&r2=781752&view=diff
==============================================================================
--- ofbiz/trunk/applications/party/data/PartyTypeData.xml (original)
+++ ofbiz/trunk/applications/party/data/PartyTypeData.xml Thu Jun  4 14:33:07 2009
@@ -297,7 +297,8 @@
     <StatusItem description="Enabled" sequenceId="01" statusCode="ENABLED" statusId="PARTY_ENABLED" statusTypeId="PARTY_STATUS"/>
     <StatusItem description="Disabled" sequenceId="99" statusCode="DISABLED" statusId="PARTY_DISABLED" statusTypeId="PARTY_STATUS"/>
     <StatusValidChange condition="" statusId="PARTY_ENABLED" statusIdTo="PARTY_DISABLED" transitionName="Disable"/>
-
+    <StatusValidChange condition="" statusId="PARTY_DISABLED" statusIdTo="PARTY_ENABLED" transitionName="Re-Enable"/>
+    
     <StatusType description="Case" hasTable="N" parentTypeId="" statusTypeId="CASE_STATUS"/>
 
     <StatusType description="Communication Event" hasTable="N" parentTypeId="" statusTypeId="COM_EVENT_STATUS"/>

Modified: ofbiz/trunk/applications/party/src/org/ofbiz/party/party/PartyServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/party/src/org/ofbiz/party/party/PartyServices.java?rev=781752&r1=781751&r2=781752&view=diff
==============================================================================
--- ofbiz/trunk/applications/party/src/org/ofbiz/party/party/PartyServices.java (original)
+++ ofbiz/trunk/applications/party/src/org/ofbiz/party/party/PartyServices.java Thu Jun  4 14:33:07 2009
@@ -211,22 +211,40 @@
         try {
             GenericValue party = delegator.findByPrimaryKey("Party", UtilMisc.toMap("partyId", partyId));
 
-            // check that status is defined as a valid change
-            GenericValue statusValidChange = delegator.findByPrimaryKey("StatusValidChange", UtilMisc.toMap("statusId", party.getString("statusId"), "statusIdTo", statusId));
-            if (statusValidChange == null) {
-                String errorMsg = "Cannot change party status from " + party.getString("statusId") + " to " + statusId;
-                Debug.logWarning(errorMsg, module);
-                return ServiceUtil.returnError(errorMsg);
+            if (party.get("statusId") == null) { // old records
+             party.set("statusId", "PARTY_ENABLED");
             }
 
-            // record the oldStatusId and change the party status
-            String oldStatusId = party.getString("statusId");
-            party.set("statusId", statusId);
-            party.store();
+         String oldStatusId = party.getString("statusId");
+            if (!party.getString("statusId").equals(statusId)) {
 
-            // record this status change in PartyStatus table
-            GenericValue partyStatus = delegator.makeValue("PartyStatus", UtilMisc.toMap("partyId", partyId, "statusId", statusId, "statusDate", statusDate));
-            partyStatus.create();
+             // check that status is defined as a valid change
+             GenericValue statusValidChange = delegator.findByPrimaryKey("StatusValidChange", UtilMisc.toMap("statusId", party.getString("statusId"), "statusIdTo", statusId));
+             if (statusValidChange == null) {
+             String errorMsg = "Cannot change party status from " + party.getString("statusId") + " to " + statusId;
+             Debug.logWarning(errorMsg, module);
+             return ServiceUtil.returnError(errorMsg);
+             }
+
+             party.set("statusId", statusId);
+             party.store();
+
+             // record this status change in PartyStatus table
+             GenericValue partyStatus = delegator.makeValue("PartyStatus", UtilMisc.toMap("partyId", partyId, "statusId", statusId, "statusDate", statusDate));
+             partyStatus.create();
+
+             // disable all userlogins for this user when the new status is disabled
+             if (("PARTY_DISABLED").equals(statusId)) {
+             List <GenericValue> userLogins = delegator.findByAnd("UserLogin", UtilMisc.toMap("partyId", partyId));
+             for(GenericValue userLogin : userLogins) {
+             if (!"N".equals(userLogin.getString("enabled"))) {
+             userLogin.set("enabled", "N");
+             userLogin.set("disabledDateTime", UtilDateTime.nowTimestamp());
+             userLogin.store();
+             }
+             }
+             }
+            }
 
             Map<String, Object> results = ServiceUtil.returnSuccess();
             results.put("oldStatusId", oldStatusId);
@@ -246,6 +264,7 @@
     public static Map<String, Object> updatePerson(DispatchContext ctx, Map<String, ? extends Object> context) {
         Map<String, Object> result = FastMap.newInstance();
         GenericDelegator delegator = ctx.getDelegator();
+        LocalDispatcher dispatcher = ctx.getDispatcher();
         Locale locale = (Locale) context.get("locale");
 
         String partyId = getPartyId(context);
@@ -267,10 +286,15 @@
         if (person == null || party == null) {
             return ServiceUtil.returnError(UtilProperties.getMessage(resource, "person.update.not_found", locale));
         }
+        
+        // update status by separate service
+        String oldStatusId = party.getString("statusId");
 
         person.setNonPKFields(context);
         party.setNonPKFields(context);
 
+        party.set("statusId", oldStatusId);
+        
         try {
             person.store();
             party.store();
@@ -278,6 +302,15 @@
             Debug.logWarning(e.getMessage(), module);
             return ServiceUtil.returnError(UtilProperties.getMessage(resource, "person.update.write_failure", new Object[] { e.getMessage() }, locale));
         }
+        
+        if (!context.get("statusId").equals(oldStatusId)) {
+            try {
+                dispatcher.runSync("setPartyStatus", UtilMisc.toMap("partyId", partyId, "statusId", context.get("statusId"), "userLogin", context.get("userLogin")));
+            } catch (GenericServiceException e) {
+                Debug.logWarning(e.getMessage(), module);
+                return ServiceUtil.returnError(UtilProperties.getMessage(resource, "person.update.write_failure", new Object[] { e.getMessage() }, locale));
+            }
+        }
 
         result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
         result.put(ModelService.SUCCESS_MESSAGE, UtilProperties.getMessage(resource, "person.update.success", locale));
@@ -399,6 +432,7 @@
     public static Map<String, Object> updatePartyGroup(DispatchContext ctx, Map<String, ? extends Object> context) {
         Map<String, Object> result = FastMap.newInstance();
         GenericDelegator delegator = ctx.getDelegator();
+        LocalDispatcher dispatcher = ctx.getDispatcher();
         Locale locale = (Locale) context.get("locale");
 
         String partyId = getPartyId(context);
@@ -425,8 +459,12 @@
             return ServiceUtil.returnError(errMsg);
         }
 
+        
+        // update status by separate service
+        String oldStatusId = party.getString("statusId");
         partyGroup.setNonPKFields(context);
         party.setNonPKFields(context);
+        party.set("statusId", oldStatusId);
 
         try {
             partyGroup.store();
@@ -438,6 +476,15 @@
             return ServiceUtil.returnError(errMsg);
         }
 
+        if (!context.get("statusId").equals(oldStatusId)) {
+            try {
+                dispatcher.runSync("setPartyStatus", UtilMisc.toMap("partyId", partyId, "statusId", context.get("statusId"), "userLogin", context.get("userLogin")));
+            } catch (GenericServiceException e) {
+                Debug.logWarning(e.getMessage(), module);
+                return ServiceUtil.returnError(UtilProperties.getMessage(resource, "person.update.write_failure", new Object[] { e.getMessage() }, locale));
+            }
+        }
+
         result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
         return result;
     }