mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Add opeerations mapping map for tenants and fixes for code review
This commit is contained in:
parent
8df87b23bc
commit
3938064210
@ -40,6 +40,7 @@ public class PushNotificationConfig {
|
||||
return type;
|
||||
}
|
||||
|
||||
@XmlElement(name = "isScheduled")
|
||||
public boolean isScheduled() {
|
||||
return isScheduled;
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ public class Operation implements Serializable {
|
||||
}
|
||||
|
||||
public enum PushStatus {
|
||||
SCHEDULED, IN_PROGRESS, COMPLETED
|
||||
SCHEDULED, COMPLETED
|
||||
}
|
||||
|
||||
private String code;
|
||||
|
||||
@ -63,9 +63,7 @@ import org.wso2.carbon.utils.ConfigurationContextService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@ -200,7 +198,7 @@ public class DeviceManagementServiceComponent {
|
||||
config.getPushNotificationConfiguration().setSchedulerBatchDelayMills(DeviceManagementConstants.PushNotifications
|
||||
.DEFAULT_BATCH_DELAY_MILLS);
|
||||
}
|
||||
ScheduledExecutorService pushNotificationExecutor = Executors.newScheduledThreadPool(1);
|
||||
ScheduledExecutorService pushNotificationExecutor = Executors.newSingleThreadScheduledExecutor();
|
||||
pushNotificationExecutor.schedule(new PushNotificationSchedulerTask(), config.getPushNotificationConfiguration()
|
||||
.getSchedulerBatchDelayMills(), TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@ -131,7 +131,7 @@ public class OperationManagerImpl implements OperationManager {
|
||||
DeviceIDHolder deviceAuthorizationResult = this.authorizeDevices(operation, validDeviceIds);
|
||||
List<DeviceIdentifier> authorizedDeviceList = deviceAuthorizationResult.getValidDeviceIDList();
|
||||
if (authorizedDeviceList.size() <= 0) {
|
||||
log.info("User : " + getUser() + " is not authorized to perform operations on given device-list.");
|
||||
log.warn("User : " + getUser() + " is not authorized to perform operations on given device-list.");
|
||||
Activity activity = new Activity();
|
||||
//Send the operation statuses only for admin triggered operations
|
||||
String deviceType = validDeviceIds.get(0).getType();
|
||||
@ -191,7 +191,7 @@ public class OperationManagerImpl implements OperationManager {
|
||||
if (notificationStrategy != null && !isScheduled) {
|
||||
try {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Sending push notification to " + deviceId + " add operation thread.");
|
||||
log.debug("Sending push notification to " + deviceId + " from add operation method.");
|
||||
}
|
||||
notificationStrategy.execute(new NotificationContext(deviceId, operation));
|
||||
operationMappingDAO.updateOperationMapping(operationId, enrolmentId, org.wso2.carbon
|
||||
|
||||
@ -25,6 +25,7 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.OperationResponse;
|
||||
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface OperationDAO {
|
||||
|
||||
@ -81,7 +82,15 @@ public interface OperationDAO {
|
||||
|
||||
boolean resetAttemptCount(int enrolmentId) throws OperationManagementDAOException;
|
||||
|
||||
List<OperationMapping> getOperationMappingsByStatus(Operation.Status opStatus, Operation.PushStatus pushStatus,
|
||||
int limit) throws OperationManagementDAOException;;
|
||||
/**
|
||||
* This method provides operation mappings for given status
|
||||
* @param opStatus Operation status
|
||||
* @param pushStatus Push notification Status
|
||||
* @param limit Limit for no devices
|
||||
* @return Tenant based operation mappings list
|
||||
* @throws OperationManagementDAOException
|
||||
*/
|
||||
Map<Integer, List<OperationMapping>> getOperationMappingsByStatus(Operation.Status opStatus, Operation.PushStatus pushStatus,
|
||||
int limit) throws OperationManagementDAOException;;
|
||||
|
||||
}
|
||||
@ -24,9 +24,9 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.ActivityStatus;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMapping;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationResponse;
|
||||
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMapping;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationDAO;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
|
||||
@ -46,8 +46,10 @@ import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This class holds the generic implementation of OperationDAO which can be used to support ANSI db syntax.
|
||||
@ -1093,32 +1095,35 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OperationMapping> getOperationMappingsByStatus(Operation.Status opStatus, Operation.PushStatus pushStatus,
|
||||
int limit) throws OperationManagementDAOException {
|
||||
|
||||
public Map<Integer, List<OperationMapping>> getOperationMappingsByStatus(Operation.Status opStatus, Operation.PushStatus pushStatus,
|
||||
int limit) throws OperationManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
OperationMapping operationMapping;
|
||||
List<OperationMapping> operationMappings = new LinkedList<>();
|
||||
Map<Integer, List<OperationMapping>> operationMappingsTenantMap = new HashMap<>();
|
||||
try {
|
||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||
String sql = "SELECT op_mappings.ENROLMENT_ID, op_mappings.OPERATION_ID, d_type.NAME ,d.TENANT_ID FROM " +
|
||||
"DM_DEVICE d, DM_ENROLMENT_OP_MAPPING op_mappings, DM_DEVICE_TYPE d_type WHERE op_mappings" +
|
||||
".STATUS = '?' AND op_mappings.PUSH_NOTIFICATION_STATUS = '?' AND d.DEVICE_TYPE_ID = d_type.ID " +
|
||||
"AND d.ID=op_mappings.ENROLMENT_ID ORDER BY op_mappings.OPERATION_ID LIMIT ?";
|
||||
|
||||
String sql = "SELECT op.ENROLMENT_ID, op.OPERATION_ID, dt.NAME ,d.TENANT_ID FROM DM_DEVICE d, " +
|
||||
"DM_ENROLMENT_OP_MAPPING op, DM_DEVICE_TYPE dt WHERE op.STATUS = '?' AND " +
|
||||
"op.PUSH_NOTIFICATION_STATUS = '?' AND d.DEVICE_TYPE_ID = dt.ID AND d.ID=op.ENROLMENT_ID ORDER BY " +
|
||||
"op.OPERATION_ID LIMIT ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, opStatus.toString());
|
||||
stmt.setString(2, pushStatus.toString());
|
||||
stmt.setInt(3, limit);
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
int tenantID = rs.getInt("TENANT_ID");
|
||||
List<OperationMapping> operationMappings = operationMappingsTenantMap.get(tenantID);
|
||||
if (operationMappings == null) {
|
||||
operationMappings = new LinkedList<>();
|
||||
operationMappingsTenantMap.put(tenantID, operationMappings);
|
||||
}
|
||||
operationMapping = new OperationMapping();
|
||||
operationMapping.setOperationId(rs.getInt("OPERATION_ID"));
|
||||
operationMapping.setDeviceIdentifier(new DeviceIdentifier(String.valueOf(rs.getInt("ENROLMENT_ID")),
|
||||
rs.getString("NAME")));
|
||||
operationMapping.setTenantId(rs.getInt("TENANT_ID"));
|
||||
operationMapping.setTenantId(tenantID);
|
||||
operationMappings.add(operationMapping);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
@ -1126,6 +1131,6 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
||||
} finally {
|
||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
return operationMappings;
|
||||
return operationMappingsTenantMap;
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ public class OperationMappingDAOImpl implements OperationMappingDAO {
|
||||
if (isScheduled) {
|
||||
stmt.setString(4, Operation.PushStatus.SCHEDULED.toString());
|
||||
} else {
|
||||
stmt.setString(4, Operation.PushStatus.IN_PROGRESS.toString());
|
||||
stmt.setString(4, Operation.PushStatus.COMPLETED.toString());
|
||||
}
|
||||
stmt.setLong(5, time);
|
||||
stmt.setLong(6, time);
|
||||
|
||||
@ -23,9 +23,9 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.ActivityStatus;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMapping;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationResponse;
|
||||
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMapping;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil;
|
||||
@ -38,8 +38,10 @@ import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This class holds the implementation of OperationDAO which can be used to support Oracle db syntax.
|
||||
@ -364,33 +366,38 @@ public class OracleOperationDAOImpl extends GenericOperationDAOImpl {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OperationMapping> getOperationMappingsByStatus(Operation.Status opStatus, Operation.PushStatus pushStatus,
|
||||
int limit) throws OperationManagementDAOException {
|
||||
|
||||
@Override
|
||||
public Map<Integer, List<OperationMapping>> getOperationMappingsByStatus(Operation.Status opStatus, Operation.PushStatus pushStatus,
|
||||
int limit) throws OperationManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
OperationMapping operationMapping;
|
||||
List<OperationMapping> operationMappings = new LinkedList<>();
|
||||
Map<Integer, List<OperationMapping>> operationMappingsTenantMap = new HashMap<>();
|
||||
try {
|
||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||
String sql = "SELECT op_mappings.ENROLMENT_ID, op_mappings.OPERATION_ID, d_type.NAME ,d.TENANT_ID FROM " +
|
||||
"DM_DEVICE d, DM_ENROLMENT_OP_MAPPING op_mappings, DM_DEVICE_TYPE d_type WHERE op_mappings" +
|
||||
".STATUS = '?' AND op_mappings.PUSH_NOTIFICATION_STATUS = '?' AND d.DEVICE_TYPE_ID = d_type.ID " +
|
||||
"AND d.ID=op_mappings.ENROLMENT_ID AND ROWNUM <= ? ORDER BY op_mappings.OPERATION_ID";
|
||||
String sql = "SELECT op.ENROLMENT_ID, op.OPERATION_ID, dt.NAME ,d.TENANT_ID FROM DM_DEVICE d, " +
|
||||
"DM_ENROLMENT_OP_MAPPING op, DM_DEVICE_TYPE dt WHERE op.STATUS = '?' AND op" +
|
||||
".PUSH_NOTIFICATION_STATUS = '?' AND d.DEVICE_TYPE_ID = dt.ID AND d.ID=op.ENROLMENT_ID AND ROWNUM" +
|
||||
" <= ? ORDER BY op.OPERATION_ID";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, opStatus.toString());
|
||||
stmt.setString(2, pushStatus.toString());
|
||||
stmt.setInt(3, limit);
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
int tenantID = rs.getInt("TENANT_ID");
|
||||
List<OperationMapping> operationMappings = operationMappingsTenantMap.get(tenantID);
|
||||
if (operationMappings == null) {
|
||||
operationMappings = new LinkedList<>();
|
||||
operationMappingsTenantMap.put(tenantID, operationMappings);
|
||||
}
|
||||
operationMapping = new OperationMapping();
|
||||
operationMapping.setOperationId(rs.getInt("OPERATION_ID"));
|
||||
operationMapping.setDeviceIdentifier(new DeviceIdentifier(String.valueOf(rs.getInt("ENROLMENT_ID")),
|
||||
rs.getString("NAME")));
|
||||
operationMapping.setTenantId(rs.getInt("TENANT_ID"));
|
||||
operationMapping.setTenantId(tenantID);
|
||||
operationMappings.add(operationMapping);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
@ -398,6 +405,6 @@ public class OracleOperationDAOImpl extends GenericOperationDAOImpl {
|
||||
} finally {
|
||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
return operationMappings;
|
||||
return operationMappingsTenantMap;
|
||||
}
|
||||
}
|
||||
@ -23,9 +23,9 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.ActivityStatus;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMapping;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationResponse;
|
||||
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMapping;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil;
|
||||
@ -38,8 +38,10 @@ import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This class holds the implementation of OperationDAO which can be used to support SQLServer db syntax.
|
||||
@ -267,33 +269,35 @@ public class SQLServerOperationDAOImpl extends GenericOperationDAOImpl {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OperationMapping> getOperationMappingsByStatus(Operation.Status opStatus, Operation.PushStatus pushStatus,
|
||||
int limit) throws OperationManagementDAOException {
|
||||
|
||||
public Map<Integer, List<OperationMapping>> getOperationMappingsByStatus(Operation.Status opStatus, Operation.PushStatus pushStatus,
|
||||
int limit) throws OperationManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
OperationMapping operationMapping;
|
||||
List<OperationMapping> operationMappings = new LinkedList<>();
|
||||
Map<Integer, List<OperationMapping>> operationMappingsTenantMap = new HashMap<>();
|
||||
try {
|
||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||
String sql = "SELECT op_mappings.ENROLMENT_ID, op_mappings.OPERATION_ID, d_type.NAME ,d.TENANT_ID FROM " +
|
||||
"DM_DEVICE d, DM_ENROLMENT_OP_MAPPING op_mappings, DM_DEVICE_TYPE d_type WHERE op_mappings" +
|
||||
".STATUS = '?' AND op_mappings.PUSH_NOTIFICATION_STATUS = '?' AND d.DEVICE_TYPE_ID = d_type.ID " +
|
||||
"AND d.ID=op_mappings.ENROLMENT_ID ORDER BY op_mappings.OPERATION_ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
|
||||
|
||||
String sql = "SELECT op.ENROLMENT_ID, op.OPERATION_ID, dt.NAME ,d.TENANT_ID FROM DM_DEVICE d, " +
|
||||
"DM_ENROLMENT_OP_MAPPING op, DM_DEVICE_TYPE dt WHERE op.STATUS = '?' AND op" +
|
||||
".PUSH_NOTIFICATION_STATUS = '?' AND d.DEVICE_TYPE_ID = dt.ID " +
|
||||
"AND d.ID=op.ENROLMENT_ID ORDER BY op.OPERATION_ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, opStatus.toString());
|
||||
stmt.setString(2, pushStatus.toString());
|
||||
stmt.setInt(3, 0);
|
||||
stmt.setInt(4, limit);
|
||||
stmt.setInt(3, limit);
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
int tenantID = rs.getInt("TENANT_ID");
|
||||
List<OperationMapping> operationMappings = operationMappingsTenantMap.get(tenantID);
|
||||
if (operationMappings == null) {
|
||||
operationMappings = new LinkedList<>();
|
||||
operationMappingsTenantMap.put(tenantID, operationMappings);
|
||||
}
|
||||
operationMapping = new OperationMapping();
|
||||
operationMapping.setOperationId(rs.getInt("OPERATION_ID"));
|
||||
operationMapping.setDeviceIdentifier(new DeviceIdentifier(String.valueOf(rs.getInt("ENROLMENT_ID")),
|
||||
rs.getString("NAME")));
|
||||
operationMapping.setTenantId(rs.getInt("TENANT_ID"));
|
||||
operationMapping.setTenantId(tenantID);
|
||||
operationMappings.add(operationMapping);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
@ -301,7 +305,6 @@ public class SQLServerOperationDAOImpl extends GenericOperationDAOImpl {
|
||||
} finally {
|
||||
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
return operationMappings;
|
||||
return operationMappingsTenantMap;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user