Fixed issues in Android JAX-RS app

revert-70aa11f8
harshanL 10 years ago
parent 0ad9d1bd16
commit e60e7b6d7f

@ -48,19 +48,20 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO {
MobileDevice mobileDevice = null;
try {
conn = this.getConnection();
String createDBQuery =
String selectDBQuery =
"SELECT * FROM MBL_DEVICE WHERE MOBILE_DEVICE_ID = ?";
stmt = conn.prepareStatement(createDBQuery);
stmt = conn.prepareStatement(selectDBQuery);
stmt.setString(1, deviceId);
ResultSet resultSet = stmt.executeQuery();
while (resultSet.next()) {
mobileDevice.setMobileDeviceId(resultSet.getString(0));
mobileDevice.setRegId(resultSet.getString(1));
mobileDevice.setImei(resultSet.getString(2));
mobileDevice.setImsi(resultSet.getString(3));
mobileDevice.setOsVersion(resultSet.getString(4));
mobileDevice.setModel(resultSet.getString(5));
mobileDevice.setVendor(resultSet.getString(6));
mobileDevice = new MobileDevice();
mobileDevice.setMobileDeviceId(resultSet.getString(1));
mobileDevice.setRegId(resultSet.getString(2));
mobileDevice.setImei(resultSet.getString(3));
mobileDevice.setImsi(resultSet.getString(4));
mobileDevice.setOsVersion(resultSet.getString(5));
mobileDevice.setModel(resultSet.getString(6));
mobileDevice.setVendor(resultSet.getString(7));
break;
}
} catch (SQLException e) {
@ -117,10 +118,10 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO {
PreparedStatement stmt = null;
try {
conn = this.getConnection();
String createDBQuery =
String updateDBQuery =
"UPDATE MBL_DEVICE SET REG_ID = ?, IMEI = ?, IMSI = ?, OS_VERSION = ?," +
"DEVICE_MODEL = ?, VENDOR = ? WHERE MOBILE_DEVICE_ID = ?";
stmt = conn.prepareStatement(createDBQuery);
stmt = conn.prepareStatement(updateDBQuery);
stmt.setString(1, mobileDevice.getRegId());
stmt.setString(2, mobileDevice.getImei());
stmt.setString(3, mobileDevice.getImsi());
@ -150,9 +151,9 @@ public class MobileDeviceDAOImpl implements MobileDeviceDAO {
PreparedStatement stmt = null;
try {
conn = this.getConnection();
String createDBQuery =
String deleteDBQuery =
"DELETE FROM MBL_DEVICE WHERE MOBILE_DEVICE_ID = ?";
stmt = conn.prepareStatement(createDBQuery);
stmt = conn.prepareStatement(deleteDBQuery);
stmt.setString(1,deviceId);
int rows = stmt.executeUpdate();
if(rows>0){

@ -30,7 +30,6 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.List;
/**
@ -44,7 +43,6 @@ public class Device {
@GET
public List<org.wso2.carbon.device.mgt.common.Device> getAllDevices() {
List<org.wso2.carbon.device.mgt.common.Device> devices = null;
String msg = "";
DeviceManagementService dmService;
@ -56,13 +54,14 @@ public class Device {
}
try {
if (dmService != null) {
devices = dmService.getAllDevices(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
devices = dmService.getAllDevices(
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
Response.status(HttpStatus.SC_OK);
} else {
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
}
} catch (DeviceManagementException e) {
msg = "Error occurred while fetching the device list";
msg = "Error occurred while fetching the device list.";
log.error(msg, e);
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
}
@ -72,10 +71,10 @@ public class Device {
@GET
@Path("{id}")
public org.wso2.carbon.device.mgt.common.Device getDevice(@PathParam("id") String id) {
String msg = "";
DeviceManagementService dmService;
org.wso2.carbon.device.mgt.common.Device device = new org.wso2.carbon.device.mgt.common.Device();
org.wso2.carbon.device.mgt.common.Device device =
new org.wso2.carbon.device.mgt.common.Device();
try {
dmService = AndroidAPIUtils.getDeviceManagementService();
@ -95,7 +94,7 @@ public class Device {
}
} catch (DeviceManagementException e) {
msg = "Error occurred while fetching the device information";
msg = "Error occurred while fetching the device information.";
log.error(msg, e);
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
}
@ -104,8 +103,8 @@ public class Device {
@PUT
@Path("{id}")
public Message updateDevice(@PathParam("id") String id, org.wso2.carbon.device.mgt.common.Device device) {
public Message updateDevice(@PathParam("id") String id,
org.wso2.carbon.device.mgt.common.Device device) {
boolean result = false;
String msg = "";
DeviceManagementService dmService;
@ -118,13 +117,15 @@ public class Device {
}
try {
if (dmService != null) {
device.setType(
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
result = dmService.updateDeviceInfo(device);
if (result) {
Response.status(HttpStatus.SC_OK);
responseMessage.setResponseMessage("Device has modified");
responseMessage.setResponseMessage("Device information has modified successfully.");
} else {
Response.status(HttpStatus.SC_NOT_MODIFIED);
responseMessage.setResponseMessage("Update device has failed");
responseMessage.setResponseMessage("Update device has failed.");
}
} else {
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
@ -133,13 +134,12 @@ public class Device {
}
} catch (DeviceManagementException e) {
msg = "Error occurred while modifying the device information";
msg = "Error occurred while modifying the device information.";
log.error(msg, e);
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
responseMessage.setResponseMessage(msg);
}
return responseMessage;
}
}

@ -42,11 +42,11 @@ 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"}]}
* Request Format : {"deviceIdentifier":"macid","description":"description","ownership":"BYOD",
* "properties":[{"name":"username","value":"harshan"},{"name":"device","value":"Harshan S5"},
* {"name":"imei","value":"356938035643809"},{"name":"imsi","value":"404685505601234"},{"name":"model","value":"Galaxy S5"},
* {"name":"regId","value":"02fab24b2242"},{"name":"vendor","value":"Samsung"},
* {"name":"osVersion","value":"5.0.0"}]}
*
**/
@POST
@ -66,14 +66,16 @@ public class Enrollment {
try {
if (dmService != null) {
device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
device.setType(
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
result = dmService.enrollDevice(device);
Response.status(HttpStatus.SC_CREATED);
responseMsg.setResponseMessage("Device enrollment has succeeded");
return responseMsg;
} else {
responseMsg.setResponseMessage(AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE);
responseMsg.setResponseMessage(
AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE);
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
return responseMsg;
}
@ -106,20 +108,20 @@ public class Enrollment {
result = dmService.isEnrolled(deviceIdentifier);
if (result) {
Response.status(HttpStatus.SC_OK);
responseMsg.setResponseMessage("Device already enroll");
responseMsg.setResponseMessage("Device has already enrolled");
} else {
Response.status(HttpStatus.SC_NOT_FOUND);
responseMsg.setResponseMessage("Device not enroll");
responseMsg.setResponseMessage("Device has not enrolled");
}
return responseMsg;
} else {
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
responseMsg.setResponseMessage(AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE);
responseMsg.setResponseMessage(
AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE);
return responseMsg;
}
} catch (DeviceManagementException e) {
msg = "Error occurred while checking enrollment of the device";
msg = "Error occurred while checking the enrollment of the device.";
log.error(msg, e);
responseMsg.setResponseMessage(msg);
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
@ -128,6 +130,14 @@ public class Enrollment {
}
/*
* Request Format : {"deviceIdentifier":"macid","description":"description","ownership":"BYOD",
* "properties":[{"name":"username","value":"harshan"},{"name":"device","value":"Harshan S5"},
* {"name":"imei","value":"356938035643809"},{"name":"imsi","value":"404685505601234"},{"name":"model","value":"Galaxy S5"},
* {"name":"regId","value":"02fab24b2242"},{"name":"vendor","value":"Samsung"},
* {"name":"osVersion","value":"5.0.0"}]}
*
**/
@PUT
@Path("{id}")
public Message modifyEnrollment(@PathParam("id") String id, Device device) {
@ -144,12 +154,14 @@ public class Enrollment {
try {
if (dmService != null) {
device.setType(
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
result = dmService.modifyEnrollment(device);
if (result) {
responseMsg.setResponseMessage("update device");
responseMsg.setResponseMessage("Device enrollment has updated successfully");
Response.status(HttpStatus.SC_OK);
}else{
} else {
responseMsg.setResponseMessage("Update enrollment has failed");
Response.status(HttpStatus.SC_NOT_MODIFIED);
}
@ -178,7 +190,6 @@ public class Enrollment {
DeviceManagementService dmService;
Message responseMsg = new Message();
try {
dmService = AndroidAPIUtils.getDeviceManagementService();
} finally {
@ -189,9 +200,9 @@ public class Enrollment {
if (dmService != null) {
result = dmService.disenrollDevice(deviceIdentifier);
if (result) {
responseMsg.setResponseMessage("Dis enrolled device");
responseMsg.setResponseMessage("Device has disenrolled successfully");
Response.status(HttpStatus.SC_OK);
}else{
} else {
responseMsg.setResponseMessage("Device not found");
Response.status(HttpStatus.SC_NOT_FOUND);
}

Loading…
Cancel
Save