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 { try {
AndroidService androidService = AndroidAPIUtils.getAndroidService(); 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) { } catch (DeviceManagementException e) {
String msg = "Error occurred while enrolling the android, which carries the id '" + String msg = "Error occurred while enrolling the android, which carries the id '" +
androidDevice.getDeviceIdentifier() + "'"; 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.bean.wrapper.WipeDataBeanWrapper;
import org.wso2.carbon.device.mgt.mobile.android.common.exception.AndroidDeviceMgtPluginException; 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.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.common.spi.AndroidService;
import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidAPIUtils; import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidAPIUtils;
import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidDeviceUtils; import org.wso2.carbon.device.mgt.mobile.android.core.util.AndroidDeviceUtils;
@ -1047,8 +1048,22 @@ public class DeviceManagementAdminAPIImpl implements DeviceManagementAdminAPI {
try{ try{
AndroidService androidService = AndroidAPIUtils.getAndroidService(); 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(); 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){ } catch (BadRequestExceptionDup e){
String msg = "Invalid request"; String msg = "Invalid request";
log.error(msg, e); log.error(msg, e);

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

@ -117,5 +117,9 @@
<groupId>org.codehaus.jackson</groupId> <groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId> <artifactId>jackson-core-asl</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </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.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; 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.Message;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.AndroidPlatformConfiguration; 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.EnterpriseTokenUrl;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.GoogleAppSyncResponse; import org.wso2.carbon.device.mgt.mobile.android.common.bean.GoogleAppSyncResponse;
import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.*; import org.wso2.carbon.device.mgt.mobile.android.common.bean.wrapper.*;
@ -380,7 +381,7 @@ public interface AndroidService {
* @return * @return
* @throws {@link AndroidDeviceMgtPluginException} * @throws {@link AndroidDeviceMgtPluginException}
*/ */
Response sendApplicationConfiguration( ProfileOperation sendApplicationConfiguration(
ApplicationRestrictionBeanWrapper applicationRestrictionBeanWrapper) ApplicationRestrictionBeanWrapper applicationRestrictionBeanWrapper)
throws AndroidDeviceMgtPluginException; throws AndroidDeviceMgtPluginException;
@ -427,7 +428,7 @@ public interface AndroidService {
* @return {@link Response} * @return {@link Response}
* @throws {@link DeviceManagementException} * @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 * Method to check if a device is enrolled
@ -480,6 +481,6 @@ public interface AndroidService {
* @return {@link Response} * @return {@link Response}
* @throws {@link AndroidDeviceMgtPluginException} * @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; throws AndroidDeviceMgtPluginException;
} }

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

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

Loading…
Cancel
Save