Search in sources :

Example 1 with OdsOrganisation

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;
}
Also used : DefaultRestContext(org.onehippo.cms7.essentials.components.rest.ctx.DefaultRestContext) NodeIterator(javax.jcr.NodeIterator) Query(javax.jcr.query.Query) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext) Logger(org.slf4j.Logger) OdsOrganisation(uk.nhs.digital.model.OdsOrganisation) Context(javax.ws.rs.core.Context) QueryManager(javax.jcr.query.QueryManager) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LoggerFactory(org.slf4j.LoggerFactory) HttpServletResponse(javax.servlet.http.HttpServletResponse) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) QueryResult(javax.jcr.query.QueryResult) Collectors(java.util.stream.Collectors) BaseRestResource(org.onehippo.cms7.essentials.components.rest.BaseRestResource) DefaultRestContext(org.onehippo.cms7.essentials.components.rest.ctx.DefaultRestContext) List(java.util.List) HttpServletRequest(javax.servlet.http.HttpServletRequest) MediaType(javax.ws.rs.core.MediaType) Value(javax.jcr.Value) RepositoryException(javax.jcr.RepositoryException) javax.ws.rs(javax.ws.rs) Node(javax.jcr.Node) TypeReference(com.fasterxml.jackson.core.type.TypeReference) NodeIterator(javax.jcr.NodeIterator) Query(javax.jcr.query.Query) Node(javax.jcr.Node) OdsOrganisation(uk.nhs.digital.model.OdsOrganisation) RepositoryException(javax.jcr.RepositoryException) QueryResult(javax.jcr.query.QueryResult) QueryManager(javax.jcr.query.QueryManager) Value(javax.jcr.Value) TypeReference(com.fasterxml.jackson.core.type.TypeReference) HstRequestContext(org.hippoecm.hst.core.request.HstRequestContext) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Node (javax.jcr.Node)1 NodeIterator (javax.jcr.NodeIterator)1 RepositoryException (javax.jcr.RepositoryException)1 Value (javax.jcr.Value)1 Query (javax.jcr.query.Query)1 QueryManager (javax.jcr.query.QueryManager)1 QueryResult (javax.jcr.query.QueryResult)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 javax.ws.rs (javax.ws.rs)1 Context (javax.ws.rs.core.Context)1 MediaType (javax.ws.rs.core.MediaType)1 HstRequestContext (org.hippoecm.hst.core.request.HstRequestContext)1 BaseRestResource (org.onehippo.cms7.essentials.components.rest.BaseRestResource)1 DefaultRestContext (org.onehippo.cms7.essentials.components.rest.ctx.DefaultRestContext)1