- @GetMapping("/status")
- @ApiOperation(value = "Returns status and statistics of DATAFILE service")
- @ApiResponses(
- value = { //
- @ApiResponse(code = 200, message = "DATAFILE service is living"),
- @ApiResponse(code = 401, message = "You are not authorized to view the resource"),
- @ApiResponse(code = 403, message = "Accessing the resource you were trying to reach is forbidden"),
- @ApiResponse(code = 404, message = "The resource you were trying to reach is not found") //
- })
- public Mono<ResponseEntity<String>> getStatus(@RequestHeader HttpHeaders headers) {
- Mono<ResponseEntity<String>> response = Mono.just(new ResponseEntity<>("hunky dory", HttpStatus.OK));
- return response;
+ 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();
+ }
+
+ @PutMapping(path = "/policy")
+ public ResponseEntity<String> putPolicy( //
+ @RequestParam(name = "type", required = true) String type, //
+ @RequestParam(name = "instance", required = true) String instanceId, //
+ @RequestParam(name = "ric", required = true) String ric, //
+ @RequestParam(name = "service", required = true) String service, //
+ @RequestBody String jsonBody) {
+
+ try {
+ // services.getService(service).ping();
+ Ric ricObj = rics.getRic(ric);
+ Policy policy = ImmutablePolicy.builder() //
+ .id(instanceId) //
+ .json(jsonBody) //
+ .type(policyTypes.getType(type)) //
+ .ric(ricObj) //
+ .ownerServiceName(service) //
+ .lastModified(getTimeStampUTC()) //
+ .build();
+ policies.put(policy);
+ return new ResponseEntity<String>(HttpStatus.OK);
+ } catch (ServiceException e) {
+ return new ResponseEntity<String>(e.getMessage(), HttpStatus.NOT_FOUND);
+ }