EntityManager em = PersistenceManager.getEntityManager();
EntityTransaction tx = em.getTransaction();
try {
tx.begin();
UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo());
new ValidatePublish(publisher).validateAddPublisherAssertions(em, body);
List<org.uddi.api_v3.PublisherAssertion> apiPubAssertionList = body.getPublisherAssertion();
for (org.uddi.api_v3.PublisherAssertion apiPubAssertion : apiPubAssertionList) {
org.apache.juddi.model.PublisherAssertion modelPubAssertion = new org.apache.juddi.model.PublisherAssertion();
MappingApiToModel.mapPublisherAssertion(apiPubAssertion, modelPubAssertion);
org.apache.juddi.model.PublisherAssertion existingPubAssertion = em.find(modelPubAssertion.getClass(), modelPubAssertion.getId());
boolean persistNewAssertion = true;
if (existingPubAssertion != null) {
if (modelPubAssertion.getTmodelKey().equalsIgnoreCase(existingPubAssertion.getTmodelKey()) &&
modelPubAssertion.getKeyName().equalsIgnoreCase(existingPubAssertion.getKeyName()) &&
modelPubAssertion.getKeyValue().equalsIgnoreCase(existingPubAssertion.getKeyValue())) {
// This pub assertion is already been "asserted". Simply need to set the "check" value on the existing (and persistent) assertion
if (publisher.isOwner(existingPubAssertion.getBusinessEntityByFromKey()))
existingPubAssertion.setFromCheck("true");
if (publisher.isOwner(existingPubAssertion.getBusinessEntityByToKey()))
existingPubAssertion.setToCheck("true");
persistNewAssertion = false;
}
else {
// Otherwise, it is a new relationship between these entities. Remove the old one so the new one can be added.
// TODO: the model only seems to allow one assertion per two business (primary key is fromKey and toKey). Spec seems to imply as
// many relationships as desired (the differentiator would be the keyedRef values).
em.remove(existingPubAssertion);
}
}
if (persistNewAssertion) {
org.apache.juddi.model.BusinessEntity beFrom = em.find(org.apache.juddi.model.BusinessEntity.class, modelPubAssertion.getId().getFromKey());
org.apache.juddi.model.BusinessEntity beTo = em.find(org.apache.juddi.model.BusinessEntity.class, modelPubAssertion.getId().getToKey());
modelPubAssertion.setBusinessEntityByFromKey(beFrom);
modelPubAssertion.setBusinessEntityByToKey(beTo);
modelPubAssertion.setFromCheck("false");
modelPubAssertion.setToCheck("false");
em.persist(modelPubAssertion);
if (publisher.isOwner(modelPubAssertion.getBusinessEntityByFromKey()))
modelPubAssertion.setFromCheck("true");
if (publisher.isOwner(modelPubAssertion.getBusinessEntityByToKey()))
modelPubAssertion.setToCheck("true");
}
}