EntityManager em = PersistenceManager.getEntityManager();
EntityTransaction tx = em.getTransaction();
try {
tx.begin();
UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo());
new ValidateCustodyTransfer(publisher).validateTransferEntities(em, body);
// Once validated, the ownership transfer is as simple as switching the publisher
KeyBag keyBag = body.getKeyBag();
List<String> keyList = keyBag.getKey();
for (String key : keyList) {
UddiEntity uddiEntity = em.find(UddiEntity.class, key);
uddiEntity.setAuthorizedName(publisher.getAuthorizedName());
if (uddiEntity instanceof BusinessEntity) {
BusinessEntity be = (BusinessEntity)uddiEntity;
List<BusinessService> bsList = be.getBusinessServices();
for (BusinessService bs : bsList) {
bs.setAuthorizedName(publisher.getAuthorizedName());
List<BindingTemplate> btList = bs.getBindingTemplates();
for (BindingTemplate bt : btList)
bt.setAuthorizedName(publisher.getAuthorizedName());
}
}
}
// After transfer is finished, the token can be removed