summaryrefslogtreecommitdiffstats
path: root/ONAP-PDP-REST/src
diff options
context:
space:
mode:
Diffstat (limited to 'ONAP-PDP-REST/src')
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java306
-rw-r--r--ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/test/GetDictionaryServiceTest.java24
2 files changed, 170 insertions, 160 deletions
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java
index 152e84ccf..44cc76478 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* ONAP-PDP-REST
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,13 +17,12 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.policy.pdp.rest.api.services;
import java.util.UUID;
-
import javax.json.JsonException;
import javax.json.JsonObject;
-
import org.onap.policy.api.DictionaryParameters;
import org.onap.policy.api.DictionaryResponse;
import org.onap.policy.api.PolicyException;
@@ -36,16 +35,15 @@ import org.springframework.http.HttpStatus;
public class GetDictionaryService {
private static final Logger LOGGER = FlexLogger.getLogger(GetDictionaryService.class.getName());
-
+
private DictionaryResponse dictionaryResponse = null;
private HttpStatus status = HttpStatus.BAD_REQUEST;
private String message = null;
private DictionaryParameters dictionaryParameters = null;
- public GetDictionaryService(DictionaryParameters dictionaryParameters,
- String requestID) {
+ public GetDictionaryService(DictionaryParameters dictionaryParameters, String requestID) {
this.dictionaryParameters = dictionaryParameters;
- if(dictionaryParameters.getRequestID()==null){
+ if (dictionaryParameters.getRequestID() == null) {
UUID requestUUID = null;
if (requestID != null && !requestID.isEmpty()) {
try {
@@ -54,16 +52,16 @@ public class GetDictionaryService {
requestUUID = UUID.randomUUID();
LOGGER.info("Generated Random UUID: " + requestUUID.toString(), e);
}
- }else{
+ } else {
requestUUID = UUID.randomUUID();
LOGGER.info("Generated Random UUID: " + requestUUID.toString());
}
this.dictionaryParameters.setRequestID(requestUUID);
}
- try{
+ try {
run();
specialCheck();
- }catch(PolicyException e){
+ } catch (PolicyException e) {
StdDictionaryResponse dictionaryResponse = new StdDictionaryResponse();
dictionaryResponse.setResponseMessage(XACMLErrorConstants.ERROR_DATA_ISSUE + e);
this.dictionaryResponse = dictionaryResponse;
@@ -72,47 +70,51 @@ public class GetDictionaryService {
}
private void specialCheck() {
- if(dictionaryResponse!=null && (dictionaryResponse.getResponseMessage()!=null && dictionaryResponse.getResponseMessage().contains("PE300"))){
- status = HttpStatus.BAD_REQUEST;
+ if (dictionaryResponse != null && (dictionaryResponse.getResponseMessage() != null
+ && dictionaryResponse.getResponseMessage().contains("PE300"))) {
+ status = HttpStatus.BAD_REQUEST;
}
}
- private void run() throws PolicyException{
- // Check Validation.
- if(!getValidation()){
+ private void run() throws PolicyException {
+ // Check Validation.
+ if (!getValidation()) {
LOGGER.error(message);
throw new PolicyException(message);
}
- // Get Result.
- try{
+ // Get Result.
+ try {
status = HttpStatus.OK;
dictionaryResponse = processResult();
- }catch (Exception e){
+ } catch (Exception e) {
LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e);
status = HttpStatus.BAD_REQUEST;
throw new PolicyException(e);
}
}
- private DictionaryResponse processResult() throws PolicyException{
+ private DictionaryResponse processResult() throws PolicyException {
StdDictionaryResponse response = new StdDictionaryResponse();
PAPServices papServices = new PAPServices();
- String result = (String) papServices.callPAP(null, new String[] {"operation=get", "apiflag=api", "dictionaryType="+dictionaryParameters.getDictionary()}, dictionaryParameters.getRequestID(), "dictionaryItem");
-
- if (result!=null && result.contains("data")) {
+ String result = (String) papServices.callPAP(null,
+ new String[] {"operation=get", "apiflag=api", "dictionaryType=" + dictionaryParameters.getDictionary()},
+ dictionaryParameters.getRequestID(), "dictionaryItem");
+
+ if (result != null && result.contains("data")) {
String jsonString = formatDictionaryJson(result);
String responseMessage = result.substring(0, 82);
JsonObject json = null;
- try{
+ try {
json = PolicyApiUtils.stringToJsonObject(jsonString.replace("\\\\\\", "\\"));
String datas = json.getString("data").replaceFirst("\"\\[", "[");
int i = datas.lastIndexOf("]");
- if( i>=0 ) {
- datas = new StringBuilder(datas).replace(i, i+2,"]").toString();
+ if (i >= 0) {
+ datas = new StringBuilder(datas).replace(i, i + 2, "]").toString();
}
json = PolicyApiUtils.stringToJsonObject(datas);
- } catch(JsonException| IllegalStateException e){
- message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " improper Dictionary JSON object : " + dictionaryParameters.getDictionaryJson();
+ } catch (JsonException | IllegalStateException e) {
+ message = XACMLErrorConstants.ERROR_DATA_ISSUE + " improper Dictionary JSON object : "
+ + dictionaryParameters.getDictionaryJson();
LOGGER.error(message, e);
response.setResponseMessage(message);
response.setResponseCode(400);
@@ -120,14 +122,14 @@ public class GetDictionaryService {
}
response.setResponseCode(papServices.getResponseCode());
response.setDictionaryJson(json);
- response.setResponseMessage(responseMessage);
+ response.setResponseMessage(responseMessage);
} else {
response.setResponseCode(400);
response.setResponseMessage(result);
- if(result!=null && result.contains("PE200")){
- status=HttpStatus.INTERNAL_SERVER_ERROR;
- }else{
- status=HttpStatus.BAD_REQUEST;
+ if (result != null && result.contains("PE200")) {
+ status = HttpStatus.INTERNAL_SERVER_ERROR;
+ } else {
+ status = HttpStatus.BAD_REQUEST;
}
}
return response;
@@ -136,135 +138,139 @@ public class GetDictionaryService {
private String formatDictionaryJson(String result) {
String jsonString = result.substring(82);
String dictionary = dictionaryParameters.getDictionary();
-
+
switch (dictionary) {
- case "OnapName":
- jsonString = jsonString.replace("onapNameDictionaryDatas", "DictionaryDatas");
- break;
- case "Attribute":
- jsonString = jsonString.replace("attributeDictionaryDatas", "DictionaryDatas");
- break;
+ case "OnapName":
+ jsonString = jsonString.replace("onapNameDictionaryDatas", "DictionaryDatas");
+ break;
+ case "Attribute":
+ jsonString = jsonString.replace("attributeDictionaryDatas", "DictionaryDatas");
+ break;
case "Action":
- jsonString = jsonString.replace("actionPolicyDictionaryDatas", "DictionaryDatas");
- break;
- case "BRMSParamTemplate":
- jsonString = jsonString.replace("brmsParamDictionaryDatas", "DictionaryDatas");
- break;
- case "VSCLAction":
- jsonString = jsonString.replace("vsclActionDictionaryDatas", "DictionaryDatas");
- break;
- case "VNFType":
- jsonString = jsonString.replace("vnfTypeDictionaryDatas", "DictionaryDatas");
- break;
- case "PEPOptions":
- jsonString = jsonString.replace("pepOptionsDictionaryDatas", "DictionaryDatas");
- break;
- case "Varbind":
- jsonString = jsonString.replace("varbindDictionaryDatas", "DictionaryDatas");
- break;
- case "Service":
- jsonString = jsonString.replace("closedLoopServiceDictionaryDatas", "DictionaryDatas");
- break;
- case "Site":
- jsonString = jsonString.replace("closedLoopSiteDictionaryDatas", "DictionaryDatas");
- break;
- case "Settings":
- jsonString = jsonString.replace("settingsDictionaryDatas", "DictionaryDatas");
- break;
- case "RainyDayTreatments":
- jsonString = jsonString.replace("rainyDayDictionaryDatas", "DictionaryDatas");
- break;
- case "DescriptiveScope":
- jsonString = jsonString.replace("descriptiveScopeDictionaryDatas", "DictionaryDatas");
- break;
- case "Enforcer":
- jsonString = jsonString.replace("enforcerDictionaryDatas", "DictionaryDatas");
- break;
- case "ActionList":
- jsonString = jsonString.replace("actionListDictionaryDatas", "DictionaryDatas");
- break;
- case "ProtocolList":
- jsonString = jsonString.replace("protocolListDictionaryDatas", "DictionaryDatas");
- break;
- case "Zone":
- jsonString = jsonString.replace("zoneDictionaryDatas", "DictionaryDatas");
- break;
- case "SecurityZone":
- jsonString = jsonString.replace("securityZoneDictionaryDatas", "DictionaryDatas");
- break;
- case "PrefixList":
- jsonString = jsonString.replace("prefixListDictionaryDatas", "DictionaryDatas");
- break;
- case "AddressGroup":
- jsonString = jsonString.replace("addressGroupDictionaryDatas", "DictionaryDatas");
- break;
- case "ServiceGroup":
- jsonString = jsonString.replace("serviceGroupDictionaryDatas", "DictionaryDatas");
- break;
- case "ServiceList":
- jsonString = jsonString.replace("serviceListDictionaryDatas", "DictionaryDatas");
- break;
- case "TermList":
- case "RuleList":
- case "FirewallRuleList":
- case "Term":
- jsonString = jsonString.replace("termListDictionaryDatas", "DictionaryDatas");
- break;
- case "MicroServiceLocation":
- jsonString = jsonString.replace("microServiceLocationDictionaryDatas", "DictionaryDatas");
- break;
- case "MicroServiceConfigName":
- jsonString = jsonString.replace("microServiceCongigNameDictionaryDatas", "DictionaryDatas");
- break;
- case "DCAEUUID":
- jsonString = jsonString.replace("dcaeUUIDDictionaryDatas", "DictionaryDatas");
- break;
- case "MicroServiceModels":
- jsonString = jsonString.replace("microServiceModelsDictionaryDatas", "DictionaryDatas");
- break;
- case "OptimizationModels":
- jsonString = jsonString.replace("optmizationModelsDictionaryDatas", "DictionaryDatas");
- break;
- case "PolicyScopeService":
- jsonString = jsonString.replace("psServiceDictionaryDatas", "DictionaryDatas");
- break;
- case "PolicyScopeResource":
- jsonString = jsonString.replace("psResourceDictionaryDatas", "DictionaryDatas");
- break;
- case "PolicyScopeType":
- jsonString = jsonString.replace("psTypeDictionaryDatas", "DictionaryDatas");
- break;
- case "PolicyScopeClosedLoop":
- jsonString = jsonString.replace("psClosedLoopDictionaryDatas", "DictionaryDatas");
- break;
- case "GroupPolicyScopeList":
- jsonString = jsonString.replace("groupPolicyScopeListDatas", "DictionaryDatas");
- break;
- case "RiskType":
- jsonString = jsonString.replace("riskTypeDictionaryDatas", "DictionaryDatas");
- break;
- case "SafePolicyWarning":
- jsonString = jsonString.replace("safePolicyWarningDatas", "DictionaryDatas");
- break;
- case "MicroServiceDictionary":
- jsonString = jsonString.replace("microServiceDictionaryDatas", "DictionaryDatas");
- break;
- default:
- break;
+ jsonString = jsonString.replace("actionPolicyDictionaryDatas", "DictionaryDatas");
+ break;
+ case "BRMSParamTemplate":
+ jsonString = jsonString.replace("brmsParamDictionaryDatas", "DictionaryDatas");
+ break;
+ case "VSCLAction":
+ jsonString = jsonString.replace("vsclActionDictionaryDatas", "DictionaryDatas");
+ break;
+ case "VNFType":
+ jsonString = jsonString.replace("vnfTypeDictionaryDatas", "DictionaryDatas");
+ break;
+ case "PEPOptions":
+ jsonString = jsonString.replace("pepOptionsDictionaryDatas", "DictionaryDatas");
+ break;
+ case "Varbind":
+ jsonString = jsonString.replace("varbindDictionaryDatas", "DictionaryDatas");
+ break;
+ case "Service":
+ jsonString = jsonString.replace("closedLoopServiceDictionaryDatas", "DictionaryDatas");
+ break;
+ case "Site":
+ jsonString = jsonString.replace("closedLoopSiteDictionaryDatas", "DictionaryDatas");
+ break;
+ case "Settings":
+ jsonString = jsonString.replace("settingsDictionaryDatas", "DictionaryDatas");
+ break;
+ case "RainyDayTreatments":
+ jsonString = jsonString.replace("rainyDayDictionaryDatas", "DictionaryDatas");
+ break;
+ case "DescriptiveScope":
+ jsonString = jsonString.replace("descriptiveScopeDictionaryDatas", "DictionaryDatas");
+ break;
+ case "Enforcer":
+ jsonString = jsonString.replace("enforcerDictionaryDatas", "DictionaryDatas");
+ break;
+ case "ActionList":
+ jsonString = jsonString.replace("actionListDictionaryDatas", "DictionaryDatas");
+ break;
+ case "ProtocolList":
+ jsonString = jsonString.replace("protocolListDictionaryDatas", "DictionaryDatas");
+ break;
+ case "Zone":
+ jsonString = jsonString.replace("zoneDictionaryDatas", "DictionaryDatas");
+ break;
+ case "SecurityZone":
+ jsonString = jsonString.replace("securityZoneDictionaryDatas", "DictionaryDatas");
+ break;
+ case "PrefixList":
+ jsonString = jsonString.replace("prefixListDictionaryDatas", "DictionaryDatas");
+ break;
+ case "AddressGroup":
+ jsonString = jsonString.replace("addressGroupDictionaryDatas", "DictionaryDatas");
+ break;
+ case "ServiceGroup":
+ jsonString = jsonString.replace("serviceGroupDictionaryDatas", "DictionaryDatas");
+ break;
+ case "ServiceList":
+ jsonString = jsonString.replace("serviceListDictionaryDatas", "DictionaryDatas");
+ break;
+ case "TermList":
+ case "RuleList":
+ case "FirewallRuleList":
+ case "Term":
+ jsonString = jsonString.replace("termListDictionaryDatas", "DictionaryDatas");
+ break;
+ case "MicroServiceLocation":
+ jsonString = jsonString.replace("microServiceLocationDictionaryDatas", "DictionaryDatas");
+ break;
+ case "MicroServiceConfigName":
+ jsonString = jsonString.replace("microServiceCongigNameDictionaryDatas", "DictionaryDatas");
+ break;
+ case "MicroServiceDictionaryData":
+ jsonString = jsonString.replace("microServiceDictionaryDatas", "DictionaryDatas");
+ break;
+ case "DCAEUUID":
+ jsonString = jsonString.replace("dcaeUUIDDictionaryDatas", "DictionaryDatas");
+ break;
+ case "MicroServiceModels":
+ jsonString = jsonString.replace("microServiceModelsDictionaryDatas", "DictionaryDatas");
+ break;
+ case "OptimizationModels":
+ jsonString = jsonString.replace("optmizationModelsDictionaryDatas", "DictionaryDatas");
+ break;
+ case "PolicyScopeService":
+ jsonString = jsonString.replace("psServiceDictionaryDatas", "DictionaryDatas");
+ break;
+ case "PolicyScopeResource":
+ jsonString = jsonString.replace("psResourceDictionaryDatas", "DictionaryDatas");
+ break;
+ case "PolicyScopeType":
+ jsonString = jsonString.replace("psTypeDictionaryDatas", "DictionaryDatas");
+ break;
+ case "PolicyScopeClosedLoop":
+ jsonString = jsonString.replace("psClosedLoopDictionaryDatas", "DictionaryDatas");
+ break;
+ case "GroupPolicyScopeList":
+ jsonString = jsonString.replace("groupPolicyScopeListDatas", "DictionaryDatas");
+ break;
+ case "RiskType":
+ jsonString = jsonString.replace("riskTypeDictionaryDatas", "DictionaryDatas");
+ break;
+ case "SafePolicyWarning":
+ jsonString = jsonString.replace("safePolicyWarningDatas", "DictionaryDatas");
+ break;
+ case "MicroServiceDictionary":
+ jsonString = jsonString.replace("microServiceDictionaryDatas", "DictionaryDatas");
+ break;
+ default:
+ break;
}
return jsonString;
}
private boolean getValidation() {
- if(dictionaryParameters==null){
+ if (dictionaryParameters == null) {
message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Dictionary Parameters are not given.";
return false;
}
- if(dictionaryParameters.getDictionaryType()==null || dictionaryParameters.getDictionaryType().toString().trim().isEmpty()){
+ if (dictionaryParameters.getDictionaryType() == null
+ || dictionaryParameters.getDictionaryType().toString().trim().isEmpty()) {
message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Dictionary Type given.";
return false;
}
- if(dictionaryParameters.getDictionary()==null || dictionaryParameters.getDictionary().trim().isEmpty()){
+ if (dictionaryParameters.getDictionary() == null || dictionaryParameters.getDictionary().trim().isEmpty()) {
message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Dictionary given.";
return false;
}
diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/test/GetDictionaryServiceTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/test/GetDictionaryServiceTest.java
index 682c9a1e0..4544b6b1c 100644
--- a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/test/GetDictionaryServiceTest.java
+++ b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/test/GetDictionaryServiceTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-PDP-REST
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Modifications Copyright (C) 2019 Samsung
* ================================================================================
@@ -19,6 +19,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.policy.pdp.rest.api.test;
import static org.junit.Assert.assertNotNull;
@@ -31,16 +32,14 @@ public class GetDictionaryServiceTest {
@Test
public void dictionaryJsonTest() throws Exception {
- Method formatDictionary =
- GetDictionaryService.class.getDeclaredMethod("formatDictionaryJson", String.class);
+ Method formatDictionary = GetDictionaryService.class.getDeclaredMethod("formatDictionaryJson", String.class);
formatDictionary.setAccessible(true);
- String input =
- "{\"key\":\"value\",\"key\":\"value\",\"key\":\"value\",\"key\":\"value\",\"key\":\"value\","
- + "\"key\":\"value\",\"key\":\"value\",\"key\":\"value\",\"key\":\"value\",\"key\":\"value\","
- + "\"key\":\"value\",\"key\":\"value\",\"key\":\"value\",\"key\":\"value\",\"key\":\"value\","
- + "\"key\":\"value\",\"key\":\"value\",\"key\":\"value\",\"key\":\"value\",\"key\":\"value\","
- + "\"key\":\"value\",\"key\":\"value\",\"key\":\"value\",\"key\":\"value\",\"key\":\"value\","
- + "\"key\":\"value\",\"key\":\"value\",\"key\":\"value\"}";
+ String input = "{\"key\":\"value\",\"key\":\"value\",\"key\":\"value\",\"key\":\"value\",\"key\":\"value\","
+ + "\"key\":\"value\",\"key\":\"value\",\"key\":\"value\",\"key\":\"value\",\"key\":\"value\","
+ + "\"key\":\"value\",\"key\":\"value\",\"key\":\"value\",\"key\":\"value\",\"key\":\"value\","
+ + "\"key\":\"value\",\"key\":\"value\",\"key\":\"value\",\"key\":\"value\",\"key\":\"value\","
+ + "\"key\":\"value\",\"key\":\"value\",\"key\":\"value\",\"key\":\"value\",\"key\":\"value\","
+ + "\"key\":\"value\",\"key\":\"value\",\"key\":\"value\"}";
DictionaryParameters dp = new DictionaryParameters();
dp.setDictionary("test");
GetDictionaryService gds = new GetDictionaryService(dp, null);
@@ -182,6 +181,11 @@ public class GetDictionaryServiceTest {
result = (String) formatDictionary.invoke(gds, input);
assertNotNull(result);
//
+ dp.setDictionary("MicroServiceDictionaryData");
+ gds = new GetDictionaryService(dp, null);
+ result = (String) formatDictionary.invoke(gds, input);
+ assertNotNull(result);
+ //
dp.setDictionary("DCAEUUID");
gds = new GetDictionaryService(dp, null);
result = (String) formatDictionary.invoke(gds, input);