diff options
author | sebdet <sebastien.determe@intl.att.com> | 2021-02-12 17:18:47 +0100 |
---|---|---|
committer | S�bastien Determe <sebastien.determe@intl.att.com> | 2021-02-17 17:38:08 +0000 |
commit | 3718a16bedbc4a5ecf2593abcb2075238fa99767 (patch) | |
tree | e8aa57765f3979934cca30dda28c203d236629bb /src/main | |
parent | ff40e4d25e810321265daadec438abd2a215951f (diff) |
Modify Backend for listing the policies
Improve Ui components to list policies + changes an existing camel route to expose the policy json schema properly. New files added to emulator for testing + comments added.
Now the Ui can show the policy config
Issue-ID: POLICY-3061
Signed-off-by: sebdet <sebastien.determe@intl.att.com>
Change-Id: Iacf9577a4ab2cc927d05ff267e7356d8410eb77a
Signed-off-by: sebdet <sebastien.determe@intl.att.com>
Diffstat (limited to 'src/main')
7 files changed, 56 insertions, 10 deletions
diff --git a/src/main/java/org/onap/policy/clamp/clds/config/AafConfiguration.java b/src/main/java/org/onap/policy/clamp/clds/config/AafConfiguration.java index 30ba6e6ae..9b6338e00 100644 --- a/src/main/java/org/onap/policy/clamp/clds/config/AafConfiguration.java +++ b/src/main/java/org/onap/policy/clamp/clds/config/AafConfiguration.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP CLAMP * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights + * Copyright (C) 2017-2018, 2021 AT&T Intellectual Property. All rights * reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -58,6 +58,7 @@ public class AafConfiguration { registration.addUrlPatterns("/restservices/clds/v2/templates/*"); registration.addUrlPatterns("/restservices/clds/v2/clampInformation/*"); registration.addUrlPatterns("/restservices/clds/v2/policyToscaModels/*"); + registration.addUrlPatterns("/restservices/clds/v2/policies/*"); registration.addUrlPatterns("/restservices/clds/v2/loop/*"); registration.setName("cadiFilter"); registration.setOrder(0); diff --git a/src/main/java/org/onap/policy/clamp/clds/tosca/ToscaYamlToJsonConvertor.java b/src/main/java/org/onap/policy/clamp/clds/tosca/ToscaYamlToJsonConvertor.java index d6b0a031f..4f718d5d7 100644 --- a/src/main/java/org/onap/policy/clamp/clds/tosca/ToscaYamlToJsonConvertor.java +++ b/src/main/java/org/onap/policy/clamp/clds/tosca/ToscaYamlToJsonConvertor.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP CLAMP * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights + * Copyright (C) 2018, 2021 AT&T Intellectual Property. All rights * reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -51,6 +51,7 @@ import org.yaml.snakeyaml.Yaml; * */ @Component +@Deprecated public class ToscaYamlToJsonConvertor { @Autowired diff --git a/src/main/java/org/onap/policy/clamp/clds/tosca/update/ToscaConverterWithDictionarySupport.java b/src/main/java/org/onap/policy/clamp/clds/tosca/update/ToscaConverterWithDictionarySupport.java index 3505c8b86..6702a6200 100644 --- a/src/main/java/org/onap/policy/clamp/clds/tosca/update/ToscaConverterWithDictionarySupport.java +++ b/src/main/java/org/onap/policy/clamp/clds/tosca/update/ToscaConverterWithDictionarySupport.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP CLAMP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights * reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -36,6 +36,13 @@ import org.onap.policy.clamp.loop.service.Service; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +/** + * This is the main class that must be used to convert a tosca to a json schema. + * This class adds feature to support the dictionary mechanism that enables json possible values extracted + * from the dictionary DB table. + * + * @see org.onap.policy.clamp.clds.tosca.update.ToscaConverterWithDictionarySupport#convertToscaToJsonSchemaObject + */ @Component public class ToscaConverterWithDictionarySupport { diff --git a/src/main/java/org/onap/policy/clamp/clds/tosca/update/parser/ToscaConverterToJsonSchema.java b/src/main/java/org/onap/policy/clamp/clds/tosca/update/parser/ToscaConverterToJsonSchema.java index c7cc7e7fa..5a9720a00 100644 --- a/src/main/java/org/onap/policy/clamp/clds/tosca/update/parser/ToscaConverterToJsonSchema.java +++ b/src/main/java/org/onap/policy/clamp/clds/tosca/update/parser/ToscaConverterToJsonSchema.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP CLAMP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights * reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -35,6 +35,15 @@ import org.onap.policy.clamp.clds.tosca.update.parser.metadata.ToscaMetadataPars import org.onap.policy.clamp.clds.tosca.update.templates.JsonTemplate; import org.onap.policy.clamp.loop.service.Service; +/** + * This class can be used to convert a tosca to a json schema. + * This class is not supposed to be used directly because it requires the json Schema templates + * (template conversion tosca type to json schema entry) but also the supported Tosca main type file. + * The class ToscaConverterWithDictionarySupport is more complete for the end user to be used (in the clamp context). + * + * @see org.onap.policy.clamp.clds.tosca.update.ToscaConverterWithDictionarySupport#convertToscaToJsonSchemaObject + * @see org.onap.policy.clamp.clds.tosca.update.parser.ToscaConverterToJsonSchema#getJsonSchemaOfToscaElement + */ public class ToscaConverterToJsonSchema { private LinkedHashMap<String, ToscaElement> components; private LinkedHashMap<String, JsonTemplate> templates; @@ -266,11 +275,12 @@ public class ToscaConverterToJsonSchema { // Native cases JsonObject itemContainer = new JsonObject(); String valueInEntrySchema = - this.extractSpecificFieldFromMap(toscaElementProperty, "entry_schema"); + this.extractSpecificFieldFromMap(toscaElementProperty, "entry_schema"); itemContainer.addProperty("type", valueInEntrySchema); propertiesInJson.add("items", itemContainer); propertiesInJson.addProperty("format", "tabs-top"); } + // MAP Case, for now nothing break; diff --git a/src/main/java/org/onap/policy/clamp/loop/template/PolicyModelsService.java b/src/main/java/org/onap/policy/clamp/loop/template/PolicyModelsService.java index c4182bd2f..fea58c552 100644 --- a/src/main/java/org/onap/policy/clamp/loop/template/PolicyModelsService.java +++ b/src/main/java/org/onap/policy/clamp/loop/template/PolicyModelsService.java @@ -29,6 +29,9 @@ import java.util.Collections; import java.util.List; import org.onap.policy.clamp.clds.tosca.ToscaSchemaConstants; import org.onap.policy.clamp.clds.tosca.ToscaYamlToJsonConvertor; +import org.onap.policy.clamp.clds.tosca.update.ToscaConverterWithDictionarySupport; +import org.onap.policy.clamp.clds.tosca.update.parser.ToscaConverterToJsonSchema; +import org.onap.policy.clamp.clds.util.JsonUtils; import org.onap.policy.clamp.policy.pdpgroup.PdpGroupsAnalyzer; import org.onap.policy.clamp.util.SemanticVersioning; import org.onap.policy.models.pdp.concepts.PdpGroups; @@ -43,8 +46,17 @@ import org.springframework.transaction.annotation.Transactional; @Service public class PolicyModelsService { private final PolicyModelsRepository policyModelsRepository; + /** + * This variable is there to support legacy saving of the tosca from the clamp UI. + */ private ToscaYamlToJsonConvertor toscaYamlToJsonConvertor; + /** + * This is the new tosca converter that must be used in clamp. + */ + @Autowired + private ToscaConverterWithDictionarySupport toscaConverterWithDictionarySupport; + @Autowired public PolicyModelsService(PolicyModelsRepository policyModelrepo, ToscaYamlToJsonConvertor convertor) { @@ -110,6 +122,22 @@ public class PolicyModelsService { return saveOrUpdatePolicyModel(thePolicyModel); } + /** + * This method retrieves the tosca model and convert it to a Json schema. + * That json schema is normally used by the UI. + * + * @param policyType The policy model type id + * @param policyTypeVersion The policy model type version + * @return A JsonObject with the json schema describing the tosca + */ + public JsonObject getPolicyModelJson(String policyType, String policyTypeVersion) { + PolicyModel thePolicyModel = getPolicyModel(policyType, policyTypeVersion); + // In the following use case we are not in the context of a closed loop, so the enrichment + // of the json cannot be done, that's why the serviceModel provided is NULL. + return toscaConverterWithDictionarySupport + .convertToscaToJsonSchemaObject(thePolicyModel.getPolicyModelTosca(), policyType, null); + } + public List<String> getAllPolicyModelTypes() { return policyModelsRepository.getAllPolicyModelType(); } diff --git a/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMerger.java b/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMerger.java index 0bd45cd33..7e3fe8cf4 100644 --- a/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMerger.java +++ b/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMerger.java @@ -55,7 +55,7 @@ public class PoliciesPdpMerger { } /** - * This method merges 2 JsonElement together. If the jsonToMerge is null nothign is changed. + * This method merges 2 JsonElement together. If the jsonToMerge is null nothing is changed. * * @param json The initial json that will received the data * @param jsonToMerge The json that will be added to the first json object @@ -101,4 +101,4 @@ public class PoliciesPdpMerger { policyJsonNode.get("type_version").getAsString()); mergeJsonElement(policyJsonNode, supportedPdpGroupsJson); } -} +}
\ No newline at end of file diff --git a/src/main/resources/clds/camel/rest/clamp-api-v2.xml b/src/main/resources/clds/camel/rest/clamp-api-v2.xml index e1f138b1d..7ca4f081e 100644 --- a/src/main/resources/clds/camel/rest/clamp-api-v2.xml +++ b/src/main/resources/clds/camel/rest/clamp-api-v2.xml @@ -1075,8 +1075,7 @@ </route> </get> <get uri="/v2/policyToscaModels/{policyModelType}/{policyModelVersion}" - outType="org.onap.policy.clamp.loop.template.PolicyModel" - produces="application/json"> + outType="com.google.gson.JsonObject" produces="application/json"> <route> <removeHeaders pattern="*" excludePattern="policyModelType|policyModelVersion"/> @@ -1086,7 +1085,7 @@ <to uri="bean:org.onap.policy.clamp.authorization.AuthorizationController?method=authorize(*,'tosca','','read')"/> <to - uri="bean:org.onap.policy.clamp.loop.template.PolicyModelsService?method=getPolicyModelByType(${header.policyModelType},${header.policyModelVersion})"/> + uri="bean:org.onap.policy.clamp.loop.template.PolicyModelsService?method=getPolicyModelJson(${header.policyModelType},${header.policyModelVersion})"/> <to uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=endLog()"/> <doCatch> |