public String toJson() { return Jsons.toJson(this); } }
@Override public Val apply(String s) { return v(s); } };
@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()))); }
public static String toJson(Obj obj) { return toJsonSimple(obj).toString(); }
@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)))))); } } });
public static String toJson(Arr arr) { return toJsonSimple(arr).toString(); }
/** Create a property. Convenience. */ public static Prop p(String key, String value) { return new Prop(key, v(value)); }
private static Object toJsonSimple(Val val) { if (val instanceof SVal) { return ((SVal) val).getVal(); } if (val instanceof Obj) { return toJsonSimple((Obj) val); } if (val instanceof Arr) { return toJsonSimple((Arr) val); } if (val.equals(NULL)) { return null; } return Prelude.unexhaustiveMatch(); }
public String toJson() { return Jsons.toJson(this); } }
/** Create a property. Convenience. */ public static Prop p(String key, Boolean value) { return new Prop(key, v(value)); }
/** Create a property. Convenience. */ public static Prop p(String key, Number value) { return new Prop(key, v(value)); }
/** 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; }
/** Create a property. Convenience. */ public static Prop p(String key, Date value) { return new Prop(key, v(value)); }