logger.debug("POST getPolicyType inputJsonString = {}", inputJsonString);
return restClient.post("/A1-ADAPTER-API:getPolicyType", inputJsonString) //
- .flatMap(response -> getValueFromResponse(response, "policy-type"));
+ .flatMap(response -> getValueFromResponse(response, "policy-type")) //
+ .flatMap(this::extractPolicySchema);
}
@Override
JSONObject paramsJson = new JSONObject();
paramsJson.put("near-rt-ric-url", ricConfig.baseUrl());
paramsJson.put("policy-id", policy.id());
+ paramsJson.put("policy-type-id", policy.type().name());
paramsJson.put("policy", policy.json());
String inputJsonString = createInputJsonString(paramsJson);
logger.debug("POST putPolicy inputJsonString = {}", inputJsonString);
return restClient.post("/A1-ADAPTER-API:putPolicy", inputJsonString) //
- .flatMap(response -> getValueFromResponse(response, "returned-policy"));
+ .flatMap(response -> getValueFromResponse(response, "returned-policy")) //
+ .flatMap(this::validateJson);
}
@Override
return Mono.error(ex);
}
}
+
+ private Mono<String> extractPolicySchema(String inputString) {
+ try {
+ JSONObject jsonObject = new JSONObject(inputString);
+ JSONObject schemaObject = jsonObject.getJSONObject("policySchema");
+ String schemaString = schemaObject.toString();
+ return Mono.just(schemaString);
+ } catch (JSONException ex) { // invalid json
+ return Mono.error(ex);
+ }
+ }
+
+ private Mono<String> validateJson(String inputString) {
+ try {
+ new JSONObject(inputString);
+ return Mono.just(inputString);
+ } catch (JSONException ex) { // invalid json
+ return Mono.error(ex);
+ }
+ }
}
leaf policy-id {\r
type string;\r
}\r
+ leaf policy-type-id {\r
+ type string;\r
+ }\r
leaf policy {\r
type string;\r
}\r
GetPolicyTypeIdentitiesInput input) {
log.info("Start of getPolicyTypeIdentities");
GetPolicyTypeIdentitiesOutputBuilder responseBuilder = new GetPolicyTypeIdentitiesOutputBuilder();
- String uri = nearRicUrlProvider.getPolicyTypeIdentitiesUrl(String.valueOf(input.getNearRtRicUrl()));
+ String uri = nearRicUrlProvider.policyTypesUrl(String.valueOf(input.getNearRtRicUrl()));
ResponseEntity<List<String>> response = restAdapter.get(uri, List.class);
if (response.hasBody()) {
log.info("Response getPolicyTypeIdentities : {} ", response.getBody());
public ListenableFuture<RpcResult<GetPolicyIdentitiesOutput>> getPolicyIdentities(GetPolicyIdentitiesInput input) {
log.info("Start of getPolicyIdentities");
GetPolicyIdentitiesOutputBuilder responseBuilder = new GetPolicyIdentitiesOutputBuilder();
- String uri = nearRicUrlProvider.getPolicyIdentitiesUrl(String.valueOf(input.getNearRtRicUrl()));
+ String uri = nearRicUrlProvider.policiesUrl(String.valueOf(input.getNearRtRicUrl()));
ResponseEntity<List<String>> response = restAdapter.get(uri, List.class);
if (response.hasBody()) {
log.info("Response getPolicyIdentities : {} ", response.getBody());
public ListenableFuture<RpcResult<PutPolicyOutput>> putPolicy(PutPolicyInput input) {
log.info("Start of putPolicy");
PutPolicyOutputBuilder responseBuilder = new PutPolicyOutputBuilder();
- String uri = nearRicUrlProvider.getPolicyUrl(String.valueOf(input.getNearRtRicUrl()),
- String.valueOf(input.getPolicyId()));
+ String uri = nearRicUrlProvider.putPolicyUrl(String.valueOf(input.getNearRtRicUrl()),
+ String.valueOf(input.getPolicyId()), String.valueOf(input.getPolicyTypeId()));
log.info("PUT Request input.getPolicy() : {} ", input.getPolicy());
ResponseEntity<String> response = restAdapter.put(uri, input.getPolicy(), String.class);
if (response.hasBody()) {
public ListenableFuture<RpcResult<DeletePolicyOutput>> deletePolicy(DeletePolicyInput input) {
log.info("Start of deletePolicy");
DeletePolicyOutputBuilder responseBuilder = new DeletePolicyOutputBuilder();
- String uri = nearRicUrlProvider.getPolicyUrl(String.valueOf(input.getNearRtRicUrl()),
+ String uri = nearRicUrlProvider.deletePolicyUrl(String.valueOf(input.getNearRtRicUrl()),
String.valueOf(input.getPolicyId()));
ResponseEntity<Void> response = restAdapter.delete(uri);
log.info("End of deletePolicy");
/**
* Retrieve the base url of the Near-RIC
*
+ * @param nearRtRicUrl the near-rt-ric url
* @return the base url
*/
public String getBaseUrl(final String nearRtRicUrl) {
}
/**
- * Retrieve the policy type ids url
+ * Retrieve the policytypes url
*
- * @return the policytype ids url
+ * @param nearRtRicUrl the near-rt-ric url
+ * @return the policytypes url
*/
- public String getPolicyTypeIdentitiesUrl(final String nearRtRicUrl) {
+ public String policyTypesUrl(final String nearRtRicUrl) {
return UriComponentsBuilder.fromUriString(getBaseUrl(nearRtRicUrl)).pathSegment("policytypes")
- .pathSegment("identities").build().toString();
+ .build().toString();
}
/**
- * Retrieve the url of the policy instances
+ * Retrieve the policies url
*
- * @param policyTypeId Policy Type Id
- * @return the policy ids url
+ * @param nearRtRicUrl the near-rt-ric url
+ * @return the policies url
*/
- public String getPolicyIdentitiesUrl(final String nearRtRicUrl) {
+ public String policiesUrl(final String nearRtRicUrl) {
return UriComponentsBuilder.fromUriString(getBaseUrl(nearRtRicUrl)).pathSegment("policies")
- .pathSegment("identities").build().toString();
+ .build().toString();
}
/**
* Retrieve the url of policy type
*
+ * @param nearRtRicUrl the near-rt-ric url
* @param policyTypeId Policy Type Id
* @return the policy type url
*/
public String getPolicyTypeUrl(final String nearRtRicUrl, final String policyTypeId) {
- return UriComponentsBuilder.fromUriString(getBaseUrl(nearRtRicUrl)).pathSegment("policytypes")
- .pathSegment(policyTypeId).build().toString();
+ return UriComponentsBuilder.fromUriString(policyTypesUrl(nearRtRicUrl)).pathSegment(policyTypeId)
+ .build().toString();
}
/**
- * Retrieve the url of the policy instance id
+ * Retrieve the url of putPolicy
*
+ * @param nearRtRicUrl the near-rt-ric url
* @param policyId Policy Id
- * @return the policy id url
+ * @param policyTypeId Policy Type Id
+ * @return the putPolicy url
*/
- public String getPolicyUrl(final String nearRtRicUrl, final String policyId) {
- return UriComponentsBuilder.fromUriString(getBaseUrl(nearRtRicUrl)).pathSegment("policies")
- .pathSegment(policyId).build().toString();
+ public String putPolicyUrl(final String nearRtRicUrl, final String policyId, final String policyTypeId) {
+ return UriComponentsBuilder.fromUriString(policiesUrl(nearRtRicUrl)).pathSegment(policyId)
+ .pathSegment("?policyTypeId=").pathSegment(policyTypeId).build().toString();
+ }
+
+ /**
+ * Retrieve the url of deletePolicy
+ *
+ * @param nearRtRicUrl the near-rt-ric url
+ * @param policyId Policy Id
+ * @return the deletePolicy url
+ */
+ public String deletePolicyUrl(final String nearRtRicUrl, final String policyId) {
+ return UriComponentsBuilder.fromUriString(policiesUrl(nearRtRicUrl)).pathSegment(policyId)
+ .build().toString();
}
}
GetPolicyTypeIdentitiesInputBuilder inputBuilder = new GetPolicyTypeIdentitiesInputBuilder();
inputBuilder.setNearRtRicUrl(nearRtRicUrl);
Whitebox.setInternalState(nonrtRicApiProvider, "restAdapter", restAdapter);
- String uri = nearRicUrlProvider.getPolicyTypeIdentitiesUrl(inputBuilder.build().getNearRtRicUrl());
+ String uri = nearRicUrlProvider.policyTypesUrl(inputBuilder.build().getNearRtRicUrl());
List<String> policyTypeIdentities = new ArrayList<>();
policyTypeIdentities.add(policyTypeId);
ResponseEntity<Object> getPolicyTypeIdentitiesResponse = new ResponseEntity<>(policyTypeIdentities, HttpStatus.OK);
GetPolicyIdentitiesInputBuilder inputBuilder = new GetPolicyIdentitiesInputBuilder();
inputBuilder.setNearRtRicUrl(nearRtRicUrl);
Whitebox.setInternalState(nonrtRicApiProvider, "restAdapter", restAdapter);
- String uri = nearRicUrlProvider.getPolicyIdentitiesUrl(inputBuilder.build().getNearRtRicUrl());
+ String uri = nearRicUrlProvider.policiesUrl(inputBuilder.build().getNearRtRicUrl());
List<String> policyIdentities = new ArrayList<>();
policyIdentities.add(policyId);
ResponseEntity<Object> getPolicyIdentitiesResponse = new ResponseEntity<>(policyIdentities, HttpStatus.OK);
String testPolicy = "{}";
inputBuilder.setNearRtRicUrl(nearRtRicUrl);
inputBuilder.setPolicyId(policyId);
+ inputBuilder.setPolicyTypeId(policyTypeId);
inputBuilder.setPolicy(testPolicy);
Whitebox.setInternalState(nonrtRicApiProvider, "restAdapter", restAdapter);
- String uri = nearRicUrlProvider.getPolicyUrl(inputBuilder.build().getNearRtRicUrl(),
- inputBuilder.getPolicyId());
+ String uri = nearRicUrlProvider.putPolicyUrl(inputBuilder.build().getNearRtRicUrl(),
+ inputBuilder.getPolicyId(), inputBuilder.getPolicyTypeId());
ResponseEntity<String> putPolicyResponse = new ResponseEntity<>(testPolicy, HttpStatus.CREATED);
when(restAdapter.put(eq(uri), eq(testPolicy), eq(String.class))).thenReturn(putPolicyResponse);
ListenableFuture<RpcResult<PutPolicyOutput>> result =