Merge branch 'rest-api-improvements' of https://github.com/wso2/carbon-device-mgt-plugins into rest-api-improvements

revert-dabc3590
inoshperera 9 years ago
commit 90747a5579

@ -30,14 +30,25 @@ import java.io.Serializable;
description = "Details related to notifications passed to device.") description = "Details related to notifications passed to device.")
public class Notification extends AndroidOperation implements Serializable { public class Notification extends AndroidOperation implements Serializable {
@ApiModelProperty(name = "message", value = "The message to be sent to the device.", required = true) @ApiModelProperty(name = "messageText", value = "The message text to be sent to the device.", required = true)
private String message; private String messageText;
public String getMessage() { @ApiModelProperty(name = "messageTitle", value = "The message title to be sent to the device.", required = true)
return message; private String messageTitle;
public String getMessageText() {
return messageText;
}
public void setMessageText(String messageText) {
this.messageText = messageText;
}
public String getMessageTitle() {
return messageTitle;
} }
public void setMessage(String message) { public void setMessageTitle(String messageTitle) {
this.message = message; this.messageTitle = messageTitle;
} }
} }

@ -29,15 +29,31 @@ import java.io.Serializable;
@ApiModel(value = "UpgradeFirmware", @ApiModel(value = "UpgradeFirmware",
description = "This class carries all information related to UpgradeFirmware.") description = "This class carries all information related to UpgradeFirmware.")
public class UpgradeFirmware extends AndroidOperation implements Serializable { public class UpgradeFirmware extends AndroidOperation implements Serializable {
@ApiModelProperty(name = "schedule", value = "Schedule of the UpgradeFirmware.", required = true) @ApiModelProperty(name = "schedule", value = "Schedule of the UpgradeFirmware.", required = true)
private String schedule; private String schedule;
@ApiModelProperty(name = "server", value = "Firmware package server.")
private String server;
@SuppressWarnings("unused")
public String getSchedule() { public String getSchedule() {
return schedule; return schedule;
} }
@SuppressWarnings("unused")
public void setSchedule(String schedule) { public void setSchedule(String schedule) {
this.schedule = schedule; this.schedule = schedule;
} }
@SuppressWarnings("unused")
public String getServer() {
return server;
}
@SuppressWarnings("unused")
public void setServer(String server) {
this.server = server;
}
} }

@ -543,8 +543,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setCode(AndroidConstants.OperationCodes.UPGRADE_FIRMWARE); operation.setCode(AndroidConstants.OperationCodes.UPGRADE_FIRMWARE);
operation.setType(Operation.Type.PROFILE); operation.setType(Operation.Type.PROFILE);
operation.setPayLoad(upgradeFirmware.toJSON()); operation.setPayLoad(upgradeFirmware.toJSON());
return AndroidAPIUtils.getOperationResponse(upgradeFirmwareBeanWrapper.getDeviceIDs(), return AndroidAPIUtils.getOperationResponse(upgradeFirmwareBeanWrapper.getDeviceIDs(), operation);
operation);
} catch (OperationManagementException e) { } catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance"; String errorMessage = "Issue in retrieving operation management service instance";
log.error(errorMessage, e); log.error(errorMessage, e);

@ -74,8 +74,6 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
} }
} }
@PUT @PUT
@Path("/{id}/pending-operations") @Path("/{id}/pending-operations")
@Override @Override
@ -85,14 +83,14 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
if (id == null || id.isEmpty()) { if (id == null || id.isEmpty()) {
String msg = "Device identifier is null or empty, hence returning device not found"; String msg = "Device identifier is null or empty, hence returning device not found";
log.error(msg); log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} }
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id); DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
try { try {
if (!AndroidDeviceUtils.isValidDeviceIdentifier(deviceIdentifier)) { if (!AndroidDeviceUtils.isValidDeviceIdentifier(deviceIdentifier)) {
String msg = "Device not found for identifier '" + id + "'"; String msg = "Device not found for identifier '" + id + "'";
log.error(msg); log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} }
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Invoking Android pending operations:" + id); log.debug("Invoking Android pending operations:" + id);
@ -133,7 +131,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
} catch (OperationManagementException e) { } catch (OperationManagementException e) {
String msg = "Issue in retrieving operation management service instance"; String msg = "Issue in retrieving operation management service instance";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
} }
return Response.status(Response.Status.CREATED).entity(pendingOperations).build(); return Response.status(Response.Status.CREATED).entity(pendingOperations).build();
} }

@ -36,6 +36,7 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.app.mgt.Application; 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.ApplicationManagementException;
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation; import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService; import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
@ -277,8 +278,7 @@ public class AndroidAPIUtils {
try { try {
Device device = new Gson().fromJson(operation.getOperationResponse(), Device.class); Device device = new Gson().fromJson(operation.getOperationResponse(), Device.class);
org.wso2.carbon.device.mgt.common.device.details.DeviceInfo deviceInfo = convertDeviceToInfo(device); org.wso2.carbon.device.mgt.common.device.details.DeviceInfo deviceInfo = convertDeviceToInfo(device);
deviceInfo.setDeviceIdentifier(deviceIdentifier); updateDeviceInfo(deviceIdentifier, deviceInfo);
updateDeviceInfo(deviceInfo);
} catch (DeviceDetailsMgtException e) { } catch (DeviceDetailsMgtException e) {
throw new OperationManagementException("Error occurred while updating the device information.", e); throw new OperationManagementException("Error occurred while updating the device information.", e);
} }
@ -312,26 +312,31 @@ public class AndroidAPIUtils {
private static void updateApplicationList(Operation operation, DeviceIdentifier deviceIdentifier) private static void updateApplicationList(Operation operation, DeviceIdentifier deviceIdentifier)
throws ApplicationManagementException { throws ApplicationManagementException {
// Parsing json string to get applications list. // Parsing json string to get applications list.
JsonElement jsonElement = new JsonParser().parse(operation.getOperationResponse()); if (operation.getOperationResponse() != null) {
JsonArray jsonArray = jsonElement.getAsJsonArray(); JsonElement jsonElement = new JsonParser().parse(operation.getOperationResponse());
Application app; JsonArray jsonArray = jsonElement.getAsJsonArray();
List<Application> applications = new ArrayList<Application>(jsonArray.size()); Application app;
for (JsonElement element : jsonArray) { List<Application> applications = new ArrayList<Application>(jsonArray.size());
app = new Application(); for (JsonElement element : jsonArray) {
app.setName(element.getAsJsonObject(). app = new Application();
get(AndroidConstants.ApplicationProperties.NAME).getAsString()); app.setName(element.getAsJsonObject().
app.setApplicationIdentifier(element.getAsJsonObject(). get(AndroidConstants.ApplicationProperties.NAME).getAsString());
get(AndroidConstants.ApplicationProperties.IDENTIFIER).getAsString()); app.setApplicationIdentifier(element.getAsJsonObject().
app.setPlatform(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID); get(AndroidConstants.ApplicationProperties.IDENTIFIER).getAsString());
if (element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.USS) != null) { app.setPlatform(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
app.setMemoryUsage(element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.USS).getAsInt()); if (element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.USS) != null) {
} app.setMemoryUsage(element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.USS).getAsInt());
if (element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.VERSION) != null) { }
app.setVersion(element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.VERSION).getAsString()); if (element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.VERSION) != null) {
app.setVersion(element.getAsJsonObject().get(AndroidConstants.ApplicationProperties.VERSION).getAsString());
}
applications.add(app);
} }
applications.add(app); getApplicationManagerService().updateApplicationListInstalledInDevice(deviceIdentifier, applications);
} else {
log.error("Operation Response is null.");
} }
getApplicationManagerService().updateApplicationListInstalledInDevice(deviceIdentifier, applications);
} }
@ -344,14 +349,14 @@ public class AndroidAPIUtils {
} }
private static void updateDeviceInfo(org.wso2.carbon.device.mgt.common.device.details.DeviceInfo deviceInfo) private static void updateDeviceInfo(DeviceIdentifier deviceId, DeviceInfo deviceInfo)
throws DeviceDetailsMgtException { throws DeviceDetailsMgtException {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
DeviceInformationManager informationManager = DeviceInformationManager informationManager =
(DeviceInformationManager) ctx.getOSGiService(DeviceInformationManager.class, null); (DeviceInformationManager) ctx.getOSGiService(DeviceInformationManager.class, null);
informationManager.addDeviceInfo(deviceInfo); informationManager.addDeviceInfo(deviceId, deviceInfo);
} }

@ -51,7 +51,7 @@ public final class AndroidConstants {
public static final String DEVICE_PROPERTIES_KEY = "properties"; public static final String DEVICE_PROPERTIES_KEY = "properties";
public static final String DEVICE_FEATURES_KEY = "features"; public static final String DEVICE_FEATURES_KEY = "features";
public static final String DEVICE_DATA = "data"; public static final String DEVICE_DATA = "data";
public static final String DEVICE_ID_NOT_FOUND = "Device Id not found for device found at %s"; public static final String DEVICE_ID_NOT_FOUND = "Device not found for device id: %s";
public static final String DEVICE_ID_SERVICE_NOT_FOUND = public static final String DEVICE_ID_SERVICE_NOT_FOUND =
"Issue in retrieving device management service instance for device found at %s"; "Issue in retrieving device management service instance for device found at %s";
} }

@ -55,8 +55,8 @@ public class AndroidDeviceUtils {
if (isValidDeviceIdentifier(deviceIdentifier)) { if (isValidDeviceIdentifier(deviceIdentifier)) {
validDeviceIDList.add(deviceIdentifier); validDeviceIDList.add(deviceIdentifier);
} else { } else {
errorDeviceIdList.add(String.format(AndroidConstants.DeviceConstants.DEVICE_ID_NOT_FOUND, errorDeviceIdList.add(String.format(AndroidConstants.DeviceConstants.
deviceIDCounter)); DEVICE_ID_NOT_FOUND, deviceID));
} }
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
errorDeviceIdList.add(String.format(AndroidConstants.DeviceConstants.DEVICE_ID_SERVICE_NOT_FOUND, errorDeviceIdList.add(String.format(AndroidConstants.DeviceConstants.DEVICE_ID_SERVICE_NOT_FOUND,

Loading…
Cancel
Save