mirror of
https://repository.entgra.net/community/device-mgt-plugins.git
synced 2025-09-16 23:42:15 +00:00
adding modify enrollment capability to save chnages in enrollment such as GCM token update
This commit is contained in:
parent
0ecd669d08
commit
d9a449dd26
@ -276,25 +276,52 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|||||||
@Path("/{id}")
|
@Path("/{id}")
|
||||||
@Override
|
@Override
|
||||||
public Response modifyEnrollment(@PathParam("id") String id, @Valid AndroidDevice androidDevice) {
|
public Response modifyEnrollment(@PathParam("id") String id, @Valid AndroidDevice androidDevice) {
|
||||||
Device device = new Device();
|
Device device;
|
||||||
String msg = "";
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
deviceIdentifier.setId(androidDevice.getDeviceIdentifier());
|
||||||
if(androidDevice.getEnrolmentInfo().getDateOfEnrolment() <= 0){
|
deviceIdentifier.setType(AndroidConstants.DEVICE_TYPE_ANDROID);
|
||||||
msg = "Invalid Enrollment date.";
|
try {
|
||||||
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
device = AndroidAPIUtils.getDeviceManagementService().getDevice(deviceIdentifier);
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
String msg = "Error occurred while getting enrollment details of the Android device that carries the id '" +
|
||||||
|
id + "'";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new UnexpectedServerErrorException(
|
||||||
|
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
|
||||||
}
|
}
|
||||||
if(androidDevice.getEnrolmentInfo().getDateOfLastUpdate() <= 0){
|
|
||||||
msg = "Invalid Last Updated date.";
|
if (androidDevice == null) {
|
||||||
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
String errorMessage = "The payload of the android device enrollment is incorrect.";
|
||||||
|
log.error(errorMessage);
|
||||||
|
throw new org.wso2.carbon.mdm.services.android.exception.BadRequestException(
|
||||||
|
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
|
||||||
|
}
|
||||||
|
if (device == null) {
|
||||||
|
String errorMessage = "The device to be modified doesn't exist.";
|
||||||
|
log.error(errorMessage);
|
||||||
|
throw new org.wso2.carbon.mdm.services.android.exception.BadRequestException(
|
||||||
|
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
|
||||||
|
}
|
||||||
|
if(androidDevice.getEnrolmentInfo() != null){
|
||||||
|
device.setEnrolmentInfo(device.getEnrolmentInfo());
|
||||||
}
|
}
|
||||||
device.setEnrolmentInfo(androidDevice.getEnrolmentInfo());
|
|
||||||
device.getEnrolmentInfo().setOwner(AndroidAPIUtils.getAuthenticatedUser());
|
device.getEnrolmentInfo().setOwner(AndroidAPIUtils.getAuthenticatedUser());
|
||||||
|
if(androidDevice.getDeviceInfo() != null) {
|
||||||
device.setDeviceInfo(androidDevice.getDeviceInfo());
|
device.setDeviceInfo(androidDevice.getDeviceInfo());
|
||||||
|
}
|
||||||
device.setDeviceIdentifier(androidDevice.getDeviceIdentifier());
|
device.setDeviceIdentifier(androidDevice.getDeviceIdentifier());
|
||||||
|
if(androidDevice.getDescription() != null) {
|
||||||
device.setDescription(androidDevice.getDescription());
|
device.setDescription(androidDevice.getDescription());
|
||||||
|
}
|
||||||
|
if(androidDevice.getName() != null) {
|
||||||
device.setName(androidDevice.getName());
|
device.setName(androidDevice.getName());
|
||||||
|
}
|
||||||
|
if(androidDevice.getFeatures() != null) {
|
||||||
device.setFeatures(androidDevice.getFeatures());
|
device.setFeatures(androidDevice.getFeatures());
|
||||||
|
}
|
||||||
|
if(androidDevice.getProperties() != null) {
|
||||||
device.setProperties(androidDevice.getProperties());
|
device.setProperties(androidDevice.getProperties());
|
||||||
|
}
|
||||||
boolean result;
|
boolean result;
|
||||||
try {
|
try {
|
||||||
device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
||||||
@ -313,7 +340,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|||||||
return Response.status(Response.Status.NOT_MODIFIED).entity(responseMessage).build();
|
return Response.status(Response.Status.NOT_MODIFIED).entity(responseMessage).build();
|
||||||
}
|
}
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
msg = "Error occurred while modifying enrollment of the Android device that carries the id '" +
|
String msg = "Error occurred while modifying enrollment of the Android device that carries the id '" +
|
||||||
id + "'";
|
id + "'";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new UnexpectedServerErrorException(
|
throw new UnexpectedServerErrorException(
|
||||||
|
|||||||
@ -159,7 +159,7 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
|
|||||||
stmt.setString(2, properties.get(AndroidPluginConstants.DEVICE_INFO));
|
stmt.setString(2, properties.get(AndroidPluginConstants.DEVICE_INFO));
|
||||||
stmt.setString(3, mobileDevice.getSerial());
|
stmt.setString(3, mobileDevice.getSerial());
|
||||||
stmt.setString(4, mobileDevice.getVendor());
|
stmt.setString(4, mobileDevice.getVendor());
|
||||||
stmt.setString(5, mobileDevice.getMobileDeviceId());
|
stmt.setString(5, properties.get(AndroidPluginConstants.MAC_ADDRESS));
|
||||||
stmt.setString(6, properties.get(AndroidPluginConstants.DEVICE_NAME));
|
stmt.setString(6, properties.get(AndroidPluginConstants.DEVICE_NAME));
|
||||||
stmt.setString(7, mobileDevice.getLatitude());
|
stmt.setString(7, mobileDevice.getLatitude());
|
||||||
stmt.setString(8, mobileDevice.getLongitude());
|
stmt.setString(8, mobileDevice.getLongitude());
|
||||||
@ -167,8 +167,8 @@ public class AndroidDeviceDAOImpl implements MobileDeviceDAO{
|
|||||||
stmt.setString(10, mobileDevice.getImsi());
|
stmt.setString(10, mobileDevice.getImsi());
|
||||||
stmt.setString(11, mobileDevice.getOsVersion());
|
stmt.setString(11, mobileDevice.getOsVersion());
|
||||||
stmt.setString(12, mobileDevice.getModel());
|
stmt.setString(12, mobileDevice.getModel());
|
||||||
stmt.setString(13, mobileDevice.getMobileDeviceId());
|
stmt.setString(13, mobileDevice.getOsBuildDate());
|
||||||
stmt.setString(14, mobileDevice.getOsBuildDate());
|
stmt.setString(14, mobileDevice.getMobileDeviceId());
|
||||||
int rows = stmt.executeUpdate();
|
int rows = stmt.executeUpdate();
|
||||||
if (rows > 0) {
|
if (rows > 0) {
|
||||||
status = true;
|
status = true;
|
||||||
|
|||||||
@ -37,7 +37,7 @@ public final class AndroidPluginConstants {
|
|||||||
public static final String VENDOR = "VENDOR";
|
public static final String VENDOR = "VENDOR";
|
||||||
public static final String OS_VERSION = "OS_VERSION";
|
public static final String OS_VERSION = "OS_VERSION";
|
||||||
public static final String OS_BUILD_DATE = "OS_BUILD_DATE";
|
public static final String OS_BUILD_DATE = "OS_BUILD_DATE";
|
||||||
public static final String MAC_ADDRESS = "MAC_ADDRESS";
|
public static final String MAC_ADDRESS = "MAC";
|
||||||
|
|
||||||
//Properties related to AD_FEATURE table
|
//Properties related to AD_FEATURE table
|
||||||
public static final String ANDROID_FEATURE_ID = "ID";
|
public static final String ANDROID_FEATURE_ID = "ID";
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user