Fixed issues in enrollment process

merge-requests/1/head
harshanL 10 years ago
parent 624d6eb6ef
commit 9ba2c0198c

@ -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);

@ -37,4 +37,5 @@ public interface DeviceDAO {
List<Device> getDevices() throws DeviceManagementDAOException;
Integer getDeviceTypeIdByDeviceTypeName(String type) throws DeviceManagementDAOException;
}

@ -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();

@ -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;
}

@ -169,7 +169,7 @@
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
<version>1.1.1</version>
<version>1.9.0</version>
</dependency>
</dependencies>
<properties>

@ -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";
}
}

@ -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");

@ -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<org.wso2.carbon.device.mgt.common.Device> getAllDevices() {
Device dev = new Device();
dev.setName("test1");
dev.setDateOfEnrolment(11111111L);
dev.setDateOfLastUpdate(992093209L);
dev.setDescription("sassasaas");
ArrayList<Device> listdevices = new ArrayList<Device>();
listdevices.add(dev);
return listdevices;
}
}

@ -51,9 +51,6 @@
<bean id="serviceBean" class="cdm.api.android.Authentication"/>
<bean id="deviceMgtServiceBean" class="cdm.api.android.Device"/>
<bean id="enrollmentServiceBean" class="cdm.api.android.Enrollment"/>
<bean id="testServiceBean" class="cdm.api.android.Test"/>
<bean id="jsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>
</beans>

@ -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,
@ -22,3 +22,5 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE
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');

Loading…
Cancel
Save