Author: jleroux
Date: Tue Jan 12 19:19:22 2010
New Revision: 898473
URL: http://svn.apache.org/viewvc?rev=898473&view=rev
Log:
Another step in enhancing the importVCard service.
Now it differentiates between a PartyGroup and a Person.
This enables to load a PostalAddress and a PartyGroup.groupName for now.
Also now the personalTitle may be loaded for a Person.
Modified:
ofbiz/trunk/applications/marketing/servicedef/services.xml
ofbiz/trunk/applications/marketing/src/org/ofbiz/sfa/vcard/VCard.java
Modified: ofbiz/trunk/applications/marketing/servicedef/services.xml
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/marketing/servicedef/services.xml?rev=898473&r1=898472&r2=898473&view=diff
==============================================================================
--- ofbiz/trunk/applications/marketing/servicedef/services.xml (original)
+++ ofbiz/trunk/applications/marketing/servicedef/services.xml Tue Jan 12
19:19:22 2010
@@ -480,6 +480,7 @@
<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"/>
+ <attribute name="partyType" type="String" mode="IN" optional="true"/>
<attribute name="serviceContext" type="Map" mode="IN" optional="true"/>
<attribute name="serviceName" type="String" mode="IN"
optional="false"/>
</service>
Modified: 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=898473&r1=898472&r2=898473&view=diff
==============================================================================
--- ofbiz/trunk/applications/marketing/src/org/ofbiz/sfa/vcard/VCard.java
(original)
+++ ofbiz/trunk/applications/marketing/src/org/ofbiz/sfa/vcard/VCard.java Tue
Jan 12 19:19:22 2010
@@ -30,6 +30,8 @@
import java.util.List;
import java.util.Map;
+import javolution.util.FastMap;
+
import net.wimpi.pim.Pim;
import net.wimpi.pim.contact.basicimpl.AddressImpl;
import net.wimpi.pim.contact.basicimpl.EmailAddressImpl;
@@ -40,6 +42,8 @@
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;
@@ -77,6 +81,10 @@
ByteBuffer byteBuffer = (ByteBuffer) context.get("infile");
byte[] inputByteArray = byteBuffer.array();
InputStream in = new ByteArrayInputStream(inputByteArray);
+ String partyType = (String) context.get("partyType");
+ Boolean isGroup = "PartyGroup".equals(partyType); // By default we
import a Person.
+ Map<String, Object> serviceCtx = FastMap.newInstance();
+
try {
ContactIOFactory ciof = Pim.getContactIOFactory();
ContactUnmarshaller unmarshaller =
ciof.createContactUnmarshaller();
@@ -84,8 +92,10 @@
for (Contact contact: contacts) {
PersonalIdentity pid = contact.getPersonalIdentity();
- Map<String, Object> serviceCtx = UtilMisc.<String,
Object>toMap("firstName", pid.getFirstname(), "lastName", pid.getLastname());
-
+ if (!isGroup) {
+ serviceCtx.put("firstName", pid.getFirstname());
+ serviceCtx.put("lastName", pid.getLastname());
+ }
for (Iterator iter = contact.getAddresses(); iter.hasNext();) {
Address address = (AddressImpl) iter.next();
if (contact.isPreferredAddress(address)) {
@@ -94,7 +104,7 @@
} else if (address.isWork()) {
workAddress = address;
break;
- } else { // for now use preffered / work address only
+ } else { // for now use preferred/work address only
continue;
}
}
@@ -123,44 +133,60 @@
serviceCtx.put("stateProvinceGeoId",
stateGeo.get("geoId"));
}
}
-
- Communications communications = contact.getCommunications();
- if (UtilValidate.isNotEmpty(communications)) {
- 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;
+
+ if (!isGroup) {
+ Communications communications =
contact.getCommunications();
+ if (UtilValidate.isNotEmpty(communications)) {
+ 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;
+ }
}
- }
- if (UtilValidate.isNotEmpty(email)) {
- 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;
+ if (UtilValidate.isNotEmpty(email)) {
+ serviceCtx.put("emailAddress", email);
}
- }
- if (UtilValidate.isNotEmpty(phone)) {
- String[] numberParts = phone.split("\\D");
- String telNumber = "";
- for (String number: numberParts) {
- if (number != "") {
- telNumber = telNumber + number;
+ 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 preferred/work phone
numbers
+ continue;
+ }
+ }
+ if (UtilValidate.isNotEmpty(phone)) {
+ String[] numberParts = phone.split("\\D");
+ String telNumber = "";
+ for (String number: numberParts) {
+ if (number != "") {
+ telNumber = telNumber + number;
+ }
}
+ serviceCtx.put("areaCode", telNumber.substring(0,
3));
+ serviceCtx.put("contactNumber",
telNumber.substring(3));
}
- serviceCtx.put("areaCode", telNumber.substring(0, 3));
- serviceCtx.put("contactNumber",
telNumber.substring(3));
+ }
+ }
+ OrganizationalIdentity oid =
contact.getOrganizationalIdentity();
+ // Useful when creating a contact with more than OOTB
+ if (!isGroup) {
+ serviceCtx.put("personalTitle", oid.getTitle());
+ }
+
+ // Needed when creating an account (a PartyGroup)
+ if (isGroup) {
+ //serviceCtx.put("partyRole", oid.getRole()); // not used
yet,maybe useful later
+ if (oid.hasOrganization()) {
+ Organization org = oid.getOrganization();
+ serviceCtx.put("groupName", org.getName());
}
}