Skip to content
Permalink
Browse files
JUDDI-992 fix for several issues with find binding with and without t…
…he service key. Also had to do some light refactoring of List<?> to List<Object> for many of the apis in juddi-core. Shouldn't effect too many users.
  • Loading branch information
spyhunter99 committed Nov 18, 2018
1 parent 926428d commit 2f5a2492e49a64da73e29bc5ba0a8bf151b49bdb
Showing 31 changed files with 239 additions and 102 deletions.
@@ -18,9 +18,8 @@

import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.persistence.EntityManager;
import javax.xml.ws.Holder;
@@ -31,6 +30,7 @@
import org.apache.juddi.config.AppConfig;
import org.apache.juddi.config.Property;
import org.apache.juddi.mapping.MappingModelToApi;
import org.apache.juddi.model.BindingTemplate;
import org.apache.juddi.query.FetchBindingTemplatesQuery;
import org.apache.juddi.query.FetchBusinessEntitiesQuery;
import org.apache.juddi.query.FetchBusinessServicesQuery;
@@ -82,15 +82,17 @@ public class InquiryHelper {

private static Log logger = LogFactory.getLog(InquiryHelper.class);

public static List<?> findBinding(FindBinding body, FindQualifiers findQualifiers, EntityManager em) throws DispositionReportFaultMessage {
public static List<Object> findBinding(FindBinding body, FindQualifiers findQualifiers, EntityManager em) throws DispositionReportFaultMessage {

List<?> keysFound = null;

// First perform the embedded FindTModel search which will augment the tModel bag with any resulting tModel keys.
List<Object> keysFound = new LinkedList<Object>();
if (body.getServiceKey()!=null && body.getServiceKey().length() > 0) {
keysFound = findBindingsByServiceKey(em, body.getServiceKey(), keysFound);
}

if (body.getTModelBag() == null)
body.setTModelBag(new TModelBag());
// First perform the embedded FindTModel search which will augment the tModel bag with any resulting tModel keys.
doFindTModelEmbeddedSearch(em, body.getFindQualifiers(), body.getFindTModel(), body.getTModelBag());

keysFound = FindBindingByTModelKeyQuery.select(em, findQualifiers, body.getTModelBag(), body.getServiceKey(), keysFound);
keysFound = FindBindingByCategoryQuery.select(em, findQualifiers, body.getCategoryBag(), body.getServiceKey(), keysFound);
keysFound = FindBindingByCategoryGroupQuery.select(em, findQualifiers, body.getCategoryBag(), body.getServiceKey(), keysFound);
@@ -168,9 +170,9 @@ public static BindingDetail getBindingDetailFromKeys(FindBinding body, FindQuali
return result;
}

public static List<?> findBusiness(FindBusiness body, FindQualifiers findQualifiers, EntityManager em) throws DispositionReportFaultMessage {
public static List<Object> findBusiness(FindBusiness body, FindQualifiers findQualifiers, EntityManager em) throws DispositionReportFaultMessage {

List<?> keysFound = null;
List<Object> keysFound = null;

// First perform the embedded FindTModel search which will augment the tModel bag with any resulting tModel keys.
if (body.getTModelBag() == null)
@@ -192,7 +194,7 @@ else if (body.getFindRelatedBusinesses().getFromKey() != null)
else if (body.getFindRelatedBusinesses().getToKey() != null)
getRelatedBusinesses(em, Direction.TO_KEY, frb.getToKey(), frb.getKeyedReference(), relatedBusinessInfos);

List<String> relatedBusinessKeys = new ArrayList<String>(0);
List<Object> relatedBusinessKeys = new ArrayList<Object>(0);
for (org.uddi.api_v3.RelatedBusinessInfo rbi : relatedBusinessInfos.getRelatedBusinessInfo())
relatedBusinessKeys.add(rbi.getBusinessKey());

@@ -322,7 +324,7 @@ public static BusinessList getBusinessListFromKeys(FindBusiness body, FindQualif

public static List<?> findService(FindService body, FindQualifiers findQualifiers, EntityManager em) throws DispositionReportFaultMessage {

List<?> keysFound = null;
List<Object> keysFound = null;

// First perform the embedded FindTModel search which will augment the tModel bag with any resulting tModel keys.
if (body.getTModelBag() == null)
@@ -419,8 +421,8 @@ public static ServiceList getServiceListFromKeys(FindService body, FindQualifier
return result;
}

public static List<?> findTModel(FindTModel body, FindQualifiers findQualifiers, EntityManager em) throws DispositionReportFaultMessage {
List<?> keysFound = null;
public static List<Object> findTModel(FindTModel body, FindQualifiers findQualifiers, EntityManager em) throws DispositionReportFaultMessage {
List<Object> keysFound = null;

keysFound = FindTModelByIdentifierQuery.select(em, findQualifiers, body.getIdentifierBag(), keysFound);
keysFound = FindTModelByCategoryQuery.select(em, findQualifiers, body.getCategoryBag(), keysFound);
@@ -608,7 +610,7 @@ else if (body.getFromKey() != null) {
return result;
}

/*
/**
* Performs the necessary queries for the find_tModel search and adds resulting tModel keys to the tModelBag provided.
*/
private static void doFindTModelEmbeddedSearch(EntityManager em,
@@ -623,7 +625,7 @@ private static void doFindTModelEmbeddedSearch(EntityManager em,
findQualifiers.mapApiFindQualifiers(findTmodel.getFindQualifiers());


List<?> tmodelKeysFound = null;
List<Object> tmodelKeysFound = null;
tmodelKeysFound = FindTModelByIdentifierQuery.select(em, findQualifiers, findTmodel.getIdentifierBag(), tmodelKeysFound);
tmodelKeysFound = FindTModelByCategoryQuery.select(em, findQualifiers, findTmodel.getCategoryBag(), tmodelKeysFound);
tmodelKeysFound = FindTModelByCategoryGroupQuery.select(em, findQualifiers, findTmodel.getCategoryBag(), tmodelKeysFound);
@@ -635,6 +637,14 @@ private static void doFindTModelEmbeddedSearch(EntityManager em,
}
}
}

private static List<Object> findBindingsByServiceKey(EntityManager em, String serviceKey, List<Object> keysFound) {
org.apache.juddi.model.BusinessService modelBusinessService=em.find(org.apache.juddi.model.BusinessService.class, serviceKey);
for (BindingTemplate bt : modelBusinessService.getBindingTemplates()){
keysFound.add(bt.getEntityKey());
}
return keysFound;
}


}
@@ -134,7 +134,7 @@ public BindingDetail findBinding(FindBinding body)
serviceCounter.update(InquiryQuery.FIND_BINDING, QueryStatus.FAILED, procTime);
throw drfm;
}

EntityManager em = PersistenceManager.getEntityManager();
EntityTransaction tx = em.getTransaction();
try {
@@ -144,27 +144,25 @@ public BindingDetail findBinding(FindBinding body)
this.getEntityPublisher(em, body.getAuthInfo());

LogFindBindingRequest(body);
if (body.getServiceKey() != null && body.getServiceKey().length() > 0) {
// Check that we were passed a valid serviceKey per
// 5.1.12.4 of the UDDI v3 spec
String serviceKey = body.getServiceKey();
org.apache.juddi.model.BusinessService modelBusinessService = null;
try {
modelBusinessService=em.find(org.apache.juddi.model.BusinessService.class, serviceKey);
} catch (Exception e) {
log.debug(e.getMessage(), e);
}
if (modelBusinessService == null)
throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.ServiceNotFound", serviceKey));
}

org.apache.juddi.query.util.FindQualifiers findQualifiers = new org.apache.juddi.query.util.FindQualifiers();
findQualifiers.mapApiFindQualifiers(body.getFindQualifiers());

List<?> keysFound = InquiryHelper.findBinding(body, findQualifiers, em);

if (keysFound!=null && keysFound.size() == 0) {
if (body.getServiceKey() != null) {
// Check that we were passed a valid serviceKey per
// 5.1.12.4 of the UDDI v3 spec
String serviceKey = body.getServiceKey();
org.apache.juddi.model.BusinessService modelBusinessService = null;
try {
modelBusinessService=em.find(org.apache.juddi.model.BusinessService.class, serviceKey);
} catch (Exception e) {
log.debug(e.getMessage(), e);
}
if (modelBusinessService == null)
throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.ServiceNotFound", serviceKey));

}
}
BindingDetail result = InquiryHelper.getBindingDetailFromKeys(body, findQualifiers, em, keysFound);
tx.rollback();
long procTime = System.currentTimeMillis() - startTime;
@@ -124,7 +124,7 @@ public static List<?> getPagedResult(EntityManager em, DynamicQuery dynamicQry,
* Used for all the find operation sub-queries. Restricts size of the IN clause based on global parameter
*/
@SuppressWarnings("unchecked")
public static List<?> getQueryResult(EntityManager em, DynamicQuery dynamicQry, List<?> keysIn, String inListTerm) {
public static List<Object> getQueryResult(EntityManager em, DynamicQuery dynamicQry, List<?> keysIn, String inListTerm) {

List<Object> result = new ArrayList<Object>(0);
// If keysIn is null, then no IN list is applied to the query - we simply need to run the query. Otherwise, the IN list is chunked based on
@@ -142,26 +142,31 @@ public static List<?> getQueryResult(EntityManager em, DynamicQuery dynamicQry,
catch(ConfigurationException ce) {
log.error("Configuration exception occurred retrieving: " + Property.JUDDI_MAX_IN_CLAUSE);
}

int inParamsLeft = keysIn.size();
int startIndex = 0;
while(inParamsLeft > 0) {
int endIndex = startIndex + Math.min(inParamsLeft, maxInClause);

List<Object> subKeysIn = new ArrayList<Object>(endIndex);
for (int i=startIndex; i< endIndex; i++) {
subKeysIn.add(keysIn.get(i));
}
dynamicQry.appendInListWithAnd(inListTerm, subKeysIn);
log.debug(dynamicQry);

Query qry = dynamicQry.buildJPAQuery(em);
List<Object> resultChunk = qry.getResultList();
result.addAll(resultChunk);

inParamsLeft = inParamsLeft - (endIndex - startIndex);
startIndex = endIndex;
}
if (keysIn.isEmpty()) {
Query qry = dynamicQry.buildJPAQuery(em);
List<Object> resultChunk = qry.getResultList();
result.addAll(resultChunk);
} else {
int inParamsLeft = keysIn.size();
int startIndex = 0;
while(inParamsLeft > 0) {
int endIndex = startIndex + Math.min(inParamsLeft, maxInClause);

List<Object> subKeysIn = new ArrayList<Object>(endIndex);
for (int i=startIndex; i< endIndex; i++) {
subKeysIn.add(keysIn.get(i));
}
dynamicQry.appendInListWithAnd(inListTerm, subKeysIn);
log.debug(dynamicQry);

Query qry = dynamicQry.buildJPAQuery(em);
List<Object> resultChunk = qry.getResultList();
result.addAll(resultChunk);

inParamsLeft = inParamsLeft - (endIndex - startIndex);
startIndex = endIndex;
}
}
}

return result;
@@ -58,7 +58,7 @@ public class FindBindingByCategoryGroupQuery {
BindingTemplateQuery.SIGNATURE_PRESENT);
}

public static List<?> select(EntityManager em, FindQualifiers fq, CategoryBag categoryBag, String parentKey, List<?> keysIn) {
public static List<Object> select(EntityManager em, FindQualifiers fq, CategoryBag categoryBag, String parentKey, List<Object> keysIn) {
if (parentKey != null && parentKey.length() > 0) {
DynamicQuery.Parameter param = new DynamicQuery.Parameter(BindingTemplateQuery.ENTITY_ALIAS + "." + BindingTemplateQuery.KEY_NAME_PARENT, parentKey, DynamicQuery.PREDICATE_EQUALS);
return findQuery.select(em, fq, categoryBag, keysIn, param);
@@ -52,7 +52,7 @@ public class FindBindingByCategoryQuery {
BindingTemplateQuery.SIGNATURE_PRESENT);
}

public static List<?> select(EntityManager em, FindQualifiers fq, CategoryBag categoryBag, String parentKey, List<?> keysIn) {
public static List<Object> select(EntityManager em, FindQualifiers fq, CategoryBag categoryBag, String parentKey, List<Object> keysIn) {
if (parentKey != null && parentKey.length() > 0) {
DynamicQuery.Parameter param = new DynamicQuery.Parameter(BindingTemplateQuery.ENTITY_ALIAS + "." + BindingTemplateQuery.KEY_NAME_PARENT, parentKey, DynamicQuery.PREDICATE_EQUALS);
return findQuery.select(em, fq, categoryBag, keysIn, param);
@@ -60,11 +60,11 @@ public class FindBindingByTModelKeyQuery extends BindingTemplateQuery {
entityAliasChild = buildAlias(ENTITY_NAME_CHILD);
}

public static List<?> select(EntityManager em, FindQualifiers fq, TModelBag tModels, String parentKey,
List<?> keysIn, DynamicQuery.Parameter... restrictions) {
public static List<Object> select(EntityManager em, FindQualifiers fq, TModelBag tModels, String parentKey,
List<Object> keysIn, DynamicQuery.Parameter... restrictions) {
// If keysIn is not null and empty, then search is over.
if ((keysIn != null) && (keysIn.size() == 0))
return keysIn;
//if ((keysIn != null) && (keysIn.size() == 0))
// return keysIn;

if (tModels == null)
return keysIn;
@@ -57,7 +57,7 @@ public class FindBusinessByCategoryGroupQuery {
BusinessEntityQuery.SIGNATURE_PRESENT);
}

public static List<?> select(EntityManager em, FindQualifiers fq, CategoryBag categoryBag, List<?> keysIn) {
public static List<Object> select(EntityManager em, FindQualifiers fq, CategoryBag categoryBag, List<Object> keysIn) {
return findQuery.select(em, fq, categoryBag, keysIn);
}
}
@@ -51,7 +51,7 @@ public class FindBusinessByCategoryQuery {
BusinessEntityQuery.SIGNATURE_PRESENT);
}

public static List<?> select(EntityManager em, FindQualifiers fq, CategoryBag categoryBag, List<?> keysIn) {
public static List<Object> select(EntityManager em, FindQualifiers fq, CategoryBag categoryBag, List<Object> keysIn) {
return findQuery.select(em, fq, categoryBag, keysIn);
}
}
@@ -71,7 +71,7 @@ public class FindBusinessByCombinedCategoryQuery {
BusinessEntityQuery.SIGNATURE_PRESENT);
}

public static List<?> select(EntityManager em, FindQualifiers fq, CategoryBag categoryBag, List<?> keysIn) {
public static List<Object> select(EntityManager em, FindQualifiers fq, CategoryBag categoryBag, List<Object> keysIn) {
return findQuery.select(em, fq, categoryBag, keysIn);
}
}
@@ -54,8 +54,8 @@ public class FindBusinessByDiscoveryURLQuery extends BusinessEntityQuery {
entityAliasChild = buildAlias(ENTITY_NAME_CHILD);
}

public static List<?> select(EntityManager em, FindQualifiers fq, DiscoveryURLs discURLs,
List<?> keysIn, DynamicQuery.Parameter... restrictions) {
public static List<Object> select(EntityManager em, FindQualifiers fq, DiscoveryURLs discURLs,
List<Object> keysIn, DynamicQuery.Parameter... restrictions) {
// If keysIn is not null and empty, then search is over.
if ((keysIn != null) && (keysIn.size() == 0))
return keysIn;
@@ -50,7 +50,7 @@ public class FindBusinessByIdentifierQuery {
BusinessEntityQuery.SIGNATURE_PRESENT);
}

public static List<?> select(EntityManager em, FindQualifiers fq, IdentifierBag identifiers, List<?> keysIn) {
public static List<Object> select(EntityManager em, FindQualifiers fq, IdentifierBag identifiers, List<Object> keysIn) {
return findQuery.select(em, fq, identifiers, keysIn);
}

@@ -58,7 +58,7 @@ public class FindBusinessByNameQuery {
BusinessEntityQuery.SIGNATURE_PRESENT);
}

public static List<?> select(EntityManager em, FindQualifiers fq, List<Name> names, List<?> keysIn) {
public static List<Object> select(EntityManager em, FindQualifiers fq, List<Name> names, List<Object> keysIn) {
return findQuery.select(em, fq, names, keysIn);
}

@@ -60,7 +60,7 @@ public class FindBusinessByTModelKeyQuery extends BusinessEntityQuery {
entityAliasChild = buildAlias(ENTITY_NAME_CHILD);
}

public static List<?> select(EntityManager em, FindQualifiers fq, TModelBag tModels, List<?> keysIn, DynamicQuery.Parameter... restrictions) {
public static List<Object> select(EntityManager em, FindQualifiers fq, TModelBag tModels, List<Object> keysIn, DynamicQuery.Parameter... restrictions) {
// If keysIn is not null and empty, then search is over.
if ((keysIn != null) && (keysIn.isEmpty()))
return keysIn;
@@ -128,7 +128,7 @@ public void setSignaturePresent(String signaturePresent) {
}

@SuppressWarnings("unchecked")
public List<?> select(EntityManager em, FindQualifiers fq, CategoryBag categoryBag, List<?> keysIn, DynamicQuery.Parameter... restrictions) {
public List<Object> select(EntityManager em, FindQualifiers fq, CategoryBag categoryBag, List<Object> keysIn, DynamicQuery.Parameter... restrictions) {
// If keysIn is not null and empty, then search is over.
if ((keysIn != null) && (keysIn.size() == 0))
return keysIn;
@@ -152,9 +152,9 @@ public List<?> select(EntityManager em, FindQualifiers fq, CategoryBag categoryB
Collections.sort(keyedRefGroups, new KeyedRefGroupTModelComparator());
int count = 0;
String prevTModelKey = null;
Set<String> orResults = new HashSet<String>(0);
List<?> restrictionList = keysIn;
List<?> curResult = null;
Set<Object> orResults = new HashSet<Object>(0);
List<Object> restrictionList = keysIn;
List<Object> curResult = null;
for (KeyedReferenceGroup keyedRefGroup : keyedRefGroups) {
String curTModelKey = keyedRefGroup.getTModelKey();

@@ -167,7 +167,7 @@ public List<?> select(EntityManager em, FindQualifiers fq, CategoryBag categoryB
if (fq.isOrLikeKeys()) {
if (!curTModelKey.equals(prevTModelKey)) {
if (count != 0) {
restrictionList = new ArrayList<String>(orResults);
restrictionList = new ArrayList<Object>(orResults);
orResults.clear();
}
}
@@ -183,20 +183,20 @@ else if (!fq.isOrAllKeys()) {
curResult = getQueryResult(em, dynamicQry, restrictionList, entityAlias + "." + keyName);

if (fq.isOrAllKeys() || fq.isOrLikeKeys()) {
orResults.addAll((List<String>)curResult);
orResults.addAll((List<Object>)curResult);
}

prevTModelKey = curTModelKey;
count++;
}

List<String> result = null;
List<Object> result = null;
if (fq.isOrAllKeys() || fq.isOrLikeKeys()) {
result = new ArrayList<String>(0);
result = new ArrayList<Object>(0);
result.addAll(orResults);
}
else
result = (List<String>)curResult;
result = (List<Object>)curResult;

return result;

@@ -117,7 +117,7 @@ public void setSignaturePresent(String signaturePresent) {
this.signaturePresent = signaturePresent;
}

public List<?> select(EntityManager em, FindQualifiers fq, CategoryBag categoryBag, List<?> keysIn, DynamicQuery.Parameter... restrictions) {
public List<Object> select(EntityManager em, FindQualifiers fq, CategoryBag categoryBag, List<Object> keysIn, DynamicQuery.Parameter... restrictions) {
// If keysIn is not null and empty, then search is over.
if ((keysIn != null) && (keysIn.size() == 0))
return keysIn;

0 comments on commit 2f5a249

Please sign in to comment.