From 9a9127b65920580de8b4a69479a9983481c8faf8 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Fri, 11 Sep 2020 14:28:32 +0100 Subject: Add TOSCA support to Apex editor The APEX editor now loads, saves, and downloads files in TOSCA format, the same as the apex-pdp does. The non-standard TOSCA handling for file upload has been refactored to be aligned with the Policy Frameowkr TOSCA support. Issue-ID: POLICY-2621 Change-Id: I1ec7475cbcc6ffc23de92687c9f284ac7dfbdd80 Signed-off-by: liamfallon --- .../src/main/resources/webapp/js/ApexConfig.js | 62 ---------------------- .../webapp/js/ApexContextSchemaEditForm.js | 5 -- .../src/main/resources/webapp/js/ApexFiles.js | 17 ++++-- .../src/main/resources/webapp/js/ApexMain.js | 2 +- .../src/main/resources/webapp/js/ApexUpload.js | 61 --------------------- .../src/main/resources/webapp/js/ApexUser.js | 32 ----------- .../webapp/js/__test__/ApexConfig.test.js | 43 --------------- .../resources/webapp/js/__test__/ApexUser.test.js | 31 ----------- .../webapp/js/lib/pubsub/ba-tiny-pubsub.min.js | 4 -- 9 files changed, 14 insertions(+), 243 deletions(-) delete mode 100644 gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexConfig.js delete mode 100644 gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexUpload.js delete mode 100644 gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexUser.js delete mode 100644 gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexConfig.test.js delete mode 100644 gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexUser.test.js delete mode 100644 gui-editors/gui-editor-apex/src/main/resources/webapp/js/lib/pubsub/ba-tiny-pubsub.min.js (limited to 'gui-editors/gui-editor-apex/src/main/resources/webapp/js') diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexConfig.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexConfig.js deleted file mode 100644 index 9a842c2..0000000 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexConfig.js +++ /dev/null @@ -1,62 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * 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 configObj = { - configMap: {}, - getConfig: function (configKey) { - return this.configMap[configKey]; - }, - setConfig: function (configKey, configValue) { - return this.configMap[configKey] = configValue; - }, - readySignal: function () { - $.publish("/config/ready"); - } -} - -$(document).ready(function () { - load(); -}); - -const load = function(){ - $("#menuFileUpload").hide(); - - const rootUrl = location.protocol - + "//" - + window.location.hostname - + (location.port ? ':' + location.port : ''); - - const configUrl = rootUrl + "/apexservices/editor/config"; - - function loadConfiguration() { - ajax_get(configUrl, function (data) { - for (let i = 0; i < data.messages.message.length; i++) { - const configEntry = JSON.parse(data.messages.message[i]); - Object.keys(configEntry).forEach(key => { - configObj.setConfig(key, configEntry[key]); - }); - } - configObj.readySignal(); - }); - } - loadConfiguration(); -} - -module.exports = { configObj, load }; -module.exports.rootUrl = load.rootUrl; diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexContextSchemaEditForm.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexContextSchemaEditForm.js index dac2e50..7eecb72 100644 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexContextSchemaEditForm.js +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexContextSchemaEditForm.js @@ -19,11 +19,6 @@ * ============LICENSE_END========================================================= */ -const {ajax_put} = require("../../../../../target/classes/webapp/js/ApexAjax"); -const {ajax_post} = require("../../../../../target/classes/webapp/js/ApexAjax"); -const {ajax_delete} = require("../../../../../target/classes/webapp/js/ApexAjax"); -const {ajax_getWithKeyInfo} = require("../../../../../target/classes/webapp/js/ApexAjax"); - function editContextSchemaForm_createContextSchema(formParent) { return editContextSchemaForm_activate(formParent, "CREATE", null); } diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexFiles.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexFiles.js index 9171fd3..a8726e7 100644 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexFiles.js +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexFiles.js @@ -19,9 +19,6 @@ * ============LICENSE_END========================================================= */ -const {ajax_get} = require("../../../../../target/classes/webapp/js/ApexAjax"); -const {ajax_put} = require("../../../../../target/classes/webapp/js/ApexAjax"); - function files_fileOpen() { $('').on('change', function() { var reader = new FileReader(); @@ -53,4 +50,16 @@ function files_fileDownload() { document.body.removeChild(downloadLink); } -module.exports = {files_fileDownload, files_fileOpen}; +function files_fileUpload() { + var requestURL = restRootURL + "/Model/Upload"; + + ajax_getOKOrFail(requestURL, function(data) { + var uploadResultString = ""; + for (var i = 0; i < data.messages.message.length; i++) { + uploadResultString += (data.messages.message[i] + "\n"); + } + resultForm_activate(document.getElementById("mainArea"), "Model Upload Result", uploadResultString); + }); +} + +module.exports = {files_fileUpload, files_fileDownload, files_fileOpen}; diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexMain.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexMain.js index 46d8398..9dea9b5 100644 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexMain.js +++ b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexMain.js @@ -44,7 +44,7 @@ $("#menu li").not(".emptyMessage").click(function() { files_fileDownload(); break; case "menuFileUpload": - uploadPlugin.openDialog(); + files_fileUpload(); break; case "menuFileClear": diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexUpload.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexUpload.js deleted file mode 100644 index a71853c..0000000 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexUpload.js +++ /dev/null @@ -1,61 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * 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========================================================= - */ - -$(document).ready(function () { - $.subscribe("/config/ready", enableUpload); - - function enableUpload() { - const menuFileUpload = $('#menuFileUpload'); - const isUploadEnabled = configObj.getConfig("plugin.policy.upload.enable"); - if (isUploadEnabled === "true" || isUploadEnabled === true) { - menuFileUpload.show(); - } else { - menuFileUpload.hide(); - } - } - -}); - -const uploadPlugin = { - dialogDiv: $('#main-dialog'), - openDialog: function () { - this.dialogDiv.load('../upload/dialog.html'); - }, - - upload: function (data, successCallback, errorCallback) { - const requestURL = restRootURL + "/Model/Upload"; - $.ajax({ - type: 'POST', - url: requestURL, - data: data, - contentType: false, - processData: false - }).done(function (data) { - pageControl_successStatus(data); - if (typeof successCallback === typeof Function) { - successCallback(data); - } - }).fail(function (jqXHR, textStatus, errorThrown) { - pageControl_restError(requestURL, jqXHR, textStatus, errorThrown); - if (typeof errorCallback === typeof Function) { - errorCallback(jqXHR, textStatus, errorThrown); - } - }); - } -} 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 deleted file mode 100644 index e30f5dd..0000000 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/ApexUser.js +++ /dev/null @@ -1,32 +0,0 @@ -/* - * ============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'); -})(); - -exports = {userManager}; \ No newline at end of file diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexConfig.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexConfig.test.js deleted file mode 100644 index 02d8406..0000000 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexConfig.test.js +++ /dev/null @@ -1,43 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * 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 apexConfig = require('../ApexConfig'); - -test('configObj called successfully', () => { - expect(apexConfig.configObj.getConfig()).not.toBeNull(); - expect(apexConfig.configObj.setConfig()).not.toBeNull(); - expect(apexConfig.configObj).toHaveProperty('configMap'); -}); - -test('load called successfully', () => { - expect(apexConfig.rootUrl).not.toBe(null); - const mock = jest.fn(apexConfig.load).mockImplementation(() => { - function test (data) { - for (let i = 0; i < data.messages.message.length; i++) { - const configEntry = JSON.parse(data.messages.message[i]); - Object.keys(configEntry).forEach(key => { - configObj.setConfig(key, configEntry[key]); - }); - } - configObj.readySignal(); - }; - }); - mock(); - expect(mock).toHaveBeenCalledTimes(1); -}); \ No newline at end of file diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexUser.test.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexUser.test.js deleted file mode 100644 index 1d445c4..0000000 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/__test__/ApexUser.test.js +++ /dev/null @@ -1,31 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * 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 user = require('../ApexUser'); - -test('userManager test', () => { - const userMock = { - userId: u => { - return `userId: ${u}`; - }, - } - const spy = jest.spyOn(userMock, 'userId'); - expect(userMock.userId('userTest')).toBe('userId: userTest'); - expect(spy).toHaveBeenCalledWith('userTest'); -}); \ No newline at end of file diff --git a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/lib/pubsub/ba-tiny-pubsub.min.js b/gui-editors/gui-editor-apex/src/main/resources/webapp/js/lib/pubsub/ba-tiny-pubsub.min.js deleted file mode 100644 index 635ab34..0000000 --- a/gui-editors/gui-editor-apex/src/main/resources/webapp/js/lib/pubsub/ba-tiny-pubsub.min.js +++ /dev/null @@ -1,4 +0,0 @@ -/*! Tiny Pub/Sub - v0.7.0 - 2013-01-29 -* https://github.com/cowboy/jquery-tiny-pubsub -* Copyright (c) 2013 "Cowboy" Ben Alman; Licensed MIT */ -(function(n){var u=n({});n.subscribe=function(){u.on.apply(u,arguments)},n.unsubscribe=function(){u.off.apply(u,arguments)},n.publish=function(){u.trigger.apply(u,arguments)}})(jQuery); \ No newline at end of file -- cgit 1.2.3-korg