diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java index a7c6ef815..ffa935461 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java @@ -54,7 +54,13 @@ public class DeviceManager implements DeviceManagerService { boolean status = dms.enrollDevice(device); try { this.getDeviceTypeDAO().getDeviceType(); - this.getDeviceDAO().addDevice(DeviceManagementDAOUtil.convertDevice(device)); + org.wso2.carbon.device.mgt.core.dto.Device deviceDto = DeviceManagementDAOUtil.convertDevice( + device); + + Integer deviceTypeId = this.getDeviceDAO().getDeviceTypeIdByDeviceTypeName(device.getType()); + deviceDto.setDeviceType(deviceTypeId); + this.getDeviceDAO().addDevice(deviceDto); + } catch (DeviceManagementDAOException e) { throw new DeviceManagementException("Error occurred while enrolling the device '" + device.getId() + "'", e); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java index 2c9cb0d58..ea9c148c8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java @@ -37,4 +37,5 @@ public interface DeviceDAO { List getDevices() throws DeviceManagementDAOException; + Integer getDeviceTypeIdByDeviceTypeName(String type) throws DeviceManagementDAOException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java index ec48c4c10..dd8509282 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java @@ -29,6 +29,7 @@ import org.wso2.carbon.device.mgt.core.dto.Status; import javax.sql.DataSource; import java.sql.Connection; import java.sql.PreparedStatement; +import java.sql.ResultSet; import java.sql.SQLException; import java.util.Date; import java.util.List; @@ -101,6 +102,38 @@ public class DeviceDAOImpl implements DeviceDAO { return null; } + @Override + public Integer getDeviceTypeIdByDeviceTypeName(String type) throws DeviceManagementDAOException { + + Connection conn = null; + PreparedStatement stmt = null; + ResultSet resultSet = null; + Integer deviceTypeId = null; + + try { + conn = this.getConnection(); + String createDBQuery = + "SELECT * From DM_DEVICE_TYPE DT WHERE DT.NAME=?"; + + stmt = conn.prepareStatement(createDBQuery); + stmt.setString(1, type); + resultSet = stmt.executeQuery(); + + while(resultSet.next()){ + deviceTypeId = resultSet.getInt(1); + } + + } catch (SQLException e) { + String msg = "Error occurred while fetch device type id for device type '" + type + "'"; + log.error(msg, e); + throw new DeviceManagementDAOException(msg, e); + } finally { + DeviceManagementDAOUtil.cleanupResources(conn, stmt, null); + } + + return deviceTypeId; + } + private Connection getConnection() throws DeviceManagementDAOException { try { return dataSource.getConnection(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java index 5f8128739..60ec9785f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/util/DeviceManagementDAOUtil.java @@ -118,7 +118,7 @@ public final class DeviceManagementDAOUtil { deviceBO.setOwnerId(device.getOwner()); deviceBO.setOwnerShip(device.getOwnership()); deviceBO.setTenantId(DeviceManagementDAOUtil.getTenantId()); - //deviceBO.setDeviceType(Integer.parseInt(device.getType())); + deviceBO.setDeviceIdentificationId(device.getDeviceIdentifier()); return deviceBO; } diff --git a/product/modules/agents/android/jax-rs/pom.xml b/product/modules/agents/android/jax-rs/pom.xml index 49ccbaf32..ff4e139e6 100644 --- a/product/modules/agents/android/jax-rs/pom.xml +++ b/product/modules/agents/android/jax-rs/pom.xml @@ -169,7 +169,7 @@ org.codehaus.jackson jackson-jaxrs - 1.1.1 + 1.9.0 diff --git a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Authentication.java b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Authentication.java index cff7c08fc..b5687928b 100644 --- a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Authentication.java +++ b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Authentication.java @@ -18,8 +18,6 @@ package cdm.api.android; import javax.ws.rs.*; -@Produces({ "application/json", "application/xml" }) -@Consumes({ "application/json", "application/xml" }) @Path("/authenticate/") public class Authentication { @@ -27,16 +25,13 @@ public class Authentication { @Path("/device/") public String authenticateDevice(@FormParam("username") String username, @FormParam("password") String password) { -/* JsonObject result = new JsonObject(); - result.addProperty("senderId", "jwwfowrjwqporqwrpqworpq");*/ - return ""; + return "jwwfowrjwqporqwrpqworpq"; } @POST @Path("/device/license") + @Produces ("text/plain") public String getLicense() { -/* JsonObject result = new JsonObject(); - result.addProperty("licenseText", "License Agreement");*/ - return ""; + return "License Agreement"; } } diff --git a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Enrollment.java b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Enrollment.java index cd68364cc..fca33567e 100644 --- a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Enrollment.java +++ b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Enrollment.java @@ -25,6 +25,7 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; @@ -40,6 +41,14 @@ public class Enrollment { private static Log log = LogFactory.getLog(Enrollment.class); + /* + * Request Format : {"deviceIdentifier":"macid","description":"ww","ownership":"ww", + * "properties":[{"name":"username","value":"ww"},{"name":"device","value":"ww"}, + * {"name":"imei","value":"imei"},{"name":"imsi","value":"imsi"},{"name":"model","value":"mi3"}, + * {"name":"regId","value":"regid"},{"name":"vendor","value":"vendor"}, + * {"name":"osVersion","value":"Lolipop"}]} + * + **/ @POST public Message enrollDevice(Device device) { @@ -57,6 +66,7 @@ public class Enrollment { try { if (dmService != null) { + device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); result = dmService.enrollDevice(device); Response.status(HttpStatus.SC_CREATED); responseMsg.setResponseMessage("Device enrollment has succeeded"); diff --git a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Test.java b/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Test.java deleted file mode 100644 index 2c7e6fd25..000000000 --- a/product/modules/agents/android/jax-rs/src/main/java/cdm/api/android/Test.java +++ /dev/null @@ -1,34 +0,0 @@ -package cdm.api.android; - -import org.wso2.carbon.device.mgt.common.*; -import org.wso2.carbon.device.mgt.common.Device; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Response; -import java.util.ArrayList; -import java.util.List; - - -@Produces({"application/json", "application/xml"}) -@Consumes({"application/json", "application/xml"}) -public class Test { - - @GET - public List getAllDevices() { - - Device dev = new Device(); - dev.setName("test1"); - dev.setDateOfEnrolment(11111111L); - dev.setDateOfLastUpdate(992093209L); - dev.setDescription("sassasaas"); - - ArrayList listdevices = new ArrayList(); - listdevices.add(dev); - - return listdevices; - } - -} diff --git a/product/modules/agents/android/jax-rs/src/main/webapp/WEB-INF/cxf-servlet.xml b/product/modules/agents/android/jax-rs/src/main/webapp/WEB-INF/cxf-servlet.xml index bab3022d9..3f42f416b 100644 --- a/product/modules/agents/android/jax-rs/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/product/modules/agents/android/jax-rs/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -51,9 +51,6 @@ - - - diff --git a/product/modules/distribution/src/repository/dbscripts/cdm/h2.sql b/product/modules/distribution/src/repository/dbscripts/cdm/h2.sql index 29f5b3075..dadcbd080 100644 --- a/product/modules/distribution/src/repository/dbscripts/cdm/h2.sql +++ b/product/modules/distribution/src/repository/dbscripts/cdm/h2.sql @@ -7,7 +7,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE CREATE TABLE IF NOT EXISTS DM_DEVICE ( - ID VARCHAR(20) NOT NULL, + ID INT auto_increment NOT NULL, DESCRIPTION TEXT NULL DEFAULT NULL, NAME VARCHAR(100) NULL DEFAULT NULL, DATE_OF_ENROLLMENT BIGINT NULL DEFAULT NULL, @@ -21,4 +21,6 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE PRIMARY KEY (ID), CONSTRAINT fk_DM_DEVICE_DM_DEVICE_TYPE2 FOREIGN KEY (DEVICE_TYPE_ID ) REFERENCES DM_DEVICE_TYPE (ID ) ON DELETE NO ACTION ON UPDATE NO ACTION -); +); +-- TO:DO - Remove this INSERT sql statement. +Insert into DM_DEVICE_TYPE (ID,NAME) VALUES (1, 'android');