|
|
@ -18,6 +18,7 @@
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl;
|
|
|
|
package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationMapping;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
|
|
|
|
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.OperationManagementDAOFactory;
|
|
|
@ -27,23 +28,30 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationMappingDAO;
|
|
|
|
import java.sql.Connection;
|
|
|
|
import java.sql.Connection;
|
|
|
|
import java.sql.PreparedStatement;
|
|
|
|
import java.sql.PreparedStatement;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
public class OperationMappingDAOImpl implements OperationMappingDAO {
|
|
|
|
public class OperationMappingDAOImpl implements OperationMappingDAO {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void addOperationMapping(int operationId, Integer deviceId) throws OperationManagementDAOException {
|
|
|
|
public void addOperationMapping(int operationId, Integer deviceId, boolean isScheduled) throws
|
|
|
|
|
|
|
|
OperationManagementDAOException {
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
long time = System.currentTimeMillis() / 1000;
|
|
|
|
long time = System.currentTimeMillis() / 1000;
|
|
|
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
|
|
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
|
|
|
String sql = "INSERT INTO DM_ENROLMENT_OP_MAPPING(ENROLMENT_ID, OPERATION_ID, STATUS, CREATED_TIMESTAMP, " +
|
|
|
|
String sql = "INSERT INTO DM_ENROLMENT_OP_MAPPING(ENROLMENT_ID, OPERATION_ID, STATUS, " +
|
|
|
|
"UPDATED_TIMESTAMP) VALUES (?, ?, ?, ?, ?)";
|
|
|
|
"PUSH_NOTIFICATION_STATUS, CREATED_TIMESTAMP, UPDATED_TIMESTAMP) VALUES (?, ?, ?, ?, ?, ?)";
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setInt(1, deviceId);
|
|
|
|
stmt.setInt(1, deviceId);
|
|
|
|
stmt.setInt(2, operationId);
|
|
|
|
stmt.setInt(2, operationId);
|
|
|
|
stmt.setString(3, Operation.Status.PENDING.toString());
|
|
|
|
stmt.setString(3, Operation.Status.PENDING.toString());
|
|
|
|
stmt.setLong(4, time);
|
|
|
|
if (isScheduled) {
|
|
|
|
|
|
|
|
stmt.setString(4, Operation.PushStatus.SCHEDULED.toString());
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
stmt.setString(4, Operation.PushStatus.IN_PROGRESS.toString());
|
|
|
|
|
|
|
|
}
|
|
|
|
stmt.setLong(5, time);
|
|
|
|
stmt.setLong(5, time);
|
|
|
|
|
|
|
|
stmt.setLong(6, time);
|
|
|
|
stmt.executeUpdate();
|
|
|
|
stmt.executeUpdate();
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new OperationManagementDAOException("Error occurred while persisting device operation mappings", e);
|
|
|
|
throw new OperationManagementDAOException("Error occurred while persisting device operation mappings", e);
|
|
|
@ -54,13 +62,13 @@ public class OperationMappingDAOImpl implements OperationMappingDAO {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void removeOperationMapping(int operationId,
|
|
|
|
public void removeOperationMapping(int operationId,
|
|
|
|
Integer deviceIds) throws OperationManagementDAOException {
|
|
|
|
Integer deviceId) throws OperationManagementDAOException {
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
|
|
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
|
|
|
String sql = "DELETE FROM DM_ENROLMENT_OP_MAPPING WHERE ENROLMENT_ID = ? AND OPERATION_ID = ?";
|
|
|
|
String sql = "DELETE FROM DM_ENROLMENT_OP_MAPPING WHERE ENROLMENT_ID = ? AND OPERATION_ID = ?";
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setInt(1, 0);
|
|
|
|
stmt.setInt(1, deviceId);
|
|
|
|
stmt.setInt(2, operationId);
|
|
|
|
stmt.setInt(2, operationId);
|
|
|
|
stmt.executeUpdate();
|
|
|
|
stmt.executeUpdate();
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
@ -70,4 +78,55 @@ public class OperationMappingDAOImpl implements OperationMappingDAO {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void updateOperationMapping(int operationId, Integer deviceId, Operation.PushStatus pushStatus) throws OperationManagementDAOException {
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
|
|
|
|
|
|
|
String sql = "UPDATE DM_ENROLMENT_OP_MAPPING SET PUSH_NOTIFICATION_STATUS = ? WHERE ENROLMENT_ID = ? and " +
|
|
|
|
|
|
|
|
"OPERATION_ID = ?";
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
|
|
|
|
stmt.setString(1, pushStatus.toString());
|
|
|
|
|
|
|
|
stmt.setInt(2, deviceId);
|
|
|
|
|
|
|
|
stmt.setInt(3, operationId);
|
|
|
|
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
throw new OperationManagementDAOException("Error occurred while updating device operation mappings", e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
OperationManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void updateOperationMapping(List<OperationMapping> operationMappingList, Operation.PushStatus pushStatus) throws
|
|
|
|
|
|
|
|
OperationManagementDAOException {
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
|
|
|
|
|
|
|
String sql = "UPDATE DM_ENROLMENT_OP_MAPPING SET PUSH_NOTIFICATION_STATUS = ? WHERE ENROLMENT_ID = ? and " +
|
|
|
|
|
|
|
|
"OPERATION_ID = ?";
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
|
|
|
|
if (conn.getMetaData().supportsBatchUpdates()) {
|
|
|
|
|
|
|
|
for (OperationMapping operationMapping : operationMappingList) {
|
|
|
|
|
|
|
|
stmt.setString(1, pushStatus.toString());
|
|
|
|
|
|
|
|
stmt.setInt(2, Integer.parseInt(operationMapping.getDeviceIdentifier().getId()));
|
|
|
|
|
|
|
|
stmt.setInt(3, operationMapping.getOperationId());
|
|
|
|
|
|
|
|
stmt.addBatch();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
stmt.executeBatch();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
for (OperationMapping operationMapping : operationMappingList) {
|
|
|
|
|
|
|
|
stmt.setString(1, pushStatus.toString());
|
|
|
|
|
|
|
|
stmt.setInt(2, Integer.parseInt(operationMapping.getDeviceIdentifier().getId()));
|
|
|
|
|
|
|
|
stmt.setInt(3, operationMapping.getOperationId());
|
|
|
|
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
throw new OperationManagementDAOException("Error occurred while updating device operation mappings as " +
|
|
|
|
|
|
|
|
"batch ", e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
OperationManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|