[POLICY-122] Policy GUI Fixes
[policy/engine.git] / ECOMP-PDP / src / main / java / org / openecomp / policy / xacml / action / FindAction.java
index 86c5c9b..5419b89 100644 (file)
@@ -20,7 +20,6 @@
 package org.openecomp.policy.xacml.action;
 
 import java.io.BufferedReader;
-import java.io.IOException;
 import java.io.InputStreamReader;
 import java.net.URL;
 import java.net.URLConnection;
@@ -35,7 +34,6 @@ import javax.json.Json;
 import javax.json.JsonReader;
 
 import org.apache.http.HttpResponse;
-import org.apache.http.client.ClientProtocolException;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.methods.HttpPost;
 import org.apache.http.client.methods.HttpPut;
@@ -63,6 +61,7 @@ import com.att.research.xacml.std.StdMutableResult;
 import com.att.research.xacml.std.StdObligation;
 import com.att.research.xacml.util.XACMLProperties;
 
+@SuppressWarnings("deprecation")
 public class FindAction {
        private Logger LOGGER = FlexLogger.getLogger(this.getClass());
        private Boolean changeIt = false;
@@ -109,9 +108,9 @@ public class FindAction {
                return newResponse;
        }
 
-       private Collection<Obligation> obligations = new ArrayList<Obligation>();
-       private Map<String, String> matchValues = new HashMap<String, String>();
-       private Map<String, String> headers = new HashMap<String, String>();
+       private Collection<Obligation> obligations = new ArrayList<>();
+       private Map<String, String> matchValues = new HashMap<>();
+       private Map<String, String> headers = new HashMap<>();
        private boolean header = false;
 
        private void search(StdMutableResponse stdResponse) {
@@ -123,7 +122,7 @@ public class FindAction {
                                        int count = 0, uri = 0, PEP = 0;
                                        header = false;
                                        changeIt = false;
-                                       Collection<AttributeAssignment> afterRemoveAssignments = new ArrayList<AttributeAssignment>();
+                                       Collection<AttributeAssignment> afterRemoveAssignments = new ArrayList<>();
                                        Identifier oblId = new IdentifierImpl(obligation.getId().stringValue());
                                        StdAttributeAssignment attributeURI = null;
                                        for (AttributeAssignment attribute : obligation.getAttributeAssignments()) {
@@ -150,22 +149,7 @@ public class FindAction {
                                                        String papPath = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_URL);
                                                        papPath= papPath.replace("/pap", "");
                                                        matchValues.put("body",attribute.getAttributeValue().getValue().toString().replace("$URL", papPath));
-                                               } /*
-                                                * else if (attribute.getAttributeId().stringValue().
-                                                * equalsIgnoreCase("type")){ requestAction.put("Type",
-                                                * attribute.getAttributeValue().getValue().toString());
-                                                * afterRemoveAssignments.add(attribute); } else
-                                                * if(attribute
-                                                * .getAttributeId().stringValue().equalsIgnoreCase
-                                                * ("method")) { requestAction.put("Method",
-                                                * attribute.getAttributeValue().getValue().toString());
-                                                * afterRemoveAssignments.add(attribute); } else
-                                                * if(attribute
-                                                * .getAttributeId().stringValue().equalsIgnoreCase
-                                                * ("body")) { requestAction.put("Body",
-                                                * attribute.getAttributeValue().getValue().toString());
-                                                * afterRemoveAssignments.add(attribute); }
-                                                */else {
+                                               }else {
                                                        StdAttributeAssignment attributeObligation = new StdAttributeAssignment(attribute);
                                                        afterRemoveAssignments.add(attributeObligation);
                                                }
@@ -173,7 +157,7 @@ public class FindAction {
                                        if (count == 1 && uri == 1 && PEP == 0) {
                                                // Remove Obligation and add Advice
                                                changeIt = true;
-                                               TakeAction(stdResponse, oblId, afterRemoveAssignments);
+                                               takeAction(stdResponse, oblId, afterRemoveAssignments);
                                        } else if (PEP == 1 && count == 0) {
                                                // Strip the PEPACTION if available
                                                if (uri == 1) {
@@ -190,7 +174,7 @@ public class FindAction {
                }
        }
 
-       private void TakeAction(StdMutableResponse stdResponse, Identifier advId,
+       private void takeAction(StdMutableResponse stdResponse, Identifier advId,
                        Collection<AttributeAssignment> afterRemoveAssignments) {
                if (changeIt) {
                        LOGGER.info("the URL is :" + configURL);
@@ -198,24 +182,22 @@ public class FindAction {
                        callRest();
                        // Including the Results in an Advice
                        Identifier id = new IdentifierImpl(
-                                       "com:att:labs:ecomp:policy:pdp:reply");
+                                       "org:openecomp:policy:pdp:reply");
                        Identifier statId = new IdentifierImpl(
-                                       "com:att:labs:ecomp:policy:pdp:reply:status");
+                                       "org:openecomp:ecomp:policy:pdp:reply:status");
                        Identifier statCategory = new IdentifierImpl(
                                        "urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject");
                        Identifier strId = new IdentifierImpl(
                                        "http://www.w3.org/2001/XMLSchema#string");
                        Identifier resId = new IdentifierImpl(
-                                       "com:att:labs:ecomp:policy:pdp:reply:resource");
+                                       "org:openecomp:ecomp:policy:pdp:reply:resource");
                        Identifier resCategory = new IdentifierImpl(
                                        "urn:oasis:names:tc:xacml:3.0:attribute-category:resource");
                        Identifier urlId = new IdentifierImpl(
                                        "http://www.w3.org/2001/XMLSchema#anyURI");
-                       // Collection<AttributeAssignment> attributes = new
-                       // ArrayList<AttributeAssignment>();
-                       AttributeValue<String> attributeStatusValue = new StdAttributeValue<String>(
+                       AttributeValue<String> attributeStatusValue = new StdAttributeValue<>(
                                        strId, status + response);
-                       AttributeValue<String> attributeResourceValue = new StdAttributeValue<String>(
+                       AttributeValue<String> attributeResourceValue = new StdAttributeValue<>(
                                        urlId, configURL);
                        StdAttributeAssignment attributeStatus = new StdAttributeAssignment(
                                        statCategory, statId, "PDP", attributeStatusValue);
@@ -288,11 +270,8 @@ public class FindAction {
                                        output = output + out;
                                }
                                response = output;
-                       } catch (ClientProtocolException e) {
-                               LOGGER.error(e.getMessage());
-                               response = e.getMessage();
-                       } catch (IOException e) {
-                               LOGGER.error(e.getMessage());
+                       } catch (Exception e) {
+                               LOGGER.error(e.getMessage()+e);
                                response = e.getMessage();
                        } finally {
                                httpClient.getConnectionManager().shutdown();
@@ -329,11 +308,8 @@ public class FindAction {
                                        output = output + out;
                                }
                                response = output;
-                       } catch (ClientProtocolException e) {
-                               LOGGER.error(e.getMessage());
-                               response = e.getMessage();
-                       } catch (IOException e) {
-                               LOGGER.error(e.getMessage());
+                       }catch (Exception e) {
+                               LOGGER.error(e.getMessage() +e);
                                response = e.getMessage();
                        } finally {
                                httpClient.getConnectionManager().shutdown();
@@ -369,13 +345,10 @@ public class FindAction {
                                        output = output + out;
                                }
                                response = output;
-                       } catch (ClientProtocolException e) {
-                               LOGGER.error(e.getMessage());
+                       } catch (Exception e) {
+                               LOGGER.error(e.getMessage() +e);
                                response = e.getMessage();
-                       } catch (IOException e) {
-                               LOGGER.error(e.getMessage());
-                               response = e.getMessage();
-                       } finally {
+                       }finally {
                                httpClient.getConnectionManager().shutdown();
                        }
                }