+ @ApiOperation(value = "Delete a policy", response = Object.class)
+ @ApiResponses(
+ value = { //
+ @ApiResponse(code = 204, message = "Policy deleted", response = Object.class),
+ @ApiResponse(code = 404, message = "Policy is not found", response = String.class),
+ @ApiResponse(code = 423, message = "RIC is not operational", response = String.class)})
+ public Mono<ResponseEntity<Object>> deletePolicy( //
+ @RequestParam(name = "id", required = true) String id) {
+ try {
+ Policy policy = policies.getPolicy(id);
+ keepServiceAlive(policy.ownerServiceName());
+ Ric ric = policy.ric();
+ return ric.getLock().lock(LockType.SHARED) //
+ .flatMap(notUsed -> assertRicStateIdle(ric)) //
+ .flatMap(notUsed -> a1ClientFactory.createA1Client(policy.ric())) //
+ .doOnNext(notUsed -> policies.remove(policy)) //
+ .flatMap(client -> client.deletePolicy(policy)) //
+ .doOnNext(notUsed -> ric.getLock().unlockBlocking()) //
+ .doOnError(notUsed -> ric.getLock().unlockBlocking()) //
+ .flatMap(notUsed -> Mono.just(new ResponseEntity<>(HttpStatus.NO_CONTENT)))
+ .onErrorResume(this::handleException);
+ } catch (ServiceException e) {
+ return Mono.just(new ResponseEntity<>(HttpStatus.NOT_FOUND));
+ }
+ }
+
+ @PutMapping(path = "/policy")
+ @ApiOperation(value = "Put a policy", response = String.class)
+ @ApiResponses(
+ value = { //
+ @ApiResponse(code = 201, message = "Policy created", response = Object.class), //
+ @ApiResponse(code = 200, message = "Policy updated", response = Object.class), //
+ @ApiResponse(code = 423, message = "RIC is not operational", response = String.class), //
+ @ApiResponse(code = 404, message = "RIC or policy type is not found", response = String.class) //
+ })
+ public Mono<ResponseEntity<Object>> putPolicy( //
+ @RequestParam(name = "type", required = false, defaultValue = "") String typeName, //
+ @RequestParam(name = "id", required = true) String instanceId, //
+ @RequestParam(name = "ric", required = true) String ricName, //
+ @RequestParam(name = "service", required = true) String service, //
+ @RequestBody Object jsonBody) {
+
+ String jsonString = gson.toJson(jsonBody);
+ Ric ric = rics.get(ricName);
+ PolicyType type = policyTypes.get(typeName);
+ keepServiceAlive(service);
+ if (ric == null || type == null) {
+ return Mono.just(new ResponseEntity<>(HttpStatus.NOT_FOUND));
+ }
+ Policy policy = ImmutablePolicy.builder() //
+ .id(instanceId) //
+ .json(jsonString) //
+ .type(type) //
+ .ric(ric) //
+ .ownerServiceName(service) //
+ .lastModified(getTimeStampUtc()) //
+ .build();
+
+ final boolean isCreate = this.policies.get(policy.id()) == null;