X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=main%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpdpx%2Fmain%2Frest%2FXacmlPdpApplicationManager.java;h=7d3292a67d6bc099103d1e1fc4da3d1cdcd63d0e;hb=5dd6d165a0b3ee88563e5bcabd4c2a7fc42a676b;hp=c97166c165f92bd6525f5a3fe5a3c1ae98c30133;hpb=9bf471abe906598ffd2cd280d372e7cb9474a418;p=policy%2Fxacml-pdp.git diff --git a/main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpApplicationManager.java b/main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpApplicationManager.java index c97166c1..7d3292a6 100644 --- a/main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpApplicationManager.java +++ b/main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpApplicationManager.java @@ -22,12 +22,13 @@ package org.onap.policy.pdpx.main.rest; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.ServiceLoader; - import org.onap.policy.models.decisions.concepts.DecisionRequest; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier; import org.onap.policy.pdp.xacml.application.common.XacmlApplicationServiceProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,6 +39,7 @@ public class XacmlPdpApplicationManager { private static boolean needsInit = true; private static ServiceLoader applicationLoader; private static Map providerActionMap = new HashMap<>(); + private static List toscaPolicyTypeIdents = new ArrayList<>(); private XacmlPdpApplicationManager() { super(); @@ -58,19 +60,17 @@ public class XacmlPdpApplicationManager { // Load service // applicationLoader = ServiceLoader.load(XacmlApplicationServiceProvider.class); + // - // Iterate through them + // Iterate through them the applications for actions and supported policy types // - Iterator iterator = applicationLoader.iterator(); - while (iterator.hasNext()) { - // - // Get the application - // - XacmlApplicationServiceProvider application = iterator.next(); + for (XacmlApplicationServiceProvider application : applicationLoader) { + LOGGER.info("Application {} supports {}", application.applicationName(), application.supportedPolicyTypes()); + // - // Iterate each application + // Iterate through the actions and save in the providerActionMap // int pathCount = 1; for (String action : application.actionDecisionsSupported()) { @@ -83,7 +83,6 @@ public class XacmlPdpApplicationManager { // May need to scan this name to remove unsafe characters etc. // But for debugging purposes, its good to use the application name // - // Path path = Paths.get(applicationPath.toAbsolutePath().toString(), application.applicationName(), Integer.toString(pathCount++)); // @@ -91,6 +90,15 @@ public class XacmlPdpApplicationManager { // application.initialize(path); } + + // Get string list of supportedPolicyTypes + List supportedPolicyTypes = application.supportedPolicyTypes(); + + // Iterate through the supportedPolicyTypes to set the toscaPolicyTypeIdents + for (String name : supportedPolicyTypes) { + ToscaPolicyTypeIdentifier ident = new ToscaPolicyTypeIdentifier(name, "1.0.0"); + toscaPolicyTypeIdents.add(ident); + } } // // we have initialized @@ -102,6 +110,10 @@ public class XacmlPdpApplicationManager { return providerActionMap.get(request.getAction()); } + public static List getToscaPolicyTypeIdents() { + return toscaPolicyTypeIdents; + } + /** * Returns the current count of policy types supported. This could be misleading a bit * as some applications can support wildcard of policy types. Eg. onap.Monitoring.* as @@ -110,10 +122,8 @@ public class XacmlPdpApplicationManager { * @return Total count added from all applications */ public static long getPolicyTypeCount() { - Iterator iterator = applicationLoader.iterator(); long types = 0; - while (iterator.hasNext()) { - XacmlApplicationServiceProvider application = iterator.next(); + for (XacmlApplicationServiceProvider application : applicationLoader) { types += application.supportedPolicyTypes().size(); } return types;