aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2020-03-19 15:28:49 +0000
committerliamfallon <liam.fallon@est.tech>2020-03-19 15:32:54 +0000
commit13a3cdebc5885440ea28f021f5cd6bd3ecac389e (patch)
tree9cb2c574fdf77172798b73cf5b161105a614d499
parent3a2564106ca6b3c01142f15d629c3289cad7b8ca (diff)
Allow fetch of old policy type verisons
Due to the problems with TOSCA and version handling, the filtering for policy types on old versions did not work. This change fixes that problem. Issue-ID: POLICY-2377 Change-Id: I462bd5710b9dea37475861d1021d28b2c7391a24 Signed-off-by: liamfallon <liam.fallon@est.tech>
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java42
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java9
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java79
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java25
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java106
5 files changed, 154 insertions, 107 deletions
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java b/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java
index b4d51d173..d259fa260 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java
@@ -30,6 +30,7 @@ import java.util.Map.Entry;
import java.util.NavigableMap;
import java.util.Set;
import java.util.TreeMap;
+import java.util.TreeSet;
import java.util.function.Function;
import javax.persistence.CascadeType;
@@ -153,7 +154,7 @@ public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> ex
public List<Map<String, A>> toAuthorative() {
// The returned list is a list of map singletons with one map for each map
// entry in the concept container
- List<Map<String, A>> toscaPolicyMapList = new ArrayList<>();
+ List<Map<String, A>> toscaConceptMapList = new ArrayList<>();
for (Entry<PfConceptKey, C> conceptEntry : getConceptMap().entrySet()) {
// Create a map to hold this entry
@@ -165,10 +166,10 @@ public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> ex
toscaPolicyMap.put(conceptEntry.getKey().getName(), authoritiveImpl.toAuthorative());
// Add the map to the returned list
- toscaPolicyMapList.add(toscaPolicyMap);
+ toscaConceptMapList.add(toscaPolicyMap);
}
- return toscaPolicyMapList;
+ return toscaConceptMapList;
}
@Override
@@ -217,6 +218,21 @@ public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> ex
}
}
+ /**
+ * Get an authorative list of the concepts in this container.
+ *
+ * @return the authorative list of concepts
+ */
+ public List<A> toAuthorativeList() {
+ List<A> toscaConceptList = new ArrayList<>();
+
+ for (Map<String, A> toscaConceptMap : toAuthorative()) {
+ toscaConceptList.addAll(toscaConceptMap.values());
+ }
+
+ return toscaConceptList;
+ }
+
@Override
public void clean() {
key.clean();
@@ -298,6 +314,26 @@ public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> ex
return 0;
}
+ /**
+ * Get all the concepts that match the given name and version.
+ *
+ * @param conceptKeyName the name of the concept, if null, return all names
+ * @param conceptKeyVersion the version of the concept, if null, return all versions
+ * @return conceptKeyVersion
+ */
+ public Set<C> getAllNamesAndVersions(final String conceptKeyName, final String conceptKeyVersion) {
+ if (conceptKeyName == null || conceptKeyVersion == null) {
+ return getAll(conceptKeyName, conceptKeyVersion);
+ } else {
+ final Set<C> returnSet = new TreeSet<>();
+ C foundConcept = get(conceptKeyName, conceptKeyVersion);
+ if (foundConcept != null) {
+ returnSet.add(foundConcept);
+ }
+ return returnSet;
+ }
+ }
+
@Override
public C get(final PfConceptKey conceptKey) {
if (conceptKey.isNullVersion()) {
diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java
index 8234741f6..a00363627 100644
--- a/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java
@@ -216,6 +216,15 @@ public class PfConceptContainerTest {
assertEquals(dacMap.get(NAME2), outMapList.get(2).get(NAME2));
assertEquals(dacMap.get(NAME3), outMapList.get(2).get(NAME3));
+ List<DummyAuthorativeConcept> outConceptList = container.toAuthorativeList();
+ assertEquals("Hello", outConceptList.get(0).getDescription());
+ assertEquals("Hi", outConceptList.get(1).getDescription());
+ assertEquals("Howdy", outConceptList.get(2).getDescription());
+ assertEquals("Ciao", outConceptList.get(3).getDescription());
+ assertEquals("name4", outConceptList.get(4).getName());
+ assertEquals("1.2.3", outConceptList.get(4).getVersion());
+ assertEquals("0.0.0", outConceptList.get(5).getVersion());
+
DummyBadPfConceptContainer badContainer = new DummyBadPfConceptContainer();
assertThatThrownBy(() -> badContainer.fromAuthorative(authorativeList))
.hasMessage("failed to instantiate instance of container concept class");
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java
index 65cce48db..a4a6e5942 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java
@@ -66,7 +66,7 @@ public class AuthorativeToscaProvider {
* @throws PfModelException on errors getting policy types
*/
public ToscaServiceTemplate getPolicyTypes(@NonNull final PfDao dao, final String name, final String version)
- throws PfModelException {
+ throws PfModelException {
LOGGER.debug("->getPolicyTypes: name={}, version={}", name, version);
@@ -88,15 +88,15 @@ public class AuthorativeToscaProvider {
* @throws PfModelException on errors getting policy types
*/
public List<ToscaPolicyType> getPolicyTypeList(@NonNull final PfDao dao, final String name, final String version)
- throws PfModelException {
+ throws PfModelException {
LOGGER.debug("->getPolicyTypeList: name={}, version={}", name, version);
List<ToscaPolicyType> policyTypeList;
try {
- policyTypeList = new ArrayList<>(new SimpleToscaProvider().getPolicyTypes(dao, name, version)
- .toAuthorative().getPolicyTypes().values());
+ policyTypeList = new ArrayList<>(
+ new SimpleToscaProvider().getPolicyTypes(dao, name, version).toAuthorative().getPolicyTypes().values());
} catch (PfModelRuntimeException pfme) {
return handlePfModelRuntimeException(pfme);
}
@@ -114,36 +114,36 @@ public class AuthorativeToscaProvider {
* @throws PfModelException on errors getting policy types
*/
public ToscaServiceTemplate getFilteredPolicyTypes(@NonNull final PfDao dao,
- @NonNull final ToscaPolicyTypeFilter filter) throws PfModelException {
+ @NonNull final ToscaPolicyTypeFilter filter) throws PfModelException {
LOGGER.debug("->getFilteredPolicyTypes: filter={}", filter);
SimpleToscaProvider simpleToscaProvider = new SimpleToscaProvider();
final JpaToscaServiceTemplate dbServiceTemplate = simpleToscaProvider.getPolicyTypes(dao, null, null);
- List<ToscaPolicyType> filteredPolicyTypes =
- new ArrayList<>(dbServiceTemplate.toAuthorative().getPolicyTypes().values());
+ List<ToscaPolicyType> filteredPolicyTypes = dbServiceTemplate.getPolicyTypes().toAuthorativeList();
filteredPolicyTypes = filter.filter(filteredPolicyTypes);
if (CollectionUtils.isEmpty(filteredPolicyTypes)) {
throw new PfModelRuntimeException(Response.Status.NOT_FOUND,
- "policy types for filter " + filter.toString() + " do not exist");
+ "policy types for filter " + filter.toString() + " do not exist");
}
JpaToscaServiceTemplate filteredServiceTemplate = new JpaToscaServiceTemplate();
for (ToscaPolicyType policyType : filteredPolicyTypes) {
JpaToscaServiceTemplate cascadedServiceTemplate = simpleToscaProvider
- .getCascadedPolicyTypes(dbServiceTemplate, policyType.getName(), policyType.getVersion());
+ .getCascadedPolicyTypes(dbServiceTemplate, policyType.getName(), policyType.getVersion());
filteredServiceTemplate =
- ToscaServiceTemplateUtils.addFragment(filteredServiceTemplate, cascadedServiceTemplate);
+ ToscaServiceTemplateUtils.addFragment(filteredServiceTemplate, cascadedServiceTemplate);
}
ToscaServiceTemplate returnServiceTemplate = filteredServiceTemplate.toAuthorative();
LOGGER.debug("<-getFilteredPolicyTypes: filter={}, serviceTemplate={}", filter, returnServiceTemplate);
return returnServiceTemplate;
+
}
/**
@@ -155,14 +155,14 @@ public class AuthorativeToscaProvider {
* @throws PfModelException on errors getting policy types
*/
public List<ToscaPolicyType> getFilteredPolicyTypeList(@NonNull final PfDao dao,
- @NonNull final ToscaPolicyTypeFilter filter) throws PfModelException {
+ @NonNull final ToscaPolicyTypeFilter filter) throws PfModelException {
LOGGER.debug("->getFilteredPolicyTypeList: filter={}", filter);
List<ToscaPolicyType> filteredPolicyTypeList = filter.filter(getPolicyTypeList(dao, null, null));
LOGGER.debug("<-getFilteredPolicyTypeList: filter={}, filteredPolicyTypeList={}", filter,
- filteredPolicyTypeList);
+ filteredPolicyTypeList);
return filteredPolicyTypeList;
}
@@ -176,12 +176,12 @@ public class AuthorativeToscaProvider {
* @throws PfModelException on errors creating policy types
*/
public ToscaServiceTemplate createPolicyTypes(@NonNull final PfDao dao,
- @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
+ @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
LOGGER.debug("->createPolicyTypes: serviceTemplate={}", serviceTemplate);
ToscaServiceTemplate createdServiceTempalate = new SimpleToscaProvider()
- .createPolicyTypes(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative();
+ .createPolicyTypes(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative();
LOGGER.debug("<-createPolicyTypes: createdServiceTempalate={}", createdServiceTempalate);
return createdServiceTempalate;
@@ -196,12 +196,12 @@ public class AuthorativeToscaProvider {
* @throws PfModelException on errors updating policy types
*/
public ToscaServiceTemplate updatePolicyTypes(@NonNull final PfDao dao,
- @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
+ @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
LOGGER.debug("->updatePolicyTypes: serviceTempalate={}", serviceTemplate);
ToscaServiceTemplate updatedServiceTempalate = new SimpleToscaProvider()
- .updatePolicyTypes(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative();
+ .updatePolicyTypes(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative();
LOGGER.debug("<-updatePolicyTypes: updatedServiceTempalate={}", updatedServiceTempalate);
return updatedServiceTempalate;
@@ -217,15 +217,15 @@ public class AuthorativeToscaProvider {
* @throws PfModelException on errors deleting policy types
*/
public ToscaServiceTemplate deletePolicyType(@NonNull final PfDao dao, @NonNull final String name,
- @NonNull final String version) throws PfModelException {
+ @NonNull final String version) throws PfModelException {
LOGGER.debug("->deletePolicyType: name={}, version={}", name, version);
ToscaServiceTemplate deletedServiceTempalate =
- new SimpleToscaProvider().deletePolicyType(dao, new PfConceptKey(name, version)).toAuthorative();
+ new SimpleToscaProvider().deletePolicyType(dao, new PfConceptKey(name, version)).toAuthorative();
LOGGER.debug("<-deletePolicyType: name={}, version={}, deletedServiceTempalate={}", name, version,
- deletedServiceTempalate);
+ deletedServiceTempalate);
return deletedServiceTempalate;
}
@@ -239,11 +239,11 @@ public class AuthorativeToscaProvider {
* @throws PfModelException on errors getting policies
*/
public ToscaServiceTemplate getPolicies(@NonNull final PfDao dao, final String name, final String version)
- throws PfModelException {
+ throws PfModelException {
LOGGER.debug("->getPolicies: name={}, version={}", name, version);
ToscaServiceTemplate gotServiceTempalate =
- new SimpleToscaProvider().getPolicies(dao, name, version).toAuthorative();
+ new SimpleToscaProvider().getPolicies(dao, name, version).toAuthorative();
LOGGER.debug("<-getPolicies: name={}, version={}, gotServiceTempalate={}", name, version, gotServiceTempalate);
return gotServiceTempalate;
@@ -259,14 +259,14 @@ public class AuthorativeToscaProvider {
* @throws PfModelException on errors getting policies
*/
public List<ToscaPolicy> getPolicyList(@NonNull final PfDao dao, final String name, final String version)
- throws PfModelException {
+ throws PfModelException {
LOGGER.debug("->getPolicyList: name={}, version={}", name, version);
List<ToscaPolicy> policyList;
try {
policyList = asConceptList(new SimpleToscaProvider().getPolicies(dao, name, version).toAuthorative()
- .getToscaTopologyTemplate().getPolicies());
+ .getToscaTopologyTemplate().getPolicies());
} catch (PfModelRuntimeException pfme) {
return handlePfModelRuntimeException(pfme);
}
@@ -284,32 +284,31 @@ public class AuthorativeToscaProvider {
* @throws PfModelException on errors getting policies
*/
public ToscaServiceTemplate getFilteredPolicies(@NonNull final PfDao dao, @NonNull final ToscaPolicyFilter filter)
- throws PfModelException {
+ throws PfModelException {
LOGGER.debug("->getFilteredPolicies: filter={}", filter);
String version = ToscaPolicyFilter.LATEST_VERSION.equals(filter.getVersion()) ? null : filter.getVersion();
SimpleToscaProvider simpleToscaProvider = new SimpleToscaProvider();
final JpaToscaServiceTemplate dbServiceTemplate =
- simpleToscaProvider.getPolicies(dao, filter.getName(), version);
+ simpleToscaProvider.getPolicies(dao, filter.getName(), version);
- List<ToscaPolicy> filteredPolicies =
- asConceptList(dbServiceTemplate.toAuthorative().getToscaTopologyTemplate().getPolicies());
+ List<ToscaPolicy> filteredPolicies = dbServiceTemplate.getTopologyTemplate().getPolicies().toAuthorativeList();
filteredPolicies = filter.filter(filteredPolicies);
if (CollectionUtils.isEmpty(filteredPolicies)) {
throw new PfModelRuntimeException(Response.Status.NOT_FOUND,
- "policies for filter " + filter.toString() + " do not exist");
+ "policies for filter " + filter.toString() + " do not exist");
}
JpaToscaServiceTemplate filteredServiceTemplate = new JpaToscaServiceTemplate();
for (ToscaPolicy policy : filteredPolicies) {
JpaToscaServiceTemplate cascadedServiceTemplate =
- simpleToscaProvider.getCascadedPolicies(dbServiceTemplate, policy.getName(), policy.getVersion());
+ simpleToscaProvider.getCascadedPolicies(dbServiceTemplate, policy.getName(), policy.getVersion());
filteredServiceTemplate =
- ToscaServiceTemplateUtils.addFragment(filteredServiceTemplate, cascadedServiceTemplate);
+ ToscaServiceTemplateUtils.addFragment(filteredServiceTemplate, cascadedServiceTemplate);
}
ToscaServiceTemplate returnServiceTemplate = filteredServiceTemplate.toAuthorative();
@@ -327,7 +326,7 @@ public class AuthorativeToscaProvider {
* @throws PfModelException on errors getting policies
*/
public List<ToscaPolicy> getFilteredPolicyList(@NonNull final PfDao dao, @NonNull final ToscaPolicyFilter filter)
- throws PfModelException {
+ throws PfModelException {
LOGGER.debug("->getFilteredPolicyList: filter={}", filter);
String version = ToscaPolicyFilter.LATEST_VERSION.equals(filter.getVersion()) ? null : filter.getVersion();
@@ -347,12 +346,12 @@ public class AuthorativeToscaProvider {
* @throws PfModelException on errors creating policies
*/
public ToscaServiceTemplate createPolicies(@NonNull final PfDao dao,
- @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
+ @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
LOGGER.debug("->createPolicies: serviceTempalate={}", serviceTemplate);
- ToscaServiceTemplate createdServiceTempalate = new SimpleToscaProvider()
- .createPolicies(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative();
+ ToscaServiceTemplate createdServiceTempalate =
+ new SimpleToscaProvider().createPolicies(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative();
LOGGER.debug("<-createPolicies: createdServiceTempalate={}", createdServiceTempalate);
return createdServiceTempalate;
@@ -367,12 +366,12 @@ public class AuthorativeToscaProvider {
* @throws PfModelException on errors updating policies
*/
public ToscaServiceTemplate updatePolicies(@NonNull final PfDao dao,
- @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
+ @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
LOGGER.debug("->updatePolicies: serviceTempalate={}", serviceTemplate);
- ToscaServiceTemplate updatedServiceTempalate = new SimpleToscaProvider()
- .updatePolicies(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative();
+ ToscaServiceTemplate updatedServiceTempalate =
+ new SimpleToscaProvider().updatePolicies(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative();
LOGGER.debug("<-updatePolicies: updatedServiceTempalate={}", updatedServiceTempalate);
return updatedServiceTempalate;
@@ -388,15 +387,15 @@ public class AuthorativeToscaProvider {
* @throws PfModelException on errors deleting policies
*/
public ToscaServiceTemplate deletePolicy(@NonNull final PfDao dao, @NonNull final String name,
- @NonNull final String version) throws PfModelException {
+ @NonNull final String version) throws PfModelException {
LOGGER.debug("->deletePolicy: name={}, version={}", name, version);
ToscaServiceTemplate deletedServiceTempalate =
- new SimpleToscaProvider().deletePolicy(dao, new PfConceptKey(name, version)).toAuthorative();
+ new SimpleToscaProvider().deletePolicy(dao, new PfConceptKey(name, version)).toAuthorative();
LOGGER.debug("<-deletePolicy: name={}, version={}, deletedServiceTempalate={}", name, version,
- deletedServiceTempalate);
+ deletedServiceTempalate);
return deletedServiceTempalate;
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java
index 3f2ebe797..772fb9ee0 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java
@@ -24,8 +24,11 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Function;
+
import javax.ws.rs.core.Response;
+
import lombok.NonNull;
+
import org.apache.commons.collections4.CollectionUtils;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfConceptContainer;
@@ -142,7 +145,7 @@ public final class ToscaUtils {
* @param serviceTemplate the service template containing policy types to be checked
*/
public static void assertExist(final JpaToscaServiceTemplate serviceTemplate,
- final Function<JpaToscaServiceTemplate, String> checkerFunction) {
+ final Function<JpaToscaServiceTemplate, String> checkerFunction) {
String message = checkerFunction.apply(serviceTemplate);
if (message != null) {
throw new PfModelRuntimeException(Response.Status.NOT_FOUND, message);
@@ -155,7 +158,7 @@ public final class ToscaUtils {
* @param serviceTemplate the service template containing policy types to be checked
*/
public static boolean doExist(final JpaToscaServiceTemplate serviceTemplate,
- final Function<JpaToscaServiceTemplate, String> checkerFunction) {
+ final Function<JpaToscaServiceTemplate, String> checkerFunction) {
return checkerFunction.apply(serviceTemplate) == null;
}
@@ -217,8 +220,8 @@ public final class ToscaUtils {
* @return the entity set containing the ancestors of the incoming entity
*/
public static Collection<JpaToscaEntityType<ToscaEntity>> getEntityTypeAncestors(
- @NonNull PfConceptContainer<? extends PfConcept, ? extends PfNameVersion> entityTypes,
- @NonNull JpaToscaEntityType<?> entityType, @NonNull final PfValidationResult result) {
+ @NonNull PfConceptContainer<? extends PfConcept, ? extends PfNameVersion> entityTypes,
+ @NonNull JpaToscaEntityType<?> entityType, @NonNull final PfValidationResult result) {
PfConceptKey parentEntityTypeKey = entityType.getDerivedFrom();
if (parentEntityTypeKey == null || parentEntityTypeKey.getName().endsWith(ROOT_KEY_NAME_SUFFIX)) {
@@ -227,17 +230,17 @@ public final class ToscaUtils {
if (entityType.getKey().equals(parentEntityTypeKey)) {
result.addValidationMessage(new PfValidationMessage(entityType.getKey(), ToscaUtils.class,
- ValidationResult.INVALID, "entity cannot be an ancestor of itself"));
+ ValidationResult.INVALID, "entity cannot be an ancestor of itself"));
throw new PfModelRuntimeException(Response.Status.CONFLICT, result.toString());
}
@SuppressWarnings("unchecked")
Set<JpaToscaEntityType<ToscaEntity>> ancestorEntitySet = (Set<JpaToscaEntityType<ToscaEntity>>) entityTypes
- .getAll(parentEntityTypeKey.getName(), parentEntityTypeKey.getVersion());
+ .getAll(parentEntityTypeKey.getName(), parentEntityTypeKey.getVersion());
Set<JpaToscaEntityType<ToscaEntity>> ancestorEntitySetToReturn = new HashSet<>(ancestorEntitySet);
if (ancestorEntitySet.isEmpty()) {
result.addValidationMessage(new PfValidationMessage(entityType.getKey(), ToscaUtils.class,
- ValidationResult.INVALID, "parent " + parentEntityTypeKey.getId() + " of entity not found"));
+ ValidationResult.INVALID, "parent " + parentEntityTypeKey.getId() + " of entity not found"));
} else {
for (JpaToscaEntityType<?> filteredEntityType : ancestorEntitySet) {
ancestorEntitySetToReturn.addAll(getEntityTypeAncestors(entityTypes, filteredEntityType, result));
@@ -254,14 +257,14 @@ public final class ToscaUtils {
* @param entityVersion the version of the entity
*/
public static void getEntityTree(
- @NonNull final PfConceptContainer<? extends PfConcept, ? extends PfNameVersion> entityTypes,
- final String entityName, final String entityVersion) {
+ @NonNull final PfConceptContainer<? extends PfConcept, ? extends PfNameVersion> entityTypes,
+ final String entityName, final String entityVersion) {
PfValidationResult result = new PfValidationResult();
@SuppressWarnings("unchecked")
Set<JpaToscaEntityType<?>> filteredEntitySet =
- (Set<JpaToscaEntityType<?>>) entityTypes.getAll(entityName, entityVersion);
+ (Set<JpaToscaEntityType<?>>) entityTypes.getAllNamesAndVersions(entityName, entityVersion);
Set<JpaToscaEntityType<?>> filteredEntitySetToReturn = new HashSet<>(filteredEntitySet);
for (JpaToscaEntityType<?> filteredEntityType : filteredEntitySet) {
filteredEntitySetToReturn
@@ -273,6 +276,6 @@ public final class ToscaUtils {
}
entityTypes.getConceptMap().entrySet()
- .removeIf(entityEntry -> !filteredEntitySetToReturn.contains(entityEntry.getValue()));
+ .removeIf(entityEntry -> !filteredEntitySetToReturn.contains(entityEntry.getValue()));
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java
index 4937c5cca..f2da23c02 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java
@@ -118,7 +118,7 @@ public class SimpleToscaProviderTest {
serviceTemplate.getDataTypes().getConceptMap().put(dataType0Key, dataType0);
JpaToscaServiceTemplate createdServiceTemplate =
- new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate);
+ new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate);
assertEquals(1, createdServiceTemplate.getDataTypes().getConceptMap().size());
assertEquals(dataType0, createdServiceTemplate.getDataTypes().get(dataType0Key));
@@ -127,19 +127,19 @@ public class SimpleToscaProviderTest {
dataType0.setDescription("Updated Description");
JpaToscaServiceTemplate updatedServiceTemplate =
- new SimpleToscaProvider().updateDataTypes(pfDao, serviceTemplate);
+ new SimpleToscaProvider().updateDataTypes(pfDao, serviceTemplate);
assertEquals(dataType0, updatedServiceTemplate.getDataTypes().get(dataType0Key));
assertEquals("Updated Description", updatedServiceTemplate.getDataTypes().get(dataType0Key).getDescription());
JpaToscaServiceTemplate gotServiceTemplate =
- new SimpleToscaProvider().getDataTypes(pfDao, dataType0Key.getName(), dataType0Key.getVersion());
+ new SimpleToscaProvider().getDataTypes(pfDao, dataType0Key.getName(), dataType0Key.getVersion());
assertEquals(dataType0, gotServiceTemplate.getDataTypes().get(dataType0Key));
assertEquals("Updated Description", gotServiceTemplate.getDataTypes().get(dataType0Key).getDescription());
assertThatThrownBy(() -> new SimpleToscaProvider().deleteDataType(pfDao, new PfConceptKey("IDontExist:0.0.1")))
- .hasMessage("data type IDontExist:0.0.1 not found");
+ .hasMessage("data type IDontExist:0.0.1 not found");
JpaToscaServiceTemplate deletedServiceTemplate = new SimpleToscaProvider().deleteDataType(pfDao, dataType0Key);
@@ -160,7 +160,7 @@ public class SimpleToscaProviderTest {
assertEquals("Updated Description", deletedServiceTemplate.getDataTypes().get(dataType0Key).getDescription());
assertThatThrownBy(() -> new SimpleToscaProvider().deleteDataType(pfDao, dataType0Key))
- .hasMessage("no data types found");
+ .hasMessage("no data types found");
// Create the data type again
new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate);
@@ -173,7 +173,7 @@ public class SimpleToscaProviderTest {
new SimpleToscaProvider().createPolicyTypes(pfDao, updatedServiceTemplate);
assertThatThrownBy(() -> new SimpleToscaProvider().deleteDataType(pfDao, dataType0Key))
- .hasMessage("data type DataType0:0.0.1 is in use, it is referenced in policy type pt0:0.0.2");
+ .hasMessage("data type DataType0:0.0.1 is in use, it is referenced in policy type pt0:0.0.2");
JpaToscaDataType dataType0v2 = new JpaToscaDataType(new PfConceptKey("DataType0:0.0.2"));
updatedServiceTemplate.getDataTypes().getConceptMap().put(dataType0v2.getKey(), dataType0v2);
@@ -185,7 +185,7 @@ public class SimpleToscaProviderTest {
assertEquals("Updated Description", deletedServiceTemplate.getDataTypes().get(dataType0Key).getDescription());
assertThatThrownBy(() -> new SimpleToscaProvider().deleteDataType(pfDao, dataType0Key))
- .hasMessage("data type DataType0:0.0.1 is in use, it is referenced in policy type pt0:0.0.2");
+ .hasMessage("data type DataType0:0.0.1 is in use, it is referenced in policy type pt0:0.0.2");
JpaToscaDataType dataType1 = new JpaToscaDataType(new PfConceptKey("DataType1:0.0.3"));
JpaToscaProperty prop1 = new JpaToscaProperty(new PfReferenceKey(dataType1.getKey(), "prop1"));
@@ -195,7 +195,7 @@ public class SimpleToscaProviderTest {
new SimpleToscaProvider().createDataTypes(pfDao, updatedServiceTemplate);
assertThatThrownBy(() -> new SimpleToscaProvider().deleteDataType(pfDao, dataType0v2.getKey()))
- .hasMessage("data type DataType0:0.0.2 is in use, it is referenced in data type DataType1:0.0.3");
+ .hasMessage("data type DataType0:0.0.2 is in use, it is referenced in data type DataType1:0.0.3");
}
@Test
@@ -215,7 +215,7 @@ public class SimpleToscaProviderTest {
serviceTemplate.getPolicyTypes().getConceptMap().put(policyType0Key, policyType0);
JpaToscaServiceTemplate createdServiceTemplate =
- new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate);
+ new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate);
assertEquals(1, createdServiceTemplate.getPolicyTypes().getConceptMap().size());
assertEquals(policyType0, createdServiceTemplate.getPolicyTypes().get(policyType0Key));
@@ -224,14 +224,14 @@ public class SimpleToscaProviderTest {
policyType0.setDescription("Updated Description");
JpaToscaServiceTemplate updatedServiceTemplate =
- new SimpleToscaProvider().updatePolicyTypes(pfDao, serviceTemplate);
+ new SimpleToscaProvider().updatePolicyTypes(pfDao, serviceTemplate);
assertEquals(policyType0, updatedServiceTemplate.getPolicyTypes().get(policyType0Key));
assertEquals("Updated Description",
- updatedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
+ updatedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
JpaToscaServiceTemplate gotServiceTemplate =
- new SimpleToscaProvider().getPolicyTypes(pfDao, policyType0Key.getName(), policyType0Key.getVersion());
+ new SimpleToscaProvider().getPolicyTypes(pfDao, policyType0Key.getName(), policyType0Key.getVersion());
assertEquals(policyType0, gotServiceTemplate.getPolicyTypes().get(policyType0Key));
assertEquals("Updated Description", gotServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
@@ -246,7 +246,7 @@ public class SimpleToscaProviderTest {
new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate);
assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key))
- .hasMessage("policy type PolicyType0:0.0.1 is in use, it is referenced in policy type pt1:0.0.2");
+ .hasMessage("policy type PolicyType0:0.0.1 is in use, it is referenced in policy type pt1:0.0.2");
serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate());
serviceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies());
@@ -261,10 +261,10 @@ public class SimpleToscaProviderTest {
new SimpleToscaProvider().createPolicies(pfDao, serviceTemplate);
assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key))
- .hasMessage("policy type PolicyType0:0.0.1 is in use, it is referenced in policy type pt1:0.0.2");
+ .hasMessage("policy type PolicyType0:0.0.1 is in use, it is referenced in policy type pt1:0.0.2");
assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(pfDao, pt1.getKey()))
- .hasMessage("policy type pt1:0.0.2 is in use, it is referenced in policy p1:0.0.1");
+ .hasMessage("policy type pt1:0.0.2 is in use, it is referenced in policy p1:0.0.1");
new SimpleToscaProvider().deletePolicy(pfDao, p1.getKey());
@@ -273,14 +273,14 @@ public class SimpleToscaProviderTest {
new SimpleToscaProvider().deletePolicy(pfDao, p0.getKey());
JpaToscaServiceTemplate deletedServiceTemplate =
- new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key);
+ new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key);
assertEquals(policyType0, deletedServiceTemplate.getPolicyTypes().get(policyType0Key));
assertEquals("Updated Description",
- deletedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
+ deletedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key))
- .hasMessage("no policy types found");
+ .hasMessage("no policy types found");
}
@Test
@@ -294,7 +294,7 @@ public class SimpleToscaProviderTest {
serviceTemplate.getPolicyTypes().getConceptMap().put(policyType0Key, policyType0);
JpaToscaServiceTemplate createdServiceTemplate =
- new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate);
+ new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate);
assertEquals(policyType0, createdServiceTemplate.getPolicyTypes().get(policyType0Key));
assertEquals(null, createdServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
@@ -302,33 +302,33 @@ public class SimpleToscaProviderTest {
policyType0.setDescription("Updated Description");
JpaToscaServiceTemplate updatedServiceTemplate =
- new SimpleToscaProvider().updatePolicyTypes(pfDao, serviceTemplate);
+ new SimpleToscaProvider().updatePolicyTypes(pfDao, serviceTemplate);
assertEquals(policyType0, updatedServiceTemplate.getPolicyTypes().get(policyType0Key));
assertEquals("Updated Description",
- updatedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
+ updatedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
JpaToscaServiceTemplate gotServiceTemplate =
- new SimpleToscaProvider().getPolicyTypes(pfDao, policyType0Key.getName(), policyType0Key.getVersion());
+ new SimpleToscaProvider().getPolicyTypes(pfDao, policyType0Key.getName(), policyType0Key.getVersion());
assertEquals(policyType0, gotServiceTemplate.getPolicyTypes().get(policyType0Key));
assertEquals("Updated Description", gotServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
JpaToscaServiceTemplate deletedServiceTemplate =
- new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key);
+ new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key);
assertEquals(policyType0, deletedServiceTemplate.getPolicyTypes().get(policyType0Key));
assertEquals("Updated Description",
- deletedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
+ deletedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key))
- .hasMessage("no policy types found");
+ .hasMessage("no policy types found");
}
@Test
public void testPoliciesGet() throws Exception {
ToscaServiceTemplate toscaServiceTemplate =
- standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class);
+ standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class);
createPolicyTypes();
@@ -337,18 +337,18 @@ public class SimpleToscaProviderTest {
assertNotNull(originalServiceTemplate);
JpaToscaServiceTemplate createdServiceTemplate =
- new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate);
+ new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate);
assertEquals(originalServiceTemplate.getTopologyTemplate().getPolicies(),
- createdServiceTemplate.getTopologyTemplate().getPolicies());
+ createdServiceTemplate.getTopologyTemplate().getPolicies());
PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0");
JpaToscaServiceTemplate gotServiceTemplate =
- new SimpleToscaProvider().getPolicies(pfDao, policyKey.getName(), policyKey.getVersion());
+ new SimpleToscaProvider().getPolicies(pfDao, policyKey.getName(), policyKey.getVersion());
assertEquals(originalServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey),
- gotServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey));
+ gotServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey));
JpaToscaServiceTemplate deletedServiceTemplate = new SimpleToscaProvider().deletePolicy(pfDao, policyKey);
assertEquals(1, deletedServiceTemplate.getTopologyTemplate().getPolicies().getConceptMap().size());
@@ -357,7 +357,7 @@ public class SimpleToscaProviderTest {
@Test
public void testPolicyCreate() throws Exception {
ToscaServiceTemplate toscaServiceTemplate =
- standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class);
+ standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class);
createPolicyTypes();
@@ -366,16 +366,16 @@ public class SimpleToscaProviderTest {
assertNotNull(originalServiceTemplate);
JpaToscaServiceTemplate createdServiceTemplate =
- new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate);
+ new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate);
assertEquals(originalServiceTemplate.getTopologyTemplate().getPolicies(),
- createdServiceTemplate.getTopologyTemplate().getPolicies());
+ createdServiceTemplate.getTopologyTemplate().getPolicies());
}
@Test
public void testPolicyUpdate() throws Exception {
ToscaServiceTemplate toscaServiceTemplate =
- standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class);
+ standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class);
createPolicyTypes();
@@ -384,7 +384,7 @@ public class SimpleToscaProviderTest {
assertNotNull(originalServiceTemplate);
JpaToscaServiceTemplate updatedServiceTemplate =
- new SimpleToscaProvider().updatePolicies(pfDao, originalServiceTemplate);
+ new SimpleToscaProvider().updatePolicies(pfDao, originalServiceTemplate);
assertEquals(originalServiceTemplate, updatedServiceTemplate);
}
@@ -392,7 +392,7 @@ public class SimpleToscaProviderTest {
@Test
public void testPoliciesDelete() throws Exception {
ToscaServiceTemplate toscaServiceTemplate =
- standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class);
+ standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class);
createPolicyTypes();
@@ -401,26 +401,26 @@ public class SimpleToscaProviderTest {
assertNotNull(originalServiceTemplate);
JpaToscaServiceTemplate createdServiceTemplate =
- new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate);
+ new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate);
assertEquals(originalServiceTemplate.getTopologyTemplate(), createdServiceTemplate.getTopologyTemplate());
PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0");
assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicy(pfDao, new PfConceptKey("IDontExist:0.0.1")))
- .hasMessage("policy IDontExist:0.0.1 not found");
+ .hasMessage("policy IDontExist:0.0.1 not found");
JpaToscaServiceTemplate deletedServiceTemplate = new SimpleToscaProvider().deletePolicy(pfDao, policyKey);
assertEquals(originalServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey),
- deletedServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey));
+ deletedServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey));
assertThatThrownBy(() -> {
new SimpleToscaProvider().getPolicies(pfDao, policyKey.getName(), policyKey.getVersion());
}).hasMessage("policies for onap.restart.tca:1.0.0 do not exist");
assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicy(pfDao, policyKey))
- .hasMessage("no policies found");
+ .hasMessage("no policies found");
}
@Test
@@ -428,21 +428,21 @@ public class SimpleToscaProviderTest {
JpaToscaServiceTemplate testServiceTemplate = new JpaToscaServiceTemplate();
assertThatThrownBy(() -> new SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate))
- .hasMessage("topology template not specified on service template");
+ .hasMessage("topology template not specified on service template");
testServiceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate());
assertThatThrownBy(() -> new SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate))
- .hasMessage("no policies specified on topology template of service template");
+ .hasMessage("no policies specified on topology template of service template");
testServiceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies());
assertThatThrownBy(() -> new SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate))
- .hasMessage("list of policies specified on topology template of service template is empty");
+ .hasMessage("list of policies specified on topology template of service template is empty");
}
@Test
public void testGetServiceTemplate() throws PfModelException {
assertThatThrownBy(() -> new SimpleToscaProvider().getServiceTemplate(pfDao))
- .hasMessage("service template not found in database");
+ .hasMessage("service template not found in database");
}
@Test
@@ -453,8 +453,8 @@ public class SimpleToscaProviderTest {
serviceTemplateFragment.getPolicyTypes().getConceptMap().put(badPt.getKey(), badPt);
assertThatThrownBy(() -> new SimpleToscaProvider().appendToServiceTemplate(pfDao, serviceTemplateFragment))
- .hasMessageContaining(
- "key on concept entry PfConceptKey(name=NULL, version=0.0.0) may not be the null key");
+ .hasMessageContaining(
+ "key on concept entry PfConceptKey(name=NULL, version=0.0.0) may not be the null key");
}
@Test
@@ -500,7 +500,7 @@ public class SimpleToscaProviderTest {
serviceTemplate.getDataTypes().getConceptMap().put(p02.getKey(), p02);
new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate);
- gotSt = new SimpleToscaProvider().getDataTypes(pfDao, p01.getName(), p01.getVersion());
+ gotSt = new SimpleToscaProvider().getDataTypes(pfDao, p01.getName(), null);
assertEquals(p01, gotSt.getDataTypes().get(p01.getKey()));
assertEquals(p02, gotSt.getDataTypes().get(p01.getName()));
@@ -542,7 +542,7 @@ public class SimpleToscaProviderTest {
}).hasMessageMatching("policy types for hello:0.0.1 do not exist");
JpaToscaServiceTemplate gotSt =
- new SimpleToscaProvider().getPolicyTypes(pfDao, pt01.getName(), pt01.getVersion());
+ new SimpleToscaProvider().getPolicyTypes(pfDao, pt01.getName(), pt01.getVersion());
assertEquals(pt01, gotSt.getPolicyTypes().get(pt01.getKey()));
assertEquals(pt01, gotSt.getPolicyTypes().get(pt01.getName()));
@@ -557,7 +557,7 @@ public class SimpleToscaProviderTest {
serviceTemplate.getPolicyTypes().getConceptMap().put(pt02.getKey(), pt02);
new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate);
- gotSt = new SimpleToscaProvider().getPolicyTypes(pfDao, pt01.getName(), pt01.getVersion());
+ gotSt = new SimpleToscaProvider().getPolicyTypes(pfDao, pt01.getName(), null);
assertEquals(pt01, gotSt.getPolicyTypes().get(pt01.getKey()));
assertEquals(pt02, gotSt.getPolicyTypes().get(pt01.getName()));
@@ -621,7 +621,7 @@ public class SimpleToscaProviderTest {
serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(p02.getKey(), p02);
new SimpleToscaProvider().createPolicies(pfDao, serviceTemplate);
- gotSt = new SimpleToscaProvider().getPolicies(pfDao, p01.getName(), p01.getVersion());
+ gotSt = new SimpleToscaProvider().getPolicies(pfDao, p01.getName(), null);
assertEquals(p01, gotSt.getTopologyTemplate().getPolicies().get(p01.getKey()));
assertEquals(p02, gotSt.getTopologyTemplate().getPolicies().get(p01.getName()));
@@ -774,12 +774,12 @@ public class SimpleToscaProviderTest {
}
private void createPolicyTypes() throws CoderException, PfModelException {
- Object yamlObject = new Yaml().load(
- ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml"));
+ Object yamlObject = new Yaml()
+ .load(ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml"));
String yamlAsJsonString = new StandardCoder().encode(yamlObject);
ToscaServiceTemplate toscaServiceTemplatePolicyType =
- standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
+ standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
assertNotNull(toscaServiceTemplatePolicyType);
new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplatePolicyType);