From 93a82676e318341056e9bcd6e3b8c14ea46fe8f8 Mon Sep 17 00:00:00 2001 From: Dulitha Wijewantha Date: Wed, 21 Jan 2015 17:08:12 +0530 Subject: [PATCH] * Created a utility js to hold the utility functions * Created the UI APIs for mobile * Fixed a bug and changed the implementation to work with the properties Map instead of the List * Changed method signature and implementation to accept DeviceType for the conversion * UI level changes and license headers --- .../device/mgt/core/DeviceManagerImpl.java | 19 ++++++---- .../dao/util/DeviceManagementDAOUtil.java | 22 ++--------- .../jaggeryapps/cdm/api/mobile/device-api.jag | 38 +++++++++++++++++++ .../src/repository/jaggeryapps/cdm/init.js | 33 +++++++++++++++- .../repository/jaggeryapps/cdm/jaggery.conf | 10 +++-- .../jaggeryapps/cdm/modules/utility.js | 32 ++++++++++++++++ .../jaggeryapps/cdm/pages/dashboard.jag | 23 +++++++++-- .../jaggeryapps/cdm/pages/device.jag | 19 +++++++++- 8 files changed, 162 insertions(+), 34 deletions(-) create mode 100644 product/modules/distribution/src/repository/jaggeryapps/cdm/api/mobile/device-api.jag create mode 100644 product/modules/distribution/src/repository/jaggeryapps/cdm/modules/utility.js diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagerImpl.java index 37b49b32b0..1af868981a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagerImpl.java @@ -28,6 +28,7 @@ import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; +import org.wso2.carbon.device.mgt.core.dto.DeviceType; import java.util.ArrayList; import java.util.List; @@ -109,17 +110,19 @@ public class DeviceManagerImpl implements DeviceManager { List devicesList = new ArrayList(); try { Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(type); - List devices = - this.getDeviceDAO().getDevices(deviceTypeId); + List devices = + this.getDeviceDAO().getDevices(deviceTypeId); for (org.wso2.carbon.device.mgt.core.dto.Device device : devices) { - Device convertedDevice = DeviceManagementDAOUtil.convertDevice(device); - DeviceIdentifier deviceIdentifier = DeviceManagementDAOUtil - .createDeviceIdentifier(device, this.deviceTypeDAO - .getDeviceType(device.getDeviceTypeId())); + DeviceType deviceType = this.deviceTypeDAO.getDeviceType(device.getDeviceTypeId()); + Device convertedDevice = DeviceManagementDAOUtil.convertDevice(device, deviceType); + DeviceIdentifier deviceIdentifier = + DeviceManagementDAOUtil.createDeviceIdentifier(device, deviceType); Device dmsDevice = dms.getDevice(deviceIdentifier); - convertedDevice.setProperties(dmsDevice.getProperties()); - convertedDevice.setFeatures(dmsDevice.getFeatures()); + if (dmsDevice != null) { + convertedDevice.setProperties(dmsDevice.getProperties()); + convertedDevice.setFeatures(dmsDevice.getFeatures()); + } devicesList.add(convertedDevice); } } catch (DeviceManagementDAOException e) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java index 951d33dae9..fdc3df4d2a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java @@ -34,9 +34,7 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; import java.util.Hashtable; -import java.util.List; public final class DeviceManagementDAOUtil { @@ -107,9 +105,10 @@ public final class DeviceManagementDAOUtil { /** * @param device - The DTO device object. + * @param deviceType - The DeviceType object associated with the device * @return A Business Object. */ - public static org.wso2.carbon.device.mgt.common.Device convertDevice(Device device){ + public static org.wso2.carbon.device.mgt.common.Device convertDevice(Device device, DeviceType deviceType){ org.wso2.carbon.device.mgt.common.Device deviceBO = new org.wso2.carbon.device.mgt.common.Device(); deviceBO.setDateOfEnrolment(device.getDateOfEnrollment()); @@ -117,6 +116,7 @@ public final class DeviceManagementDAOUtil { deviceBO.setDescription(device.getDescription()); deviceBO.setDeviceIdentifier(device.getDeviceIdentificationId()); deviceBO.setDeviceTypeId(device.getDeviceTypeId()); + deviceBO.setType(deviceType.getName()); deviceBO.setName(device.getName()); deviceBO.setId(device.getId()); deviceBO.setOwner(device.getOwnerId()); @@ -126,21 +126,7 @@ public final class DeviceManagementDAOUtil { } else if (device.getStatus() == Status.INACTIVE) { deviceBO.setStatus(false); } - return null; - } - - /** - * @param devices - DTO Device Object list. - * @return converted Business Object list. - */ - public static List convertDevices( - List devices) { - List deviceBOList = - new ArrayList(); - for (Device device : devices) { - deviceBOList.add(convertDevice(device)); - } - return deviceBOList; + return deviceBO; } public static Device convertDevice(org.wso2.carbon.device.mgt.common.Device diff --git a/product/modules/distribution/src/repository/jaggeryapps/cdm/api/mobile/device-api.jag b/product/modules/distribution/src/repository/jaggeryapps/cdm/api/mobile/device-api.jag new file mode 100644 index 0000000000..10f37dc405 --- /dev/null +++ b/product/modules/distribution/src/repository/jaggeryapps/cdm/api/mobile/device-api.jag @@ -0,0 +1,38 @@ +<% +/* + * Copyright (c) 2015, 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 utility = require("/modules/utility.js"); +var deviceManagementService = utility.getDeviceManagementService(); +var devices = deviceManagementService.getAllDevices("android"); +var logger = new Log(); +var deviceList = []; +for (i = 0; i < devices.size(); i++) { + var device = devices.get(i); + deviceList.push({ + "identifier": device.getDeviceIdentifier(), + "name": device.getName(), + "ownership": device.getOwnership(), + "owner": device.getOwner(), + "deviceType": device.getType(), + "vendor": device.getProperties().get("vendor"), + "model": device.getProperties().get("model"), + "osVersion": device.getProperties().get("osVersion") + }); +} +print(deviceList); +%> \ No newline at end of file diff --git a/product/modules/distribution/src/repository/jaggeryapps/cdm/init.js b/product/modules/distribution/src/repository/jaggeryapps/cdm/init.js index 27d9cf25ce..859dd1037f 100644 --- a/product/modules/distribution/src/repository/jaggeryapps/cdm/init.js +++ b/product/modules/distribution/src/repository/jaggeryapps/cdm/init.js @@ -1 +1,32 @@ -//Init js to execute \ No newline at end of file +/* + * Copyright (c) 2015, 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. + */ +//Init js to execute +var logger = new Log(); +logger.debug("running debug"); +var app_TENANT_CONFIGS = 'tenant.configs'; +var app_carbon = require('carbon'); +var app_configs = { + "HTTPS_URL": "https://localhost:9443" +}; + +var app_server = new app_carbon.server.Server({ + tenanted: app_configs.tenanted, + url: app_configs.HTTPS_URL + '/admin' +}); +application.put("SERVER", app_server); +application.put(app_TENANT_CONFIGS, {}); diff --git a/product/modules/distribution/src/repository/jaggeryapps/cdm/jaggery.conf b/product/modules/distribution/src/repository/jaggeryapps/cdm/jaggery.conf index 3012d60828..efc8b12576 100644 --- a/product/modules/distribution/src/repository/jaggeryapps/cdm/jaggery.conf +++ b/product/modules/distribution/src/repository/jaggeryapps/cdm/jaggery.conf @@ -1,6 +1,6 @@ { "welcomeFiles": ["pages/dashboard.jag"], - "initScripts": ["init.js"], + "initScripts": ["/init.js"], "urlMappings": [ { "url": "/devices/*", @@ -9,12 +9,16 @@ { "url": "/dashboard", "path": "/pages/dashboard.jag" + }, + { + "url": "/api/devices/mobile/*", + "path": "/api/mobile/device-api.jag" } ], "errorPages": { "500": "/error500.jag", "404": "/error404.jag", - "403": "/error403.jag" + "403": "/error403.jag " }, - "logLevel": "info" + "logLevel": "debug" } \ No newline at end of file diff --git a/product/modules/distribution/src/repository/jaggeryapps/cdm/modules/utility.js b/product/modules/distribution/src/repository/jaggeryapps/cdm/modules/utility.js new file mode 100644 index 0000000000..47b8862bfe --- /dev/null +++ b/product/modules/distribution/src/repository/jaggeryapps/cdm/modules/utility.js @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2015, 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. + */ + +//temporary + +var PrivilegedCarbonContext = Packages.org.wso2.carbon.context.PrivilegedCarbonContext, + Class = java.lang.Class; + +osgiService = function (clazz) { + return PrivilegedCarbonContext.getThreadLocalCarbonContext().getOSGiService(Class.forName(clazz)); +}; +var getDeviceManagementService= function(){ + //server.authenticate("admin", "admin"); + var realmService = osgiService('org.wso2.carbon.device.mgt.core.service.DeviceManagementService'); + //var realmService = null; + return realmService; +} diff --git a/product/modules/distribution/src/repository/jaggeryapps/cdm/pages/dashboard.jag b/product/modules/distribution/src/repository/jaggeryapps/cdm/pages/dashboard.jag index 7231b35304..46c5cd3dad 100644 --- a/product/modules/distribution/src/repository/jaggeryapps/cdm/pages/dashboard.jag +++ b/product/modules/distribution/src/repository/jaggeryapps/cdm/pages/dashboard.jag @@ -1,5 +1,22 @@ -<% +<% +/* + * Copyright (c) 2015, 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 title="WSO2 CDM"; %> @@ -31,7 +48,7 @@ var title="WSO2 CDM";
- +
@@ -39,7 +56,7 @@ var title="WSO2 CDM"; - + diff --git a/product/modules/distribution/src/repository/jaggeryapps/cdm/pages/device.jag b/product/modules/distribution/src/repository/jaggeryapps/cdm/pages/device.jag index e4930c190f..3005b915cd 100644 --- a/product/modules/distribution/src/repository/jaggeryapps/cdm/pages/device.jag +++ b/product/modules/distribution/src/repository/jaggeryapps/cdm/pages/device.jag @@ -1,5 +1,22 @@ -<% +<% +/* + * Copyright (c) 2015, 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 title="WSO2 CDM"; %>
Name Owner OwnershipDevice TypeDevice Type Vendor Model OS Version