Merge branch 'master' into 'master'

Update APPM subscriptions when operation log updates

See merge request entgra/carbon-device-mgt!812
master
Dharmakeerthi Lasantha 3 years ago
commit 7cf68d7975

@ -37,6 +37,7 @@
package org.wso2.carbon.device.mgt.jaxrs.service.impl;
import com.google.gson.Gson;
import io.entgra.application.mgt.common.services.ApplicationManager;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
@ -1417,9 +1418,15 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
Operation operation = DeviceMgtAPIUtils.validateOperationStatusBean(operationStatusBean);
operation.setId(operationStatusBean.getOperationId());
DeviceMgtAPIUtils.getDeviceManagementService().updateOperation(device, operation);
if (MDMAppConstants.AndroidConstants.OPCODE_INSTALL_APPLICATION.equals(operation.getCode()) ||
MDMAppConstants.AndroidConstants.OPCODE_UNINSTALL_APPLICATION.equals(operation.getCode())) {
ApplicationManager applicationManager = DeviceMgtAPIUtils.getApplicationManager();
applicationManager.updateSubsStatus(device.getId(), operation.getId(),operation.getStatus().toString());
}
return Response.status(Response.Status.OK).entity("OperationStatus updated successfully.").build();
} catch (BadRequestException e) {
String msg = "Error occured due to invalid request";
String msg = "Error occurred due to invalid request";
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (DeviceManagementException e) {
@ -1430,7 +1437,11 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
String msg = "Error occurred when updating operation of device " + deviceIdentifier;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
} catch (io.entgra.application.mgt.common.exception.ApplicationManagementException e) {
String msg = "Error occurred when updating the application subscription status of the operation. " +
"The device identifier is: " + deviceIdentifier;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); }
}
@GET

@ -35,6 +35,7 @@
package org.wso2.carbon.device.mgt.jaxrs.util;
import io.entgra.application.mgt.common.services.ApplicationManager;
import org.apache.axis2.AxisFault;
import org.apache.axis2.client.Options;
import org.apache.axis2.java.security.SSLProtocolSocketFactory;
@ -172,6 +173,7 @@ public class DeviceMgtAPIUtils {
private static OTPManagementService otpManagementService;
private static volatile SubscriptionManager subscriptionManager;
private static volatile ApplicationManager applicationManager;
static {
String keyStorePassword = ServerConfiguration.getInstance().getFirstProperty("Security.KeyStore.Password");
@ -233,6 +235,23 @@ public class DeviceMgtAPIUtils {
return subscriptionManager;
}
public static ApplicationManager getApplicationManager() {
if (applicationManager == null) {
synchronized (DeviceMgtAPIUtils.class) {
if (applicationManager == null) {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
applicationManager =
(ApplicationManager) ctx.getOSGiService(ApplicationManager.class, null);
if (applicationManager == null) {
String msg = "Application Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
}
}
}
return applicationManager;
}
public static void scheduleTaskService(int notifierFrequency) {
TaskScheduleService taskScheduleService;

Loading…
Cancel
Save