aboutsummaryrefslogtreecommitdiffstats
path: root/gui-editors/gui-editor-apex/src
diff options
context:
space:
mode:
Diffstat (limited to 'gui-editors/gui-editor-apex/src')
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ApexEditorRestResource.java16
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/PolicyUploadHandler.java8
-rw-r--r--gui-editors/gui-editor-apex/src/main/resources/webapp/index.html1
-rw-r--r--gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexUser.js30
-rw-r--r--gui-editors/gui-editor-apex/src/main/resources/webapp/upload/dialog.html10
-rw-r--r--gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/PolicyUploadHandlerTest.java15
6 files changed, 59 insertions, 21 deletions
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ApexEditorRestResource.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ApexEditorRestResource.java
index 33aa04d..3083c4a 100644
--- a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ApexEditorRestResource.java
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/ApexEditorRestResource.java
@@ -74,7 +74,6 @@ import org.slf4j.ext.XLoggerFactory;
public class ApexEditorRestResource implements RestCommandHandler {
// Get a reference to the logger
-
private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexEditorRestResource.class);
// Location of the periodi event template
@@ -262,13 +261,15 @@ public class ApexEditorRestResource implements RestCommandHandler {
@Path("Model/Upload")
@Consumes({MediaType.MULTIPART_FORM_DATA})
public ApexApiResult uploadModel(@FormDataParam("tosca-template-file") InputStream toscaTemplateFileStream,
- @FormDataParam("apex-config-file") InputStream apexConfigFileStream) {
+ @FormDataParam("apex-config-file") InputStream apexConfigFileStream,
+ @FormDataParam("userId") String userId) {
final ApexApiResult result = new ApexApiResult();
final RestSession session = SESSION_HANDLER.getSession(sessionId, result);
if (session == null) {
return result;
}
- return policyUploadHandler.doUpload(session.getApexModel(), toscaTemplateFileStream, apexConfigFileStream);
+ return policyUploadHandler.doUpload(session.getApexModel(), toscaTemplateFileStream,
+ apexConfigFileStream, userId);
}
/**
@@ -295,7 +296,7 @@ public class ApexEditorRestResource implements RestCommandHandler {
@GET
@Path("KeyInformation/Get")
public ApexApiResult listKeyInformation(@QueryParam(NAME) final String name,
- @QueryParam(VERSION) final String version) {
+ @QueryParam(VERSION) final String version) {
return processRestCommand(RestCommandType.KEY_INFO, RestCommand.LIST, name, version);
}
@@ -587,7 +588,6 @@ public class ApexEditorRestResource implements RestCommandHandler {
return processRestCommand(RestCommandType.TASK, RestCommand.VALIDATE, name, version);
}
- // CHECKSTYLE:OFF: MethodLength
/**
* Creates a policy with the information in the JSON string passed.
*
@@ -741,7 +741,7 @@ public class ApexEditorRestResource implements RestCommandHandler {
*/
@Override
public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
- final RestCommand command) {
+ final RestCommand command) {
switch (commandType) {
case MODEL:
return MODEL_HANDLER.executeRestCommand(session, commandType, command);
@@ -773,7 +773,7 @@ public class ApexEditorRestResource implements RestCommandHandler {
*/
@Override
public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
- final RestCommand command, final String jsonString) {
+ final RestCommand command, final String jsonString) {
switch (commandType) {
case MODEL:
return MODEL_HANDLER.executeRestCommand(session, commandType, command, jsonString);
@@ -806,7 +806,7 @@ public class ApexEditorRestResource implements RestCommandHandler {
*/
@Override
public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
- final RestCommand command, final String name, final String version) {
+ final RestCommand command, final String name, final String version) {
switch (commandType) {
case MODEL:
return MODEL_HANDLER.executeRestCommand(session, commandType, command, name, version);
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/PolicyUploadHandler.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/PolicyUploadHandler.java
index af8d9dd..3540b2d 100644
--- a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/PolicyUploadHandler.java
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/handling/PolicyUploadHandler.java
@@ -83,7 +83,7 @@ public class PolicyUploadHandler {
* @return the result of the upload process
*/
public ApexApiResult doUpload(final ApexModel apexModel, final InputStream toscaTemplateInputStream,
- final InputStream apexConfigInputStream) {
+ final InputStream apexConfigInputStream, final String userId) {
final ProcessedTemplate processedToscaTemplate;
try {
processedToscaTemplate = toscaTemplateProcessor.process(toscaTemplateInputStream);
@@ -113,10 +113,11 @@ public class PolicyUploadHandler {
if (!processedApexConfig.isValid()) {
return buildResponse(processedApexConfig);
}
- return doUpload(apexModel, processedToscaTemplate.getContent(), processedApexConfig.getContent());
+ return doUpload(apexModel, processedToscaTemplate.getContent(), processedApexConfig.getContent(), userId);
}
- private ApexApiResult doUpload(final ApexModel apexModel, final String toscaTemplate, final String apexConfig) {
+ private ApexApiResult doUpload(final ApexModel apexModel, final String toscaTemplate, final String apexConfig,
+ final String userId) {
LOGGER.entry();
if (!isUploadPluginEnabled()) {
final ApexApiResult apexApiResult = new ApexApiResult(Result.FAILED);
@@ -128,6 +129,7 @@ public class PolicyUploadHandler {
final UploadPolicyRequestDto uploadPolicyRequestDto = new UploadPolicyRequestDto();
final AxArtifactKey policyKey = policyModel.getKeyInformation().getKey();
final java.util.UUID uuid = policyModel.getKeyInformation().get(policyKey).getUuid();
+ uploadPolicyRequestDto.setUserId(userId);
uploadPolicyRequestDto
.setFilename(String.format("%s.%s.%s", uuid, policyKey.getName(), policyKey.getVersion()));
final String apexPolicy = convert(result.getMessage(), toscaTemplate, apexConfig).orElse(null);
diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/index.html b/gui-editors/gui-editor-apex/src/main/resources/webapp/index.html
index 53e205e..7aa3508 100644
--- a/gui-editors/gui-editor-apex/src/main/resources/webapp/index.html
+++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/index.html
@@ -242,6 +242,7 @@
<script type="text/javascript" src="js/ApexConfig.js"></script>
<script type="text/javascript" src="js/ApexUpload.js"></script>
<script type="text/javascript" src="js/ApexMain.js"></script>
+ <script type="text/javascript" src="js/ApexUser.js"></script>
</body>
</html>
diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexUser.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexUser.js
new file mode 100644
index 0000000..684fdf7
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexUser.js
@@ -0,0 +1,30 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+const userManager = {
+ userId: null
+};
+
+(function () {
+ //grabbing the userId
+ const urlParams = new URLSearchParams(window.location.search);
+ userManager.userId = urlParams.get('userId');
+})();
diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/upload/dialog.html b/gui-editors/gui-editor-apex/src/main/resources/webapp/upload/dialog.html
index aac7762..912bec4 100644
--- a/gui-editors/gui-editor-apex/src/main/resources/webapp/upload/dialog.html
+++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/upload/dialog.html
@@ -30,6 +30,7 @@
const toscaTemplateFile = $('#tosca-template-file')[0].files[0];
data.append('apex-config-file', apexConfigFile);
data.append('tosca-template-file', toscaTemplateFile);
+ data.append('userId', userManager.userId);
uploadPlugin.upload(data, function () {
dialog.dialog("close");
});
@@ -48,6 +49,7 @@
}
});
});
+
</script>
</head>
<body>
@@ -55,10 +57,12 @@
<p>Provide the following files to compose the policy TOSCA</p>
<div id="upload-form">
<label for="apex-config-file">Apex Config</label> <br/>
- <input id="apex-config-file" type="file" required="required" accept="application/json" class="ui-widget-content ui-corner-all"/> <br/>
+ <input id="apex-config-file" type="file" required="required" accept="application/json"
+ class="ui-widget-content ui-corner-all"/> <br/>
<label for="tosca-template-file">Tosca Template</label> <br/>
- <input id="tosca-template-file" type="file" required="required" accept="application/json" class="ui-widget-content ui-corner-all"/>
+ <input id="tosca-template-file" type="file" required="required" accept="application/json"
+ class="ui-widget-content ui-corner-all"/>
</div>
</div>
</body>
-</html> \ No newline at end of file
+</html>
diff --git a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/PolicyUploadHandlerTest.java b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/PolicyUploadHandlerTest.java
index 7a6ead7..6ec5eef 100644
--- a/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/PolicyUploadHandlerTest.java
+++ b/gui-editors/gui-editor-apex/src/test/java/org/onap/policy/gui/editors/apex/rest/handling/converter/tosca/PolicyUploadHandlerTest.java
@@ -52,6 +52,7 @@ import org.onap.policy.gui.editors.apex.rest.handling.plugin.upload.UploadPolicy
public class PolicyUploadHandlerTest {
+ private static final String USER_ID = "cs0008";
@Mock
private PolicyToscaConverter policyToscaConverter;
@Mock
@@ -87,7 +88,7 @@ public class PolicyUploadHandlerTest {
.thenReturn(Response.ok().status(201).build());
ApexApiResult apexApiResult = policyUploadHandler
- .doUpload(apexModel, mock(InputStream.class), mock(InputStream.class));
+ .doUpload(apexModel, mock(InputStream.class), mock(InputStream.class), USER_ID);
assertThat("Response should be ok", apexApiResult.isOk(), is(true));
String expectedSuccessMsg =
@@ -99,7 +100,7 @@ public class PolicyUploadHandlerTest {
.thenReturn(Response.serverError().build());
apexApiResult = policyUploadHandler
- .doUpload(apexModel, mock(InputStream.class), mock(InputStream.class));
+ .doUpload(apexModel, mock(InputStream.class), mock(InputStream.class), USER_ID);
assertThat("Response should not be ok", apexApiResult.isNok(), is(true));
expectedSuccessMsg =
@@ -118,7 +119,7 @@ public class PolicyUploadHandlerTest {
when(toscaTemplateProcessor.process(any(InputStream.class))).thenReturn(processedToscaTemplate);
when(apexConfigProcessor.process(any(InputStream.class))).thenReturn(processedApexConfig);
final ApexApiResult apexApiResult = policyUploadHandler
- .doUpload(mock(ApexModel.class), mock(InputStream.class), mock(InputStream.class));
+ .doUpload(mock(ApexModel.class), mock(InputStream.class), mock(InputStream.class), USER_ID);
assertThat("Response should not be ok", apexApiResult.isNok(), is(true));
assertThat("Response message should be as expected",
@@ -134,7 +135,7 @@ public class PolicyUploadHandlerTest {
processedToscaTemplate.addToErrors(Collections.singleton(errorMsg));
when(toscaTemplateProcessor.process(any(InputStream.class))).thenReturn(processedToscaTemplate);
final ApexApiResult apexApiResult = policyUploadHandler
- .doUpload(mock(ApexModel.class), mock(InputStream.class), mock(InputStream.class));
+ .doUpload(mock(ApexModel.class), mock(InputStream.class), mock(InputStream.class), USER_ID);
assertThat("Response should not be ok", apexApiResult.isNok(), is(true));
assertThat("Response message should be as expected",
@@ -151,7 +152,7 @@ public class PolicyUploadHandlerTest {
processedApexConfig.addToErrors(Collections.singleton(errorMsg));
when(apexConfigProcessor.process(any(InputStream.class))).thenReturn(processedApexConfig);
final ApexApiResult apexApiResult = policyUploadHandler
- .doUpload(mock(ApexModel.class), mock(InputStream.class), mock(InputStream.class));
+ .doUpload(mock(ApexModel.class), mock(InputStream.class), mock(InputStream.class), USER_ID);
assertThat("Response should not be ok", apexApiResult.isNok(), is(true));
assertThat("Response message should be as expected",
@@ -173,7 +174,7 @@ public class PolicyUploadHandlerTest {
.thenReturn(Response.ok().status(201).build());
final ApexApiResult apexApiResult = policyUploadHandler
- .doUpload(apexModel, mock(InputStream.class), mock(InputStream.class));
+ .doUpload(apexModel, mock(InputStream.class), mock(InputStream.class), USER_ID);
assertThat("Response should not be ok", apexApiResult.isNok(), is(true));
final String expectedErrorMsg = String
@@ -197,4 +198,4 @@ public class PolicyUploadHandlerTest {
when(apexModel.getPolicyModel()).thenReturn(axPolicyModel);
return apexModel;
}
-} \ No newline at end of file
+}