diff --git a/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/pom.xml b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/pom.xml new file mode 100644 index 0000000000..08e244b9af --- /dev/null +++ b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/pom.xml @@ -0,0 +1,198 @@ + + + + device-mgt-iot-androidsense + org.wso2.carbon.devicemgt-plugins + 1.9.2-SNAPSHOT + ../pom.xml + + + 4.0.0 + org.wso2.carbon.device.mgt.iot.androidsense.api + 1.9.2-SNAPSHOT + war + WSO2 Carbon - Android Sense API + WSO2 Carbon - Android Sense Service API Implementation + http://wso2.org + + + + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.common + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.core + provided + + + org.apache.axis2.wso2 + axis2-client + + + + + + + org.apache.cxf + cxf-rt-frontend-jaxws + provided + + + org.apache.cxf + cxf-rt-frontend-jaxrs + provided + + + org.apache.cxf + cxf-rt-transports-http + provided + + + + org.eclipse.paho + mqtt-client + + + + + org.apache.httpcomponents + httpasyncclient + 4.1 + provided + + + org.wso2.carbon.devicemgt-plugins + org.wso2.carbon.device.mgt.iot + provided + + + org.wso2.carbon.devicemgt-plugins + org.wso2.carbon.device.mgt.iot.androidsense + provided + + + + org.codehaus.jackson + jackson-core-asl + provided + + + org.codehaus.jackson + jackson-jaxrs + provided + + + javax + javaee-web-api + provided + + + javax.ws.rs + jsr311-api + provided + + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.analytics + provided + + + + commons-httpclient.wso2 + commons-httpclient + provided + + + + org.wso2.carbon + org.wso2.carbon.utils + provided + + + org.bouncycastle.wso2 + bcprov-jdk15on + + + org.wso2.carbon + org.wso2.carbon.user.api + + + org.wso2.carbon + org.wso2.carbon.queuing + + + org.wso2.carbon + org.wso2.carbon.base + + + org.apache.axis2.wso2 + axis2 + + + org.igniterealtime.smack.wso2 + smack + + + org.igniterealtime.smack.wso2 + smackx + + + jaxen + jaxen + + + commons-fileupload.wso2 + commons-fileupload + + + org.apache.ant.wso2 + ant + + + org.apache.ant.wso2 + ant + + + commons-httpclient.wso2 + commons-httpclient + + + org.eclipse.equinox + javax.servlet + + + org.wso2.carbon + org.wso2.carbon.registry.api + + + + + + + + + + maven-compiler-plugin + + UTF-8 + ${wso2.maven.compiler.source} + ${wso2.maven.compiler.target} + + + + maven-war-plugin + + android_sense + + + + + + diff --git a/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseService.java b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseService.java new file mode 100644 index 0000000000..e5045e69ea --- /dev/null +++ b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/AndroidSenseService.java @@ -0,0 +1,396 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) 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. + */ + +package org.wso2.carbon.device.mgt.iot.androidsense.service.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.analytics.exception.DataPublisherConfigurationException; +import org.wso2.carbon.device.mgt.analytics.service.DeviceAnalyticsService; +import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.EnrolmentInfo; +import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.DeviceJSON; +import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.SensorJSON; +import org.wso2.carbon.device.mgt.iot.DeviceManagement; +import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException; +import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager; +import org.wso2.carbon.device.mgt.iot.sensormgt.SensorRecord; +import org.wso2.carbon.device.mgt.iot.androidsense.plugin.constants.AndroidSenseConstants; + +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.*; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.util.Date; + +public class AndroidSenseService { + + private static final String BATTERY_STREAM_DEFINITION = "org.wso2.iot.devices.battery"; + private static final String LIGHT_STREAM_DEFINITION = "org.wso2.iot.devices.light"; + private static final String GPS_STREAM_DEFINITION = "org.wso2.iot.devices.gps"; + private static final String MAGNETIC_STREAM_DEFINITION = "org.wso2.iot.devices.magnetic"; + + /*Definetions for other sensor types. + * Accelerometer + * Gyroscope + * Pressure + * Proximity + * Gravity + * Rotation Vector + * */ + + private static final String ACCELEROMETER_STREAM_DEFINITION = "org.wso2.iot.devices.accelerometer"; + private static final String GYROSCOPE_STREAM_DEFINITION = "org.wso2.iot.devices.gyroscope"; + private static final String PRESSURE_STREAM_DEFINITION = "org.wso2.iot.devices.pressure"; + private static final String GRAVITY_STREAM_DEFINITION = "org.wso2.iot.devices.gravity"; + private static final String ROTATION_STREAM_DEFINITION = "org.wso2.iot.devices.rotation"; + + private static final String SENSOR_ACCELEROMETER = "accelerometer"; + private static final String SENSOR_GYROSCOPE = "gyroscope"; + private static final String SENSOR_PRESSURE = "pressure"; + private static final String SENSOR_GRVITY = "gravity"; + private static final String SENSOR_ROTATION = "rotation"; + private static final String SENSOR_LIGHT = "light"; + private static final String SENSOR_GPS = "gps"; + + ///////////////////////////////////////////////////////////////////////////////////////////// + private static final String SENSOR_BATTERY = "battery"; + private static final String SENSOR_MAGNETIC = "magnetic"; + private static Log log = LogFactory.getLog(AndroidSenseService.class); + + //TODO; replace this tenant domain + private final String SUPER_TENANT = "carbon.super"; + + @Context //injected response proxy supporting multiple thread + private HttpServletResponse response; + + @Path("manager/device") @PUT public boolean register(@FormParam("deviceId") String deviceId, + @FormParam("owner") String owner) { + + DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT); + + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId); + deviceIdentifier.setType(AndroidSenseConstants.DEVICE_TYPE); + try { + if (deviceManagement.getDeviceManagementService().isEnrolled(deviceIdentifier)) { + response.setStatus(Response.Status.CONFLICT.getStatusCode()); + return true; + } + Device device = new Device(); + device.setDeviceIdentifier(deviceId); + EnrolmentInfo enrolmentInfo = new EnrolmentInfo(); + + enrolmentInfo.setDateOfEnrolment(new Date().getTime()); + enrolmentInfo.setDateOfLastUpdate(new Date().getTime()); + enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE); + enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD); + String name = owner + " android " + deviceId; + device.setName(name); + device.setType(AndroidSenseConstants.DEVICE_TYPE); + enrolmentInfo.setOwner(owner); + device.setEnrolmentInfo(enrolmentInfo); + boolean added = deviceManagement.getDeviceManagementService().enrollDevice(device); + + if (added) { + response.setStatus(Response.Status.OK.getStatusCode()); + } else { + response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); + } + + return added; + } catch (DeviceManagementException e) { + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + return false; + } finally { + deviceManagement.endTenantFlow(); + } + } + + @Path("manager/device/remove/{device_id}") @DELETE public void removeDevice(@PathParam("device_id") String deviceId, + @Context HttpServletResponse response) { + + DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT); + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId); + deviceIdentifier.setType(AndroidSenseConstants.DEVICE_TYPE); + try { + boolean removed = deviceManagement.getDeviceManagementService().disenrollDevice(deviceIdentifier); + if (removed) { + response.setStatus(Response.Status.OK.getStatusCode()); + + } else { + response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); + + } + } catch (DeviceManagementException e) { + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + } finally { + deviceManagement.endTenantFlow(); + } + + } + + @Path("manager/device/update/{device_id}") @POST + public boolean updateDevice(@PathParam("device_id") String deviceId, + @QueryParam("name") String name, + @Context HttpServletResponse response) { + + DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT); + + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId); + deviceIdentifier.setType(AndroidSenseConstants.DEVICE_TYPE); + try { + Device device = deviceManagement.getDeviceManagementService().getDevice(deviceIdentifier); + device.setDeviceIdentifier(deviceId); + + // device.setDeviceTypeId(deviceTypeId); + device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime()); + + device.setName(name); + device.setType(AndroidSenseConstants.DEVICE_TYPE); + + boolean updated = deviceManagement.getDeviceManagementService().modifyEnrollment(device); + + if (updated) { + response.setStatus(Response.Status.OK.getStatusCode()); + + } else { + response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); + + } + return updated; + } catch (DeviceManagementException e) { + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + return false; + } finally { + deviceManagement.endTenantFlow(); + } + + } + + @Path("manager/device/{device_id}") @GET @Consumes("application/json") @Produces("application/json") public Device getDevice( + @PathParam("device_id") String deviceId) { + + DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT); + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId); + deviceIdentifier.setType(AndroidSenseConstants.DEVICE_TYPE); + + try { + return deviceManagement.getDeviceManagementService().getDevice(deviceIdentifier); + + } catch (DeviceManagementException e) { + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + return null; + } finally { + deviceManagement.endTenantFlow(); + } + + } + + /* Service to push all the sensor data collected by the Android + Called by the Android device */ + @Path("controller/sensordata") @POST @Consumes(MediaType.APPLICATION_JSON) + public void pushSensorData(final DeviceJSON dataMsg, @Context HttpServletResponse response) { + + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + ctx.setTenantDomain("carbon.super", true); + DeviceAnalyticsService deviceAnalyticsService = (DeviceAnalyticsService) ctx + .getOSGiService(DeviceAnalyticsService.class, null); + + SensorJSON[] sensorData = dataMsg.values; + String streamDef = null; + Object payloadData[] = null; + String sensorName = null; + + for (SensorJSON sensor : sensorData) { + switch (sensor.key) { + case "battery": + streamDef = BATTERY_STREAM_DEFINITION; + payloadData = new Object[] { Float.parseFloat(sensor.value) }; + sensorName = SENSOR_BATTERY; + break; + case "GPS": + streamDef = GPS_STREAM_DEFINITION; + String gpsValue = sensor.value; + String gpsValues[] = gpsValue.split(","); + Float gpsValuesF[] = new Float[2]; + gpsValuesF[0] = Float.parseFloat(gpsValues[0]); + gpsValuesF[1] = Float.parseFloat(gpsValues[0]); + payloadData = gpsValuesF; + sensorName = SENSOR_GPS; + break; + default: + try { + int androidSensorId = Integer.parseInt(sensor.key); + + if (androidSensorId == 2) { + streamDef = MAGNETIC_STREAM_DEFINITION; + String value = sensor.value; + String valuesM[] = value.split(","); + Float gValuesF[] = new Float[1]; + gValuesF[0] = Float.parseFloat(valuesM[0]) * Float.parseFloat(valuesM[0]) * Float + .parseFloat(valuesM[0]); + payloadData = gValuesF; + sensorName = SENSOR_MAGNETIC; + } else if (androidSensorId == 5) { + streamDef = LIGHT_STREAM_DEFINITION; + sensorName = SENSOR_LIGHT; + payloadData = new Object[] { Float.parseFloat(sensor.value) }; + }else if(androidSensorId == 1){ + streamDef = ACCELEROMETER_STREAM_DEFINITION; + String value = sensor.value; + String valuesM[] = value.split(","); + Float gValuesF[] = new Float[1]; + gValuesF[0] = Float.parseFloat(valuesM[0]) * Float.parseFloat(valuesM[0]) * Float + .parseFloat(valuesM[0]); + payloadData = gValuesF; + sensorName = SENSOR_ACCELEROMETER; + } + //Add the remaining sensor types. + + } catch (NumberFormatException e) { + continue; + } + + } + Object metdaData[] = { dataMsg.owner, AndroidSenseConstants.DEVICE_TYPE, dataMsg.deviceId, sensor.time }; + + if (streamDef != null && payloadData != null && payloadData.length > 0) { + try { + SensorDataManager.getInstance() + .setSensorRecord(dataMsg.deviceId, sensorName, sensor.value, sensor.time); + deviceAnalyticsService.publishEvent(streamDef, "1.0.0", metdaData, new Object[0], payloadData); + } catch (DataPublisherConfigurationException e) { + response.setStatus(Response.Status.UNSUPPORTED_MEDIA_TYPE.getStatusCode()); + } + } + + } + + } + + //TODO below endpoints needs to be removed and cep websocket have to be added + @Path("controller/readlight") + @GET + @Consumes("application/json") + @Produces("application/json") + public SensorRecord readLight( + @HeaderParam("owner") String owner, @HeaderParam("deviceId") String deviceId, + @Context HttpServletResponse response) { + SensorRecord sensorRecord = null; + + try { + sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, SENSOR_LIGHT); + } catch (DeviceControllerException e) { + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + } + + response.setStatus(Response.Status.OK.getStatusCode()); + return sensorRecord; + } + + @Path("controller/readbattery") + @GET + @Consumes("application/json") + @Produces("application/json") + public SensorRecord readBattery( + @HeaderParam("owner") String owner, @HeaderParam("deviceId") String deviceId, + @Context HttpServletResponse response) { + SensorRecord sensorRecord = null; + + try { + sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, SENSOR_BATTERY); + } catch (DeviceControllerException e) { + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + } + + response.setStatus(Response.Status.OK.getStatusCode()); + return sensorRecord; + } + + @Path("controller/readgps") + @GET + @Consumes("application/json") + @Produces("application/json") + public SensorRecord readGPS( + @HeaderParam("owner") String owner, @HeaderParam("deviceId") String deviceId, + @Context HttpServletResponse response) { + SensorRecord sensorRecord = null; + + try { + sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, SENSOR_GPS); + } catch (DeviceControllerException e) { + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + } + + response.setStatus(Response.Status.OK.getStatusCode()); + return sensorRecord; + } + + + @Path("controller/readmagnetic") + @GET + @Consumes("application/json") + @Produces("application/json") + public SensorRecord readMagnetic(@HeaderParam("owner") String owner, + @HeaderParam("deviceId") String deviceId, + @Context HttpServletResponse response) { + SensorRecord sensorRecord = null; + + try { + sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, SENSOR_MAGNETIC); + } catch (DeviceControllerException e) { + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + } + + response.setStatus(Response.Status.OK.getStatusCode()); + return sensorRecord; + } + + /** + * Created by Menaka + * Adding Accelerometer + * */ + + @Path("controller/readaccelerometer") + @GET + @Consumes("application/json") + @Produces("application/json") + public SensorRecord readAccelerometer(@HeaderParam("owner") String owner, + @HeaderParam("deviceId") String deviceId, + @Context HttpServletResponse response) { + SensorRecord sensorRecord = null; + + try { + sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, SENSOR_ACCELEROMETER); + } catch (DeviceControllerException e) { + response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); + } + + response.setStatus(Response.Status.OK.getStatusCode()); + return sensorRecord; + } + + +} diff --git a/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/util/DeviceJSON.java b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/util/DeviceJSON.java new file mode 100644 index 0000000000..0c7c13d821 --- /dev/null +++ b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/util/DeviceJSON.java @@ -0,0 +1,15 @@ +package org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util; + +import org.codehaus.jackson.annotate.JsonIgnoreProperties; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement + +@JsonIgnoreProperties(ignoreUnknown = true) +public class DeviceJSON { + @XmlElement(required = true) public String owner; + @XmlElement(required = true) public String deviceId; + @XmlElement public SensorJSON[] values; +} diff --git a/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/util/SensorJSON.java b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/util/SensorJSON.java new file mode 100644 index 0000000000..70c7f7cf3b --- /dev/null +++ b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/service/impl/util/SensorJSON.java @@ -0,0 +1,16 @@ +package org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util; + +import org.codehaus.jackson.annotate.JsonIgnoreProperties; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement + +@JsonIgnoreProperties(ignoreUnknown = true) +public class SensorJSON { + + @XmlElement public Long time; + @XmlElement public String key; + @XmlElement public String value; +} diff --git a/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/webapp/META-INF/resources.xml b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/webapp/META-INF/resources.xml new file mode 100644 index 0000000000..fda8f3253c --- /dev/null +++ b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/webapp/META-INF/resources.xml @@ -0,0 +1,93 @@ + + + + + + + + + Any + PUT + http://localhost:9763/android_sense/manager/device/register + /manager/device/register/* + + + Any + DELETE + http://localhost:9763/android_sense/manager/device/remove + /manager/device/remove/* + + + Any + POST + http://localhost:9763/android_sense/manager/device/update + /manager/device/update/* + + + Any + GET + http://localhost:9763/android_sense/manager/device/{device_id} + /manager/device/{device_id} + + + Any + GET + http://localhost:9763/android_sense/controller/sensordata + /controller/sensordata + + + Any + GET + http://localhost:9763/android_sense/controller/readbattery + /controller/readbattery + + + Any + GET + http://localhost:9763/android_sense/controller/readlight + /controller/readlight + + + Any + GET + http://localhost:9763/android_sense/controller/readgps + /controller/readgps + + + Any + GET + http://localhost:9763/android_sense/controller/readmagnetic + /controller/readmagnetic + + + Any + GET + http://localhost:9763/android_sense/controller/readaccelerometer + /controller/readaccelerometer + + diff --git a/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/webapp/META-INF/webapp-classloading.xml b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/webapp/META-INF/webapp-classloading.xml new file mode 100644 index 0000000000..fa44619195 --- /dev/null +++ b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/webapp/META-INF/webapp-classloading.xml @@ -0,0 +1,33 @@ + + + + + + + + + false + + + CXF,Carbon + diff --git a/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/webapp/WEB-INF/cxf-servlet.xml new file mode 100644 index 0000000000..8b00045b87 --- /dev/null +++ b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + diff --git a/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/webapp/WEB-INF/web.xml b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..5227008858 --- /dev/null +++ b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense.api/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,73 @@ + + + Android Sense + Android Sense + + + CXFServlet + org.apache.cxf.transport.servlet.CXFServlet + 1 + + + + + CXFServlet + /* + + + + isAdminService + false + + + doAuthentication + false + + + + + managed-api-enabled + true + + + managed-api-owner + admin + + + managed-api-name + android_sense + + + managed-api-endpoint + http://localhost:9763/android_sense + + + managed-api-version + 1.0.0 + + + managed-api-context + /android_sense + + + managed-api-isSecured + true + + + + + + + + + + + + + + + diff --git a/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense/pom.xml b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense/pom.xml new file mode 100644 index 0000000000..a0d9ebaa48 --- /dev/null +++ b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense/pom.xml @@ -0,0 +1,117 @@ + + + + + + + device-mgt-iot-androidsense + org.wso2.carbon.devicemgt-plugins + 1.9.2-SNAPSHOT + ../pom.xml + + + 4.0.0 + org.wso2.carbon.device.mgt.iot.androidsense + ${carbon.iot.device.mgt.version} + bundle + WSO2 Carbon - Android Sense Management Impl + WSO2 Carbon - Android Sense Management and Control Implementation + http://wso2.org + + + + + org.apache.felix + maven-scr-plugin + + + maven-compiler-plugin + + 1.7 + 1.7 + + 2.3.2 + + + org.apache.felix + maven-bundle-plugin + 1.4.0 + true + + + ${project.artifactId} + ${project.artifactId} + ${carbon.iot.device.mgt.version} + IoT Server Impl Bundle + org.wso2.carbon.device.mgt.iot.androidsense.plugin.internal + + org.osgi.framework, + org.osgi.service.component, + org.apache.commons.logging, + javax.xml.bind.*, + javax.naming, + javax.sql, + javax.xml.bind.annotation.*, + javax.xml.parsers, + javax.net, + javax.net.ssl, + org.w3c.dom, + org.wso2.carbon.device.mgt.common.*, + org.wso2.carbon.device.mgt.common, + org.wso2.carbon.context.*, + org.wso2.carbon.ndatasource.core, + org.wso2.carbon.device.mgt.iot.*, + + + + !org.wso2.carbon.device.mgt.iot.androidsense.plugin.internal, + org.wso2.carbon.device.mgt.iot.androidsense.plugin.* + + + + + + + + + + org.eclipse.osgi + org.eclipse.osgi + + + org.eclipse.osgi + org.eclipse.osgi.services + + + + org.wso2.carbon + org.wso2.carbon.logging + + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.common + + + org.wso2.carbon + org.wso2.carbon.ndatasource.core + + + + org.wso2.carbon.devicemgt-plugins + org.wso2.carbon.device.mgt.iot + + + + + + \ No newline at end of file diff --git a/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/constants/AndroidSenseConstants.java b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/constants/AndroidSenseConstants.java new file mode 100644 index 0000000000..1c69899756 --- /dev/null +++ b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/constants/AndroidSenseConstants.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) 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. + */ + +package org.wso2.carbon.device.mgt.iot.androidsense.plugin.constants; + +public class AndroidSenseConstants { + + public final static String DEVICE_TYPE = "android_sense"; + public final static String DEVICE_PLUGIN_DEVICE_NAME = "DEVICE_NAME"; + public final static String DEVICE_PLUGIN_DEVICE_ID = "ANDROID_DEVICE_ID"; + +} diff --git a/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/AndroidSenseManager.java b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/AndroidSenseManager.java new file mode 100644 index 0000000000..01a7ddde35 --- /dev/null +++ b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/AndroidSenseManager.java @@ -0,0 +1,279 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) 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. + */ + +package org.wso2.carbon.device.mgt.iot.androidsense.plugin.impl; + + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.DeviceManager; +import org.wso2.carbon.device.mgt.common.EnrolmentInfo; +import org.wso2.carbon.device.mgt.common.FeatureManager; +import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration; +import org.wso2.carbon.device.mgt.common.license.mgt.License; +import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; +import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceManagementDAOException; +import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceManagementDAOFactory; +import org.wso2.carbon.device.mgt.iot.util.iotdevice.dto.IotDevice; +import org.wso2.carbon.device.mgt.iot.util.iotdevice.util.IotDeviceManagementUtil; +import org.wso2.carbon.device.mgt.iot.androidsense.plugin.impl.dao.AndroidSenseDAO; + + +import java.util.ArrayList; +import java.util.List; + + +/** + * This represents the Android implementation of DeviceManagerService. + */ +public class AndroidSenseManager implements DeviceManager { + + private static final IotDeviceManagementDAOFactory iotDeviceManagementDAOFactory = new AndroidSenseDAO(); + private static final Log log = LogFactory.getLog(AndroidSenseManager.class); + + + @Override + public FeatureManager getFeatureManager() { + return null; + } + + @Override + public boolean saveConfiguration(TenantConfiguration tenantConfiguration) + throws DeviceManagementException { + //TODO implement this + return false; + } + + @Override + public TenantConfiguration getConfiguration() throws DeviceManagementException { + //TODO implement this + return null; + } + + @Override + public boolean enrollDevice(Device device) throws DeviceManagementException { + boolean status; + IotDevice iotDevice = IotDeviceManagementUtil.convertToIotDevice(device); + try { + if (log.isDebugEnabled()) { + log.debug("Enrolling a new Android device : " + device.getDeviceIdentifier()); + } + AndroidSenseDAO.beginTransaction(); + status = iotDeviceManagementDAOFactory.getIotDeviceDAO().addIotDevice( + iotDevice); + AndroidSenseDAO.commitTransaction(); + } catch (IotDeviceManagementDAOException e) { + try { + AndroidSenseDAO.rollbackTransaction(); + } catch (IotDeviceManagementDAOException iotDAOEx) { + String msg = "Error occurred while roll back the device enrol transaction :" + device.toString(); + log.warn(msg, iotDAOEx); + } + String msg = "Error while enrolling the Android device : " + device.getDeviceIdentifier(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return status; + } + + @Override + public boolean modifyEnrollment(Device device) throws DeviceManagementException { + boolean status; + IotDevice iotDevice = IotDeviceManagementUtil.convertToIotDevice(device); + try { + if (log.isDebugEnabled()) { + log.debug("Modifying the Android device enrollment data"); + } + AndroidSenseDAO.beginTransaction(); + status = iotDeviceManagementDAOFactory.getIotDeviceDAO() + .updateIotDevice(iotDevice); + AndroidSenseDAO.commitTransaction(); + } catch (IotDeviceManagementDAOException e) { + try { + AndroidSenseDAO.rollbackTransaction(); + } catch (IotDeviceManagementDAOException iotDAOEx) { + String msg = "Error occurred while roll back the update device transaction :" + device.toString(); + log.warn(msg, iotDAOEx); + } + String msg = "Error while updating the enrollment of the Android device : " + + device.getDeviceIdentifier(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return status; + } + + @Override + public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + boolean status; + try { + if (log.isDebugEnabled()) { + log.debug("Dis-enrolling Android device : " + deviceId); + } + AndroidSenseDAO.beginTransaction(); + status = iotDeviceManagementDAOFactory.getIotDeviceDAO() + .deleteIotDevice(deviceId.getId()); + AndroidSenseDAO.commitTransaction(); + } catch (IotDeviceManagementDAOException e) { + try { + AndroidSenseDAO.rollbackTransaction(); + } catch (IotDeviceManagementDAOException iotDAOEx) { + String msg = "Error occurred while roll back the device dis enrol transaction :" + deviceId.toString(); + log.warn(msg, iotDAOEx); + } + String msg = "Error while removing the Android device : " + deviceId.getId(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return status; + } + + @Override + public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException { + boolean isEnrolled = false; + try { + if (log.isDebugEnabled()) { + log.debug("Checking the enrollment of Android device : " + deviceId.getId()); + } + IotDevice iotDevice = + iotDeviceManagementDAOFactory.getIotDeviceDAO().getIotDevice( + deviceId.getId()); + if (iotDevice != null) { + isEnrolled = true; + } + } catch (IotDeviceManagementDAOException e) { + String msg = "Error while checking the enrollment status of Android device : " + + deviceId.getId(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return isEnrolled; + } + + @Override + public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { + return true; + } + + @Override + public boolean setActive(DeviceIdentifier deviceId, boolean status) + throws DeviceManagementException { + return true; + } + + @Override + public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + Device device; + try { + if (log.isDebugEnabled()) { + log.debug("Getting the details of Android device : " + deviceId.getId()); + } + IotDevice iotDevice = iotDeviceManagementDAOFactory.getIotDeviceDAO(). + getIotDevice(deviceId.getId()); + device = IotDeviceManagementUtil.convertToDevice(iotDevice); + } catch (IotDeviceManagementDAOException e) { + String msg = "Error while fetching the Android device : " + deviceId.getId(); + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return device; + } + + @Override + public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) + throws DeviceManagementException { + return true; + } + + public boolean isClaimable(DeviceIdentifier deviceIdentifier) throws DeviceManagementException { + return false; + } + + @Override + public boolean setStatus(DeviceIdentifier deviceId, String currentOwner, + EnrolmentInfo.Status status) throws DeviceManagementException { + return false; + } + + @Override + public License getLicense(String s) throws LicenseManagementException { + return null; + } + + @Override + public void addLicense(License license) throws LicenseManagementException { + + } + + @Override public boolean requireDeviceAuthorization() { + return false; + } + + @Override + public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException { + boolean status; + IotDevice iotDevice = IotDeviceManagementUtil.convertToIotDevice(device); + try { + if (log.isDebugEnabled()) { + log.debug( + "updating the details of Android device : " + deviceIdentifier); + } + AndroidSenseDAO.beginTransaction(); + status = iotDeviceManagementDAOFactory.getIotDeviceDAO() + .updateIotDevice(iotDevice); + AndroidSenseDAO.commitTransaction(); + } catch (IotDeviceManagementDAOException e) { + try { + AndroidSenseDAO.rollbackTransaction(); + } catch (IotDeviceManagementDAOException iotDAOEx) { + String msg = "Error occurred while roll back the update device info transaction :" + device.toString(); + log.warn(msg, iotDAOEx); + } + String msg = + "Error while updating the Android device : " + deviceIdentifier; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return status; + } + + @Override + public List getAllDevices() throws DeviceManagementException { + List devices = null; + try { + if (log.isDebugEnabled()) { + log.debug("Fetching the details of all Android devices"); + } + List iotDevices = + iotDeviceManagementDAOFactory.getIotDeviceDAO().getAllIotDevices(); + if (iotDevices != null) { + devices = new ArrayList(); + for (IotDevice iotDevice : iotDevices) { + devices.add(IotDeviceManagementUtil.convertToDevice(iotDevice)); + } + } + } catch (IotDeviceManagementDAOException e) { + String msg = "Error while fetching all Android devices."; + log.error(msg, e); + throw new DeviceManagementException(msg, e); + } + return devices; + } + +} \ No newline at end of file diff --git a/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/AndroidSenseManagerService.java b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/AndroidSenseManagerService.java new file mode 100644 index 0000000000..765ddd2ee2 --- /dev/null +++ b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/AndroidSenseManagerService.java @@ -0,0 +1,90 @@ +package org.wso2.carbon.device.mgt.iot.androidsense.plugin.impl; + +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.DeviceManager; +import org.wso2.carbon.device.mgt.common.app.mgt.Application; +import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; +import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; +import org.wso2.carbon.device.mgt.iot.androidsense.plugin.constants.AndroidSenseConstants; + +import java.util.List; + +public class AndroidSenseManagerService implements DeviceManagementService { + private DeviceManager deviceManager; + @Override + public String getType() { + return AndroidSenseConstants.DEVICE_TYPE; + } + + @Override + public String getProviderTenantDomain() { + return "carbon.super"; + } + + @Override + public boolean isSharedWithAllTenants() { + return true; + } + + @Override + public String[] getSharedTenantsDomain() { + return new String[0]; + } + + @Override + public void init() throws DeviceManagementException { + this.deviceManager=new AndroidSenseManager(); + } + + @Override + public DeviceManager getDeviceManager() { + return deviceManager; + } + + @Override + public ApplicationManager getApplicationManager() { + return null; + } + + @Override public void notifyOperationToDevices(Operation operation, List list) + throws DeviceManagementException { + + } + + @Override + public Application[] getApplications(String domain, int pageNumber, int size) + throws ApplicationManagementException { + return new Application[0]; + } + + @Override + public void updateApplicationStatus(DeviceIdentifier deviceId, Application application, + String status) throws ApplicationManagementException { + + } + + @Override + public String getApplicationStatus(DeviceIdentifier deviceId, Application application) + throws ApplicationManagementException { + return null; + } + + @Override public void installApplicationForDevices(Operation operation, List list) + throws ApplicationManagementException { + + } + + @Override public void installApplicationForUsers(Operation operation, List list) + throws ApplicationManagementException { + + } + + @Override public void installApplicationForUserRoles(Operation operation, List list) + throws ApplicationManagementException { + + } + +} diff --git a/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/dao/AndroidSenseDAO.java b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/dao/AndroidSenseDAO.java new file mode 100644 index 0000000000..0d4324b156 --- /dev/null +++ b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/dao/AndroidSenseDAO.java @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) 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. + */ + +package org.wso2.carbon.device.mgt.iot.androidsense.plugin.impl.dao; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceDAO; +import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceManagementDAOException; +import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceManagementDAOFactory; +import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceManagementDAOFactoryInterface; +import org.wso2.carbon.device.mgt.iot.androidsense.plugin.constants.AndroidSenseConstants; +import org.wso2.carbon.device.mgt.iot.androidsense.plugin.impl.dao.impl.AndroidSenseDAOImpl; + + + +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.SQLException; + +public class AndroidSenseDAO extends IotDeviceManagementDAOFactory implements IotDeviceManagementDAOFactoryInterface { + + private static final Log log = LogFactory.getLog(AndroidSenseDAO.class); + static DataSource dataSource; + private static ThreadLocal currentConnection = new ThreadLocal(); + + public AndroidSenseDAO() { + initAndroidDAO(); + } + + public static void initAndroidDAO() { + dataSource = getDataSourceMap().get(AndroidSenseConstants.DEVICE_TYPE); + } + + @Override public IotDeviceDAO getIotDeviceDAO() { + return new AndroidSenseDAOImpl(); + } + + public static void beginTransaction() throws IotDeviceManagementDAOException { + try { + Connection conn = dataSource.getConnection(); + conn.setAutoCommit(false); + currentConnection.set(conn); + } catch (SQLException e) { + throw new IotDeviceManagementDAOException("Error occurred while retrieving datasource connection", e); + } + } + + public static Connection getConnection() throws IotDeviceManagementDAOException { + if (currentConnection.get() == null) { + try { + currentConnection.set(dataSource.getConnection()); + } catch (SQLException e) { + throw new IotDeviceManagementDAOException("Error occurred while retrieving data source connection", e); + } + } + return currentConnection.get(); + } + + public static void commitTransaction() throws IotDeviceManagementDAOException { + try { + Connection conn = currentConnection.get(); + if (conn != null) { + conn.commit(); + } else { + if (log.isDebugEnabled()) { + log.debug("Datasource connection associated with the current thread is null, hence commit " + + "has not been attempted"); + } + } + } catch (SQLException e) { + throw new IotDeviceManagementDAOException("Error occurred while committing the transaction", e); + } finally { + closeConnection(); + } + } + + public static void closeConnection() throws IotDeviceManagementDAOException { + + Connection con = currentConnection.get(); + if (con != null) { + try { + con.close(); + } catch (SQLException e) { + log.error("Error occurred while close the connection"); + } + } + currentConnection.remove(); + } + + public static void rollbackTransaction() throws IotDeviceManagementDAOException { + try { + Connection conn = currentConnection.get(); + if (conn != null) { + conn.rollback(); + } else { + if (log.isDebugEnabled()) { + log.debug("Datasource connection associated with the current thread is null, hence rollback " + + "has not been attempted"); + } + } + } catch (SQLException e) { + throw new IotDeviceManagementDAOException("Error occurred while rollback the transaction", e); + } finally { + closeConnection(); + } + } +} \ No newline at end of file diff --git a/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/dao/impl/AndroidSenseDAOImpl.java b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/dao/impl/AndroidSenseDAOImpl.java new file mode 100644 index 0000000000..7440dfd854 --- /dev/null +++ b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/dao/impl/AndroidSenseDAOImpl.java @@ -0,0 +1,236 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) 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. + */ + +package org.wso2.carbon.device.mgt.iot.androidsense.plugin.impl.dao.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.iot.androidsense.plugin.constants.AndroidSenseConstants; +import org.wso2.carbon.device.mgt.iot.androidsense.plugin.impl.dao.AndroidSenseDAO; +import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceDAO; +import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceManagementDAOException; +import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.util.IotDeviceManagementDAOUtil; +import org.wso2.carbon.device.mgt.iot.util.iotdevice.dto.IotDevice; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Implements IotDeviceDAO for android Devices. + */ +public class AndroidSenseDAOImpl implements IotDeviceDAO{ + + + private static final Log log = LogFactory.getLog(AndroidSenseDAOImpl.class); + + @Override + public IotDevice getIotDevice(String iotDeviceId) + throws IotDeviceManagementDAOException { + Connection conn = null; + PreparedStatement stmt = null; + IotDevice iotDevice = null; + ResultSet resultSet = null; + try { + conn = AndroidSenseDAO.getConnection(); + String selectDBQuery = + "SELECT ANDROID_DEVICE_ID, DEVICE_NAME" + + " FROM ANDROID_SENSE_DEVICE WHERE ANDROID_DEVICE_ID = ?"; + stmt = conn.prepareStatement(selectDBQuery); + stmt.setString(1, iotDeviceId); + resultSet = stmt.executeQuery(); + + if (resultSet.next()) { + iotDevice = new IotDevice(); + iotDevice.setIotDeviceName(resultSet.getString( + AndroidSenseConstants.DEVICE_PLUGIN_DEVICE_NAME)); + Map propertyMap = new HashMap(); + + + + iotDevice.setDeviceProperties(propertyMap); + + if (log.isDebugEnabled()) { + log.debug("Android device " + iotDeviceId + " data has been fetched from " + + "Android database."); + } + } + } catch (SQLException e) { + String msg = "Error occurred while fetching Android device : '" + iotDeviceId + "'"; + log.error(msg, e); + throw new IotDeviceManagementDAOException(msg, e); + } finally { + IotDeviceManagementDAOUtil.cleanupResources(stmt, resultSet); + AndroidSenseDAO.closeConnection(); + } + + return iotDevice; + } + + @Override + public boolean addIotDevice(IotDevice iotDevice) + throws IotDeviceManagementDAOException { + boolean status = false; + Connection conn = null; + PreparedStatement stmt = null; + try { + conn = AndroidSenseDAO.getConnection(); + String createDBQuery = + "INSERT INTO ANDROID_SENSE_DEVICE(ANDROID_DEVICE_ID, DEVICE_NAME) VALUES (?, ?)"; + + stmt = conn.prepareStatement(createDBQuery); + stmt.setString(1, iotDevice.getIotDeviceId()); + stmt.setString(2,iotDevice.getIotDeviceName()); + if (iotDevice.getDeviceProperties() == null) { + iotDevice.setDeviceProperties(new HashMap()); + } + + + int rows = stmt.executeUpdate(); + if (rows > 0) { + status = true; + if (log.isDebugEnabled()) { + log.debug("Android device " + iotDevice.getIotDeviceId() + " data has been" + + " added to the Android database."); + } + } + } catch (SQLException e) { + String msg = "Error occurred while adding the Android device '" + + iotDevice.getIotDeviceId() + "' to the Android db."; + log.error(msg, e); + throw new IotDeviceManagementDAOException(msg, e); + } finally { + IotDeviceManagementDAOUtil.cleanupResources(stmt, null); + } + return status; + } + + @Override + public boolean updateIotDevice(IotDevice iotDevice) + throws IotDeviceManagementDAOException { + boolean status = false; + Connection conn = null; + PreparedStatement stmt = null; + try { + conn = AndroidSenseDAO.getConnection(); + String updateDBQuery = + "UPDATE ANDROID_SENSE_DEVICE SET DEVICE_NAME = ? WHERE ANDROID_DEVICE_ID = ?"; + + stmt = conn.prepareStatement(updateDBQuery); + + if (iotDevice.getDeviceProperties() == null) { + iotDevice.setDeviceProperties(new HashMap()); + } + stmt.setString(1, iotDevice.getIotDeviceName()); + + stmt.setString(2, iotDevice.getIotDeviceId()); + int rows = stmt.executeUpdate(); + if (rows > 0) { + status = true; + if (log.isDebugEnabled()) { + log.debug("Android device " + iotDevice.getIotDeviceId() + " data has been" + + " modified."); + } + } + } catch (SQLException e) { + String msg = "Error occurred while modifying the Android device '" + + iotDevice.getIotDeviceId() + "' data."; + log.error(msg, e); + throw new IotDeviceManagementDAOException(msg, e); + } finally { + IotDeviceManagementDAOUtil.cleanupResources(stmt, null); + } + return status; + } + + @Override + public boolean deleteIotDevice(String iotDeviceId) + throws IotDeviceManagementDAOException { + boolean status = false; + Connection conn = null; + PreparedStatement stmt = null; + try { + conn = AndroidSenseDAO.getConnection(); + String deleteDBQuery = + "DELETE FROM ANDROID_SENSE_DEVICE WHERE ANDROID_DEVICE_ID = ?"; + stmt = conn.prepareStatement(deleteDBQuery); + stmt.setString(1, iotDeviceId); + int rows = stmt.executeUpdate(); + if (rows > 0) { + status = true; + if (log.isDebugEnabled()) { + log.debug("Android device " + iotDeviceId + " data has deleted" + + " from the Android database."); + } + } + } catch (SQLException e) { + String msg = "Error occurred while deleting Android device " + iotDeviceId; + log.error(msg, e); + throw new IotDeviceManagementDAOException(msg, e); + } finally { + IotDeviceManagementDAOUtil.cleanupResources(stmt, null); + } + return status; + } + + @Override + public List getAllIotDevices() + throws IotDeviceManagementDAOException { + + Connection conn = null; + PreparedStatement stmt = null; + ResultSet resultSet = null; + IotDevice iotDevice; + List iotDevices = new ArrayList(); + + try { + conn = AndroidSenseDAO.getConnection(); + String selectDBQuery = + "SELECT ANDROID_DEVICE_ID, DEVICE_NAME " + + "FROM ANDROID_SENSE_DEVICE"; + stmt = conn.prepareStatement(selectDBQuery); + resultSet = stmt.executeQuery(); + while (resultSet.next()) { + iotDevice = new IotDevice(); + iotDevice.setIotDeviceId(resultSet.getString(AndroidSenseConstants.DEVICE_PLUGIN_DEVICE_ID)); + iotDevice.setIotDeviceName(resultSet.getString(AndroidSenseConstants.DEVICE_PLUGIN_DEVICE_NAME)); + + Map propertyMap = new HashMap(); + + iotDevice.setDeviceProperties(propertyMap); + iotDevices.add(iotDevice); + } + if (log.isDebugEnabled()) { + log.debug("All Android device details have fetched from Android database."); + } + return iotDevices; + } catch (SQLException e) { + String msg = "Error occurred while fetching all Android device data'"; + log.error(msg, e); + throw new IotDeviceManagementDAOException(msg, e); + } finally { + IotDeviceManagementDAOUtil.cleanupResources(stmt, resultSet); + AndroidSenseDAO.closeConnection(); + } + + } + + } \ No newline at end of file diff --git a/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/util/AndroidSenseUtils.java b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/util/AndroidSenseUtils.java new file mode 100644 index 0000000000..3745691b53 --- /dev/null +++ b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/impl/util/AndroidSenseUtils.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) 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. + */ + +package org.wso2.carbon.device.mgt.iot.androidsense.plugin.impl.util; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.util.Map; + +/** + * Contains utility methods used by Android plugin. + */ +public class AndroidSenseUtils { + + private static Log log = LogFactory.getLog(AndroidSenseUtils.class); + + public static String getDeviceProperty(Map deviceProperties, String property) { + + String deviceProperty = deviceProperties.get(property); + + if (deviceProperty == null) { + return ""; + } + + return deviceProperty; + } + + +} diff --git a/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/internal/AndroidSenseManagementServiceComponent.java b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/internal/AndroidSenseManagementServiceComponent.java new file mode 100644 index 0000000000..fc7f3df064 --- /dev/null +++ b/components/device-mgt-iot-androidsense/org.wso2.carbon.device.mgt.iot.androidsense/src/main/java/org/wso2/carbon/device/mgt/iot/androidsense/plugin/internal/AndroidSenseManagementServiceComponent.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) 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. + */ + +package org.wso2.carbon.device.mgt.iot.androidsense.plugin.internal; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; +import org.osgi.service.component.ComponentContext; +import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; +import org.wso2.carbon.device.mgt.iot.androidsense.plugin.impl.AndroidSenseManagerService; +import org.wso2.carbon.device.mgt.iot.service.DeviceTypeService; + + + +/** + * @scr.component name="org.wso2.carbon.device.mgt.iot.android.internal.AndroidSenseManagementServiceComponent" + * immediate="true" + * @scr.reference name="wso2.carbon.device.mgt.iot.service.DeviceTypeServiceImpl" + * interface="org.wso2.carbon.device.mgt.iot.service.DeviceTypeService" + * cardinality="1..1" + * policy="dynamic" + * bind="setDeviceTypeService" + * unbind="unsetDeviceTypeService" + */ +public class AndroidSenseManagementServiceComponent { + + + private ServiceRegistration androidServiceRegRef; + + + + private static final Log log = LogFactory.getLog(AndroidSenseManagementServiceComponent.class); + protected void activate(ComponentContext ctx) { + if (log.isDebugEnabled()) { + log.debug("Activating Android Device Management Service Component"); + } + try { + BundleContext bundleContext = ctx.getBundleContext(); + + + androidServiceRegRef = + bundleContext.registerService(DeviceManagementService.class.getName(), new AndroidSenseManagerService(), null); + + + + if (log.isDebugEnabled()) { + log.debug("Android Device Management Service Component has been successfully activated"); + } + } catch (Throwable e) { + log.error("Error occurred while activating Android Device Management Service Component", e); + } + } + + protected void deactivate(ComponentContext ctx) { + if (log.isDebugEnabled()) { + log.debug("De-activating Android Device Management Service Component"); + } + try { + if (androidServiceRegRef != null) { + androidServiceRegRef.unregister(); + } + + if (log.isDebugEnabled()) { + log.debug( + "Android Device Management Service Component has been successfully de-activated"); + } + } catch (Throwable e) { + log.error("Error occurred while de-activating Android Device Management bundle", e); + } + } + + protected void setDeviceTypeService(DeviceTypeService deviceTypeService) { + /* This is to avoid this component getting initialized before the + common registered */ + if (log.isDebugEnabled()) { + log.debug("Data source service set to mobile service component"); + } + } + + protected void unsetDeviceTypeService(DeviceTypeService deviceTypeService) { + //do nothing + } + + + +} diff --git a/components/device-mgt-iot-androidsense/pom.xml b/components/device-mgt-iot-androidsense/pom.xml new file mode 100644 index 0000000000..95e0c843d0 --- /dev/null +++ b/components/device-mgt-iot-androidsense/pom.xml @@ -0,0 +1,62 @@ + + + + + + + org.wso2.carbon.devicemgt-plugins + carbon-device-mgt-plugins-parent + 1.9.2-SNAPSHOT + ../../pom.xml + + + 4.0.0 + device-mgt-iot-androidsense + 1.9.2-SNAPSHOT + pom + WSO2 Carbon - IoT Device Android Sense Management Component + http://wso2.org + + + org.wso2.carbon.device.mgt.iot.androidsense + org.wso2.carbon.device.mgt.iot.androidsense.api + + + + + + + org.apache.felix + maven-scr-plugin + 1.7.2 + + + generate-scr-scrdescriptor + + scr + + + + + + + + \ No newline at end of file diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/VirtualFireAlarmService.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/VirtualFireAlarmService.java index aa73d67db7..b51ac43202 100644 --- a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/VirtualFireAlarmService.java +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/VirtualFireAlarmService.java @@ -235,8 +235,7 @@ public class VirtualFireAlarmService { deviceIdentifier.setId(deviceId); deviceIdentifier.setType(VirtualFireAlarmConstants.DEVICE_TYPE); try { - Device device = deviceManagement.getDeviceManagementService().getDevice( - deviceIdentifier); + Device device = deviceManagement.getDeviceManagementService().getDevice(deviceIdentifier); device.setDeviceIdentifier(deviceId); // device.setDeviceTypeId(deviceTypeId); @@ -245,8 +244,7 @@ public class VirtualFireAlarmService { device.setName(name); device.setType(VirtualFireAlarmConstants.DEVICE_TYPE); - boolean updated = deviceManagement.getDeviceManagementService().modifyEnrollment( - device); + boolean updated = deviceManagement.getDeviceManagementService().modifyEnrollment(device); if (updated) { response.setStatus(Response.Status.OK.getStatusCode()); diff --git a/components/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.url.printer/src/main/java/org/wso2/carbon/device/mgt/mobile/url/printer/URLPrinterStartupHandler.java b/components/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.url.printer/src/main/java/org/wso2/carbon/device/mgt/mobile/url/printer/URLPrinterStartupHandler.java index ab9d41b14c..1eaad8ad4c 100644 --- a/components/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.url.printer/src/main/java/org/wso2/carbon/device/mgt/mobile/url/printer/URLPrinterStartupHandler.java +++ b/components/device-mgt-mdm/org.wso2.carbon.device.mgt.mobile.url.printer/src/main/java/org/wso2/carbon/device/mgt/mobile/url/printer/URLPrinterStartupHandler.java @@ -37,7 +37,7 @@ public class URLPrinterStartupHandler implements ServerStartupObserver { @Override public void completedServerStartup() { - log.info("EMM Console URL : " + this.getEmmUrl()); + log.info("Device Management Console URL : " + this.getEmmUrl()); } private String getEmmUrl() { @@ -58,7 +58,7 @@ public class URLPrinterStartupHandler implements ServerStartupObserver { if (httpsProxyPort > 0) { port = httpsProxyPort; } - return "https://" + hostName + ":" + port + "/mdm"; + return "https://" + hostName + ":" + port + "/devicemgt"; } } diff --git a/components/device-mgt-mdm/org.wso2.mdm.appmgt/pom.xml b/components/device-mgt-mdm/org.wso2.mdm.appmgt/pom.xml new file mode 100644 index 0000000000..75d2f993ba --- /dev/null +++ b/components/device-mgt-mdm/org.wso2.mdm.appmgt/pom.xml @@ -0,0 +1,125 @@ + + + + org.wso2.carbon.devicemgt-plugins + device-mgt-mdm + 1.9.2-SNAPSHOT + ../pom.xml + + + 4.0.0 + WSO2 Carbon - Mobile Device app Management Core + WSO2 Carbon - Device Management Core + http://wso2.org + org.wso2.mdm.appmgt + 1.9.2-SNAPSHOT + bundle + + + + + org.apache.felix + maven-scr-plugin + + + org.apache.felix + maven-bundle-plugin + 1.4.0 + true + + + ${project.artifactId} + ${project.artifactId} + ${project.version} + MDM Management Core Bundle + org.wso2.mdm.appmgt.internal + + org.osgi.framework, + org.osgi.service.component, + org.apache.commons.logging, + org.wso2.carbon.appmgt.mobile.*, + org.wso2.carbon.device.mgt.common, + org.wso2.carbon.device.mgt.common.operation.mgt, + org.wso2.carbon.device.mgt.core.operation.mgt, + org.wso2.mdm.mdmmgt.*, + org.wso2.carbon.device.mgt.common.app.mgt, + org.wso2.carbon.device.mgt.core.service, + org.wso2.carbon.device.mgt.core.app.mgt + + + !org.wso2.mdm.appmgt.internal, + org.wso2.mdm.appmgt.* + + + + + + + + + + + org.wso2.carbon.devicemgt-plugins + org.wso2.mdm.mdmmgt + + + org.eclipse.osgi + org.eclipse.osgi + + + org.eclipse.osgi + org.eclipse.osgi.services + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.common + + + org.wso2.carbon + org.wso2.carbon.logging + + + org.wso2.carbon + org.wso2.carbon.utils + + + org.wso2.carbon + org.wso2.carbon.core + + + org.testng + testng + + + org.wso2.carbon.appmgt + org.wso2.carbon.appmgt.mobile + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.core + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.policy.mgt.core + provided + + + + \ No newline at end of file diff --git a/components/device-mgt-mdm/org.wso2.mdm.appmgt/src/main/java/org/wso2/mdm/appmgt/internal/AppMgtMDMService.java b/components/device-mgt-mdm/org.wso2.mdm.appmgt/src/main/java/org/wso2/mdm/appmgt/internal/AppMgtMDMService.java new file mode 100644 index 0000000000..76eb72b759 --- /dev/null +++ b/components/device-mgt-mdm/org.wso2.mdm.appmgt/src/main/java/org/wso2/mdm/appmgt/internal/AppMgtMDMService.java @@ -0,0 +1,24 @@ +package org.wso2.mdm.appmgt.internal; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.osgi.framework.BundleContext; +import org.osgi.service.component.ComponentContext; +import org.wso2.carbon.appmgt.mobile.interfaces.MDMOperations; +import org.wso2.mdm.appmgt.service.MDMOperationsImpl; + +/** + * @scr.component name="org.wso2.mdm.appmgt.manager" immediate="true" + */ +public class AppMgtMDMService { + private static Log log = LogFactory.getLog(AppMgtMDMService.class); + + protected void activate(ComponentContext componentContext) { + + BundleContext bundleContext = componentContext.getBundleContext(); + bundleContext.registerService(MDMOperations.class.getName(), + new MDMOperationsImpl(), null); + + } + +} diff --git a/components/device-mgt-mdm/org.wso2.mdm.appmgt/src/main/java/org/wso2/mdm/appmgt/service/MDMOperationsImpl.java b/components/device-mgt-mdm/org.wso2.mdm.appmgt/src/main/java/org/wso2/mdm/appmgt/service/MDMOperationsImpl.java new file mode 100644 index 0000000000..279e9c3d45 --- /dev/null +++ b/components/device-mgt-mdm/org.wso2.mdm.appmgt/src/main/java/org/wso2/mdm/appmgt/service/MDMOperationsImpl.java @@ -0,0 +1,185 @@ +package org.wso2.mdm.appmgt.service; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.appmgt.mobile.interfaces.MDMOperations; +import org.wso2.carbon.appmgt.mobile.mdm.App; +import org.wso2.carbon.appmgt.mobile.mdm.Device; +import org.wso2.carbon.appmgt.mobile.utils.User; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.Platform; +import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; +import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; +import org.wso2.mdm.mdmmgt.beans.MobileApp; +import org.wso2.mdm.mdmmgt.beans.MobileAppTypes; +import org.wso2.mdm.mdmmgt.common.MDMException; +import org.wso2.mdm.mdmmgt.util.MDMAndroidOperationUtil; +import org.wso2.mdm.mdmmgt.util.MDMIOSOperationUtil; +import org.wso2.mdm.mdmmgt.util.MDMServiceAPIUtils; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Properties; + +public class MDMOperationsImpl implements MDMOperations { + + private static Log log = LogFactory.getLog(MDMOperationsImpl.class); + + @Override + public void performAction(User currentUser, String action, App app, int tenantId, String type, + String[] params, + HashMap configProperties) { + + ApplicationManager appManagerConnector; + org.wso2.carbon.device.mgt.common.operation.mgt.Operation operation = null; + + List userNameList; + List roleNameList; + List deviceIdentifiers = new ArrayList<>(); + List deviceList = null; + + if ("user".equals(type)) { + String userName = null; + for (String param : params) { + userName = param; + + try { + deviceList = MDMServiceAPIUtils.getDeviceManagementService(tenantId).getDevicesOfUser(userName); + } catch (DeviceManagementException devEx) { + String errorMsg = + "Error occurred fetch device for user " + userName + devEx.getErrorMessage() + " " + + "at app installation"; + log.error(errorMsg, devEx); + } + + for (org.wso2.carbon.device.mgt.common.Device device : deviceList) { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(device.getDeviceIdentifier()); + deviceIdentifier.setType(device.getType()); + + deviceIdentifiers.add(deviceIdentifier); + } + } + } else if ("role".equals(type)) { + String userRole; + for (String param : params) { + userRole = param; + try { + deviceList = MDMServiceAPIUtils.getDeviceManagementService(tenantId).getAllDevices(); + } catch (DeviceManagementException devMgtEx) { + String errorMsg = "Error occurred fetch device for user role " + userRole + devMgtEx + .getErrorMessage() + " " + + "at app installation"; + log.error(errorMsg, devMgtEx); + } + for (org.wso2.carbon.device.mgt.common.Device device : deviceList) { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(device.getDeviceIdentifier()); + deviceIdentifier.setType(device.getType()); + deviceIdentifiers.add(deviceIdentifier); + } + } + } else { + deviceIdentifiers = new ArrayList<>(); + DeviceIdentifier deviceIdentifier = null; + for (String param : params) { + deviceIdentifier = new DeviceIdentifier(); + String[] paramDevices = param.split("---"); + deviceIdentifier.setId(paramDevices[0]); + deviceIdentifier.setType(paramDevices[1]); + deviceIdentifiers.add(deviceIdentifier); + } + + } + MobileApp mobileApp = new MobileApp(); + mobileApp.setId(app.getId()); + mobileApp.setType(MobileAppTypes.valueOf(app.getType().toUpperCase())); + mobileApp.setAppIdentifier(app.getAppIdentifier()); + mobileApp.setIconImage(app.getIconImage()); + mobileApp.setIdentifier(app.getIdentifier()); + mobileApp.setLocation(app.getLocation()); + mobileApp.setName(app.getName()); + mobileApp.setPackageName(app.getPackageName()); + mobileApp.setPlatform(app.getPlatform()); + mobileApp.setVersion(app.getVersion()); + + Properties properties = new Properties(); + + if ("ios".equals(app.getPlatform())) { + if ("enterprise".equals(app.getType())) { + properties.put("isRemoveApp", true); + properties.put("isPreventBackup", true); + } else if ("public".equals(app.getType())) { + properties.put("iTunesId", Integer.parseInt(app.getIdentifier().toString())); + properties.put("isRemoveApp", true); + properties.put("isPreventBackup", true); + } else if ("webapp".equals(app.getType())) { + properties.put("label", app.getName()); + properties.put("isRemoveApp", true); + } + } else if ("webapp".equals(app.getPlatform())) { + properties.put("label", app.getName()); + properties.put("isRemoveApp", true); + } + mobileApp.setProperties(properties); + + try { + if (deviceIdentifiers != null) { + for (DeviceIdentifier deviceIdentifier : deviceIdentifiers) { + if (deviceIdentifier.getType().equals(Platform.android.toString())) { + if ("install".equals(action)) { + operation = MDMAndroidOperationUtil.createInstallAppOperation(mobileApp); + } else { + operation = MDMAndroidOperationUtil.createAppUninstallOperation(mobileApp); + } + } else if (deviceIdentifier.getType().equals(Platform.ios.toString())) { + if ("install".equals(action)) { + operation = MDMIOSOperationUtil.createInstallAppOperation(mobileApp); + } else { + operation = MDMIOSOperationUtil.createAppUninstallOperation(mobileApp); + } + } + MDMServiceAPIUtils.getAppManagementService(tenantId).installApplicationForDevices(operation, + deviceIdentifiers); + } + } + } catch (MDMException mdmExce) { + log.error("Error in creating operation object using app", mdmExce); + } catch (ApplicationManagementException appMgtExce) { + log.error("Error in app installation", appMgtExce); + } + } + + @Override + + public List getDevices(User currentUser, int tenantId, String type, String[] params, + String platform, + String platformVersion, boolean isSampleDevicesEnabled, + HashMap configProperties) { + + List devices = new ArrayList<>(); + Device device = null; + try { + List deviceList = + MDMServiceAPIUtils.getDeviceManagementService(tenantId).getAllDevices(); + + for (org.wso2.carbon.device.mgt.common.Device commondevice : deviceList) { + device = new Device(); + device.setId(commondevice.getDeviceIdentifier() + "---" + commondevice.getType()); + device.setName(commondevice.getName()); + device.setModel(commondevice.getName()); + device.setType("mobileDevice"); + device.setImage("/store/extensions/assets/mobileapp/resources/models/none.png"); + device.setPlatform(commondevice.getType()); + devices.add(device); + + } + + } catch (DeviceManagementException e) { + e.printStackTrace(); + } + return devices; + } +} diff --git a/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/pom.xml b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/pom.xml new file mode 100644 index 0000000000..4153f4a43c --- /dev/null +++ b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/pom.xml @@ -0,0 +1,101 @@ + + + + org.wso2.carbon.devicemgt-plugins + device-mgt-mdm + 1.9.2-SNAPSHOT + ../pom.xml + + + 4.0.0 + bundle + org.wso2.mdm.mdmmgt + 1.9.2-SNAPSHOT + + + + org.apache.cxf + cxf-rt-frontend-jaxws + + + org.apache.cxf + cxf-rt-frontend-jaxrs + + + org.apache.cxf + cxf-rt-transports-http + + + junit + junit + test + + + commons-httpclient.wso2 + commons-httpclient + provided + + + javax.ws.rs + jsr311-api + provided + + + org.wso2.carbon + org.wso2.carbon.utils + provided + + + org.wso2.carbon + org.wso2.carbon.logging + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.common + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.core + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.policy.mgt.core + provided + + + org.wso2.carbon.identity + org.wso2.carbon.identity.oauth.stub + provided + + + com.google.code.gson + gson + + + + + + org.apache.felix + maven-bundle-plugin + 1.4.0 + true + + + ${project.artifactId} + ${project.artifactId} + ${project.version} + MDM Management Components Bundle + + org.wso2.mdm.mdmmgt.* + + + + + + + \ No newline at end of file diff --git a/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/ApplicationWrapper.java b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/ApplicationWrapper.java new file mode 100644 index 0000000000..c9cde2fe16 --- /dev/null +++ b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/ApplicationWrapper.java @@ -0,0 +1,65 @@ +/* + * + * 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. + */ + +package org.wso2.mdm.mdmmgt.beans; + +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; + +import java.util.List; + +public class ApplicationWrapper { + + private List userNameList; + private List roleNameList; + private List deviceIdentifiers; + private MobileApp application; + + public MobileApp getApplication() { + return application; + } + + public void setApplication(MobileApp application) { + this.application = application; + } + + public List getUserNameList() { + return userNameList; + } + + public void setUserNameList(List userNameList) { + this.userNameList = userNameList; + } + + public List getRoleNameList() { + return roleNameList; + } + + public void setRoleNameList(List roleNameList) { + this.roleNameList = roleNameList; + } + + public List getDeviceIdentifiers() { + return deviceIdentifiers; + } + + public void setDeviceIdentifiers(List deviceIdentifiers) { + this.deviceIdentifiers = deviceIdentifiers; + } + +} diff --git a/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/MobileApp.java b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/MobileApp.java new file mode 100644 index 0000000000..f009b71469 --- /dev/null +++ b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/MobileApp.java @@ -0,0 +1,128 @@ +/* + * 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. + */ +package org.wso2.mdm.mdmmgt.beans; + +import java.util.Properties; + +/** + * This class represents the generic mobile Application information + * which is used by AppM. + */ +public class MobileApp { + + private String id; + private String name; + private MobileAppTypes type; + private String platform; + private String version; + private String identifier; + private String iconImage; + private String packageName; + private String appIdentifier; + private String location; + private Properties properties; + + public MobileAppTypes getType() { + return type; + } + + public void setType(MobileAppTypes type) { + this.type = type; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPlatform() { + return platform; + } + + public void setPlatform(String platform) { + this.platform = platform; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getIdentifier() { + return identifier; + } + + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + public String getIconImage() { + return iconImage; + } + + public void setIconImage(String iconImage) { + this.iconImage = iconImage; + } + + public String getPackageName() { + return packageName; + } + + public void setPackageName(String packageName) { + this.packageName = packageName; + } + + public String getAppIdentifier() { + return appIdentifier; + } + + public void setAppIdentifier(String appIdentifier) { + this.appIdentifier = appIdentifier; + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + + public Properties getProperties() { + return properties; + } + + public void setProperties(Properties properties) { + this.properties = properties; + } + +} diff --git a/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/MobileAppTypes.java b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/MobileAppTypes.java new file mode 100644 index 0000000000..da72bed0fc --- /dev/null +++ b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/MobileAppTypes.java @@ -0,0 +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. + */ +package org.wso2.mdm.mdmmgt.beans; + +public enum MobileAppTypes { + ENTERPRISE, WEBAPP, PUBLIC +} diff --git a/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/PolicyWrapper.java b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/PolicyWrapper.java new file mode 100644 index 0000000000..440e24ff20 --- /dev/null +++ b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/PolicyWrapper.java @@ -0,0 +1,127 @@ +/* + * 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. + */ + +package org.wso2.mdm.mdmmgt.beans; + +import org.wso2.carbon.device.mgt.common.Device; + +import java.util.List; + +public class PolicyWrapper { + + private int id; + private Profile profile; + private String policyName; + private String description; + private String compliance; + private List roles; + private String ownershipType; + private List devices; + private List users; + private int tenantId; + private int profileId; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public Profile getProfile() { + return profile; + } + + public void setProfile(Profile profile) { + this.profile = profile; + } + + public String getCompliance() { + return compliance; + } + + public void setCompliance(String compliance) { + this.compliance = compliance; + } + + public String getPolicyName() { + return policyName; + } + + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public List getRoles() { + return roles; + } + + public void setRoles(List roles) { + this.roles = roles; + } + + public String getOwnershipType() { + return ownershipType; + } + + public void setOwnershipType(String ownershipType) { + this.ownershipType = ownershipType; + } + + public List getDevices() { + return devices; + } + + public void setDevices(List devices) { + this.devices = devices; + } + + public List getUsers() { + return users; + } + + public void setUsers(List users) { + this.users = users; + } + + public int getTenantId() { + return tenantId; + } + + public void setTenantId(int tenantId) { + this.tenantId = tenantId; + } + + public int getProfileId() { + return profileId; + } + + public void setProfileId(int profileId) { + this.profileId = profileId; + } + +} diff --git a/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/PriorityUpdatedPolicyWrapper.java b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/PriorityUpdatedPolicyWrapper.java new file mode 100644 index 0000000000..73d67c56d6 --- /dev/null +++ b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/PriorityUpdatedPolicyWrapper.java @@ -0,0 +1,41 @@ +/* + * 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. + */ + +package org.wso2.mdm.mdmmgt.beans; + +public class PriorityUpdatedPolicyWrapper { + + private int id; + private int priority; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public int getPriority() { + return priority; + } + + public void setPriority(int priority) { + this.priority = priority; + } +} diff --git a/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/Profile.java b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/Profile.java new file mode 100644 index 0000000000..3a665d93c5 --- /dev/null +++ b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/Profile.java @@ -0,0 +1,107 @@ +/* +* 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. +*/ + +package org.wso2.mdm.mdmmgt.beans; + +import org.wso2.carbon.device.mgt.core.dto.DeviceType; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import java.sql.Timestamp; +import java.util.List; + +@XmlRootElement +public class Profile { + + private int profileId; + private String profileName; + private int tenantId; + private DeviceType deviceType; + private Timestamp createdDate; + private Timestamp updatedDate; + private List profileFeaturesList; // Features included in the policies. + + public DeviceType getDeviceType() { + return deviceType; + } + + public void setDeviceType(DeviceType deviceType) { + this.deviceType = deviceType; + } + + @XmlElement + public int getTenantId() { + return tenantId; + } + + public void setTenantId(int tenantId) { + this.tenantId = tenantId; + } + + /* public List getFeaturesList() { + return featuresList; + } + + public void setFeaturesList(List featuresList) { + this.featuresList = featuresList; + }*/ + @XmlElement + public int getProfileId() { + return profileId; + } + + public void setProfileId(int profileId) { + this.profileId = profileId; + } + + @XmlElement + public String getProfileName() { + return profileName; + } + + public void setProfileName(String profileName) { + this.profileName = profileName; + } + + @XmlElement + public Timestamp getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(Timestamp createdDate) { + this.createdDate = createdDate; + } + + @XmlElement + public Timestamp getUpdatedDate() { + return updatedDate; + } + + public void setUpdatedDate(Timestamp updatedDate) { + this.updatedDate = updatedDate; + } + + @XmlElement + public List getProfileFeaturesList() { + return profileFeaturesList; + } + + public void setProfileFeaturesList(List profileFeaturesList) { + this.profileFeaturesList = profileFeaturesList; + } +} diff --git a/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/ProfileFeature.java b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/ProfileFeature.java new file mode 100644 index 0000000000..637d07fb0f --- /dev/null +++ b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/ProfileFeature.java @@ -0,0 +1,85 @@ +/* +* 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. +*/ + +package org.wso2.mdm.mdmmgt.beans; + +import com.google.gson.Gson; + +import java.io.Serializable; + +public class ProfileFeature implements Serializable { + + private int id; + private String featureCode; + private int profileId; + private int deviceTypeId; + private Object content; + private String payLoad; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getFeatureCode() { + return featureCode; + } + + public void setFeatureCode(String featureCode) { + this.featureCode = featureCode; + } + + public int getProfileId() { + return profileId; + } + + public void setProfileId(int profileId) { + this.profileId = profileId; + } + + public int getDeviceTypeId() { + return deviceTypeId; + } + + public void setDeviceTypeId(int deviceTypeId) { + this.deviceTypeId = deviceTypeId; + } + + + public String getPayLoad() { + Gson gson = new Gson(); + this.payLoad = gson.toJson(content); + return payLoad; + } + + public void setPayLoad(String payLoad) { + this.payLoad = payLoad; + } + + + public Object getContent() { + return content; + } + + public void setContent(Object content) { + this.content = content; + } +} diff --git a/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/RoleWrapper.java b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/RoleWrapper.java new file mode 100644 index 0000000000..014ecde56b --- /dev/null +++ b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/RoleWrapper.java @@ -0,0 +1,59 @@ +package org.wso2.mdm.mdmmgt.beans; + +import org.wso2.carbon.user.mgt.common.UIPermissionNode; + +/* + * 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. + */ +public class RoleWrapper { + private String roleName; + private String[] permissions; + private String[] users; + private UIPermissionNode permissionList; + + public String getRoleName() { + return roleName; + } + + public void setRoleName(String roleName) { + this.roleName = roleName; + } + + public String[] getPermissions() { + return permissions; + } + + public void setPermissions(String[] permissions) { + this.permissions = permissions; + } + + public String[] getUsers() { + return users; + } + + public void setUsers(String[] users) { + this.users = users; + } + + public UIPermissionNode getPermissionList() { + return permissionList; + } + + public void setPermissionList(UIPermissionNode permissionList) { + this.permissionList = permissionList; + } +} diff --git a/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/UserCredentialWrapper.java b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/UserCredentialWrapper.java new file mode 100644 index 0000000000..87c70dd368 --- /dev/null +++ b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/UserCredentialWrapper.java @@ -0,0 +1,53 @@ +/* + * 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. + */ + +package org.wso2.mdm.mdmmgt.beans; + +public class UserCredentialWrapper { + + private String username; + /* + Base64 encoded password + */ + private String oldPassword; + private String newPassword; + + public String getNewPassword() { + return newPassword; + } + + public void setNewPassword(String newPassword) { + this.newPassword = newPassword; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getOldPassword() { + return oldPassword; + } + + public void setOldPassword(String oldPassword) { + this.oldPassword = oldPassword; + } +} diff --git a/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/UserWrapper.java b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/UserWrapper.java new file mode 100644 index 0000000000..cd9705f79d --- /dev/null +++ b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/UserWrapper.java @@ -0,0 +1,87 @@ +/* + * 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. + */ + +package org.wso2.mdm.mdmmgt.beans; + +public class UserWrapper { + + private String username; + /* + Base64 encoded password + */ + private String password; + private String firstname; + private String lastname; + private String emailAddress; + private String[] roles; + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getFirstname() { + return firstname; + } + + public void setFirstname(String firstname) { + this.firstname = firstname; + } + + public String getLastname() { + return lastname; + } + + public void setLastname(String lastname) { + this.lastname = lastname; + } + + public String getEmailAddress() { + return emailAddress; + } + + public void setEmailAddress(String emailAddress) { + this.emailAddress = emailAddress; + } + + /* + Giving a clone of the array since arrays are mutable + */ + public String[] getRoles() { + String[] copiedRoles = roles; + if (roles != null) { + copiedRoles = roles.clone(); + } + return copiedRoles; + } + + public void setRoles(String[] roles) { + this.roles = roles; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } +} diff --git a/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/android/AppStoreApplication.java b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/android/AppStoreApplication.java new file mode 100644 index 0000000000..afb46ad21f --- /dev/null +++ b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/android/AppStoreApplication.java @@ -0,0 +1,52 @@ +/* + * + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) 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. + */ +package org.wso2.mdm.mdmmgt.beans.android; + +import com.google.gson.Gson; +import org.wso2.mdm.mdmmgt.common.MDMException; + +import java.io.Serializable; + +/** + * This class represents the Appstore Application information. + */ +public class AppStoreApplication implements Serializable { + + private String type; + private String appIdentifier; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getAppIdentifier() { + return appIdentifier; + } + + public void setAppIdentifier(String appIdentifier) { + this.appIdentifier = appIdentifier; + } + + public String toJSON() throws MDMException { + Gson gson = new Gson(); + return gson.toJson(this); + } +} diff --git a/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/android/EnterpriseApplication.java b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/android/EnterpriseApplication.java new file mode 100644 index 0000000000..5e23755c3a --- /dev/null +++ b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/android/EnterpriseApplication.java @@ -0,0 +1,61 @@ +/* + * + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) 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. + */ +package org.wso2.mdm.mdmmgt.beans.android; + +import com.google.gson.Gson; +import org.wso2.mdm.mdmmgt.common.MDMException; + +import java.io.Serializable; + +/** + * This class represents the Enterprise Application information. + */ +public class EnterpriseApplication implements Serializable { + + private String type; + private String url; + private String appIdentifier; + + public String getAppIdentifier() { + return appIdentifier; + } + + public void setAppIdentifier(String appIdentifier) { + this.appIdentifier = appIdentifier; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String toJSON() throws MDMException { + Gson gson = new Gson(); + return gson.toJson(this); + } +} diff --git a/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/android/WebApplication.java b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/android/WebApplication.java new file mode 100644 index 0000000000..58a282b5b8 --- /dev/null +++ b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/android/WebApplication.java @@ -0,0 +1,61 @@ +/* + * + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) 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. + */ +package org.wso2.mdm.mdmmgt.beans.android; + +import com.google.gson.Gson; +import org.wso2.mdm.mdmmgt.common.MDMException; + +import java.io.Serializable; + +/** + * This class represents the Web Application information. + */ +public class WebApplication implements Serializable { + + private String name; + private String url; + private String type; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String toJSON() throws MDMException { + Gson gson = new Gson(); + return gson.toJson(this); + } +} diff --git a/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/ios/AppStoreApplication.java b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/ios/AppStoreApplication.java new file mode 100644 index 0000000000..e30c09b19c --- /dev/null +++ b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/ios/AppStoreApplication.java @@ -0,0 +1,86 @@ +/* + * 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. + */ +package org.wso2.mdm.mdmmgt.beans.ios; + +import com.google.gson.Gson; +import org.wso2.mdm.mdmmgt.common.MDMException; + +import java.io.Serializable; + +public class AppStoreApplication implements Serializable { + + private String identifier; + private int iTunesStoreID; + private boolean removeAppUponMDMProfileRemoval; + private boolean preventBackupOfAppData; + private String bundleId; + private String UUID; + + public String getUUID() { + return UUID; + } + + public void setUUID(String UUID) { + this.UUID = UUID; + } + + public String getIdentifier() { + return identifier; + } + + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + public int getiTunesStoreID() { + return iTunesStoreID; + } + + public void setiTunesStoreID(int iTunesStoreID) { + this.iTunesStoreID = iTunesStoreID; + } + + public boolean isRemoveAppUponMDMProfileRemoval() { + return removeAppUponMDMProfileRemoval; + } + + public void setRemoveAppUponMDMProfileRemoval(boolean removeAppUponMDMProfileRemoval) { + this.removeAppUponMDMProfileRemoval = removeAppUponMDMProfileRemoval; + } + + public boolean isPreventBackupOfAppData() { + return preventBackupOfAppData; + } + + public void setPreventBackupOfAppData(boolean preventBackupOfAppData) { + this.preventBackupOfAppData = preventBackupOfAppData; + } + + public String getBundleId() { + return bundleId; + } + + public void setBundleId(String bundleId) { + this.bundleId = bundleId; + } + + public String toJSON() throws MDMException { + Gson gson = new Gson(); + return gson.toJson(this); + } +} diff --git a/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/ios/EnterpriseApplication.java b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/ios/EnterpriseApplication.java new file mode 100644 index 0000000000..dbe6d5ba77 --- /dev/null +++ b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/ios/EnterpriseApplication.java @@ -0,0 +1,83 @@ +/* + * 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. + * + */ +package org.wso2.mdm.mdmmgt.beans.ios; + +import com.google.gson.Gson; +import org.wso2.mdm.mdmmgt.common.MDMException; + +import java.io.Serializable; + +public class EnterpriseApplication implements Serializable { + + private String identifier; + private String manifestURL; + private boolean removeAppUponMDMProfileRemoval; + private boolean preventBackupOfAppData; + private String bundleId; + private String UUID; + + public void setUUID(String UUID) { + this.UUID = UUID; + } + + public String getIdentifier() { + return identifier; + } + + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + public String getManifestURL() { + return manifestURL; + } + + public void setManifestURL(String manifestURL) { + this.manifestURL = manifestURL; + } + + public boolean isRemoveAppUponMDMProfileRemoval() { + return removeAppUponMDMProfileRemoval; + } + + public void setRemoveAppUponMDMProfileRemoval(boolean removeAppUponMDMProfileRemoval) { + this.removeAppUponMDMProfileRemoval = removeAppUponMDMProfileRemoval; + } + + public boolean isPreventBackupOfAppData() { + return preventBackupOfAppData; + } + + public void setPreventBackupOfAppData(boolean preventBackupOfAppData) { + this.preventBackupOfAppData = preventBackupOfAppData; + } + + public String getBundleId() { + return bundleId; + } + + public void setBundleId(String bundleId) { + this.bundleId = bundleId; + } + + public String toJSON() throws MDMException { + Gson gson = new Gson(); + return gson.toJson(this); + } +} diff --git a/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/ios/RemoveApplication.java b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/ios/RemoveApplication.java new file mode 100644 index 0000000000..3deb12c4bd --- /dev/null +++ b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/ios/RemoveApplication.java @@ -0,0 +1,24 @@ +package org.wso2.mdm.mdmmgt.beans.ios; + +import com.google.gson.Gson; +import org.wso2.mdm.mdmmgt.common.MDMException; + +import java.io.Serializable; + +public class RemoveApplication implements Serializable { + + private String bundleId; + + public String getBundleId() { + return bundleId; + } + + public void setBundleId(String bundleId) { + this.bundleId = bundleId; + } + + public String toJSON() throws MDMException { + Gson gson = new Gson(); + return gson.toJson(this); + } +} diff --git a/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/ios/WebClip.java b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/ios/WebClip.java new file mode 100644 index 0000000000..1517631aab --- /dev/null +++ b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/beans/ios/WebClip.java @@ -0,0 +1,59 @@ +package org.wso2.mdm.mdmmgt.beans.ios; + +import com.google.gson.Gson; +import org.wso2.mdm.mdmmgt.common.MDMException; + +public class WebClip { + + private String URL; + private String label; + private String icon; + private String isRemovable; + private String UUID; + + public String getUUID() { + return UUID; + } + + public void setUUID(String UUID) { + this.UUID = UUID; + } + + public String getURL() { + return URL; + } + + public void setURL(String URL) { + this.URL = URL; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public String getIcon() { + return icon; + } + + public void setIcon(String icon) { + this.icon = icon; + } + + public String getIsRemovable() { + return isRemovable; + } + + public void setIsRemovable(String isRemovable) { + this.isRemovable = isRemovable; + } + + public String toJSON() throws MDMException { + Gson gson = new Gson(); + return gson.toJson(this); + } + +} diff --git a/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/common/MDMException.java b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/common/MDMException.java new file mode 100644 index 0000000000..8591bfee47 --- /dev/null +++ b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/common/MDMException.java @@ -0,0 +1,36 @@ +package org.wso2.mdm.mdmmgt.common; + + +public class MDMException extends Exception { + + private static final long serialVersionUID = 5136875495185597926L; + private String errorMessage; + + + public MDMException(String msg, Exception e) { + super(msg, e); + setErrorMessage(msg); + } + + public MDMException(String msg, Throwable cause) { + super(msg, cause); + setErrorMessage(msg); + } + + public MDMException(String msg) { + super(msg); + setErrorMessage(msg); + } + + public MDMException() { + super(); + } + + public MDMException(Throwable cause) { + super(cause); + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } +} diff --git a/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/util/MDMAndroidOperationUtil.java b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/util/MDMAndroidOperationUtil.java new file mode 100644 index 0000000000..c486a390f8 --- /dev/null +++ b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/util/MDMAndroidOperationUtil.java @@ -0,0 +1,114 @@ +/* + * 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. + */ +package org.wso2.mdm.mdmmgt.util; + + +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation; +import org.wso2.mdm.mdmmgt.beans.MobileApp; +import org.wso2.mdm.mdmmgt.beans.android.AppStoreApplication; +import org.wso2.mdm.mdmmgt.beans.android.EnterpriseApplication; +import org.wso2.mdm.mdmmgt.beans.android.WebApplication; +import org.wso2.mdm.mdmmgt.common.MDMException; + +/** + * This class contains the all the operations related to Android. + */ +public class MDMAndroidOperationUtil { + + /** + * This method is used to create Install Application operation. + * + * @param application MobileApp application + * @return operation + * @throws MDMException + */ + public static Operation createInstallAppOperation(MobileApp application) throws MDMException { + + ProfileOperation operation = new ProfileOperation(); + operation.setCode(MDMAppConstants.AndroidConstants.OPCODE_INSTALL_APPLICATION); + operation.setType(Operation.Type.PROFILE); + + switch (application.getType()) { + case ENTERPRISE: + EnterpriseApplication enterpriseApplication = new EnterpriseApplication(); + enterpriseApplication.setType(application.getType().toString()); + enterpriseApplication.setUrl(application.getLocation()); + operation.setPayLoad(enterpriseApplication.toJSON()); + break; + case PUBLIC: + AppStoreApplication appStoreApplication = new AppStoreApplication(); + appStoreApplication.setType(application.getType().toString()); + appStoreApplication.setAppIdentifier(application.getIdentifier()); + operation.setPayLoad(appStoreApplication.toJSON()); + break; + case WEBAPP: + WebApplication webApplication = new WebApplication(); + webApplication.setUrl(application.getLocation()); + webApplication.setName(application.getName()); + webApplication.setType(application.getType().toString()); + operation.setPayLoad(webApplication.toJSON()); + break; + default: + String errorMessage = "Invalid application type."; + throw new MDMException(errorMessage); + } + return operation; + } + + /** + * This method is used to create Uninstall Application operation. + * + * @param application MobileApp application + * @return operation + * @throws MDMException + */ + public static Operation createAppUninstallOperation(MobileApp application) throws MDMException { + + ProfileOperation operation = new ProfileOperation(); + operation.setCode(MDMAppConstants.AndroidConstants.OPCODE_UNINSTALL_APPLICATION); + operation.setType(Operation.Type.PROFILE); + + switch (application.getType()) { + case ENTERPRISE: + EnterpriseApplication enterpriseApplication = new EnterpriseApplication(); + enterpriseApplication.setType(application.getType().toString()); + enterpriseApplication.setAppIdentifier(application.getIdentifier()); + operation.setPayLoad(enterpriseApplication.toJSON()); + break; + case PUBLIC: + AppStoreApplication appStoreApplication = new AppStoreApplication(); + appStoreApplication.setType(application.getType().toString()); + appStoreApplication.setAppIdentifier(application.getIdentifier()); + operation.setPayLoad(appStoreApplication.toJSON()); + break; + case WEBAPP: + WebApplication webApplication = new WebApplication(); + webApplication.setUrl(application.getLocation()); + webApplication.setName(application.getName()); + webApplication.setType(application.getType().toString()); + operation.setPayLoad(webApplication.toJSON()); + break; + default: + String errorMessage = "Invalid application type."; + throw new MDMException(errorMessage); + } + return operation; + } + +} diff --git a/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/util/MDMAppConstants.java b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/util/MDMAppConstants.java new file mode 100644 index 0000000000..46fe591710 --- /dev/null +++ b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/util/MDMAppConstants.java @@ -0,0 +1,63 @@ +/* + * + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) 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. + */ +package org.wso2.mdm.mdmmgt.util; + +/** + * This class holds all the constants used for IOS and Android. + */ +public class MDMAppConstants { + + public class IOSConstants { + + public static final String IS_REMOVE_APP = "isRemoveApp"; + public static final String IS_PREVENT_BACKUP = "isPreventBackup"; + public static final String I_TUNES_ID = "iTunesId"; + public static final String LABEL = "label"; + public static final String OPCODE_INSTALL_ENTERPRISE_APPLICATION = "INSTALL_ENTERPRISE_APPLICATION"; + public static final String OPCODE_INSTALL_STORE_APPLICATION = "INSTALL_STORE_APPLICATION"; + public static final String OPCODE_INSTALL_WEB_APPLICATION = "WEB_CLIP"; + public static final String OPCODE_REMOVE_APPLICATION = "REMOVE_APPLICATION"; + + private IOSConstants() { + throw new AssertionError(); + } + } + + public class AndroidConstants { + + public static final String OPCODE_INSTALL_APPLICATION = "INSTALL_APPLICATION"; + public static final String OPCODE_UNINSTALL_APPLICATION = "UNINSTALL_APPLICATION"; + + private AndroidConstants() { + throw new AssertionError(); + } + } + + public class RegistryConstants { + + public static final String GENERAL_CONFIG_RESOURCE_PATH = "general"; + + private RegistryConstants() { + throw new AssertionError(); + } + } + + public class APPManagerConstants { + + private static final String APP_MANAGER_MDM_SERVICE_NAME = "org.wso2.carbon.appmgt.mobile.interfaces.MDMOperations"; + } +} diff --git a/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/util/MDMIOSOperationUtil.java b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/util/MDMIOSOperationUtil.java new file mode 100644 index 0000000000..0f3413b44f --- /dev/null +++ b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/util/MDMIOSOperationUtil.java @@ -0,0 +1,105 @@ +/* + * + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) 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. + */ +package org.wso2.mdm.mdmmgt.util; + +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation; +import org.wso2.mdm.mdmmgt.beans.MobileApp; +import org.wso2.mdm.mdmmgt.beans.ios.AppStoreApplication; +import org.wso2.mdm.mdmmgt.beans.ios.EnterpriseApplication; +import org.wso2.mdm.mdmmgt.beans.ios.RemoveApplication; +import org.wso2.mdm.mdmmgt.beans.ios.WebClip; +import org.wso2.mdm.mdmmgt.common.MDMException; + +import java.util.Properties; + +/** + * This class contains the all the operations related to IOS. + */ +public class MDMIOSOperationUtil { + + /** + * This method is used to create Install Application operation. + * + * @param application MobileApp application + * @return operation + * @throws MDMException + */ + public static Operation createInstallAppOperation(MobileApp application) throws MDMException { + + ProfileOperation operation = new ProfileOperation(); + + switch (application.getType()) { + case ENTERPRISE: + EnterpriseApplication enterpriseApplication = new EnterpriseApplication(); + enterpriseApplication.setBundleId(application.getId()); + enterpriseApplication.setIdentifier(application.getIdentifier()); + enterpriseApplication.setManifestURL(application.getLocation()); + + Properties properties = application.getProperties(); + enterpriseApplication.setPreventBackupOfAppData((Boolean) properties. + get(MDMAppConstants.IOSConstants.IS_PREVENT_BACKUP)); + enterpriseApplication.setRemoveAppUponMDMProfileRemoval((Boolean) properties. + get(MDMAppConstants.IOSConstants.IS_REMOVE_APP)); + operation.setCode(MDMAppConstants.IOSConstants.OPCODE_INSTALL_ENTERPRISE_APPLICATION); + operation.setPayLoad(enterpriseApplication.toJSON()); + operation.setType(Operation.Type.COMMAND); + break; + case PUBLIC: + AppStoreApplication appStoreApplication = new AppStoreApplication(); + appStoreApplication.setRemoveAppUponMDMProfileRemoval((Boolean) application.getProperties(). + get(MDMAppConstants.IOSConstants.IS_REMOVE_APP)); + appStoreApplication.setIdentifier(application.getIdentifier()); + appStoreApplication.setPreventBackupOfAppData((Boolean) application.getProperties(). + get(MDMAppConstants.IOSConstants.IS_PREVENT_BACKUP)); + appStoreApplication.setBundleId(application.getId()); + appStoreApplication.setiTunesStoreID((Integer) application.getProperties(). + get(MDMAppConstants.IOSConstants.I_TUNES_ID)); + operation.setCode(MDMAppConstants.IOSConstants.OPCODE_INSTALL_STORE_APPLICATION); + operation.setType(Operation.Type.COMMAND); + operation.setPayLoad(appStoreApplication.toJSON()); + break; + case WEBAPP: + WebClip webClip = new WebClip(); + webClip.setIcon(application.getIconImage()); + webClip.setIsRemovable(application.getProperties(). + getProperty(MDMAppConstants.IOSConstants.IS_REMOVE_APP)); + webClip.setLabel(application.getProperties(). + getProperty(MDMAppConstants.IOSConstants.LABEL)); + webClip.setURL(application.getLocation()); + + operation.setCode(MDMAppConstants.IOSConstants.OPCODE_INSTALL_WEB_APPLICATION); + operation.setType(Operation.Type.PROFILE); + operation.setPayLoad(webClip.toJSON()); + break; + } + return operation; + } + + public static Operation createAppUninstallOperation(MobileApp application) throws MDMException { + + ProfileOperation operation = new ProfileOperation(); + operation.setCode(MDMAppConstants.IOSConstants.OPCODE_REMOVE_APPLICATION); + operation.setType(Operation.Type.PROFILE); + + RemoveApplication removeApplication = new RemoveApplication(); + removeApplication.setBundleId(application.getIdentifier()); + operation.setPayLoad(removeApplication.toJSON()); + + return operation; + } +} diff --git a/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/util/MDMServiceAPIUtils.java b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/util/MDMServiceAPIUtils.java new file mode 100644 index 0000000000..dd6082081b --- /dev/null +++ b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/util/MDMServiceAPIUtils.java @@ -0,0 +1,226 @@ +/* + * 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. + */ + +package org.wso2.mdm.mdmmgt.util; + + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.CarbonContext; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.PaginationResult; +import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfigurationManagementService; +import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService; +import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; +import org.wso2.carbon.policy.mgt.core.PolicyManagerService; +import org.wso2.carbon.user.api.AuthorizationManager; +import org.wso2.carbon.user.api.UserRealm; +import org.wso2.carbon.user.api.UserStoreException; +import org.wso2.carbon.user.api.UserStoreManager; +import org.wso2.carbon.user.core.service.RealmService; +import org.wso2.carbon.utils.multitenancy.MultitenantConstants; +import org.wso2.mdm.mdmmgt.common.MDMException; + +import java.util.List; + +/** + * MDMServiceAPIUtils class provides utility function. + */ +public class MDMServiceAPIUtils { + + private static Log log = LogFactory.getLog(MDMServiceAPIUtils.class); + + public static DeviceManagementProviderService getDeviceManagementService(int tenantId) { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + ctx.setTenantId(tenantId, true); + DeviceManagementProviderService deviceManagementProviderService = + (DeviceManagementProviderService) ctx.getOSGiService(DeviceManagementProviderService.class, null); + if (deviceManagementProviderService == null) { + String msg = "Device Management provider service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); + } + return deviceManagementProviderService; + } + + public static int getTenantId(String tenantDomain) throws MDMException { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + RealmService realmService = (RealmService) ctx.getOSGiService(RealmService.class, null); + try { + return realmService.getTenantManager().getTenantId(tenantDomain); + } catch (UserStoreException e) { + throw new MDMException( + "Error obtaining tenant id from tenant domain " + tenantDomain); + } + } + + public static UserStoreManager getUserStoreManager(int tenantId) throws MDMException { + RealmService realmService; + UserStoreManager userStoreManager; + try { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + ctx.setTenantId(tenantId, true); + realmService = (RealmService) ctx.getOSGiService(RealmService.class, null); + if (realmService == null) { + String msg = "Realm service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); + } + userStoreManager = realmService.getTenantUserRealm(tenantId).getUserStoreManager(); + } catch (UserStoreException e) { + String msg = "Error occurred while retrieving current user store manager"; + log.error(msg, e); + throw new MDMException(msg, e); + } + return userStoreManager; + } + + /** + * Getting the current tenant's user realm + * + * @return + * @throws org.wso2.mdm.mdmmgt.common.MDMException + */ + public static UserRealm getUserRealm(int tenantId) throws MDMException { + RealmService realmService; + UserRealm realm; + try { + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + ctx.setTenantId(tenantId, true); + ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); + ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID); + realmService = (RealmService) ctx.getOSGiService(RealmService.class, null); + + if (realmService == null) { + String msg = "Realm service not initialized"; + log.error(msg); + throw new MDMException(msg); + } + realm = realmService.getTenantUserRealm(tenantId); + } catch (UserStoreException e) { + String msg = "Error occurred while retrieving current user realm"; + log.error(msg, e); + throw new MDMException(msg, e); + } finally { + PrivilegedCarbonContext.endTenantFlow(); + } + return realm; + } + + public static AuthorizationManager getAuthorizationManager(int tenantId) throws MDMException { + RealmService realmService; + AuthorizationManager authorizationManager; + try { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + ctx.setTenantId(tenantId, true); + realmService = (RealmService) ctx.getOSGiService(RealmService.class, null); + if (realmService == null) { + String msg = "Realm service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); + } + authorizationManager = realmService.getTenantUserRealm(tenantId).getAuthorizationManager(); + } catch (UserStoreException e) { + String msg = "Error occurred while retrieving current Authorization manager."; + log.error(msg, e); + throw new MDMException(msg, e); + } + return authorizationManager; + } + + /** + * This method is used to get the current tenant id. + * + * @return returns the tenant id. + */ + public static int getTenantId() { + return CarbonContext.getThreadLocalCarbonContext().getTenantId(); + } + + public static DeviceIdentifier instantiateDeviceIdentifier(String deviceType, String deviceId) { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setType(deviceType); + deviceIdentifier.setId(deviceId); + return deviceIdentifier; + } + + public static ApplicationManagementProviderService getAppManagementService(int tenantId) { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + ctx.setTenantId(tenantId, true); + ApplicationManagementProviderService applicationManagementProviderService = + (ApplicationManagementProviderService) ctx.getOSGiService(ApplicationManagementProviderService.class, null); + if (applicationManagementProviderService == null) { + String msg = "Application management service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); + } + return applicationManagementProviderService; + } + + public static PolicyManagerService getPolicyManagementService(int tenantId) { + PolicyManagerService policyManagementService; + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + ctx.setTenantId(tenantId, true); + policyManagementService = + (PolicyManagerService) ctx.getOSGiService(PolicyManagerService.class, null); + if (policyManagementService == null) { + String msg = "Policy Management service not initialized."; + log.error(msg); + throw new IllegalStateException(msg); + } + return policyManagementService; + } + + public static TenantConfigurationManagementService getTenantConfigurationManagementService() { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + TenantConfigurationManagementService tenantConfigurationManagementService = + (TenantConfigurationManagementService) ctx.getOSGiService(TenantConfigurationManagementService.class, null); + if (tenantConfigurationManagementService == null) { + String msg = "Tenant configuration Management service not initialized."; + log.error(msg); + throw new IllegalStateException(msg); + } + return tenantConfigurationManagementService; + } + + public static NotificationManagementService getNotificationManagementService() { + NotificationManagementService notificationManagementService; + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + notificationManagementService = (NotificationManagementService) ctx.getOSGiService( + NotificationManagementService.class, null); + if (notificationManagementService == null) { + String msg = "Notification Management service not initialized."; + log.error(msg); + throw new IllegalStateException(msg); + } + return notificationManagementService; + } + + public static PaginationResult getPagingResponse(int recordsTotal, int recordsFiltered, + int draw, List data) { + PaginationResult pagingResponse = new PaginationResult(); + pagingResponse.setRecordsTotal(recordsTotal); + pagingResponse.setRecordsFiltered(recordsFiltered); + pagingResponse.setDraw(draw); + pagingResponse.setData(data); + return pagingResponse; + } +} diff --git a/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/util/ResponsePayload.java b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/util/ResponsePayload.java new file mode 100644 index 0000000000..563f454453 --- /dev/null +++ b/components/device-mgt-mdm/org.wso2.mdm.mdmmgt/src/main/java/org/wso2/mdm/mdmmgt/util/ResponsePayload.java @@ -0,0 +1,106 @@ +/* + * 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. + */ +package main.java.org.wso2.mdm.mdmmgt.util; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement +public class ResponsePayload { + + private int statusCode; + private String messageFromServer; + private Object responseContent; + + public static ResponsePayloadBuilder statusCode(int statusCode) { + ResponsePayload message = new ResponsePayload(); + return message.getBuilder().statusCode(statusCode); + } + + public static ResponsePayloadBuilder messageFromServer(String messageFromServer) { + ResponsePayload message = new ResponsePayload(); + return message.getBuilder().messageFromServer(messageFromServer); + } + + public static ResponsePayloadBuilder responseContent(String responseContent) { + ResponsePayload message = new ResponsePayload(); + return message.getBuilder().responseContent(responseContent); + } + + @XmlElement + public int getStatusCode() { + return statusCode; + } + + public void setStatusCode(int statusCode) { + this.statusCode = statusCode; + } + + @XmlElement + public String getMessageFromServer() { + return messageFromServer; + } + + public void setMessageFromServer(String messageFromServer) { + this.messageFromServer = messageFromServer; + } + + @XmlElement + public Object getResponseContent() { + return responseContent; + } + + public void setResponseContent(Object responseContent) { + this.responseContent = responseContent; + } + + private ResponsePayloadBuilder getBuilder() { + return new ResponsePayloadBuilder(); + } + + public class ResponsePayloadBuilder { + + private int statusCode; + private String messageFromServer; + private Object responseContent; + + public ResponsePayloadBuilder statusCode(int statusCode) { + this.statusCode = statusCode; + return this; + } + + public ResponsePayloadBuilder messageFromServer(String messageFromServer) { + this.messageFromServer = messageFromServer; + return this; + } + + public ResponsePayloadBuilder responseContent(String responseContent) { + this.responseContent = responseContent; + return this; + } + + public ResponsePayload build() { + ResponsePayload payload = new ResponsePayload(); + payload.setStatusCode(statusCode); + payload.setMessageFromServer(messageFromServer); + payload.setResponseContent(responseContent); + return payload; + } + } + +} diff --git a/components/device-mgt-mdm/pom.xml b/components/device-mgt-mdm/pom.xml index 1ef3e71390..8ab7a9e1cb 100644 --- a/components/device-mgt-mdm/pom.xml +++ b/components/device-mgt-mdm/pom.xml @@ -17,8 +17,8 @@ ~ under the License. --> - @@ -39,6 +39,8 @@ org.wso2.carbon.device.mgt.mobile org.wso2.carbon.device.mgt.mobile.api org.wso2.carbon.device.mgt.mobile.url.printer + org.wso2.mdm.appmgt + org.wso2.mdm.mdmmgt diff --git a/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/pom.xml b/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/pom.xml new file mode 100644 index 0000000000..f4007e4b5a --- /dev/null +++ b/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/pom.xml @@ -0,0 +1,139 @@ + + + + + + + + org.wso2.carbon.devicemgt-plugins + device-mgt-iot-androidsense-feature + 1.9.2-SNAPSHOT + ../pom.xml + + + 4.0.0 + org.wso2.carbon.device.mgt.iot.androidsense.feature + pom + 1.9.2-SNAPSHOT + WSO2 Carbon - IoT Server Android Sense Feature + http://wso2.org + This feature contains the Android Sense Device type specific implementations for the IoT Server + + + + + org.wso2.carbon.devicemgt-plugins + org.wso2.carbon.device.mgt.iot.androidsense + + + org.wso2.carbon.devicemgt-plugins + org.wso2.carbon.device.mgt.iot.androidsense.api + war + + + + + + + maven-resources-plugin + + + copy-resources + generate-resources + + copy-resources + + + src/main/resources + + + resources + + build.properties + p2.inf + + + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-jaxrs-war + package + + copy + + + + + org.wso2.carbon.devicemgt-plugins + org.wso2.carbon.device.mgt.iot.androidsense.api + war + true + ${basedir}/src/main/resources/webapps/ + android_sense.war + + + + + + + + + org.wso2.maven + carbon-p2-plugin + + + p2-feature-generation + package + + p2-feature-gen + + + org.wso2.carbon.device.mgt.iot.androidsense + ../../../features/etc/feature.properties + + + org.wso2.carbon.p2.category.type:server + org.eclipse.equinox.p2.type.group:false + + + + + org.wso2.carbon.devicemgt-plugins:org.wso2.carbon.device.mgt.iot.androidsense:${carbon.iot.device.mgt.version} + + + + org.wso2.carbon.core.server:${carbon.kernel.version} + org.wso2.carbon.device.mgt.server:${carbon.device.mgt.version} + + + + + + + + diff --git a/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/src/main/resources/agent/androidsense.apk b/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/src/main/resources/agent/androidsense.apk new file mode 100644 index 0000000000..0c86f8395d Binary files /dev/null and b/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/src/main/resources/agent/androidsense.apk differ diff --git a/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/src/main/resources/agent/sketch.properties b/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/src/main/resources/agent/sketch.properties new file mode 100644 index 0000000000..aefe1a60bf --- /dev/null +++ b/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/src/main/resources/agent/sketch.properties @@ -0,0 +1,2 @@ +templates=androidsense.apk +zipfilename=androidsense.zip \ No newline at end of file diff --git a/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/src/main/resources/build.properties b/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/src/main/resources/build.properties new file mode 100644 index 0000000000..93c4b10701 --- /dev/null +++ b/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/src/main/resources/build.properties @@ -0,0 +1 @@ +custom = true \ No newline at end of file diff --git a/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/src/main/resources/dbscripts/h2_android_sense.sql b/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/src/main/resources/dbscripts/h2_android_sense.sql new file mode 100644 index 0000000000..218cdbf05c --- /dev/null +++ b/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/src/main/resources/dbscripts/h2_android_sense.sql @@ -0,0 +1,11 @@ + +-- ----------------------------------------------------- +-- Table `ANDROID_DEVICE` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `ANDROID_SENSE_DEVICE` ( + `ANDROID_DEVICE_ID` VARCHAR(45) NOT NULL , + `DEVICE_NAME` VARCHAR(100) NULL DEFAULT NULL, + PRIMARY KEY (`ANDROID_DEVICE_ID`) ); + + + diff --git a/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/src/main/resources/dbscripts/mysql_android_sense.sql b/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/src/main/resources/dbscripts/mysql_android_sense.sql new file mode 100644 index 0000000000..4637b4daf2 --- /dev/null +++ b/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/src/main/resources/dbscripts/mysql_android_sense.sql @@ -0,0 +1,12 @@ +-- ----------------------------------------------------- +-- Table `ANDROID_DEVICE` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `ANDROID_SENSE_DEVICE` ( + `ANDROID_DEVICE_ID` VARCHAR(45) NOT NULL , + `DEVICE_NAME` VARCHAR(100) NULL DEFAULT NULL, + PRIMARY KEY (`ANDROID_DEVICE_ID`) ) +ENGINE = InnoDB; + + + + diff --git a/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.androidsense-overview/androidsense-overview.hbs b/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.androidsense-overview/androidsense-overview.hbs new file mode 100644 index 0000000000..737550d14d --- /dev/null +++ b/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.androidsense-overview/androidsense-overview.hbs @@ -0,0 +1,36 @@ +
+
+ {{unit "cdmf.unit.device.overview.androidsense-display-image"}} +
+
+
Device Overview - Android Sense
+ {{#defineZone "device-detail-properties"}} + + + + + + {{#if device.viewModel.udid}} + + {{/if}} + {{#if device.viewModel.phoneNumber}} + + {{/if}} + + + + + +
Device{{device.viewModel.vendor}} {{device.properties.model}}
Model{{device.viewModel.model}}
IMEI{{device.viewModel.imei}}
UDID{{device.viewModel.udid}}
Phone Number{{device.viewModel.phoneNumber}}
Status + {{#equal device.status "ACTIVE"}} Active{{/equal}} + {{#equal device.status "INACTIVE"}} Inactive{{/equal}} + {{#equal device.status "BLOCKED"}} Blocked{{/equal}} + {{#equal device.status "REMOVED"}} Removed{{/equal}} +
+ {{/defineZone}} +
Operations
+
+ {{unit "cdmf.unit.device.iot-operation" deviceType=device.type}} +
+
+
\ No newline at end of file diff --git a/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.androidsense-overview/androidsense-overview.js b/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.androidsense-overview/androidsense-overview.js new file mode 100644 index 0000000000..bd9503d3f6 --- /dev/null +++ b/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.androidsense-overview/androidsense-overview.js @@ -0,0 +1,25 @@ +function onRequest (context) { + var log = new Log("detail.js"); + var deviceType = request.getParameter("type"); + var deviceId = request.getParameter("id"); + + if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) { + var deviceModule = require("/modules/device.js").deviceModule; + var device = deviceModule.viewDevice(deviceType, deviceId); + + if (device) { + var viewModel = {}; + var deviceInfo = device.properties.DEVICE_INFO; + if (deviceInfo != undefined && String(deviceInfo.toString()).length > 0) { + deviceInfo = parse(stringify(deviceInfo)); + viewModel.system = device.properties.IMEI; + viewModel.machine = "Android Sense"; + viewModel.vendor = device.properties.VENDOR; + } + device.viewModel = viewModel; + } + context.device = device; + + return context; + } +} \ No newline at end of file diff --git a/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.androidsense-overview/androidsense-overview.json b/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.androidsense-overview/androidsense-overview.json new file mode 100644 index 0000000000..688e939808 --- /dev/null +++ b/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.androidsense-overview/androidsense-overview.json @@ -0,0 +1,3 @@ +{ + "version": "1.0.0" +} \ No newline at end of file diff --git a/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/src/main/resources/p2.inf b/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/src/main/resources/p2.inf new file mode 100644 index 0000000000..41a72428c5 --- /dev/null +++ b/features/device-mgt-iot-androidsense-feature/org.wso2.carbon.device.mgt.iot.androidsense.feature/src/main/resources/p2.inf @@ -0,0 +1,6 @@ +instructions.configure = \ +org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../deployment/server/webapps/);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.androidsense_${feature.version}/webapps/,target:${installFolder}/../../deployment/server/webapps/,overwrite:true);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.androidsense_${feature.version}/dbscripts/,target:${installFolder}/../../../dbscripts/cdm/plugins/androidsense,overwrite:true);\ +org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../deployment/server/jaggeryapps/);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.androidsense_${feature.version}/jaggeryapps/,target:${installFolder}/../../deployment/server/jaggeryapps/,overwrite:true);\ diff --git a/features/device-mgt-iot-androidsense-feature/pom.xml b/features/device-mgt-iot-androidsense-feature/pom.xml new file mode 100644 index 0000000000..c608ddc4bf --- /dev/null +++ b/features/device-mgt-iot-androidsense-feature/pom.xml @@ -0,0 +1,41 @@ + + + + + + + org.wso2.carbon.devicemgt-plugins + carbon-device-mgt-plugins-parent + 1.9.2-SNAPSHOT + ../../pom.xml + + + 4.0.0 + device-mgt-iot-androidsense-feature + 1.9.2-SNAPSHOT + pom + WSO2 Carbon - IoT Server Android Sense Device Feature + http://wso2.org + + + org.wso2.carbon.device.mgt.iot.androidsense.feature + + + diff --git a/features/device-mgt-mdm-feature/org.wso2.mdm.mdmmgt.server.feature/pom.xml b/features/device-mgt-mdm-feature/org.wso2.mdm.mdmmgt.server.feature/pom.xml new file mode 100644 index 0000000000..05269b4767 --- /dev/null +++ b/features/device-mgt-mdm-feature/org.wso2.mdm.mdmmgt.server.feature/pom.xml @@ -0,0 +1,107 @@ + + + + org.wso2.carbon.devicemgt-plugins + device-mgt-mdm-feature + 1.9.2-SNAPSHOT + ../pom.xml + + 4.0.0 + + org.wso2.mdm.mdmmgt.server.feature + 1.9.2-SNAPSHOT + + + + + maven-resources-plugin + 2.6 + + + copy-resources + generate-resources + + copy-resources + + + src/main/resources + + + resources + + build.properties + p2.inf + + + + + + + + + org.wso2.maven + carbon-p2-plugin + ${carbon.p2.plugin.version} + + + p2-feature-generation + package + + p2-feature-gen + + + org.wso2.mdm.mdmmgt.server + ../../../features/etc/feature.properties + + + + org.wso2.carbon.p2.category.type:server + + org.eclipse.equinox.p2.type.group:false + + + + + + org.wso2.carbon.devicemgt-plugins:org.wso2.mdm.mdmmgt:${project.version} + + + org.wso2.carbon.devicemgt-plugins:org.wso2.mdm.appmgt:${project.version} + + + + + org.wso2.carbon.core.server:${carbon.kernel.version} + + + org.wso2.carbon.apimgt.core:${carbon.api.mgt.version} + + + org.wso2.carbon.device.mgt.extensions:${carbon.device.mgt.version} + + + + com.google.code.gson:gson:${google.gson.version} + + + org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.common:compatible:${carbon.device.mgt.version} + + + org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.core:compatible:${carbon.device.mgt.version} + + + org.wso2.carbon.devicemgt:org.wso2.carbon.policy.mgt.core:compatible:${carbon.device.mgt.version} + + + org.wso2.carbon.appmgt:org.wso2.carbon.appmgt.mobile:compatible:${appmgt.feature.version} + + + + + + + + + \ No newline at end of file diff --git a/features/device-mgt-mdm-feature/org.wso2.mdm.mdmmgt.server.feature/src/main/resources/build.properties b/features/device-mgt-mdm-feature/org.wso2.mdm.mdmmgt.server.feature/src/main/resources/build.properties new file mode 100644 index 0000000000..9c86577d76 --- /dev/null +++ b/features/device-mgt-mdm-feature/org.wso2.mdm.mdmmgt.server.feature/src/main/resources/build.properties @@ -0,0 +1 @@ +custom = true diff --git a/features/device-mgt-mdm-feature/org.wso2.mdm.mdmmgt.server.feature/src/main/resources/p2.inf b/features/device-mgt-mdm-feature/org.wso2.mdm.mdmmgt.server.feature/src/main/resources/p2.inf new file mode 100644 index 0000000000..a828a69832 --- /dev/null +++ b/features/device-mgt-mdm-feature/org.wso2.mdm.mdmmgt.server.feature/src/main/resources/p2.inf @@ -0,0 +1 @@ +instructions.configure = \ diff --git a/features/device-mgt-mdm-feature/pom.xml b/features/device-mgt-mdm-feature/pom.xml index 7c966344de..cd4d0102e7 100644 --- a/features/device-mgt-mdm-feature/pom.xml +++ b/features/device-mgt-mdm-feature/pom.xml @@ -17,7 +17,8 @@ ~ under the License. --> - @@ -36,6 +37,7 @@ org.wso2.carbon.device.mgt.mobile.feature + org.wso2.mdm.mdmmgt.server.feature diff --git a/pom.xml b/pom.xml index 763871c499..d65066782b 100644 --- a/pom.xml +++ b/pom.xml @@ -18,7 +18,8 @@ --> - 4.0.0 @@ -47,6 +48,7 @@ components/device-mgt-iot-virtualfirealarm + components/device-mgt-iot-androidsense features/device-mgt-iot-feature @@ -58,6 +60,7 @@ features/device-mgt-iot-virtualfirealarm-feature + features/device-mgt-iot-androidsense-feature @@ -382,6 +385,23 @@ + + + + + + org.wso2.carbon.devicemgt-plugins + org.wso2.carbon.device.mgt.iot.androidsense + ${carbon.iot.device.mgt.version} + + + org.wso2.carbon.devicemgt-plugins + org.wso2.carbon.device.mgt.iot.androidsense.api + ${carbon.iot.device.mgt.version} + war + + + org.json.wso2 json @@ -442,6 +462,11 @@ org.wso2.carbon.device.mgt.mobile.url.printer ${carbon.mobile.device.mgt.version} + + org.wso2.carbon.devicemgt-plugins + org.wso2.mdm.mdmmgt + ${carbon.mobile.device.mgt.version} + @@ -902,57 +927,57 @@ org.wso2.carbon.appmgt org.wso2.carbon.appmgt.core.feature - ${appmgt..feature.version} + ${appmgt.feature.version} org.wso2.carbon.appmgt org.wso2.carbon.appmgt.feature - ${appmgt..feature.version} + ${appmgt.feature.version} - + org.wso2.carbon.appmgt org.wso2.carbon.appmgt.mdm.wso2emm.feature - ${appmgt..feature.version} + ${appmgt.feature.version} org.wso2.carbon.appmgt org.wso2.carbon.appmgt.mdm.wso2mdm.feature - ${appmgt..feature.version} + ${appmgt.feature.version} org.wso2.carbon.appmgt - org.wso2.carbon.appmgt.mobile.feature - ${appmgt..feature.version} + org.wso2.carbon.appmgt.mobile + ${appmgt.feature.version} org.wso2.carbon.appmgt org.wso2.carbon.appmgt.publisher.feature - ${appmgt..feature.version} + ${appmgt.feature.version} org.wso2.carbon.appmgt org.wso2.carbon.appmgt.services.api.feature - ${appmgt..feature.version} + ${appmgt.feature.version} - + org.wso2.carbon.appmgt org.wso2.carbon.appmgt.store.feature - ${appmgt..feature.version} + ${appmgt.feature.version} @@ -1100,6 +1125,10 @@ 4.3.0 + + 1.1.1 + 1.1.1 + 4.6.0