diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2022-12-08 12:41:49 +0000 |
---|---|---|
committer | Francesco Fiora <francesco.fiora@est.tech> | 2022-12-08 13:53:38 +0000 |
commit | 73088c5cd088a764b5d517de481392d91d9e8043 (patch) | |
tree | 13ccb070e8bdd13b3f0415c11e449c7a743524bc /models/src/main/java/org | |
parent | 2d3c8c987001ac176acb2feaadd885ceb1f7d234 (diff) |
Add support for instance properties
Issue-ID: POLICY-4483
Change-Id: I6ca953e05e74d68262507b393fb6415573fa3eab
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'models/src/main/java/org')
3 files changed, 77 insertions, 4 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java index 7033abac2..e5c85dd10 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java @@ -31,7 +31,6 @@ import lombok.ToString; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfUtils; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; /** @@ -65,7 +64,7 @@ public class AutomationCompositionElement { // A map indexed by the property name. Each map entry is the serialized value of the property, // which can be deserialized into an instance of the type of the property. - private Map<String, ToscaProperty> propertiesMap = new LinkedHashMap<>(); + private Map<String, Object> properties = new LinkedHashMap<>(); /** * Copy constructor, does a deep copy but as all fields here are immutable, it's just a regular copy. @@ -81,6 +80,6 @@ public class AutomationCompositionElement { this.orderedState = otherElement.orderedState; this.toscaServiceTemplateFragment = otherElement.toscaServiceTemplateFragment; this.description = otherElement.description; - this.propertiesMap = PfUtils.mapMap(otherElement.propertiesMap, UnaryOperator.identity()); + this.properties = PfUtils.mapMap(otherElement.properties, UnaryOperator.identity()); } } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java index 08d8ee06b..d8e4237b7 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * Copyright (C) 2021-2022 Nordix Foundation. * ================================================================================ * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ @@ -22,14 +22,19 @@ package org.onap.policy.clamp.models.acm.persistence.concepts; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import java.util.UUID; +import java.util.function.UnaryOperator; import javax.persistence.AttributeOverride; import javax.persistence.Column; +import javax.persistence.Convert; import javax.persistence.EmbeddedId; 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; @@ -39,11 +44,13 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; import org.onap.policy.common.parameters.annotations.NotNull; +import org.onap.policy.common.parameters.annotations.Valid; 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.PfReferenceKey; +import org.onap.policy.models.base.PfUtils; import org.onap.policy.models.base.validation.annotations.VerifyKey; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; @@ -95,6 +102,12 @@ public class JpaAutomationCompositionElement extends PfConcept implements PfAuth @Column private String description; + @Lob + @NotNull + @Valid + @Convert(converter = StringToMapConverter.class) + private Map<String, Object> properties; + /** * The Default Constructor creates a {@link JpaAutomationCompositionElement} object with a null key. */ @@ -141,6 +154,7 @@ public class JpaAutomationCompositionElement extends PfConcept implements PfAuth this.state = copyConcept.state; this.orderedState = copyConcept.orderedState; this.description = copyConcept.description; + this.properties = (copyConcept.properties != null ? new LinkedHashMap<>(copyConcept.properties) : null); } /** @@ -163,6 +177,7 @@ public class JpaAutomationCompositionElement extends PfConcept implements PfAuth element.setState(state); element.setOrderedState(orderedState != null ? orderedState : state.asOrderedState()); element.setDescription(description); + element.setProperties(PfUtils.mapMap(properties, UnaryOperator.identity())); return element; } @@ -180,6 +195,7 @@ public class JpaAutomationCompositionElement extends PfConcept implements PfAuth this.state = element.getState(); this.orderedState = element.getOrderedState(); this.description = element.getDescription(); + properties = PfUtils.mapMap(element.getProperties(), UnaryOperator.identity()); } @Override diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/StringToMapConverter.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/StringToMapConverter.java new file mode 100644 index 000000000..5dccd0862 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/StringToMapConverter.java @@ -0,0 +1,58 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2022 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.models.acm.persistence.concepts; + +import java.util.HashMap; +import java.util.Map; +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; +import javax.ws.rs.core.Response; +import org.onap.policy.common.utils.coder.Coder; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.common.utils.coder.StandardCoder; +import org.onap.policy.models.base.PfModelRuntimeException; + +@Converter(autoApply = true) +public class StringToMapConverter implements AttributeConverter<Map<String, Object>, String> { + + private static final Coder coder = new StandardCoder(); + + @Override + public String convertToDatabaseColumn(Map<String, Object> map) { + try { + return map == null ? null : coder.encode(map); + } catch (CoderException e) { + throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, e.getMessage(), e); + } + } + + @Override + public Map<String, Object> convertToEntityAttribute(String dbData) { + if (dbData == null) { + return new HashMap<>(); + } + try { + return coder.decode(dbData, Map.class); + } catch (CoderException e) { + throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, e.getMessage(), e); + } + } +} |