SCOUT-54, Applying patch by Tom Cunningham to fix empty addressing info coming back for the Primary Conteact
git-svn-id: https://svn.apache.org/repos/asf/webservices/scout/trunk@634334 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scout/src/main/java/org/apache/ws/scout/util/ScoutUddiJaxrHelper.java b/scout/src/main/java/org/apache/ws/scout/util/ScoutUddiJaxrHelper.java
index dbe629f..3408058 100644
--- a/scout/src/main/java/org/apache/ws/scout/util/ScoutUddiJaxrHelper.java
+++ b/scout/src/main/java/org/apache/ws/scout/util/ScoutUddiJaxrHelper.java
@@ -18,6 +18,7 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.Locale;
import javax.xml.registry.JAXRException;
@@ -26,30 +27,38 @@
import javax.xml.registry.infomodel.Classification;
import javax.xml.registry.infomodel.ClassificationScheme;
import javax.xml.registry.infomodel.Concept;
+import javax.xml.registry.infomodel.EmailAddress;
import javax.xml.registry.infomodel.ExternalIdentifier;
import javax.xml.registry.infomodel.ExternalLink;
import javax.xml.registry.infomodel.InternationalString;
import javax.xml.registry.infomodel.Organization;
+import javax.xml.registry.infomodel.PostalAddress;
import javax.xml.registry.infomodel.RegistryObject;
import javax.xml.registry.infomodel.Service;
import javax.xml.registry.infomodel.ServiceBinding;
+import javax.xml.registry.infomodel.TelephoneNumber;
import javax.xml.registry.infomodel.User;
import org.apache.ws.scout.registry.infomodel.AssociationImpl;
import org.apache.ws.scout.registry.infomodel.ClassificationImpl;
import org.apache.ws.scout.registry.infomodel.ClassificationSchemeImpl;
import org.apache.ws.scout.registry.infomodel.ConceptImpl;
+import org.apache.ws.scout.registry.infomodel.EmailAddressImpl;
import org.apache.ws.scout.registry.infomodel.ExternalIdentifierImpl;
import org.apache.ws.scout.registry.infomodel.ExternalLinkImpl;
import org.apache.ws.scout.registry.infomodel.InternationalStringImpl;
import org.apache.ws.scout.registry.infomodel.KeyImpl;
import org.apache.ws.scout.registry.infomodel.OrganizationImpl;
import org.apache.ws.scout.registry.infomodel.PersonNameImpl;
+import org.apache.ws.scout.registry.infomodel.PostalAddressImpl;
import org.apache.ws.scout.registry.infomodel.ServiceBindingImpl;
import org.apache.ws.scout.registry.infomodel.ServiceImpl;
import org.apache.ws.scout.registry.infomodel.SpecificationLinkImpl;
+import org.apache.ws.scout.registry.infomodel.TelephoneNumberImpl;
import org.apache.ws.scout.registry.infomodel.UserImpl;
import org.apache.ws.scout.uddi.AccessPoint;
+import org.apache.ws.scout.uddi.Address;
+import org.apache.ws.scout.uddi.AddressLine;
import org.apache.ws.scout.uddi.BindingTemplate;
import org.apache.ws.scout.uddi.BindingTemplates;
import org.apache.ws.scout.uddi.BusinessDetail;
@@ -62,12 +71,14 @@
import org.apache.ws.scout.uddi.Description;
import org.apache.ws.scout.uddi.DiscoveryURL;
import org.apache.ws.scout.uddi.DiscoveryURLs;
+import org.apache.ws.scout.uddi.Email;
import org.apache.ws.scout.uddi.HostingRedirector;
import org.apache.ws.scout.uddi.IdentifierBag;
import org.apache.ws.scout.uddi.InstanceDetails;
import org.apache.ws.scout.uddi.KeyedReference;
import org.apache.ws.scout.uddi.Name;
import org.apache.ws.scout.uddi.OverviewDoc;
+import org.apache.ws.scout.uddi.Phone;
import org.apache.ws.scout.uddi.ServiceInfo;
import org.apache.ws.scout.uddi.TModel;
import org.apache.ws.scout.uddi.TModelDetail;
@@ -141,7 +152,6 @@
User user = new UserImpl(null);
String pname = contact.getPersonName();
user.setPersonName(new PersonNameImpl(pname));
-
if (i == 0)
{
org.setPrimaryContact(user);
@@ -223,7 +233,33 @@
String pname = contact.getPersonName();
user.setType(contact.getUseType());
user.setPersonName(new PersonNameImpl(pname));
+
+ Email[] emails = (Email[]) contact.getEmailArray();
+ ArrayList<EmailAddress> tempEmails = new ArrayList<EmailAddress>();
+ for (int x = 0; x < emails.length; x++) {
+ tempEmails.add(new EmailAddressImpl(emails[x].getStringValue(), null));
+ }
+ user.setEmailAddresses(tempEmails);
+
+ Address[] addresses = (Address[]) contact.getAddressArray();
+ ArrayList<PostalAddress> tempAddresses = new ArrayList<PostalAddress>();
+ for (int x = 0; x < addresses.length; x++) {
+ AddressLine[] alines = addresses[x].getAddressLineArray();
+ PostalAddress pa = getPostalAddress(alines);
+ tempAddresses.add(pa);
+ }
+ user.setPostalAddresses(tempAddresses);
+ Phone[] phones = contact.getPhoneArray();
+ ArrayList<TelephoneNumber> tempPhones = new ArrayList<TelephoneNumber>();
+ for (int x = 0; x < phones.length; x++) {
+ TelephoneNumberImpl tni = new TelephoneNumberImpl();
+ tni.setType(phones[x].getUseType());
+ tni.setNumber(phones[x].getStringValue());
+ tempPhones.add(tni);
+ }
+ user.setTelephoneNumbers(tempPhones);
+
if (i == 0)
{
org.setPrimaryContact(user);
@@ -254,6 +290,40 @@
return org;
}
+ private static PostalAddress getPostalAddress(AddressLine[] al) throws JAXRException {
+ PostalAddress pa = new PostalAddressImpl();
+ HashMap<String, String> hm = new HashMap<String, String>();
+ for (int y = 0; y < al.length; y++) {
+ hm.put(al[y].getKeyName(), al[y].getKeyValue());
+ }
+
+ if (hm.containsKey("STREET_NUMBER")) {
+ pa.setStreetNumber(hm.get("STREET_NUMBER"));
+ }
+
+ if (hm.containsKey("STREET")) {
+ pa.setStreet(hm.get("STREET"));
+ }
+
+ if (hm.containsKey("CITY")) {
+ pa.setCity(hm.get("CITY"));
+ }
+
+ if (hm.containsKey("COUNTRY")) {
+ pa.setCountry(hm.get("COUNTRY"));
+ }
+
+ if (hm.containsKey("POSTALCODE")) {
+ pa.setPostalCode(hm.get("POSTALCODE"));
+ }
+
+ if (hm.containsKey("STATE")) {
+ pa.setStateOrProvince(hm.get("STATE"));
+ }
+
+ return pa;
+ }
+
private static InternationalString getIString(String lang, String str, LifeCycleManager blm)
throws JAXRException
{
diff --git a/scout/src/test/java/org/apache/ws/scout/registry/qa/JAXR015PrimaryContactTest.java b/scout/src/test/java/org/apache/ws/scout/registry/qa/JAXR015PrimaryContactTest.java
new file mode 100644
index 0000000..38c19b3
--- /dev/null
+++ b/scout/src/test/java/org/apache/ws/scout/registry/qa/JAXR015PrimaryContactTest.java
@@ -0,0 +1,312 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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.apache.ws.scout.registry.qa;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+
+import javax.xml.registry.BulkResponse;
+import javax.xml.registry.JAXRException;
+import javax.xml.registry.JAXRResponse;
+import javax.xml.registry.RegistryService;
+import javax.xml.registry.infomodel.Classification;
+import javax.xml.registry.infomodel.ClassificationScheme;
+import javax.xml.registry.infomodel.EmailAddress;
+import javax.xml.registry.infomodel.Key;
+import javax.xml.registry.infomodel.Organization;
+import javax.xml.registry.infomodel.PersonName;
+import javax.xml.registry.infomodel.PostalAddress;
+import javax.xml.registry.infomodel.Service;
+import javax.xml.registry.infomodel.ServiceBinding;
+import javax.xml.registry.infomodel.TelephoneNumber;
+import javax.xml.registry.infomodel.User;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.apache.ws.scout.BaseTestCase;
+import org.apache.ws.scout.Creator;
+import org.apache.ws.scout.Finder;
+import org.apache.ws.scout.Printer;
+import org.apache.ws.scout.Remover;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test to check that the primary contact is added
+ * @author <a href="mailto:tcunning@redhat.com">Tom Cunningham</a>
+ * @since Dec 6, 2007
+ */
+public class JAXR015PrimaryContactTest extends BaseTestCase
+{
+ private static final String PERSON_NAME = "John AXel Rose";
+ private static final String PHONE_NUMBER = "111-222-3333";
+ private static final String STREET_NUMBER = "1";
+ private static final String STREET = "Uddi Drive";
+ private static final String CITY = "Apache Town";
+ private static final String STATE = "CA";
+ private static final String COUNTRY = "USA";
+ private static final String POSTAL_CODE = "00000-1111";
+
+ private static final String EMAIL = "jaxr@apache.org";
+
+ @Before
+ public void setUp()
+ {
+ super.setUp();
+ }
+
+ @After
+ public void tearDown()
+ {
+ super.tearDown();
+ }
+
+ @Test
+ public void publishClassificationScheme()
+ {
+ login();
+ try
+ {
+ RegistryService rs = connection.getRegistryService();
+ blm = rs.getBusinessLifeCycleManager();
+ Creator creator = new Creator(blm);
+
+ Collection<ClassificationScheme> schemes = new ArrayList<ClassificationScheme>();
+ ClassificationScheme classificationScheme = creator.createClassificationScheme(this.getClass().getName());
+ schemes.add(classificationScheme);
+
+ BulkResponse bulkResponse = blm.saveClassificationSchemes(schemes);
+ assertEquals(JAXRResponse.STATUS_SUCCESS,bulkResponse.getStatus());
+
+
+ } catch (JAXRException e) {
+ e.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+ @Test
+ public void publishOrganization()
+ {
+ BulkResponse response = null;
+ login();
+ try
+ {
+ RegistryService rs = connection.getRegistryService();
+ blm = rs.getBusinessLifeCycleManager();
+ bqm = rs.getBusinessQueryManager();
+ Creator creator = new Creator(blm);
+ Finder finder = new Finder(bqm);
+
+ Collection<Organization> orgs = new ArrayList<Organization>();
+ Organization organization = creator.createOrganization(this.getClass().getName());
+// Add a Service
+ Service service = creator.createService(this.getClass().getName());
+ ServiceBinding serviceBinding = creator.createServiceBinding();
+ service.addServiceBinding(serviceBinding);
+ organization.addService(service);
+ //Add a classification
+ ClassificationScheme cs = finder.findClassificationSchemeByName(this.getClass().getName());
+ Classification classification = creator.createClassification(cs);
+ organization.addClassification(classification);
+
+ User user = blm.createUser();
+ PersonName personName = blm.createPersonName(PERSON_NAME);
+ TelephoneNumber telephoneNumber = blm.createTelephoneNumber();
+ telephoneNumber.setNumber(PHONE_NUMBER);
+ telephoneNumber.setType(null);
+ PostalAddress address = blm.createPostalAddress(STREET_NUMBER,
+ STREET, CITY, STATE, COUNTRY, POSTAL_CODE, "");
+
+ Collection<PostalAddress> postalAddresses = new ArrayList<PostalAddress>();
+ postalAddresses.add(address);
+ Collection<EmailAddress> emailAddresses = new ArrayList<EmailAddress>();
+ EmailAddress emailAddress = blm.createEmailAddress(EMAIL);
+ emailAddresses.add(emailAddress);
+
+ Collection<TelephoneNumber> numbers = new ArrayList<TelephoneNumber>();
+ numbers.add(telephoneNumber);
+ user.setPersonName(personName);
+ user.setPostalAddresses(postalAddresses);
+ user.setEmailAddresses(emailAddresses);
+ user.setTelephoneNumbers(numbers);
+ organization.setPrimaryContact(user);
+
+ orgs.add(organization);
+
+ //Now save the Organization along with a Service, ServiceBinding and Classification
+ BulkResponse br = blm.saveOrganizations(orgs);
+ if (br.getStatus() == JAXRResponse.STATUS_SUCCESS)
+ {
+ System.out.println("Organization Saved");
+ Collection coll = br.getCollection();
+ Iterator iter = coll.iterator();
+ while (iter.hasNext())
+ {
+ Key key = (Key) iter.next();
+ System.out.println("Saved Key=" + key.getId());
+ }//end while
+ } else
+ {
+ System.err.println("JAXRExceptions " +
+ "occurred during save:");
+ Collection exceptions = br.getExceptions();
+ Iterator iter = exceptions.iterator();
+ while (iter.hasNext())
+ {
+ Exception e = (Exception) iter.next();
+ System.err.println(e.toString());
+ }
+ }
+
+ } catch (JAXRException e) {
+ e.printStackTrace();
+ assertTrue(false);
+ }
+ assertNull(response);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void queryOrganization()
+ {
+ login();
+ try
+ {
+ // Get registry service and business query manager
+ RegistryService rs = connection.getRegistryService();
+ bqm = rs.getBusinessQueryManager();
+ System.out.println("We have the Business Query Manager");
+ Printer printer = new Printer();
+ Finder finder = new Finder(bqm);
+
+ Collection orgs = finder.findOrganizationsByName(this.getClass().getName());
+ if (orgs == null) {
+ fail("Only Expecting 1 Organization");
+ } else {
+ assertEquals(1,orgs.size());
+ // then step through them
+ for (Iterator orgIter = orgs.iterator(); orgIter.hasNext();)
+ {
+ Organization org = (Organization) orgIter.next();
+ System.out.println("Org name: " + printer.getName(org));
+ System.out.println("Org description: " + printer.getDescription(org));
+ System.out.println("Org key id: " + printer.getKey(org));
+
+ User user = org.getPrimaryContact();
+ System.out.println("Primary Contact Full Name : " + user.getPersonName().getFullName());
+ assertEquals("User name does not match", user.getPersonName().getFullName(), PERSON_NAME);
+
+ Collection<EmailAddress> emailAddresses = user.getEmailAddresses();
+ System.out.println("Found " + emailAddresses.size() + " email addresses.");
+ assertEquals("Should have found 1 email address, found " + emailAddresses.size(), 1, emailAddresses.size());
+ for (EmailAddress email : emailAddresses) {
+ System.out.println("Primary Contact email : " + email.getAddress());
+ assertEquals("Email should be " + EMAIL, EMAIL, email.getAddress());
+ }
+
+ Collection<PostalAddress> postalAddresses = user.getPostalAddresses();
+ System.out.println("Found " + postalAddresses.size() + " postal addresses.");
+ assertEquals("Should have found 1 postal address, found " + postalAddresses.size(), 1, postalAddresses.size());
+ for (PostalAddress postalAddress : postalAddresses) {
+ System.out.println("Postal Address is " + postalAddress);
+ assertEquals("Street number should be " + STREET_NUMBER, STREET_NUMBER, postalAddress.getStreetNumber());
+ assertEquals("Street should be " + STREET, STREET, postalAddress.getStreet());
+ assertEquals("City should be " + CITY, CITY, postalAddress.getCity());
+ assertEquals("State should be " + STATE, STATE, postalAddress.getStateOrProvince());
+ assertEquals("Country should be " + COUNTRY, COUNTRY, postalAddress.getCountry());
+ assertEquals("Postal code should be " + POSTAL_CODE, POSTAL_CODE, postalAddress.getPostalCode());
+ }
+
+ Collection<TelephoneNumber> numbers = user.getTelephoneNumbers(null);
+ System.out.println("Found " + numbers.size() + " telephone numbers.");
+ assertEquals("Should have found 1 phone number, found " + numbers.size(), 1, numbers.size());
+ for (TelephoneNumber tele : numbers) {
+ System.out.println("Phone number is " + tele.getNumber());
+ assertEquals("Telephone number should be " + PHONE_NUMBER, PHONE_NUMBER, tele.getNumber());
+ }
+ printer.printServices(org);
+ printer.printClassifications(org);
+ }
+ }//end else
+ } catch (JAXRException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ @Test
+ public void deleteOrganization()
+ {
+ login();
+ try
+ {
+ RegistryService rs = connection.getRegistryService();
+ blm = rs.getBusinessLifeCycleManager();
+ // Get registry service and business query manager
+ bqm = rs.getBusinessQueryManager();
+ System.out.println("We have the Business Query Manager");
+ Finder finder = new Finder(bqm);
+ Remover remover = new Remover(blm);
+ Collection orgs = finder.findOrganizationsByName(this.getClass().getName());
+ for (Iterator orgIter = orgs.iterator(); orgIter.hasNext();)
+ {
+ Organization org = (Organization) orgIter.next();
+ remover.removeOrganization(org);
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ @Test
+ public void deleteClassificationScheme()
+ {
+ login();
+ try {
+ RegistryService rs = connection.getRegistryService();
+ bqm = rs.getBusinessQueryManager();
+ blm = rs.getBusinessLifeCycleManager();
+ System.out.println("We have the Business Query Manager");
+ Finder finder = new Finder(bqm);
+ Remover remover = new Remover(blm);
+ Collection schemes = finder.findClassificationSchemesByName(this.getClass().getName());
+ for (Iterator iter = schemes.iterator(); iter.hasNext();)
+ {
+ ClassificationScheme scheme = (ClassificationScheme) iter.next();
+ remover.removeClassificationScheme(scheme);
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ public static junit.framework.Test suite() {
+ return new JUnit4TestAdapter(JAXR015PrimaryContactTest.class);
+ }
+}