use of uk.nhs.digital.model.OdsOrganisation in project hippo by NHS-digital-website.
the class OrganisationDataResource method getOrg.
@GET
@Path("/")
public List<OdsOrganisation> getOrg(@Context HttpServletRequest request, @Context HttpServletResponse servletResponse, @QueryParam("orgName") String orgName) {
if (odsResults == null) {
try {
log.debug("Loading ODS Data");
HstRequestContext context = new DefaultRestContext(this, request).getRequestContext();
QueryManager manager = context.getSession().getWorkspace().getQueryManager();
Query jcrQuery = manager.createQuery("/jcr:root/content/assets//*[@jcr:primaryType='externalstorage:resource']", "xpath");
QueryResult execute = jcrQuery.execute();
NodeIterator iterator = execute.getNodes();
while (iterator.hasNext()) {
Node node = iterator.nextNode();
if (node.getPath().contains("/content/assets/ODS_Data")) {
Value val = node.getProperty("jcr:data").getValue();
// convert JSON array to Java List
odsResults = new ObjectMapper().readValue(val.getString().replace("\n", ""), new TypeReference<List<OdsOrganisation>>() {
});
break;
}
}
} catch (RepositoryException | JsonProcessingException e) {
log.debug("Failed to load ODS Data ", e);
}
}
List<OdsOrganisation> filterOrg = odsResults.stream().filter(b -> (b.getOrgName() + " " + b.getCode()).toUpperCase().contains(orgName.toUpperCase())).collect(Collectors.toList());
return filterOrg;
}
Aggregations