refactored general configuration

revert-70aa11f8
ayyoob 8 years ago
parent c71e5ead00
commit a7074e2e4e

@ -16,7 +16,7 @@
* under the License. * under the License.
* *
*/ */
package org.wso2.carbon.device.mgt.jaxrs.service.api.admin; package org.wso2.carbon.device.mgt.jaxrs.service.api;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import org.wso2.carbon.apimgt.annotations.api.API; import org.wso2.carbon.apimgt.annotations.api.API;
@ -30,7 +30,7 @@ import javax.ws.rs.core.Response;
@API(name = "Device Type Management", version = "1.0.0", context = "/admin/device-types", tags = {"devicemgt_admin"}) @API(name = "Device Type Management", version = "1.0.0", context = "/admin/device-types", tags = {"devicemgt_admin"})
@Path("/admin/device-types") @Path("/device-types")
@Api(value = "Device Type Management", description = "This API corresponds to all tasks related to device " + @Api(value = "Device Type Management", description = "This API corresponds to all tasks related to device " +
"type management") "type management")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)

@ -16,14 +16,14 @@
* under the License. * under the License.
* *
*/ */
package org.wso2.carbon.device.mgt.jaxrs.service.impl.admin; package org.wso2.carbon.device.mgt.jaxrs.service.impl;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceTypeList; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceTypeList;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.DeviceTypeManagementService; import org.wso2.carbon.device.mgt.jaxrs.service.api.DeviceTypeManagementService;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import javax.ws.rs.GET; import javax.ws.rs.GET;
@ -32,7 +32,7 @@ import javax.ws.rs.Path;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.List; import java.util.List;
@Path("/admin/device-types") @Path("/device-types")
public class DeviceTypeManagementServiceImpl implements DeviceTypeManagementService { public class DeviceTypeManagementServiceImpl implements DeviceTypeManagementService {
private static Log log = LogFactory.getLog(DeviceTypeManagementServiceImpl.class); private static Log log = LogFactory.getLog(DeviceTypeManagementServiceImpl.class);

@ -107,7 +107,7 @@
<Permission> <Permission>
<name>View device types</name> <name>View device types</name>
<path>/device-mgt/admin/devices/Admin-DeviceType-View</path> <path>/device-mgt/admin/devices/Admin-DeviceType-View</path>
<url>/admin/device-types</url> <url>/device-types</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<!-- End of Device related APIs --> <!-- End of Device related APIs -->

@ -78,7 +78,7 @@
<bean id="groupManagementAdminService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.admin.GroupManagementAdminServiceImpl"/> <bean id="groupManagementAdminService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.admin.GroupManagementAdminServiceImpl"/>
<bean id="userManagementAdminService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.admin.UserManagementAdminServiceImpl"/> <bean id="userManagementAdminService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.admin.UserManagementAdminServiceImpl"/>
<bean id="dashboardServiceBean" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.DashboardImpl"/> <bean id="dashboardServiceBean" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.DashboardImpl"/>
<bean id="deviceTypeManagementAdminService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.admin.DeviceTypeManagementServiceImpl"/> <bean id="deviceTypeManagementAdminService" class="org.wso2.carbon.device.mgt.jaxrs.service.impl.DeviceTypeManagementServiceImpl"/>
<bean id="jsonProvider" class="org.wso2.carbon.device.mgt.jaxrs.common.GsonMessageBodyHandler"/> <bean id="jsonProvider" class="org.wso2.carbon.device.mgt.jaxrs.common.GsonMessageBodyHandler"/>
<!--<bean id="errorHandler" class="org.wso2.carbon.device.mgt.jaxrs.common.ErrorHandler"/>--> <!--<bean id="errorHandler" class="org.wso2.carbon.device.mgt.jaxrs.common.ErrorHandler"/>-->

@ -18,7 +18,7 @@
var WEB_APP_TITLE = "WSO2 CDM"; var WEB_APP_TITLE = "WSO2 CDM";
var WEB_APP_CONTEXT = "/devicemgt"; var WEB_APP_CONTEXT = "/devicemgt";
var ADMIN_SERVICE_CONTEXT = "/devicemgt_admin"; var ADMIN_SERVICE_CONTEXT = "/api/device-mgt/v1.0";
var USER_SESSION_KEY = "_UUF_USER"; var USER_SESSION_KEY = "_UUF_USER";
var UNSPECIFIED = "Unspecified"; var UNSPECIFIED = "Unspecified";
var httpURL = "httpURL"; var httpURL = "httpURL";

@ -38,6 +38,32 @@ deviceModule = function () {
var deviceCloudService = devicemgtProps["httpsURL"] + "/common/device_manager"; var deviceCloudService = devicemgtProps["httpsURL"] + "/common/device_manager";
/**
* Only GET method is implemented for now since there are no other type of methods used this method.
* @param url - URL to call the backend without the host
* @param method - HTTP Method (GET, POST)
* @returns An object with 'status': 'success'|'error', 'content': {}
*/
privateMethods.callBackend = function (url, method) {
if (constants["HTTP_GET"] == method) {
return serviceInvokers.XMLHttp.get(url,
function (backendResponse) {
var response = {};
response.content = backendResponse.responseText;
if (backendResponse.status == 200) {
response.status = "success";
} else if (backendResponse.status == 400 || backendResponse.status == 401 ||
backendResponse.status == 404 || backendResponse.status == 500) {
response.status = "error";
}
return response;
}
);
} else {
log.error("Runtime error : This method only support HTTP GET requests.");
}
};
privateMethods.validateAndReturn = function (value) { privateMethods.validateAndReturn = function (value) {
return (value == undefined || value == null) ? constants.UNSPECIFIED : value; return (value == undefined || value == null) ? constants.UNSPECIFIED : value;
}; };
@ -289,16 +315,12 @@ deviceModule = function () {
}; };
publicMethods.getDeviceTypes = function () { publicMethods.getDeviceTypes = function () {
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/types"; var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/device-types";
return serviceInvokers.XMLHttp.get( var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
url, function (responsePayload) { if (response.status == "success") {
return responsePayload; response.content = parse(response.content);
},
function (responsePayload) {
log.error(responsePayload);
return -1;
} }
); return response;
}; };
//Old methods //Old methods

@ -263,29 +263,30 @@ var userModule = function () {
/** /**
* Get Platforms. * Get Platforms.
* @deprecated moved this device module under getDeviceTypes.
*/ */
//TODO Move this piece of logic out of user.js to somewhere else appropriate. //TODO Move this piece of logic out of user.js to somewhere else appropriate.
publicMethods.getPlatforms = function () { //publicMethods.getPlatforms = function () {
var carbonUser = session.get(constants["USER_SESSION_KEY"]); // var carbonUser = session.get(constants["USER_SESSION_KEY"]);
var utility = require("/app/modules/utility.js")["utility"]; // var utility = require("/app/modules/utility.js")["utility"];
if (!carbonUser) { // if (!carbonUser) {
log.error("User object was not found in the session"); // log.error("User object was not found in the session");
throw constants["ERRORS"]["USER_NOT_FOUND"]; // throw constants["ERRORS"]["USER_NOT_FOUND"];
} // }
try { // try {
utility.startTenantFlow(carbonUser); // utility.startTenantFlow(carbonUser);
var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/admin/device-types"; // var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/device-types";
var response = privateMethods.callBackend(url, constants["HTTP_GET"]); // var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
if (response.status == "success") { // if (response.status == "success") {
response.content = parse(response.content); // response.content = parse(response.content);
} // }
return response; // return response;
} catch (e) { // } catch (e) {
throw e; // throw e;
} finally { // } finally {
utility.endTenantFlow(); // utility.endTenantFlow();
} // }
}; //};
/** /**
* Get role * Get role

@ -50,8 +50,10 @@ function onRequest(context) {
if (deviceCount > 0) { if (deviceCount > 0) {
page.deviceCount = deviceCount; page.deviceCount = deviceCount;
var utility = require("/app/modules/utility.js").utility; var utility = require("/app/modules/utility.js").utility;
var data = deviceModule.getDeviceTypes(); var typesListResponse = deviceModule.getDeviceTypes();
var deviceTypes = []; var deviceTypes = [];
if (typesListResponse["status"] == "success") {
var data = typesListResponse["content"];
if (data) { if (data) {
for (var i = 0; i < data.length; i++) { for (var i = 0; i < data.length; i++) {
var config = utility.getDeviceTypeConfig(data[i].name); var config = utility.getDeviceTypeConfig(data[i].name);
@ -67,6 +69,7 @@ function onRequest(context) {
}); });
} }
} }
}
page.deviceTypes = stringify(deviceTypes); page.deviceTypes = stringify(deviceTypes);
} }
} }

@ -25,8 +25,9 @@ function onRequest(context) {
var viewModel = {}; var viewModel = {};
var deviceModule = require("/app/modules/device.js").deviceModule; var deviceModule = require("/app/modules/device.js").deviceModule;
var utility = require("/app/modules/utility.js").utility; var utility = require("/app/modules/utility.js").utility;
var deviceTypes = deviceModule.getDeviceTypes(); var typesListResponse = deviceModule.getDeviceTypes();
if (typesListResponse["status"] == "success") {
var deviceTypes = typesListResponse["content"];
if (deviceTypes) { if (deviceTypes) {
var deviceTypesList = [], virtualDeviceTypesList = []; var deviceTypesList = [], virtualDeviceTypesList = [];
for (var i = 0; i < deviceTypes.length; i++) { for (var i = 0; i < deviceTypes.length; i++) {
@ -66,6 +67,7 @@ function onRequest(context) {
viewModel.virtualDeviceTypesList = virtualDeviceTypesList; viewModel.virtualDeviceTypesList = virtualDeviceTypesList;
} }
viewModel.deviceTypesList = stringify(deviceTypesList); viewModel.deviceTypesList = stringify(deviceTypesList);
}
} else { } else {
log.error("Unable to fetch device types data"); log.error("Unable to fetch device types data");
throw new Error("Unable to fetch device types!"); throw new Error("Unable to fetch device types!");

@ -15,6 +15,7 @@
specific language governing permissions and limitations specific language governing permissions and limitations
under the License. under the License.
}} }}
{{#zone "content"}}
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
<!-- content --> <!-- content -->
@ -116,6 +117,7 @@
<!-- /content --> <!-- /content -->
</div> </div>
</div> </div>
{{/zone}}
{{#zone "bottomJs"}} {{#zone "bottomJs"}}
{{js "js/platform-configuration.js"}} {{js "js/platform-configuration.js"}}
{{/zone}} {{/zone}}

@ -20,15 +20,22 @@ function onRequest(context) {
var utility = require("/app/modules/device.js").utility; var utility = require("/app/modules/device.js").utility;
var deviceModule = require("/app/modules/device.js").deviceModule; var deviceModule = require("/app/modules/device.js").deviceModule;
//get all device types //get all device types
var data = deviceModule.getDeviceTypes();
var deviceTypesArray = []; var deviceTypesArray = [];
var typesListResponse = deviceModule.getDeviceTypes();
if (typesListResponse["status"] == "success") {
var data = typesListResponse["content"].deviceTypes;
if (data) { if (data) {
for (var i = 0; i < data.length; i++) { for (var i = 0; i < data.length; i++) {
var deviceTypeName = data[i].name; var deviceTypeName = data[i];
var configUnitName = utility.getTenantedDeviceUnitName(deviceTypeName, "platform.configuration"); var configUnitName = utility.getTenantedDeviceUnitName(deviceTypeName, "platform.configuration");
if (configUnitName) { if (configUnitName) {
var deviceTypeConfig = utility.getDeviceTypeConfig(deviceTypeName); var deviceTypeConfig = utility.getDeviceTypeConfig(deviceTypeName);
deviceTypesArray.push({name: deviceTypeName, label:deviceTypeConfig.deviceType.label, unitName : configUnitName}); deviceTypesArray.push({
name: deviceTypeName,
label: deviceTypeConfig.deviceType.label,
unitName: configUnitName
});
}
} }
} }
} }

@ -41,7 +41,7 @@ $(document).ready(function () {
} }
invokerUtil.get( invokerUtil.get(
"/devicemgt_admin/configuration", "/api/device-mgt/v1.0/configuration",
function (data) { function (data) {
data = JSON.parse(data); data = JSON.parse(data);
if (data && data.configuration) { if (data && data.configuration) {
@ -85,13 +85,13 @@ $(document).ready(function () {
configList.push(monitorFrequency); configList.push(monitorFrequency);
addConfigFormData.configuration = configList; addConfigFormData.configuration = configList;
var addConfigAPI = "/devicemgt_admin/configuration"; var addConfigAPI = "/api/device-mgt/v1.0/configuration";
invokerUtil.post( invokerUtil.put(
addConfigAPI, addConfigAPI,
addConfigFormData, addConfigFormData,
function (data) { function (data, textStatus, jqXHR) {
data = JSON.parse(data); data = jqXHR.status;
if (data.statusCode == responseCodes["SUCCESS"]) { if (data == 200) {
$("#config-save-form").addClass("hidden"); $("#config-save-form").addClass("hidden");
$("#record-created-msg").removeClass("hidden"); $("#record-created-msg").removeClass("hidden");
} else if (data == 500) { } else if (data == 500) {
@ -118,3 +118,12 @@ $(document).ready(function () {
} }
}); });
}); });
// Start of HTML embedded invoke methods
var showAdvanceOperation = function (operation, button) {
$(button).addClass('selected');
$(button).siblings().removeClass('selected');
var hiddenOperation = ".wr-hidden-operations-content > div";
$(hiddenOperation + '[data-operation="' + operation + '"]').show();
$(hiddenOperation + '[data-operation="' + operation + '"]').siblings().hide();
};

@ -21,11 +21,11 @@ function onRequest(context) {
var DTYPE_CONF_DEVICE_TYPE_LABEL_KEY = "label"; var DTYPE_CONF_DEVICE_TYPE_LABEL_KEY = "label";
var utility = require("/app/modules/utility.js").utility; var utility = require("/app/modules/utility.js").utility;
var userModule = require("/app/modules/user.js")["userModule"]; var deviceModule = require("/app/modules/device.js").deviceModule;
var types = {}; var types = {};
types["types"] = []; types["types"] = [];
var typesListResponse = userModule.getPlatforms(); var typesListResponse = deviceModule.getDeviceTypes();
if (typesListResponse["status"] == "success") { if (typesListResponse["status"] == "success") {
for (var type in typesListResponse["content"]) { for (var type in typesListResponse["content"]) {
var deviceType = typesListResponse["content"][type]["name"]; var deviceType = typesListResponse["content"][type]["name"];

Loading…
Cancel
Save