|
|
@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.core.operation.mgt;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.wso2.carbon.context.CarbonContext;
|
|
|
|
import org.wso2.carbon.context.CarbonContext;
|
|
|
|
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
import org.wso2.carbon.device.mgt.common.Device;
|
|
|
|
import org.wso2.carbon.device.mgt.common.Device;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
@ -67,7 +68,9 @@ import java.util.ArrayList;
|
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* This class implements all the functionality exposed as part of the OperationManager. Any transaction initiated
|
|
|
|
* This class implements all the functionality exposed as part of the OperationManager. Any transaction initiated
|
|
|
@ -88,10 +91,10 @@ public class OperationManagerImpl implements OperationManager {
|
|
|
|
private OperationDAO operationDAO;
|
|
|
|
private OperationDAO operationDAO;
|
|
|
|
private DeviceDAO deviceDAO;
|
|
|
|
private DeviceDAO deviceDAO;
|
|
|
|
private EnrollmentDAO enrollmentDAO;
|
|
|
|
private EnrollmentDAO enrollmentDAO;
|
|
|
|
private NotificationStrategy notificationStrategy;
|
|
|
|
|
|
|
|
private String deviceType;
|
|
|
|
private String deviceType;
|
|
|
|
private DeviceManagementService deviceManagementService;
|
|
|
|
private DeviceManagementService deviceManagementService;
|
|
|
|
private long lastUpdatedTimeStamp = 0;
|
|
|
|
private Map<Integer, NotificationStrategy> notificationStrategies;
|
|
|
|
|
|
|
|
private Map<Integer, Long> lastUpdatedTimeStamps;
|
|
|
|
|
|
|
|
|
|
|
|
public OperationManagerImpl() {
|
|
|
|
public OperationManagerImpl() {
|
|
|
|
commandOperationDAO = OperationManagementDAOFactory.getCommandOperationDAO();
|
|
|
|
commandOperationDAO = OperationManagementDAOFactory.getCommandOperationDAO();
|
|
|
@ -102,6 +105,8 @@ public class OperationManagerImpl implements OperationManager {
|
|
|
|
operationDAO = OperationManagementDAOFactory.getOperationDAO();
|
|
|
|
operationDAO = OperationManagementDAOFactory.getOperationDAO();
|
|
|
|
deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
|
|
|
deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
|
|
|
enrollmentDAO = DeviceManagementDAOFactory.getEnrollmentDAO();
|
|
|
|
enrollmentDAO = DeviceManagementDAOFactory.getEnrollmentDAO();
|
|
|
|
|
|
|
|
notificationStrategies = new HashMap<>();
|
|
|
|
|
|
|
|
lastUpdatedTimeStamps = new HashMap<>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public OperationManagerImpl(String deviceType, DeviceManagementService deviceManagementService) {
|
|
|
|
public OperationManagerImpl(String deviceType, DeviceManagementService deviceManagementService) {
|
|
|
@ -111,23 +116,32 @@ public class OperationManagerImpl implements OperationManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public NotificationStrategy getNotificationStrategy() {
|
|
|
|
public NotificationStrategy getNotificationStrategy() {
|
|
|
|
|
|
|
|
// Notification strategy can be set by the platform configurations. Therefore it is needed to
|
|
|
|
|
|
|
|
// get tenant specific notification strategy dynamically in the runtime. However since this is
|
|
|
|
|
|
|
|
// a resource intensive retrieval, we are maintaining tenant aware local cache here to keep device
|
|
|
|
|
|
|
|
// type specific notification strategy.
|
|
|
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(false);
|
|
|
|
|
|
|
|
long lastUpdatedTimeStamp = 0;
|
|
|
|
|
|
|
|
if (lastUpdatedTimeStamps.containsKey(tenantId)){
|
|
|
|
|
|
|
|
lastUpdatedTimeStamp = lastUpdatedTimeStamps.get(tenantId);
|
|
|
|
|
|
|
|
}
|
|
|
|
if (Calendar.getInstance().getTimeInMillis() - lastUpdatedTimeStamp > CACHE_VALIDITY_PERIOD) {
|
|
|
|
if (Calendar.getInstance().getTimeInMillis() - lastUpdatedTimeStamp > CACHE_VALIDITY_PERIOD) {
|
|
|
|
PushNotificationConfig pushNoteConfig = deviceManagementService.getPushNotificationConfig();
|
|
|
|
PushNotificationConfig pushNoteConfig = deviceManagementService.getPushNotificationConfig();
|
|
|
|
if (pushNoteConfig != null && !NOTIFIER_TYPE_LOCAL.equals(pushNoteConfig.getType())) {
|
|
|
|
if (pushNoteConfig != null && !NOTIFIER_TYPE_LOCAL.equals(pushNoteConfig.getType())) {
|
|
|
|
PushNotificationProvider provider = DeviceManagementDataHolder.getInstance()
|
|
|
|
PushNotificationProvider provider = DeviceManagementDataHolder.getInstance()
|
|
|
|
.getPushNotificationProviderRepository().getProvider(pushNoteConfig.getType());
|
|
|
|
.getPushNotificationProviderRepository().getProvider(pushNoteConfig.getType());
|
|
|
|
if (provider == null) {
|
|
|
|
if (provider == null) {
|
|
|
|
log.error("No registered push notification provider found for the type: '" +
|
|
|
|
log.error("No registered push notification provider found for the type '" +
|
|
|
|
pushNoteConfig.getType() + "'.");
|
|
|
|
pushNoteConfig.getType() + "' under tenant ID '" + tenantId + "'.");
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
notificationStrategy = provider.getNotificationStrategy(pushNoteConfig);
|
|
|
|
notificationStrategies.put(tenantId, provider.getNotificationStrategy(pushNoteConfig));
|
|
|
|
} else {
|
|
|
|
} else if (notificationStrategies.containsKey(tenantId)){
|
|
|
|
notificationStrategy = null;
|
|
|
|
notificationStrategies.remove(tenantId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lastUpdatedTimeStamp = Calendar.getInstance().getTimeInMillis();
|
|
|
|
lastUpdatedTimeStamps.put(tenantId, Calendar.getInstance().getTimeInMillis());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return notificationStrategy;
|
|
|
|
return notificationStrategies.get(tenantId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -164,7 +178,7 @@ public class OperationManagerImpl implements OperationManager {
|
|
|
|
boolean isScheduledOperation = this.isTaskScheduledOperation(operation);
|
|
|
|
boolean isScheduledOperation = this.isTaskScheduledOperation(operation);
|
|
|
|
boolean isNotRepeated = false;
|
|
|
|
boolean isNotRepeated = false;
|
|
|
|
boolean isScheduled = false;
|
|
|
|
boolean isScheduled = false;
|
|
|
|
notificationStrategy = getNotificationStrategy();
|
|
|
|
NotificationStrategy notificationStrategy = getNotificationStrategy();
|
|
|
|
|
|
|
|
|
|
|
|
// check whether device list is greater than batch size notification strategy has enable to send push
|
|
|
|
// check whether device list is greater than batch size notification strategy has enable to send push
|
|
|
|
// notification using scheduler task
|
|
|
|
// notification using scheduler task
|
|
|
|