From 18957b0110bf717422fac4af4713031da5cc95d2 Mon Sep 17 00:00:00 2001 From: charitha Date: Wed, 11 May 2016 19:30:55 +0530 Subject: [PATCH 01/24] Add required jagerry modules for the app --- .../carbon/device/mgt/jaxrs/api/Group.java | 6 +- .../src/assembly/src.xml | 9 +- .../jaggery-modules/utils/module.xml | 38 +++ .../utils/scripts/exception/exception.js | 62 +++++ .../utils/scripts/file/file.js | 167 +++++++++++++ .../utils/scripts/patterns/patterns.js | 128 ++++++++++ .../utils/scripts/reflection/reflection.js | 230 ++++++++++++++++++ .../utils/scripts/request/request.js | 57 +++++ .../utils/scripts/response/response.js | 96 ++++++++ .../utils/scripts/time/time.js | 35 +++ .../jaggery-modules/utils/scripts/url/url.js | 47 ++++ .../jaggery-modules/utils/scripts/xml/xml.js | 138 +++++++++++ .../pom.xml | 2 +- .../src/main/resources/p2.inf | 3 +- 14 files changed, 1010 insertions(+), 8 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/module.xml create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/exception/exception.js create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/file/file.js create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/patterns/patterns.js create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/reflection/reflection.js create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/request/request.js create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/response/response.js create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/time/time.js create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/url/url.js create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/xml/xml.js diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Group.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Group.java index ab350b6b076..36e1723ba8d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Group.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Group.java @@ -43,7 +43,6 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; -import java.util.Arrays; import java.util.Date; import java.util.List; @@ -114,7 +113,7 @@ public class Group { @GET @Produces("application/json") - public Response getGroups(@QueryParam("start") int startIndex, @PathParam("length") int length) { + public Response getGroups(@QueryParam("start") int startIndex, @QueryParam("length") int length) { try { PaginationResult paginationResult = DeviceMgtAPIUtils.getGroupManagementProviderService() .getGroups(startIndex, length); @@ -318,8 +317,7 @@ public class Group { @Produces("application/json") public Response addSharing(@QueryParam("shareUser") String shareUser, @PathParam("groupName") String groupName, @PathParam("owner") String owner, - @PathParam("roleName") String roleName, - @FormParam("permissions") String[] permissions) { + @PathParam("roleName") String roleName, String[] permissions) { try { boolean isAdded = DeviceMgtAPIUtils.getGroupManagementProviderService().addGroupSharingRole( diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/assembly/src.xml b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/assembly/src.xml index 36997aa7180..c9805f89463 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/assembly/src.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/assembly/src.xml @@ -29,12 +29,17 @@ ${basedir}/src/main/resources/jaggeryapps/devicemgt - / + /jaggeryapps/devicemgt-cdmf/ true ${basedir}/src/main/resources/jaggeryapps/uuf-template-app - / + /jaggeryapps/devicemgt-cdmf/ + true + + + ${basedir}/src/main/resources/jaggery-modules + /jaggery-modules/ true diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/module.xml b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/module.xml new file mode 100644 index 00000000000..485112332c2 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/module.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/exception/exception.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/exception/exception.js new file mode 100644 index 00000000000..a80361dec0f --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/exception/exception.js @@ -0,0 +1,62 @@ +/* + * Copyright (c) WSO2 Inc. (http://wso2.com) 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. + * 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. + */ + +/** + * Description: The response of the currently invoked api enpoint is organized + */ + +var exception = {}; +var log = new Log('exception_module'); + +(function(exception) { + /** + * + * @param message The exception description + * @param code HTTP STATUS CODE related to the exception + * @return The error object + */ + exception.buildExceptionObject = function(message, code) { + var error = {}; + error.message = message; + error.code = code; + return error; + }; + + exception.handleError = function (exception, type, code){ + var constants = require('rxt').constants; + + if (type == constants.THROW_EXCEPTION_TO_CLIENT) { + log.debug(exception); + var e = exceptionModule.buildExceptionObject(exception, code); + throw e; + } else if (type == constants.LOG_AND_THROW_EXCEPTION) { + log.error(exception); + throw exception; + } else if (type == constants.LOG_EXCEPTION_AND_TERMINATE) { + log.error(exception); + var msg = 'An error occurred while serving the request!'; + var e = exceptionModule.buildExceptionObject(msg, constants.STATUS_CODES.INTERNAL_SERVER_ERROR); + throw e; + } else if (type == constants.LOG_EXCEPTION_AND_CONTINUE) { + log.debug(exception); + } + else { + log.error(exception); + throw e; + } + }; +}(exception)) + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/file/file.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/file/file.js new file mode 100644 index 00000000000..f3aa6578f52 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/file/file.js @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2005-2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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. + * + */ +var file = {}; +(function() { + var log = new Log('utils-file'); + var CONTENT_MAP = { + 'js': 'application/javascript', + 'css': 'text/css', + 'csv': 'text/csv', + 'html': 'text/html', + 'json': 'application/json', + 'png': 'image/png', + 'jpeg': 'image/jpeg', + 'gif': 'image/gif', + 'svg': 'image/svg+xml', + 'ttf': 'application/x-font-ttf', + 'eot': 'application/vnd.ms-fontobject', + 'woff': 'application/font-woff', + 'otf': 'application/x-font-otf', + 'zip': 'application/zip', + 'xml': 'text/xml', + 'xhtml': 'application/xhtml+xml', + 'pdf': 'application/pdf' + }; + /** + * The function checks whether a directory contains a particular file + * @param dir The directory in which the file must be checked + * @param file A File object if the file exists,else null + */ + file.getFileInDir = function(dir, fileName) { + var isFilePresent = false; + var files = dir.listFiles(); + for (var index in files) { + if (files[index].getName() == fileName) { + return files[index]; + } + } + return null; + }; + /** + * The function returns the file extension of a filename + * @param file + * @return: The extension of the file + */ + file.getExtension = function(file) { + var baseFileName = file.getName(); + //Break up the name by . + var baseNameComponents = baseFileName.split('.'); + var extension = baseNameComponents[baseNameComponents.length - 1]; + return extension; + }; + /** + * The function obtains the MIME type based on the extension + * @param The extension + * @return The mime type + */ + file.getMimeType = function(extension) { + return CONTENT_MAP[extension]; + }; + /** + * The function returns the name of the file without the file extension + * @param file A file object + * @return: The name of the file without the extension + */ + file.getFileName = function(file) { + //Get the name of the file + var baseFileName = file.getName(); + //Break up the name by . + var baseNameComponents = baseFileName.split('.'); + //Get all of the components except the last one + baseNameComponents.splice(baseNameComponents.length - 1, 1); + return baseNameComponents.join('.'); + }; + /** + * The function returns the contents of a directory as a JSON object.The name of the + * file is used as the property names without the extensions. + * NOTE: The method will not traverse sub folders. + * @param The directory to be inspected + * @return A JSON object which contains the files in the directory + */ + file.getDirectoryContents = function(dir) { + var dirContents = {}; + //Check if it is a directory + if (!dir.isDirectory()) { + log.info('Not a directory'); + return dirContents; + } + //Obtain a list of all files + var files = this.getAllFiles(dir); + var name; + log.info('Files: ' + files); + //Create the directory object with each file been a property + for (var index in files) { + dirContents[this.getFileName(files[index])] = files[index]; + } + return dirContents; + }; + /** + * The function obtains a list of files that are not directories + * @param dir The directory to be inspected + * @return An array with all of the files in the directory + */ + file.getAllFiles = function(dir) { + var filesInDir = []; + if (!dir.isDirectory()) { + return filesInDir; + } + //Obtain a list of all files + var files = dir.listFiles(); + for (var index in files) { + log.info('Checking file: ' + files[index].getName()); + //Check if the file is a directory + if (!files[index].isDirectory()) { + filesInDir.push(files[index]); + } + } + return filesInDir; + }; + /** + * The function returns a list of all file names in a directory + * @param dir The directory to be inspected + * @return {An array containing the name of all files in a directory + */ + file.getAllFileNames = function(dir) { + var files = dir.listFiles(); + var list = []; + var fileName; + for (var index in files) { + if (files[index].isDirectory()) { + fileName=this.getFileName(files[index].getName()); + list.push(fileName); + } + } + return list; + }; + /** + * The function returns a list of all sub directories in a given directory + * @param dir The root directory + * @return: An array containing all sub directories + */ + file.getAllSubDirs = function(dir) { + var files = dir.listFiles(); + var subDirs = []; + for (var index in files) { + if (files[index].isDirectory()) { + subDirs.push(files[index]); + } + } + return subDirs; + }; +}()); \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/patterns/patterns.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/patterns/patterns.js new file mode 100644 index 00000000000..f0e55bb2542 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/patterns/patterns.js @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2005-2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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. + * + */ +var patterns = {}; + +(function () { + + var DEF_ERR_ARITY = 3; + var DEF_HANDLE_ARITY = 2; + var log = new Log('utils.patterns.GenericPipe'); + + function GenericPipe(options) { + this.errHandlerArity = DEF_ERR_ARITY || options.errArity; + this.handlerArity = DEF_HANDLE_ARITY || options.handlerArity; + this.plugins = []; + this.finalHandler = function () { + }; + } + + + /** + *The function registers the provided plugin + */ + GenericPipe.prototype.plug = function (plugin, options) { + var options = options || {}; + //Only a function + if (plugin instanceof Function) { + this.plugins.push({ + handle: plugin, + options: options + }); + } + //Is it a plugin object + else if (plugin instanceof Object) { + plugin.options = options; + this.plugins.push(plugin); + } + + return this; + }; + + GenericPipe.prototype.finally = function (plugin) { + this.finalHandler = plugin; + return this; + }; + + GenericPipe.prototype.resolve = function (data, req, res, session) { + var context = {}; + context.req = req; + context.res = res; + context.session = session; + context.data = data; + handle(context, this.plugins, this.errHandlerArity, this.handlerArity, this.finalHandler); + }; + + var handle = function (context, plugins, errArity, handlerArity, finallyHandler) { + var index = 0; + var currentPlugin; + + var recursiveHandle = function (err) { + + currentPlugin = plugins[index]; + + index++; + + //Check if there is a plugin + if (!currentPlugin) { + //log.warn('No plugin found at index: ' + index); + return; + } + + //Populate the options object for the plugin + context.options=currentPlugin.options;; + + //Check if an error has been provided + if (err) { + //Can the current plugin handle the err + if (currentPlugin.handle.length == errArity) { + try { + currentPlugin.handle(err, context,recursiveHandle); + } + catch (e) { + recursiveHandle(e); + } + } + else { + recursiveHandle(err); + } + } + //There is no error so try to invoke the current plugin + else { + if (currentPlugin.handle.length == handlerArity) { + try { + + + currentPlugin.handle(context,recursiveHandle); + } catch (e) { + recursiveHandle(e); + } + } + else { + recursiveHandle(); + } + } + }; + + recursiveHandle(); + finallyHandler(context); + }; + + patterns.GenericPipe = GenericPipe; + +}()); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/reflection/reflection.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/reflection/reflection.js new file mode 100644 index 00000000000..77ff58d49e6 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/reflection/reflection.js @@ -0,0 +1,230 @@ +/* + * Copyright (c) 2005-2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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. + * + */ +var reflection = {}; +/** + * Description: The script encapsulates any reflection related utility functions + */ +(function() { + var log = new Log('utils-reflection'); + reflection.copyPropKeys = function(from, to) { + for (var key in from) { + if (from.hasOwnProperty(key)) { + to[key] = ''; + } + } + return to; + }; + /** + * The function recursively copies all property keys in an object + * @param from + * @param to + */ + reflection.copyAllPropKeys = function(from, to) { + recurse(from, to, function(from, to, key) { + if (from[key] instanceof Object) { + to[key] = from[key]; + } else { + to[key] = null; + } + }); + }; + reflection.copyAllPropValues = function(from, to) { + recurse(from, to, function(from, to, key) { + //Create an instance if the property does not exist + if (!to[key]) { + to[key] = {}; + } + //Copy the values over + if (!(from[key] instanceof Object)) { + to[key] = from[key]; + } else { + log.debug('Not copying values of key: ' + key); + } + }); + }; + /** + * The function will only copy public properties + * @param from + * @param to + */ + reflection.copyPublicPropValues = function(from, to) { + recurse(from, to, function(from, to, key) { + //Ignore any hidden properties + if (key.charAt(0) == '_') { + log.warn('Drop key: ' + key); + return; + } + //Create an instance if the property does not exist + if (!to[key]) { + to[key] = {}; + } + //Copy the values over + if (!(from[key] instanceof Object)) { + to[key] = from[key]; + } else { + log.warn('Not copying values of key: ' + key); + } + }); + }; + reflection.inspect = function(from, to, cb) { + recurse(from, to, cb); + }; + /** + * The function recursively traverses an object and then invokes the provided + * callback + * @param root + * @param clone + * @param cb + */ + var recurse = function(root, clone, cb) { + var key; + //Check if the root is an object + if (!(root instanceof Object)) { + return; + } else { + var keys = Object.keys(root); + //Go through all the other keys in the current root + for (var index in keys) { + key = keys[index]; + cb(root, clone, key); + recurse(root[key], clone[key], cb); + } + } + }; + reflection.copyProps = function(from, to) { + for (var key in from) { + if (from.hasOwnProperty(key)) { + to[key] = from[key]; + } + } + return to; + }; + reflection.getProps = function(obj) { + var props = {}; + for (var key in obj) { + if (!(obj[key] instanceof Function)) { + props[key] = obj[key]; + } + } + return props; + }; + reflection.printProps = function(obj) { + for (var key in obj) { + if (obj.hasOwnProperty(key)) { + log.info('key: ' + key); + } + } + }; + /** + * The function determines if a property is hidden based on _ + * @param key + * @returns {boolean} + */ + reflection.isHiddenProp = function(key) { + if (key == '') { + return false; + } + return (key.charAt(0) == '_') ? true : false; + }; + var getDiff = function(a, b, diff) {}; + /** + * The function calculates the differences between two simple JSON objects + * @param a The object with which b is compared + * @param b The target of the comparison + * @return An object which records the differences between the two objects + */ + reflection.diff = function(a, b) {}; + /** + * The function merges the two provided objects to create a new + * object.In the case where b has the same property as a; the property of b + * will have precedence + * @param {[type]} a [description] + * @param {[type]} b [description] + * @return A new object having the properties of both object a and b + */ + reflection.merge = function(a, b) { + var newObj = {}; + //Copy the properties of a first + for (var key in a) { + newObj[key] = b[key]; + } + //Override with the properties of b + for (var key in b) { + newObj[key] = b[key]; + } + return newObj; + }; + /** + * The function allows a child class to override a select set of methods of + * a parent class.The original methods of the parent can be accessed + * using the this._super keyword + * @param {[type]} parent The parent class instance to be overriden + * @param {[type]} child The child class instance containing methods which will override the parent + */ + reflection.override = function(parent, child) { + //Make a clone of the parent + var super = parse(stringify(parent)); + for (var childKey in child) { + for (var parentKey in parent) { + //Only override those methods that are common + if (childKey === parentKey) { + var parentPtr = parent[parentKey]; + var childPtr = child[childKey]; + //Update the clone with the old parent method + super[parentKey] = parentPtr; + parent[parentKey] = childPtr; + /*parent[parentKey] = function() { + var result=childPtr.apply(this, arguments)||null; + return result; + };*/ + } + } + } + //Allow the child object to call methods of the parent + parent._super = super; + }; + reflection.overrideAll=function(parent,child){ + //Make a clone of the parent + var super = parse(stringify(parent)); + for (var childKey in child) { + for (var parentKey in parent) { + //Only override those methods that are common + if ( (child.hasOwnProperty(childKey))&&(parent.hasOwnProperty(parentKey)) ) { + var parentPtr = parent[parentKey]; + var childPtr = child[childKey]; + //Update the clone with the old parent method + super[parentKey] = parentPtr; + parent[parentKey] = childPtr; + /*parent[parentKey] = function() { + var result=childPtr.apply(this, arguments)||null; + return result; + };*/ + } + } + } + //Allow the child object to call methods of the parent + parent._super = super; + }; + reflection.isArray = function(object) { + if (Object.prototype.toString.call(object) === '[object Array]') { + return true; + } + return false; + }; +}()); \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/request/request.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/request/request.js new file mode 100644 index 00000000000..4218da70fde --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/request/request.js @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2005-2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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. + * + */ +var request = {}; +(function(request) { + var hasOwnProperty = function(obj, element) { + return Object.prototype.hasOwnProperty.call(obj, element); + }; + var isObject = function(object) {; + return typeof object === 'object'; + }; + /* + * ECMA Standard (ECMA-262 : 5.1 Edition)*/ + var decodes = function(encodedURI) { + return decodeURIComponent(encodedURI); + }; + request.getQueryOptions = function(queryString) { + var opt={}; + var sep = opt.sep || '&', + assign = opt.assign || '=', + compoArray = []; + var obj = {}; + var decodedURI = decodes(queryString); + decodedURI.split(sep).forEach(function(comp) { + comp.split(assign).some(function(element, index, array) { + if (hasOwnProperty(obj, element.toString())) { + compoArray.push(obj[element]); + compoArray.push(array[1]); + obj[element] = compoArray; + } else { + Object.defineProperty(obj, element, { + enumerable: true, + writable: true, + value: array[1] + }); + } + return true; + }); + }); + return obj; + }; +}(request)) \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/response/response.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/response/response.js new file mode 100644 index 00000000000..a8dae442470 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/response/response.js @@ -0,0 +1,96 @@ +/* + * Copyright (c) WSO2 Inc. (http://wso2.com) 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. + * 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. + */ + +/** + * Description: The response of the currently invoked api endpoint is organized + */ + +var response = {}; +var log = new Log("response"); + +(function(response) { + + /** + * Build Error response + * @param resp jaggery-response object to retrieve to client + * @param code status code + * @param message message to the client side + * @return return response + */ + response.buildErrorResponse = function(resp,code,message) { + var content={}; + content.error = message; + resp = processResponse(resp,code,content); + return resp; + }; + + /** + * Build success response + * @param resp jaggery response object + * @param code status code + * @param data the result to client + * @return return response + */ + response.buildSuccessResponse= function(resp, code, data){ + var content={}; + content.data = data; + resp = processResponse(resp,code,content); + return resp; + }; + + /** + * process General response + * @param resp jaggery response + * @param code status code + * @param data success result + * @return resp jaggery response + */ + response.buildSuccessResponseForRxt= function(resp, code, data){ + resp.status = code; + resp.content = data; + return resp; + }; + + /** + * General response builder + * @param resp jaggery response + * @param code status code + * @param content what ever the content to be sent as response + * @return resp jaggery response + */ + function processResponse(resp, code, content){ + resp.status = code; + resp.contentType = 'application/json'; + resp.content = content; + return resp; + + }; + + /** + * + * @param resp + * @param code + * @param data + * @return The http response + */ + response.buildSuccessResponseForRxt= function(resp, code, data){ + resp.contentType = 'application/json'; + resp.status = code; + resp.content = data; + return resp; + }; + +}(response)) \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/time/time.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/time/time.js new file mode 100644 index 00000000000..142d4fa73c3 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/time/time.js @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2005-2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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. + * + */ +var time = {}; +(function(time) { + time.getCurrentTime = function(dateLength) { + var dateLength=dateLength||20; + var now = new String(new Date().valueOf()); + var length = now.length; + var prefix = dateLength; + var onsetVal = ''; + if (length != prefix) { + var onset = prefix - length; + for (var i = 0; i < onset; i++) { + onsetVal += '0'; + } + } + return onsetVal + now; + }; +}(time)); \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/url/url.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/url/url.js new file mode 100644 index 00000000000..5f8154607ad --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/url/url.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2005-2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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. + * + */ +var url = {}; +(function() { + var log=new Log('utils-url'); + url.popServerDetails = function(obj) { + var process = require('process'); + var localIP = process.getProperty('server.host'); + var httpPort = process.getProperty('http.port'); + var httpsPort = process.getProperty('https.port'); + var value = ''; + var carbonLocalIP = process.getProperty('carbon.local.ip'); + + for (var key in obj) { + if (obj.hasOwnProperty(key)) { + value = obj[key]; + if ((typeof value === 'string') && value.indexOf('%https.host%') > -1) { + value=value.replace('%https.host%', 'https://' + localIP + ':' + httpsPort); + } else if ((typeof value === 'string') && value.indexOf('%http.host%') > -1) { + value=value.replace('%http.host%', 'http://' + localIP + ':' + httpPort); + } else if ((typeof value === 'string') && value.indexOf('%https.carbon.local.ip%') > -1) { + value=value.replace('%https.carbon.local.ip%', 'https://' + carbonLocalIP + ':' + httpsPort); + } else if ((typeof value === 'string') && value.indexOf('%http.carbon.local.ip%') > -1) { + value=value.replace('%http.carbon.local.ip%', 'http://' + carbonLocalIP + ':' + httpPort); + } + obj[key] = value; + } + } + return obj; + }; +}(url)); \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/xml/xml.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/xml/xml.js new file mode 100644 index 00000000000..7caefe9d070 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggery-modules/utils/scripts/xml/xml.js @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2005-2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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. + * + */ +var xml = {}; + +(function () { + + var log=new Log('util.xml') + + /* + The method is used to create a JSON object using + an xml object. + @xmlElement: An xml element object to be processed + @return: A pseudo object containing the properties of the + xml element. + */ + var createJSONObject = function (xmlElement) { + + var pseudo = {}; + + //Extract all attributes + var attributes = xmlElement.@*; + + //Fill the pseudo object with the attributes of the element + for (var attributeKey in attributes) { + var attribute = attributes[attributeKey]; + pseudo[attribute.localName()] = attribute.toString(); + } + + return pseudo; + }; + + /* + The function converts an E4X Xml object to a JSON object + This function has been adapted from the work of Oleg Podsechin available at + https://gist.github.com/olegp/642667 + It uses a slightly modified version of his algorithm , therefore + all credit should be attributed to Oleg Podsechin. + IMPORTANT: + 1. It does not create a 1..1 mapping due to the differences + between Xml and JSON.It is IMPORTANT that you verify the structure + of the object generated before using it. + 2. The input xml object must not contain the xml header information + This is a known bug 336551 (Mozilla Developer Network) + Source: https://developer.mozilla.org/en/docs/E4X + Please remove the header prior to sending the xml object for processing. + @root: A starting element in an E4X Xml object + @return: A JSON object mirroring the provided Xml object + */ + var recursiveConvertE4XtoJSON = function (root) { + + log.debug('Root: ' + root.localName()); + + //Obtain child nodes + var children = root.*; + + //The number of children + var numChildren = children.length(); + + //No children + if (numChildren == 0) { + + //Extract contents + return createJSONObject(root); + } + else { + + //Create an empty object + var rootObject = createJSONObject(root); + + //Could be multiple children + for (var childElementKey in children) { + + var child = children[childElementKey]; + + log.debug('Examining child: ' + child.localName()); + + //If the child just contains a single value then stop + if (child.localName() == undefined) { + + log.debug('Child is undefined: ' + child.toString()); + + //Change the object to just a key value pair + rootObject[root.localName()] = child.toString(); + return rootObject; + } + + //Make a recursive call to construct the child element + var createdObject = recursiveConvertE4XtoJSON(child); + + log.debug('Converted object: ' + stringify(createdObject)); + + //Check if the root object has the property + if (rootObject.hasOwnProperty(child.localName())) { + + log.debug('key: ' + child.localName() + ' already present.'); + rootObject[child.localName()].push(createdObject); + } + else { + + log.debug('key: ' + child.localName() + ' not present.'); + rootObject[child.localName()] = []; + rootObject[child.localName()].push(createdObject); + + } + } + + log.debug('root: ' + root.localName()); + + return rootObject; + } + }; + + /** + * The function is used to convert an E4X xml to JSON + * @param root + */ + xml.convertE4XtoJSON = function (root) { + return recursiveConvertE4XtoJSON(root); + }; + + +}()); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.ui.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.ui.feature/pom.xml index 883cc9f3c34..d00f2d32134 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.ui.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.ui.feature/pom.xml @@ -57,7 +57,7 @@ zip true - ${project.build.directory}/maven-shared-archive-resources/jaggeryapps/devicemgt-cdmf + ${project.build.directory}/maven-shared-archive-resources **/* diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.ui.feature/src/main/resources/p2.inf b/features/device-mgt/org.wso2.carbon.device.mgt.ui.feature/src/main/resources/p2.inf index d4cb94274fc..47e5f30872c 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.ui.feature/src/main/resources/p2.inf +++ b/features/device-mgt/org.wso2.carbon.device.mgt.ui.feature/src/main/resources/p2.inf @@ -1,3 +1,4 @@ instructions.configure = \ org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt-cdmf);\ -org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.ui_${feature.version}/jaggeryapps/devicemgt-cdmf,target:${installFolder}/../../deployment/server/jaggeryapps/devicemgt-cdmf,overwrite:true);\ \ No newline at end of file +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.ui_${feature.version}/jaggeryapps/devicemgt-cdmf,target:${installFolder}/../../deployment/server/jaggeryapps/devicemgt-cdmf,overwrite:true);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.ui_${feature.version}/jaggery-modules/utils/,target:${installFolder}/../../modules/utils,overwrite:true);\ \ No newline at end of file From 707da02c7e3e822532eca04d4de56b57909fe97d Mon Sep 17 00:00:00 2001 From: Madhawa Date: Thu, 12 May 2016 21:58:23 +0530 Subject: [PATCH 02/24] Adding swagger annotations to beans --- .../pom.xml | 6 +++++ .../mgt/core/dto/CertificateResponse.java | 23 +++++++++++++++++++ .../device/mgt/jaxrs/api/Certificate.java | 3 +-- .../device/mgt/jaxrs/api/Configuration.java | 10 ++++---- .../org.wso2.carbon.device.mgt.core/pom.xml | 6 +++++ .../device/mgt/core/dto/DeviceType.java | 7 ++++++ 6 files changed, 47 insertions(+), 8 deletions(-) diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml index dd66b2ab029..41cd547d10b 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml @@ -166,6 +166,12 @@ org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.common + + + io.swagger + swagger-annotations + provided + diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/dto/CertificateResponse.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/dto/CertificateResponse.java index 5ffb8270f37..9d0504e2dc1 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/dto/CertificateResponse.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/dto/CertificateResponse.java @@ -18,19 +18,42 @@ package org.wso2.carbon.certificate.mgt.core.dto; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + import java.math.BigInteger; +@ApiModel(value = "CertificateResponse", description = "This class carries all information related to certificates") public class CertificateResponse { + @ApiModelProperty(name = "certificate", value = "The certificate in bytes", required = true) byte[] certificate; + + @ApiModelProperty(name = "serialNumber", value = "It is the unique ID that is used to identify a certificate", required = true) String serialNumber; + + @ApiModelProperty(name = "tenantId", value = "The ID of the tenant who adds the certificate", required = true) int tenantId; + + @ApiModelProperty(name = "commonName", value = "In mutual SSL the common name refers to the serial number of the Android device.", required = true) String commonName; + + @ApiModelProperty(name = "notAfter", value = "The expiration date of the certificate that is inherent to the certificate", required = true) long notAfter; + + @ApiModelProperty(name = "notBefore", value = "The date from when the certificate is valid", required = true) long notBefore; + + @ApiModelProperty(name = "certificateserial", value = "The serial number of the certificate", required = true) BigInteger certificateserial; + + @ApiModelProperty(name = "issuer", value = "The identity of the authority that signs the SSL certificate", required = true) String issuer; + + @ApiModelProperty(name = "subject", value = "The identity of the certificate", required = true) String subject; + + @ApiModelProperty(name = "certificateVersion", value = "The version of the certificate", required = true) int certificateVersion; public long getNotAfter() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Certificate.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Certificate.java index 8bfcd31f660..96c865f07f2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Certificate.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Certificate.java @@ -56,8 +56,7 @@ public interface Certificate { produces = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, httpMethod = "POST", value = "Adding an SSL Certificate", - notes = "Add a new SSL certificate to the client end database", - response = MediaType.class) + notes = "Add a new SSL certificate to the client end database") @ApiResponses(value = { @ApiResponse(code = 200, message = "Added successfully"), @ApiResponse(code = 500, message = "Error occurred while saving the certificate") diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Configuration.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Configuration.java index c7bc7759cf2..12e21f451bb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Configuration.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Configuration.java @@ -46,10 +46,9 @@ public interface Configuration { produces = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, httpMethod = "POST", value = "Configuring general platform settings", - notes = "Configure the general platform settings using this REST API", - response = ResponsePayload.class) + notes = "Configure the general platform settings using this REST API") @ApiResponses(value = { - @ApiResponse(code = 200, message = "Tenant configuration saved successfully"), + @ApiResponse(code = 201, message = "Tenant configuration saved successfully"), @ApiResponse(code = 500, message = "Error occurred while saving the tenant configuration") }) Response saveTenantConfiguration(@ApiParam(name = "configuration", value = "The required properties to " @@ -76,10 +75,9 @@ public interface Configuration { produces = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, httpMethod = "PUT", value = "Updating General Platform Configurations", - notes = "Update the notification frequency using this REST API", - response = ResponsePayload.class) + notes = "Update the notification frequency using this REST API") @ApiResponses(value = { - @ApiResponse(code = 200, message = "Tenant configuration updated successfully"), + @ApiResponse(code = 201, message = "Tenant configuration updated successfully"), @ApiResponse(code = 500, message = "Error occurred while updating the tenant configuration") }) Response updateConfiguration(@ApiParam(name = "configuration", value = "The required properties to update" diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml index bb73550ff63..183d211f8e6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml @@ -245,6 +245,12 @@ 1.7.1 + + io.swagger + swagger-annotations + provided + + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceType.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceType.java index 52ca3ac8915..eb363fff1ca 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceType.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/DeviceType.java @@ -18,12 +18,19 @@ package org.wso2.carbon.device.mgt.core.dto; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + import java.io.Serializable; +@ApiModel(value = "DeviceType", description = "This class carries all information related device types") public class DeviceType implements Serializable { private static final long serialVersionUID = 7927802716452548282L; + + @ApiModelProperty(name = "id", value = "Device type id", required = true) private int id; + @ApiModelProperty(name = "name", value = "Device type name", required = true) private String name; public DeviceType() { From ec7727e8bf46962e68caac63d631d43e4de33fe4 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Thu, 12 May 2016 22:01:48 +0530 Subject: [PATCH 03/24] removed method and type from features --- .../carbon/device/mgt/common/Feature.java | 20 ---------- .../feature/mgt/annotations/Feature.java | 1 - .../feature/mgt/util/AnnotationUtil.java | 39 +++++++++---------- 3 files changed, 19 insertions(+), 41 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Feature.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Feature.java index 375b8d45628..eb48ea1ee56 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Feature.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Feature.java @@ -28,8 +28,6 @@ public class Feature implements Serializable { private String name; private String description; private String deviceType; - private String method; - private String type; private List metadataEntries; @XmlElement @@ -85,24 +83,6 @@ public class Feature implements Serializable { this.description = description; } - @XmlElement - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - @XmlElement - public String getMethod() { - return method; - } - - public void setMethod(String method) { - this.method = method; - } - public static class MetadataEntry implements Serializable { private int id; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/feature/mgt/annotations/Feature.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/feature/mgt/annotations/Feature.java index da0040f9820..02c9ba96e15 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/feature/mgt/annotations/Feature.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/feature/mgt/annotations/Feature.java @@ -32,5 +32,4 @@ public @interface Feature { String description(); - String type(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/feature/mgt/util/AnnotationUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/feature/mgt/util/AnnotationUtil.java index dbca91f10e7..42e7d9d87d8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/feature/mgt/util/AnnotationUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/feature/mgt/util/AnnotationUtil.java @@ -147,7 +147,8 @@ public class AnnotationUtil { Map apiParams = new HashMap<>(); for (int i = 0; i < annotations.length; i++) { Annotation currentAnnotation = annotations[i]; - feature = processHttpMethodAnnotation(feature, currentAnnotation); + String method = processHttpMethodAnnotation(feature, currentAnnotation); + apiParams.put("method", method); if (currentAnnotation.annotationType().getName().equals(Path.class.getName())) { String uri = getPathAnnotationValue(currentMethod); apiParams.put("uri", uri); @@ -203,20 +204,21 @@ public class AnnotationUtil { * @param currentAnnotation * @return */ - private Feature processHttpMethodAnnotation(Feature feature, Annotation currentAnnotation) { + private String processHttpMethodAnnotation(Feature feature, Annotation currentAnnotation) { //Extracting method with which feature is exposed + String method = null; if (currentAnnotation.annotationType().getName().equals(GET.class.getName())) { - feature.setMethod(HttpMethod.GET); + method = HttpMethod.GET; } else if (currentAnnotation.annotationType().getName().equals(POST.class.getName())) { - feature.setMethod(HttpMethod.POST); + method = HttpMethod.POST; } else if (currentAnnotation.annotationType().getName().equals(OPTIONS.class.getName())) { - feature.setMethod(HttpMethod.OPTIONS); + method = HttpMethod.OPTIONS; } else if (currentAnnotation.annotationType().getName().equals(DELETE.class.getName())) { - feature.setMethod(HttpMethod.DELETE); + method = HttpMethod.DELETE; } else if (currentAnnotation.annotationType().getName().equals(PUT.class.getName())) { - feature.setMethod(HttpMethod.PUT); + method = HttpMethod.PUT; } - return feature; + return method; } /** @@ -231,18 +233,15 @@ public class AnnotationUtil { Annotation featureAnno = currentMethod.getAnnotation(featureAnnotationClazz); for (int k = 0; k < featureAnnoMethods.length; k++) { switch (featureAnnoMethods[k].getName()) { - case "name": - feature.setName(invokeMethod(featureAnnoMethods[k], featureAnno, STRING)); - break; - case "code": - feature.setCode(invokeMethod(featureAnnoMethods[k], featureAnno, STRING)); - break; - case "description": - feature.setDescription(invokeMethod(featureAnnoMethods[k], featureAnno, STRING)); - break; - case "type": - feature.setType(invokeMethod(featureAnnoMethods[k], featureAnno, STRING)); - break; + case "name": + feature.setName(invokeMethod(featureAnnoMethods[k], featureAnno, STRING)); + break; + case "code": + feature.setCode(invokeMethod(featureAnnoMethods[k], featureAnno, STRING)); + break; + case "description": + feature.setDescription(invokeMethod(featureAnnoMethods[k], featureAnno, STRING)); + break; } } return feature; From fffc7f3205890e07c4e3a08517d6c791a8105635 Mon Sep 17 00:00:00 2001 From: Madhawa Date: Thu, 12 May 2016 22:12:23 +0530 Subject: [PATCH 04/24] Adding swagger annotations to beans --- .../certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml | 1 + components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml | 1 + 2 files changed, 2 insertions(+) diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml index 41cd547d10b..cf72d3d1a24 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml @@ -83,6 +83,7 @@ javax.xml.bind, org.wso2.carbon.utils.*, org.wso2.carbon.device.mgt.common.*, + io.swagger.annotations.*, org.wso2.carbon.device.mgt.core.*, org.bouncycastle.pkcs.jcajce diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml index 183d211f8e6..3e6c845eb90 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml @@ -83,6 +83,7 @@ org.apache.catalina.core, org.apache.commons.collections, org.wso2.carbon.email.sender.*, + io.swagger.annotations.*, org.wso2.carbon, org.wso2.carbon.base From 85f485df4cc5e0120a66705297bb2015c09110fe Mon Sep 17 00:00:00 2001 From: Madhawa Date: Thu, 12 May 2016 22:19:17 +0530 Subject: [PATCH 05/24] Few changes to interfaces with swagger annotations --- .../device/mgt/jaxrs/api/DeviceNotification.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceNotification.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceNotification.java index f17e5840518..e01110ff77d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceNotification.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceNotification.java @@ -89,10 +89,9 @@ public interface DeviceNotification { httpMethod = "PUT", value = "Updating the Device Notification Status", notes = "When a user has read the the device notification the device notification status must " - + "change from NEW to CHECKED. Update the device notification status using this REST API", - response = ResponsePayload.class) + + "change from NEW to CHECKED. Update the device notification status using this REST API") @ApiResponses(value = { - @ApiResponse(code = 200, message = "Notification status updated successfully"), + @ApiResponse(code = 201, message = "Notification status updated successfully"), @ApiResponse(code = 500, message = "Error occurred while updating notification status") }) Response updateNotificationStatus( @ApiParam(name = "id", value = "Provide the ID of the notification" @@ -107,10 +106,9 @@ public interface DeviceNotification { produces = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, httpMethod = "POST", value = "Sending a Device Notification", - notes = "Notify users on device operation failures and other information using this REST API", - response = ResponsePayload.class) + notes = "Notify users on device operation failures and other information using this REST API") @ApiResponses(value = { - @ApiResponse(code = 200, message = "NNotification has added successfully"), + @ApiResponse(code = 201, message = "NNotification has added successfully"), @ApiResponse(code = 500, message = "Error occurred while updating notification status") }) Response addNotification(Notification notification); From 07c5362104cbd418faa9a201fe6b2c48452c3aa2 Mon Sep 17 00:00:00 2001 From: Madhawa Date: Thu, 12 May 2016 23:11:23 +0530 Subject: [PATCH 06/24] Adding swagger annotations to beans and some modifications to api interfaces --- .../carbon/device/mgt/jaxrs/api/Certificate.java | 2 +- .../wso2/carbon/device/mgt/jaxrs/api/Policy.java | 6 ++++-- .../wso2/carbon/device/mgt/jaxrs/api/User.java | 16 +++++++--------- .../device/mgt/common/PaginationResult.java | 12 ++++++++++++ 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Certificate.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Certificate.java index 96c865f07f2..962603e2629 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Certificate.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Certificate.java @@ -36,7 +36,7 @@ import javax.ws.rs.core.Response; /** * All the certificate related tasks such as saving certificates, can be done through this endpoint. */ -@Api(value = "Certificate", description = "certificate related tasks such as saving certificates") +@Api(value = "Certificate", description = "Certificate related tasks such as saving certificates") @SuppressWarnings("NonJaxWsWebServices") @Produces({ "application/json", "application/xml" }) @Consumes({ "application/json", "application/xml" }) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Policy.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Policy.java index e266e8ee944..59ecc88a839 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Policy.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Policy.java @@ -97,7 +97,8 @@ public interface Policy { produces = MediaType.APPLICATION_JSON, httpMethod = "GET", value = "Getting Details of a Policy.", - notes = "Retrieve the details of a selected policy in WSO2 EMM.") + notes = "Retrieve the details of a selected policy in WSO2 EMM.", + response = org.wso2.carbon.policy.mgt.common.Policy.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Fetched policy details."), @ApiResponse(code = 500, message = "Policy Management related error occurred when " + "fetching the policies.") }) @@ -254,7 +255,8 @@ public interface Policy { value = "Getting Policy Enforced Details of a Device.", notes = "When a device registers with WSO2 EMM a policy is enforced on the device. Initially the EMM " + "filters the policies based on the Platform (device type), filters based on the device ownership" + - " type , filters based on the user role or name and finally the policy is enforced on the device.") + " type , filters based on the user role or name and finally the policy is enforced on the device.", + response = org.wso2.carbon.policy.mgt.common.Policy.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Fetched current policy."), @ApiResponse(code = 500, message = "Error occurred while getting the current policy.") }) Response getDeviceActivePolicy(@ApiParam(name = "type", value = "Define the device type as the value for {type}." + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/User.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/User.java index 6c5e45b7b92..d531fa25bee 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/User.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/User.java @@ -112,8 +112,7 @@ public interface User { value = "Deleting a User", notes = "In a situation where an employee leaves the organization you will need to remove the" + " user details from WSO2 EMM. In such situations you can use this REST API " - + "to remove a user", - response = ResponsePayload.class) + + "to remove a user") @ApiResponses(value = { @ApiResponse(code = 200, message = "User by username: 'username' was successfully removed"), @ApiResponse(code = 400, message = "User by username: 'username' does not exist for removal"), @@ -150,7 +149,8 @@ public interface User { value = "Getting Details of Users", notes = "If you wish to get the details of all the user registered with WSO2 EMM, you can do so " + "using the REST API", - response = ResponsePayload.class) + response = UserWrapper.class, + responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 201, message = "All users were successfully retrieved"), @ApiResponse(code = 500, message = "Error occurred while retrieving the list of users") @@ -275,10 +275,9 @@ public interface User { produces = MediaType.APPLICATION_JSON, httpMethod = "POST", value = "Changing the User Password", - notes = "A user is able to change the password to secure their EMM profile via this REST API", - response = UserCredentialWrapper.class) + notes = "A user is able to change the password to secure their EMM profile via this REST API") @ApiResponses(value = { - @ApiResponse(code = 200, message = "UserImpl password by username: 'Username' was " + @ApiResponse(code = 201, message = "UserImpl password by username: 'Username' was " + "successfully changed"), @ApiResponse(code = 400, message = "Old password does not match"), @ApiResponse(code = 400, message = "Could not change the password of the user: 'Username'. The" @@ -301,10 +300,9 @@ public interface User { notes = "In a situation where you need to block a user from accessing their EMM profile, " + "the EMM administrator is able to reset the password. This will change the user's " + "password and the user will not be able to able to login to the account as he/she is " - + "not aware of the new password.", - response = UserCredentialWrapper.class) + + "not aware of the new password.") @ApiResponses(value = { - @ApiResponse(code = 200, message = "UserImpl password by username: 'Username' was " + @ApiResponse(code = 201, message = "UserImpl password by username: 'Username' was " + "successfully changed"), @ApiResponse(code = 400, message = "Old password does not match"), @ApiResponse(code = 400, message = "Could not change the password of the user: 'Username'. The" diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/PaginationResult.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/PaginationResult.java index 0125b0fd90b..433553b2dae 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/PaginationResult.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/PaginationResult.java @@ -18,18 +18,30 @@ package org.wso2.carbon.device.mgt.common; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + import java.io.Serializable; import java.util.List; /** * This class holds necessary data to represent a paginated result. */ +@ApiModel(value = "PaginationResult", description = "This class carries all information related Pagination Result") public class PaginationResult implements Serializable { private static final long serialVersionUID = 1998101711L; + + @ApiModelProperty(name = "recordsTotal", value = "The total number of records that are given before filtering", required = true) private int recordsTotal; + + @ApiModelProperty(name = "recordsFiltered", value = "The total number of records that are given after filtering", required = true) private int recordsFiltered; + + @ApiModelProperty(name = "draw", value = "The draw counter that this object is a response to, from the draw parameter sent as part of the data request", required = true) private int draw; + + @ApiModelProperty(name = "data", value = "The details of the SSL certificate", required = true) private List data; public int getRecordsTotal() { From 797c7a02d0419ee0453061e2007ae1f606cd1735 Mon Sep 17 00:00:00 2001 From: inosh-perera Date: Fri, 13 May 2016 00:24:59 +0530 Subject: [PATCH 07/24] adding swagger annotation to beans --- .../device/mgt/jaxrs/beans/RoleWrapper.java | 16 +++++ .../wso2/carbon/device/mgt/common/Device.java | 19 ++++++ .../device/mgt/common/DeviceIdentifier.java | 8 +++ .../device/mgt/common/EnrolmentInfo.java | 17 +++++ .../carbon/device/mgt/common/Feature.java | 11 ++++ .../mgt/common/device/details/DeviceInfo.java | 32 +++++++++- .../common/device/details/DeviceLocation.java | 18 +++++- .../common/device/details/DeviceWrapper.java | 9 +++ .../mgt/common/operation/mgt/Operation.java | 39 ++++++++++++ .../device/mgt/common/search/Condition.java | 62 +++++++++++++++++++ .../mgt/common/search/SearchContext.java | 7 +++ 11 files changed, 234 insertions(+), 4 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/RoleWrapper.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/RoleWrapper.java index b8d633f3f66..ed8cfda09cd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/RoleWrapper.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/RoleWrapper.java @@ -18,12 +18,28 @@ package org.wso2.carbon.device.mgt.jaxrs.beans; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import org.wso2.carbon.user.mgt.common.UIPermissionNode; +@ApiModel(value = "RoleWrapper", description = "Role details including permission and the users in the roles are " + + "wrapped here.") public class RoleWrapper { + + @ApiModelProperty(name = "roleName", value = "The name of the role.", required = true) private String roleName; + @ApiModelProperty(name = "permissions", value = "Lists out all the permissions associated with roles.", + required = true) private String[] permissions; + @ApiModelProperty(name = "users", value = "The list of users assigned to the selected role.", + required = true) private String[] users; + @ApiModelProperty(name = "permissionList", value = "This contain the following, " + + "\n resourcePath\tThe path related to the API.\n " + + "displayName\tThe name of the permission that is shown " + + "in the UI.\n" + + "nodeList\tLists out the nested permissions.", + required = true) private UIPermissionNode permissionList; public String getRoleName() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java index feb5f987a21..865aff801e0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Device.java @@ -17,19 +17,38 @@ */ package org.wso2.carbon.device.mgt.common; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + import java.io.Serializable; import java.util.List; +@ApiModel(value = "Device", description = "This class carries all information related to a managed device.") public class Device implements Serializable{ private static final long serialVersionUID = 1998101711L; + @ApiModelProperty(name = "id", value = "ID of the device in the WSO2 EMM device information database.", + required = true) private int id; + @ApiModelProperty(name = "name", value = "The device name that can be set on the device by the device user.", + required = true) private String name; + @ApiModelProperty(name = "type", value = "The OS type of the device.", required = true) private String type; + @ApiModelProperty(name = "description", value = "Additional information on the device.", required = true) private String description; + @ApiModelProperty(name = "deviceIdentifier", value = "This is a 64-bit number (as a hex string) that is randomly" + + " generated when the user first sets up the device and should" + + " remain constant for the lifetime of the user's device." + + " The value may change if a factory reset is performed on " + + "the device.", + required = true) private String deviceIdentifier; + @ApiModelProperty(name = "enrolmentInfo", value = "This defines the device registration related information. " + + "It is mandatory to define this information.", required = true) private EnrolmentInfo enrolmentInfo; + @ApiModelProperty(name = "features", value = "List of features.", required = true) private List features; private List properties; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java index 3c5e2405027..a88bcb465a3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceIdentifier.java @@ -17,11 +17,19 @@ */ package org.wso2.carbon.device.mgt.common; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + import java.io.Serializable; + +@ApiModel(value = "DeviceIdentifier", description = "This contains device details that is used to identify a device " + + "uniquely.") public class DeviceIdentifier implements Serializable{ + @ApiModelProperty(name = "id", value = "Identity of the device.", required = true) private String id; + @ApiModelProperty(name = "type", value = "Type of the device.", required = true) private String type; public DeviceIdentifier() {} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/EnrolmentInfo.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/EnrolmentInfo.java index eb37127d2ef..2ba839243c1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/EnrolmentInfo.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/EnrolmentInfo.java @@ -18,8 +18,13 @@ */ package org.wso2.carbon.device.mgt.common; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + import java.io.Serializable; +@ApiModel(value = "EnrolmentInfo", description = "This class carries all information related to a devices enrollment" + + " status.") public class EnrolmentInfo implements Serializable { private static final long serialVersionUID = 1998101712L; @@ -32,12 +37,24 @@ public class EnrolmentInfo implements Serializable { BYOD, COPE } + @ApiModelProperty(name = "id", value = "ID of the device in the WSO2 EMM device information database.", + required = true) private int id; + @ApiModelProperty(name = "device", value = "Enrolled device.", required = true) private Device device; + @ApiModelProperty(name = "dateOfEnrolment", value = "Date of the device enrollment.", required = true ) private Long dateOfEnrolment; + @ApiModelProperty(name = "dateOfLastUpdate", value = "Date of the device's last update.", required = true ) private Long dateOfLastUpdate; + @ApiModelProperty(name = "ownership", value = "Defines the ownership details. The ownership type can be any of the" + + " following values.\n" + + "BYOD - Bring your own device (BYOD).\n" + + "COPE - Corporate owned personally enabled (COPE).", required = true ) private OwnerShip ownership; + @ApiModelProperty(name = "status", value = "Current status of the device, such as whether the device " + + "is active, removed etc.", required = true ) private Status status; + @ApiModelProperty(name = "owner", value = "The device owner's name.", required = true ) private String owner; public EnrolmentInfo() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Feature.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Feature.java index 0519367fa53..e7dabd76ac5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Feature.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/Feature.java @@ -22,15 +22,26 @@ import java.io.Serializable; import java.util.List; import io.swagger.annotations.*; +@ApiModel(value = "Feature", description = "This class carries all information related to a devices enrollment" + + " status.") public class Feature implements Serializable { + @ApiModelProperty(name = "id", value = "Feature Id.", required = true ) private int id; + @ApiModelProperty(name = "code", value = "The code of the feature. For example the code to lock a device" + + " is DEVICE_LOCK.", required = true ) private String code; + @ApiModelProperty(name = "name", value = "A name that describes a feature.", required = true ) private String name; + @ApiModelProperty(name = "description", value = "Provides a description of the features..", required = true ) private String description; + @ApiModelProperty(name = "deviceType", value = "Provide the device type for the respective feature. " + + "Features allow you to perform operations on any device type, " + + "such as android, iOS or windows..", required = true ) private String deviceType; private String method; private String type; + @ApiModelProperty(name = "metadataEntries", value = "Properties related to features.", required = true ) private List metadataEntries; @XmlElement diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceInfo.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceInfo.java index 92af0d4544e..e76daf6611b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceInfo.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceInfo.java @@ -19,6 +19,8 @@ package org.wso2.carbon.device.mgt.common.device.details; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import java.io.Serializable; @@ -26,34 +28,60 @@ import java.util.Date; import java.util.HashMap; import java.util.Map; +@ApiModel(value = "DeviceInfo", description = "This class carries all information related to the device information " + + "provided by a device.") public class DeviceInfo implements Serializable { private static final long serialVersionUID = 1998101733L; + @ApiModelProperty(name = "deviceId", value = "Device Id.", required = true) private int deviceId; + @ApiModelProperty(name = "deviceType", value = "Type of the device.", required = true) private String deviceType; + @ApiModelProperty(name = "deviceId", value = "Device identifier.", required = true) private DeviceIdentifier deviceIdentifier; - + @ApiModelProperty(name = "IMEI", value = "IMEI number of the device.", required = true) private String IMEI; + @ApiModelProperty(name = "IMSI", value = "IMSI number of the device.", required = true) private String IMSI; + @ApiModelProperty(name = "deviceModel", value = "Model of the device.", required = true) private String deviceModel; + @ApiModelProperty(name = "vendor", value = "Vendor of the device.", required = true) private String vendor; + @ApiModelProperty(name = "osVersion", value = "Operating system version.", required = true) private String osVersion; + @ApiModelProperty(name = "batteryLevel", value = "Battery level of the device.", required = true) private Double batteryLevel; + @ApiModelProperty(name = "internalTotalMemory", value = "Total internal memory of the device.", required = true) private Double internalTotalMemory; + @ApiModelProperty(name = "internalAvailableMemory", value = "Total available memory of the device.", + required = true) private Double internalAvailableMemory; + @ApiModelProperty(name = "externalTotalMemory", value = "Total external memory of the device.", required = true) private Double externalTotalMemory; + @ApiModelProperty(name = "externalAvailableMemory", value = "Total external memory avilable of the device.", + required = true) private Double externalAvailableMemory; + @ApiModelProperty(name = "operator", value = "Mobile operator of the device.", required = true) private String operator; + @ApiModelProperty(name = "connectionType", value = "How the device is connected to the network.", required = true) private String connectionType; + @ApiModelProperty(name = "mobileSignalStrength", value = "Current mobile signal strength.", required = true) private Double mobileSignalStrength; + @ApiModelProperty(name = "ssid", value = "ssid of the connected WiFi.", required = true) private String ssid; + @ApiModelProperty(name = "cpuUsage", value = "Current total cpu usage.", required = true) private Double cpuUsage; + @ApiModelProperty(name = "totalRAMMemory", value = "Total Ram memory size.", required = true) private Double totalRAMMemory; + @ApiModelProperty(name = "availableRAMMemory", value = "Available total memory of RAM.", required = true) private Double availableRAMMemory; + @ApiModelProperty(name = "pluggedIn", value = "Whether the device is plugged into power or not.", + required = true) private boolean pluggedIn; + @ApiModelProperty(name = "updatedTime", value = "Device updated time.", required = true) private Date updatedTime; - + @ApiModelProperty(name = "deviceDetailsMap", value = ".", required = true) private Map deviceDetailsMap = new HashMap<>(); public int getDeviceId() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceLocation.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceLocation.java index 1368b92806a..5223b0f047c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceLocation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceLocation.java @@ -19,27 +19,41 @@ package org.wso2.carbon.device.mgt.common.device.details; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import java.io.Serializable; import java.util.Date; +@ApiModel(value = "DeviceLocation", description = "This class carries all information related to the device location " + + "details provided by a device.") public class DeviceLocation implements Serializable { private static final long serialVersionUID = 1998101722L; + @ApiModelProperty(name = "deviceId", value = "Device id", required = true) private int deviceId; + @ApiModelProperty(name = "deviceIdentifier", value = "Device identifier used to identify a device uniquely.", + required = true) private DeviceIdentifier deviceIdentifier; + @ApiModelProperty(name = "latitude", value = "Device GPS latitude.", required = true) private Double latitude; + @ApiModelProperty(name = "longitude", value = "Device GPS longitude.", required = true) private Double longitude; - + @ApiModelProperty(name = "street1", value = "First line of the address.", required = true) private String street1; + @ApiModelProperty(name = "street2", value = "Second part of the address.", required = true) private String street2; - + @ApiModelProperty(name = "city", value = "City of the device location.", required = true) private String city; + @ApiModelProperty(name = "state", value = "State of the device address.", required = true) private String state; + @ApiModelProperty(name = "zip", value = "Zip code of the device address.", required = true) private String zip; + @ApiModelProperty(name = "country", value = "Country of the device address.", required = true) private String country; + @ApiModelProperty(name = "updatedTime", value = "Update time of the device.", required = true) private Date updatedTime; public int getDeviceId() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceWrapper.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceWrapper.java index 0fae8987784..205caf531cc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceWrapper.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceWrapper.java @@ -19,14 +19,23 @@ package org.wso2.carbon.device.mgt.common.device.details; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +@ApiModel(value = "DeviceWrapper", description = "This contains device details including, " + + "location and device meta information.") public class DeviceWrapper { + @ApiModelProperty(name = "device", value = "Device's basic information", required = true) private Device device; + @ApiModelProperty(name = "deviceIdentifier", value = "Device identifier used to identify a device.", + required = true) private DeviceIdentifier deviceIdentifier; + @ApiModelProperty(name = "deviceInfo", value = "Device's runtime information", required = true) private DeviceInfo deviceInfo; + @ApiModelProperty(name = "deviceLocation", value = "Device's current location", required = true) private DeviceLocation deviceLocation; public Device getDevice() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java index 3496bacb8c8..6bdbc9b0c2d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java @@ -18,12 +18,17 @@ package org.wso2.carbon.device.mgt.common.operation.mgt; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import java.io.Serializable; import java.util.Properties; @XmlRootElement +@ApiModel(value = "Operation", description = "This class carries all information related to a operations that can be " + + "applied on a device.") public class Operation implements Serializable { public enum Type { @@ -38,17 +43,51 @@ public class Operation implements Serializable { REPEAT, NO_REPEAT, PAUSE_SEQUENCE, STOP_SEQUENCE } + @ApiModelProperty(name = "code", value = "The code of the operation that you carried out. For example the code of" + + " the operation carried out to device info operation is DEVICE_INFO.", + required = true) private String code; + @ApiModelProperty(name = "properties", value = "Properties of an operation containing meta information.", + required = true) private Properties properties; + @ApiModelProperty(name = "type", value = "The operation type that was carried out on the device. " + + "The operations types can be one of the following: COMMAND, PROFILE", + required = true) private Type type; + @ApiModelProperty(name = "id", value = "The operations carried out on a device is recorded in a database table. " + + "The ID of the operation in the database table is given as the ID " + + "in the output.", + required = true) private int id; + @ApiModelProperty(name = "status", value = "The status of the operation that has been carried out on a device. The" + + " operation status can be any one of the following:\n" + + "IN-PROGRESS - The operation is processing on the EMM server" + + " side and has not yet been delivered to the device.\n" + + "PENDING - The operation is delivered to the device but the response " + + "from the device is pending.\n" + + "COMPLETED - The operation is delivered to the device and the server has " + + "received a response back from the device.\n" + + "ERROR - An error has occurred while carrying out the operation.", + required = true) private Status status; + @ApiModelProperty(name = "control", value = "How the operation should be executed.", required = true) private Control control; + @ApiModelProperty(name = "receivedTimeStamp", value = "The time WSO2 EMM received the response from the device.", + required = true) private String receivedTimeStamp; + @ApiModelProperty(name = "createdTimeStamp", value = "The time when the operation was requested to be carried out.", + required = true) private String createdTimeStamp; + @ApiModelProperty(name = "isEnabled", value = "If the assigned value is true it indicates that a policy is " + + "enforced on the device. If the assigned value is false it indicates" + + " that a policy is not enforced on a device.", required = true) private boolean isEnabled; + @ApiModelProperty(name = "payLoad", value = "Payload of the operation to be sent to the device", required = true) private Object payLoad; + @ApiModelProperty(name = "operationResponse", value = "Response received from the device", required = true) private String operationResponse; + @ApiModelProperty(name = "activityId", value = "The identifier used to identify the operation uniquely.", + required = true) private String activityId; @Override diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/search/Condition.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/search/Condition.java index 5a4b45dd1e3..2cf03c56459 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/search/Condition.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/search/Condition.java @@ -19,12 +19,74 @@ package org.wso2.carbon.device.mgt.common.search; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +@ApiModel(value = "Condition", description = "Contains the advance search parameters.") public class Condition { + @ApiModelProperty(name = "conditions", value = "Provide the operation code. You can assign the following operation " + + "codes:\n" + + "DEVICE_MODEL : The model of the device.\n" + + "VENDOR : The name of the device vendor.\n" + + "OS_VERSION : The version of the device operating system.\n" + + "BATTERY_LEVEL : The current level of the device battery.\n" + + "INTERNAL_TOTAL_MEMORY : The total capacity of the internal memory" + + " available in the device.\n" + + "INTERNAL_AVAILABLE_MEMORY : The internal memory in the device " + + "that is available.\n" + + "EXTERNAL_TOTAL_MEMORY : The total capacity of the external memory " + + "available in the device.\n" + + "EXTERNAL_AVAILABLE_MEMORY : The external memory in the device" + + " that is available.\n" + + "CONNECTION_TYPE : Define if the device is connected to the GPRS " + + "or Wi-Fi settings.\n" + + "SSID : The name of the Wifi network that the device is " + + "connected to.\n" + + "CPU_USAGE : The current CPU usage of the mobile device.\n" + + "TOTAL_RAM_MEMORY : The total capacity of the random access " + + "memory available in the device.\n" + + "AVAILABLE_RAM_MEMORY : The random access memory capacity " + + "in the device that is available.\n" + + "PLUGGED_IN : Define true if the device is plugged in for charging " + + "or define false if the device is not plugged in for charging.", + required = true) private String key; + @ApiModelProperty(name = "value", value = "Define the value for the key you provide.\n" + + "Example: If you provide the key as VERSION, you can provide the " + + "value as 5.1, which indicates the version of the mobile device you" + + " are searching.", + required = true) private String value; + @ApiModelProperty(name = "operator", value = "Define the search condition between the key and the value you " + + "provide. The following values can be used to define the search " + + "condition:\n" + + "= : Searches for devices where the key is equal to the value " + + "provided.\n" + + "=! : Searches for devices where the key is not equal to the " + + "value provided.\n" + + "<= : Searches for devices where the key is greater than or equal" + + " to the value provide.\n" + + ">= : Searches for devices where the key is less than or equal to" + + " the value provided.\n" + + "> : Searches for devices where the key is greater than the value" + + " provided.\n" + + "< : Searches for devices where the key is less than the value " + + "provided.\n" + + "Example: If you wish to get the devises that have the version " + + "as 5.1, you need to use the = operator..", + required = true) public String operator; + @ApiModelProperty(name = "conditions", value = "There can be many search options as shown in the sample JSON " + + "definition. The field that connects the independent search " + + "options, is known as state.\n" + + "The following values can be assigned to state.\n" + + "AND : Defines if you want the search result to match all the " + + "search conditions provided.\n" + + "OR : Defines if you want the search result to match either of" + + " the search conditions provided.", + required = true) private State state; public enum State { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/search/SearchContext.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/search/SearchContext.java index c7c4be65ca4..5207ddc5022 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/search/SearchContext.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/search/SearchContext.java @@ -19,10 +19,17 @@ package org.wso2.carbon.device.mgt.common.search; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + import java.util.List; + +@ApiModel(value = "SearchContext", description = "Search details when carrying out a search contain in this class.") public class SearchContext { + @ApiModelProperty(name = "conditions", value = "Contains the advance search parameters.", + required = true) private List conditions; // private int start; // private int end; From 362cf40d854a2c264d0eec74b64f8c9354fa54c0 Mon Sep 17 00:00:00 2001 From: geethkokila Date: Fri, 13 May 2016 00:25:13 +0530 Subject: [PATCH 08/24] Fixing the operation activity id issues --- .../mgt/common/operation/mgt/Operation.java | 10 ++ .../operation/mgt/OperationResponse.java | 43 +++++ .../mgt/core/dto/operation/mgt/Operation.java | 9 + .../operation/mgt/OperationManagerImpl.java | 55 +++++- .../core/operation/mgt/dao/OperationDAO.java | 7 + .../mgt/dao/impl/GenericOperationDAOImpl.java | 158 ++++++++++++++++-- .../mgt/dao/util/OperationDAOUtil.java | 2 +- .../src/main/resources/dbscripts/cdm/h2.sql | 1 + .../main/resources/dbscripts/cdm/mssql.sql | 1 + .../main/resources/dbscripts/cdm/mysql.sql | 1 + .../main/resources/dbscripts/cdm/oracle.sql | 1 + .../resources/dbscripts/cdm/postgresql.sql | 1 + 12 files changed, 274 insertions(+), 15 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationResponse.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java index 3496bacb8c8..55030a87cef 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java @@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.common.operation.mgt; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import java.io.Serializable; +import java.util.List; import java.util.Properties; @XmlRootElement @@ -50,6 +51,7 @@ public class Operation implements Serializable { private Object payLoad; private String operationResponse; private String activityId; + private List responses; @Override public boolean equals(Object o) { @@ -218,6 +220,14 @@ public class Operation implements Serializable { this.activityId = activityId; } + public List getResponses() { + return responses; + } + + public void setResponses(List responses) { + this.responses = responses; + } + @Override public String toString() { return "Operation{" + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationResponse.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationResponse.java new file mode 100644 index 00000000000..b993f087430 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationResponse.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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. + */ + + +package org.wso2.carbon.device.mgt.common.operation.mgt; + +public class OperationResponse { + + private String response; + private String recievedTimeStamp; + + public String getResponse() { + return response; + } + + public void setResponse(String response) { + this.response = response; + } + + public String getRecievedTimeStamp() { + return recievedTimeStamp; + } + + public void setRecievedTimeStamp(String recievedTimeStamp) { + this.recievedTimeStamp = recievedTimeStamp; + } +} + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/Operation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/Operation.java index 360deb868ae..c61b2d304fc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/Operation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/Operation.java @@ -46,6 +46,7 @@ public class Operation implements Serializable { private boolean isEnabled; private Object payLoad; private Object operationResponse; + private String activityId; public String getCode() { return code; @@ -135,4 +136,12 @@ public class Operation implements Serializable { this.operationResponse = operationResponse; } + public String getActivityId() { + return activityId; + } + + public void setActivityId(String activityId) { + this.activityId = activityId; + } + } \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java index 5ec27f4c7cb..6784b0cb705 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -659,12 +659,57 @@ public class OperationManagerImpl implements OperationManager { @Override public Operation getOperationByActivityId(String activity) throws OperationManagementException { // This parses the operation id from activity id (ex : ACTIVITY_23) and converts to the integer. - int operationId = Integer.parseInt( + Operation operation; + int enrollmentOpMappingId = Integer.parseInt( activity.replace(DeviceManagementConstants.OperationAttributes.ACTIVITY, "")); - if(operationId == 0){ + if(enrollmentOpMappingId == 0){ throw new IllegalArgumentException("Operation ID cannot be null or zero (0)."); } - return this.getOperation(operationId); + try { + OperationManagementDAOFactory.openConnection(); + org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = + operationDAO.getOperationFromEnrollment(enrollmentOpMappingId); + + if (dtoOperation == null) { + throw new OperationManagementException("Operation not found for given activity Id:" + activity); + } + org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status status = dtoOperation.getStatus(); + if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) { + org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation; + commandOperation = + (org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO. + getOperation(dtoOperation.getId()); + dtoOperation.setEnabled(commandOperation.isEnabled()); + } else if (dtoOperation.getType(). + equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG)) { + dtoOperation = configOperationDAO.getOperation(dtoOperation.getId()); + } else if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type. + PROFILE)) { + dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId()); + } else if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type. + POLICY)) { + dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId()); + } + operation = OperationDAOUtil.convertOperation(dtoOperation); + int enrolmentId = operationDAO.getEnrolmentIdFromMappingId(enrollmentOpMappingId); + if (enrolmentId !=0) { + operation.setResponses(operationDAO.getOperationResponses(enrolmentId, operation.getId())); + } + + operation.setStatus(Operation.Status.valueOf(status.toString())); + operation.setActivityId(activity); + + } catch (SQLException e) { + throw new OperationManagementException("Error occurred while opening a connection to the data source", e); + } catch (OperationManagementDAOException e) { + throw new OperationManagementException("Error occurred while retrieving the operation with activity Id '" + + activity, e); + } finally { + OperationManagementDAOFactory.closeConnection(); + } + + // return this.getOperation(operationId); + return operation; } private OperationDAO lookupOperationDAO(Operation operation) { @@ -722,4 +767,8 @@ public class OperationManagerImpl implements OperationManager { return status; } + private void setActivityId(Operation operation, int enrolmentId) { + operation.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + enrolmentId); + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java index 92349538299..c7499d84964 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java @@ -19,6 +19,7 @@ package org.wso2.carbon.device.mgt.core.operation.mgt.dao; import org.wso2.carbon.device.mgt.common.PaginationRequest; +import org.wso2.carbon.device.mgt.common.operation.mgt.OperationResponse; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation; import java.util.List; @@ -33,6 +34,8 @@ public interface OperationDAO { Operation getOperation(int operationId) throws OperationManagementDAOException; + Operation getOperationFromEnrollment(int enrollmentOpMappingId) throws OperationManagementDAOException; + Operation getOperationByDeviceAndId(int enrolmentId, int operationId) throws OperationManagementDAOException; List getOperationsByDeviceAndStatus(int enrolmentId, Operation.Status status) @@ -58,4 +61,8 @@ public interface OperationDAO { void addOperationResponse(int enrolmentId, int operationId, Object operationResponse) throws OperationManagementDAOException; + List getOperationResponses(int enrolmentId, int operationId) throws OperationManagementDAOException; + + int getEnrolmentIdFromMappingId(int enrollmentOpMappingId) throws OperationManagementDAOException; + } \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java index 592be91c71f..45e9f4d2ccf 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java @@ -20,15 +20,15 @@ package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.PaginationRequest; +import org.wso2.carbon.device.mgt.common.operation.mgt.OperationResponse; +import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationDAO; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.ObjectOutputStream; +import java.io.*; import java.sql.*; import java.util.ArrayList; import java.util.Date; @@ -149,7 +149,7 @@ public class GenericOperationDAOImpl implements OperationDAO { try { Connection connection = OperationManagementDAOFactory.getConnection(); stmt = connection.prepareStatement("INSERT INTO DM_DEVICE_OPERATION_RESPONSE(OPERATION_ID,ENROLMENT_ID," + - "OPERATION_RESPONSE) VALUES(?, ?, ?)"); + "OPERATION_RESPONSE, RECEIVED_TIMESTAMP) VALUES(?, ?, ?, ?)"); bao = new ByteArrayOutputStream(); oos = new ObjectOutputStream(bao); oos.writeObject(operationResponse); @@ -157,6 +157,7 @@ public class GenericOperationDAOImpl implements OperationDAO { stmt.setInt(1, operationId); stmt.setInt(2, enrolmentId); stmt.setBytes(3, bao.toByteArray()); + stmt.setTimestamp(4, new Timestamp(new Date().getTime())); stmt.executeUpdate(); } catch (SQLException e) { throw new OperationManagementDAOException("Error occurred while inserting operation response", e); @@ -181,6 +182,92 @@ public class GenericOperationDAOImpl implements OperationDAO { } } + @Override + public List getOperationResponses(int enrolmentId, int operationId) throws + OperationManagementDAOException { + + PreparedStatement stmt = null; + ResultSet rs = null; + List responces = new ArrayList<>(); + try { + Connection conn = OperationManagementDAOFactory.getConnection(); + String sql = "SELECT * FROM DM_DEVICE_OPERATION_RESPONSE WHERE ENROLMENT_ID = ? AND OPERATION_ID = ?"; + stmt = conn.prepareStatement(sql); + stmt.setInt(1, enrolmentId); + stmt.setInt(2, operationId); + rs = stmt.executeQuery(); + + while (rs.next()) { + OperationResponse response = new OperationResponse(); + response.setRecievedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString()); + ByteArrayInputStream bais = null; + ObjectInputStream ois = null; + byte[] contentBytes; + try { + contentBytes = (byte[]) rs.getBytes("OPERATION_RESPONSE"); + bais = new ByteArrayInputStream(contentBytes); + ois = new ObjectInputStream(bais); + response.setResponse(ois.readObject().toString()); + + } finally { + if (bais != null) { + try { + bais.close(); + } catch (IOException e) { + log.warn("Error occurred while closing ByteArrayOutputStream", e); + } + } + if (ois != null) { + try { + ois.close(); + } catch (IOException e) { + log.warn("Error occurred while closing ObjectOutputStream", e); + } + } + } + responces.add(response); + } + + } catch (SQLException e) { + throw new OperationManagementDAOException("SQL Error occurred while retrieving the operation responses for " + + "operation id " + operationId + " and enrolment id " + enrolmentId, e); + } catch (ClassNotFoundException e) { + throw new OperationManagementDAOException("Error occurred while converting the operation responses to string" + + " for operation id " + operationId + " and enrolment id " + enrolmentId, e); + } catch (IOException e) { + throw new OperationManagementDAOException("Error occurred while converting the operation responses to string" + + " for operation id " + operationId + " and enrolment id " + enrolmentId, e); + } finally { + OperationManagementDAOUtil.cleanupResources(stmt, rs); + } + + return responces; + } + + @Override + public int getEnrolmentIdFromMappingId(int enrollmentOpMappingId) throws OperationManagementDAOException { + PreparedStatement stmt = null; + ResultSet rs = null; + try { + Connection conn = OperationManagementDAOFactory.getConnection(); + String sql = "SELECT * FROM DM_ENROLMENT_OP_MAPPING WHERE ID = ?"; + stmt = conn.prepareStatement(sql); + stmt.setInt(1, enrollmentOpMappingId); + rs = stmt.executeQuery(); + + if (rs.next()) { + return rs.getInt("ENROLMENT_ID"); + } + + } catch (SQLException e) { + throw new OperationManagementDAOException("SQL Error occurred while retrieving the enrolment id " + + " for the mapping id '" + enrollmentOpMappingId, e); + } finally { + OperationManagementDAOUtil.cleanupResources(stmt, rs); + } + return -1; + } + @Override public void deleteOperation(int id) throws OperationManagementDAOException { PreparedStatement stmt = null; @@ -231,6 +318,43 @@ public class GenericOperationDAOImpl implements OperationDAO { return operation; } + @Override + public Operation getOperationFromEnrollment(int enrollmentOpMappingId) throws OperationManagementDAOException { + PreparedStatement stmt = null; + ResultSet rs = null; + Operation operation = null; + try { + Connection conn = OperationManagementDAOFactory.getConnection(); + String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, \n" + + " om.STATUS FROM DM_OPERATION o \n" + + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm WHERE dm.ID = ? ) om \n" + + "ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP DESC "; + stmt = conn.prepareStatement(sql); + stmt.setInt(1, enrollmentOpMappingId); + rs = stmt.executeQuery(); + + if (rs.next()) { + operation = new Operation(); + operation.setId(rs.getInt("ID")); + operation.setType(Operation.Type.valueOf(rs.getString("TYPE"))); + operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString()); + if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) { + operation.setReceivedTimeStamp(""); + } else { + operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString()); + } + operation.setCode(rs.getString("OPERATION_CODE")); + operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS"))); + this.setActivityId(operation, enrollmentOpMappingId); + } + } catch (SQLException e) { + throw new OperationManagementDAOException("SQL error occurred while retrieving the operation .", e); + } finally { + OperationManagementDAOUtil.cleanupResources(stmt, rs); + } + return operation; + } + @Override public Operation getOperationByDeviceAndId(int enrolmentId, int operationId) throws OperationManagementDAOException { PreparedStatement stmt = null; @@ -238,7 +362,7 @@ public class GenericOperationDAOImpl implements OperationDAO { Operation operation = null; try { Connection conn = OperationManagementDAOFactory.getConnection(); - String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATION_CODE " + + String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATION_CODE, om.ID AS OM_MAPPING_ID " + " FROM (SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, STATUS," + "OPERATION_CODE FROM DM_OPERATION WHERE id = ?) o INNER JOIN (SELECT * FROM " + "DM_ENROLMENT_OP_MAPPING dm where dm.OPERATION_ID = ? AND dm.ENROLMENT_ID = ?) om " + @@ -260,6 +384,7 @@ public class GenericOperationDAOImpl implements OperationDAO { operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString()); } operation.setCode(rs.getString("OPERATION_CODE")); + this.setActivityId(operation, rs.getInt("OM_MAPPING_ID")); } } catch (SQLException e) { throw new OperationManagementDAOException("SQL error occurred while retrieving the operation " + @@ -279,7 +404,7 @@ public class GenericOperationDAOImpl implements OperationDAO { List operations = new ArrayList(); try { Connection conn = OperationManagementDAOFactory.getConnection(); - String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " + + String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, om.ID AS OM_MAPPING_ID" + "FROM DM_OPERATION o " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + "WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP DESC"; @@ -300,6 +425,7 @@ public class GenericOperationDAOImpl implements OperationDAO { } operation.setCode(rs.getString("OPERATION_CODE")); operation.setStatus(status); + this.setActivityId(operation, rs.getInt("OM_MAPPING_ID")); operations.add(operation); } } catch (SQLException e) { @@ -321,7 +447,7 @@ public class GenericOperationDAOImpl implements OperationDAO { List operations = new ArrayList(); try { Connection conn = OperationManagementDAOFactory.getConnection(); - String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " + + String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, om.ID AS OM_MAPPING_ID " + "FROM DM_OPERATION o " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + "WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY " + @@ -345,6 +471,7 @@ public class GenericOperationDAOImpl implements OperationDAO { } operation.setCode(rs.getString("OPERATION_CODE")); operation.setStatus(status); + this.setActivityId(operation, rs.getInt("OM_MAPPING_ID")); operations.add(operation); } } catch (SQLException e) { @@ -365,7 +492,7 @@ public class GenericOperationDAOImpl implements OperationDAO { try { Connection conn = OperationManagementDAOFactory.getConnection(); String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " + - "OPERATION_CODE, om.STATUS FROM DM_OPERATION o " + + "OPERATION_CODE, om.STATUS, om.ID AS OM_MAPPING_ID FROM DM_OPERATION o " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + "WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP DESC"; stmt = conn.prepareStatement(sql); @@ -384,6 +511,7 @@ public class GenericOperationDAOImpl implements OperationDAO { } operation.setCode(rs.getString("OPERATION_CODE")); operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS"))); + this.setActivityId(operation, rs.getInt("OM_MAPPING_ID")); operations.add(operation); } } catch (SQLException e) { @@ -405,7 +533,7 @@ public class GenericOperationDAOImpl implements OperationDAO { try { Connection conn = OperationManagementDAOFactory.getConnection(); String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " + - "OPERATION_CODE, om.STATUS FROM DM_OPERATION o " + + "OPERATION_CODE, om.STATUS, om.ID AS OM_MAPPING_ID FROM DM_OPERATION o " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + "WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP DESC LIMIT ?,?"; stmt = conn.prepareStatement(sql); @@ -426,6 +554,7 @@ public class GenericOperationDAOImpl implements OperationDAO { } operation.setCode(rs.getString("OPERATION_CODE")); operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS"))); + this.setActivityId(operation, rs.getInt("OM_MAPPING_ID")); operations.add(operation); } } catch (SQLException e) { @@ -468,7 +597,7 @@ public class GenericOperationDAOImpl implements OperationDAO { try { Connection connection = OperationManagementDAOFactory.getConnection(); stmt = connection.prepareStatement("SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " + - "OPERATION_CODE FROM DM_OPERATION o " + + "OPERATION_CODE, om.ID AS OM_MAPPING_ID FROM DM_OPERATION o " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + "WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID " + "ORDER BY o.CREATED_TIMESTAMP ASC LIMIT 1"); @@ -489,6 +618,7 @@ public class GenericOperationDAOImpl implements OperationDAO { } operation.setCode(rs.getString("OPERATION_CODE")); operation.setStatus(Operation.Status.PENDING); + this.setActivityId(operation, rs.getInt("OM_MAPPING_ID")); } return operation; } catch (SQLException e) { @@ -507,7 +637,7 @@ public class GenericOperationDAOImpl implements OperationDAO { List operations = new ArrayList(); try { Connection conn = OperationManagementDAOFactory.getConnection(); - String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE FROM " + + String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, om.ID AS OM_MAPPING_ID FROM " + "(SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " + "FROM DM_OPERATION o WHERE o.TYPE = ?) o " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + @@ -530,6 +660,7 @@ public class GenericOperationDAOImpl implements OperationDAO { operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString()); } operation.setCode(rs.getString("OPERATION_CODE")); + this.setActivityId(operation, rs.getInt("OM_MAPPING_ID")); operations.add(operation); } } catch (SQLException e) { @@ -545,4 +676,9 @@ public class GenericOperationDAOImpl implements OperationDAO { return Operation.Type.valueOf(type); } + private void setActivityId(Operation operation, int enrolmentId) { + operation.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + enrolmentId); + } + + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/util/OperationDAOUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/util/OperationDAOUtil.java index 6625ceab894..03e7e64143a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/util/OperationDAOUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/util/OperationDAOUtil.java @@ -95,7 +95,7 @@ public class OperationDAOUtil { operation.setReceivedTimeStamp(dtoOperation.getReceivedTimeStamp()); operation.setEnabled(dtoOperation.isEnabled()); operation.setProperties(dtoOperation.getProperties()); - operation.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + dtoOperation.getId()); + operation.setActivityId(dtoOperation.getActivityId()); return operation; diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql index 67cdf57a338..a767ae6bfb5 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -123,6 +123,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE ( ENROLMENT_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL, OPERATION_RESPONSE BLOB DEFAULT NULL, + RECEIVED_TIMESTAMP TIMESTAMP NULL, PRIMARY KEY (ID), CONSTRAINT fk_dm_device_operation_response_enrollment FOREIGN KEY (ENROLMENT_ID) REFERENCES DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql index e18fcf915a5..5c7e5e97993 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -123,6 +123,7 @@ CREATE TABLE DM_DEVICE_OPERATION_RESPONSE ( ENROLMENT_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL, OPERATION_RESPONSE VARBINARY(max) DEFAULT NULL, + RECEIVED_TIMESTAMP DATETIME2(0) NULL, PRIMARY KEY (ID), CONSTRAINT fk_dm_device_operation_response_enrollment FOREIGN KEY (ENROLMENT_ID) REFERENCES DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql index 0fd8889cc33..b7f06c57aa7 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -108,6 +108,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE ( ENROLMENT_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL, OPERATION_RESPONSE BLOB DEFAULT NULL, + RECEIVED_TIMESTAMP TIMESTAMP NULL, PRIMARY KEY (ID), CONSTRAINT fk_dm_device_operation_response_enrollment FOREIGN KEY (ENROLMENT_ID) REFERENCES DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql index 7a41ae3a66e..fa18093ba9c 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -229,6 +229,7 @@ CREATE TABLE DM_DEVICE_OPERATION_RESPONSE ( ENROLMENT_ID NUMBER(10) NOT NULL, OPERATION_ID NUMBER(10) NOT NULL, OPERATION_RESPONSE BLOB DEFAULT NULL, + RECEIVED_TIMESTAMP TIMESTAMP(0) NULL, CONSTRAINT PK_DM_DEVICE_OP_RESPONSE PRIMARY KEY (ID), CONSTRAINT FK_DM_DEVICE_OP_RES_DEVICE FOREIGN KEY (ENROLMENT_ID) REFERENCES DM_ENROLMENT (ID), diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql index 9ec4ef37788..de4a8ca0165 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -94,6 +94,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE ( ENROLMENT_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL, OPERATION_RESPONSE BYTEA DEFAULT NULL, + RECEIVED_TIMESTAMP TIMESTAMP NULL, CONSTRAINT fk_dm_device_operation_response_enrollment FOREIGN KEY (ENROLMENT_ID) REFERENCES DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT fk_dm_device_operation_response_operation FOREIGN KEY (OPERATION_ID) REFERENCES From 4e4e660fa1adc27181dd540dca747c71d8688c6d Mon Sep 17 00:00:00 2001 From: geethkokila Date: Fri, 13 May 2016 01:09:56 +0530 Subject: [PATCH 09/24] Adding the swagger documentation to the activity id resource --- .../carbon/device/mgt/jaxrs/api/Operation.java | 16 ++++++++++++++++ .../mgt/jaxrs/api/impl/OperationImpl.java | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Operation.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Operation.java index 131eef9b2da..da1da349d8b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Operation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Operation.java @@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.jaxrs.api; import io.swagger.annotations.*; import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.app.mgt.Application; +import org.wso2.carbon.device.mgt.jaxrs.api.common.MDMAPIException; import org.wso2.carbon.device.mgt.jaxrs.api.context.DeviceOperationContext; import org.wso2.carbon.device.mgt.jaxrs.api.util.ResponsePayload; import org.wso2.carbon.device.mgt.jaxrs.beans.ApplicationWrapper; @@ -155,4 +156,19 @@ public interface Operation { "{tenantDomain}. The default tenant domain " + "of WSO2 EMM is carbon.super.", required = true) @PathParam("tenantDomain") String tenantDomain); + + + @GET + @Path("activity/{id}") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, + produces = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, + httpMethod = "POST", + value = "Retrieving the operation details.", + notes = "This will return the operation details including the responses from the devices") + @ApiResponses(value = { @ApiResponse(code = 200, message = "Activity details provided successfully.."), + @ApiResponse(code = 500, message = "Error occurred while fetching the activity for the supplied id.") }) + Response getActivity(@ApiParam(name = "id", value = "Provide activity id {id} as ACTIVITY_(number)", + required = true) @PathParam("id") String id) + throws MDMAPIException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/OperationImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/OperationImpl.java index bdca4c54915..83066826685 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/OperationImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/OperationImpl.java @@ -224,4 +224,22 @@ public class OperationImpl implements org.wso2.carbon.device.mgt.jaxrs.api.Opera return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } } + + @Override + @GET + @Path("activity/{id}") + public Response getActivity(@PathParam("id") String id) + throws MDMAPIException { + org.wso2.carbon.device.mgt.common.operation.mgt.Operation operation; + DeviceManagementProviderService dmService; + try { + dmService = DeviceMgtAPIUtils.getDeviceManagementService(); + operation = dmService.getOperationByActivityId(id); + } catch (OperationManagementException e) { + String msg = "Error occurred while fetching the activity for the supplied id."; + log.error(msg, e); + throw new MDMAPIException(msg, e); + } + return Response.status(Response.Status.OK).entity(operation).build(); + } } \ No newline at end of file From 087adafeb7c247cd8a1d2c9eb15fbb158645b127 Mon Sep 17 00:00:00 2001 From: Madhawa Perera Date: Fri, 13 May 2016 01:25:29 +0530 Subject: [PATCH 10/24] Adding swagger annotations to beans --- .../device/mgt/jaxrs/beans/PolicyWrapper.java | 31 ++++++++++++++++++ .../beans/PriorityUpdatedPolicyWrapper.java | 8 +++++ .../org.wso2.carbon.policy.mgt.common/pom.xml | 7 ++++ .../wso2/carbon/policy/mgt/common/Policy.java | 32 +++++++++++++++++-- 4 files changed, 76 insertions(+), 2 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/PolicyWrapper.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/PolicyWrapper.java index c05fa535a5a..b8558856fec 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/PolicyWrapper.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/PolicyWrapper.java @@ -18,21 +18,52 @@ package org.wso2.carbon.device.mgt.jaxrs.beans; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import org.wso2.carbon.device.mgt.common.Device; import java.util.List; +@ApiModel(value = "PolicyWrapper", description = "This class carries all information related to Policy " + + "Wrappers") public class PolicyWrapper { + @ApiModelProperty(name = "id", value = "The policy ID", required = true) private int id; + @ApiModelProperty(name = "profile", value = "Contains the details of the profile that is included in the" + + " policy", required = true) private Profile profile; + @ApiModelProperty(name = "policyName", value = "The name of the policy", required = true) private String policyName; + @ApiModelProperty(name = "description", value = "Gives a description on the policy", required = true) private String description; + @ApiModelProperty(name = "compliance", value = "Provides the non-compliance rules. WSO2 EMM provides the" + + " following non-compliance rules:\n" + + "Enforce - Forcefully enforce the policies on the devices\n" + + "Warning - If the device does not adhere to the given policies a warning message will be sent\n" + + "Monitor - If the device does not adhere to the given policies the server is notified of the " + + "violation unknown to the user and the administrator can take the necessary actions with regard" + + " to the reported", required = true) private String compliance; + @ApiModelProperty(name = "roles", value = "The roles to whom the policy is applied on", required = true) private List roles; + @ApiModelProperty(name = "ownershipType", value = "The policy ownership type. It can be any of the " + + "following values:\n" + + "ANY - The policy will be applied on the BYOD and COPE device types\n" + + "BYOD (Bring Your Own Device) - The policy will only be applied on the BYOD device type\n" + + "COPE (Corporate-Owned, Personally-Enabled) - The policy will only be applied on the COPE " + + "device type", required = true) private String ownershipType; + @ApiModelProperty(name = "devices", value = "Lists out the devices the policy is enforced on", + required = true) private List devices; + @ApiModelProperty(name = "users", value = "Lists out the users on whose devices the policy is enforced", + required = true) private List users; + @ApiModelProperty(name = "tenantId", value = "The ID of the tenant that created the policy", + required = true) private int tenantId; + @ApiModelProperty(name = "profileId", value = "The ID of each profile that is in the selected policy", + required = true) private int profileId; public int getId() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/PriorityUpdatedPolicyWrapper.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/PriorityUpdatedPolicyWrapper.java index 20f5248f85a..56a4764d0b6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/PriorityUpdatedPolicyWrapper.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/PriorityUpdatedPolicyWrapper.java @@ -18,9 +18,17 @@ package org.wso2.carbon.device.mgt.jaxrs.beans; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +@ApiModel(value = "PriorityUpdatedPolicyWrapper", description = "This class carries all information related " + + "to Priority Updated Policy Wrapper ") public class PriorityUpdatedPolicyWrapper { + @ApiModelProperty(name = "id", value = "Define the ID of the policy", required = true) private int id; + @ApiModelProperty(name = "priority", value = "Define the priority of the order, where 1 indicates the " + + "highest priority", required = true) private int priority; public int getId() { diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml index cfa51b818be..c8251cb93b9 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml @@ -53,6 +53,8 @@ ${carbon.device.mgt.version} Policy Management Common Bundle + javax.xml.bind.annotation, + io.swagger.annotations.*;resolution:=optional org.wso2.carbon.device.mgt.common.*, org.wso2.carbon.device.mgt.core.dto.*, javax.xml.bind.*, @@ -91,6 +93,11 @@ org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.core + + io.swagger + swagger-annotations + provided + diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Policy.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Policy.java index 25c5f48cc44..4620adb72e1 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Policy.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Policy.java @@ -17,6 +17,8 @@ */ package org.wso2.carbon.policy.mgt.common; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import org.wso2.carbon.device.mgt.common.Device; import javax.xml.bind.annotation.XmlElement; @@ -29,24 +31,50 @@ import java.util.Map; * This class will be the used to create policy object with relevant information for evaluating. */ @XmlRootElement +@ApiModel(value = "Policy", description = "This class carries all information related to Policies") public class Policy implements Comparable, Serializable { private static final long serialVersionUID = 19981017L; + @ApiModelProperty(name = "id", value = "The policy ID", required = true) private int id; // Identifier of the policy. - private int priorityId; // Priority of the policies. This will be used only for simple evaluation. + @ApiModelProperty(name = "priorityId", value = "The priority order of the policy. 1 indicates the highest" + + " priority", required = true) + private int priorityId; // Priority of the policies. This will be used only for simple evaluation. + @ApiModelProperty(name = "profile", value = "Contains the details of the profile that is included in the " + + "policy", required = true) private Profile profile; // Profile + @ApiModelProperty(name = "policyName", value = "The name of the policy", required = true) private String policyName; // Name of the policy. + @ApiModelProperty(name = "generic", value = "If true, this should be applied to all related device", + required = true) private boolean generic; // If true, this should be applied to all related device. + @ApiModelProperty(name = "roles", value = "The roles to whom the policy is applied on", required = true) private List roles; // Roles which this policy should be applied. + @ApiModelProperty(name = "ownershipType", value = "The policy ownership type. It can be any of the " + + "following values:\n" + + "ANY - The policy will be applied on the BYOD and COPE device types\n" + + "BYOD (Bring Your Own Device) - The policy will only be applied on the BYOD device type\n" + + "COPE (Corporate-Owned, Personally-Enabled) - The policy will only be applied on the COPE " + + "device type\n", required = true) private String ownershipType; // Ownership type (COPE, BYOD, CPE) + @ApiModelProperty(name = "devices", value = "Lists out the devices the policy is enforced on", + required = true) private List devices; // Individual devices this policy should be applied + @ApiModelProperty(name = "users", value = "Lists out the users on whose devices the policy is enforced", + required = true) private List users; + @ApiModelProperty(name = "active", value = "If the value is true it indicates that the policy is active. " + + "If the value is false it indicates that the policy is inactive", required = true) private boolean active; + @ApiModelProperty(name = "updated", value = "If you have made changes to the policy but have not applied" + + " these changes to the devices that are registered with EMM, then the value is defined as true." + + " But if you have already applied any changes made to the policy then the value is defined as" + + " false.", required = true) private boolean updated; + @ApiModelProperty(name = "description", value = "Gives a description on the policy", required = true) private String description; - /* Compliance data*/ private String compliance; From 0cf0ec6e77b4ac55706fb395374e34bc20e35e2a Mon Sep 17 00:00:00 2001 From: inosh-perera Date: Fri, 13 May 2016 01:30:17 +0530 Subject: [PATCH 11/24] adding swagger annotations to APIs --- .../device/mgt/jaxrs/api/Certificate.java | 3 ++- .../device/mgt/jaxrs/api/Configuration.java | 4 ++- .../carbon/device/mgt/jaxrs/api/Device.java | 3 ++- .../mgt/jaxrs/api/DeviceInformation.java | 3 ++- .../mgt/jaxrs/api/DeviceNotification.java | 2 +- .../device/mgt/jaxrs/api/DeviceSearch.java | 3 ++- .../carbon/device/mgt/jaxrs/api/Feature.java | 3 ++- .../device/mgt/jaxrs/api/Operation.java | 3 ++- .../carbon/device/mgt/jaxrs/api/Policy.java | 3 ++- .../carbon/device/mgt/jaxrs/api/Role.java | 2 +- .../carbon/device/mgt/jaxrs/api/User.java | 2 +- .../mgt/jaxrs/beans/ApplicationWrapper.java | 9 +++++++ .../jaxrs/beans/EnrollmentCertificate.java | 10 +++++++ .../device/mgt/jaxrs/beans/MobileApp.java | 27 +++++++++++++++++++ .../jaxrs/beans/UserCredentialWrapper.java | 7 +++++ .../device/mgt/jaxrs/beans/UserWrapper.java | 10 +++++++ .../common/notification/mgt/Notification.java | 14 ++++++++++ 17 files changed, 97 insertions(+), 11 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Certificate.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Certificate.java index 962603e2629..af03e226aa7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Certificate.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Certificate.java @@ -36,7 +36,8 @@ import javax.ws.rs.core.Response; /** * All the certificate related tasks such as saving certificates, can be done through this endpoint. */ -@Api(value = "Certificate", description = "Certificate related tasks such as saving certificates") +@Api(value = "Certificate", description = "Certificate related tasks such as saving certificates, " + + "can be done through this API") @SuppressWarnings("NonJaxWsWebServices") @Produces({ "application/json", "application/xml" }) @Consumes({ "application/json", "application/xml" }) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Configuration.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Configuration.java index 12e21f451bb..7c5db4f1898 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Configuration.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Configuration.java @@ -34,7 +34,9 @@ import javax.ws.rs.core.Response; * General Tenant Configuration REST-API implementation. * All end points support JSON, XMl with content negotiation. */ -@Api(value = "Configuration", description = "General Tenant Configuration implementation") +@Api(value = "Configuration", description = "General Tenant Configuration management capabilities are exposed " + + "through " + + "this API") @SuppressWarnings("NonJaxWsWebServices") @Produces({ "application/json", "application/xml" }) @Consumes({ "application/json", "application/xml" }) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Device.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Device.java index 9710e6f426c..0dc381d335e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Device.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Device.java @@ -29,7 +29,8 @@ import javax.ws.rs.core.Response; /** * Device related operations such as get all the available devices, etc. */ -@Api(value = "Devices") + +@Api(value = "Device", description = "Device related operations such as get all the available devices, etc.") @SuppressWarnings("NonJaxWsWebServices") public interface Device { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceInformation.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceInformation.java index d55477eb076..40bd74aa624 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceInformation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceInformation.java @@ -36,7 +36,8 @@ import javax.ws.rs.core.Response; /** * Device information related operations. */ -@Api(value = "DeviceInfo") + +@Api(value = "DeviceInformation", description = "Device information related operations can be found here.") @SuppressWarnings("NonJaxWsWebServices") public interface DeviceInformation { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceNotification.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceNotification.java index e01110ff77d..41f1747b341 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceNotification.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceNotification.java @@ -40,7 +40,7 @@ import javax.ws.rs.core.Response; * DeviceNotification management REST-API implementation. * All end points support JSON, XMl with content negotiation. */ -@Api(value = "DeviceNotification") +@Api(value = "DeviceNotification", description = "Device notification related operations can be found here.") @SuppressWarnings("NonJaxWsWebServices") @Produces({"application/json", "application/xml"}) @Consumes({ "application/json", "application/xml" }) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceSearch.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceSearch.java index ec27086e360..5760813e07b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceSearch.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceSearch.java @@ -34,7 +34,8 @@ import javax.ws.rs.core.Response; /** * Device search related operations such as getting device information. */ -@Api(value = "DeviceSearch") + +@Api(value = "DeviceSearch", description = "Device searching related operations can be found here.") @SuppressWarnings("NonJaxWsWebServices") public interface DeviceSearch { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Feature.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Feature.java index 42f23ae3b9c..5051c153fcd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Feature.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Feature.java @@ -31,7 +31,8 @@ import javax.ws.rs.core.Response; /** * Features */ -@Api(value = "Feature") + +@Api(value = "Feature", description = "Feature management related operations can be found here.") @SuppressWarnings("NonJaxWsWebServices") @Produces({"application/json", "application/xml"}) @Consumes({"application/json", "application/xml"}) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Operation.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Operation.java index 131eef9b2da..fb398dba68e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Operation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Operation.java @@ -36,7 +36,8 @@ import javax.ws.rs.core.Response; /** * */ -@Api(value = "Operation") + +@Api(value = "Operation", description = "Operation management related operations can be found here.") public interface Operation { /* @deprecated */ diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Policy.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Policy.java index 59ecc88a839..57a55213289 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Policy.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Policy.java @@ -38,7 +38,8 @@ import java.util.List; /** * */ -@Api(value = "Policy") + +@Api(value = "Policy", description = "Policy management related operations can be found here.") public interface Policy { @POST diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Role.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Role.java index abf48eb8e5f..a179d32e426 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Role.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Role.java @@ -39,7 +39,7 @@ import java.util.List; /** * */ -@Api(value = "Role") +@Api(value = "Role", description = "Role management related operations can be found here.") public interface Role { @GET diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/User.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/User.java index d531fa25bee..c3aefdbd823 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/User.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/User.java @@ -44,7 +44,7 @@ import java.util.List; /** * This represents the JAX-RS services of User related functionality. */ -@Api(value = "User") +@Api(value = "User", description = "User management related operations can be found here.") public interface User { @POST diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ApplicationWrapper.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ApplicationWrapper.java index 4631e4e944e..bb43a976435 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ApplicationWrapper.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/ApplicationWrapper.java @@ -18,14 +18,23 @@ package org.wso2.carbon.device.mgt.jaxrs.beans; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import java.util.List; + +@ApiModel(value = "ApplicationWrapper", description = "Application details together with user, " + + "role or devices the application is associated with.") public class ApplicationWrapper { + @ApiModelProperty(name = "userNameList", value = "List of user names.", required = true ) private List userNameList; + @ApiModelProperty(name = "roleNameList", value = "List of role names.", required = true ) private List roleNameList; + @ApiModelProperty(name = "deviceIdentifiers", value = "List of device identifiers.", required = true ) private List deviceIdentifiers; + @ApiModelProperty(name = "application", value = "Details of the mobile application.", required = true ) private MobileApp application; public MobileApp getApplication() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/EnrollmentCertificate.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/EnrollmentCertificate.java index 40d94da4edb..d6a79db6f93 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/EnrollmentCertificate.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/EnrollmentCertificate.java @@ -18,9 +18,19 @@ package org.wso2.carbon.device.mgt.jaxrs.beans; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +@ApiModel(value = "EnrollmentCertificate", description = "Details of certificates used in enrollment.") public class EnrollmentCertificate { + + @ApiModelProperty(name = "serial", value = "The unique ID used to identify a certificate. This is the devices " + + "serial number in case of mutual SSL is used for enrollment.", + required = true ) String serial; + @ApiModelProperty(name = "pem", value = "Case 64 encode .pem file content.", required = true ) String pem; + @ApiModelProperty(name = "tenantId", value = "The ID of the tenant who adds the certificate.", required = true ) int tenantId; public int getTenantId() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/MobileApp.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/MobileApp.java index 7338f6141c6..dd6a699c6c3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/MobileApp.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/MobileApp.java @@ -18,24 +18,51 @@ package org.wso2.carbon.device.mgt.jaxrs.beans; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + import java.util.Properties; /** * This class represents the generic mobile AuthenticationImpl information * which is used by AppM. */ +@ApiModel(value = "ApplicationWrapper", description = "Details of a mobile application.") public class MobileApp { + @ApiModelProperty(name = "id", value = "Id of the app used internally.", required = true ) private String id; + @ApiModelProperty(name = "name", value = "The name of the application.", required = true ) private String name; + @ApiModelProperty(name = "type", value = "The type of the application. The following types of applications are " + + "supported: enterprise, public and webapp..", required = true ) private MobileAppTypes type; + @ApiModelProperty(name = "platform", value = "Platform the app can be installed on .", required = true ) private String platform; + @ApiModelProperty(name = "version", value = "Version of the application.", required = true ) private String version; + @ApiModelProperty(name = "identifier", value = "The package name of the application.", required = true ) private String identifier; + @ApiModelProperty(name = "iconImage", value = "Link to the icon of the app.", required = true ) private String iconImage; + @ApiModelProperty(name = "packageName", value = "Define the exact name of the application package. You can use one " + + "of the following methods to get the package name.\n" + + "Go to the respective application in the play store and copy the" + + " ID or package name from the URL.\n" + + "Example: The play store application URL for the Viber app is " + + "https://play.google.com/store/apps/details?id=com.viber.voip&hl=en." + + " Therefore, the package name or " + + "the application ID is: id=com.viber.voip \n" + + "Download the System Info for Android to your device from the" + + " play store. \n" + + "Once the application is successfully installed go to the Tasks " + + "tab and you will see the package name under the respective " + + "application..", required = true ) private String packageName; + @ApiModelProperty(name = "appIdentifier", value = "The package name of the application.", required = true ) private String appIdentifier; private String location; + @ApiModelProperty(name = "properties", value = "List of meta data.", required = true ) private Properties properties; public MobileAppTypes getType() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/UserCredentialWrapper.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/UserCredentialWrapper.java index d0c201b8d66..e5674b9de71 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/UserCredentialWrapper.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/UserCredentialWrapper.java @@ -18,13 +18,20 @@ package org.wso2.carbon.device.mgt.jaxrs.beans; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +@ApiModel(value = "UserCredentialWrapper", description = "User credentials are included in this class.") public class UserCredentialWrapper { + @ApiModelProperty(name = "username", value = "Username of the user.", required = true ) private String username; /* Base64 encoded password */ + @ApiModelProperty(name = "oldPassword", value = "Old password of the user.", required = true ) private String oldPassword; + @ApiModelProperty(name = "newPassword", value = "New password of the user.", required = true ) private String newPassword; public String getNewPassword() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/UserWrapper.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/UserWrapper.java index c03a762ee32..8009ae233e2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/UserWrapper.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/UserWrapper.java @@ -18,16 +18,26 @@ package org.wso2.carbon.device.mgt.jaxrs.beans; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +@ApiModel(value = "UserWrapper", description = "User details and the roles of the user.") public class UserWrapper { private String username; /* Base64 encoded password */ + + @ApiModelProperty(name = "password", value = "Base64 encoded password.", required = true ) private String password; + @ApiModelProperty(name = "firstname", value = "The first name of the user.", required = true ) private String firstname; + @ApiModelProperty(name = "lastname", value = "The last name of the user.", required = true ) private String lastname; + @ApiModelProperty(name = "emailAddress", value = "The email address of the user.", required = true ) private String emailAddress; + @ApiModelProperty(name = "roles", value = "List of roles.", required = true ) private String[] roles; public String getUsername() { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/notification/mgt/Notification.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/notification/mgt/Notification.java index 0d3af9886d9..f9f776222ae 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/notification/mgt/Notification.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/notification/mgt/Notification.java @@ -18,11 +18,15 @@ package org.wso2.carbon.device.mgt.common.notification.mgt; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; /** * DTO of Notification object which is used to communicate Operation notifications to MDM core. */ + +@ApiModel(value = "Notification", description = "This is used to communicate Operation notifications to MDM.") public class Notification { public enum Status{ @@ -33,10 +37,20 @@ public class Notification { ALERT, } + @ApiModelProperty(name = "notificationId", value = "Defines the notification ID.", required = true ) private int notificationId; + @ApiModelProperty(name = "deviceIdentifier", value = "Defines the device identification properties.", + required = true ) private DeviceIdentifier deviceIdentifier; + @ApiModelProperty(name = "description", value = "Provides the message you want to send to the user.", + required = true ) private String description; + @ApiModelProperty(name = "operationId", value = "Provides the operationID.", required = true ) private int operationId; + @ApiModelProperty(name = "status", value = "Provides the status of the message." + + "The following values can be assigned for the status.\n" + + "NEW: The message is in the unread state.\n" + + "CHECKED: The message is in the read state.", required = true ) private Status status; public Status getStatus() { From 5d1bf67630bfbb0c35982c11b68fcd29a73f33e7 Mon Sep 17 00:00:00 2001 From: Madhawa Perera Date: Fri, 13 May 2016 01:31:33 +0530 Subject: [PATCH 12/24] Adding swagger annotations to beans --- components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml index c8251cb93b9..597ea8239ac 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml @@ -54,7 +54,7 @@ Policy Management Common Bundle javax.xml.bind.annotation, - io.swagger.annotations.*;resolution:=optional + io.swagger.annotations.*;resolution:=optional, org.wso2.carbon.device.mgt.common.*, org.wso2.carbon.device.mgt.core.dto.*, javax.xml.bind.*, From 94aacb16256b12a487e84a350d4c885aa1d1fa90 Mon Sep 17 00:00:00 2001 From: Madhawa Perera Date: Fri, 13 May 2016 02:38:10 +0530 Subject: [PATCH 13/24] Adding swagger annotations to beans --- .../carbon/policy/mgt/common/ProfileFeature.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/ProfileFeature.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/ProfileFeature.java index 00e3b65d968..5de755a35d4 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/ProfileFeature.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/ProfileFeature.java @@ -18,16 +18,29 @@ package org.wso2.carbon.policy.mgt.common; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + import java.io.Serializable; +@ApiModel(value = "ProfileFeature", description = "This class carries all information related to profile " + + "features") public class ProfileFeature implements Serializable { private static final long serialVersionUID = 19981018L; + @ApiModelProperty(name = "id", value = "Define the ID", required = true) private int id; + @ApiModelProperty(name = "featureCode", value = "Provide the code that defines the policy you wish to add", + required = true) private String featureCode; + @ApiModelProperty(name = "profileId", value = "Define the ID of the profile", required = true) private int profileId; + @ApiModelProperty(name = "deviceTypeId", value = "The ID used to define the type of the device platform", + required = true) private int deviceTypeId; + @ApiModelProperty(name = "content", value = "The list of parameters that define the policy", + required = true) private Object content; public int getId() { From bee9a106cc86c4420cb154cd1ea2e94adba62415 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Fri, 13 May 2016 02:53:08 +0530 Subject: [PATCH 14/24] removed method and type from feature --- .../feature/mgt/util/AnnotationUtil.java | 39 ++++++++--------- .../devicemgt/app/modules/operation.js | 42 +++++++++---------- 2 files changed, 36 insertions(+), 45 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/feature/mgt/util/AnnotationUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/feature/mgt/util/AnnotationUtil.java index 42e7d9d87d8..a70c9c5dc14 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/feature/mgt/util/AnnotationUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/feature/mgt/util/AnnotationUtil.java @@ -64,6 +64,7 @@ public class AnnotationUtil { private static final String PACKAGE_ORG_SPRINGFRAMEWORK = "org.springframework"; private static final String STRING_ARR = "string_arr"; private static final String STRING = "string"; + private static final String METHOD = "method"; private Class featureAnnotationClazz; private ClassLoader classLoader; @@ -147,8 +148,7 @@ public class AnnotationUtil { Map apiParams = new HashMap<>(); for (int i = 0; i < annotations.length; i++) { Annotation currentAnnotation = annotations[i]; - String method = processHttpMethodAnnotation(feature, currentAnnotation); - apiParams.put("method", method); + processHttpMethodAnnotation(apiParams, currentAnnotation); if (currentAnnotation.annotationType().getName().equals(Path.class.getName())) { String uri = getPathAnnotationValue(currentMethod); apiParams.put("uri", uri); @@ -200,25 +200,20 @@ public class AnnotationUtil { /** * Read Method annotations indicating HTTP Methods - * @param feature - * @param currentAnnotation - * @return */ - private String processHttpMethodAnnotation(Feature feature, Annotation currentAnnotation) { + private void processHttpMethodAnnotation(Map apiParams, Annotation currentAnnotation) { //Extracting method with which feature is exposed - String method = null; if (currentAnnotation.annotationType().getName().equals(GET.class.getName())) { - method = HttpMethod.GET; + apiParams.put(METHOD, HttpMethod.GET); } else if (currentAnnotation.annotationType().getName().equals(POST.class.getName())) { - method = HttpMethod.POST; + apiParams.put(METHOD, HttpMethod.POST); } else if (currentAnnotation.annotationType().getName().equals(OPTIONS.class.getName())) { - method = HttpMethod.OPTIONS; + apiParams.put(METHOD, HttpMethod.OPTIONS); } else if (currentAnnotation.annotationType().getName().equals(DELETE.class.getName())) { - method = HttpMethod.DELETE; + apiParams.put(METHOD, HttpMethod.DELETE); } else if (currentAnnotation.annotationType().getName().equals(PUT.class.getName())) { - method = HttpMethod.PUT; + apiParams.put(METHOD, HttpMethod.PUT); } - return method; } /** @@ -233,15 +228,15 @@ public class AnnotationUtil { Annotation featureAnno = currentMethod.getAnnotation(featureAnnotationClazz); for (int k = 0; k < featureAnnoMethods.length; k++) { switch (featureAnnoMethods[k].getName()) { - case "name": - feature.setName(invokeMethod(featureAnnoMethods[k], featureAnno, STRING)); - break; - case "code": - feature.setCode(invokeMethod(featureAnnoMethods[k], featureAnno, STRING)); - break; - case "description": - feature.setDescription(invokeMethod(featureAnnoMethods[k], featureAnno, STRING)); - break; + case "name": + feature.setName(invokeMethod(featureAnnoMethods[k], featureAnno, STRING)); + break; + case "code": + feature.setCode(invokeMethod(featureAnnoMethods[k], featureAnno, STRING)); + break; + case "description": + feature.setDescription(invokeMethod(featureAnnoMethods[k], featureAnno, STRING)); + break; } } return feature; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/operation.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/operation.js index c6219757082..1655adf1edd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/operation.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/operation.js @@ -40,14 +40,11 @@ var operationModule = function () { privateMethods.getOperationsFromFeatures = function (deviceType, operationType) { var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/features/" + deviceType; var featuresList = serviceInvokers.XMLHttp.get(url, function (responsePayload) { - var features = responsePayload; - var featureList = []; - var feature; - for (var i = 0; i < features.length; i++) { - feature = {}; - if (features[i].type != operationType) { - continue; - } else if (features[i].type == 'monitor') { + var features = responsePayload; + var featureList = []; + var feature; + for (var i = 0; i < features.length; i++) { + feature = {}; var analyticStreams = utility.getDeviceTypeConfig(deviceType)["analyticStreams"]; if (analyticStreams) { for (var stream in analyticStreams) { @@ -57,23 +54,22 @@ var operationModule = function () { } } } - } - feature["operation"] = features[i].code; - feature["name"] = features[i].name; - feature["method"] = features[i].method; - feature["description"] = features[i].description; - feature["deviceType"] = deviceType; - feature["params"] = []; - var metaData = features[i].metadataEntries; - if (metaData) { - for (var j = 0; j < metaData.length; j++) { - feature["params"].push(metaData[j].value); + + feature["operation"] = features[i].code; + feature["name"] = features[i].name; + feature["description"] = features[i].description; + feature["deviceType"] = deviceType; + feature["params"] = []; + var metaData = features[i].metadataEntries; + if (metaData) { + for (var j = 0; j < metaData.length; j++) { + feature["params"].push(metaData[j].value); + } + featureList.push(feature); } - featureList.push(feature); } - } - return featureList; - }, function (responsePayload) { + return featureList; + }, function (responsePayload) { var response = {}; response["status"] = "error"; return response; From 9e4b4d22054225cac28385b198d4eb39755b4bf2 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Fri, 13 May 2016 04:02:42 +0530 Subject: [PATCH 15/24] Improving swagger annotations --- .../org.wso2.carbon.device.mgt.api/pom.xml | 18 +++ .../device/mgt/jaxrs/ApiOriginFilter.java | 44 ++++++ .../device/mgt/jaxrs/api/Authentication.java | 34 ----- .../device/mgt/jaxrs/api/Certificate.java | 3 +- .../device/mgt/jaxrs/api/Configuration.java | 1 + .../carbon/device/mgt/jaxrs/api/Device.java | 8 +- .../mgt/jaxrs/api/DeviceInformation.java | 1 + .../mgt/jaxrs/api/DeviceNotification.java | 1 + .../device/mgt/jaxrs/api/DeviceSearch.java | 4 +- .../carbon/device/mgt/jaxrs/api/Feature.java | 1 + .../carbon/device/mgt/jaxrs/api/License.java | 1 + .../device/mgt/jaxrs/api/Operation.java | 5 +- .../carbon/device/mgt/jaxrs/api/Policy.java | 1 + .../carbon/device/mgt/jaxrs/api/Profile.java | 1 + .../carbon/device/mgt/jaxrs/api/Role.java | 20 +-- .../carbon/device/mgt/jaxrs/api/User.java | 5 +- .../jaxrs/api/impl/AuthenticationImpl.java | 36 ----- .../device/mgt/jaxrs/api/impl/DeviceImpl.java | 4 +- .../mgt/jaxrs/api/impl/DeviceSearchImpl.java | 2 +- .../mgt/jaxrs/api/impl/OperationImpl.java | 2 +- .../device/mgt/jaxrs/api/impl/RoleImpl.java | 4 +- .../device/mgt/jaxrs/api/impl/UserImpl.java | 4 +- .../src/main/webapp/WEB-INF/cxf-servlet.xml | 140 +++--------------- .../src/main/webapp/WEB-INF/web.xml | 21 ++- pom.xml | 19 ++- 25 files changed, 153 insertions(+), 227 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/ApiOriginFilter.java delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Authentication.java delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/AuthenticationImpl.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml index 07ef52fde5a..0d53ffbc058 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml @@ -207,6 +207,24 @@ io.swagger swagger-annotations + + + io.swagger + swagger-core + + + org.slf4j + slf4j-api + + + + + io.swagger + swagger-jaxrs + + + javax.servlet + servlet-api provided diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/ApiOriginFilter.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/ApiOriginFilter.java new file mode 100644 index 00000000000..9ba3b5b97b4 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/ApiOriginFilter.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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. + * + */ +package org.wso2.carbon.device.mgt.jaxrs; + +import javax.servlet.*; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +public class ApiOriginFilter implements Filter { + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + HttpServletResponse res = (HttpServletResponse) response; + res.addHeader("Access-Control-Allow-Origin", "*"); + res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT"); + res.addHeader("Access-Control-Allow-Headers", "Content-Type"); + chain.doFilter(request, response); + } + + public void destroy() { + //do nothing + } + + public void init(FilterConfig filterConfig) throws ServletException { + //do nothing + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Authentication.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Authentication.java deleted file mode 100644 index e28de808a09..00000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Authentication.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you 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. - */ - -package org.wso2.carbon.device.mgt.jaxrs.api; - -import io.swagger.annotations.Api; - -import javax.ws.rs.Consumes; -import javax.ws.rs.Produces; - -/** - * Authentication related REST-API interface. - */ -@Api(value = "Authentication") -@Produces({ "application/json", "application/xml" }) -@Consumes({ "application/json", "application/xml" }) -public interface Authentication { - -} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Certificate.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Certificate.java index 8bfcd31f660..8a2662036b3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Certificate.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Certificate.java @@ -36,8 +36,9 @@ import javax.ws.rs.core.Response; /** * All the certificate related tasks such as saving certificates, can be done through this endpoint. */ -@Api(value = "Certificate", description = "certificate related tasks such as saving certificates") +@Api(value = "Certificate", description = "Certificate related tasks such as saving certificates") @SuppressWarnings("NonJaxWsWebServices") +@Path("/certificates") @Produces({ "application/json", "application/xml" }) @Consumes({ "application/json", "application/xml" }) public interface Certificate { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Configuration.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Configuration.java index c7bc7759cf2..5e7c8a9cd27 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Configuration.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Configuration.java @@ -35,6 +35,7 @@ import javax.ws.rs.core.Response; * All end points support JSON, XMl with content negotiation. */ @Api(value = "Configuration", description = "General Tenant Configuration implementation") +@Path("/configuration") @SuppressWarnings("NonJaxWsWebServices") @Produces({ "application/json", "application/xml" }) @Consumes({ "application/json", "application/xml" }) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Device.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Device.java index 9710e6f426c..97b34d16fee 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Device.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Device.java @@ -29,7 +29,8 @@ import javax.ws.rs.core.Response; /** * Device related operations such as get all the available devices, etc. */ -@Api(value = "Devices") +@Api(value = "Devices", description = "") +@Path("/devices") @SuppressWarnings("NonJaxWsWebServices") public interface Device { @@ -40,6 +41,7 @@ public interface Device { * @return Device List */ @GET + @Path("devices") @ApiOperation( consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON, @@ -94,7 +96,7 @@ public interface Device { */ @GET @Path("user/{user}") - Response getDevice(@PathParam("user") String user); + Response getDeviceOfUser(@PathParam("user") String user); /** * Fetch device count of a given user. @@ -104,7 +106,7 @@ public interface Device { */ @GET @Path("user/{user}/count") - Response getDeviceCount(@PathParam("user") String user); + Response getDeviceCountOfUser(@PathParam("user") String user); /** * Get current device count diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceInformation.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceInformation.java index d55477eb076..f03c5c6c731 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceInformation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceInformation.java @@ -37,6 +37,7 @@ import javax.ws.rs.core.Response; * Device information related operations. */ @Api(value = "DeviceInfo") +@Path("/information") @SuppressWarnings("NonJaxWsWebServices") public interface DeviceInformation { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceNotification.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceNotification.java index f17e5840518..9e1aa4ddfc4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceNotification.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceNotification.java @@ -42,6 +42,7 @@ import javax.ws.rs.core.Response; */ @Api(value = "DeviceNotification") @SuppressWarnings("NonJaxWsWebServices") +@Path("/notifications") @Produces({"application/json", "application/xml"}) @Consumes({ "application/json", "application/xml" }) public interface DeviceNotification { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceSearch.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceSearch.java index ec27086e360..9cf154e9554 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceSearch.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/DeviceSearch.java @@ -28,6 +28,7 @@ import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper; import org.wso2.carbon.device.mgt.common.search.SearchContext; import javax.ws.rs.GET; +import javax.ws.rs.Path; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -35,6 +36,7 @@ import javax.ws.rs.core.Response; * Device search related operations such as getting device information. */ @Api(value = "DeviceSearch") +@Path("/search") @SuppressWarnings("NonJaxWsWebServices") public interface DeviceSearch { @@ -50,6 +52,6 @@ public interface DeviceSearch { @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 500, message = "Error occurred while searching the device information") }) - Response getDeviceInfo(@ApiParam(name = "enrollmentCertificates", value = "List of search conditions", + Response getFilteredDeviceInfo(@ApiParam(name = "enrollmentCertificates", value = "List of search conditions", required = true) SearchContext searchContext); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Feature.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Feature.java index 42f23ae3b9c..c95195714be 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Feature.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Feature.java @@ -33,6 +33,7 @@ import javax.ws.rs.core.Response; */ @Api(value = "Feature") @SuppressWarnings("NonJaxWsWebServices") +@Path("/features") @Produces({"application/json", "application/xml"}) @Consumes({"application/json", "application/xml"}) public interface Feature { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/License.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/License.java index fe07dce2e32..f8884e818c3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/License.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/License.java @@ -28,6 +28,7 @@ import javax.ws.rs.core.Response; * This class represents license related operations. */ @Api(value = "License") +@Path("/license") @SuppressWarnings("NonJaxWsWebServices") public interface License { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Operation.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Operation.java index 131eef9b2da..8c3bc55a974 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Operation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Operation.java @@ -37,6 +37,7 @@ import javax.ws.rs.core.Response; * */ @Api(value = "Operation") +@Path("/operations") public interface Operation { /* @deprecated */ @@ -49,7 +50,7 @@ public interface Operation { consumes = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, produces = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, httpMethod = "GET", - value = "Getting Pagination Details for Operations on a Device.", + value = "Getting Paginated Details for Operations on a Device.", notes = "You will carry out many operations on a device. In a situation where you wish to view the all" + " the operations carried out on a device it is not feasible to show all the details on one page" + " therefore the details are paginated." + @@ -89,7 +90,7 @@ public interface Operation { @ApiResponses(value = { @ApiResponse(code = 200, message = "List of Operations on a device."), @ApiResponse(code = 500, message = "Error occurred while fetching the operations for the " + "device.") }) - Response getDeviceOperations(@ApiParam(name = "type", value = "Define the device type as the value for {type}. " + + Response getAllDeviceOperations(@ApiParam(name = "type", value = "Define the device type as the value for {type}. " + "Example: ios, android or windows.", required = true) @PathParam("type") String type, @ApiParam(name = "id", value = "Define the device ID", diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Policy.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Policy.java index e266e8ee944..9cad9178428 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Policy.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Policy.java @@ -39,6 +39,7 @@ import java.util.List; * */ @Api(value = "Policy") +@Path("/policies") public interface Policy { @POST diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Profile.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Profile.java index 182b1adbf63..7762048499c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Profile.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Profile.java @@ -30,6 +30,7 @@ import javax.ws.rs.core.Response; * These end points provide profile related operations. */ @Api(value = "Profile") +@Path("/profiles") @SuppressWarnings("NonJaxWsWebServices") public interface Profile { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Role.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Role.java index abf48eb8e5f..57ec14ce761 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Role.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Role.java @@ -19,27 +19,16 @@ package org.wso2.carbon.device.mgt.jaxrs.api; import io.swagger.annotations.*; -import org.wso2.carbon.device.mgt.common.app.mgt.Application; -import org.wso2.carbon.device.mgt.jaxrs.api.util.ResponsePayload; import org.wso2.carbon.device.mgt.jaxrs.beans.RoleWrapper; import org.wso2.carbon.user.mgt.common.UIPermissionNode; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; +import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.List; -/** - * - */ @Api(value = "Role") +@Path("/roles") public interface Role { @GET @@ -54,7 +43,7 @@ public interface Role { response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "List of available roles"), @ApiResponse(code = 500, message = "Error occurred while fetching the role list.") }) - Response getRoles(); + Response getAllRoles(); @GET @Path("{userStore}") @@ -69,7 +58,7 @@ public interface Role { response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "List of available roles"), @ApiResponse(code = 500, message = "Error occurred while fetching the role list.") }) - Response getRoles(@ApiParam(name = "userStore", value = "Provide the name of the UserStore you wish to get the" + + Response getRolesOfUserStore(@ApiParam(name = "userStore", value = "Provide the name of the UserStore you wish to get the" + " details from ", required = true) @PathParam("userStore") String userStore); @@ -208,4 +197,5 @@ public interface Role { @ApiResponses(value = { @ApiResponse(code = 200, message = "Retrieved the role count."), @ApiResponse(code = 500, message = "Error occurred while retrieving the role count.") }) Response getRoleCount(); + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/User.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/User.java index 6c5e45b7b92..747abf0b4ac 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/User.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/User.java @@ -45,6 +45,7 @@ import java.util.List; * This represents the JAX-RS services of User related functionality. */ @Api(value = "User") +@Path("/users") public interface User { @POST @@ -139,7 +140,7 @@ public interface User { @ApiResponse(code = 400, message = "User by username: 'username' does not exist for role retrieval"), @ApiResponse(code = 500, message = "Exception in trying to retrieve roles for user by username: 'username'") }) - Response getRoles(@ApiParam(name = "username", value = "Provide the user name of the user you wish to get" + Response getRolesOfUser(@ApiParam(name = "username", value = "Provide the user name of the user you wish to get" + " the role details", required = true) @QueryParam("username") String username); @GET @@ -264,7 +265,7 @@ public interface User { @PUT @Path("{roleName}/users") @Produces({MediaType.APPLICATION_JSON}) - Response updateRoles(@PathParam("username") String username, List userList); + Response updateRoles(@PathParam("roleName") String roleName, List userList); @POST @Path("change-password") diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/AuthenticationImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/AuthenticationImpl.java deleted file mode 100644 index 8bc0cd78d87..00000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/AuthenticationImpl.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you 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. - */ - -package org.wso2.carbon.device.mgt.jaxrs.api.impl; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.ws.rs.Consumes; -import javax.ws.rs.Produces; - -/** - * Authentication related REST-API implementation. - */ -@Produces({ "application/json", "application/xml" }) -@Consumes({ "application/json", "application/xml" }) -public class AuthenticationImpl { - - private static Log log = LogFactory.getLog(AuthenticationImpl.class); -} - diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/DeviceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/DeviceImpl.java index e25b9b9288f..19ea361c089 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/DeviceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/DeviceImpl.java @@ -142,7 +142,7 @@ public class DeviceImpl implements Device{ */ @GET @Path("user/{user}") - public Response getDevice(@PathParam("user") String user) { + public Response getDeviceOfUser(@PathParam("user") String user) { List devices; try { devices = DeviceMgtAPIUtils.getDeviceManagementService().getDevicesOfUser(user); @@ -165,7 +165,7 @@ public class DeviceImpl implements Device{ */ @GET @Path("user/{user}/count") - public Response getDeviceCount(@PathParam("user") String user) { + public Response getDeviceCountOfUser(@PathParam("user") String user) { try { Integer count = DeviceMgtAPIUtils.getDeviceManagementService().getDeviceCount(user); return Response.status(Response.Status.OK).entity(count).build(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/DeviceSearchImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/DeviceSearchImpl.java index 4582fa24d3d..7ed9576d0b5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/DeviceSearchImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/DeviceSearchImpl.java @@ -38,7 +38,7 @@ public class DeviceSearchImpl implements DeviceSearch { private static Log log = LogFactory.getLog(DeviceSearchImpl.class); @GET - public Response getDeviceInfo(SearchContext searchContext) { + public Response getFilteredDeviceInfo(SearchContext searchContext) { SearchManagerService searchManagerService; List devices; try { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/OperationImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/OperationImpl.java index bdca4c54915..09beeeeda44 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/OperationImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/OperationImpl.java @@ -103,7 +103,7 @@ public class OperationImpl implements org.wso2.carbon.device.mgt.jaxrs.api.Opera @Override @GET @Path("{type}/{id}") - public Response getDeviceOperations(@PathParam("type") String type, @PathParam("id") String id) { + public Response getAllDeviceOperations(@PathParam("type") String type, @PathParam("id") String id) { List operations; DeviceManagementProviderService dmService; DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/RoleImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/RoleImpl.java index 739f5f56782..278a7dfd269 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/RoleImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/RoleImpl.java @@ -65,7 +65,7 @@ public class RoleImpl implements org.wso2.carbon.device.mgt.jaxrs.api.Role { @Override @GET @Produces({MediaType.APPLICATION_JSON}) - public Response getRoles() { + public Response getAllRoles() { List filteredRoles; try { filteredRoles = getRolesFromUserStore(); @@ -89,7 +89,7 @@ public class RoleImpl implements org.wso2.carbon.device.mgt.jaxrs.api.Role { @GET @Path("{userStore}") @Produces({MediaType.APPLICATION_JSON}) - public Response getRoles(@PathParam("userStore") String userStore) { + public Response getRolesOfUserStore(@PathParam("userStore") String userStore) { String[] roles; try { AbstractUserStoreManager abstractUserStoreManager = diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/UserImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/UserImpl.java index 2b136e6131f..427a654e544 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/UserImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/UserImpl.java @@ -371,7 +371,7 @@ public class UserImpl implements org.wso2.carbon.device.mgt.jaxrs.api.User { @GET @Path("roles") @Produces({MediaType.APPLICATION_JSON}) - public Response getRoles(@QueryParam("username") String username) { + public Response getRolesOfUser(@QueryParam("username") String username) { ResponsePayload responsePayload = new ResponsePayload(); try { UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); @@ -716,7 +716,7 @@ public class UserImpl implements org.wso2.carbon.device.mgt.jaxrs.api.User { @PUT @Path("{roleName}/users") @Produces({MediaType.APPLICATION_JSON}) - public Response updateRoles(@PathParam("username") String username, List userList) { + public Response updateRoles(@PathParam("roleName") String username, List userList) { try { final UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); if (log.isDebugEnabled()) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml index 3f2159018c1..05d9a6d8b41 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -24,145 +24,46 @@ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd"> - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - + + + + + + + + + + + + + + + + @@ -175,9 +76,6 @@ - diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/web.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/web.xml index ab8d04cbe83..97f0970968d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/web.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/web.xml @@ -25,6 +25,16 @@ org.apache.cxf.transport.servlet.CXFServlet + + + + + + + + swagger.security.filter + ApiAuthorizationFilterImpl + 1 @@ -41,7 +51,7 @@ doAuthentication - true + false