Pick up userId from apex editor URL 83/113383/2
authorliamfallon <liam.fallon@est.tech>
Wed, 30 Sep 2020 14:56:24 +0000 (15:56 +0100)
committerLiam Fallon <liam.fallon@est.tech>
Wed, 30 Sep 2020 15:22:25 +0000 (15:22 +0000)
The userId must be picked up from the URL passed to the policy editor
and then passed to the server.

Issue-ID: POLICY-2850
Change-Id: I98948f2e0a2bf8090926751ee98c26c46d272fcf
Signed-off-by: liamfallon <liam.fallon@est.tech>
gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ApexEditorRestResource.java
gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/plugin/upload/PolicyUploadHandler.java
gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexFiles.js

index ba3d5e7..dc27d49 100644 (file)
@@ -32,9 +32,11 @@ import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.MediaType;
+import org.apache.commons.lang3.StringUtils;
 import org.onap.policy.apex.model.modelapi.ApexApiResult;
 import org.onap.policy.apex.model.modelapi.ApexApiResult.Result;
 import org.onap.policy.common.utils.resources.TextFileUtils;
+import org.onap.policy.gui.editors.apex.rest.ApexEditorMain;
 import org.slf4j.ext.XLogger;
 import org.slf4j.ext.XLoggerFactory;
 
@@ -229,11 +231,15 @@ public class ApexEditorRestResource implements RestCommandHandler {
     /**
      * Uploads a TOSCA Policy Model to a configured endpoint.
      *
+     * @param userid the userid to use for upload
      * @return an ApexAPIResult that contains the operation status and success/error messages
      */
     @GET
     @Path("Model/Upload")
-    public ApexApiResult uploadModel() {
+    public ApexApiResult uploadModel(@QueryParam("userId") final String userid) {
+        if (!StringUtils.isBlank(userid)) {
+            ApexEditorMain.getParameters().setUploadUserid(userid);
+        }
         return processRestCommand(RestCommandType.MODEL, RestCommand.UPLOAD);
     }
 
index 5e3cf56..6d8b803 100644 (file)
@@ -56,7 +56,7 @@ public class PolicyUploadHandler {
 
         if (StringUtils.isBlank(ApexEditorMain.getParameters().getUploadUrl())) {
             final ApexApiResult apexApiResult = new ApexApiResult(Result.FAILED);
-            apexApiResult.addMessage("Model download is disabled, parameter upload-url is not set on server");
+            apexApiResult.addMessage("Model upload is disabled, parameter upload-url is not set on server");
             LOGGER.exit(MODEL_UPLOAD_NOT_OK);
             return apexApiResult;
 
index a8726e7..93b1183 100644 (file)
@@ -51,7 +51,7 @@ function files_fileDownload() {
 }
 
 function files_fileUpload() {
-    var requestURL = restRootURL + "/Model/Upload";
+    var requestURL = restRootURL + "/Model/Upload?userId=" + new URLSearchParams(window.location.search).get('userId');
 
     ajax_getOKOrFail(requestURL, function(data) {
         var uploadResultString = "";