summaryrefslogtreecommitdiffstats
path: root/models-base
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2020-01-27 19:33:25 -0500
committerliamfallon <liam.fallon@est.tech>2020-01-28 09:58:17 -0500
commit252dc4ea8da89739ed18d6509ea72d2321676034 (patch)
treedc10e683f267261bacf02dd4179bb13d529c2c62 /models-base
parentf77d0a91298e4e4ec14991366b5e439824919d5d (diff)
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 <liam.fallon@est.tech>
Diffstat (limited to 'models-base')
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java51
1 files changed, 33 insertions, 18 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 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<C extends PfConcept, A extends PfNameVersion> 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<PfConceptKey, C> conceptMap;
/**
@@ -181,8 +199,7 @@ public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> 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<C extends PfConcept, A extends PfNameVersion> 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;
}