diff options
Diffstat (limited to 'POLICY-SDK-APP/src/main')
7 files changed, 67 insertions, 247 deletions
diff --git a/POLICY-SDK-APP/src/main/java/org/openecomp/policy/components/HumanPolicyComponent.java b/POLICY-SDK-APP/src/main/java/org/openecomp/policy/components/HumanPolicyComponent.java index b67cb261d..5b4fdeb02 100644 --- a/POLICY-SDK-APP/src/main/java/org/openecomp/policy/components/HumanPolicyComponent.java +++ b/POLICY-SDK-APP/src/main/java/org/openecomp/policy/components/HumanPolicyComponent.java @@ -27,8 +27,8 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; -import java.nio.file.FileSystems; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; @@ -37,6 +37,23 @@ import java.util.Map; import javax.xml.bind.JAXBElement; +import org.apache.commons.io.FilenameUtils; +import org.json.JSONObject; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.openecomp.policy.controller.PolicyController; +import org.openecomp.policy.rest.jpa.FunctionDefinition; +import org.openecomp.policy.utils.XACMLPolicyWriterWithPapNotify; +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import org.openecomp.policy.xacml.util.XACMLPolicyScanner; + +import com.att.research.xacml.api.AttributeValue; +import com.att.research.xacml.std.IdentifierImpl; +import com.att.research.xacml.std.StdAttribute; +import com.att.research.xacml.std.StdAttributeValue; +import com.att.research.xacml.util.XACMLPolicyScanner.CallbackResult; +import com.att.research.xacml.util.XACMLPolicyScanner.SimpleCallback; + import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType; @@ -55,24 +72,6 @@ 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.VariableReferenceType; -import org.apache.commons.io.FilenameUtils; -import org.json.JSONObject; -import org.openecomp.policy.controller.PolicyController; -import org.openecomp.policy.rest.jpa.FunctionDefinition; -import org.openecomp.policy.utils.XACMLPolicyWriterWithPapNotify; - -import com.att.research.xacml.api.AttributeValue; -import org.openecomp.policy.xacml.api.XACMLErrorConstants; -import com.att.research.xacml.std.IdentifierImpl; -import com.att.research.xacml.std.StdAttribute; -import com.att.research.xacml.std.StdAttributeValue; -import org.openecomp.policy.xacml.util.XACMLPolicyScanner; -import com.att.research.xacml.util.XACMLPolicyScanner.CallbackResult; -import com.att.research.xacml.util.XACMLPolicyScanner.SimpleCallback; - -import org.openecomp.policy.common.logging.flexlogger.FlexLogger; -import org.openecomp.policy.common.logging.flexlogger.Logger; - public class HumanPolicyComponent{ @@ -147,7 +146,7 @@ public class HumanPolicyComponent{ HumanPolicyComponent.htmlProcessor = new HtmlProcessor(HumanPolicyComponent.policyFile, policy); - Path policyPath = FileSystems.getDefault().getPath(policyFile.getAbsolutePath()); + Path policyPath = Paths.get(policyFile.getAbsolutePath()); XACMLPolicyScanner xacmlScanner = new XACMLPolicyScanner(policyPath, htmlProcessor); xacmlScanner.scan(); String html = htmlProcessor.html(); @@ -734,35 +733,36 @@ class HtmlProcessor extends SimpleCallback { } String functionName = getHumanFunction(match.getMatchId()); - - String succintIdentifier = extractLastIdentifier(attribute.getCategory().stringValue(), ":") + - ":" + extractLastIdentifier(attribute.getAttributeId().stringValue(), ":"); - AttributeIdentifiers ai = new AttributeIdentifiers(attribute.getCategory().stringValue(), - attributeDataType, - attribute.getAttributeId().stringValue()); - this.attributeIdentifiersMap.put(succintIdentifier,ai); - - targetInHuman += "<i><a href=\"#" + succintIdentifier + "\">" + succintIdentifier + "</a></i> " + functionName + " "; - - int numAttributes = attribute.getValues().size(); - int count = 0; - for (AttributeValue<?> v: attribute.getValues()) { - count++; - if (v.getValue() instanceof Collection<?>) { - Collection<?> value_s = (Collection<?>) v.getValue(); - int numValues = value_s.size(); - int countValues = 0; - for (Object o : value_s) { - countValues++; - targetInHuman += " <I>" + o + "</I>"; - if (countValues < numValues) { - targetInHuman += ", or"; + if(attribute != null){ + String succintIdentifier = extractLastIdentifier(attribute.getCategory().stringValue(), ":") + + ":" + extractLastIdentifier(attribute.getAttributeId().stringValue(), ":"); + AttributeIdentifiers ai = new AttributeIdentifiers(attribute.getCategory().stringValue(), + attributeDataType, + attribute.getAttributeId().stringValue()); + this.attributeIdentifiersMap.put(succintIdentifier,ai); + + targetInHuman += "<i><a href=\"#" + succintIdentifier + "\">" + succintIdentifier + "</a></i> " + functionName + " "; + + int numAttributes = attribute.getValues().size(); + int count = 0; + for (AttributeValue<?> v: attribute.getValues()) { + count++; + if (v.getValue() instanceof Collection<?>) { + Collection<?> value_s = (Collection<?>) v.getValue(); + int numValues = value_s.size(); + int countValues = 0; + for (Object o : value_s) { + countValues++; + targetInHuman += " <I>" + o + "</I>"; + if (countValues < numValues) { + targetInHuman += ", or"; + } + } + } else { + targetInHuman += " <I>" + v.getValue() + "</I>"; + if (count < numAttributes) { + targetInHuman += ", or "; } - } - } else { - targetInHuman += " <I>" + v.getValue() + "</I>"; - if (count < numAttributes) { - targetInHuman += ", or "; } } } diff --git a/POLICY-SDK-APP/src/main/java/org/openecomp/policy/components/PolicyImportWindow.java b/POLICY-SDK-APP/src/main/java/org/openecomp/policy/components/PolicyImportWindow.java deleted file mode 100644 index f5cc5d0fa..000000000 --- a/POLICY-SDK-APP/src/main/java/org/openecomp/policy/components/PolicyImportWindow.java +++ /dev/null @@ -1,177 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP Policy Engine - * ================================================================================ - * Copyright (C) 2017 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.components; - - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Set; - -import org.apache.commons.compress.archivers.tar.TarArchiveEntry; -import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; -import org.apache.commons.io.IOUtils; -import org.openecomp.policy.common.logging.flexlogger.FlexLogger; -import org.openecomp.policy.common.logging.flexlogger.Logger; -import org.openecomp.policy.xacml.api.XACMLErrorConstants; - - - -public class PolicyImportWindow{ - - private static final Logger LOGGER = FlexLogger.getLogger(PolicyImportWindow.class); - private Path newfile = null; - private boolean succeeded = false; - private Boolean superadmin = false; - private ArrayList<String> xacmlFiles = new ArrayList<String>(); - private static FileOutputStream outputFile; - /** - * The constructor should first build the main layout, set the - * composition root and then do any custom initialization. - * - * The constructor will not be automatically regenerated by the - * visual editor. - */ - - public OutputStream receiveUpload(String filename, String mimeType) { - - // - // Create its new full path - // - this.newfile = null; - // - // Does it already exist? - // - if (Files.exists(this.newfile)) { - return null; - } - // - // Try to create the output stream - // - try { - return new FileOutputStream(this.newfile.toFile()); - } catch (FileNotFoundException e) { - LOGGER.error("Failed to create uploaded file", e); - } - return null; - } - - public void Upload(){ - TarArchiveEntry entry = null; - TarArchiveInputStream extractFile = null; - try { - extractFile = new TarArchiveInputStream (new FileInputStream(this.newfile.toFile())); - } catch (FileNotFoundException e1) { - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW+"Exception while Importing Polcies"+e1); - } - //Create a loop to read every single entry in TAR file - try { - while (extractFile!=null && (entry = extractFile.getNextTarEntry()) != null) { - this.superadmin = true; - try{ - copyFileToLocation(extractFile, entry, xacmlFiles, null, superadmin); - }catch(Exception e){ - LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR+"Exception while Importing Polcies"+e); - } - } - } catch (IOException e) { - LOGGER.error("Exception Occured"+e); - }finally{ - try { - if(extractFile != null){ - extractFile.close(); - } - } catch (IOException e) { - LOGGER.error("Exception Occured"+e); - } - } - - } - - //Copy files to Directorys - public static void copyFileToLocation(TarArchiveInputStream extractFile, TarArchiveEntry entry, ArrayList<String> xacmlFiles, Set<String> finalScopes, Boolean superadminValue ) throws IOException{ - String individualFiles = ""; - int offset = 0; - outputFile = null; - // Get the name of the file - if(superadminValue){ - individualFiles = entry.getName(); - }else{ - for(int i =0; i< finalScopes.size(); i++){ - if(entry.getName().startsWith(finalScopes.toArray()[i].toString())){ - individualFiles = entry.getName(); - } - } - } - - if(individualFiles.endsWith(".xls")){ - if(individualFiles.contains("\\")){ - individualFiles = individualFiles.replace("\\", File.separator); - }else if(individualFiles.contains("/")){ - individualFiles = individualFiles.replace("/", File.separator); - } - return; - } - - individualFiles = individualFiles.replace("/", File.separator); - individualFiles = individualFiles.replace("\\", File.separator); - - //Create the path with the entry name - - - - // Get Size of the file and create a byte array for the size - byte[] content = new byte[(int) entry.getSize()]; - - offset=0; - LOGGER.info("Size of the File is: " + entry.getSize()); - // Read file from the archive into byte array - extractFile.read(content, offset, content.length - offset); - - // Use IOUtiles to write content of byte array to physical file - IOUtils.write(content,outputFile); - - // Close Output Stream - try { - if(outputFile != null){ - outputFile.close(); - } - } catch (IOException e) { - LOGGER.info("IOException:" +e); - LOGGER.error("Exception Occured"+e); - } - } - - - public Path getUploadedFile() { - if (this.succeeded) { - return this.newfile; - } - return null; - } - -} diff --git a/POLICY-SDK-APP/src/main/java/org/openecomp/policy/controller/PolicyValidationController.java b/POLICY-SDK-APP/src/main/java/org/openecomp/policy/controller/PolicyValidationController.java index bb138d415..ed47fd949 100644 --- a/POLICY-SDK-APP/src/main/java/org/openecomp/policy/controller/PolicyValidationController.java +++ b/POLICY-SDK-APP/src/main/java/org/openecomp/policy/controller/PolicyValidationController.java @@ -22,7 +22,6 @@ package org.openecomp.policy.controller; import java.io.ByteArrayInputStream; -import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.StringReader; @@ -42,7 +41,6 @@ import javax.json.Json; import javax.json.JsonReader; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; @@ -65,7 +63,6 @@ import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import org.xml.sax.InputSource; -import org.xml.sax.SAXException; import org.xml.sax.XMLReader; import com.fasterxml.jackson.databind.DeserializationFeature; @@ -419,12 +416,6 @@ public class PolicyValidationController extends RestrictedBaseController { } } } - //for continue testing for Dkat, just blocked this validation until fixing it. gw1218 on 3/30/17 - //if (!checkAttributeValues()){ - //responseString.append("<b>Micro Service</b>:<i> Attribute Values Missing" + "</i><br>"); - //valid = false; - //} - }else{ responseString.append("<b>Micro Service</b>:<i> Micro Service is required" + "</i><br>"); valid = false; @@ -576,7 +567,7 @@ public class PolicyValidationController extends RestrictedBaseController { if (!spData.isEmpty()){ SafePolicyWarning safePolicyWarningData = (SafePolicyWarning) spData.get(0); safePolicyWarningData.getMessage(); - value = "Messaage:" + safePolicyWarningData.getMessage(); + value = "Message:" + safePolicyWarningData.getMessage(); } responseString.append("success" + "@#"+ value); } @@ -698,14 +689,19 @@ public class PolicyValidationController extends RestrictedBaseController { // Validation for json. protected static boolean isJSONValid(String data) { + JsonReader jsonReader = null; try { new JSONObject(data); InputStream stream = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)); - JsonReader jsonReader = Json.createReader(stream); - System.out.println("Json Value is: " + jsonReader.read().toString() ); + jsonReader = Json.createReader(stream); + LOGGER.info("Json Value is: " + jsonReader.read().toString() ); } catch (Exception e) { - e.printStackTrace(); + LOGGER.error("Exception Occured While Validating"+e); return false; + }finally{ + if(jsonReader != null){ + jsonReader.close(); + } } return true; } @@ -720,11 +716,8 @@ public class PolicyValidationController extends RestrictedBaseController { XMLReader reader = parser.getXMLReader(); reader.setErrorHandler(new XMLErrorHandler()); reader.parse(new InputSource(new StringReader(data))); - } catch (ParserConfigurationException e) { - return false; - } catch (SAXException e) { - return false; - } catch (IOException e) { + } catch (Exception e) { + LOGGER.error("Exception Occured While Validating"+e); return false; } return true; diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/policy_AutoPush.html b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/policy_AutoPush.html index 776663595..070cafc8b 100644 --- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/policy_AutoPush.html +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/policy_AutoPush.html @@ -27,9 +27,10 @@ /* The Modal (background) */ .modal { + overflow-y: auto; display: block; position: fixed; - z-index: 1; + z-index: 2; left: 0; top: 0; width: 100%; diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/policy_Dictionary.html b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/policy_Dictionary.html index 4e3a9746f..2eaf98cd9 100644 --- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/policy_Dictionary.html +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/policy_Dictionary.html @@ -20,9 +20,10 @@ <style> /* The Modal (background) */ .modal { + overflow-y: auto; display: block; position: fixed; - z-index: 1; + z-index: 2; left: 0; top: 0; width: 100%; diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/policy_PDPManagement.html b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/policy_PDPManagement.html index 4c77cf528..613eb6d4c 100644 --- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/policy_PDPManagement.html +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/policy_PDPManagement.html @@ -20,9 +20,10 @@ <style> /* The Modal (background) */ .modal { + overflow-y: auto; display: block; position: fixed; - z-index: 1; + z-index: 2; left: 0; top: 0; width: 100%; diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/policy_Roles.html b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/policy_Roles.html index 6df44bc24..2c112477d 100644 --- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/policy_Roles.html +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/policy_Roles.html @@ -20,9 +20,10 @@ <style> /* The Modal (background) */ .modal { + overflow-y: auto; display: block; position: fixed; - z-index: 1; + z-index: 2; left: 0; top: 0; width: 100%; |