Skip to content
Permalink
Browse files
JUDDI-913 fixed and tested
  • Loading branch information
spyhunter99 committed Jan 19, 2015
1 parent ba85baa commit 2ba82c8ea43ed7e405dda8f4e3894d109ab89ca8
Showing 6 changed files with 199 additions and 84 deletions.
@@ -25,6 +25,7 @@
import javax.jws.WebService;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.Query;
import javax.xml.bind.JAXB;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
@@ -43,9 +44,9 @@
import org.apache.juddi.model.BusinessEntity;
import org.apache.juddi.model.BusinessService;
import org.apache.juddi.model.ChangeRecord;
import org.apache.juddi.model.Signature;
import org.apache.juddi.model.Tmodel;
import org.apache.juddi.model.UddiEntityPublisher;
import org.apache.juddi.query.DeletePublisherAssertionByBusinessQuery;
import org.apache.juddi.query.FetchBusinessEntitiesQuery;
import org.apache.juddi.query.FetchTModelsQuery;
import org.apache.juddi.query.FindBusinessByPublisherQuery;
@@ -156,6 +157,9 @@ public void addPublisherAssertions(AddPublisherAssertions body)
if (publisher.isOwner(existingPubAssertion.getBusinessEntityByToKey())) {
existingPubAssertion.setToCheck("true");
}
//it's also possible that the signatures have changed
removeExistingPublisherAssertionSignatures(existingPubAssertion.getBusinessEntityByFromKey().getEntityKey(), existingPubAssertion.getBusinessEntityByToKey().getEntityKey(), em);
savePushliserAssertionSignatures(existingPubAssertion.getBusinessEntityByFromKey().getEntityKey(), existingPubAssertion.getBusinessEntityByToKey().getEntityKey(), modelPubAssertion.getSignatures(), em);

em.merge(existingPubAssertion);
persistNewAssertion = false;
@@ -164,6 +168,7 @@ public void addPublisherAssertions(AddPublisherAssertions body)
// 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).
removeExistingPublisherAssertionSignatures(existingPubAssertion.getBusinessEntityByFromKey().getEntityKey(), existingPubAssertion.getBusinessEntityByToKey().getEntityKey(), em);
em.remove(existingPubAssertion);
changes.add(getChangeRecord_deletePublisherAssertion(apiPubAssertion, node, true, true, System.currentTimeMillis()));
}
@@ -185,6 +190,8 @@ public void addPublisherAssertions(AddPublisherAssertions body)
modelPubAssertion.setToCheck("true");
}
modelPubAssertion.setModified(new Date());
savePushliserAssertionSignatures(modelPubAssertion.getBusinessEntityByFromKey().getEntityKey(), modelPubAssertion.getBusinessEntityByToKey().getEntityKey(), modelPubAssertion.getSignatures(), em);

em.persist(modelPubAssertion);

changes.add(getChangeRecord_NewAssertion(apiPubAssertion, modelPubAssertion, node));
@@ -359,9 +366,15 @@ public void deletePublisherAssertions(DeletePublisherAssertions body)
}
if ("false".equalsIgnoreCase(existingPubAssertion.getToCheck())
&& "false".equalsIgnoreCase(existingPubAssertion.getFromCheck())) {
logger.info("Publisher assertion updated database via replication");
removeExistingPublisherAssertionSignatures(existingPubAssertion.getBusinessEntityByFromKey().getEntityKey(), existingPubAssertion.getBusinessEntityByToKey().getEntityKey(), em);
em.remove(existingPubAssertion);
} else {
existingPubAssertion.setModified(new Date());
logger.info("Publisher assertion updated database via replication");
removeExistingPublisherAssertionSignatures(existingPubAssertion.getBusinessEntityByFromKey().getEntityKey(), existingPubAssertion.getBusinessEntityByToKey().getEntityKey(), em);
savePushliserAssertionSignatures(existingPubAssertion.getBusinessEntityByFromKey().getEntityKey(),
existingPubAssertion.getBusinessEntityByToKey().getEntityKey(), modelPubAssertion.getSignatures(), em);
em.persist(existingPubAssertion);
}

@@ -419,11 +432,15 @@ protected void deletePublisherAssertion(org.uddi.repl_v3.ChangeRecordDeleteAsser
}
if ("false".equalsIgnoreCase(existingPubAssertion.getToCheck())
&& "false".equalsIgnoreCase(existingPubAssertion.getFromCheck())) {
logger.info("!!!Deletion of publisher assertion from database via replication");
logger.info("Deletion of publisher assertion from database via replication");
removeExistingPublisherAssertionSignatures(existingPubAssertion.getBusinessEntityByFromKey().getEntityKey(), existingPubAssertion.getBusinessEntityByToKey().getEntityKey(), em);
em.remove(existingPubAssertion);
} else {
existingPubAssertion.setModified(new Date());
logger.info("!!!Publisher assertion update database via replication");
logger.info("Publisher assertion updated database via replication");
removeExistingPublisherAssertionSignatures(existingPubAssertion.getBusinessEntityByFromKey().getEntityKey(), existingPubAssertion.getBusinessEntityByToKey().getEntityKey(), em);
savePushliserAssertionSignatures(existingPubAssertion.getBusinessEntityByFromKey().getEntityKey(),
existingPubAssertion.getBusinessEntityByToKey().getEntityKey(), modelPubAssertion.getSignatures(), em);
em.persist(existingPubAssertion);
}

@@ -927,7 +944,7 @@ public TModelDetail saveTModel(SaveTModel body)
List<ChangeRecord> changes = new ArrayList<ChangeRecord>();
for (org.uddi.api_v3.TModel apiTModel : apiTModelList) {

// Object obj=em.find( org.apache.juddi.model.Tmodel.class, apiTModel.getTModelKey());
// Object obj=em.find( org.apache.juddi.model.Tmodel.class, apiTModel.getTModelKey());
//just making changes to an existing tModel, no worries
org.apache.juddi.model.Tmodel modelTModel = new org.apache.juddi.model.Tmodel();

@@ -940,14 +957,14 @@ public TModelDetail saveTModel(SaveTModel body)
result.getTModel().add(apiTModel);
changes.add(getChangeRecord(modelTModel, apiTModel, node));
/*
//TODO JUDDI-915
if (obj != null) {
//TODO JUDDI-915
if (obj != null) {
changes.add(getChangeRecord(modelTModel, apiTModel, node));
} else {
//special case for replication, must setup a new data conditional change record
changes.add(getChangeRecordConditional(modelTModel, apiTModel, node));
}*/
changes.add(getChangeRecord(modelTModel, apiTModel, node));
} else {
//special case for replication, must setup a new data conditional change record
changes.add(getChangeRecordConditional(modelTModel, apiTModel, node));
}*/

}

@@ -1574,4 +1591,22 @@ private static ChangeRecord getChangeRecordConditional(Tmodel modelTModel, TMode
return cr;
}

private void removeExistingPublisherAssertionSignatures(String from, String to, EntityManager em) {
Query createQuery = em.createQuery("delete from Signature pa where pa.publisherAssertionFromKey=:from and pa.publisherAssertionToKey=:to");
createQuery.setParameter("from", from);
createQuery.setParameter("to", to);
createQuery.executeUpdate();
}

private void savePushliserAssertionSignatures(String from, String to, List<Signature> signatures, EntityManager em) {
if (signatures == null) {
return;
}
for (Signature s : signatures) {
s.setPublisherAssertionFromKey(from);
s.setPublisherAssertionToKey(to);
em.persist(s);
}
}

}
@@ -1004,10 +1004,14 @@ public static void mapPublisherAssertion(org.uddi.api_v3.PublisherAssertion apiP
}
if (!apiPubAssertion.getSignature().isEmpty())
{
/* modelPubAssertion.setSignatures(mapApiSignaturesToModelSignatures(apiPubAssertion.getSignature()));
modelPubAssertion.setSignatures(mapApiSignaturesToModelSignatures(apiPubAssertion.getSignature()));
for (Signature s : modelPubAssertion.getSignatures())
s.setPublisherAssertion(modelPubAssertion);
*/
{ s.setPublisherAssertionFromKey(modelPubAssertion.getBusinessEntityByFromKey().getEntityKey());
s.setPublisherAssertionToKey(modelPubAssertion.getBusinessEntityByToKey().getEntityKey());

}


}
}

@@ -1018,11 +1018,11 @@ public static void mapPublisherAssertion(org.apache.juddi.model.PublisherAsserti
keyedRef.setKeyName(modelPublisherAssertion.getKeyName());
keyedRef.setKeyValue(modelPublisherAssertion.getKeyValue());

/* if (modelPublisherAssertion.getSignatures()!=null &&
if (modelPublisherAssertion.getSignatures()!=null &&
!modelPublisherAssertion.getSignatures().isEmpty())
{
mapSignature(modelPublisherAssertion.getSignatures(), apiPublisherAssertion.getSignature());
}*/
}
apiPublisherAssertion.setKeyedReference(keyedRef);

}
@@ -28,7 +28,6 @@
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
@@ -95,6 +94,8 @@ public PublisherAssertionId getId() {
public void setId(PublisherAssertionId id) {
this.id = id;
}


@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "to_key", nullable = false, insertable = false, updatable = false)

@@ -170,13 +171,15 @@ public boolean equals(Object compareto){
return (this.id.equals(rhs.id));
}

/*

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
public List<Signature> getSignatures() {
if (signatures==null)
signatures=new ArrayList<Signature>();
return signatures;
}

public void setSignatures(List<Signature> signatures) {
this.signatures = signatures;
}*/
}
}
@@ -24,7 +24,6 @@
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
@@ -50,7 +49,8 @@ public class Signature implements java.io.Serializable {
private ReplicationConfiguration replConfig;
private Tmodel tmodel;
private String xmlID;
private PublisherAssertion assertion;
private String assertionFromKey;
private String assertionToKey;

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@@ -72,18 +72,23 @@ public void setBindingTemplate(BindingTemplate bindingTemplate) {
this.bindingTemplate = bindingTemplate;
}

/*@ManyToOne
@JoinColumns({
@JoinColumn(name = "fromKey", nullable = true),
@JoinColumn(name = "toKey", nullable = true)
})
public PublisherAssertion getPublisherAssertion() {
return assertion;
}
public void setPublisherAssertion(PublisherAssertion item) {
this.assertion = item;
}*/


@Column(nullable = true, length = 255, name = "passertionfrom")
public String getPublisherAssertionFromKey() {
return assertionFromKey;
}

public void setPublisherAssertionFromKey(String item) {
this.assertionFromKey = item;
}
@Column(nullable = true, length = 255, name = "passertionto")
public String getPublisherAssertionToKey() {
return assertionFromKey;
}
public void setPublisherAssertionToKey(String item) {
this.assertionToKey = item;
}


@ManyToOne

0 comments on commit 2ba82c8

Please sign in to comment.