+ Policy p = policies.removeId(instance);
+ return new ResponseEntity<String>("OK", HttpStatus.OK);
+ }
+
+ @GetMapping("/policies")
+ public ResponseEntity<String> getPolicies( //
+ @RequestParam(name = "type", required = false) String type, //
+ @RequestParam(name = "ric", required = false) String ric, //
+ @RequestParam(name = "service", required = false) String service) //
+ {
+ Collection<Policy> result = null;
+
+ if (type != null) {
+ result = policies.getForType(type);
+ result = filter(result, null, ric, service);
+ } else if (service != null) {
+ result = policies.getForService(service);
+ result = filter(result, type, ric, null);
+ } else if (ric != null) {
+ result = policies.getForRic(ric);
+ result = filter(result, type, null, service);
+ } else {
+ result = policies.getAll();
+ }
+
+ return new ResponseEntity<String>(policiesToJson(result), HttpStatus.OK);
+ }
+
+ private boolean include(String filter, String value) {
+ return filter == null || value.equals(filter);
+ }
+
+ private Collection<Policy> filter(Collection<Policy> collection, String type, String ric, String service) {
+ if (type == null && ric == null && service == null) {
+ return collection;
+ }
+ Vector<Policy> filtered = new Vector<>();
+ for (Policy p : collection) {
+ if (include(type, p.type().name()) && include(ric, p.ric().name())
+ && include(service, p.ownerServiceName())) {
+ filtered.add(p);
+ }
+ }
+ return filtered;
+ }
+
+ private String policiesToJson(Collection<Policy> policies) {
+ Vector<PolicyInfo> v = new Vector<>(policies.size());
+ for (Policy p : policies) {
+ PolicyInfo policyInfo = ImmutablePolicyInfo.builder() //
+ .json(p.json()) //
+ .id(p.id()) //
+ .ric(p.ric().name()) //
+ .type(p.type().name()) //
+ .service(p.ownerServiceName()) //
+ .lastModified(p.lastModified()) //
+ .build();
+ v.add(policyInfo);
+ }
+ return gson.toJson(v);
+ }
+
+ private String policyTypesToJson(Collection<PolicyType> types) {
+ Vector<PolicyTypeInfo> v = new Vector<>(types.size());
+ for (PolicyType t : types) {
+ PolicyTypeInfo policyInfo = ImmutablePolicyTypeInfo.builder() //
+ .schema(t.jsonSchema()) //
+ .name(t.name()) //
+ .build();
+ v.add(policyInfo);
+ }
+ return gson.toJson(v);
+ }
+
+ private String getTimeStampUTC() {
+ return java.time.Instant.now().toString();