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
@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);
}
/**
@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);
}
return processRestCommand(RestCommandType.TASK, RestCommand.VALIDATE, name, version);
}
- // CHECKSTYLE:OFF: MethodLength
/**
* Creates a policy with the information in the JSON string passed.
*
*/
@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);
*/
@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);
*/
@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);
* @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);
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);
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);
<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>
--- /dev/null
+/*
+ * ============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');
+})();
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");
});
}
});
});
+
</script>
</head>
<body>
<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>
public class PolicyUploadHandlerTest {
+ private static final String USER_ID = "cs0008";
@Mock
private PolicyToscaConverter policyToscaConverter;
@Mock
.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 =
.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 =
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",
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",
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",
.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
when(apexModel.getPolicyModel()).thenReturn(axPolicyModel);
return apexModel;
}
-}
\ No newline at end of file
+}