You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ap...@apache.org on 2007/07/14 12:19:32 UTC

svn commit: r556256 - in /ofbiz/trunk/applications/party: servicedef/services.xml src/org/ofbiz/party/contact/ContactMechServices.java

Author: apatel
Date: Sat Jul 14 03:19:31 2007
New Revision: 556256

URL: http://svn.apache.org/viewvc?view=rev&rev=556256
Log:
Service to expire a contactmechpurpose if it exists. Found useful in Party profile page.

Modified:
    ofbiz/trunk/applications/party/servicedef/services.xml
    ofbiz/trunk/applications/party/src/org/ofbiz/party/contact/ContactMechServices.java

Modified: ofbiz/trunk/applications/party/servicedef/services.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/party/servicedef/services.xml?view=diff&rev=556256&r1=556255&r2=556256
==============================================================================
--- ofbiz/trunk/applications/party/servicedef/services.xml (original)
+++ ofbiz/trunk/applications/party/servicedef/services.xml Sat Jul 14 03:19:31 2007
@@ -490,6 +490,13 @@
         <attribute name="contactMechPurposeTypeId" type="String" mode="IN" optional="false"/>
         <attribute name="fromDate" type="Timestamp" mode="IN" optional="false"/>
     </service>
+    <service name="deletePartyContactMechPurposeIfExists" engine="java"
+            location="org.ofbiz.party.contact.ContactMechServices" invoke="deletePartyContactMechPurposeIfExists" auth="true">
+        <description>Delete a Party ContactMech Purpose</description>
+        <attribute name="partyId" type="String" mode="IN" optional="true"/>
+        <attribute name="contactMechId" type="String" mode="IN" optional="false"/>
+        <attribute name="contactMechPurposeTypeId" type="String" mode="IN" optional="false"/>
+    </service>
 
     <!-- ContactMechList services -->
     <service name="createContactMechLink" default-entity-name="ContactMechLink" engine="simple"

Modified: ofbiz/trunk/applications/party/src/org/ofbiz/party/contact/ContactMechServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/party/src/org/ofbiz/party/contact/ContactMechServices.java?view=diff&rev=556256&r1=556255&r2=556256
==============================================================================
--- ofbiz/trunk/applications/party/src/org/ofbiz/party/contact/ContactMechServices.java (original)
+++ ofbiz/trunk/applications/party/src/org/ofbiz/party/contact/ContactMechServices.java Sat Jul 14 03:19:31 2007
@@ -849,6 +849,57 @@
         return result;
     }
 
+    public static Map deletePartyContactMechPurposeIfExists(DispatchContext ctx, Map context) {
+        //Debug.logInfo(new Exception(), "In createPartyContactMechPurpose context: " + context, module);
+        Map result = new HashMap();
+        GenericDelegator delegator = ctx.getDelegator();
+        Security security = ctx.getSecurity();
+        GenericValue userLogin = (GenericValue) context.get("userLogin");
+
+        String partyId = ServiceUtil.getPartyIdCheckSecurity(userLogin, security, context, result, "PARTYMGR", "_PCM_DELETE");
+        String errMsg = null;
+        Locale locale = (Locale) context.get("locale");
+
+        if (result.size() > 0) {
+            return result;
+        }
+
+        // required parameters
+        String contactMechId = (String) context.get("contactMechId");
+        String contactMechPurposeTypeId = (String) context.get("contactMechPurposeTypeId");
+
+        GenericValue tempVal = null;
+        try {
+            Map pcmpFindMap = UtilMisc.toMap("partyId", partyId, "contactMechId", contactMechId, "contactMechPurposeTypeId", contactMechPurposeTypeId);
+            //Debug.logInfo("pcmpFindMap = " + pcmpFindMap, module);
+            List allPCMPs = EntityUtil.filterByDate(delegator.findByAnd("PartyContactMechPurpose", pcmpFindMap), true);
+
+            tempVal = EntityUtil.getFirst(allPCMPs);
+        } catch (GenericEntityException e) {
+            Debug.logWarning(e.getMessage(), module);
+            tempVal = null;
+        }
+        if (tempVal != null) {
+            Map deletePcmCtx = UtilMisc.toMap("contactMechId", context.get("contactMechId"));
+            deletePcmCtx.put("contactMechPurposeTypeId", context.get("contactMechPurposeTypeId"));
+            deletePcmCtx.put("fromDate", tempVal.get("fromDate"));
+            deletePcmCtx.put("userLogin", context.get("userLogin"));
+            try {
+                Map deletePcmResult = ctx.getDispatcher().runSync("deletePartyContactMechPurpose", deletePcmCtx);
+                if(ServiceUtil.isError(deletePcmResult)){
+                    return deletePcmResult;
+                }
+            } catch (GenericServiceException e) {
+                Debug.logWarning(e.getMessage(), module);
+                Map messageMap = UtilMisc.toMap("errMessage", e.getMessage());
+                errMsg = UtilProperties.getMessage(resource,"contactmechservices.could_not_delete_purpose_from_contact_mechanism_read", messageMap, locale);
+                return ServiceUtil.returnError(errMsg);
+            }
+        }
+        result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
+        return result;
+
+    }
     /**
      * Deletes the PartyContactMechPurpose corresponding to the parameters in the context
      * <b>security check</b>: userLogin partyId must equal partyId, or must have PARTYMGR_DELETE permission