Name n = namearr != null && namearr.length > 0 ? namearr[0] : null;
String name = n != null ? n.getStringValue(): null;
Description[] descarr = entity.getDescriptionArray();
Description desc = descarr != null && descarr.length > 0 ? descarr[0] : null;
Organization org = new OrganizationImpl(lcm);
if( name != null ) {
org.setName(getIString(n.getLang(), name, lcm));
}
if( desc != null ) {
org.setDescription(getIString(desc.getLang(), desc.getStringValue(), lcm));
}
org.setKey(lcm.createKey(entity.getBusinessKey()));
//Set Services also
BusinessServices services = entity.getBusinessServices();
BusinessService[] sarr = services != null ? services.getBusinessServiceArray() : null;
for (int i = 0; sarr != null && i < sarr.length; i++)
{
BusinessService s = (BusinessService)sarr[i];
org.addService(getService(s, lcm));
}
/*
* 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();
Contact[] carr = contacts != null ? contacts.getContactArray():null;
for (int i = 0; carr != null && i < carr.length; i++)
{
Contact contact = carr[i];
User user = new UserImpl(null);
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);
}
else
{
org.addUser(user);
}
}
//External Links
DiscoveryURLs durls = entity.getDiscoveryURLs();
if (durls != null)
{
DiscoveryURL[] darr = durls.getDiscoveryURLArray();
for (int j = 0; darr != null && j < darr.length; j++)
{
DiscoveryURL durl = darr[j];
ExternalLink link = new ExternalLinkImpl(lcm);
link.setExternalURI(durl.getStringValue());
org.addExternalLink(link);
}
}
org.addExternalIdentifiers(getExternalIdentifiers(entity.getIdentifierBag(), lcm));
org.addClassifications(getClassifications(entity.getCategoryBag(), lcm));
return org;
}