aboutsummaryrefslogtreecommitdiffstats
path: root/models-tosca/src/main/java
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2020-01-10 13:57:29 +0000
committerliamfallon <liam.fallon@est.tech>2020-01-10 13:57:34 +0000
commit39faa708e1f4e34930171dfcbd23876fe5c274e1 (patch)
treef6f9c364e4666bf6152c087fc63f9d37a082e2c4 /models-tosca/src/main/java
parenta3771d2efbf906cc4bf58683d4b2f40637d63ced (diff)
Fix policy-models to support data type properties
Data type properties are not being stored correctly into the database when MariaDB is used (it worked fine in unit tests in H2). Issue-ID: POLICY-2315 Change-Id: Ia901a070292b338154f3766f5fc7b91d656038df Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-tosca/src/main/java')
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataType.java7
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java2
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java21
3 files changed, 16 insertions, 14 deletions
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataType.java
index e9590072e..86d67e4d8 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataType.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataType.java
@@ -28,14 +28,18 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
+import javax.persistence.Lob;
import javax.persistence.Table;
+
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
+
import org.onap.policy.models.base.PfAuthorative;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfConceptKey;
@@ -67,6 +71,7 @@ public class JpaToscaDataType extends JpaToscaEntityType<ToscaDataType> implemen
private List<JpaToscaConstraint> constraints;
@ElementCollection
+ @Lob
private Map<String, JpaToscaProperty> properties;
/**
@@ -142,7 +147,7 @@ public class JpaToscaDataType extends JpaToscaEntityType<ToscaDataType> implemen
if (toscaDataType.getConstraints() != null) {
constraints = new ArrayList<>();
- for (ToscaConstraint toscaConstraint: toscaDataType.getConstraints()) {
+ for (ToscaConstraint toscaConstraint : toscaDataType.getConstraints()) {
constraints.add(JpaToscaConstraint.newInstance(toscaConstraint));
}
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java
index 0a7983c47..508b47060 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java
@@ -189,7 +189,7 @@ public class SimpleToscaProvider {
serviceTemplate.getPolicyTypes().getConceptMap().putAll(asConceptMap(jpaPolicyTypeList));
// Return all data types
- // TODO: In the next review, return just the data types used by the policy types on the policy type list
+ // TODO: In an upcoming review, return just the data types used by the policy types on the policy type list
List<JpaToscaDataType> jpaDataTypeList = dao.getFiltered(JpaToscaDataType.class, null, null);
if (!CollectionUtils.isEmpty(jpaDataTypeList)) {
serviceTemplate.setDataTypes(new JpaToscaDataTypes());
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 5ba42fef5..0e1d8e96b 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
@@ -20,6 +20,8 @@
package org.onap.policy.models.tosca.utils;
+import java.util.function.Function;
+
import javax.ws.rs.core.Response;
import org.onap.policy.models.base.PfModelRuntimeException;
@@ -102,8 +104,8 @@ public final class ToscaUtils {
* @param serviceTemplate the service template containing policy types to be checked
*/
public static void assertExist(final JpaToscaServiceTemplate serviceTemplate,
- final ToscaChecker<JpaToscaServiceTemplate> checkerFunction) {
- String message = checkerFunction.check(serviceTemplate);
+ final Function<JpaToscaServiceTemplate, String> checkerFunction) {
+ String message = checkerFunction.apply(serviceTemplate);
if (message != null) {
LOGGER.warn(message);
throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, message);
@@ -116,14 +118,14 @@ public final class ToscaUtils {
* @param serviceTemplate the service template containing policy types to be checked
*/
public static boolean doExist(final JpaToscaServiceTemplate serviceTemplate,
- final ToscaChecker<JpaToscaServiceTemplate> checkerFunction) {
- return checkerFunction.check(serviceTemplate) == null;
+ final Function<JpaToscaServiceTemplate, String> checkerFunction) {
+ return checkerFunction.apply(serviceTemplate) == null;
}
/**
* Check if data types have been specified correctly.
*/
- public static ToscaChecker<JpaToscaServiceTemplate> checkDataTypesExist() {
+ public static Function<JpaToscaServiceTemplate, String> checkDataTypesExist() {
return serviceTemplate -> {
if (serviceTemplate.getDataTypes() == null) {
return "no data types specified on service template";
@@ -140,7 +142,7 @@ public final class ToscaUtils {
/**
* Check if policy types have been specified correctly.
*/
- public static ToscaChecker<JpaToscaServiceTemplate> checkPolicyTypesExist() {
+ public static Function<JpaToscaServiceTemplate, String> checkPolicyTypesExist() {
return serviceTemplate -> {
if (serviceTemplate.getPolicyTypes() == null) {
return "no policy types specified on service template";
@@ -157,7 +159,7 @@ public final class ToscaUtils {
/**
* Check if policies have been specified correctly.
*/
- public static ToscaChecker<JpaToscaServiceTemplate> checkPoliciesExist() {
+ public static Function<JpaToscaServiceTemplate, String> checkPoliciesExist() {
return serviceTemplate -> {
if (serviceTemplate.getTopologyTemplate() == null) {
return "topology template not specified on service template";
@@ -174,9 +176,4 @@ public final class ToscaUtils {
return null;
};
}
-
- @FunctionalInterface
- interface ToscaChecker<T> {
- String check(final T serviceTemplate);
- }
}