use of org.onehippo.cms7.essentials.components.rest.ctx.DefaultRestContext 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;
}
use of org.onehippo.cms7.essentials.components.rest.ctx.DefaultRestContext in project hippo by NHS-digital-website.
the class CyberAlertResource method fetchAllThreatIds.
@GET
@Path("/getAllThreatIds/")
public ThreatIds fetchAllThreatIds(@Context HttpServletRequest request, @Context HttpServletResponse servletResponse) {
ThreatIds threatId = new ThreatIds();
List<ThreatIdDate> threatIdDateList = new ArrayList<ThreatIdDate>();
try {
final HstQuery query = createQuery(new DefaultRestContext(this, request), CyberAlert.class, Subtypes.INCLUDE);
query.setLimit(100);
final HstQueryResult result = query.execute();
HippoBeanIterator iterator = result.getHippoBeans();
while (iterator.hasNext()) {
CyberAlert cyberAlert = (CyberAlert) iterator.nextHippoBean();
List<Calendar> calList = new ArrayList<Calendar>();
ThreatIdDate threDate = new ThreatIdDate();
if (cyberAlert != null) {
List<HippoBean> cyberAcknowledgementList = (List<HippoBean>) cyberAlert.getCyberAcknowledgements();
for (HippoBean cyberAckn : cyberAcknowledgementList) {
if (cyberAckn instanceof CyberAcknowledgement) {
CyberAcknowledgement cybAck = (CyberAcknowledgement) cyberAckn;
calList.add(cybAck.getResponseDatetime());
}
}
threDate.setResponsedates(calList);
threDate.setThreatid(cyberAlert.getThreatId());
}
threatIdDateList.add(threDate);
}
} catch (Exception e) {
log.error("Error finding beans", e);
}
threatId.setThreatids(threatIdDateList);
return threatId;
}
Aggregations