From 78a5a8cd584f5bcd8c68a93f10a57fbd726f644b Mon Sep 17 00:00:00 2001 From: liamfallon Date: Thu, 24 Sep 2020 16:12:50 +0100 Subject: Default should be an object on TOSCA properties Property default value is serialized to the database as Yaml and deserialized back into an object on a DB read. Issue-ID: POLICY-2844 Change-Id: I69f2843a93cd5f831359a0965223298b769498d9 Signed-off-by: liamfallon --- .../tosca/authorative/concepts/ToscaEntity.java | 6 +-- .../tosca/authorative/concepts/ToscaProperty.java | 4 +- .../tosca/simple/concepts/JpaToscaProperty.java | 29 ++++++++--- .../authorative/concepts/ToscaPropertyTest.java | 57 ++++++++++++++++++++++ 4 files changed, 83 insertions(+), 13 deletions(-) create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPropertyTest.java (limited to 'models-tosca') diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java index e588a59fe..b242bff65 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP Policy Model * ================================================================================ - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -88,7 +88,7 @@ public class ToscaEntity implements PfNameVersion { * * @param listOfMapsOfEntities the incoming list of maps of entities * @return The entities on a regular map - * @throws PfModelException on duplicate entity entries + * @throws PfModelRuntimeException on duplicate entity entries */ public static Map getEntityListMapAsMap( List> listOfMapsOfEntities) { @@ -114,7 +114,7 @@ public class ToscaEntity implements PfNameVersion { * * @param mapOfEntities the incoming list of maps of entities * @return The entities on a regular map - * @throws PfModelException on duplicate entity entries + * @throws PfModelRuntimeException on duplicate entity entries */ public static Map getEntityMapAsMap(Map mapOfEntities) { // Declare the return map diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaProperty.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaProperty.java index fd8a86a0d..59fbc8b22 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaProperty.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaProperty.java @@ -3,7 +3,7 @@ * ONAP Policy Model * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -50,7 +50,7 @@ public class ToscaProperty { @ApiModelProperty(name = "default") @SerializedName("default") - private String defaultValue; + private Object defaultValue; private boolean required = false; diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaProperty.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaProperty.java index 25d22661f..60e2fa05a 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaProperty.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaProperty.java @@ -35,14 +35,19 @@ import javax.persistence.Entity; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.Table; +import javax.ws.rs.core.Response; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; import org.apache.commons.lang3.ObjectUtils; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.common.utils.coder.StandardCoder; +import org.onap.policy.common.utils.coder.YamlJsonTranslator; import org.onap.policy.models.base.PfAuthorative; import org.onap.policy.models.base.PfConcept; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfKey; +import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.base.PfReferenceKey; import org.onap.policy.models.base.PfUtils; import org.onap.policy.models.base.PfValidationMessage; @@ -112,7 +117,7 @@ public class JpaToscaProperty extends PfConcept implements PfAuthorative toscaConstraints = new ArrayList<>(); @@ -196,9 +204,14 @@ public class JpaToscaProperty extends PfConcept implements PfAuthorative(); @@ -262,14 +275,14 @@ public class JpaToscaProperty extends PfConcept implements PfAuthorative testList = new ArrayList<>(); + property.setDefaultValue(testList); + jpaProperty = new JpaToscaProperty(property); + assertEquals("[]", jpaProperty.getDefaultValue()); + outProperty = jpaProperty.toAuthorative(); + assertEquals("[]", outProperty.getDefaultValue().toString()); + + testList.add("Foo"); + testList.add("Bar"); + jpaProperty = new JpaToscaProperty(property); + assertEquals("- Foo\n- Bar", jpaProperty.getDefaultValue()); + outProperty = jpaProperty.toAuthorative(); + assertEquals("[Foo, Bar]", outProperty.getDefaultValue().toString()); + } +} -- cgit 1.2.3-korg