Added changes to save original model file 45/83245/4
authorHOCKLA <ah999m@att.com>
Mon, 25 Mar 2019 17:38:25 +0000 (12:38 -0500)
committerHOCKLA <ah999m@att.com>
Tue, 26 Mar 2019 14:22:00 +0000 (09:22 -0500)
When a user imports a model, save the original model file

Issue-ID: POLICY-1423
Change-Id: Ic7ccf2cc91ce466d7aac644cf566e35577888217
Signed-off-by: HOCKLA <ah999m@att.com>
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateNewMicroServiceModel.java
ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/XACMLPdpServlet.java
ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PolicyEngineImportService.java
ONAP-PDP-REST/xacml.pdp.properties
packages/base/src/files/install/servers/pdp/bin/xacml.pdp.properties

index abb4251..86455aa 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP-PAP-REST
  * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
  * Modified Copyright (C) 2018 Samsung Electronics Co., Ltd.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -333,7 +333,7 @@ public class CreateNewMicroServiceModel {
         Map<String, String> successMap = new HashMap<>();
         CommonClassDaoImpl dbConnection = new CommonClassDaoImpl();
         List<Object> result = dbConnection.getDataById(MicroServiceModels.class, "modelName:version", modelName+":"+version);
-        if(result.isEmpty()){
+        if(result == null || result.isEmpty()){
             MicroServiceModels model = new MicroServiceModels();
             model.setModelName(modelName);
             model.setVersion(version);
index fcf319c..c227d9d 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP-PDP-REST
  * ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-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.
@@ -276,6 +276,13 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable {
             PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "Failed to create IntegrityMonitor" + e);
             throw new ServletException(e);
         }
+        
+        try {
+            System.setProperty("msToscaModel.home", properties.getProperty("msToscaModel.home"));
+        } catch (Exception e) {
+           logger.error("ERROR: Unable to set msToscaModel.home- Please check the configuration");
+        }
+
         startThreads(baseLoggingContext, new Thread(this));
     }
 
index f7c1cc5..f8cba51 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP-PDP-REST
  * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-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.
@@ -20,6 +20,7 @@
 package org.onap.policy.pdp.rest.api.services;
 
 import java.io.BufferedInputStream;
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.UUID;
@@ -77,6 +78,25 @@ public class PolicyEngineImportService {
             importResponse = XACMLErrorConstants.ERROR_DATA_ISSUE + e;
             status = HttpStatus.BAD_REQUEST;
         }
+        
+        // Save the imported file
+        if (!file.isEmpty() && status.equals(HttpStatus.OK) ) {
+            String filePath = null;
+            try {
+                 String uploadsDir = System.getProperty("msToscaModel.home");
+                 if(uploadsDir != null) {
+                     if(! new File(uploadsDir).exists()){
+                         new File(uploadsDir).mkdir();
+                     }
+                     String orgName = file.getOriginalFilename();
+                     filePath = uploadsDir + orgName;
+                     File dest = new File(filePath);
+                     file.transferTo(dest);
+                 }
+             }catch(Exception e){
+                 LOGGER.error("Operation: policyEngineImport : " + e.getMessage() + ". " + filePath + " is not a valid file path.");
+             } 
+         }      
     }
 
     private void specialCheck() {
index b6050ff..90e0f5c 100644 (file)
@@ -2,7 +2,7 @@
 # ============LICENSE_START=======================================================
 # ONAP-PDP-REST
 # ================================================================================
-# Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2017-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.
@@ -192,6 +192,9 @@ aaf_oauth2_token_url=https://aaf-onap-test.osaaf.org:8095/AAF_NS.token:2.1/token
 fs_url=https://aaf-onap-test.osaaf.org:8095/AAF_NS.fs.2.1
 gui_url=https://aaf-onap-test.osaaf.org:8095/AAF_NS.gui.2.1
 
+#TOSCA MS model yaml file directory which can be changed based on systems. 
+#msToscaModel.home=C://home//msyamlFiles//
+msToscaModel.home=/home/users/PolicyEngine/webapps/ConfigPAP/
 
 # Decision Response settings. 
 # can be either PERMIT or DENY. 
index 315fb4d..8835fe4 100644 (file)
@@ -2,7 +2,7 @@
 # ============LICENSE_START=======================================================
 # ONAP Policy Engine
 # ================================================================================
-# Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2017-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.
@@ -164,3 +164,5 @@ gui_url=https://${{AAF_HOST}}:8095/AAF_NS.gui.2.1
 # Decision Response settings. 
 # can be either PERMIT or DENY. 
 decision.indeterminate.response=${{DECISION_INDETERMINATE_RESPONSE}}
+
+msToscaModel.home=${{REST_PDP_WEBAPPS}}
\ No newline at end of file