svn commit: r659458 - in /ofbiz/trunk/applications/marketing: ./ config/ lib/ servicedef/ src/org/ofbiz/sfa/ src/org/ofbiz/sfa/vcard/ webapp/sfa/WEB-INF/ widget/sfa/forms/

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

svn commit: r659458 - in /ofbiz/trunk/applications/marketing: ./ config/ lib/ servicedef/ src/org/ofbiz/sfa/ src/org/ofbiz/sfa/vcard/ webapp/sfa/WEB-INF/ widget/sfa/forms/

mor-2
Author: mor
Date: Fri May 23 00:05:45 2008
New Revision: 659458

URL: http://svn.apache.org/viewvc?rev=659458&view=rev
Log:
Adding functinality to create a contact from a vCard and vice-versa (in sfa)

Added:
    ofbiz/trunk/applications/marketing/config/sfa.properties   (with props)
    ofbiz/trunk/applications/marketing/lib/
    ofbiz/trunk/applications/marketing/lib/jpim-0.1.jar   (with props)
    ofbiz/trunk/applications/marketing/src/org/ofbiz/sfa/
    ofbiz/trunk/applications/marketing/src/org/ofbiz/sfa/vcard/
    ofbiz/trunk/applications/marketing/src/org/ofbiz/sfa/vcard/VCard.java   (with props)
Modified:
    ofbiz/trunk/applications/marketing/build.xml
    ofbiz/trunk/applications/marketing/ofbiz-component.xml
    ofbiz/trunk/applications/marketing/servicedef/services.xml
    ofbiz/trunk/applications/marketing/webapp/sfa/WEB-INF/controller.xml
    ofbiz/trunk/applications/marketing/widget/sfa/forms/ContactForms.xml

Modified: ofbiz/trunk/applications/marketing/build.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/marketing/build.xml?rev=659458&r1=659457&r2=659458&view=diff
==============================================================================
--- ofbiz/trunk/applications/marketing/build.xml (original)
+++ ofbiz/trunk/applications/marketing/build.xml Fri May 23 00:05:45 2008
@@ -37,7 +37,7 @@
 
     <target name="classpath">
         <path id="local.class.path">
-            <!--<fileset dir="${lib.dir}" includes="*.jar"/>-->
+            <fileset dir="${lib.dir}" includes="*.jar"/>
             <fileset dir="../../framework/base/lib" includes="*.jar"/>
             <fileset dir="../../framework/base/lib/j2eespecs" includes="*.jar"/>
             <fileset dir="../../framework/base/build/lib" includes="*.jar"/>
@@ -52,6 +52,7 @@
             <fileset dir="../content/build/lib" includes="*.jar"/>
             <fileset dir="../../framework/common/build/lib" includes="*.jar"/>
             <fileset dir="../product/build/lib" includes="*.jar"/>
+            <fileset dir="../party/build/lib" includes="*.jar"/>
         </path>
     </target>
 

Added: ofbiz/trunk/applications/marketing/config/sfa.properties
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/marketing/config/sfa.properties?rev=659458&view=auto
==============================================================================
--- ofbiz/trunk/applications/marketing/config/sfa.properties (added)
+++ ofbiz/trunk/applications/marketing/config/sfa.properties Fri May 23 00:05:45 2008
@@ -0,0 +1,21 @@
+###############################################################################
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+###############################################################################
+
+# if the save.outgoing.directory is specified the file will be saved there else it will be saved under OFBIZ_HOME
+#save.outgoing.directory=
\ No newline at end of file

Propchange: ofbiz/trunk/applications/marketing/config/sfa.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/trunk/applications/marketing/config/sfa.properties
------------------------------------------------------------------------------
    svn:keywords = Date Rev Author URL Id

Propchange: ofbiz/trunk/applications/marketing/config/sfa.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: ofbiz/trunk/applications/marketing/lib/jpim-0.1.jar
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/marketing/lib/jpim-0.1.jar?rev=659458&view=auto
==============================================================================
Binary file - no diff available.

Propchange: ofbiz/trunk/applications/marketing/lib/jpim-0.1.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: ofbiz/trunk/applications/marketing/ofbiz-component.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/marketing/ofbiz-component.xml?rev=659458&r1=659457&r2=659458&view=diff
==============================================================================
--- ofbiz/trunk/applications/marketing/ofbiz-component.xml (original)
+++ ofbiz/trunk/applications/marketing/ofbiz-component.xml Fri May 23 00:05:45 2008
@@ -23,6 +23,7 @@
         xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/ofbiz-component.xsd">
     <resource-loader name="main" type="component"/>
     <classpath type="jar" location="build/lib/*"/>
+    <classpath type="jar" location="lib/*"/>
     <classpath type="dir" location="script"/>
     <classpath type="dir" location="config"/>
     <entity-resource type="model" reader-name="main" loader="main" location="entitydef/entitymodel.xml"/>

Modified: ofbiz/trunk/applications/marketing/servicedef/services.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/marketing/servicedef/services.xml?rev=659458&r1=659457&r2=659458&view=diff
==============================================================================
--- ofbiz/trunk/applications/marketing/servicedef/services.xml (original)
+++ ofbiz/trunk/applications/marketing/servicedef/services.xml Fri May 23 00:05:45 2008
@@ -458,4 +458,14 @@
         <attribute name="leadPartyId" type="String" mode="IN" optional="false"/>
         <attribute name="partyId" type="String" mode="IN" optional="true"/>
     </service>
+    
+    <!-- VCard services -->
+    <service name="importVCard" engine="java" location="org.ofbiz.sfa.vcard.VCard" invoke="importVCard">
+        <attribute name="infile" type="java.nio.ByteBuffer" mode="IN" optional="false"/>
+        <attribute name="partyId" type="String" mode="OUT" optional="false"/>
+    </service>
+    <service name="exportVCard" engine="java" location="org.ofbiz.sfa.vcard.VCard" invoke="exportVCard">
+        <attribute name="partyId" type="String" mode="IN" optional="false"/>
+    </service>
+    
 </services>
\ No newline at end of file

Added: ofbiz/trunk/applications/marketing/src/org/ofbiz/sfa/vcard/VCard.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/marketing/src/org/ofbiz/sfa/vcard/VCard.java?rev=659458&view=auto
==============================================================================
--- ofbiz/trunk/applications/marketing/src/org/ofbiz/sfa/vcard/VCard.java (added)
+++ ofbiz/trunk/applications/marketing/src/org/ofbiz/sfa/vcard/VCard.java Fri May 23 00:05:45 2008
@@ -0,0 +1,233 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *******************************************************************************/
+
+package org.ofbiz.sfa.vcard;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.base.util.UtilProperties;
+import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.entity.GenericDelegator;
+import org.ofbiz.entity.GenericEntityException;
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.entity.condition.EntityCondition;
+import org.ofbiz.entity.condition.EntityConditionList;
+import org.ofbiz.entity.condition.EntityExpr;
+import org.ofbiz.entity.condition.EntityOperator;
+import org.ofbiz.entity.util.EntityUtil;
+import org.ofbiz.service.DispatchContext;
+import org.ofbiz.service.GenericServiceException;
+import org.ofbiz.service.LocalDispatcher;
+import org.ofbiz.service.ServiceUtil;
+
+import org.ofbiz.party.party.PartyHelper;
+import org.ofbiz.party.party.PartyWorker;
+
+import net.wimpi.pim.Pim;
+import net.wimpi.pim.contact.io.ContactMarshaller;
+import net.wimpi.pim.contact.io.ContactUnmarshaller;
+import net.wimpi.pim.factory.ContactIOFactory;
+import net.wimpi.pim.factory.ContactModelFactory;
+import net.wimpi.pim.contact.model.Contact;
+import net.wimpi.pim.contact.model.Address;
+import net.wimpi.pim.contact.model.Communications;
+import net.wimpi.pim.contact.model.EmailAddress;
+import net.wimpi.pim.contact.model.PersonalIdentity;
+import net.wimpi.pim.contact.model.PhoneNumber;
+import net.wimpi.pim.contact.basicimpl.AddressImpl;
+import net.wimpi.pim.contact.basicimpl.EmailAddressImpl;
+import net.wimpi.pim.contact.basicimpl.PhoneNumberImpl;
+
+public class VCard {
+    public static final String module = VCard.class.getName();
+    
+    public static Map importVCard(DispatchContext dctx, Map context) {
+        LocalDispatcher dispatcher = (LocalDispatcher) dctx.getDispatcher();
+        GenericDelegator delegator = (GenericDelegator) dctx.getDelegator();
+        Map result = ServiceUtil.returnSuccess();
+        Address workAddress = null;
+        String email = null;
+        String phone = null;
+        ByteBuffer byteBuffer = (ByteBuffer) context.get("infile");
+        byte[] inputByteArray = byteBuffer.array();
+        InputStream in = new ByteArrayInputStream(inputByteArray);
+        try {
+            ContactIOFactory ciof = Pim.getContactIOFactory();
+            ContactUnmarshaller unmarshaller = ciof.createContactUnmarshaller();
+            Contact[] contact = unmarshaller.unmarshallContacts(in);
+            
+            for (int i = 0; i < contact.length; i++) {
+                PersonalIdentity pid = contact[i].getPersonalIdentity();
+                Map serviceCtx = UtilMisc.toMap("firstName", pid.getFirstname(), "lastName", pid.getLastname());
+                
+                for (Iterator iter = contact[i].getAddresses(); iter.hasNext();) {
+                    Address address = (AddressImpl) iter.next();
+                    if (contact[i].isPreferredAddress(address)) {
+                        workAddress = address;
+                        break;
+                    } else if (address.isWork()) {
+                        workAddress = address;
+                        break;
+                    } else { // for now use preffered / work address only
+                        continue;
+                    }
+                }
+                serviceCtx.put("address1", workAddress.getStreet());
+                serviceCtx.put("city", workAddress.getCity());
+                serviceCtx.put("postalCode", workAddress.getPostalCode());
+                EntityCondition cond = new EntityConditionList(UtilMisc.toList(
+                                                    new EntityExpr("geoTypeId", EntityOperator.EQUALS, "COUNTRY"),
+                                                    new EntityExpr("geoName", EntityOperator.LIKE, workAddress.getCountry())), EntityOperator.AND);
+                GenericValue countryGeo = EntityUtil.getFirst(delegator.findList("Geo", cond, null, null, null, true));
+                serviceCtx.put("countryGeoId", countryGeo.get("geoId"));
+
+                EntityCondition condition = new EntityConditionList(UtilMisc.toList(
+                        new EntityExpr("geoTypeId", EntityOperator.EQUALS, "STATE"),
+                        new EntityExpr("geoName", EntityOperator.LIKE, workAddress.getRegion())), EntityOperator.AND);
+                GenericValue stateGeo = EntityUtil.getFirst(delegator.findList("Geo", condition, null, null, null, true));
+                serviceCtx.put("stateProvinceGeoId", stateGeo.get("geoId"));
+                
+                Communications communications = contact[i].getCommunications();
+                for (Iterator iter = communications.getEmailAddresses(); iter.hasNext();) {
+                    EmailAddress emailAddress = (EmailAddressImpl) iter.next();
+                    if (communications.isPreferredEmailAddress(emailAddress)) {
+                        email = emailAddress.getAddress();
+                        break;
+                    } else {
+                        email = emailAddress.getAddress();
+                        break;
+                    }
+                }
+                serviceCtx.put("emailAddress", email);
+                
+                for (Iterator iter = communications.getPhoneNumbers(); iter.hasNext();) {
+                    PhoneNumber phoneNumber = (PhoneNumberImpl) iter.next();
+                    if (phoneNumber.isPreferred()) {
+                        phone = phoneNumber.getNumber();
+                        break;
+                    } else if (phoneNumber.isWork()) {
+                        phone = phoneNumber.getNumber();
+                        break;
+                    } else { // for now use only preffered / work phone numbers
+                        continue;
+                    }
+                }
+                String[] number = phone.split("\\D");
+                String telNumber = "";
+                for (int j = 0; j < number.length; j++) {
+                    if (number[j] != "") {
+                        telNumber =  telNumber + number[j];
+                    }
+                }
+                serviceCtx.put("areaCode", telNumber.substring(0, 3));
+                serviceCtx.put("contactNumber", telNumber.substring(3));
+                
+                GenericValue userLogin = (GenericValue) context.get("userLogin");
+                serviceCtx.put("userLogin", userLogin);
+                Map resp = dispatcher.runSync("createContact", serviceCtx);
+                result.put("partyId", resp.get("partyId"));
+            }
+        } catch (GenericEntityException e) {
+            Debug.logError(e, module);
+            return ServiceUtil.returnError(e.getMessage());
+        } catch (GenericServiceException e) {
+            Debug.logError(e, module);
+            return ServiceUtil.returnError(e.getMessage());
+        }
+        return result;
+    }
+    
+    public static Map exportVCard(DispatchContext dctx, Map context) {
+        GenericDelegator delegator = (GenericDelegator) dctx.getDelegator();
+        String partyId = (String) context.get("partyId");
+        File file = null;
+        try {
+            ContactModelFactory cmf = Pim.getContactModelFactory();
+            Contact contact = cmf.createContact();
+            
+            PersonalIdentity pid = cmf.createPersonalIdentity();
+            String fullName = PartyHelper.getPartyName(delegator, partyId, false);
+            String[] name = fullName.split("\\s");
+            pid.setFirstname(name[0]);
+            pid.setLastname(name[1]);
+            contact.setPersonalIdentity(pid);
+            
+            GenericValue postalAddress = PartyWorker.findPartyLatestPostalAddress(partyId, delegator);
+            Address address = cmf.createAddress();
+            address.setStreet(postalAddress.getString("address1"));
+            address.setCity(postalAddress.getString("city"));
+            
+            address.setPostalCode(postalAddress.getString("postalCode"));
+            String state = postalAddress.getRelatedOne("StateProvinceGeo").getString("geoName");
+            address.setRegion(state);
+            
+            String country = postalAddress.getRelatedOne("CountryGeo").getString("geoName");
+            address.setCountry(country);
+            address.setWork(true); // this can be better set by checking contactMechPurposeTypeId
+            contact.addAddress(address);
+            
+            Communications communication = cmf.createCommunications();
+            contact.setCommunications(communication);
+
+            PhoneNumber number = cmf.createPhoneNumber();
+            GenericValue telecomNumber = PartyWorker.findPartyLatestTelecomNumber(partyId, delegator);
+            if (UtilValidate.isNotEmpty(telecomNumber)) {
+                number.setNumber(telecomNumber.getString("areaCode") + telecomNumber.getString("contactNumber"));
+                number.setWork(true); // this can be better set by checking contactMechPurposeTypeId
+                communication.addPhoneNumber(number);
+            }
+            EmailAddress email = cmf.createEmailAddress();
+            GenericValue emailAddress = PartyWorker.findPartyLatestContactMech(partyId, "EMAIL_ADDRESS", delegator);
+            if (UtilValidate.isNotEmpty(emailAddress.getString("infoString"))) {
+                email.setAddress(emailAddress.getString("infoString"));
+                communication.addEmailAddress(email);
+            }
+            ContactIOFactory ciof = Pim.getContactIOFactory();
+            ContactMarshaller marshaller = ciof.createContactMarshaller();
+            String saveToDirectory = UtilProperties.getPropertyValue("sfa.properties", "save.outgoing.directory", "");
+            if (UtilValidate.isEmpty(saveToDirectory)) {
+                saveToDirectory = System.getProperty("ofbiz.home");
+            }
+            String saveToFilename = fullName + ".vcf";
+            file = new File(saveToDirectory + "/" + saveToFilename);
+            FileOutputStream outputStream = new FileOutputStream(file);
+            marshaller.marshallContact(outputStream, contact);
+            outputStream.close();
+        } catch (FileNotFoundException e) {
+            Debug.logError(e, module);
+            return ServiceUtil.returnError("Unable to open file for writing: " + file.getAbsolutePath());
+        } catch (IOException e) {
+            Debug.logError(e, module);
+            return ServiceUtil.returnError("Unable to write data to: " + file.getAbsolutePath());
+        } catch (GenericEntityException e) {
+            return ServiceUtil.returnError(e.getMessage());            
+        }
+        return ServiceUtil.returnSuccess();
+    }
+}
\ No newline at end of file

Propchange: ofbiz/trunk/applications/marketing/src/org/ofbiz/sfa/vcard/VCard.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/trunk/applications/marketing/src/org/ofbiz/sfa/vcard/VCard.java
------------------------------------------------------------------------------
    svn:keywords = Date Rev Author URL Id

Propchange: ofbiz/trunk/applications/marketing/src/org/ofbiz/sfa/vcard/VCard.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: ofbiz/trunk/applications/marketing/webapp/sfa/WEB-INF/controller.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/marketing/webapp/sfa/WEB-INF/controller.xml?rev=659458&r1=659457&r2=659458&view=diff
==============================================================================
--- ofbiz/trunk/applications/marketing/webapp/sfa/WEB-INF/controller.xml (original)
+++ ofbiz/trunk/applications/marketing/webapp/sfa/WEB-INF/controller.xml Fri May 23 00:05:45 2008
@@ -151,7 +151,19 @@
     <request-map uri="CreateContactFromVCard">
         <security https="true" auth="true"/>
         <response name="success" type="view" value="CreateContactFromVCard"/>
-    </request-map>    
+    </request-map>
+    <request-map uri="createContactFromVCard">
+        <security https="true" auth="true"/>
+        <event type="service" invoke="importVCard"/>
+        <response name="success" type="view" value="viewprofile"/><!-- What would be the view in case a vCard contains more than one contact -->
+        <response name="error" type="view" value="CreateContactFromVCard"/>
+    </request-map>
+    <request-map uri="createVCardFromContact">
+        <security https="true" auth="true"/>
+        <event type="service" invoke="exportVCard"/>
+        <response name="success" type="view" value="FindContacts"/><!-- This need to be fixed -->
+        <response name="error" type="view" value="FindContacts"/>
+    </request-map>        
     <!-- end of request mappings -->
 
     <!-- View Mappings -->

Modified: ofbiz/trunk/applications/marketing/widget/sfa/forms/ContactForms.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/marketing/widget/sfa/forms/ContactForms.xml?rev=659458&r1=659457&r2=659458&view=diff
==============================================================================
--- ofbiz/trunk/applications/marketing/widget/sfa/forms/ContactForms.xml (original)
+++ ofbiz/trunk/applications/marketing/widget/sfa/forms/ContactForms.xml Fri May 23 00:05:45 2008
@@ -35,6 +35,9 @@
             <hyperlink target="viewprofile?partyId=${partyRow.partyId}" description="${partyRow.partyId}"/>
         </field>
         <field name="partyName" title="${uiLabelMap.PartyName}"><display description="${person.lastName}, ${person.firstName}"/></field>
+        <field name="export">
+            <hyperlink target="createVCardFromContact?partyId=${partyRow.partyId}" description="vCard"/>
+        </field>
     </form>
     <form name="CreateContact" type="single" target="createContact" header-row-style="header-row" default-table-style="basic-table">
         <field name="firstName" tooltip="${uiLabelMap.CommonRequired}" widget-style="required"><text/></field>
@@ -84,8 +87,8 @@
         <field name="submitButton" position="3" title="${uiLabelMap.SfaMergeContacts}" widget-style="buttontext" tooltip-style="button-text"><submit button-type="text-link"/></field>
     </form>
     
-    <form name="CreateContactFromVCard" type="single" target="" header-row-style="header-row" default-table-style="basic-table">
-        <field name="uploadVCard" title="${uiLabelMap.SfaUploadVCard}" ><file maxlength="100" size="50"/></field>
+    <form name="CreateContactFromVCard" type="upload" target="createContactFromVCard" header-row-style="header-row" default-table-style="basic-table">
+        <field name="infile" title="${uiLabelMap.SfaUploadVCard}"><file/></field>
         <field name="submitButton" title="${uiLabelMap.CommonUpload}" widget-style="smallSubmit"><submit button-type="button"/></field>
     </form>
 </forms>