@SuppressWarnings("unchecked")
public static BusinessList getBusinessListFromKeys(FindBusiness body, FindQualifiers findQualifiers, EntityManager em, List<?> keysFound,
Date modifiedAfter, Date modifiedBefore, Holder<Integer> subscriptionStartIndex, Integer subscriptionMaxRows)
throws DispositionReportFaultMessage {
BusinessList result = new BusinessList();
ListDescription listDesc = new ListDescription();
result.setListDescription(listDesc);
// Sort and retrieve the final results taking paging into account
List<?> queryResults = FetchBusinessEntitiesQuery.select(em, findQualifiers, keysFound, body.getMaxRows(), body.getListHead(), listDesc);
List<?> serviceResults = null;
for (int i = 0; i<queryResults.size(); i++) {
org.apache.juddi.model.BusinessEntity be = (org.apache.juddi.model.BusinessEntity) queryResults.get(i);
List<Object> keysIn = new ArrayList<Object>();
List<org.apache.juddi.model.BusinessService> services = be.getBusinessServices();
for (int j = 0; j<services.size(); j++) {
keysIn.add(services.get(j).getEntityKey());
}
serviceResults = FindServiceByTModelKeyQuery.select(em, findQualifiers, body.getTModelBag(), null, keysIn);
if (serviceResults == null) {
be.setBusinessServices(null);
} else {
ListDescription ldesc = new ListDescription();
result.setListDescription(listDesc);
List<?> srvcs = FetchBusinessServicesQuery.select(em, findQualifiers, serviceResults, body.getMaxRows(),
body.getListHead(), ldesc);
be.setBusinessServices((List<org.apache.juddi.model.BusinessService>)srvcs);
}
}
if (queryResults != null && queryResults.size() > 0)
result.setBusinessInfos(new org.uddi.api_v3.BusinessInfos());
// Set the currentIndex to 0 or the value of the subscriptionStartIndex
int currentIndex = 0;
if (subscriptionStartIndex != null && subscriptionStartIndex.value != null)
currentIndex = subscriptionStartIndex.value;
int returnedRowCount = 0;
while (currentIndex < queryResults.size()) {
Object item = queryResults.get(currentIndex);
org.apache.juddi.model.BusinessEntity modelBusinessEntity = (org.apache.juddi.model.BusinessEntity)item;
org.uddi.api_v3.BusinessInfo apiBusinessInfo = new org.uddi.api_v3.BusinessInfo();
if (modifiedAfter != null && modifiedAfter.after(modelBusinessEntity.getModifiedIncludingChildren())){
currentIndex++;
continue;
}
if (modifiedBefore != null && modifiedBefore.before(modelBusinessEntity.getModifiedIncludingChildren())) {
currentIndex++;
continue;
}
MappingModelToApi.mapBusinessInfo(modelBusinessEntity, apiBusinessInfo);
result.getBusinessInfos().getBusinessInfo().add(apiBusinessInfo);
returnedRowCount++;
// If the returned rows equals the max allowed, we can end the loop (applies to subscription calls only)
if (subscriptionMaxRows != null) {
if (returnedRowCount == subscriptionMaxRows)