From 252dc4ea8da89739ed18d6509ea72d2321676034 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Mon, 27 Jan 2020 19:33:25 -0500 Subject: Add service template persistence provider Persistence needs to be carried out at service template level in order to guarantee consistency of the service template in the database as much as possible. Therefire, service template lelve reading, writing, and delting is required. Issue-ID: POLICY-1402 Change-Id: I5be57c29381bf6ddc87afdbb64ddae66a5ea5e5f Signed-off-by: liamfallon --- .../policy/models/base/PfConceptContainer.java | 51 ++++++++++++++-------- 1 file changed, 33 insertions(+), 18 deletions(-) (limited to 'models-base') 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 b4c19cd16..2ecf8c1c6 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 @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -30,16 +30,21 @@ import java.util.Map.Entry; import java.util.NavigableMap; import java.util.Set; import java.util.TreeMap; + import javax.persistence.CascadeType; import javax.persistence.EmbeddedId; import javax.persistence.Entity; -import javax.persistence.FetchType; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; import javax.persistence.ManyToMany; +import javax.persistence.MappedSuperclass; import javax.persistence.Table; import javax.ws.rs.core.Response; + import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; + import org.onap.policy.models.base.PfValidationResult.ValidationResult; // @formatter:off @@ -55,6 +60,7 @@ import org.onap.policy.models.base.PfValidationResult.ValidationResult; * @param C the concept being contained */ //@formatter:on +@MappedSuperclass @Entity @Table(name = "PfConceptContainer") @Data @@ -67,7 +73,19 @@ public class PfConceptContainer ex @EmbeddedId private PfConceptKey key; - @ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL) + @ManyToMany(cascade = CascadeType.ALL) + // @formatter:off + @JoinTable( + joinColumns = { + @JoinColumn(name = "conceptContainerMapName", referencedColumnName = "name"), + @JoinColumn(name = "concpetContainerMapVersion", referencedColumnName = "version") + }, + inverseJoinColumns = { + @JoinColumn(name = "conceptContainerName", referencedColumnName = "name"), + @JoinColumn(name = "conceptContainerVersion", referencedColumnName = "version") + } + ) + // @formatter:on private Map conceptMap; /** @@ -181,8 +199,7 @@ public class PfConceptContainer ex if (incomingConceptEntry.getValue().getVersion() != null) { conceptKey.setVersion(incomingConceptEntry.getValue().getVersion()); - } - else { + } else { conceptKey.setVersion(PfKey.NULL_KEY_VERSION); } @@ -240,19 +257,17 @@ public class PfConceptContainer ex if (conceptEntry.getKey().equals(PfConceptKey.getNullKey())) { result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key on concept entry " + conceptEntry.getKey() + " may not be the null key")); - } else - if (conceptEntry.getValue() == null) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "value on concept entry " + conceptEntry.getKey() + " may not be null")); - } else - if (!conceptEntry.getKey().equals(conceptEntry.getValue().getKey())) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), - ValidationResult.INVALID, "key on concept entry key " + conceptEntry.getKey() - + " does not equal concept value key " + conceptEntry.getValue().getKey())); - result = conceptEntry.getValue().validate(result); - } else { - result = conceptEntry.getValue().validate(result); - } + } else if (conceptEntry.getValue() == null) { + result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, + "value on concept entry " + conceptEntry.getKey() + " may not be null")); + } else if (!conceptEntry.getKey().equals(conceptEntry.getValue().getKey())) { + result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, + "key on concept entry key " + conceptEntry.getKey() + " does not equal concept value key " + + conceptEntry.getValue().getKey())); + result = conceptEntry.getValue().validate(result); + } else { + result = conceptEntry.getValue().validate(result); + } } return result; } -- cgit 1.2.3-korg