Merge "Adding PolicyType to getConfig Response"
authorPamela Dragosh <pdragosh@research.att.com>
Wed, 3 Jan 2018 20:19:17 +0000 (20:19 +0000)
committerGerrit Code Review <gerrit@onap.org>
Wed, 3 Jan 2018 20:19:17 +0000 (20:19 +0000)
1  2 
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java
ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/CreateUpdatePolicyServiceImpl.java

@@@ -40,7 -40,6 +40,6 @@@ import java.nio.file.Paths
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.HashSet;
- import java.util.Iterator;
  import java.util.List;
  import java.util.Properties;
  import java.util.Scanner;
@@@ -88,7 -87,6 +87,6 @@@ import org.onap.policy.xacml.api.pap.ON
  import org.onap.policy.xacml.api.pap.OnapPDP;
  import org.onap.policy.xacml.api.pap.OnapPDPGroup;
  import org.onap.policy.xacml.api.pap.PAPPolicyEngine;
- import org.onap.policy.xacml.std.pap.StdPAPPolicy;
  import org.onap.policy.xacml.std.pap.StdPDP;
  import org.onap.policy.xacml.std.pap.StdPDPGroup;
  import org.onap.policy.xacml.std.pap.StdPDPItemSetChangeNotifier.StdItemSetChangeListener;
@@@ -1421,10 -1419,12 +1419,10 @@@ public class XACMLPapServlet extends Ht
                        //If the selected policy is in the group we must remove the old version of it
                        LOGGER.info("Removing old version of the policy");
                        for(PDPPolicy existingPolicy : currentPoliciesInGroup) {
 -                              if (existingPolicy.getName().equals(policy.getName())){
 -                                      if (!existingPolicy.getId().equals(policy.getId())) {
 -                                              group.removePolicy(existingPolicy);
 -                                              LOGGER.info("Removing policy: " + existingPolicy);
 -                                              break;
 -                                      }
 +                              if (existingPolicy.getName().equals(policy.getName()) && !existingPolicy.getId().equals(policy.getId())){
 +                                      group.removePolicy(existingPolicy);
 +                                      LOGGER.info("Removing policy: " + existingPolicy);
 +                                      break;
                                }
                        }
                        
                                         */
                                        if(apiflag != null){
  
 -                                              // get the request content into a String
 -                                              String json = null;
                                                // read the inputStream into a buffer
                                                java.util.Scanner scanner = new java.util.Scanner(request.getInputStream());
                                                scanner.useDelimiter("\\A");
 -                                              json =  scanner.hasNext() ? scanner.next() : "";
 +                                              String json =  scanner.hasNext() ? scanner.next() : "";
                                                scanner.close();
                                                LOGGER.info("PushPolicy API request: " + json);
                                                
                                                }
                                                
                                                //delete temporary policy file from the bin directory
 -                                              Files.deleteIfExists(Paths.get(policy.getId()));
 +                                              if(policy != null) {
 +                                                      Files.deleteIfExists(Paths.get(policy.getId()));
 +                                              }
                                                
                                        }
                                } catch (Exception e) {
  
                public UpdatePDPThread(OnapPDP pdp, ONAPLoggingContext loggingContext) {
                        this.pdp = pdp;
 -                      if (!(loggingContext == null)) {
 -                              if (!(loggingContext.getRequestID() == null) || (loggingContext.getRequestID() == "")) {
 +                      if ((loggingContext != null) && (loggingContext.getRequestID() != null || loggingContext.getRequestID() == "")) {
                                        this.requestId = loggingContext.getRequestID();
 -                              }
                        }
                        this.loggingContext = loggingContext;
                }
                        HttpURLConnection connection = null;
                        // get a new logging context for the thread
                        try {
 -                              if (this.loggingContext.equals(null)) {
 +                              if (this.loggingContext == null) {
                                     loggingContext = new ONAPLoggingContext(baseLoggingContext);
                                } 
                        } catch (Exception e) {
@@@ -23,7 -23,6 +23,6 @@@ import java.text.SimpleDateFormat
  import java.util.Date;
  import java.util.UUID;
  
- import org.glassfish.jersey.spi.Contract;
  import org.onap.policy.api.PolicyException;
  import org.onap.policy.api.PolicyParameters;
  import org.onap.policy.common.logging.flexlogger.FlexLogger;
@@@ -34,7 -33,6 +33,6 @@@ import org.onap.policy.rest.util.Policy
  import org.onap.policy.rest.util.PolicyValidationRequestWrapper;
  import org.onap.policy.xacml.api.XACMLErrorConstants;
  import org.springframework.http.HttpStatus;
- import org.springframework.stereotype.Controller;
  
  import com.google.common.base.Strings;
  
@@@ -244,13 -242,17 +242,13 @@@ public class CreateUpdatePolicyServiceI
                        return false;
                }
                
 -              if(policyParameters.getPolicyClass() != null){
 -                      if ("Config".equals(policyParameters.getPolicyClass().toString())){
 -                              String policyConfigType = policyParameters.getPolicyConfigType().toString();
 -                              if(!"BRMS_Param".equalsIgnoreCase(policyConfigType)){
 -                              if(Strings.isNullOrEmpty(policyParameters.getConfigBody())){
 -                                      message = XACMLErrorConstants.ERROR_DATA_ISSUE + "ConfigBody: No Config Body given";
 -                              LOGGER.error("Common validation did not return success:  " + message);
 -                            return false;
 -                              }
 -                              }
 -                      }
 +              if(policyParameters.getPolicyClass() != null && "Config".equals(policyParameters.getPolicyClass().toString())){
 +                      String policyConfigType = policyParameters.getPolicyConfigType().toString();
 +                      if(!"BRMS_Param".equalsIgnoreCase(policyConfigType) && Strings.isNullOrEmpty(policyParameters.getConfigBody())){
 +                              message = XACMLErrorConstants.ERROR_DATA_ISSUE + "ConfigBody: No Config Body given";
 +                      LOGGER.error("Common validation did not return success:  " + message);
 +                    return false;
 +                      }
                }
  
                try {