Use protected methods vs private 76/121976/2
authorPamela Dragosh <pdragosh@research.att.com>
Wed, 23 Jun 2021 15:05:05 +0000 (11:05 -0400)
committerPamela Dragosh <pdragosh@research.att.com>
Thu, 24 Jun 2021 14:33:45 +0000 (10:33 -0400)
Application and common code in xacml-pdp is meant to be
available for developers to re-use and/or extend as desired.

Private methods are unnecessary at this time, but could be
re-visited in a later release.

For Honolulu, simply moving to protected to keep functionality
the same. Possibly for Istanbul we can make more changes to
support mixing of ONAP application with custom applications
during runtime.

Issue-ID: POLICY-3305
Change-Id: I6db23bda3c81fdbbf86e39cc2cd2e706d8bee63d
Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
(cherry picked from commit 8e0aa0ffa5cef537de1c841acf38300832c52a56)
Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyRequest.java
applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java
applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/GuardPolicyRequest.java
applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/GuardTranslator.java
applications/monitoring/src/main/java/org/onap/policy/xacml/pdp/application/monitoring/MonitoringPdpApplication.java
applications/native/src/main/java/org/onap/policy/xacml/pdp/application/nativ/NativePdpApplicationTranslator.java
applications/optimization/src/main/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplication.java
applications/optimization/src/main/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplicationTranslator.java

index 75b89d2..9618d5b 100644 (file)
@@ -112,14 +112,15 @@ public class StdCombinedPolicyRequest {
         return request;
     }
 
-    private static StdCombinedPolicyRequest addPolicyIds(StdCombinedPolicyRequest request, Collection<Object> ids) {
+    protected static StdCombinedPolicyRequest addPolicyIds(StdCombinedPolicyRequest request, Collection<Object> ids) {
         for (Object id : ids) {
             request.resource.add(id.toString());
         }
         return request;
     }
 
-    private static StdCombinedPolicyRequest addPolicyTypes(StdCombinedPolicyRequest request, Collection<Object> types) {
+    protected static StdCombinedPolicyRequest addPolicyTypes(StdCombinedPolicyRequest request,
+            Collection<Object> types) {
         for (Object type : types) {
             request.resourcePolicyType.add(type.toString());
         }
index 9d0124b..8d71276 100644 (file)
@@ -477,7 +477,7 @@ public class StdMatchableTranslator  extends StdBaseTranslator implements Matcha
      * @param policyTypeId ToscaConceptIdentifier to find
      * @return ToscaPolicyType object. Can be null if failure.
      */
-    private ToscaServiceTemplate findPolicyType(ToscaConceptIdentifier policyTypeId) {
+    protected ToscaServiceTemplate findPolicyType(ToscaConceptIdentifier policyTypeId) {
         //
         // Is it loaded in memory?
         //
@@ -508,7 +508,7 @@ public class StdMatchableTranslator  extends StdBaseTranslator implements Matcha
      * @param policyTypeId ToscaConceptIdentifier input
      * @return ToscaPolicyType object. Null if failure.
      */
-    private ToscaServiceTemplate loadPolicyType(ToscaConceptIdentifier policyTypeId) {
+    protected ToscaServiceTemplate loadPolicyType(ToscaConceptIdentifier policyTypeId) {
         //
         // Construct what the file name should be
         //
@@ -567,7 +567,7 @@ public class StdMatchableTranslator  extends StdBaseTranslator implements Matcha
      * @param policyTypePath Path object to store locally
      * @return ToscaPolicyType object. Null if failure.
      */
-    private synchronized ToscaServiceTemplate pullPolicyType(ToscaConceptIdentifier policyTypeId,
+    protected synchronized ToscaServiceTemplate pullPolicyType(ToscaConceptIdentifier policyTypeId,
             Path policyTypePath) {
         //
         // This is what we return
@@ -603,7 +603,7 @@ public class StdMatchableTranslator  extends StdBaseTranslator implements Matcha
      * @param policyTypeId ToscaConceptIdentifier
      * @return Path object
      */
-    private Path constructLocalFilePath(ToscaConceptIdentifier policyTypeId) {
+    protected Path constructLocalFilePath(ToscaConceptIdentifier policyTypeId) {
         return Paths.get(this.pathForData.toAbsolutePath().toString(), policyTypeId.getName() + "-"
                 + policyTypeId.getVersion() + ".yaml");
     }
index 96b2878..8a77449 100644 (file)
@@ -167,7 +167,7 @@ public class GuardPolicyRequest {
         return request;
     }
 
-    private static GuardPolicyRequest findFields(GuardPolicyRequest request, Map<String, Object> guard)
+    protected static GuardPolicyRequest findFields(GuardPolicyRequest request, Map<String, Object> guard)
             throws ToscaPolicyConversionException {
         if (guard.containsKey("actor")) {
             request.actorId = guard.get("actor").toString();
@@ -192,7 +192,7 @@ public class GuardPolicyRequest {
         return request;
     }
 
-    private static GuardPolicyRequest findFilterFields(GuardPolicyRequest request, Map<String, Object> guard) {
+    protected static GuardPolicyRequest findFilterFields(GuardPolicyRequest request, Map<String, Object> guard) {
         if (guard.containsKey("generic-vnf.vnf-name")) {
             request.vnfName = guard.get("generic-vnf.vnf-name").toString();
         }
index d606cc2..df5fe43 100644 (file)
@@ -194,7 +194,7 @@ public class GuardTranslator implements ToscaPolicyTranslator {
      * @param variable VariableDefinitionType to add
      * @param newPolicyType PolicyType that will be updated
      */
-    private void addVariableToConditionTypes(VariableReferenceType variable,
+    protected void addVariableToConditionTypes(VariableReferenceType variable,
             PolicyType newPolicyType) {
         //
         // Iterate through the rules
@@ -432,7 +432,7 @@ public class GuardTranslator implements ToscaPolicyTranslator {
         return reference;
     }
 
-    private Object parseTimestamp(String string) throws ToscaPolicyConversionException {
+    protected Object parseTimestamp(String string) throws ToscaPolicyConversionException {
         //
         // First see if it is a full datetime object
         //
@@ -675,7 +675,7 @@ public class GuardTranslator implements ToscaPolicyTranslator {
         }
     }
 
-    private String validateFilterPropertyField(String field)
+    protected String validateFilterPropertyField(String field)
             throws ToscaPolicyConversionException {
         String fieldLowerCase = field.toLowerCase();
         switch (fieldLowerCase) {
@@ -691,7 +691,7 @@ public class GuardTranslator implements ToscaPolicyTranslator {
         }
     }
 
-    private Identifier validateFilterPropertyFunction(String function)
+    protected Identifier validateFilterPropertyFunction(String function)
             throws ToscaPolicyConversionException {
         switch (function.toLowerCase()) {
             case "string-equal":
@@ -719,7 +719,7 @@ public class GuardTranslator implements ToscaPolicyTranslator {
         }
     }
 
-    private RuleType createFilterRule(String ruleId, String field, String filter, Identifier function,
+    protected RuleType createFilterRule(String ruleId, String field, String filter, Identifier function,
             boolean isBlacklisted) {
         var rule = new RuleType();
         rule.setRuleId(ruleId);
index fc03f1c..95150c3 100644 (file)
@@ -118,7 +118,7 @@ public class MonitoringPdpApplication extends StdXacmlApplicationServiceProvider
      *
      * @param queryParams - http request query parameters
      */
-    private boolean checkAbbreviateResults(Map<String, String[]> queryParams) {
+    protected boolean checkAbbreviateResults(Map<String, String[]> queryParams) {
         if (queryParams != null && !queryParams.isEmpty()) {
             // Check if query params contains "abbrev" flag
             if (queryParams.containsKey("abbrev")) {
index a1230c2..06e324d 100644 (file)
@@ -86,7 +86,7 @@ public class NativePdpApplicationTranslator implements ToscaPolicyTranslator {
         }
     }
 
-    private String getNativeXacmlPolicy(ToscaPolicy toscaPolicy) throws ToscaPolicyConversionException {
+    protected String getNativeXacmlPolicy(ToscaPolicy toscaPolicy) throws ToscaPolicyConversionException {
 
         var nativeDefinition = ToscaPolicyTranslatorUtils.decodeProperties(toscaPolicy.getProperties(),
                         NativeDefinition.class);
index 92a8e68..998ed53 100644 (file)
@@ -188,14 +188,14 @@ public class OptimizationPdpApplication extends StdXacmlApplicationServiceProvid
     }
 
     @SuppressWarnings("unchecked")
-    private boolean hasSubscriberAttributes(DecisionRequest request) {
+    protected boolean hasSubscriberAttributes(DecisionRequest request) {
         return request.getContext() != null
                 && request.getContext().containsKey(RESOURCE_SUBSCRIBERNAME)
                 && request.getContext().get(RESOURCE_SUBSCRIBERNAME) instanceof List
                 && ! ((List<String>) request.getContext().get(RESOURCE_SUBSCRIBERNAME)).isEmpty();
     }
 
-    private boolean addSubscriberAttributes(Response xacmlResponse, DecisionRequest initialRequest) {
+    protected boolean addSubscriberAttributes(Response xacmlResponse, DecisionRequest initialRequest) {
         //
         // This has multiple results right now because of how the attributes were added to the
         // request. That will have to be fixed in the future, for now find the Permit result
@@ -221,7 +221,7 @@ public class OptimizationPdpApplication extends StdXacmlApplicationServiceProvid
         return false;
     }
 
-    private void addSubscriberAdvice(Response xacmlResponse, DecisionResponse response) {
+    protected void addSubscriberAdvice(Response xacmlResponse, DecisionResponse response) {
         //
         // Again find the Permit result
         //
@@ -237,7 +237,7 @@ public class OptimizationPdpApplication extends StdXacmlApplicationServiceProvid
 
 
     @SuppressWarnings("unchecked")
-    private void scanAdvice(Collection<Advice> adviceCollection, DecisionRequest initialRequest) {
+    protected void scanAdvice(Collection<Advice> adviceCollection, DecisionRequest initialRequest) {
         //
         // There really should only be one advice object
         //
index e1fe2dc..84a6ffa 100644 (file)
@@ -136,7 +136,7 @@ public class OptimizationPdpApplicationTranslator extends StdMatchableTranslator
     }
 
     @SuppressWarnings("unchecked")
-    private static void addValuesToMap(Object values, String key, Map<String, Object> mapAdvice) {
+    protected static void addValuesToMap(Object values, String key, Map<String, Object> mapAdvice) {
         if (values instanceof Collection) {
             List<String> valueList = new ArrayList<>();
             ((Collection<Object>) values).forEach(val -> valueList.add(val.toString()));
@@ -147,7 +147,7 @@ public class OptimizationPdpApplicationTranslator extends StdMatchableTranslator
 
     }
 
-    private static PolicyType addSubscriberNameIntoTarget(PolicyType policy,
+    protected static PolicyType addSubscriberNameIntoTarget(PolicyType policy,
             Map<String, Object> subscriberProperties) throws ToscaPolicyConversionException {
         //
         // Iterate through all the subscriber names
@@ -174,7 +174,7 @@ public class OptimizationPdpApplicationTranslator extends StdMatchableTranslator
         return policy;
     }
 
-    private static AdviceExpressionsType generateSubscriberAdvice(Map<String, Object> subscriberProperties)
+    protected static AdviceExpressionsType generateSubscriberAdvice(Map<String, Object> subscriberProperties)
             throws ToscaPolicyConversionException {
         //
         // Create our subscriber advice expression
@@ -207,7 +207,7 @@ public class OptimizationPdpApplicationTranslator extends StdMatchableTranslator
         return adviceExpressions;
     }
 
-    private static void generateSubscriberAdviceAttributes(AdviceExpressionType adviceExpression,
+    protected static void generateSubscriberAdviceAttributes(AdviceExpressionType adviceExpression,
             Identifier attributeId, Collection<Object> adviceAttribute) {
         for (Object attribute : adviceAttribute) {
             var value = new AttributeValueType();