X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=POLICY-SDK-APP%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fcontroller%2FCreateDcaeMicroServiceController.java;h=2e7654e844990731f3b687c72f6f6a14045511e0;hb=b536883546b9fa87bce50c7a6d030f6de3aafdce;hp=2549e216700d7f875b40ac9d7941cb0776b870e6;hpb=0950d79047d3404c15b4dd30cffeb81346565f64;p=policy%2Fengine.git diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateDcaeMicroServiceController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateDcaeMicroServiceController.java index 2549e2167..2e7654e84 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateDcaeMicroServiceController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateDcaeMicroServiceController.java @@ -72,8 +72,6 @@ import lombok.Getter; import lombok.Setter; import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType; -import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType; -import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; @@ -89,7 +87,7 @@ import org.json.JSONArray; import org.json.JSONObject; import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; -import org.onap.policy.rest.XACMLRestProperties; +import org.onap.policy.rest.XacmlRestProperties; import org.onap.policy.rest.adapter.PolicyRestAdapter; import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.GroupPolicyScopeList; @@ -99,6 +97,7 @@ import org.onap.policy.rest.jpa.PolicyEntity; import org.onap.policy.rest.util.MSAttributeObject; import org.onap.policy.rest.util.MSModelUtils; import org.onap.policy.rest.util.MSModelUtils.MODEL_TYPE; +import org.onap.policy.utils.PolicyUtils; import org.onap.portalsdk.core.controller.RestrictedBaseController; import org.onap.portalsdk.core.web.support.JsonMessage; import org.springframework.beans.factory.annotation.Autowired; @@ -269,7 +268,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { String json = ""; DCAEMicroServiceObject microServiceObject = new DCAEMicroServiceObject(); MicroServiceModels returnModel = new MicroServiceModels(); - microServiceObject.setTemplateVersion(XACMLProperties.getProperty(XACMLRestProperties.TemplateVersion_MS)); + microServiceObject.setTemplateVersion(XACMLProperties.getProperty(XacmlRestProperties.TEMPLATE_VERSION_MS)); if (policyAdapter.getServiceType() != null) { microServiceObject.setService(policyAdapter.getServiceType()); microServiceObject.setVersion(policyAdapter.getVersion()); @@ -904,8 +903,8 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { // Get all keys with "MANY-true" defined in their value from subAttribute Set allkeys = null; - if (returnModel.getSub_attributes() != null && !returnModel.getSub_attributes().isEmpty()) { - JSONObject json = new JSONObject(returnModel.getSub_attributes()); + if (returnModel.getSubAttributes() != null && !returnModel.getSubAttributes().isEmpty()) { + JSONObject json = new JSONObject(returnModel.getSubAttributes()); getAllKeys(json); allkeys = allManyTrueKeys; allManyTrueKeys = new TreeSet<>(); @@ -943,8 +942,8 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { jsonModel = finalJsonObject.toString(); } - // get all properties with "MANY-true" defined in Ref_attributes - Set manyTrueProperties = getManyTrueProperties(returnModel.getRef_attributes()); + // get all properties with "MANY-true" defined in RefAttributes + Set manyTrueProperties = getManyTrueProperties(returnModel.getRefAttributes()); if (manyTrueProperties != null) { JSONObject jsonObj = new JSONObject(jsonModel); for (String s : manyTrueProperties) { @@ -960,9 +959,9 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { } } - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING); + response.setContentType(PolicyUtils.APPLICATION_JSON); + request.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING); List list = new ArrayList<>(); String responseString = mapper.writeValueAsString(returnModel); @@ -989,7 +988,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { if (attribute != null) { attribute = attribute.trim(); } - String refAttribute = returnModel.getRef_attributes(); + String refAttribute = returnModel.getRefAttributes(); if (refAttribute != null) { refAttribute = refAttribute.trim(); } @@ -1006,7 +1005,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { Gson gson = new Gson(); - String subAttributes = returnModel.getSub_attributes(); + String subAttributes = returnModel.getSubAttributes(); if (subAttributes != null) { subAttributes = subAttributes.trim(); } else { @@ -1183,6 +1182,14 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { return keys; } + /** + * getModelServiceVersionData. + * + * @param request HttpServletRequest + * @param response HttpServletResponse + * @return ModelAndView + * @throws IOException IOException + */ @RequestMapping( value = {"/policyController/getModelServiceVersioneData.htm"}, method = {org.springframework.web.bind.annotation.RequestMethod.POST}) @@ -1191,9 +1198,9 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING); + response.setContentType(PolicyUtils.APPLICATION_JSON); + request.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING); List list = new ArrayList<>(); String value = mapper.readTree(request.getReader()).get("policyData").toString().replaceAll("^\"|\"$", ""); String servicename = value.split("-v")[0]; @@ -1311,29 +1318,9 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { // Under the match we have attribute value and // attributeDesignator. So,finally down to the actual attribute. // - AttributeValueType attributeValue = match.getAttributeValue(); - String value = (String) attributeValue.getContent().get(0); - AttributeDesignatorType designator = match.getAttributeDesignator(); - String attributeId = designator.getAttributeId(); // First match in the target is OnapName, so set that value. - if ("ONAPName".equals(attributeId)) { - policyAdapter.setOnapName(value); - } else if ("ConfigName".equals(attributeId)) { - policyAdapter.setConfigName(value); - } else if ("uuid".equals(attributeId)) { - policyAdapter.setUuid(value); - } else if ("location".equals(attributeId)) { - policyAdapter.setLocation(value); - } else if ("RiskType".equals(attributeId)) { - policyAdapter.setRiskType(value); - } else if ("RiskLevel".equals(attributeId)) { - policyAdapter.setRiskLevel(value); - } else if ("guard".equals(attributeId)) { - policyAdapter.setGuard(value); - } else if ("TTLDate".equals(attributeId) && !value.contains("NA")) { - String newDate = new PolicyController().convertDate(value); - policyAdapter.setTtlDate(newDate); - } + policyAdapter.setupUsingAttribute(match.getAttributeDesignator().getAttributeId(), + (String) match.getAttributeValue().getContent().get(0)); } readFile(policyAdapter, entity); } @@ -1397,6 +1384,12 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { } + /** + * readRecursivlyJSONContent. + * + * @param map Map of String to something + * @param data Map of String to Object + */ @SuppressWarnings({"rawtypes", "unchecked"}) public void readRecursivlyJSONContent(Map map, Map data) { for (Iterator iterator = map.keySet().iterator(); iterator.hasNext();) {