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.")
public class Notification extends AndroidOperation implements Serializable {
@ApiModelProperty(name = "message", value = "The message to be sent to the device.", required = true)
private String message;
@ApiModelProperty(name = "messageText", value = "The message text to be sent to the device.", required = true)
private String messageText;
public String getMessage() {
return message;
@ApiModelProperty(name = "messageTitle", value = "The message title to be sent to the device.", required = true)
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) {
this.message = message;
public void setMessageTitle(String messageTitle) {
this.messageTitle = messageTitle;
}
}

@ -29,15 +29,31 @@ import java.io.Serializable;
@ApiModel(value = "UpgradeFirmware",
description = "This class carries all information related to UpgradeFirmware.")
public class UpgradeFirmware extends AndroidOperation implements Serializable {
@ApiModelProperty(name = "schedule", value = "Schedule of the UpgradeFirmware.", required = true)
private String schedule;
@ApiModelProperty(name = "server", value = "Firmware package server.")
private String server;
@SuppressWarnings("unused")
public String getSchedule() {
return schedule;
}
@SuppressWarnings("unused")
public void setSchedule(String 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.setType(Operation.Type.PROFILE);
operation.setPayLoad(upgradeFirmware.toJSON());
return AndroidAPIUtils.getOperationResponse(upgradeFirmwareBeanWrapper.getDeviceIDs(),
operation);
return AndroidAPIUtils.getOperationResponse(upgradeFirmwareBeanWrapper.getDeviceIDs(), operation);
} catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance";
log.error(errorMessage, e);

@ -74,8 +74,6 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
}
}
@PUT
@Path("/{id}/pending-operations")
@Override
@ -85,14 +83,14 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
if (id == null || id.isEmpty()) {
String msg = "Device identifier is null or empty, hence returning device not found";
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);
try {
if (!AndroidDeviceUtils.isValidDeviceIdentifier(deviceIdentifier)) {
String msg = "Device not found for identifier '" + id + "'";
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()) {
log.debug("Invoking Android pending operations:" + id);
@ -133,7 +131,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
} catch (OperationManagementException e) {
String msg = "Issue in retrieving operation management service instance";
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();
}

@ -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.app.mgt.Application;
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.notification.mgt.NotificationManagementService;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
@ -277,8 +278,7 @@ public class AndroidAPIUtils {
try {
Device device = new Gson().fromJson(operation.getOperationResponse(), Device.class);
org.wso2.carbon.device.mgt.common.device.details.DeviceInfo deviceInfo = convertDeviceToInfo(device);
deviceInfo.setDeviceIdentifier(deviceIdentifier);
updateDeviceInfo(deviceInfo);
updateDeviceInfo(deviceIdentifier, deviceInfo);
} catch (DeviceDetailsMgtException e) {
throw new OperationManagementException("Error occurred while updating the device information.", e);
}
@ -312,6 +312,7 @@ public class AndroidAPIUtils {
private static void updateApplicationList(Operation operation, DeviceIdentifier deviceIdentifier)
throws ApplicationManagementException {
// Parsing json string to get applications list.
if (operation.getOperationResponse() != null) {
JsonElement jsonElement = new JsonParser().parse(operation.getOperationResponse());
JsonArray jsonArray = jsonElement.getAsJsonArray();
Application app;
@ -332,6 +333,10 @@ public class AndroidAPIUtils {
applications.add(app);
}
getApplicationManagerService().updateApplicationListInstalledInDevice(deviceIdentifier, applications);
} else {
log.error("Operation Response is null.");
}
}
@ -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 {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
DeviceInformationManager informationManager =
(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_FEATURES_KEY = "features";
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 =
"Issue in retrieving device management service instance for device found at %s";
}

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

Loading…
Cancel
Save