Remove Response references from Android Service

revert-dabc3590
shamalka 5 years ago
parent b9c04a91e3
commit 0fdff58017

@ -146,7 +146,9 @@ public class DeviceManagementAPIImpl implements DeviceManagementAPI {
}
try {
AndroidService androidService = AndroidAPIUtils.getAndroidService();
return androidService.enrollDevice(androidDevice);
Message message = androidService.enrollDevice(androidDevice);
return Response.status(Integer.parseInt(message.getResponseCode()))
.entity(message.getResponseMessage()).build();
} catch (DeviceManagementException e) {
String msg = "Error occurred while enrolling the android, which carries the id '" +
androidDevice.getDeviceIdentifier() + "'";

@ -89,6 +89,7 @@ import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.WifiBeanWra
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.WipeDataBeanWrapper;
import org.wso2.carbon.device.mgt.mobile.android.common.exception.AndroidDeviceMgtPluginException;
import org.wso2.carbon.device.mgt.mobile.android.common.exception.BadRequestExceptionDup;
import org.wso2.carbon.device.mgt.mobile.android.common.exception.UnexpectedServerErrorExceptionDup;
import org.wso2.carbon.device.mgt.mobile.android.common.spi.AndroidService;
import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidAPIUtils;
import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidDeviceUtils;
@ -1047,8 +1048,22 @@ public class DeviceManagementAdminAPIImpl implements DeviceManagementAdminAPI {
try{
AndroidService androidService = AndroidAPIUtils.getAndroidService();
Response response = androidService.sendApplicationConfiguration(applicationRestrictionBeanWrapper);
ProfileOperation operation = androidService.sendApplicationConfiguration(applicationRestrictionBeanWrapper);
Response response = AndroidAPIUtils.getOperationResponse(applicationRestrictionBeanWrapper.getDeviceIDs(),
operation);
return Response.status(Response.Status.CREATED).entity(response).build();
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
return Response.status(Response.Status.BAD_REQUEST).entity(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_BAD_REQUEST)
.setMessage(errorMessage).build()).build();
} catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance";
log.error(errorMessage, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
new ErrorResponse.ErrorResponseBuilder().setCode(HttpStatusCodes.STATUS_CODE_SERVER_ERROR)
.setMessage(errorMessage).build()).build();
} catch (BadRequestExceptionDup e){
String msg = "Invalid request";
log.error(msg, e);

@ -137,8 +137,8 @@ public class EventReceiverAPIImpl implements EventReceiverAPI {
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
try{
AndroidService androidService = AndroidAPIUtils.getAndroidService();
Response response = androidService.retrieveAlerts(deviceId, from, to, type, ifModifiedSince);
return response;
List<DeviceState> deviceStates = androidService.retrieveAlerts(deviceId, from, to, type, ifModifiedSince);
return Response.status(Response.Status.OK).entity(deviceStates).build();
} catch (BadRequestExceptionDup e){
String msg = "Invalid request";
log.error(msg, e);

@ -117,5 +117,9 @@
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
</dependency>
</dependencies>
</project>

@ -28,9 +28,10 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
import org.wso2.carbon.device.mgt.mobile.android.common.Message;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.AndroidPlatformConfiguration;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.DeviceState;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.EnterpriseTokenUrl;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.GoogleAppSyncResponse;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.*;
@ -380,7 +381,7 @@ public interface AndroidService {
* @return
* @throws {@link AndroidDeviceMgtPluginException}
*/
Response sendApplicationConfiguration(
ProfileOperation sendApplicationConfiguration(
ApplicationRestrictionBeanWrapper applicationRestrictionBeanWrapper)
throws AndroidDeviceMgtPluginException;
@ -427,7 +428,7 @@ public interface AndroidService {
* @return {@link Response}
* @throws {@link DeviceManagementException}
*/
Response enrollDevice(AndroidDevice androidDevice) throws DeviceManagementException, AndroidDeviceMgtPluginException;
Message enrollDevice(AndroidDevice androidDevice) throws DeviceManagementException, AndroidDeviceMgtPluginException;
/**
* Method to check if a device is enrolled
@ -480,6 +481,6 @@ public interface AndroidService {
* @return {@link Response}
* @throws {@link AndroidDeviceMgtPluginException}
*/
Response retrieveAlerts(String deviceId, long from, long to, String type, String ifModifiedSince)
List<DeviceState> retrieveAlerts(String deviceId, long from, long to, String type, String ifModifiedSince)
throws AndroidDeviceMgtPluginException;
}

@ -81,6 +81,8 @@
org.wso2.carbon.analytics.datasource.commons.*,
org.wso2.carbon.base,
com.google.gson.*
org.wso2.carbon.device.application.mgt.common.*
org.wso2.carbon.user.core.
</Import-Package>
<Export-Package>
!org.wso2.carbon.device.mgt.mobile.android.core.internal,

@ -17,6 +17,7 @@
package org.wso2.carbon.device.mgt.mobile.android.core.impl;
import com.google.api.client.http.HttpStatusCodes;
import com.google.api.services.androidenterprise.model.ProductsListResponse;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
@ -63,7 +64,7 @@ import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidEnterpriseUtil
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
@ -222,13 +223,13 @@ public class AndroidServiceImpl implements AndroidService {
if (device != null) {
String status = String.valueOf(device.getEnrolmentInfo().getStatus());
Message responseMessage = new Message();
responseMessage.setResponseCode(Response.Status.OK.toString());
responseMessage.setResponseCode(String.valueOf(HttpStatusCodes.STATUS_CODE_OK));
responseMessage
.setResponseMessage("Status of android device that carries the id '" + id + "' is " + status);
return responseMessage;
} else {
Message responseMessage = new Message();
responseMessage.setResponseCode(Response.Status.NOT_FOUND.toString());
responseMessage.setResponseCode(String.valueOf(HttpStatusCodes.STATUS_CODE_NOT_FOUND));
responseMessage.setResponseMessage("No Android device is found upon the id '" + id + "'");
return responseMessage;
}
@ -824,7 +825,7 @@ public class AndroidServiceImpl implements AndroidService {
}
@Override
public Response sendApplicationConfiguration(ApplicationRestrictionBeanWrapper applicationRestrictionBeanWrapper)
public ProfileOperation sendApplicationConfiguration(ApplicationRestrictionBeanWrapper applicationRestrictionBeanWrapper)
throws AndroidDeviceMgtPluginException {
try {
if (applicationRestrictionBeanWrapper == null || applicationRestrictionBeanWrapper.getOperation() == null) {
@ -837,16 +838,7 @@ public class AndroidServiceImpl implements AndroidService {
operation.setCode(AndroidConstants.OperationCodes.REMOTE_APP_CONFIG);
operation.setType(Operation.Type.PROFILE);
operation.setPayLoad(applicationRestriction.toJSON());
return AndroidAPIUtils.getOperationResponse(applicationRestrictionBeanWrapper.getDeviceIDs(),
operation);
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
throw new BadRequestExceptionDup(errorMessage, e);
} catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance";
log.error(errorMessage, e);
throw new UnexpectedServerErrorExceptionDup(errorMessage);
return operation;
} catch (BadRequestExceptionDup e) {
String errorMessage = "Issue in retrieving device management service instance";
log.error(errorMessage, e);
@ -975,7 +967,7 @@ public class AndroidServiceImpl implements AndroidService {
}
@Override
public Response enrollDevice(AndroidDevice androidDevice)
public Message enrollDevice(AndroidDevice androidDevice)
throws DeviceManagementException, AndroidDeviceMgtPluginException {
try {
String token = null;
@ -1069,21 +1061,21 @@ public class AndroidServiceImpl implements AndroidService {
}
Message responseMessage = new Message();
responseMessage.setResponseCode(Response.Status.OK.toString());
responseMessage.setResponseCode(String.valueOf(HttpStatusCodes.STATUS_CODE_OK));
if (token == null) {
responseMessage.setResponseMessage("Android device, which carries the id '" +
androidDevice.getDeviceIdentifier() + "' has successfully been enrolled");
} else {
responseMessage.setResponseMessage("Google response token" + token);
}
return Response.status(Response.Status.OK).entity(responseMessage).build();
return responseMessage;
} else {
Message responseMessage = new Message();
responseMessage.setResponseCode(Response.Status.INTERNAL_SERVER_ERROR.toString());
responseMessage.setResponseCode(String.valueOf(HttpStatusCodes.STATUS_CODE_SERVER_ERROR));
responseMessage.setResponseMessage("Failed to enroll '" +
device.getType() + "' device, which carries the id '" +
androidDevice.getDeviceIdentifier() + "'");
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(responseMessage).build();
return responseMessage;
}
} catch (PolicyManagementException | InvalidDeviceException | OperationManagementException e) {
String msg = "Error occurred while enforcing default enrollment policy upon android " +
@ -1174,11 +1166,11 @@ public class AndroidServiceImpl implements AndroidService {
}
@Override
public Response retrieveAlerts(String deviceId,
long from,
long to,
String type,
String ifModifiedSince) throws AndroidDeviceMgtPluginException {
public List<DeviceState> retrieveAlerts(String deviceId,
long from,
long to,
String type,
String ifModifiedSince) throws AndroidDeviceMgtPluginException {
if (from != 0l && to != 0l && deviceId != null){
return retrieveAlertFromDate(deviceId, from, to);
} else if (deviceId != null && type != null) {
@ -1194,7 +1186,7 @@ public class AndroidServiceImpl implements AndroidService {
}
}
private Response retrieveAlert(String deviceId) throws NotFoundExceptionDup, UnexpectedServerErrorExceptionDup {
private List<DeviceState> retrieveAlert(String deviceId) throws NotFoundExceptionDup, UnexpectedServerErrorExceptionDup {
if (log.isDebugEnabled()) {
log.debug("Retrieving events for given device Identifier.");
}
@ -1207,7 +1199,7 @@ public class AndroidServiceImpl implements AndroidService {
"published for Device: " + deviceId + ".";
throw new NotFoundExceptionDup(errorMessage);
} else {
return Response.status(Response.Status.OK).entity(deviceStates).build();
return deviceStates;
}
} catch (AnalyticsException e) {
String msg = "Error occurred while getting published events for specific device: " + deviceId + ".";
@ -1216,7 +1208,7 @@ public class AndroidServiceImpl implements AndroidService {
}
}
private Response retrieveAlertFromDate(String deviceId, long from, long to) throws NotFoundExceptionDup, UnexpectedServerErrorExceptionDup {
private List<DeviceState> retrieveAlertFromDate(String deviceId, long from, long to) throws NotFoundExceptionDup, UnexpectedServerErrorExceptionDup {
String fromDate = String.valueOf(from);
String toDate = String.valueOf(to);
if (log.isDebugEnabled()) {
@ -1233,7 +1225,7 @@ public class AndroidServiceImpl implements AndroidService {
throw new NotFoundExceptionDup(errorMessage);
} else {
return Response.status(Response.Status.OK).entity(deviceStates).build();
return deviceStates;
}
} catch (AnalyticsException e) {
String msg = "Error occurred while getting published events for specific " +
@ -1243,7 +1235,7 @@ public class AndroidServiceImpl implements AndroidService {
}
}
private Response retrieveAlertByType(String deviceId, String type) throws NotFoundExceptionDup, UnexpectedServerErrorExceptionDup {
private List<DeviceState> retrieveAlertByType(String deviceId, String type) throws NotFoundExceptionDup, UnexpectedServerErrorExceptionDup {
if (log.isDebugEnabled()) {
log.debug("Retrieving events for given device identifier and type.");
}
@ -1257,7 +1249,7 @@ public class AndroidServiceImpl implements AndroidService {
throw new NotFoundExceptionDup(errorMessage);
} else {
return Response.status(Response.Status.OK).entity(deviceStates).build();
return deviceStates;
}
} catch (AnalyticsException e) {
String msg = "Error occurred while getting published events for specific " +

Loading…
Cancel
Save