public static BindingDetail getBindingDetailFromKeys(FindBinding body, FindQualifiers findQualifiers, EntityManager em, List<?> keysFound,
Date modifiedAfter, Date modifiedBefore, Holder<Integer> subscriptionStartIndex, Integer subscriptionMaxRows)
throws DispositionReportFaultMessage {
BindingDetail result = new BindingDetail();
ListDescription listDesc = new ListDescription();
result.setListDescription(listDesc);
// Sort and retrieve the final results with paging taken into account
List<?> queryResults = FetchBindingTemplatesQuery.select(em, findQualifiers, keysFound, body.getMaxRows(), body.getListHead(), listDesc);
// 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.BindingTemplate modelBindingTemplate = (org.apache.juddi.model.BindingTemplate)item;
org.uddi.api_v3.BindingTemplate apiBindingTemplate = new org.uddi.api_v3.BindingTemplate();
if (modifiedAfter != null && modifiedAfter.after(modelBindingTemplate.getModifiedIncludingChildren())) {
currentIndex++;
continue;
}
if (modifiedBefore != null && modifiedBefore.before(modelBindingTemplate.getModifiedIncludingChildren())) {
currentIndex++;
continue;
}
MappingModelToApi.mapBindingTemplate(modelBindingTemplate, apiBindingTemplate);
result.getBindingTemplate().add(apiBindingTemplate);
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)
break;
}
currentIndex++;
}
// If the loop was broken prematurely (max row count hit) we set the subscriptionStartIndex to the next index to start with.
// Otherwise, set it to null so the subscription call won't trigger chunk token generation.
if (currentIndex < (queryResults.size() - 1)) {
if (subscriptionStartIndex != null)
subscriptionStartIndex.value = currentIndex + 1;
result.setTruncated(Boolean.TRUE);
}
else {
if (subscriptionStartIndex != null)
subscriptionStartIndex.value = null;
result.setTruncated(Boolean.FALSE);
}
return result;
}