summaryrefslogtreecommitdiffstats
path: root/src/main/java/org
diff options
context:
space:
mode:
authorsebdet <sebastien.determe@intl.att.com>2020-02-18 02:00:11 -0800
committerSébastien Determe <sebastien.determe@intl.att.com>2020-02-25 10:57:35 +0000
commitaa486be66b1c29ad2e953cb44d105ca1bde40b1c (patch)
treeb5893560b1eee8f1e456104deec7924f05e4fbfb /src/main/java/org
parent4e8e11afced0693e24074fd6bb8d5b2cace98ab6 (diff)
Modify the Ui
Modify the Ui to have a modify option in the menu so that the user can tune the loop instance Issue-ID: CLAMP-648 Change-Id: I57523bc1c3afaf5ca5a2acf5c59823df06fd4cd9 Signed-off-by: sebdet <sebastien.determe@intl.att.com>
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/onap/clamp/loop/template/PolicyModel.java9
-rw-r--r--src/main/java/org/onap/clamp/loop/template/PolicyModelsService.java78
2 files changed, 51 insertions, 36 deletions
diff --git a/src/main/java/org/onap/clamp/loop/template/PolicyModel.java b/src/main/java/org/onap/clamp/loop/template/PolicyModel.java
index d06cb8cff..fd0110c79 100644
--- a/src/main/java/org/onap/clamp/loop/template/PolicyModel.java
+++ b/src/main/java/org/onap/clamp/loop/template/PolicyModel.java
@@ -65,7 +65,7 @@ public class PolicyModel extends AuditEntity implements Serializable, Comparable
*/
@Id
@Expose
- @Column(name = "version")
+ @Column(name = "version",nullable = false)
private String version;
@Column(columnDefinition = "MEDIUMTEXT", name = "policy_tosca")
@@ -179,7 +179,10 @@ public class PolicyModel extends AuditEntity implements Serializable, Comparable
this.policyModelType = policyType;
this.policyModelTosca = policyModelTosca;
this.version = version;
- this.policyAcronym = policyAcronym;
+ this.policyAcronym=policyAcronym;
+ if (this.policyAcronym == null) {
+ this.policyAcronym = createDefaultPolicyAcronym(policyType);
+ }
}
/**
@@ -190,7 +193,7 @@ public class PolicyModel extends AuditEntity implements Serializable, Comparable
* @param version the version like 1.0.0
*/
public PolicyModel(String policyType, String policyModelTosca, String version) {
- this(policyType, policyModelTosca, version, createDefaultPolicyAcronym(policyType));
+ this(policyType, policyModelTosca, version, null);
}
public static String createDefaultPolicyAcronym(String policyType) {
diff --git a/src/main/java/org/onap/clamp/loop/template/PolicyModelsService.java b/src/main/java/org/onap/clamp/loop/template/PolicyModelsService.java
index 0a09dd8d7..ad9ce7078 100644
--- a/src/main/java/org/onap/clamp/loop/template/PolicyModelsService.java
+++ b/src/main/java/org/onap/clamp/loop/template/PolicyModelsService.java
@@ -24,6 +24,8 @@
package org.onap.clamp.loop.template;
import com.google.gson.JsonObject;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import org.onap.clamp.clds.tosca.ToscaSchemaConstants;
import org.onap.clamp.clds.tosca.ToscaYamlToJsonConvertor;
@@ -38,7 +40,7 @@ public class PolicyModelsService {
@Autowired
public PolicyModelsService(PolicyModelsRepository policyModelrepo,
- ToscaYamlToJsonConvertor convertor) {
+ ToscaYamlToJsonConvertor convertor) {
policyModelsRepository = policyModelrepo;
toscaYamlToJsonConvertor = convertor;
}
@@ -48,35 +50,45 @@ public class PolicyModelsService {
}
/**
- * Creates or updates the Tosca Policy Model.
+ * Creates the Tosca Policy Model from a policy tosca file,
+ * if the same type already exists in database, it increases the version automatically.
*
- * @param policyModelType
- * The policyModeltype in Tosca yaml
- * @param policyModel
- * The Policymodel object
- * @return The Policy Model
+ * @param policyModelType The policyModeltype in Tosca yaml
+ * @param policyModelTosca The Policymodel object
+ * @return The Policy Model created
*/
- public PolicyModel saveOrUpdateByPolicyModelType(String policyModelType,
- String policyModelTosca) {
+ public PolicyModel createNewPolicyModelFromTosca(String policyModelType,
+ String policyModelTosca) {
JsonObject jsonObject = toscaYamlToJsonConvertor.validateAndConvertToJson(policyModelTosca);
+ String policyModelTypeFromTosca = toscaYamlToJsonConvertor.getValueFromMetadata(jsonObject,
+ ToscaSchemaConstants.METADATA_POLICY_MODEL_TYPE);
+ String policyModelTypeToUse = policyModelTypeFromTosca != null ? policyModelTypeFromTosca : policyModelType;
+ Iterable<PolicyModel> models = getAllPolicyModelsByType(policyModelTypeToUse);
+ Collections.sort((List<PolicyModel>) models);
+ PolicyModel newPolicyModel = new PolicyModel(policyModelTypeToUse, policyModelTosca,
+ SemanticVersioning.incrementMajorVersion(
+ ((ArrayList) models).isEmpty() ? null : ((ArrayList<PolicyModel>) models).get(0).getVersion()),
+ toscaYamlToJsonConvertor.getValueFromMetadata(jsonObject,
+ ToscaSchemaConstants.METADATA_ACRONYM));
+ return saveOrUpdatePolicyModel(newPolicyModel);
+ }
- String policyModelTypeName = toscaYamlToJsonConvertor.getValueFromMetadata(jsonObject,
- ToscaSchemaConstants.METADATA_POLICY_MODEL_TYPE);
- String acronym = toscaYamlToJsonConvertor.getValueFromMetadata(jsonObject,
- ToscaSchemaConstants.METADATA_ACRONYM);
- PolicyModel model = getPolicyModelByType(
- policyModelTypeName != null ? policyModelTypeName : policyModelType);
-
- if (model == null) {
- model = new PolicyModel(policyModelTypeName, policyModelTosca,
- SemanticVersioning.incrementMajorVersion(null), acronym);
- } else {
- model.setVersion(SemanticVersioning
- .incrementMajorVersion(model.getVersion() != null ? model.getVersion() : null));
- model.setPolicyModelType(policyModelTypeName);
- model.setPolicyAcronym(acronym);
- }
- return saveOrUpdatePolicyModel(model);
+ /**
+ * Update an existing Tosca Policy Model.
+ *
+ * @param policyModelType The policy Model type in Tosca yaml
+ * @param policyModelVersion The policy Version to update
+ * @param policyModelTosca The Policy Model tosca
+ * @return The Policy Model updated
+ */
+ public PolicyModel updatePolicyModelTosca(String policyModelType, String policyModelVersion,
+ String policyModelTosca) {
+ JsonObject jsonObject = toscaYamlToJsonConvertor.validateAndConvertToJson(policyModelTosca);
+ PolicyModel thePolicyModel = getPolicyModelByType(policyModelType, policyModelVersion);
+ thePolicyModel.setPolicyAcronym(toscaYamlToJsonConvertor.getValueFromMetadata(jsonObject,
+ ToscaSchemaConstants.METADATA_ACRONYM));
+ thePolicyModel.setPolicyModelTosca(policyModelTosca);
+ return saveOrUpdatePolicyModel(thePolicyModel);
}
public List<String> getAllPolicyModelTypes() {
@@ -95,19 +107,19 @@ public class PolicyModelsService {
return policyModelsRepository.findByPolicyModelType(type);
}
- public PolicyModel getPolicyModelByType(String type) {
- List<PolicyModel> list = policyModelsRepository.findByPolicyModelType(type);
- return list.stream().sorted().findFirst().orElse(null);
+ public PolicyModel getPolicyModelByType(String type, String version) {
+ return policyModelsRepository.findById(new PolicyModelId(type, version)).orElse(null);
}
/**
* Retrieves the Tosca model Yaml string.
*
- * @param type The PolicyModelType
+ * @param type The Policy Model Type
+ * @param version The policy model version
* @return The Tosca model Yaml string
*/
- public String getPolicyModelTosca(String type) {
- PolicyModel policyModel = getPolicyModelByType(type);
- return policyModel != null ? policyModel.getPolicyModelTosca() : null;
+ public String getPolicyModelTosca(String type, String version) {
+ return policyModelsRepository.findById(new PolicyModelId(type, version)).orElse(new PolicyModel())
+ .getPolicyModelTosca();
}
}