List<Description> descriptionList = entity.getDescription();
Description desc =null;
if (descriptionList.size()>0) desc = descriptionList.get(0);
Organization org = new OrganizationImpl(lifeCycleManager);
if( n != null ) {
org.setName(getIString(n.getLang(), n.getValue(), lifeCycleManager));
}
if( desc != null ) {
org.setDescription(getIString(desc.getLang(), desc.getValue(), lifeCycleManager));
}
org.setKey(lifeCycleManager.createKey(entity.getBusinessKey()));
//Set Services also
BusinessServices services = entity.getBusinessServices();
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();
List<Contact> contactList = contacts.getContact();
boolean isFirst=true;
for (Contact contact : contactList) {
User user = new UserImpl(null);
String pname = contact.getPersonName();
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;
}