if ((uploadRegVector != null) && (uploadRegVector.size() > 0))
throw new UnsupportedException("Saving BusinessEntities via " +
"UploadRegistry is not supported.");
// aquire a jUDDI datastore instance
DataStore dataStore = DataStoreFactory.getDataStore();
try
{
dataStore.beginTrans();
// validate authentication parameters
Publisher publisher = getPublisher(authInfo,dataStore);
String publisherID = publisher.getPublisherID();
String authorizedName = publisher.getName();
// validate request parameters & execute
for (int i=0; i<businessVector.size(); i++)
{
// move the BusinessEntity into a form we can work with easily
BusinessEntity business = (BusinessEntity)businessVector.elementAt(i);
String businessKey = business.getBusinessKey();
// If a BusinessKey was specified then make sure it's a valid one.
if ((businessKey != null) && (businessKey.length() > 0) && (!dataStore.isValidBusinessKey(businessKey)))
throw new InvalidKeyPassedException("businessKey="+businessKey);
// If a BusinessKey was specified then make sure 'publisherID' controls it.
if ((businessKey != null) && (businessKey.length() > 0) && (!dataStore.isBusinessPublisher(businessKey,publisherID)))
throw new UserMismatchException("businessKey="+businessKey);
}
for (int i=0; i<businessVector.size(); i++)
{
// move the BusinessEntity into a form we can work with easily
BusinessEntity business = (BusinessEntity)businessVector.elementAt(i);
String businessKey = business.getBusinessKey();
// If the new BusinessEntity has a BusinessKey then it must already
// exists so delete the old one. It a BusinessKey isn't specified then
// this is a new BusinessEntity so create a new BusinessKey for it.
if ((businessKey != null) && (businessKey.length() > 0))
{
dataStore.deleteBusiness(businessKey);
}
else
{
business.setBusinessKey(uuidgen.uuidgen());
}
// check if the business has DiscoveryURL with
// useType as 'businessEntity' if not create one
// and add it to the business object.
addBusinessEntityDiscoveryURL(business);
// Everything checks out so let's save it. First
// store 'authorizedName' and 'operator' values
// in each BusinessEntity.
business.setAuthorizedName(authorizedName);
business.setOperator(Config.getOperator());
// If no contacts were specified with the Business
// Entity then add a new contact of type 'publisher'
// using the publishers information.
Contacts contacts = business.getContacts();
if ((contacts == null) ||
(contacts.getContactVector() == null) ||
(contacts.getContactVector().isEmpty()))
{
Contact contact = new Contact();
contact.setPersonNameValue(publisher.getName());
contact.setUseType("publisher");
String workPhone = publisher.getWorkPhone();
if (workPhone != null)
contact.addPhone(new Phone(workPhone,"business"));
String mobile = publisher.getMobilePhone();
if (mobile != null)
contact.addPhone(new Phone(mobile,"mobile"));
String pager = publisher.getPager();
if (pager != null)
contact.addPhone(new Phone(pager,"pager"));
String email = publisher.getEmailAddress();
if (email != null)
contact.addEmail(new Email(email,"email"));
business.addContact(contact);
}
dataStore.saveBusiness(business,publisherID);
}
dataStore.commit();
BusinessDetail detail = new BusinessDetail();
detail.setGeneric(generic);
detail.setOperator(Config.getOperator());
detail.setTruncated(false);
detail.setBusinessEntityVector(businessVector);
return detail;
}
catch(UnsupportedException suppex)
{
try { dataStore.rollback(); } catch(Exception e) { }
log.info(suppex);
throw (RegistryException)suppex;
}
catch(InvalidKeyPassedException ikpex)
{
try { dataStore.rollback(); } catch(Exception e) { }
log.info(ikpex);
throw (RegistryException)ikpex;
}
catch(UserMismatchException umex)
{
try { dataStore.rollback(); } catch(Exception e) { }
log.info(umex);
throw (RegistryException)umex;
}
catch(RegistryException regex)
{
try { dataStore.rollback(); } catch(Exception e) { }
log.error(regex);
throw (RegistryException)regex;
}
catch(Exception ex)
{
try { dataStore.rollback(); } catch(Exception e) { }
log.error(ex);
throw new RegistryException(ex);
}
finally
{
if (dataStore != null)
dataStore.release();
}
}