mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Cleaning up the code.
This commit is contained in:
parent
a4c7ade205
commit
a6f97ce2c3
@ -25,12 +25,12 @@ import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
|||||||
*/
|
*/
|
||||||
public class OperationEnrolmentMapping {
|
public class OperationEnrolmentMapping {
|
||||||
|
|
||||||
int enrolmentId;
|
private int enrolmentId;
|
||||||
int tenantId;
|
private int tenantId;
|
||||||
long createdTime;
|
private long createdTime;
|
||||||
String deviceType;
|
private String deviceType;
|
||||||
String deviceId;
|
private String deviceId;
|
||||||
EnrolmentInfo.Status deviceStatus;
|
private EnrolmentInfo.Status deviceStatus;
|
||||||
|
|
||||||
public int getTenantId() {
|
public int getTenantId() {
|
||||||
return tenantId;
|
return tenantId;
|
||||||
|
|||||||
@ -22,7 +22,6 @@ public class OperationMgtConstants {
|
|||||||
|
|
||||||
public final class DeviceConstants {
|
public final class DeviceConstants {
|
||||||
private DeviceConstants() {
|
private DeviceConstants() {
|
||||||
throw new AssertionError();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String DEVICE_ID_NOT_FOUND = "Device not found for device id: %s";
|
public static final String DEVICE_ID_NOT_FOUND = "Device not found for device id: %s";
|
||||||
@ -30,8 +29,8 @@ public class OperationMgtConstants {
|
|||||||
|
|
||||||
public final class OperationCodes {
|
public final class OperationCodes {
|
||||||
private OperationCodes() {
|
private OperationCodes() {
|
||||||
throw new AssertionError();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String POLICY_REVOKE = "POLICY_REVOKE";
|
public static final String POLICY_REVOKE = "POLICY_REVOKE";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,8 +31,6 @@ public interface OperationDAO {
|
|||||||
|
|
||||||
int addOperation(Operation operation) throws OperationManagementDAOException;
|
int addOperation(Operation operation) throws OperationManagementDAOException;
|
||||||
|
|
||||||
void updateOperation(Operation operation) throws OperationManagementDAOException;
|
|
||||||
|
|
||||||
Operation getOperation(int operationId) throws OperationManagementDAOException;
|
Operation getOperation(int operationId) throws OperationManagementDAOException;
|
||||||
|
|
||||||
Operation getOperationByDeviceAndId(int enrolmentId, int operationId) throws OperationManagementDAOException;
|
Operation getOperationByDeviceAndId(int enrolmentId, int operationId) throws OperationManagementDAOException;
|
||||||
@ -66,8 +64,6 @@ public interface OperationDAO {
|
|||||||
|
|
||||||
Activity getActivityByDevice(int operationId, int deviceId) throws OperationManagementDAOException;
|
Activity getActivityByDevice(int operationId, int deviceId) throws OperationManagementDAOException;
|
||||||
|
|
||||||
List<Activity> getActivitiesUpdatedAfter(long timestamp) throws OperationManagementDAOException;
|
|
||||||
|
|
||||||
List<Activity> getActivitiesUpdatedAfter(long timestamp, int limit, int offset) throws OperationManagementDAOException;
|
List<Activity> getActivitiesUpdatedAfter(long timestamp, int limit, int offset) throws OperationManagementDAOException;
|
||||||
|
|
||||||
int getActivityCountUpdatedAfter(long timestamp) throws OperationManagementDAOException;
|
int getActivityCountUpdatedAfter(long timestamp) throws OperationManagementDAOException;
|
||||||
|
|||||||
@ -53,23 +53,6 @@ public class CommandOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
return operationId;
|
return operationId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateOperation(Operation operation) throws OperationManagementDAOException {
|
|
||||||
PreparedStatement stmt = null;
|
|
||||||
try {
|
|
||||||
Connection connection = OperationManagementDAOFactory.getConnection();
|
|
||||||
stmt = connection.prepareStatement(
|
|
||||||
"UPDATE DM_COMMAND_OPERATION SET ENABLED = ? WHERE OPERATION_ID = ?");
|
|
||||||
stmt.setBoolean(1, operation.isEnabled());
|
|
||||||
stmt.setInt(2, operation.getId());
|
|
||||||
stmt.executeUpdate();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new OperationManagementDAOException("Error occurred while adding operation metadata", e);
|
|
||||||
} finally {
|
|
||||||
OperationManagementDAOUtil.cleanupResources(stmt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public CommandOperation getOperation(int id) throws OperationManagementDAOException {
|
public CommandOperation getOperation(int id) throws OperationManagementDAOException {
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
|
|||||||
@ -58,46 +58,6 @@ public class ConfigOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
return operationId;
|
return operationId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateOperation(Operation operation) throws OperationManagementDAOException {
|
|
||||||
PreparedStatement stmt = null;
|
|
||||||
ByteArrayOutputStream bao = null;
|
|
||||||
ObjectOutputStream oos = null;
|
|
||||||
try {
|
|
||||||
super.updateOperation(operation);
|
|
||||||
Connection connection = OperationManagementDAOFactory.getConnection();
|
|
||||||
stmt = connection.prepareStatement("UPDATE FROM DM_CONFIG_OPERATION SET OPERATION_CONFIG = ? " +
|
|
||||||
"WHERE OPERATION_ID = ?");
|
|
||||||
bao = new ByteArrayOutputStream();
|
|
||||||
oos = new ObjectOutputStream(bao);
|
|
||||||
oos.writeObject(operation);
|
|
||||||
|
|
||||||
stmt.setBytes(1, bao.toByteArray());
|
|
||||||
stmt.setInt(2, operation.getId());
|
|
||||||
stmt.executeUpdate();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new OperationManagementDAOException("Error occurred while update policy operation metadata", e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new OperationManagementDAOException("Error occurred while serializing policy operation object", e);
|
|
||||||
} finally {
|
|
||||||
if (bao != null) {
|
|
||||||
try {
|
|
||||||
bao.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.warn("Error occurred while closing ByteArrayOutputStream", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (oos != null) {
|
|
||||||
try {
|
|
||||||
oos.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.warn("Error occurred while closing ObjectOutputStream", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
OperationManagementDAOUtil.cleanupResources(stmt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Operation getOperation(int operationId) throws OperationManagementDAOException {
|
public Operation getOperation(int operationId) throws OperationManagementDAOException {
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
|
|||||||
@ -85,23 +85,6 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateOperation(Operation operation) throws OperationManagementDAOException {
|
|
||||||
PreparedStatement stmt = null;
|
|
||||||
try {
|
|
||||||
Connection connection = OperationManagementDAOFactory.getConnection();
|
|
||||||
stmt = connection.prepareStatement("UPDATE DM_OPERATION SET RECEIVED_TIMESTAMP=? " +
|
|
||||||
"WHERE ID=?");
|
|
||||||
stmt.setTimestamp(1, new Timestamp(new Date().getTime()));
|
|
||||||
stmt.setInt(2, operation.getId());
|
|
||||||
stmt.executeUpdate();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new OperationManagementDAOException("Error occurred while update operation metadata", e);
|
|
||||||
} finally {
|
|
||||||
OperationManagementDAOUtil.cleanupResources(stmt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean updateOperationStatus(int enrolmentId, int operationId, Operation.Status status)
|
public boolean updateOperationStatus(int enrolmentId, int operationId, Operation.Status status)
|
||||||
throws OperationManagementDAOException {
|
throws OperationManagementDAOException {
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
@ -403,11 +386,6 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
return activity;
|
return activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Activity> getActivitiesUpdatedAfter(long timestamp) throws OperationManagementDAOException {
|
|
||||||
return this.getActivitiesUpdatedAfter(timestamp, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Activity> getActivitiesUpdatedAfter(long timestamp, int limit,
|
public List<Activity> getActivitiesUpdatedAfter(long timestamp, int limit,
|
||||||
int offset) throws OperationManagementDAOException {
|
int offset) throws OperationManagementDAOException {
|
||||||
|
|||||||
@ -82,46 +82,6 @@ public class PolicyOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
return operationId;
|
return operationId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateOperation(Operation operation) throws OperationManagementDAOException {
|
|
||||||
PreparedStatement stmt = null;
|
|
||||||
ByteArrayOutputStream bao = null;
|
|
||||||
ObjectOutputStream oos = null;
|
|
||||||
try {
|
|
||||||
super.updateOperation(operation);
|
|
||||||
Connection connection = OperationManagementDAOFactory.getConnection();
|
|
||||||
stmt = connection.prepareStatement("UPDATE DM_POLICY_OPERATION SET OPERATION_DETAILS=? " +
|
|
||||||
"WHERE OPERATION_ID=?");
|
|
||||||
bao = new ByteArrayOutputStream();
|
|
||||||
oos = new ObjectOutputStream(bao);
|
|
||||||
oos.writeObject(operation);
|
|
||||||
|
|
||||||
stmt.setBytes(1, bao.toByteArray());
|
|
||||||
stmt.setInt(2, operation.getId());
|
|
||||||
stmt.executeUpdate();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new OperationManagementDAOException("Error occurred while update policy operation metadata", e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new OperationManagementDAOException("Error occurred while serializing policy operation object", e);
|
|
||||||
} finally {
|
|
||||||
if (bao != null) {
|
|
||||||
try {
|
|
||||||
bao.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.warn("Error occurred while closing ByteArrayOutputStream", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (oos != null) {
|
|
||||||
try {
|
|
||||||
oos.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.warn("Error occurred while closing ObjectOutputStream", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
OperationManagementDAOUtil.cleanupResources(stmt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Operation getOperation(int operationId) throws OperationManagementDAOException {
|
public Operation getOperation(int operationId) throws OperationManagementDAOException {
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
|
|||||||
@ -82,47 +82,6 @@ public class ProfileOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
return operationId;
|
return operationId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateOperation(Operation operation) throws OperationManagementDAOException {
|
|
||||||
PreparedStatement stmt = null;
|
|
||||||
ByteArrayOutputStream bao = null;
|
|
||||||
ObjectOutputStream oos = null;
|
|
||||||
try {
|
|
||||||
super.updateOperation(operation);
|
|
||||||
Connection connection = OperationManagementDAOFactory.getConnection();
|
|
||||||
stmt = connection.prepareStatement("UPDATE DM_PROFILE_OPERATION SET OPERATION_DETAILS=? " +
|
|
||||||
"WHERE OPERATION_ID=?");
|
|
||||||
|
|
||||||
bao = new ByteArrayOutputStream();
|
|
||||||
oos = new ObjectOutputStream(bao);
|
|
||||||
oos.writeObject(operation);
|
|
||||||
|
|
||||||
stmt.setBytes(1, bao.toByteArray());
|
|
||||||
stmt.setInt(2, operation.getId());
|
|
||||||
stmt.executeUpdate();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new OperationManagementDAOException("Error occurred while update operation metadata", e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new OperationManagementDAOException("Error occurred while serializing profile operation object", e);
|
|
||||||
} finally {
|
|
||||||
if (bao != null) {
|
|
||||||
try {
|
|
||||||
bao.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.warn("Error occurred while closing ByteArrayOutputStream", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (oos != null) {
|
|
||||||
try {
|
|
||||||
oos.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.warn("Error occurred while closing ObjectOutputStream", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
OperationManagementDAOUtil.cleanupResources(stmt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Operation getOperation(int id) throws OperationManagementDAOException {
|
public Operation getOperation(int id) throws OperationManagementDAOException {
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user