summaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rwxr-xr-xsrc/main/java/org/onap/clamp/clds/util/drawing/Painter.java7
-rw-r--r--src/main/java/org/onap/clamp/loop/LoopController.java30
-rw-r--r--src/main/java/org/onap/clamp/loop/LoopService.java10
-rw-r--r--src/main/java/org/onap/clamp/loop/template/PolicyModelsService.java43
-rw-r--r--src/main/java/org/onap/clamp/policy/operational/LegacyOperationalPolicy.java2
-rw-r--r--src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java14
-rw-r--r--src/main/java/org/onap/clamp/tosca/Dictionary.java13
-rw-r--r--src/main/java/org/onap/clamp/tosca/DictionaryService.java26
8 files changed, 87 insertions, 58 deletions
diff --git a/src/main/java/org/onap/clamp/clds/util/drawing/Painter.java b/src/main/java/org/onap/clamp/clds/util/drawing/Painter.java
index 5ec59dbaf..509d4e41c 100755
--- a/src/main/java/org/onap/clamp/clds/util/drawing/Painter.java
+++ b/src/main/java/org/onap/clamp/clds/util/drawing/Painter.java
@@ -83,13 +83,12 @@ public class Painter {
for (MicroServicePolicy ms : microServices) {
ib.arrow().rectangle(ms.getName(),
- RectTypes.MICROSERVICE, ms.getPolicyModel().getPolicyAcronym()).arrow();
+ RectTypes.MICROSERVICE, ms.getPolicyModel().getPolicyAcronym());
}
for (OperationalPolicy policy : policies) {
- ib.arrow().rectangle(policy.getName(), RectTypes.POLICY, policy.getPolicyModel().getPolicyAcronym())
- .arrow();
+ ib.arrow().rectangle(policy.getName(), RectTypes.POLICY, policy.getPolicyModel().getPolicyAcronym());
}
- ib.circle("stop-circle", THICK_LINE);
+ ib.arrow().circle("stop-circle", THICK_LINE);
}
private void adjustGraphics2DProperties() {
diff --git a/src/main/java/org/onap/clamp/loop/LoopController.java b/src/main/java/org/onap/clamp/loop/LoopController.java
index 7b037da6d..7ee088c44 100644
--- a/src/main/java/org/onap/clamp/loop/LoopController.java
+++ b/src/main/java/org/onap/clamp/loop/LoopController.java
@@ -26,10 +26,8 @@ package org.onap.clamp.loop;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
-
import java.lang.reflect.Type;
import java.util.List;
-
import org.onap.clamp.clds.util.JsonUtils;
import org.onap.clamp.policy.microservice.MicroServicePolicy;
import org.onap.clamp.policy.operational.OperationalPolicy;
@@ -41,11 +39,10 @@ public class LoopController {
private final LoopService loopService;
private static final Type OPERATIONAL_POLICY_TYPE = new TypeToken<List<OperationalPolicy>>() {
- }
- .getType();
+ }.getType();
+
private static final Type MICROSERVICE_POLICY_TYPE = new TypeToken<List<MicroServicePolicy>>() {
- }
- .getType();
+ }.getType();
@Autowired
public LoopController(LoopService loopService) {
@@ -103,6 +100,27 @@ public class LoopController {
}
/**
+ * This method add an operational policy to a loop instance.
+ *
+ * @param loopName The loop name
+ * @param policyType The policy model type
+ * @param policyVersion The policy model version
+ * @return The loop modified
+ */
+ public Loop addOperationalPolicy(String loopName, String policyType, String policyVersion) {
+ return loopService.addOperationalPolicy(loopName, policyType, policyVersion);
+ }
+
+ /**
+ * This method deletes the loop.
+ *
+ * @param loopName The loop Name
+ */
+ public void deleteLoop(String loopName) {
+ loopService.deleteLoop(loopName);
+ }
+
+ /**
* Update one MicroService policy properties.
*
* @param loopName The loop name
diff --git a/src/main/java/org/onap/clamp/loop/LoopService.java b/src/main/java/org/onap/clamp/loop/LoopService.java
index 34be2038e..0be3132b0 100644
--- a/src/main/java/org/onap/clamp/loop/LoopService.java
+++ b/src/main/java/org/onap/clamp/loop/LoopService.java
@@ -102,8 +102,16 @@ public class LoopService {
loopsRepository.save(loop);
}
+ /**
+ * This method add an operational policy to a loop instance.
+ *
+ * @param loopName The loop name
+ * @param policyType The policy model type
+ * @param policyVersion The policy model version
+ * @return The loop modified
+ */
Loop addOperationalPolicy(String loopName, String policyType, String policyVersion) {
- Loop loop = findClosedLoopByName(loopName);
+ Loop loop = getLoop(loopName);
PolicyModel policyModel = policyModelsService.getPolicyModel(policyType, policyVersion);
if (policyModel == null) {
return null;
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 7e21cc390..aeea55dbb 100644
--- a/src/main/java/org/onap/clamp/loop/template/PolicyModelsService.java
+++ b/src/main/java/org/onap/clamp/loop/template/PolicyModelsService.java
@@ -44,7 +44,7 @@ public class PolicyModelsService {
@Autowired
public PolicyModelsService(PolicyModelsRepository policyModelrepo,
- ToscaYamlToJsonConvertor convertor) {
+ ToscaYamlToJsonConvertor convertor) {
policyModelsRepository = policyModelrepo;
toscaYamlToJsonConvertor = convertor;
}
@@ -72,40 +72,37 @@ public class PolicyModelsService {
/**
* Creates or updates the Tosca Policy Model.
*
- * @param policyModelType The policyModeltype in Tosca yaml
* @param policyModelTosca The Policymodel object
* @return The Policy Model created
*/
- public PolicyModel createNewPolicyModelFromTosca(String policyModelType,
- String policyModelTosca) {
+ public PolicyModel createNewPolicyModelFromTosca(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);
+ ToscaSchemaConstants.METADATA_POLICY_MODEL_TYPE);
+ Iterable<PolicyModel> models = getAllPolicyModelsByType(policyModelTypeFromTosca);
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));
+ PolicyModel newPolicyModel = new PolicyModel(policyModelTypeFromTosca, policyModelTosca,
+ SemanticVersioning.incrementMajorVersion(((ArrayList) models).isEmpty() ? null
+ : ((ArrayList<PolicyModel>) models).get(0).getVersion()),
+ toscaYamlToJsonConvertor.getValueFromMetadata(jsonObject,
+ ToscaSchemaConstants.METADATA_ACRONYM));
return saveOrUpdatePolicyModel(newPolicyModel);
}
/**
* Update an existing Tosca Policy Model.
*
- * @param policyModelType The policy Model type in Tosca yaml
+ * @param policyModelType The policy Model type in Tosca yaml
* @param policyModelVersion The policy Version to update
- * @param policyModelTosca The Policy Model tosca
+ * @param policyModelTosca The Policy Model tosca
* @return The Policy Model updated
*/
public PolicyModel updatePolicyModelTosca(String policyModelType, String policyModelVersion,
- String policyModelTosca) {
+ String policyModelTosca) {
JsonObject jsonObject = toscaYamlToJsonConvertor.validateAndConvertToJson(policyModelTosca);
PolicyModel thePolicyModel = getPolicyModelByType(policyModelType, policyModelVersion);
thePolicyModel.setPolicyAcronym(toscaYamlToJsonConvertor.getValueFromMetadata(jsonObject,
- ToscaSchemaConstants.METADATA_ACRONYM));
+ ToscaSchemaConstants.METADATA_ACRONYM));
thePolicyModel.setPolicyModelTosca(policyModelTosca);
return saveOrUpdatePolicyModel(thePolicyModel);
}
@@ -133,13 +130,13 @@ public class PolicyModelsService {
/**
* Retrieves the Tosca model Yaml string.
*
- * @param type The Policy Model Type
+ * @param type The Policy Model Type
* @param version The policy model version
* @return The Tosca model Yaml string
*/
public String getPolicyModelTosca(String type, String version) {
- return policyModelsRepository.findById(new PolicyModelId(type, version)).orElse(new PolicyModel())
- .getPolicyModelTosca();
+ return policyModelsRepository.findById(new PolicyModelId(type, version))
+ .orElse(new PolicyModel()).getPolicyModelTosca();
}
/**
@@ -149,8 +146,8 @@ public class PolicyModelsService {
*/
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void createPolicyInDbIfNeeded(PolicyModel policyModel) {
- if (!policyModelsRepository
- .existsById(new PolicyModelId(policyModel.getPolicyModelType(), policyModel.getVersion()))) {
+ if (!policyModelsRepository.existsById(
+ new PolicyModelId(policyModel.getPolicyModelType(), policyModel.getVersion()))) {
policyModelsRepository.save(policyModel);
}
}
@@ -165,8 +162,8 @@ public class PolicyModelsService {
for (PolicyModel policyModel : policyModelList) {
JsonArray supportedPdpGroups = new JsonArray();
for (PdpGroup pdpGroup : pdpGroupList) {
- JsonObject supportedPdpGroup = pdpGroup.getSupportedSubgroups(policyModel.getPolicyModelType(),
- policyModel.getVersion());
+ JsonObject supportedPdpGroup = pdpGroup.getSupportedSubgroups(
+ policyModel.getPolicyModelType(), policyModel.getVersion());
if (supportedPdpGroup != null) {
supportedPdpGroups.add(supportedPdpGroup);
}
diff --git a/src/main/java/org/onap/clamp/policy/operational/LegacyOperationalPolicy.java b/src/main/java/org/onap/clamp/policy/operational/LegacyOperationalPolicy.java
index 725bfe88b..ff7777f7f 100644
--- a/src/main/java/org/onap/clamp/policy/operational/LegacyOperationalPolicy.java
+++ b/src/main/java/org/onap/clamp/policy/operational/LegacyOperationalPolicy.java
@@ -173,7 +173,7 @@ public class LegacyOperationalPolicy {
* @param loop The parent loop object
*/
public static void preloadConfiguration(JsonObject configurationsJson, Loop loop) {
- if (configurationsJson.entrySet().isEmpty()) {
+ if (configurationsJson != null && configurationsJson.entrySet().isEmpty()) {
JsonObject controlLoopName = new JsonObject();
controlLoopName.addProperty("controlLoopName",
loop != null ? loop.getName() : "Empty (NO loop loaded yet)");
diff --git a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java
index 52b877208..1c7840579 100644
--- a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java
+++ b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java
@@ -32,7 +32,6 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;
import com.google.gson.annotations.Expose;
-
import java.io.IOException;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
@@ -40,7 +39,6 @@ import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
-
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
@@ -50,7 +48,6 @@ import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
-
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.onap.clamp.dao.model.jsontype.StringJsonUserType;
@@ -94,12 +91,13 @@ public class OperationalPolicy extends Policy implements Serializable {
/**
* The constructor.
- * @param name The name of the operational policy
+ *
+ * @param name The name of the operational policy
* @param loop The loop that uses this operational policy
* @param configurationsJson The operational policy property in the format of
- * json
+ * json
* @param policyModel The policy model associated if any, can be null
- * @param loopElementModel The loop element from which this instance is supposed to be created
+ * @param loopElementModel The loop element from which this instance is supposed to be created
*/
public OperationalPolicy(String name, Loop loop, JsonObject configurationsJson, PolicyModel policyModel,
LoopElementModel loopElementModel) {
@@ -108,7 +106,9 @@ public class OperationalPolicy extends Policy implements Serializable {
this.setPolicyModel(policyModel);
this.setConfigurationsJson(configurationsJson);
this.setLoopElementModel(loopElementModel);
- LegacyOperationalPolicy.preloadConfiguration(configurationsJson, loop);
+ if (policyModel != null && policyModel.getPolicyModelType().contains("legacy")) {
+ LegacyOperationalPolicy.preloadConfiguration(configurationsJson, loop);
+ }
try {
this.setJsonRepresentation(
OperationalPolicyRepresentationBuilder.generateOperationalPolicySchema(loop.getModelService()));
diff --git a/src/main/java/org/onap/clamp/tosca/Dictionary.java b/src/main/java/org/onap/clamp/tosca/Dictionary.java
index 44b5b6f68..cf514c4bd 100644
--- a/src/main/java/org/onap/clamp/tosca/Dictionary.java
+++ b/src/main/java/org/onap/clamp/tosca/Dictionary.java
@@ -65,9 +65,7 @@ public class Dictionary extends AuditEntity implements Serializable {
private String subDictionaryType;
@Expose
- @ManyToMany(
- fetch = FetchType.EAGER,
- cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
+ @ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.ALL})
@JoinTable(
name = "dictionary_to_dictionaryelements",
joinColumns = @JoinColumn(name = "dictionary_name", referencedColumnName = "name"),
@@ -150,6 +148,15 @@ public class Dictionary extends AuditEntity implements Serializable {
}
/**
+ * Method to set dictionaryElements.
+ *
+ * @param dictionaryElements The dictionary elements set
+ */
+ public void setDictionaryElements(Set<DictionaryElement> dictionaryElements) {
+ this.dictionaryElements = dictionaryElements;
+ }
+
+ /**
* Method to delete a dictionaryElement from the list.
*
* @param dictionaryElement The dictionary element
diff --git a/src/main/java/org/onap/clamp/tosca/DictionaryService.java b/src/main/java/org/onap/clamp/tosca/DictionaryService.java
index 5b24def98..98e3516fa 100644
--- a/src/main/java/org/onap/clamp/tosca/DictionaryService.java
+++ b/src/main/java/org/onap/clamp/tosca/DictionaryService.java
@@ -26,6 +26,7 @@ package org.onap.clamp.tosca;
import com.google.common.collect.Sets;
import java.util.List;
import java.util.Set;
+import java.util.stream.Collectors;
import javax.persistence.EntityNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -63,20 +64,19 @@ public class DictionaryService {
Set<DictionaryElement> newDictionaryElements = dictionary.getDictionaryElements();
- for (DictionaryElement dictionaryElement : newDictionaryElements) {
- if (dict.getDictionaryElements().contains(dictionaryElement)) {
- // Update the Dictionary Element
- getAndUpdateDictionaryElement(dict, dictionaryElement);
- } else {
- // Create the Dictionary Element
- dict.addDictionaryElements(getAndUpdateDictionaryElement(dict, dictionaryElement));
- dictionaryRepository.save(dict);
- }
+ if (newDictionaryElements != null && !newDictionaryElements.isEmpty()) {
+ Set<DictionaryElement> updatedDictionaryElements = newDictionaryElements.stream()
+ .map(dictionaryElement -> getAndUpdateDictionaryElement(dict, dictionaryElement))
+ .collect(Collectors.toSet());
+
+ dict.getDictionaryElements().forEach(dictElement -> {
+ if (!updatedDictionaryElements.contains(dictElement)) {
+ updatedDictionaryElements.add(dictElement);
+ }
+ });
+ dict.setDictionaryElements(updatedDictionaryElements);
}
-
- // Fetch again to get Dictionary with most recent updates.
- return dictionaryRepository.findById(dictionaryName).orElseThrow(
- () -> new EntityNotFoundException("Couldn't find Dictionary named: " + dictionaryName));
+ return dictionaryRepository.save(dict);
}