/** Constructor method. */ public static IncidentDto mk( Long jobId, Date date, String code, Severity severity, Map<String, String> parameters, List<Tuple<String, String>> details) { IncidentDto dto = new IncidentDto(); dto.jobId = jobId; dto.timestamp = date; dto.code = code; dto.severity = severity.ordinal(); List<Prop> props = new ArrayList<Jsons.Prop>(); for (Entry<String, String> entry : parameters.entrySet()) { props.add(p(entry.getKey(), entry.getValue())); } dto.parameters = obj(props.toArray(new Prop[props.size()])).toJson(); props = new ArrayList<Jsons.Prop>(); for (Tuple<String, String> t : details) { props.add(p(t.getA(), t.getB())); } dto.details = obj(props.toArray(new Prop[props.size()])).toJson(); return dto; }
@GET // path prefix "bundles" is contained here and not in the path annotation of the class // See https://opencast.jira.com/browse/MH-9768 @Path("bundles/list") @Produces(APPLICATION_JSON) @RestQuery( name = "list", description = "Return a list of all running bundles on the whole cluster.", reponses = { @RestResponse(description = "A list of bundles.", responseCode = HttpServletResponse.SC_OK) }, returnDescription = "The search results, expressed as xml or json.") public Response getVersions() { final Monadics.ListMonadic<Jsons.Val> bundleInfos = mlist(getDb().getBundles()).map( Functions.<BundleInfo, Jsons.Val> co(bundleInfo)); return ok(obj(p("bundleInfos", arr(bundleInfos)), p("count", bundleInfos.value().size()))); }
@Override public Response apply(List<BundleInfo> infos) { final Set<BundleVersion> versions = set(); for (BundleInfo bundle : infos) { versions.add(bundle.getVersion()); } final BundleInfo example = infos.get(0); switch (versions.size()) { case 0: // no versions... throw new Error("bug"); case 1: // all versions align return ok(obj(p("consistent", true)).append(fullVersionJson.apply(example.getVersion()))); default: // multiple versions found return ok(obj(p("consistent", false), p("versions", arr(mlist(versions.iterator()) .map(Functions.<BundleVersion, Jsons.Val> co(fullVersionJson)))))); } } });