public static Organization getOrganization(BusinessDetail bizdetail,
LifeCycleManager lifeCycleManager)
throws JAXRException
{
List<BusinessEntity> bizEntityList = bizdetail.getBusinessEntity();
Organization org = new OrganizationImpl(lifeCycleManager);
if (bizEntityList.size() != 1) {
throw new JAXRException("Unexpected count of organizations in BusinessDetail: " + bizEntityList.size());
}
BusinessEntity entity = bizEntityList.get(0);
List<Name> namesList = entity.getName();
if ((namesList != null) && (namesList.size() > 0)) {
InternationalString is = null;
for (Name n : namesList) {
if (is == null) {
is = getIString(n.getLang(), n.getValue(), lifeCycleManager);
} else {
is.setValue(getLocale(n.getLang()), n.getValue());
}
}
org.setName(is);
}
List<Description> descriptionList = entity.getDescription();
if ((descriptionList != null) && (descriptionList.size() > 0)) {
InternationalString is = null;
for (Description desc : descriptionList) {
if (is == null) {
is = getIString(desc.getLang(), desc.getValue(), lifeCycleManager);
} else {
is.setValue(getLocale(desc.getLang()), desc.getValue());
}
}
org.setDescription(is);
}
org.setKey(lifeCycleManager.createKey(entity.getBusinessKey()));
//Set Services also
BusinessServices services = entity.getBusinessServices();
if (services != null) {
List<BusinessService> bizServiceList = services.getBusinessService();
for (BusinessService businessService : bizServiceList) {
org.addService(getService(businessService, lifeCycleManager));
}
}
/*
* Users
*
* we need to take the first contact and designate as the
* 'primary contact'. Currently, the OrganizationImpl
* class does that automatically as a safety in case
* user forgets to set - lets be explicit here as to not
* depend on that behavior
*/
Contacts contacts = entity.getContacts();
if (contacts != null) {
List<Contact> contactList = contacts.getContact();
boolean isFirst=true;
for (Contact contact : contactList) {
User user = new UserImpl(null);
List<PersonName> pnames = (List<PersonName>) contact.getPersonName();
String pname = null;
if (pnames != null && pnames.size() > 0) {
PersonName personname = pnames.get(0);
pname = personname.getValue();
}
user.setType(contact.getUseType());
user.setPersonName(new PersonNameImpl(pname));
List<Email> emailList = contact.getEmail();
ArrayList<EmailAddress> tempEmails = new ArrayList<EmailAddress>();
for (Email email : emailList) {
tempEmails.add(new EmailAddressImpl(email.getValue(), null));
}
user.setEmailAddresses(tempEmails);
List<Address> addressList = contact.getAddress();
ArrayList<PostalAddress> tempAddresses = new ArrayList<PostalAddress>();
for (Address address : addressList) {
ArrayList<AddressLine> addressLineList = new ArrayList<AddressLine>(address.getAddressLine());
AddressLine[] alines = new AddressLine[addressLineList.size()];
addressLineList.toArray(alines);
PostalAddress pa = getPostalAddress(alines);
tempAddresses.add(pa);
}
user.setPostalAddresses(tempAddresses);
List<Phone> phoneList = contact.getPhone();
ArrayList<TelephoneNumber> tempPhones = new ArrayList<TelephoneNumber>();
for (Phone phone : phoneList) {
TelephoneNumberImpl tni = new TelephoneNumberImpl();
tni.setType(phone.getUseType());
tni.setNumber(phone.getValue());
tempPhones.add(tni);
}
user.setTelephoneNumbers(tempPhones);
if (isFirst) {
isFirst=false;
org.setPrimaryContact(user);
} else {
org.addUser(user);
}
}
}
//External Links
DiscoveryURLs durls = entity.getDiscoveryURLs();
if (durls != null)
{
List<DiscoveryURL> discoveryURL_List = durls.getDiscoveryURL();
for (DiscoveryURL discoveryURL : discoveryURL_List) {
ExternalLink link = new ExternalLinkImpl(lifeCycleManager);
link.setExternalURI(discoveryURL.getValue());
org.addExternalLink(link);
}
}
org.addExternalIdentifiers(getExternalIdentifiers(entity.getIdentifierBag(), lifeCycleManager));
org.addClassifications(getClassifications(entity.getCategoryBag(), lifeCycleManager));
return org;
}