Author: jleroux
Date: Fri Jan 15 10:25:03 2016 New Revision: 1724768 URL: http://svn.apache.org/viewvc?rev=1724768&view=rev Log: "Applied fix from trunk for revision: 1724763 " ------------------------------------------------------------------------ r1724763 | jleroux | 2016-01-15 11:18:00 +0100 (ven. 15 janv. 2016) | 6 lignes A slightly modified patch from Chula Lathong for <<Bug on SFA vcard import.>> https://issues.apache.org/jira/browse/OFBIZ-6795 Error occur when create Lead/Contact from Vcard. This patch will improve importVcard service to able to create Lead/Contact from Vcard and display error messages when Vcard has invalid values. jleroux: I simply changed the importVCard service transaction-timeout from 72000 (20 hours!) to 7200. Also added corresponding French labels ------------------------------------------------------------------------ Modified: ofbiz/branches/release15.12/ (props changed) ofbiz/branches/release15.12/applications/marketing/config/MarketingUiLabels.xml ofbiz/branches/release15.12/applications/marketing/servicedef/services.xml ofbiz/branches/release15.12/applications/marketing/src/org/ofbiz/sfa/vcard/VCard.java Propchange: ofbiz/branches/release15.12/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Fri Jan 15 10:25:03 2016 @@ -9,4 +9,4 @@ /ofbiz/branches/json-integration-refactoring:1634077-1635900 /ofbiz/branches/multitenant20100310:921280-927264 /ofbiz/branches/release13.07:1547657 -/ofbiz/trunk:1722712,1724402,1724411,1724566,1724689 +/ofbiz/trunk:1722712,1724402,1724411,1724566,1724689,1724763 Modified: ofbiz/branches/release15.12/applications/marketing/config/MarketingUiLabels.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/release15.12/applications/marketing/config/MarketingUiLabels.xml?rev=1724768&r1=1724767&r2=1724768&view=diff ============================================================================== --- ofbiz/branches/release15.12/applications/marketing/config/MarketingUiLabels.xml (original) +++ ofbiz/branches/release15.12/applications/marketing/config/MarketingUiLabels.xml Fri Jan 15 10:25:03 2016 @@ -3185,6 +3185,18 @@ <value xml:lang="zh">å¯¼å ¥çº¿ç´¢</value> <value xml:lang="zh-TW">å¯å ¥ç·ç´¢</value> </property> + <property key="SfaImportVcardDuplicatedVcardError"> + <value xml:lang="en">All parties in this vcard are duplicated.</value> + <value xml:lang="fr">Tous les acteurs de cette vcard sont dupliqués.</value> + </property> + <property key="SfaImportVCardEmailFormatError"> + <value xml:lang="en">incorrect email format.</value> + <value xml:lang="fr">Format de l'addresse courriel incorrect.</value> + </property> + <property key="SfaImportVcardNameMissingError"> + <value xml:lang="en">first name or last name missing.</value> + <value xml:lang="fr">Prénom ou nom manquant.</value> + </property> <property key="SfaImportVCardError"> <value xml:lang="de">Fehler beim importieren von VCard: ${errorString}</value> <value xml:lang="en">Error during import data from VCard: ${errorString}</value> Modified: ofbiz/branches/release15.12/applications/marketing/servicedef/services.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/release15.12/applications/marketing/servicedef/services.xml?rev=1724768&r1=1724767&r2=1724768&view=diff ============================================================================== --- ofbiz/branches/release15.12/applications/marketing/servicedef/services.xml (original) +++ ofbiz/branches/release15.12/applications/marketing/servicedef/services.xml Fri Jan 15 10:25:03 2016 @@ -515,7 +515,7 @@ under the License. </service> <!-- VCard services --> - <service name="importVCard" engine="java" location="org.ofbiz.sfa.vcard.VCard" invoke="importVCard"> + <service name="importVCard" engine="java" location="org.ofbiz.sfa.vcard.VCard" invoke="importVCard" transaction-timeout="7200"> <attribute name="infile" type="java.nio.ByteBuffer" mode="IN" optional="false"/> <attribute name="partyId" type="String" mode="OUT" optional="false"/> <attribute name="partyType" type="String" mode="IN" optional="true"/> Modified: ofbiz/branches/release15.12/applications/marketing/src/org/ofbiz/sfa/vcard/VCard.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release15.12/applications/marketing/src/org/ofbiz/sfa/vcard/VCard.java?rev=1724768&r1=1724767&r2=1724768&view=diff ============================================================================== --- ofbiz/branches/release15.12/applications/marketing/src/org/ofbiz/sfa/vcard/VCard.java (original) +++ ofbiz/branches/release15.12/applications/marketing/src/org/ofbiz/sfa/vcard/VCard.java Fri Jan 15 10:25:03 2016 @@ -28,25 +28,12 @@ import java.io.InputStream; import java.nio.ByteBuffer; import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Locale; import java.util.Map; -import net.wimpi.pim.Pim; -import net.wimpi.pim.contact.basicimpl.AddressImpl; -import net.wimpi.pim.contact.basicimpl.EmailAddressImpl; -import net.wimpi.pim.contact.basicimpl.PhoneNumberImpl; -import net.wimpi.pim.contact.io.ContactMarshaller; -import net.wimpi.pim.contact.io.ContactUnmarshaller; -import net.wimpi.pim.contact.model.Address; -import net.wimpi.pim.contact.model.Communications; -import net.wimpi.pim.contact.model.Contact; -import net.wimpi.pim.contact.model.EmailAddress; -import net.wimpi.pim.contact.model.Organization; -import net.wimpi.pim.contact.model.OrganizationalIdentity; -import net.wimpi.pim.contact.model.PersonalIdentity; -import net.wimpi.pim.contact.model.PhoneNumber; -import net.wimpi.pim.factory.ContactIOFactory; -import net.wimpi.pim.factory.ContactModelFactory; +import javax.mail.internet.AddressException; +import javax.mail.internet.InternetAddress; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.FileUtil; @@ -68,6 +55,23 @@ import org.ofbiz.service.GenericServiceE import org.ofbiz.service.LocalDispatcher; import org.ofbiz.service.ServiceUtil; +import net.wimpi.pim.Pim; +import net.wimpi.pim.contact.basicimpl.AddressImpl; +import net.wimpi.pim.contact.basicimpl.EmailAddressImpl; +import net.wimpi.pim.contact.basicimpl.PhoneNumberImpl; +import net.wimpi.pim.contact.io.ContactMarshaller; +import net.wimpi.pim.contact.io.ContactUnmarshaller; +import net.wimpi.pim.contact.model.Address; +import net.wimpi.pim.contact.model.Communications; +import net.wimpi.pim.contact.model.Contact; +import net.wimpi.pim.contact.model.EmailAddress; +import net.wimpi.pim.contact.model.Organization; +import net.wimpi.pim.contact.model.OrganizationalIdentity; +import net.wimpi.pim.contact.model.PersonalIdentity; +import net.wimpi.pim.contact.model.PhoneNumber; +import net.wimpi.pim.factory.ContactIOFactory; +import net.wimpi.pim.factory.ContactModelFactory; + public class VCard { public static final String module = VCard.class.getName(); public static final String resourceError = "MarketingUiLabels"; @@ -90,8 +94,10 @@ public class VCard { try { ContactIOFactory ciof = Pim.getContactIOFactory(); ContactUnmarshaller unmarshaller = ciof.createContactUnmarshaller(); + unmarshaller.setStrict(false); Contact[] contacts = unmarshaller.unmarshallContacts(in); + int contactsCount = 1; for (Contact contact: contacts) { PersonalIdentity pid = contact.getPersonalIdentity(); if (!isGroup) { @@ -146,6 +152,14 @@ public class VCard { } } if (UtilValidate.isNotEmpty(email)) { + InternetAddress emailAddr; + try { + emailAddr = new InternetAddress(email); + emailAddr.validate(); + } catch (AddressException e) { + String emailFOrmatErrMsg = UtilProperties.getMessage(resourceError, "SfaImportVCardEmailFormatError", locale); + return ServiceUtil.returnError(pid.getFirstname() + " " + pid.getLastname() + " has " + emailFOrmatErrMsg); + } serviceCtx.put("emailAddress", email); } for (Iterator<?> iter = communications.getPhoneNumbers(); iter.hasNext();) { @@ -175,8 +189,12 @@ public class VCard { } OrganizationalIdentity oid = contact.getOrganizationalIdentity(); // Useful when creating a contact with more than OOTB - if (!isGroup) { - serviceCtx.put("personalTitle", oid.getTitle()); + if (!isGroup && oid != null && oid.getTitle() != null) { + String personalTitle = oid.getTitle().replace("\\","").replaceAll("\uFFFD", " "); + if (personalTitle.length() > 100) { + personalTitle = oid.getTitle().replace("\\", "").replaceAll("\uFFFD", " ").substring(0, 100); + } + serviceCtx.put("personalTitle", personalTitle); } // Needed when creating an account (a PartyGroup) @@ -184,7 +202,7 @@ public class VCard { //serviceCtx.put("partyRole", oid.getRole()); // not used yet,maybe useful later if (oid.hasOrganization()) { Organization org = oid.getOrganization(); - serviceCtx.put("groupName", org.getName()); + serviceCtx.put("groupName", org.getName().replace("\\", "")); } } @@ -197,8 +215,34 @@ public class VCard { serviceCtx.put(entry.getKey(), entry.getValue()); } } - Map<String, Object> resp = dispatcher.runSync(serviceName, serviceCtx); - result.put("partyId", resp.get("partyId")); + List<GenericValue> persons = EntityQuery.use(delegator).from("Person").where( + "firstName", serviceCtx.get("firstName"), + "lastName", serviceCtx.get("lastName") + ).queryList(); + boolean blockPerson = false; + for (GenericValue person: persons) { + GenericValue partyStatus = EntityQuery.use(delegator).from("PartyStatus").where( + "partyId", person.get("partyId")).orderBy("-statusDate").queryFirst(); + if (!partyStatus.get("statusId").equals("PARTY_DISABLED")) { + blockPerson = true; + } + } + if (!blockPerson) { + String nameMissingErrMsg = UtilProperties.getMessage(resourceError, "SfaImportVcardNameMissingError", locale); + if (!isGroup && serviceCtx.get("lastName") == null) { + return ServiceUtil.returnError(serviceCtx.get("firstName") + " " + nameMissingErrMsg); + } + if (!isGroup && serviceCtx.get("firstName") == null) { + return ServiceUtil.returnError(serviceCtx.get("lastName") + " " + nameMissingErrMsg); + } + Map<String, Object> resp = dispatcher.runSync(serviceName, serviceCtx); + result.put("partyId", resp.get("partyId")); + } + if (result.get("partyId") == null && contactsCount == contacts.length) { + String duplicatedErrMsg = UtilProperties.getMessage(resourceError, "SfaImportVcardDuplicatedVcardError", locale); + return ServiceUtil.returnError(duplicatedErrMsg); + } + contactsCount++; } } catch (GenericEntityException e) { Debug.logError(e, module); |
Free forum by Nabble | Edit this page |