import org.onap.policy.common.utils.resources.ResourceUtils;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.yaml.snakeyaml.Yaml;
         Yaml yaml = new Yaml();
         Object yamlObject = yaml.load(policyYaml);
         String yamlAsJsonString = standardCoder.encode(yamlObject);
+        //
+        // Serialize it into a class
+        //
         ToscaServiceTemplate serviceTemplate = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
         //
+        // Make sure all the fields are setup properly
+        //
+        JpaToscaServiceTemplate jtst = new JpaToscaServiceTemplate();
+        jtst.fromAuthorative(serviceTemplate);
+        ToscaServiceTemplate completedJtst = jtst.toAuthorative();
+        //
         // Get the policies
         //
-        for (Map<String, ToscaPolicy> policies : serviceTemplate.getToscaTopologyTemplate().getPolicies()) {
+        for (Map<String, ToscaPolicy> policies : completedJtst.getToscaTopologyTemplate().getPolicies()) {
             for (ToscaPolicy policy : policies.values()) {
                 if (service.loadPolicy(policy)) {
                     loadedPolicies.add(policy);
 
             new IdentifierImpl(ID_URN_ONAP, "onap-instance");
 
     /*
-     * These 2 ID's are for Optimization policies
+     * These ID's are for Matchable Attributes
      */
 
-    public static final Identifier ID_RESOURCE_POLICY_SCOPE_PROPERTY =
-            new IdentifierImpl(ID_URN_ONAP, "policy-scope-property");
-
-    public static final Identifier ID_RESOURCE_POLICY_TYPE_PROPERTY =
-            new IdentifierImpl(ID_URN_ONAP, "policy-type-property");
+    public static final String ID_RESOURCE_MATCHABLE = URN_ONAP + ":matchable:";
 
     /*
      * These ID's are for Legacy Guard Policies
 
 import java.util.List;
 
 import org.apache.commons.lang3.tuple.Pair;
+import org.onap.policy.common.endpoints.parameters.RestServerParameters;
 import org.onap.policy.models.decisions.concepts.DecisionRequest;
 import org.onap.policy.models.decisions.concepts.DecisionResponse;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
     /**
      * Initializes the application and gives it a Path for storing its
      * data. The Path may be already populated with previous data.
+     * Also gives api rest parameters if needed.
      *
      * @param pathForData Local Path
+     * @param policyApiParameters API rest parameters
      */
-    void             initialize(Path pathForData) throws XacmlApplicationException;
+    void             initialize(Path pathForData, RestServerParameters policyApiParameters)
+            throws XacmlApplicationException;
 
     /**
      * Returns a list of supported Tosca Policy Types.
 
 
 package org.onap.policy.pdp.xacml.application.common.std;
 
+import com.att.research.xacml.api.AttributeValue;
+import com.att.research.xacml.api.DataType;
+import com.att.research.xacml.api.DataTypeException;
+import com.att.research.xacml.api.DataTypeFactory;
+import com.att.research.xacml.api.Request;
+import com.att.research.xacml.api.XACML3;
+import com.att.research.xacml.std.IdentifierImpl;
+import com.att.research.xacml.std.StdMutableAttribute;
+import com.att.research.xacml.std.StdMutableRequest;
+import com.att.research.xacml.std.StdMutableRequestAttributes;
+import com.att.research.xacml.std.annotations.RequestParser;
 import com.att.research.xacml.std.annotations.XACMLAction;
 import com.att.research.xacml.std.annotations.XACMLRequest;
-import com.att.research.xacml.std.annotations.XACMLResource;
 import com.att.research.xacml.std.annotations.XACMLSubject;
-
+import com.att.research.xacml.util.FactoryException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Map;
 import java.util.Map.Entry;
-
 import lombok.Getter;
 import lombok.Setter;
 import lombok.ToString;
-
 import org.onap.policy.models.decisions.concepts.DecisionRequest;
+import org.onap.policy.pdp.xacml.application.common.ToscaDictionary;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 @Getter
 @Setter
 @XACMLRequest(ReturnPolicyIdList = true)
 public class StdMatchablePolicyRequest {
 
-    public static final String POLICY_TYPE_KEY = "policyType";
-    public static final String POLICY_SCOPE_KEY = "policyScope";
+    private static final Logger LOGGER = LoggerFactory.getLogger(StdMatchablePolicyRequest.class);
 
     @XACMLSubject(includeInResults = true)
     private String onapName;
     @XACMLAction()
     private String action;
 
-    //
-    // Unfortunately the annotations won't take an object.toString()
-    // So I could not use the ToscaDictionary class to put these id's
-    // into the annotations.
-    //
-    @XACMLResource(attributeId = "urn:org:onap:policy-scope-property", includeInResults = true)
-    Collection<String> policyScopes = new ArrayList<>();
-
-    @XACMLResource(attributeId = "urn:org:onap:policy-type-property", includeInResults = true)
-    Collection<String> policyTypes = new ArrayList<>();
-
     public StdMatchablePolicyRequest() {
         super();
     }
 
+    protected static DataTypeFactory dataTypeFactory        = null;
+
+    protected static synchronized DataTypeFactory getDataTypeFactory() {
+        try {
+            if (dataTypeFactory != null) {
+                return dataTypeFactory;
+            }
+            dataTypeFactory = DataTypeFactory.newInstance();
+            if (dataTypeFactory == null) {
+                LOGGER.error("Could not create data type factory");
+            }
+        } catch (FactoryException e) {
+            LOGGER.error("Can't get Data type Factory: {}", e);
+        }
+        return dataTypeFactory;
+    }
+
     /**
      * Parses the DecisionRequest into a MonitoringRequest.
      *
      * @param decisionRequest Input DecisionRequest
-     * @return MonitoringRequest
+     * @return Request XACML Request object
+     * @throws DataTypeException DataType exception
+     * @throws IllegalAccessException  Illegal access exception
      */
     @SuppressWarnings({"rawtypes", "unchecked"})
-    public static StdMatchablePolicyRequest createInstance(DecisionRequest decisionRequest) {
+    public static Request createInstance(DecisionRequest decisionRequest) throws IllegalAccessException,
+        DataTypeException {
         //
         // Create our request object
         //
         //
         request.action = decisionRequest.getAction();
         //
+        // Parse the request - we use the annotations to create a
+        // basic XACML request.
+        //
+        Request xacmlRequest = RequestParser.parseRequest(request);
+        //
+        // Create an object we can add to
+        //
+        StdMutableRequest mutableRequest = new StdMutableRequest(xacmlRequest);
+        StdMutableRequestAttributes resourceAttributes = new StdMutableRequestAttributes();
+        resourceAttributes.setCategory(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE);
+        //
         // Add the resource attributes
         //
         Map<String, Object> resources = decisionRequest.getResource();
         for (Entry<String, Object> entrySet : resources.entrySet()) {
             //
-            // Making an assumption that these two fields are matchable.
+            // Making an assumption that these fields are matchable.
             // Its possible we may have to load the policy type model
-            // and use that to find the fields that are matchable.
+            // and use that to validate the fields that are matchable.
             //
-            if (POLICY_SCOPE_KEY.equals(entrySet.getKey())) {
-                if (entrySet.getValue() instanceof Collection) {
-                    addPolicyScopes(request, (Collection) entrySet.getValue());
-                } else if (entrySet.getValue() instanceof String) {
-                    request.policyScopes.add(entrySet.getValue().toString());
-                }
-                continue;
-            }
-            if (POLICY_TYPE_KEY.equals(entrySet.getKey())) {
-                if (entrySet.getValue() instanceof Collection) {
-                    addPolicyTypes(request, (Collection) entrySet.getValue());
-                }
-                if (entrySet.getValue() instanceof String) {
-                    request.policyTypes.add(entrySet.getValue().toString());
-                }
+            if (entrySet.getValue() instanceof Collection) {
+                addResources(resourceAttributes, (Collection) entrySet.getValue(), entrySet.getKey());
+            } else {
+                addResources(resourceAttributes, Arrays.asList(entrySet.getValue().toString()), entrySet.getKey());
             }
         }
-        return request;
+        mutableRequest.add(resourceAttributes);
+        return mutableRequest;
     }
 
-    private static StdMatchablePolicyRequest addPolicyScopes(StdMatchablePolicyRequest request,
-            Collection<Object> scopes) {
-        for (Object scope : scopes) {
-            request.policyScopes.add(scope.toString());
-        }
-        return request;
-    }
+    private static StdMutableRequestAttributes addResources(StdMutableRequestAttributes attributes,
+            Collection<Object> values, String id) throws DataTypeException {
 
-    private static StdMatchablePolicyRequest addPolicyTypes(StdMatchablePolicyRequest request,
-            Collection<Object> types) {
-        for (Object type : types) {
-            request.policyTypes.add(type.toString());
+        DataTypeFactory factory = getDataTypeFactory();
+        if (factory == null) {
+            return null;
         }
-        return request;
+        for (Object value : values) {
+            StdMutableAttribute mutableAttribute    = new StdMutableAttribute();
+            mutableAttribute.setCategory(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE);
+            mutableAttribute.setAttributeId(new IdentifierImpl(ToscaDictionary.ID_RESOURCE_MATCHABLE + id));
+            mutableAttribute.setIncludeInResults(true);
+
+            DataType<?> dataTypeExtended    = factory.getDataType(XACML3.ID_DATATYPE_STRING);
+            AttributeValue<?> attributeValue = dataTypeExtended.createAttributeValue(value);
+            Collection<AttributeValue<?>> attributeValues = new ArrayList<>();
+            attributeValues.add(attributeValue);
+            mutableAttribute.setValues(attributeValues);
+
+            attributes.add(mutableAttribute);
+        }
+        return attributes;
     }
+
 }
 
 import com.att.research.xacml.api.Response;
 import com.att.research.xacml.api.Result;
 import com.att.research.xacml.api.XACML3;
+import com.att.research.xacml.std.IdentifierImpl;
 import com.att.research.xacml.std.annotations.RequestParser;
+import com.att.research.xacml.util.XACMLPolicyWriter;
 import com.google.gson.Gson;
-
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
-
+import lombok.Setter;
 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType;
 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeAssignmentExpressionType;
 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType;
 import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
 import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType;
 import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
-
+import org.onap.policy.common.endpoints.parameters.RestServerParameters;
 import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.common.utils.coder.StandardCoder;
 import org.onap.policy.models.decisions.concepts.DecisionRequest;
 import org.onap.policy.models.decisions.concepts.DecisionResponse;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
+import org.onap.policy.pdp.xacml.application.common.PolicyApiCaller;
+import org.onap.policy.pdp.xacml.application.common.PolicyApiException;
 import org.onap.policy.pdp.xacml.application.common.ToscaDictionary;
 import org.onap.policy.pdp.xacml.application.common.ToscaPolicyConversionException;
 import org.onap.policy.pdp.xacml.application.common.ToscaPolicyTranslator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+/**
+ * This standard matchable translator uses Policy Types that contain "matchable" field in order
+ * to translate policies.
+ *
+ * @author pameladragosh
+ *
+ */
 public class StdMatchableTranslator implements ToscaPolicyTranslator {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(StdMatchableTranslator.class);
     private static final String POLICY_ID = "policy-id";
+    private static final StandardCoder standardCoder = new StandardCoder();
+
+    private final Map<ToscaPolicyTypeIdentifier, ToscaPolicyType> matchablePolicyTypes = new HashMap<>();
+    @Setter
+    private RestServerParameters apiRestParameters;
+    @Setter
+    private Path pathForData;
 
     public StdMatchableTranslator() {
         super();
     public Request convertRequest(DecisionRequest request) {
         LOGGER.info("Converting Request {}", request);
         try {
-            return RequestParser.parseRequest(StdMatchablePolicyRequest.createInstance(request));
+            return StdMatchablePolicyRequest.createInstance(request);
         } catch (IllegalArgumentException | IllegalAccessException | DataTypeException e) {
             LOGGER.error("Failed to convert DecisionRequest: {}", e);
         }
 
     @Override
     public PolicyType convertPolicy(ToscaPolicy toscaPolicy) throws ToscaPolicyConversionException {
+        //
+        // Get the TOSCA Policy Type for this policy
+        //
+        Collection<ToscaPolicyType> policyTypes = this.getPolicyTypes(toscaPolicy.getTypeIdentifier());
+        //
+        // If we don't have any policy types, then we cannot know
+        // which properties are matchable.
+        //
+        if (policyTypes.isEmpty()) {
+            throw new ToscaPolicyConversionException(
+                    "Cannot retrieve Policy Type definition for policy " + toscaPolicy.getName());
+        }
         //
         // Policy name should be at the root
         //
         //
         // Generate the TargetType
         //
-        newPolicyType.setTarget(generateTargetType(toscaPolicy.getProperties()));
+        newPolicyType.setTarget(generateTargetType(toscaPolicy.getProperties(), policyTypes));
         //
         // Now create the Permit Rule
         // No target since the policy has a target
         //
         // Return our new policy
         //
+        try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
+            XACMLPolicyWriter.writePolicyFile(os, newPolicyType);
+            LOGGER.info("{}", os);
+        } catch (IOException e) {
+            LOGGER.error("Failed to create byte array stream", e);
+        }
         return newPolicyType;
     }
 
     }
 
     /**
-     * For generating target type, we are making an assumption that the
-     * policyScope and policyType are the fields that OOF wants to match on.
-     *
-     * <P>In the future, we would need to receive the Policy Type specification
-     * from the PAP so we can dynamically see which fields are matchable.
-     *
-     * <P>Note: I am making an assumption that the matchable fields are what
-     * the OOF wants to query a policy on.
+     * For generating target type, we are scan for matchable properties
+     * and use those to build the policy.
      *
      * @param properties Properties section of policy
+     * @param policyTypes Collection of policy Type to find matchable metadata
      * @return TargetType object
      */
     @SuppressWarnings("unchecked")
-    protected TargetType generateTargetType(Map<String, Object> properties) {
+    protected TargetType generateTargetType(Map<String, Object> properties, Collection<ToscaPolicyType> policyTypes) {
         TargetType targetType = new TargetType();
         //
         // Iterate the properties
         //
         for (Entry<String, Object> entrySet : properties.entrySet()) {
             //
-            // Find policyScope and policyType
+            // Find matchable properties
             //
-            if (entrySet.getKey().equals("policyScope")) {
-                LOGGER.info("Found policyScope: {}", entrySet.getValue());
+            if (isMatchable(entrySet.getKey(), policyTypes)) {
+                LOGGER.info("Found matchable property {}", entrySet.getValue());
                 if (entrySet.getValue() instanceof Collection) {
-                    targetType.getAnyOf().add(generateMatches((Collection<Object>) entrySet.getValue(),
-                            ToscaDictionary.ID_RESOURCE_POLICY_SCOPE_PROPERTY));
-                } else if (entrySet.getValue() instanceof String) {
-                    targetType.getAnyOf().add(generateMatches(Arrays.asList(entrySet.getValue()),
-                            ToscaDictionary.ID_RESOURCE_POLICY_SCOPE_PROPERTY));
-                }
-            }
-            if (entrySet.getKey().equals("policyType")) {
-                LOGGER.info("Found policyType: {}", entrySet.getValue());
-                if (entrySet.getValue() instanceof Collection) {
-                    targetType.getAnyOf().add(generateMatches((Collection<Object>) entrySet.getValue(),
-                            ToscaDictionary.ID_RESOURCE_POLICY_TYPE_PROPERTY));
-                } else if (entrySet.getValue() instanceof String) {
-                    targetType.getAnyOf().add(generateMatches(Arrays.asList(entrySet.getValue()),
-                            ToscaDictionary.ID_RESOURCE_POLICY_TYPE_PROPERTY));
+                    AnyOfType anyOf = generateMatches((Collection<Object>) entrySet.getValue(),
+                            new IdentifierImpl(ToscaDictionary.ID_RESOURCE_MATCHABLE + entrySet.getKey()));
+                    if (! anyOf.getAllOf().isEmpty()) {
+                        targetType.getAnyOf().add(anyOf);
+                    }
+                } else {
+                    AnyOfType anyOf = generateMatches(Arrays.asList(entrySet.getValue()),
+                            new IdentifierImpl(ToscaDictionary.ID_RESOURCE_MATCHABLE + entrySet.getKey()));
+                    if (! anyOf.getAllOf().isEmpty()) {
+                        targetType.getAnyOf().add(anyOf);
+                    }
                 }
             }
         }
         return targetType;
     }
 
+    protected boolean isMatchable(String propertyName, Collection<ToscaPolicyType> policyTypes) {
+        for (ToscaPolicyType policyType : policyTypes) {
+            for (Entry<String, ToscaProperty> propertiesEntry : policyType.getProperties().entrySet()) {
+                if (! propertiesEntry.getKey().equals(propertyName)
+                        || propertiesEntry.getValue().getMetadata() == null) {
+                    continue;
+                }
+                for (Entry<String, String> entrySet : propertiesEntry.getValue().getMetadata().entrySet()) {
+                    if (entrySet.getKey().equals("matchable") && entrySet.getValue().equals("true")) {
+                        return true;
+                    }
+                }
+            }
+        }
+        return false;
+    }
+
     protected AnyOfType generateMatches(Collection<Object> matchables, Identifier attributeId) {
         //
         // This is our outer AnyOf - which is an OR
         //
         AnyOfType anyOf = new AnyOfType();
         for (Object matchable : matchables) {
+            //
+            // Default to string
+            //
+            Identifier idFunction = XACML3.ID_FUNCTION_STRING_EQUAL;
+            Identifier idDatatype = XACML3.ID_DATATYPE_STRING;
+            //
+            // See if we are another datatype
+            //
+            // TODO We should add datetime support. But to do that we need
+            // probably more metadata to describe how that would be translated.
+            //
+            if (matchable instanceof Integer) {
+                idFunction = XACML3.ID_FUNCTION_INTEGER_EQUAL;
+                idDatatype = XACML3.ID_DATATYPE_INTEGER;
+            } else if (matchable instanceof Double) {
+                idFunction = XACML3.ID_FUNCTION_DOUBLE_EQUAL;
+                idDatatype = XACML3.ID_DATATYPE_DOUBLE;
+            } else if (matchable instanceof Boolean) {
+                idFunction = XACML3.ID_FUNCTION_BOOLEAN_EQUAL;
+                idDatatype = XACML3.ID_DATATYPE_BOOLEAN;
+            }
             //
             // Create a match for this
             //
             MatchType match = ToscaPolicyTranslatorUtils.buildMatchTypeDesignator(
-                    XACML3.ID_FUNCTION_STRING_EQUAL,
+                    idFunction,
                     matchable.toString(),
-                    XACML3.ID_DATATYPE_STRING,
+                    idDatatype,
                     attributeId,
                     XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE);
             //
         return rule;
     }
 
+
+    /**
+     * Get Policy Type definitions. This could be previously loaded, or could be
+     * stored in application path, or may need to be pulled from the API.
+     *
+     *
+     * @param policyTypeId Policy Type Id
+     * @return A list of PolicyTypes
+     */
+    private List<ToscaPolicyType> getPolicyTypes(ToscaPolicyTypeIdentifier policyTypeId) {
+        //
+        // Create identifier from the policy
+        //
+        ToscaPolicyTypeIdentifier typeId = new ToscaPolicyTypeIdentifier(policyTypeId);
+        //
+        // Find the Policy Type
+        //
+        ToscaPolicyType policyType = findPolicyType(typeId);
+        if (policyType == null)  {
+            return Collections.emptyList();
+        }
+        //
+        // Create our return object
+        //
+        List<ToscaPolicyType> listTypes = new ArrayList<>();
+        listTypes.add(policyType);
+        //
+        // Look for parent policy types that could also contain matchable properties
+        //
+        ToscaPolicyType childPolicyType = policyType;
+        while (! childPolicyType.getDerivedFrom().startsWith("tosca.policies.Root")) {
+            //
+            // Create parent policy type id.
+            //
+            // We will have to assume the same version between child and the
+            // parent policy type it derives from.
+            //
+            // Or do we assume 1.0.0?
+            //
+            String strDerivedFrom = childPolicyType.getDerivedFrom();
+            //
+            // Hack that fixes policy/models appending 0.0.0 to the derivedFrom name
+            //
+            if (strDerivedFrom.endsWith("0.0.0")) {
+                strDerivedFrom = strDerivedFrom.substring(0, strDerivedFrom.length() - "0.0.0".length() - 1);
+            }
+            ToscaPolicyTypeIdentifier parentId = new ToscaPolicyTypeIdentifier(strDerivedFrom, "1.0.0");
+            //
+            // Find the policy type
+            //
+            ToscaPolicyType parentPolicyType = findPolicyType(parentId);
+            if (parentPolicyType == null) {
+                //
+                // Probably would be best to throw an exception and
+                // return nothing back.
+                //
+                // But instead we will log a warning
+                //
+                LOGGER.warn("Missing parent policy type - proceeding anyway {}", parentId);
+                //
+                // Break the loop
+                //
+                break;
+            }
+            //
+            // Great save it
+            //
+            listTypes.add(parentPolicyType);
+            //
+            // Move to the next parent
+            //
+            childPolicyType = parentPolicyType;
+        }
+
+
+        return listTypes;
+    }
+
+    private ToscaPolicyType findPolicyType(ToscaPolicyTypeIdentifier policyTypeId) {
+        //
+        // Is it loaded in memory?
+        //
+        ToscaPolicyType policyType = this.matchablePolicyTypes.get(policyTypeId);
+        if (policyType == null)  {
+            //
+            // Load the policy
+            //
+            policyType = this.loadPolicyType(policyTypeId);
+        }
+        //
+        // Yep return it
+        //
+        return policyType;
+    }
+
+    private ToscaPolicyType loadPolicyType(ToscaPolicyTypeIdentifier policyTypeId) {
+        //
+        // Construct what the file name should be
+        //
+        Path policyTypePath = this.constructLocalFilePath(policyTypeId);
+        //
+        // See if it exists
+        //
+        byte[] bytes;
+        try {
+            //
+            // If it exists locally, read the bytes in
+            //
+            bytes = Files.readAllBytes(policyTypePath);
+        } catch (IOException e) {
+            //
+            // Does not exist locally, so let's GET it from the policy api
+            //
+            LOGGER.error("PolicyType not found in data area yet {}", policyTypePath, e);
+            //
+            // So let's pull it from API REST call and save it locally
+            //
+            return this.pullPolicyType(policyTypeId, policyTypePath);
+        }
+        LOGGER.info("Read in local policy type {}", policyTypePath.toAbsolutePath());
+        try {
+            ToscaServiceTemplate serviceTemplate = standardCoder.decode(new String(bytes, StandardCharsets.UTF_8),
+                    ToscaServiceTemplate.class);
+            JpaToscaServiceTemplate jtst = new JpaToscaServiceTemplate();
+            jtst.fromAuthorative(serviceTemplate);
+            ToscaServiceTemplate completedJtst = jtst.toAuthorative();
+            //
+            // Search for our Policy Type, there really only should be one but
+            // this is returned as a map.
+            //
+            for ( Entry<String, ToscaPolicyType> entrySet : completedJtst.getPolicyTypes().entrySet()) {
+                ToscaPolicyType entryPolicyType = entrySet.getValue();
+                if (policyTypeId.getName().equals(entryPolicyType.getName())
+                        && policyTypeId.getVersion().equals(entryPolicyType.getVersion())) {
+                    LOGGER.info("Found existing local policy type {} {}", entryPolicyType.getName(),
+                            entryPolicyType.getVersion());
+                    //
+                    // Just simply return the policy type right here
+                    //
+                    return entryPolicyType;
+                } else {
+                    LOGGER.warn("local policy type contains different name version {} {}", entryPolicyType.getName(),
+                            entryPolicyType.getVersion());
+                }
+            }
+            //
+            // This would be an error, if the file stored does not match what its supposed to be
+            //
+            LOGGER.error("Existing policy type file does not contain right name and version");
+        } catch (CoderException e) {
+            LOGGER.error("Failed to decode tosca template for {}", policyTypePath, e);
+        }
+        //
+        // Hopefully we never get here
+        //
+        LOGGER.error("Failed to find/load policy type {}", policyTypeId);
+        return null;
+    }
+
+    private synchronized ToscaPolicyType pullPolicyType(ToscaPolicyTypeIdentifier policyTypeId, Path policyTypePath) {
+        //
+        // This is what we return
+        //
+        ToscaPolicyType policyType = null;
+        try {
+            PolicyApiCaller api = new PolicyApiCaller(this.apiRestParameters);
+
+            policyType = api.getPolicyType(policyTypeId);
+        } catch (PolicyApiException e) {
+            LOGGER.error("Failed to make API call", e);
+            LOGGER.error("parameters: {} ", this.apiRestParameters);
+            return null;
+        }
+        //
+        // Store it locally
+        //
+        try {
+            standardCoder.encode(policyTypePath.toFile(), policyType);
+        } catch (CoderException e) {
+            LOGGER.error("Failed to store {} locally to {}", policyTypeId, policyTypePath, e);
+        }
+        //
+        // Done return the policy type
+        //
+        return policyType;
+    }
+
+    private Path constructLocalFilePath(ToscaPolicyTypeIdentifier policyTypeId) {
+        return Paths.get(this.pathForData.toAbsolutePath().toString(), policyTypeId.getName() + "-"
+                + policyTypeId.getVersion() + ".json");
+    }
 }
 
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import lombok.Getter;
 import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
 import org.apache.commons.lang3.tuple.Pair;
+import org.onap.policy.common.endpoints.parameters.RestServerParameters;
 import org.onap.policy.models.decisions.concepts.DecisionRequest;
 import org.onap.policy.models.decisions.concepts.DecisionResponse;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
 
     private static final Logger LOGGER = LoggerFactory.getLogger(StdXacmlApplicationServiceProvider.class);
     private Path pathForData = null;
+    @Getter
+    private RestServerParameters policyApiParameters;
     private Properties pdpProperties = null;
     private PDPEngine pdpEngine = null;
     private Map<ToscaPolicy, Path> mapLoadedPolicies = new HashMap<>();
     }
 
     @Override
-    public void initialize(Path pathForData) throws XacmlApplicationException {
+    public void initialize(Path pathForData, RestServerParameters policyApiParameters)
+            throws XacmlApplicationException {
         //
         // Save our path
         //
         this.pathForData = pathForData;
         LOGGER.info("New Path is {}", this.pathForData.toAbsolutePath());
         //
+        // Save our params
+        //
+        this.policyApiParameters = policyApiParameters;
+        //
         // Look for and load the properties object
         //
         try {
 
 
 package org.onap.policy.pdp.xacml.application.common.std;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.when;
 
-import java.util.Collection;
-import java.util.Collections;
+import com.att.research.xacml.api.DataTypeException;
+import com.att.research.xacml.api.Request;
+import com.att.research.xacml.api.RequestAttributes;
+import com.att.research.xacml.api.XACML3;
+import com.att.research.xacml.std.IdentifierImpl;
+import java.util.Arrays;
+import java.util.Iterator;
 import java.util.Map;
 import java.util.TreeMap;
 import org.junit.Before;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.onap.policy.models.decisions.concepts.DecisionRequest;
+import org.onap.policy.pdp.xacml.application.common.ToscaDictionary;
 
 public class StdMatchablePolicyRequestTest {
     private static final String ACTION = "my-action";
     private static final String ONAP_NAME = "my-name";
     private static final String ONAP_INSTANCE = "my-instance";
     private static final String ONAP_COMPONENT = "my-component";
-    private static final String POLICY_SCOPE = "my-scope";
-    private static final String POLICY_TYPE = "my-type";
+    private static final String RESOURCE1 = "my-scope";
+    private static final String RESOURCE2 = "my-service";
+    private static final String RESOURCE3 = "my-geography1";
+    private static final String RESOURCE4 = "my-geography2";
 
     @Mock
     private DecisionRequest decreq;
 
     private Map<String, Object> resources;
 
-    private StdMatchablePolicyRequest stdreq;
+    private Request stdreq;
 
     /**
      * Initializes objects.
     }
 
     @Test
-    public void testCreateInstance() {
-        resources.put(StdMatchablePolicyRequest.POLICY_SCOPE_KEY, 100);
-        resources.put(StdMatchablePolicyRequest.POLICY_TYPE_KEY, 101);
+    public void testCreateInstance() throws IllegalAccessException, DataTypeException {
+        resources.put("resource1", RESOURCE1);
+        resources.put("resource2", RESOURCE2);
+        resources.put("resource3", Arrays.asList(RESOURCE3, RESOURCE4));
 
         stdreq = StdMatchablePolicyRequest.createInstance(decreq);
 
         assertNotNull(stdreq);
 
-        assertEquals(ACTION, stdreq.getAction());
-        assertEquals(ONAP_COMPONENT, stdreq.getOnapComponent());
-        assertEquals(ONAP_INSTANCE, stdreq.getOnapInstance());
-        assertEquals(ONAP_NAME, stdreq.getOnapName());
+        assertTrue(stdreq.getRequestAttributes(XACML3.ID_ATTRIBUTE_CATEGORY_ACTION).hasNext());
+        assertTrue(stdreq.getRequestAttributes(XACML3.ID_SUBJECT_CATEGORY_ACCESS_SUBJECT).hasNext());
+
+
+        Iterator<RequestAttributes> iterResources = stdreq.getRequestAttributes(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE);
+        assertTrue(iterResources.hasNext());
+        while (iterResources.hasNext()) {
+            RequestAttributes attrs = iterResources.next();
+            assertTrue(attrs.hasAttributes(new IdentifierImpl(ToscaDictionary.ID_RESOURCE_MATCHABLE + "resource1")));
+        }
 
-        assertTrue(stdreq.getPolicyScopes().isEmpty());
-        assertTrue(stdreq.getPolicyTypes().isEmpty());
     }
 
+    /*
     @Test
     public void testCreateInstance_StringValues() {
         resources.put(StdMatchablePolicyRequest.POLICY_SCOPE_KEY, POLICY_SCOPE);
         assertFalse(res.isEmpty());
         assertEquals(POLICY_TYPE, res.iterator().next());
     }
+*/
 
 }
 
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.pdp.xacml.application.common.std;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.Properties;
+import java.util.UUID;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Response;
+import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.onap.policy.common.endpoints.http.server.HttpServletServer;
+import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
+import org.onap.policy.common.endpoints.parameters.RestServerParameters;
+import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
+import org.onap.policy.common.gson.GsonMessageBodyHandler;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.network.NetworkUtil;
+import org.onap.policy.common.utils.resources.ResourceUtils;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
+import org.onap.policy.pdp.xacml.application.common.ToscaPolicyConversionException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.yaml.snakeyaml.Yaml;
+
+public class StdMatchableTranslatorTest {
+
+    private static final Logger logger = LoggerFactory.getLogger(StdMatchableTranslatorTest.class);
+    private static final String CLIENT_NAME = "policy-api";
+    private static final StandardCoder standardCoder = new StandardCoder();
+    private static int port;
+    private static RestServerParameters clientParams;
+    private static ToscaPolicyType testPolicyType;
+
+    @ClassRule
+    public static final TemporaryFolder policyFolder = new TemporaryFolder();
+
+    /**
+     * Initializes {@link #clientParams} and starts a simple REST server to handle the
+     * test requests.
+     *
+     * @throws IOException if an error occurs
+     */
+    @BeforeClass
+    public static void setUpBeforeClass() throws Exception {
+        System.setProperty("org.eclipse.jetty.util.log.class", "org.eclipse.jetty.util.log.StdErrLog");
+        System.setProperty("org.eclipse.jetty.LEVEL", "OFF");
+        //
+        // Setup our api server simulator
+        //
+        port = NetworkUtil.allocPort();
+
+        clientParams = mock(RestServerParameters.class);
+        when(clientParams.getHost()).thenReturn("localhost");
+        when(clientParams.getPort()).thenReturn(port);
+
+        Properties props = new Properties();
+        props.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES, CLIENT_NAME);
+
+        final String svcpfx =
+                        PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + CLIENT_NAME;
+
+        props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_HOST_SUFFIX, clientParams.getHost());
+        props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_PORT_SUFFIX,
+                        Integer.toString(clientParams.getPort()));
+        props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_REST_CLASSES_SUFFIX,
+                        ApiRestController.class.getName());
+        props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, "true");
+        props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_HTTPS_SUFFIX, "false");
+        props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_AAF_SUFFIX, "false");
+        props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_SERIALIZATION_PROVIDER,
+                        GsonMessageBodyHandler.class.getName());
+
+        HttpServletServerFactoryInstance.getServerFactory().build(props).forEach(HttpServletServer::start);
+
+        assertTrue(NetworkUtil.isTcpPortOpen(clientParams.getHost(), clientParams.getPort(), 100, 100));
+        //
+        // Load our test policy type
+        //
+        String policyYaml = ResourceUtils.getResourceAsString("matchable/onap.policies.Test-1.0.0.yaml");
+        Yaml yaml = new Yaml();
+        Object yamlObject = yaml.load(policyYaml);
+        String yamlAsJsonString = standardCoder.encode(yamlObject);
+        //
+        // Serialize it into a class
+        //
+        ToscaServiceTemplate serviceTemplate = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
+        //
+        // Make sure all the fields are setup properly
+        //
+        JpaToscaServiceTemplate jtst = new JpaToscaServiceTemplate();
+        jtst.fromAuthorative(serviceTemplate);
+        ToscaServiceTemplate completedJtst = jtst.toAuthorative();
+        //
+        // Find the Policy Type - SHOULD only be one
+        //
+        assertEquals(1, completedJtst.getPolicyTypes().size());
+        testPolicyType = completedJtst.getPolicyTypes().get("onap.policies.Test");
+        assertNotNull(testPolicyType);
+        logger.info("Test Policy Type {}{}", System.lineSeparator(), testPolicyType);
+    }
+
+    @AfterClass
+    public static void tearDownAfterClass() {
+        HttpServletServerFactoryInstance.getServerFactory().destroy();
+    }
+
+    @Test
+    public void test() throws CoderException, ToscaPolicyConversionException {
+        //
+        // Create our translator
+        //
+        StdMatchableTranslator translator = new StdMatchableTranslator();
+        assertNotNull(translator);
+        //
+        // Set it up
+        //
+        translator.setPathForData(policyFolder.getRoot().toPath());
+        translator.setApiRestParameters(clientParams);
+        //
+        // Load policies to test
+        //
+        String policyYaml = ResourceUtils.getResourceAsString(
+                "src/test/resources/matchable/test.policies.input.tosca.yaml");
+        Yaml yaml = new Yaml();
+        Object yamlObject = yaml.load(policyYaml);
+        String yamlAsJsonString = standardCoder.encode(yamlObject);
+        //
+        // Serialize it into a class
+        //
+        ToscaServiceTemplate serviceTemplate = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
+        //
+        // Make sure all the fields are setup properly
+        //
+        JpaToscaServiceTemplate jtst = new JpaToscaServiceTemplate();
+        jtst.fromAuthorative(serviceTemplate);
+        ToscaServiceTemplate completedJtst = jtst.toAuthorative();
+        //
+        // Get the policies
+        //
+        for (Map<String, ToscaPolicy> policies : completedJtst.getToscaTopologyTemplate().getPolicies()) {
+            for (ToscaPolicy policy : policies.values()) {
+                PolicyType translatedPolicy = translator.convertPolicy(policy);
+                assertNotNull(translatedPolicy);
+                logger.info("Translated policy {} {}", System.lineSeparator(), translatedPolicy);
+            }
+        }
+    }
+
+    /**
+     * Simple REST server to handle test requests.
+     */
+
+    @Path("/policy/api/v1")
+    @Produces({"application/json", "application/yaml"})
+    @Consumes({"application/json", "application/yaml"})
+    public static class ApiRestController {
+
+        /**
+         * Retrieves the specified version of a particular policy type.
+         *
+         * @param policyTypeId ID of desired policy type
+         * @param versionId version of desired policy type
+         * @param requestId optional request ID
+         *
+         * @return the Response object containing the results of the API operation
+         */
+        @GET
+        @Path("/policytypes/{policyTypeId}/versions/{versionId}")
+        public Response getSpecificVersionOfPolicyType(@PathParam("policyTypeId") String policyTypeId,
+                        @PathParam("versionId") String versionId, @HeaderParam("X-ONAP-RequestID") UUID requestId) {
+            logger.info("request for policy type={} version={}", policyTypeId, versionId);
+            return Response.status(Response.Status.OK).entity(testPolicyType).build();
+
+        }
+    }
+}
 
 import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
+import org.onap.policy.common.endpoints.parameters.RestServerParameters;
 import org.onap.policy.models.decisions.concepts.DecisionRequest;
 import org.onap.policy.models.decisions.concepts.DecisionResponse;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
     private static final String POLICY_NAME = "my-name";
     private static final String POLICY_VERSION = "1.2.3";
     private static final String POLICY_TYPE = "my-type";
+    private static final RestServerParameters apiRestParameters = new RestServerParameters();
 
     @Mock
     private ToscaPolicyTranslator trans;
 
     @Test
     public void testInitialize_testGetXxx() throws XacmlApplicationException {
-        prov.initialize(TEMP_PATH);
+        prov.initialize(TEMP_PATH, apiRestParameters);
 
         assertEquals(TEMP_PATH, prov.getDataPath());
         assertNotNull(prov.getEngine());
 
     @Test
     public void testInitialize_Ex() throws XacmlApplicationException {
-        assertThatThrownBy(() -> prov.initialize(new File(TEMP_DIR_NAME + "-nonExistent").toPath()))
+        assertThatThrownBy(() -> prov.initialize(new File(TEMP_DIR_NAME + "-nonExistent").toPath(), apiRestParameters))
                         .isInstanceOf(XacmlApplicationException.class).hasMessage("Failed to load xacml.properties");
     }
 
 
     @Test
     public void testLoadPolicy_testUnloadPolicy() throws Exception {
-        prov.initialize(TEMP_PATH);
+        prov.initialize(TEMP_PATH, apiRestParameters);
         PROP_FILE.delete();
 
         final Set<String> set = XACMLProperties.getRootPolicyIDs(prov.getProperties());
 
     @Test
     public void testUnloadPolicy_NotDeployed() throws Exception {
-        prov.initialize(TEMP_PATH);
+        prov.initialize(TEMP_PATH, apiRestParameters);
 
         assertFalse(prov.unloadPolicy(policy));
 
         engineFactory = null;
 
         prov = new MyProv();
-        prov.initialize(TEMP_PATH);
+        prov.initialize(TEMP_PATH, apiRestParameters);
 
         assertNotNull(prov.getEngine());
     }
 
--- /dev/null
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+policy_types:
+    onap.policies.Test:
+        derived_from: tosca.policies.Root
+        version: 1.0.0
+        properties:
+            nonmatachableString:
+                type: string
+            matchableString:
+                type: string
+                metadata:
+                   matchable: true
+            nonmatachableInteger:
+                type: integer
+                metadata:
+                   matchable: false
+            matachableInteger:
+                type: integer
+                metadata:
+                   matchable: true
+            nonmatachableDouble:
+                type: double
+            matchableDouble:
+                type: double
+                metadata:
+                   matchable: true
+            nonmatachableBoolean:
+                type: boolean
+            matachableBoolean:
+                type: boolean
+                metadata:
+                   matchable: true
+            matchableListString:
+                type: list
+                metadata:
+                   matchable: true
+                entry_schema:
+                   type: string
\ No newline at end of file
 
--- /dev/null
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+topology_template:
+  policies:
+    -
+      Test.policy:
+         type: onap.policies.Test
+         type_version: 1.0.0
+         version: 1.0.0
+         metadata:
+             policy-id: Test.policy
+             policy-version: 1
+         properties:
+            nonmatachableString: "I am NON matchable"
+            matchableString: "I should be matched"
+            nonmatachableInteger: 0
+            matachableInteger: 1000
+            nonmatachableDouble: 0.0
+            matchableDouble: 1.1
+            nonmatachableBoolean: false
+            matachableBoolean: true
+            matchableListString:
+               - match A
+               - match B
\ No newline at end of file
 
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.junit.runners.MethodSorters;
+import org.onap.policy.common.endpoints.parameters.RestServerParameters;
 import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.common.utils.coder.StandardCoder;
 import org.onap.policy.common.utils.resources.TextFileUtils;
     private static final Logger LOGGER = LoggerFactory.getLogger(CoordinationTest.class);
     private static Properties properties = new Properties();
     private static File propertiesFile;
+    private static RestServerParameters clientParams = new RestServerParameters();
     private static XacmlApplicationServiceProvider service;
     private static DecisionRequest requestCl1Node1;
     @SuppressWarnings("unused")
         // Tell it to initialize based on the properties file
         // we just built for it.
         //
-        service.initialize(propertiesFile.toPath().getParent());
+        service.initialize(propertiesFile.toPath().getParent(), clientParams);
         //
         // Load Decision Requests
         //
 
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.junit.runners.MethodSorters;
+import org.onap.policy.common.endpoints.parameters.RestServerParameters;
 import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.common.utils.coder.StandardCoder;
 import org.onap.policy.common.utils.resources.TextFileUtils;
     private static final Logger LOGGER = LoggerFactory.getLogger(GuardPdpApplicationTest.class);
     private static Properties properties = new Properties();
     private static File propertiesFile;
+    private static RestServerParameters clientParams = new RestServerParameters();
     private static XacmlApplicationServiceProvider service;
     private static DecisionRequest requestVfCount1;
     private static DecisionRequest requestVfCount3;
         // Tell it to initialize based on the properties file
         // we just built for it.
         //
-        service.initialize(propertiesFile.toPath().getParent());
+        service.initialize(propertiesFile.toPath().getParent(), clientParams);
         //
         // Load Decision Requests
         //
 
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.junit.runners.MethodSorters;
+import org.onap.policy.common.endpoints.parameters.RestServerParameters;
 import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.common.utils.coder.StandardCoder;
 import org.onap.policy.common.utils.resources.TextFileUtils;
     private static DecisionRequest requestPolicyType;
 
     private static StandardCoder gson = new StandardCoder();
+    private static RestServerParameters clientParams = new RestServerParameters();
 
     @ClassRule
     public static final TemporaryFolder policyFolder = new TemporaryFolder();
         // Tell it to initialize based on the properties file
         // we just built for it.
         //
-        service.initialize(propertiesFile.toPath().getParent());
+        service.initialize(propertiesFile.toPath().getParent(), clientParams);
     }
 
     @Test
 
     <description>This modules contains applications that implement policy-types for XACML PDP.</description>
 
     <dependencies>
+        <dependency>
+            <groupId>org.powermock</groupId>
+            <artifactId>powermock-api-mockito</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.onap.policy.xacml-pdp.applications</groupId>
             <artifactId>common</artifactId>
 
 
 package org.onap.policy.xacml.pdp.application.optimization;
 
+import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
-
+import org.onap.policy.common.endpoints.parameters.RestServerParameters;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
 import org.onap.policy.pdp.xacml.application.common.ToscaPolicyTranslator;
+import org.onap.policy.pdp.xacml.application.common.XacmlApplicationException;
 import org.onap.policy.pdp.xacml.application.common.std.StdMatchableTranslator;
 import org.onap.policy.pdp.xacml.application.common.std.StdXacmlApplicationServiceProvider;
 import org.slf4j.Logger;
         return Arrays.asList("optimize");
     }
 
+    @Override
+    public void initialize(Path pathForData, RestServerParameters policyApiParameters)
+            throws XacmlApplicationException {
+        //
+        // Store our API parameters and path for translator so it
+        // can go get Policy Types
+        //
+        this.translator.setPathForData(pathForData);
+        this.translator.setApiRestParameters(policyApiParameters);
+        //
+        // Let our super class do its thing
+        //
+        super.initialize(pathForData, policyApiParameters);
+    }
+
     @Override
     public synchronized List<ToscaPolicyTypeIdentifier> supportedPolicyTypes() {
         return Collections.unmodifiableList(supportedPolicyTypes);
 
     @Override
     protected ToscaPolicyTranslator getTranslator(String type) {
+        //
+        // Return translator
+        //
         return translator;
     }
 
 
 package org.onap.policy.xacml.pdp.application.optimization;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 import com.att.research.xacml.api.Response;
-
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.util.Iterator;
 import java.util.Properties;
 import java.util.ServiceLoader;
-
 import org.apache.commons.lang3.tuple.Pair;
 import org.junit.BeforeClass;
 import org.junit.ClassRule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.junit.runners.MethodSorters;
+import org.onap.policy.common.endpoints.parameters.RestServerParameters;
 import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.common.utils.coder.StandardCoder;
 import org.onap.policy.common.utils.resources.TextFileUtils;
     private static XacmlApplicationServiceProvider service;
     private static StandardCoder gson = new StandardCoder();
     private static DecisionRequest requestAffinity;
+    private static RestServerParameters clientParams;
+    private static String[] listPolicyTypeFiles = { "onap.policies.Optimization",
+        "onap.policies.optimization.AffinityPolicy",
+        "onap.policies.optimization.DistancePolicy",
+        "onap.policies.optimization.SubscriberPolicy"};
 
     @ClassRule
     public static final TemporaryFolder policyFolder = new TemporaryFolder();
      */
     @BeforeClass
     public static void setUp() throws Exception {
+        clientParams = mock(RestServerParameters.class);
+        when(clientParams.getHost()).thenReturn("localhost");
+        when(clientParams.getPort()).thenReturn(6969);
         //
         // Load Single Decision Request
         //
         propertiesFile = XacmlPolicyUtils.copyXacmlPropertiesContents("src/test/resources/xacml.properties",
                 properties, myCreator);
         //
+        // Copy the test policy types into data area
+        //
+        for (String policy : listPolicyTypeFiles) {
+            Files.copy(Paths.get("src/test/resources", policy + "-1.0.0.json"),
+                    Paths.get(policyFolder.getRoot().getAbsolutePath(), policy + "-1.0.0.json"));
+        }
+        //
         // Load service
         //
         ServiceLoader<XacmlApplicationServiceProvider> applicationLoader =
         // Tell it to initialize based on the properties file
         // we just built for it.
         //
-        service.initialize(propertiesFile.toPath().getParent());
+        service.initialize(propertiesFile.toPath().getParent(), clientParams);
     }
 
     @Test
         LOGGER.info("Decision {}", decision.getKey());
 
         assertThat(decision.getKey()).isNotNull();
-        assertThat(decision.getKey().getPolicies().size()).isEqualTo(1);
+        assertThat(decision.getKey().getPolicies().size()).isEqualTo(4);
         //
         // Dump it out as Json
         //
 
--- /dev/null
+{
+    "tosca_definitions_version": "tosca_simple_yaml_1_0_0",
+    "policy_types": {
+        "onap.policies.Optimization": {
+            "derived_from": "tosca.policies.Root",
+            "version": "1.0.0",
+            "description": "The base policy type for all policies that govern optimization",
+            "properties": {
+                "scope": {
+                    "description": "Scope for the policy - could be for a specific release.",
+                    "type": "list",
+                    "metadata": {
+                        "matchable": true
+                    },
+                    "required": true
+                },
+                "services": {
+                    "description": "One or more services that the policy applies to.",
+                    "type": "list",
+                    "metadata": {
+                        "matchable": true
+                    },
+                    "required": true,
+                    "entry_schema": {
+                        "type": "string"
+                    }
+                },
+                "resources": {
+                    "description": "One or more VNF resources that the policy applies to.",
+                    "type": "list",
+                    "metadata": {
+                        "matchable": true
+                    },
+                    "required": true,
+                    "entry_schema": {
+                        "type": "string"
+                    }
+                },
+                "geography": {
+                    "description": "One or more geographic regions",
+                    "type": "list",
+                    "metadata": {
+                        "matchable": true
+                    },
+                    "required": true,
+                    "entry_schema": {
+                        "type": "string",
+                        "constraints": [
+                            {
+                                "valid_values": [
+                                    "US",
+                                    "International"
+                                ]
+                            }
+                        ]
+                    }
+                },
+                "identity": {
+                    "description": "Used internally for identification",
+                    "type": "string",
+                    "required": true
+                }
+            }
+        }
+    }
+}
\ No newline at end of file
 
--- /dev/null
+{
+    "tosca_definitions_version": "tosca_simple_yaml_1_0_0",
+    "policy_types": {
+        "onap.policies.optimization.AffinityPolicy": {
+            "derived_from": "onap.policies.Optimization",
+            "version": "1.0.0",
+            "type_version": "1.0.0",
+            "properties": {
+                "applicableResources": {
+                    "type": "list",
+                    "required": true,
+                    "entry_schema": {
+                        "type": "string",
+                        "constraints": [
+                            {
+                                "valid_values": [
+                                    "any",
+                                    "all"
+                                ]
+                            }
+                        ]
+                    }
+                },
+                "affinityProperties": {
+                    "type": "policy.data.affinityProperties_properties",
+                    "required": true
+                }
+            }
+        }
+    },
+    "data_types": {
+        "policy.data.affinityProperties_properties": {
+            "derived_from": "tosca.nodes.Root",
+            "version": "1.0.0",
+            "properties": {
+                "qualifier": {
+                    "type": "string",
+                    "constraints": [
+                        {
+                            "valid_values": [
+                                "same",
+                                "different"
+                            ]
+                        }
+                    ]
+                },
+                "category": {
+                    "type": "string",
+                    "required": true
+                }
+            }
+        }
+    }
+}
\ No newline at end of file
 
--- /dev/null
+{
+    "tosca_definitions_version": "tosca_simple_yaml_1_0_0",
+    "policy_types": {
+        "onap.policies.optimization.DistancePolicy": {
+            "derived_from": "onap.policies.Optimization",
+            "version": "1.0.0",
+            "properties": {
+                "applicableResources": {
+                    "type": "list",
+                    "required": true,
+                    "entry_schema": {
+                        "type": "string",
+                        "constraints": [
+                            {
+                                "valid_values": [
+                                    "any",
+                                    "all"
+                                ]
+                            }
+                        ]
+                    }
+                },
+                "distanceProperties": {
+                    "type": "policy.data.distanceProperties_properties",
+                    "required": true
+                }
+            }
+        }
+    },
+    "data_types": {
+        "policy.data.distanceProperties_properties": {
+            "derived_from": "tosca.nodes.Root",
+            "properties": {
+                "locationInfo": {
+                    "type": "string",
+                    "required": true
+                },
+                "distance": {
+                    "type": "policy.data.distance_properties",
+                    "required": true,
+                    "entry_schema": {
+                        "type": "policy.data.distance_properties"
+                    }
+                }
+            }
+        },
+        "policy.data.distance_properties": {
+            "derived_from": "tosca.nodes.Root",
+            "properties": {
+                "value": {
+                    "type": "string",
+                    "required": true
+                },
+                "operator": {
+                    "type": "list",
+                    "required": true,
+                    "entry_schema": {
+                        "type": "string",
+                        "constraints": [
+                            {
+                                "valid_values": [
+                                    "<",
+                                    "<=",
+                                    "\n",
+                                    ">=",
+                                    "="
+                                ]
+                            }
+                        ]
+                    }
+                },
+                "unit": {
+                    "type": "list",
+                    "required": true,
+                    "entry_schema": {
+                        "type": "string",
+                        "constraints": [
+                            {
+                                "valid_values": [
+                                    "km"
+                                ]
+                            }
+                        ]
+                    }
+                }
+            }
+        }
+    }
+}
\ No newline at end of file
 
--- /dev/null
+{
+    "tosca_definitions_version": "tosca_simple_yaml_1_0_0",
+    "policy_types": {
+        "onap.policies.optimization.SubscriberPolicy": {
+            "derived_from": "onap.policies.Optimization",
+            "version": "1.0.0",
+            "properties": {
+                "subscriberProperties": {
+                    "type": "policy.data.subscriberProperties_properties",
+                    "required": true
+                }
+            }
+        }
+    },
+    "data_types": {
+        "policy.data.subscriberProperties_properties": {
+            "derived_from": "tosca.nodes.Root",
+            "properties": {
+                "subscriberName": {
+                    "type": "list",
+                    "required": true,
+                    "entry_schema": {
+                        "type": "string"
+                    }
+                },
+                "subscriberRole": {
+                    "type": "list",
+                    "required": true,
+                    "entry_schema": {
+                        "type": "string"
+                    }
+                },
+                "provStatus": {
+                    "type": "list",
+                    "required": true,
+                    "entry_schema": {
+                        "type": "string"
+                    }
+                }
+            }
+        }
+    }
+}
\ No newline at end of file
 
 tosca_definitions_version: tosca_simple_yaml_1_0_0
 topology_template:
   policies:
-    - 
-        OSDF_CASABLANCA.Affinity_vCPE_1:
+    -
+        OSDF_CASABLANCA.Affinity_Default:
             type: onap.policies.optimization.AffinityPolicy
             version: 1.0.0
+            type_version: 1.0.0
             metadata:
-                policy-id: OSDF_CASABLANCA.Affinity_vCPE_1
+                policy-id: OSDF_CASABLANCA.Affinity_Default
                 policy-version: 1
             properties:
+                scope: []
+                services: []
+                resources: []
+                geography: [US]
                 identity: affinity_vCPE
-                policyScope: [vCPE, US, INTERNATIONAL, ip, vGMuxInfra, vG]
-                affinityProperties: 
+                applicableResources: any
+                affinityProperties:
                     qualifier: same
                     category: complex
-                policyType: zone
+    -
+        OSDF_CASABLANCA.Affinity_vCPE_0:
+            type: onap.policies.optimization.AffinityPolicy
+            version: 1.0.0
+            type_version: 1.0.0
+            metadata:
+                policy-id: OSDF_CASABLANCA.Affinity_vCPE_0
+                policy-version: 1
+            properties:
+                scope: []
+                services: [vCPE]
+                resources: []
+                geography: [US]
+                identity: affinity_vCPE
+                applicableResources: any
+                affinityProperties:
+                    qualifier: different
+                    category: complex
+    -
+        OSDF_CASABLANCA.Affinity_vCPE_1:
+            type: onap.policies.optimization.AffinityPolicy
+            version: 1.0.0
+            type_version: 1.0.0
+            metadata:
+                policy-id: OSDF_CASABLANCA.Affinity_vCPE_1
+                policy-version: 1
+            properties:
+                scope: [gold, platinum]
+                services: [vCPE]
                 resources: [vGMuxInfra, vG]
+                geography: [US, INTERNATIONAL]
+                identity: affinity_vCPE
+                applicableResources: any
+                affinityProperties:
+                    qualifier: same
+                    category: availabilityZone
     -
         OSDF_CASABLANCA.Capacity_vG_1:
             type: onap.policies.optimization.Vim_fit
             version: 1.0.0
+            type_version: 1.0.0
             metadata:
                 policy-id: OSDF_CASABLANCA.Capacity_vG_1
                 policy-version: 1
             properties:
-                identity: capacity_vG
-                policyScope: [VCPE, US, INTERNATIONAL, ip, vG]
+                scope: []
+                services: [vCPE]
                 resources: [vG]
-                capacityProperty: 
+                geography: [US, INTERNATIONAL]
+                identity: capacity_vG
+                applicableResources: any
+                capacityProperty:
                    controller: multicloud
                    request: "{\"vCPU\": 10, \"Memory\": {\"quantity\": {\"get_param\": \"REQUIRED_MEM\"}, \"unit\": \"GB\"}, \"Storage\": {\"quantity\": {\"get_param\": \"REQUIRED_DISK\"}, \"unit\": \"GB\"}}"
-                policyType: vim_fit
-                applicableResources: any
     -
         OSDF_CASABLANCA.Distance_vG_1:
             type: onap.policies.optimization.DistancePolicy
             version: 1.0.0
+            type_version: 1.0.0
             metadata:
                 policy-id: OSDF_CASABLANCA.Distance_vG_1
                 policy-version: 1
             properties:
-                distanceProperties: 
+                scope: [platinum]
+                services: [vCPE]
+                resources: [vG]
+                geography: [US, INTERNATIONAL]
+                identity: distance-vG
+                applicableResources: any
+                distanceProperties:
                     locationInfo: customer_loc
-                    distance: 
+                    distance:
                         value: 1500
                         operator: "<"
                         unit: km
-                identity: "distance-vG"
-                resources: [vG]
-                policyScope: [vCPE, US, INTERNATIONAL, ip, vG]
-                policyType: distance_to_location
-                applicableResources: any
     -
         OSDF_CASABLANCA.hpa_policy_vG_1:
             type: onap.policies.optimization.HpaPolicy
             version: 1.0.0
+            type_version: 1.0.0
             metadata:
                 policy-id: OSDF_CASABLANCA.hpa_policy_vG_1
                 policy-version: 1
             properties:
+                scope: []
+                services: [vCPE]
                 resources: [vG]
-                identity: "hpa-vG"
-                policyScope: [vCPE, US, INTERNATIONAL, ip, vG]
-                policyType: hpa            
-                # NONE OF THE FLAVORFEATURES CAME OUT RIGHT
+                geography: []
+                identity: hpa-vG
+                flavorFeatures:
+                    -
+                         id: vg_1
+                         type: vnfc
+                         directives:
+                             -    type: flavor_directives
+                                  attributes:
+                                      -    attribute_name: flavor_label_vm_01
+                                           attribute_value: ""
+                         flavorProperties:
+                             -
+                                  hpa-feature: basicCapabilities
+                                  mandatory: True
+                                  architecture: generic
+                                  directives: []
+                                  hpa-feature-attributes:
+                                      -    hpa-attribute-key: numVirtualCpu
+                                           hpa-attribute-value: 6
+                                           operator: ['>=']
+                                           unit: ""
+                                      -    hpa-attribute-key: virtualMemSize
+                                           hpa-attribute-value: 4
+                                           operator: ['<=']
+                                           unit: ""
+                             -
+                                  hpa-feature: ovsDpdk
+                                  mandatory: False
+                                  architecture: generic
+                                  directives: []
+                                  hpa-feature-attributes:
+                                      -    hpa-attribute-key: dataProcessingAccelerationLibrary
+                                           hpa-attribute-value: ovsDpdk_version
+                                           operator: [=]
+                                           unit: ""
     -
         OSDF_CASABLANCA.queryPolicy_vCPE:
             type: onap.policies.optimization.QueryPolicy
             version: 1.0.0
+            type_version: 1.0.0
             metadata:
                 policy-id: OSDF_CASABLANCA.queryPolicy_vCPE
                 policy-version: 1
             properties:
-                queryProperties: 
-                    - 
+                scope: []
+                services: [vCPE]
+                resources: [vGMuxInfra, vG]
+                geography: [US, INTERNATIONAL]
+                identity: vCPE_Query_Policy
+                queryProperties:
+                    -
                         attribute: locationId
                         attribute_location: customerLocation
                         value: ""
-                    - 
+                    -
                         attribute: id
                         attribute_location: "vpnInfo.vpnId"
                         value: ""
-                    - 
+                    -
                         attribute: upstreamBW
                         attribute_location: "vpnInfo.upstreamBW"
                         value: ""
-                    - 
+                    -
                         attribute: customerLatitude
                         attribute_location: customerLatitude
                         value: 1.1
                         attribute: customerLongitude
                         attribute_location: customerLongitude
                         value: 2.2
-                serviceName: vCPE
-                policyScope: [vCPE, US, INTERNATIONAL, ip, vGMuxInfra, vG]
-                policyType: request_param_query
-                identity: vCPE_Query_Policy            
-            
     -
         OSDF_CASABLANCA.SubscriberPolicy_v1:
             type: onap.policies.optimization.SubscriberPolicy
             version: 1.0.0
+            type_version: 1.0.0
             metadata:
                 policy-id: OSDF_CASABLANCA.SubscriberPolicy_v1
                 policy-version: 1
             properties:
+                scope: []
+                services: [vCPE]
                 identity: subscriber_vCPE
-                policyScope: [vCPE, subscriber_x, subscriber_y, subscriberPolicy]
-                properties: 
+                properties:
                     subscriberName: [subscriber_x, subscriber_y]
-                    subscriberRole: ["PVT Homing"]
+                    subscriberRole: [platinum]
+                    provStatus: [CAPPED]
+    -
+        OSDF_CASABLANCA.SubscriberPolicy_v2:
+            type: onap.policies.optimization.SubscriberPolicy
+            version: 1.0.0
+            type_version: 1.0.0
+            metadata:
+                policy-id: OSDF_CASABLANCA.SubscriberPolicy_v2
+                policy-version: 1
+            properties:
+                scope: []
+                services: [vCPE]
+                identity: subscriber_vCPE
+                properties:
+                    subscriberName: [subscriber_a, subscriber_b]
+                    subscriberRole: [gold]
                     provStatus: [CAPPED]
-                policyType: subscriberPolicy
-                serviceName: vCPE
     -
         OSDF_CASABLANCA.vnfPolicy_vG:
             type: onap.policies.optimization.VnfPolicy
             version: 1.0.0
+            type_version: 1.0.0
             metadata:
                 policy-id: OSDF_CASABLANCA.vnfPolicy_vG
                 policy-version: 1
             properties:
-                identity: vnf_vG
-                policyScope: [vCPE, US, INTERNATIONAL, ip, vG]
-                policyType: vnfPolicy
+                scope: []
+                services: [vCPE]
                 resources: [vG]
+                geography: [US, INTERNATIONAL]
+                identity: vnf_vG
                 applicableResources: any
-                vnfProperties: 
-                    - 
+                vnfProperties:
+                    -
                         inventoryProvider: aai
                         serviceType: ""
-                        inventoryType: cloud
+                        inventoryType: cloudRegionId
                         customerId: ""
-                        orchestrationStatus: ""
-                        equipmentRole: ""
\ No newline at end of file
 
 import java.util.stream.Collectors;
 import lombok.Getter;
 import lombok.Setter;
+import org.onap.policy.common.endpoints.parameters.RestServerParameters;
 import org.onap.policy.models.decisions.concepts.DecisionRequest;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
     /**
      * One time to initialize the applications upon startup.
      */
-    public XacmlPdpApplicationManager(Path applicationPath) {
+    public XacmlPdpApplicationManager(Path applicationPath, RestServerParameters policyApiParameters) {
         if (LOGGER.isInfoEnabled()) {
-            LOGGER.info("Initialization applications {}", applicationPath.toAbsolutePath());
+            LOGGER.info("Initialization applications {} {}", applicationPath.toAbsolutePath(), policyApiParameters);
         }
         //
         // Load service
             // Have it initialize at a path
             //
             try {
-                initializeApplicationPath(applicationPath, application);
+                initializeApplicationPath(applicationPath, application, policyApiParameters);
                 //
                 // We are initialized
                 //
         return mapLoadedPolicies.size();
     }
 
-    private void initializeApplicationPath(Path basePath, XacmlApplicationServiceProvider application)
-            throws XacmlApplicationException {
+    private void initializeApplicationPath(Path basePath, XacmlApplicationServiceProvider application,
+            RestServerParameters policyApiParameters) throws XacmlApplicationException {
         //
         // Making an assumption that all application names are unique, and
         // they can result in a valid directory being created.
         //
         // Have the application initialize
         //
-        application.initialize(path);
+        application.initialize(path, policyApiParameters);
     }
 }
 
 
         try {
             XacmlPdpApplicationManager appmgr =
-                            new XacmlPdpApplicationManager(Paths.get(xacmlPdpParameterGroup.getApplicationPath()));
+                            new XacmlPdpApplicationManager(Paths.get(xacmlPdpParameterGroup.getApplicationPath()),
+                                    xacmlPdpParameterGroup.getPolicyApiParameters());
             XacmlPdpApplicationManager.setCurrent(appmgr);
 
             XacmlPdpStatisticsManager stats = new XacmlPdpStatisticsManager();
 
   "ONAPInstance": "OOF-component-instance",
   "action": "optimize",
   "resource": {
-      "policyScope": ["vCPE", "US", "INTERNATIONAL", "ip", "vGMuxInfra", "vG"],
-      "policyType": "zone"
+      "scope": [],
+      "services": ["vCPE"],
+      "resources": [],
+      "geography": ["US"]
   }
 }
\ No newline at end of file
 
         <appender-ref ref="AsyncNetworkOut" />
     </logger>
 
+    <logger name="org.eclipse.jetty" level="ERROR" />
+
     <root level="INFO">
         <appender-ref ref="AsyncDebugOut" />
         <appender-ref ref="AsyncErrorOut" />