aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/main/java/org/onap/policy/pap/main/rest/depundep/SessionData.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/main/java/org/onap/policy/pap/main/rest/depundep/SessionData.java')
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/depundep/SessionData.java35
1 files changed, 32 insertions, 3 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/depundep/SessionData.java b/main/src/main/java/org/onap/policy/pap/main/rest/depundep/SessionData.java
index 98a5e675..a76d6e13 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/depundep/SessionData.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/depundep/SessionData.java
@@ -27,7 +27,6 @@ import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
-import javax.ws.rs.core.Response.Status;
import org.apache.commons.lang3.tuple.Pair;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.pdp.concepts.PdpGroup;
@@ -40,6 +39,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter.ToscaPolicyFilterBuilder;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifierOptVersion;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
/**
@@ -79,6 +79,11 @@ public class SessionData {
*/
private final Map<ToscaPolicyIdentifierOptVersion, ToscaPolicy> policyCache = new HashMap<>();
+ /**
+ * Maps a policy type's identifier to the policy.
+ */
+ private final Map<ToscaPolicyTypeIdentifier, ToscaPolicyType> typeCache = new HashMap<>();
+
/**
* Constructs the object.
@@ -90,6 +95,31 @@ public class SessionData {
}
/**
+ * Gets the policy type, referenced by an identifier. Loads it from the cache, if possible.
+ * Otherwise, gets it from the DB.
+ *
+ * @param desiredType policy type identifier
+ * @return the specified policy type
+ * @throws PfModelException if an error occurred
+ */
+ public ToscaPolicyType getPolicyType(ToscaPolicyTypeIdentifier desiredType) throws PfModelException {
+
+ ToscaPolicyType type = typeCache.get(desiredType);
+ if (type == null) {
+
+ List<ToscaPolicyType> lst = dao.getPolicyTypeList(desiredType.getName(), desiredType.getVersion());
+ if (lst.isEmpty()) {
+ return null;
+ }
+
+ type = lst.get(0);
+ typeCache.put(desiredType, type);
+ }
+
+ return type;
+ }
+
+ /**
* Gets the policy, referenced by an identifier. Loads it from the cache, if possible.
* Otherwise, gets it from the DB.
*
@@ -106,8 +136,7 @@ public class SessionData {
List<ToscaPolicy> lst = dao.getFilteredPolicyList(filterBuilder.build());
if (lst.isEmpty()) {
- throw new PfModelException(Status.NOT_FOUND,
- "cannot find policy: " + desiredPolicy.getName() + " " + desiredPolicy.getVersion());
+ return null;
}
policy = lst.get(0);