aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/onap/clamp/loop/template/PolicyModelsService.java43
-rw-r--r--src/main/java/org/onap/clamp/tosca/Dictionary.java13
-rw-r--r--src/main/java/org/onap/clamp/tosca/DictionaryService.java26
-rw-r--r--src/main/resources/clds/camel/rest/clamp-api-v2.xml7
4 files changed, 46 insertions, 43 deletions
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 7e21cc39..aeea55db 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/tosca/Dictionary.java b/src/main/java/org/onap/clamp/tosca/Dictionary.java
index 44b5b6f6..cf514c4b 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 5b24def9..98e3516f 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);
}
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 fe3f6bda..3ed272e7 100644
--- a/src/main/resources/clds/camel/rest/clamp-api-v2.xml
+++ b/src/main/resources/clds/camel/rest/clamp-api-v2.xml
@@ -910,13 +910,12 @@
</route>
</get>
- <post uri="/v2/policyToscaModels/{policyModelType}"
+ <post uri="/v2/policyToscaModels"
type="java.lang.String"
outType="org.onap.clamp.loop.template.PolicyModel"
consumes="plain/text" produces="application/json">
<route>
- <removeHeaders pattern="*"
- excludePattern="policyModelType" />
+ <removeHeaders pattern="*"/>
<doTry>
<to
uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=startLog(*, 'Upload New or Update Tosca Policy Model')" />
@@ -926,7 +925,7 @@
<simple>${body}</simple>
</setProperty>
<to
- uri="bean:org.onap.clamp.loop.template.PolicyModelsService?method=createNewPolicyModelFromTosca(${header.policyModelType},${exchangeProperty[PolicyModelTosca]})" />
+ uri="bean:org.onap.clamp.loop.template.PolicyModelsService?method=createNewPolicyModelFromTosca(${exchangeProperty[PolicyModelTosca]})" />
<to
uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=endLog()" />
<doCatch>