@ -59,6 +59,7 @@ import java.util.HashMap;
import java.util.LinkedList ;
import java.util.LinkedList ;
import java.util.List ;
import java.util.List ;
import java.util.Map ;
import java.util.Map ;
import java.util.Properties ;
import java.util.stream.Collectors ;
import java.util.stream.Collectors ;
import java.util.stream.IntStream ;
import java.util.stream.IntStream ;
@ -75,15 +76,16 @@ public class GenericOperationDAOImpl implements OperationDAO {
try {
try {
Connection connection = OperationManagementDAOFactory . getConnection ( ) ;
Connection connection = OperationManagementDAOFactory . getConnection ( ) ;
String sql = "INSERT INTO DM_OPERATION(TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, " +
String sql = "INSERT INTO DM_OPERATION(TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, " +
"INITIATED_BY, OPERATION_DETAILS, TENANT_ID) VALUES (?, ?, ?, ?, ?, ?, ?)";
"INITIATED_BY, OPERATION_DETAILS, OPERATION_PROPERTIES, TENANT_ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
stmt = connection . prepareStatement ( sql , new String [ ] { "id" } ) ;
stmt = connection . prepareStatement ( sql , new String [ ] { "id" } ) ;
stmt . setString ( 1 , operation . getType ( ) . toString ( ) ) ;
stmt . setString ( 1 , operation . getType ( ) . toString ( ) ) ;
stmt . setLong ( 2 , DeviceManagementDAOUtil . getCurrentUTCTime ( ) ) ;
stmt . setLong ( 2 , DeviceManagementDAOUtil . getCurrentUTCTime ( ) ) ;
stmt . setLong ( 3 , 0 ) ;
stmt . setLong ( 3 , 0 ) ;
stmt . setString ( 4 , operation . getCode ( ) ) ;
stmt . setString ( 4 , operation . getCode ( ) ) ;
stmt . setString ( 5 , operation . getInitiatedBy ( ) ) ;
stmt . setString ( 5 , operation . getInitiatedBy ( ) ) ;
stmt . setObject ( 6 , operation ) ;
stmt . setObject ( 6 , operation . getPayLoad ( ) ) ;
stmt . setInt ( 7 , PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( ) ) ;
stmt . setObject ( 7 , operation . getProperties ( ) ) ;
stmt . setInt ( 8 , PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( ) ) ;
stmt . executeUpdate ( ) ;
stmt . executeUpdate ( ) ;
rs = stmt . getGeneratedKeys ( ) ;
rs = stmt . getGeneratedKeys ( ) ;
@ -164,7 +166,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
}
}
@Override
@Override
public Map < Integer , Integer > getExisting OperationIDs( Integer [ ] enrolmentIds , String operationCode )
public Map < Integer , Integer > getExisting NotExecuted OperationIDs( Integer [ ] enrolmentIds , String operationCode )
throws OperationManagementDAOException {
throws OperationManagementDAOException {
PreparedStatement stmt = null ;
PreparedStatement stmt = null ;
ResultSet rs = null ;
ResultSet rs = null ;
@ -576,7 +578,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
+ "dor.ID AS OP_RES_ID, de.DEVICE_ID, d.DEVICE_IDENTIFICATION, d.DEVICE_TYPE_ID, "
+ "dor.ID AS OP_RES_ID, de.DEVICE_ID, d.DEVICE_IDENTIFICATION, d.DEVICE_TYPE_ID, "
+ "dt.NAME AS DEVICE_TYPE_NAME, eom.STATUS, eom.CREATED_TIMESTAMP, "
+ "dt.NAME AS DEVICE_TYPE_NAME, eom.STATUS, eom.CREATED_TIMESTAMP, "
+ "eom.UPDATED_TIMESTAMP, op.OPERATION_CODE, op.TYPE AS OPERATION_TYPE, "
+ "eom.UPDATED_TIMESTAMP, op.OPERATION_CODE, op.TYPE AS OPERATION_TYPE, "
+ "dor.OPERATION_RESPONSE, op.INITIATED_BY, dor.RECEIVED_TIMESTAMP, dor.IS_LARGE_RESPONSE FROM "
+ "dor.OPERATION_RESPONSE, op.INITIATED_BY, dor.RECEIVED_TIMESTAMP, dor.IS_LARGE_RESPONSE FROM "
+ "DM_ENROLMENT_OP_MAPPING eom INNER JOIN DM_OPERATION op "
+ "DM_ENROLMENT_OP_MAPPING eom INNER JOIN DM_OPERATION op "
+ "ON op.ID=eom.OPERATION_ID INNER JOIN DM_ENROLMENT de "
+ "ON op.ID=eom.OPERATION_ID INNER JOIN DM_ENROLMENT de "
+ "ON de.ID=eom.ENROLMENT_ID INNER JOIN DM_DEVICE d ON d.ID=de.DEVICE_ID "
+ "ON de.ID=eom.ENROLMENT_ID INNER JOIN DM_DEVICE d ON d.ID=de.DEVICE_ID "
@ -1189,24 +1191,14 @@ public class GenericOperationDAOImpl implements OperationDAO {
Operation operation = null ;
Operation operation = null ;
try {
try {
Connection conn = OperationManagementDAOFactory . getConnection ( ) ;
Connection conn = OperationManagementDAOFactory . getConnection ( ) ;
String sql = "SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, INITIATED_BY FROM " +
String sql = "SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, INITIATED_BY , " +
" DM_OPERATION WHERE id = ?";
" OPERATION_DETAILS, OPERATION_PROPERTIES FROM DM_OPERATION WHERE id = ?";
stmt = conn . prepareStatement ( sql ) ;
stmt = conn . prepareStatement ( sql ) ;
stmt . setInt ( 1 , id ) ;
stmt . setInt ( 1 , id ) ;
rs = stmt . executeQuery ( ) ;
rs = stmt . executeQuery ( ) ;
if ( rs . next ( ) ) {
if ( rs . next ( ) ) {
operation = new Operation ( ) ;
operation = OperationDAOUtil . getOperation ( rs ) ;
operation . setId ( rs . getInt ( "ID" ) ) ;
operation . setType ( Operation . Type . valueOf ( rs . getString ( "TYPE" ) ) ) ;
operation . setCreatedTimeStamp ( new Timestamp ( rs . getLong ( "CREATED_TIMESTAMP" ) * 1000L ) . toString ( ) ) ;
if ( rs . getLong ( "RECEIVED_TIMESTAMP" ) = = 0 ) {
operation . setReceivedTimeStamp ( "" ) ;
} else {
operation . setReceivedTimeStamp ( new Timestamp ( rs . getLong ( "RECEIVED_TIMESTAMP" ) * 1000L ) . toString ( ) ) ;
}
operation . setCode ( rs . getString ( "OPERATION_CODE" ) ) ;
operation . setInitiatedBy ( rs . getString ( "INITIATED_BY" ) ) ;
}
}
} catch ( SQLException e ) {
} catch ( SQLException e ) {
@ -1219,16 +1211,19 @@ public class GenericOperationDAOImpl implements OperationDAO {
}
}
@Override
@Override
public Operation getOperationByDeviceAndId ( int enrolmentId , int operationId ) throws OperationManagementDAOException {
public Operation getOperationByDeviceAndId ( int enrolmentId , int operationId )
throws OperationManagementDAOException {
PreparedStatement stmt = null ;
PreparedStatement stmt = null ;
ResultSet rs = null ;
ResultSet rs = null ;
Operation operation = null ;
Operation operation = null ;
try {
try {
Connection conn = OperationManagementDAOFactory . getConnection ( ) ;
Connection conn = OperationManagementDAOFactory . getConnection ( ) ;
String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, om.STATUS, " +
String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, om.STATUS, " +
"o.OPERATION_CODE, o.INITIATED_BY, om.ID AS OM_MAPPING_ID, " +
"o.OPERATION_CODE, o.INITIATED_BY, o.OPERATION_DETAILS, o.OPERATION_PROPERTIES, " +
"om.UPDATED_TIMESTAMP FROM (SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP," +
"om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP, om.STATUS FROM " +
"OPERATION_CODE, INITIATED_BY FROM DM_OPERATION WHERE id = ?) o INNER JOIN (SELECT * FROM " +
"(SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP," +
"OPERATION_CODE, INITIATED_BY, OPERATION_DETAILS, OPERATION_PROPERTIES FROM DM_OPERATION " +
"WHERE id = ?) o INNER JOIN (SELECT * FROM " +
"DM_ENROLMENT_OP_MAPPING dm where dm.OPERATION_ID = ? AND dm.ENROLMENT_ID = ?) om " +
"DM_ENROLMENT_OP_MAPPING dm where dm.OPERATION_ID = ? AND dm.ENROLMENT_ID = ?) om " +
"ON o.ID = om.OPERATION_ID " ;
"ON o.ID = om.OPERATION_ID " ;
stmt = conn . prepareStatement ( sql ) ;
stmt = conn . prepareStatement ( sql ) ;
@ -1238,20 +1233,14 @@ public class GenericOperationDAOImpl implements OperationDAO {
rs = stmt . executeQuery ( ) ;
rs = stmt . executeQuery ( ) ;
if ( rs . next ( ) ) {
if ( rs . next ( ) ) {
operation = new Operation ( ) ;
operation = OperationDAOUtil . getOperation ( rs ) ;
operation . setId ( rs . getInt ( "ID" ) ) ;
operation . setType ( Operation . Type . valueOf ( rs . getString ( "TYPE" ) ) ) ;
operation . setCreatedTimeStamp ( new Timestamp ( rs . getLong ( "CREATED_TIMESTAMP" ) * 1000L ) . toString ( ) ) ;
operation . setStatus ( Operation . Status . valueOf ( rs . getString ( "STATUS" ) ) ) ;
if ( rs . getLong ( "UPDATED_TIMESTAMP" ) = = 0 ) {
if ( rs . getLong ( "UPDATED_TIMESTAMP" ) = = 0 ) {
operation . setReceivedTimeStamp ( "" ) ;
operation . setReceivedTimeStamp ( "" ) ;
} else {
} else {
operation . setReceivedTimeStamp (
operation . setReceivedTimeStamp (
new Timestamp ( ( rs . getLong ( "UPDATED_TIMESTAMP" ) * 1000 ) ) . toString ( ) ) ;
new Timestamp ( ( rs . getLong ( "UPDATED_TIMESTAMP" ) * 1000 ) ) . toString ( ) ) ;
}
}
operation . setCode ( rs . getString ( "OPERATION_CODE" ) ) ;
operation . setStatus ( Operation . Status . valueOf ( rs . getString ( "STATUS" ) ) ) ;
operation . setInitiatedBy ( rs . getString ( "INITIATED_BY" ) ) ;
OperationDAOUtil . setActivityId ( operation , rs . getInt ( "ID" ) ) ;
}
}
} catch ( SQLException e ) {
} catch ( SQLException e ) {
throw new OperationManagementDAOException ( "SQL error occurred while retrieving the operation " +
throw new OperationManagementDAOException ( "SQL error occurred while retrieving the operation " +
@ -1272,7 +1261,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
try {
try {
Connection conn = OperationManagementDAOFactory . getConnection ( ) ;
Connection conn = OperationManagementDAOFactory . getConnection ( ) ;
String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.OPERATION_CODE, " +
String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.OPERATION_CODE, " +
"o.INITIATED_BY, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM DM_OPERATION o " +
"o.INITIATED_BY, o.OPERATION_DETAILS, o.OPERATION_PROPERTIES, om.ID AS OM_MAPPING_ID, " +
"om.UPDATED_TIMESTAMP FROM DM_OPERATION o " +
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
"WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP DESC" ;
"WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP DESC" ;
stmt = conn . prepareStatement ( sql ) ;
stmt = conn . prepareStatement ( sql ) ;
@ -1281,20 +1271,14 @@ public class GenericOperationDAOImpl implements OperationDAO {
rs = stmt . executeQuery ( ) ;
rs = stmt . executeQuery ( ) ;
while ( rs . next ( ) ) {
while ( rs . next ( ) ) {
operation = new Operation ( ) ;
operation = OperationDAOUtil . getOperation ( rs ) ;
operation . setId ( rs . getInt ( "ID" ) ) ;
operation . setStatus ( status ) ;
operation . setType ( Operation . Type . valueOf ( rs . getString ( "TYPE" ) ) ) ;
operation . setCreatedTimeStamp ( new Timestamp ( rs . getLong ( "CREATED_TIMESTAMP" ) * 1000L ) . toString ( ) ) ;
if ( rs . getLong ( "UPDATED_TIMESTAMP" ) = = 0 ) {
if ( rs . getLong ( "UPDATED_TIMESTAMP" ) = = 0 ) {
operation . setReceivedTimeStamp ( "" ) ;
operation . setReceivedTimeStamp ( "" ) ;
} else {
} else {
operation . setReceivedTimeStamp (
operation . setReceivedTimeStamp (
new Timestamp ( ( rs . getLong ( "UPDATED_TIMESTAMP" ) * 1000 ) ) . toString ( ) ) ;
new Timestamp ( ( rs . getLong ( "UPDATED_TIMESTAMP" ) * 1000 ) ) . toString ( ) ) ;
}
}
operation . setCode ( rs . getString ( "OPERATION_CODE" ) ) ;
operation . setInitiatedBy ( rs . getString ( "INITIATED_BY" ) ) ;
operation . setStatus ( status ) ;
OperationDAOUtil . setActivityId ( operation , rs . getInt ( "ID" ) ) ;
operations . add ( operation ) ;
operations . add ( operation ) ;
}
}
} catch ( SQLException e ) {
} catch ( SQLException e ) {
@ -1317,7 +1301,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
try {
try {
Connection conn = OperationManagementDAOFactory . getConnection ( ) ;
Connection conn = OperationManagementDAOFactory . getConnection ( ) ;
String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.OPERATION_CODE, " +
String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.OPERATION_CODE, " +
"o.INITIATED_BY, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM DM_OPERATION o " +
"o.INITIATED_BY, o.OPERATION_DETAILS, o.OPERATION_PROPERTIES, om.ID AS OM_MAPPING_ID, " +
"om.UPDATED_TIMESTAMP FROM DM_OPERATION o " +
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
"WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY " +
"WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY " +
"o.CREATED_TIMESTAMP DESC LIMIT ?,?" ;
"o.CREATED_TIMESTAMP DESC LIMIT ?,?" ;
@ -1329,20 +1314,15 @@ public class GenericOperationDAOImpl implements OperationDAO {
rs = stmt . executeQuery ( ) ;
rs = stmt . executeQuery ( ) ;
while ( rs . next ( ) ) {
while ( rs . next ( ) ) {
operation = new Operation ( ) ;
operation = OperationDAOUtil . getOperation ( rs ) ;
operation . setId ( rs . getInt ( "ID" ) ) ;
operation . setStatus ( status ) ;
operation . setType ( Operation . Type . valueOf ( rs . getString ( "TYPE" ) ) ) ;
operation . setCreatedTimeStamp ( new Timestamp ( rs . getLong ( "CREATED_TIMESTAMP" ) * 1000L ) . toString ( ) ) ;
if ( rs . getLong ( "UPDATED_TIMESTAMP" ) = = 0 ) {
if ( rs . getLong ( "UPDATED_TIMESTAMP" ) = = 0 ) {
operation . setReceivedTimeStamp ( "" ) ;
operation . setReceivedTimeStamp ( "" ) ;
} else {
} else {
operation . setReceivedTimeStamp (
operation . setReceivedTimeStamp (
new Timestamp ( ( rs . getLong ( "UPDATED_TIMESTAMP" ) * 1000 ) ) . toString ( ) ) ;
new Timestamp ( ( rs . getLong ( "UPDATED_TIMESTAMP" ) * 1000 ) ) . toString ( ) ) ;
}
}
operation . setCode ( rs . getString ( "OPERATION_CODE" ) ) ;
operation . setInitiatedBy ( rs . getString ( "INITIATED_BY" ) ) ;
operation . setStatus ( status ) ;
operation . setStatus ( status ) ;
OperationDAOUtil . setActivityId ( operation , rs . getInt ( "OM_MAPPING_ID" ) ) ;
operations . add ( operation ) ;
operations . add ( operation ) ;
}
}
} catch ( SQLException e ) {
} catch ( SQLException e ) {
@ -1364,7 +1344,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
try {
try {
Connection conn = OperationManagementDAOFactory . getConnection ( ) ;
Connection conn = OperationManagementDAOFactory . getConnection ( ) ;
String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " +
String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " +
"o.OPERATION_CODE, o.INITIATED_BY, om.STATUS, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP " +
"o.OPERATION_CODE, o.INITIATED_BY, o.OPERATION_DETAILS, o.OPERATION_PROPERTIES, om.STATUS, " +
"om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP " +
"FROM DM_OPERATION o INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
"FROM DM_OPERATION o INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
"WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID " +
"WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID " +
"ORDER BY o.CREATED_TIMESTAMP DESC, o.ID DESC" ;
"ORDER BY o.CREATED_TIMESTAMP DESC, o.ID DESC" ;
@ -1373,18 +1354,13 @@ public class GenericOperationDAOImpl implements OperationDAO {
rs = stmt . executeQuery ( ) ;
rs = stmt . executeQuery ( ) ;
while ( rs . next ( ) ) {
while ( rs . next ( ) ) {
operation = new Operation ( ) ;
operation = OperationDAOUtil . getOperation ( rs ) ;
operation . setId ( rs . getInt ( "ID" ) ) ;
operation . setType ( Operation . Type . valueOf ( rs . getString ( "TYPE" ) ) ) ;
operation . setCreatedTimeStamp ( new Timestamp ( rs . getLong ( "CREATED_TIMESTAMP" ) * 1000L ) . toString ( ) ) ;
if ( rs . getLong ( "UPDATED_TIMESTAMP" ) = = 0 ) {
if ( rs . getLong ( "UPDATED_TIMESTAMP" ) = = 0 ) {
operation . setReceivedTimeStamp ( "" ) ;
operation . setReceivedTimeStamp ( "" ) ;
} else {
} else {
operation . setReceivedTimeStamp (
operation . setReceivedTimeStamp (
new Timestamp ( ( rs . getLong ( "UPDATED_TIMESTAMP" ) * 1000 ) ) . toString ( ) ) ;
new Timestamp ( ( rs . getLong ( "UPDATED_TIMESTAMP" ) * 1000 ) ) . toString ( ) ) ;
}
}
operation . setCode ( rs . getString ( "OPERATION_CODE" ) ) ;
operation . setInitiatedBy ( rs . getString ( "INITIATED_BY" ) ) ;
operation . setStatus ( Operation . Status . valueOf ( rs . getString ( "STATUS" ) ) ) ;
operation . setStatus ( Operation . Status . valueOf ( rs . getString ( "STATUS" ) ) ) ;
operations . add ( operation ) ;
operations . add ( operation ) ;
}
}
@ -1428,6 +1404,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
"o.OPERATION_CODE, " +
"o.OPERATION_CODE, " +
"o.INITIATED_BY, " +
"o.INITIATED_BY, " +
"o.OPERATION_DETAILS, " +
"o.OPERATION_DETAILS, " +
"o.OPERATION_PROPERTIES, " +
"om.STATUS, " +
"om.STATUS, " +
"om.ID AS OM_MAPPING_ID, " +
"om.ID AS OM_MAPPING_ID, " +
"om.UPDATED_TIMESTAMP " +
"om.UPDATED_TIMESTAMP " +
@ -1514,36 +1491,14 @@ public class GenericOperationDAOImpl implements OperationDAO {
stmt . setInt ( paramIndex , request . getRowCount ( ) ) ;
stmt . setInt ( paramIndex , request . getRowCount ( ) ) ;
try ( ResultSet rs = stmt . executeQuery ( ) ) {
try ( ResultSet rs = stmt . executeQuery ( ) ) {
while ( rs . next ( ) ) {
while ( rs . next ( ) ) {
operation = new Operation ( ) ;
operation = OperationDAOUtil . getOperation ( rs ) ;
operation . setId ( rs . getInt ( "ID" ) ) ;
operation . setType ( Operation . Type . valueOf ( rs . getString ( "TYPE" ) ) ) ;
operation . setCreatedTimeStamp ( new Timestamp ( rs . getLong ( "CREATED_TIMESTAMP" ) * 1000L ) . toString ( ) ) ;
if ( rs . getLong ( "UPDATED_TIMESTAMP" ) = = 0 ) {
if ( rs . getLong ( "UPDATED_TIMESTAMP" ) = = 0 ) {
operation . setReceivedTimeStamp ( "" ) ;
operation . setReceivedTimeStamp ( "" ) ;
} else {
} else {
operation . setReceivedTimeStamp (
operation . setReceivedTimeStamp (
new Timestamp ( ( rs . getLong ( "UPDATED_TIMESTAMP" ) * 1000 ) ) . toString ( ) ) ;
new Timestamp ( ( rs . getLong ( "UPDATED_TIMESTAMP" ) * 1000 ) ) . toString ( ) ) ;
}
}
operation . setCode ( rs . getString ( "OPERATION_CODE" ) ) ;
operation . setInitiatedBy ( rs . getString ( "INITIATED_BY" ) ) ;
if ( MDMAppConstants . AndroidConstants . UNMANAGED_APP_UNINSTALL . equals ( operation . getCode ( ) ) ) {
byte [ ] operationDetails = rs . getBytes ( "OPERATION_DETAILS" ) ;
try ( ByteArrayInputStream bais = new ByteArrayInputStream ( operationDetails ) ;
ObjectInputStream ois = new ObjectInputStream ( bais ) ) {
profileOperation = ( ProfileOperation ) ois . readObject ( ) ;
operation . setPayLoad ( profileOperation . getPayLoad ( ) ) ;
} catch ( IOException e ) {
String msg = "IO Error occurred while retrieving app data of operation " ;
log . error ( msg , e ) ;
throw new OperationManagementDAOException ( msg , e ) ;
} catch ( ClassNotFoundException e ) {
String msg = "Class not found error occurred while retrieving app data of operation " ;
log . error ( msg , e ) ;
throw new OperationManagementDAOException ( msg , e ) ;
}
}
operation . setStatus ( Operation . Status . valueOf ( rs . getString ( "STATUS" ) ) ) ;
operation . setStatus ( Operation . Status . valueOf ( rs . getString ( "STATUS" ) ) ) ;
OperationDAOUtil . setActivityId ( operation , rs . getInt ( "ID" ) ) ;
operations . add ( operation ) ;
operations . add ( operation ) ;
}
}
}
}
@ -1562,7 +1517,6 @@ public class GenericOperationDAOImpl implements OperationDAO {
List < Operation > operations = new ArrayList < > ( ) ;
List < Operation > operations = new ArrayList < > ( ) ;
String createdTo = null ;
String createdTo = null ;
String createdFrom = null ;
String createdFrom = null ;
ProfileOperation profileOperation = null ;
DateFormat simple = new SimpleDateFormat ( "yyyy-MM-dd HH:mm:ss.SSS" ) ;
DateFormat simple = new SimpleDateFormat ( "yyyy-MM-dd HH:mm:ss.SSS" ) ;
boolean isCreatedDayProvided = false ;
boolean isCreatedDayProvided = false ;
boolean isUpdatedDayProvided = false ; //updated day = received day
boolean isUpdatedDayProvided = false ; //updated day = received day
@ -1586,6 +1540,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
"o.OPERATION_CODE, " +
"o.OPERATION_CODE, " +
"o.INITIATED_BY, " +
"o.INITIATED_BY, " +
"o.OPERATION_DETAILS, " +
"o.OPERATION_DETAILS, " +
"o.OPERATION_PROPERTIES, " +
"om.STATUS, " +
"om.STATUS, " +
"om.ID AS OM_MAPPING_ID, " +
"om.ID AS OM_MAPPING_ID, " +
"om.UPDATED_TIMESTAMP " +
"om.UPDATED_TIMESTAMP " +
@ -1672,36 +1627,14 @@ public class GenericOperationDAOImpl implements OperationDAO {
stmt . setInt ( paramIndex , request . getRowCount ( ) ) ;
stmt . setInt ( paramIndex , request . getRowCount ( ) ) ;
try ( ResultSet rs = stmt . executeQuery ( ) ) {
try ( ResultSet rs = stmt . executeQuery ( ) ) {
while ( rs . next ( ) ) {
while ( rs . next ( ) ) {
operation = new Operation ( ) ;
operation = OperationDAOUtil . getOperation ( rs ) ;
operation . setId ( rs . getInt ( "ID" ) ) ;
operation . setType ( Operation . Type . valueOf ( rs . getString ( "TYPE" ) ) ) ;
operation . setCreatedTimeStamp ( new Timestamp ( rs . getLong ( "CREATED_TIMESTAMP" ) * 1000L ) . toString ( ) ) ;
if ( rs . getLong ( "UPDATED_TIMESTAMP" ) = = 0 ) {
if ( rs . getLong ( "UPDATED_TIMESTAMP" ) = = 0 ) {
operation . setReceivedTimeStamp ( "" ) ;
operation . setReceivedTimeStamp ( "" ) ;
} else {
} else {
operation . setReceivedTimeStamp (
operation . setReceivedTimeStamp (
new Timestamp ( ( rs . getLong ( "UPDATED_TIMESTAMP" ) * 1000 ) ) . toString ( ) ) ;
new Timestamp ( ( rs . getLong ( "UPDATED_TIMESTAMP" ) * 1000 ) ) . toString ( ) ) ;
}
}
operation . setCode ( rs . getString ( "OPERATION_CODE" ) ) ;
operation . setInitiatedBy ( rs . getString ( "INITIATED_BY" ) ) ;
if ( MDMAppConstants . AndroidConstants . UNMANAGED_APP_UNINSTALL . equals ( operation . getCode ( ) ) ) {
byte [ ] operationDetails = rs . getBytes ( "OPERATION_DETAILS" ) ;
try ( ByteArrayInputStream bais = new ByteArrayInputStream ( operationDetails ) ;
ObjectInputStream ois = new ObjectInputStream ( bais ) ) {
profileOperation = ( ProfileOperation ) ois . readObject ( ) ;
operation . setPayLoad ( profileOperation . getPayLoad ( ) ) ;
} catch ( IOException e ) {
String msg = "IO Error occurred while retrieving app data of operation " ;
log . error ( msg , e ) ;
throw new OperationManagementDAOException ( msg , e ) ;
} catch ( ClassNotFoundException e ) {
String msg = "Class not found error occurred while retrieving app data of operation " ;
log . error ( msg , e ) ;
throw new OperationManagementDAOException ( msg , e ) ;
}
}
operation . setStatus ( Operation . Status . valueOf ( rs . getString ( "STATUS" ) ) ) ;
operation . setStatus ( Operation . Status . valueOf ( rs . getString ( "STATUS" ) ) ) ;
OperationDAOUtil . setActivityId ( operation , rs . getInt ( "ID" ) ) ;
operations . add ( operation ) ;
operations . add ( operation ) ;
}
}
}
}
@ -1932,7 +1865,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
try {
try {
Connection connection = OperationManagementDAOFactory . getConnection ( ) ;
Connection connection = OperationManagementDAOFactory . getConnection ( ) ;
stmt = connection . prepareStatement ( "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " +
stmt = connection . prepareStatement ( "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " +
"o.OPERATION_CODE, o.INITIATED_BY, om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM DM_OPERATION o " +
"o.OPERATION_CODE, o.INITIATED_BY, o.OPERATION_DETAILS, o.OPERATION_PROPERTIES, " +
"om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM DM_OPERATION o " +
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
"WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID " +
"WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID " +
"ORDER BY om.UPDATED_TIMESTAMP ASC, om.ID ASC LIMIT 1" ) ;
"ORDER BY om.UPDATED_TIMESTAMP ASC, om.ID ASC LIMIT 1" ) ;
@ -1942,21 +1876,14 @@ public class GenericOperationDAOImpl implements OperationDAO {
Operation operation = null ;
Operation operation = null ;
if ( rs . next ( ) ) {
if ( rs . next ( ) ) {
operation = new Operation ( ) ;
operation = OperationDAOUtil . getOperation ( rs ) ;
operation . setType ( OperationDAOUtil . getType ( rs . getString ( "TYPE" ) ) ) ;
operation . setId ( rs . getInt ( "ID" ) ) ;
operation . setCreatedTimeStamp ( new Timestamp ( rs . getLong ( "CREATED_TIMESTAMP" ) * 1000L ) . toString ( ) ) ;
if ( rs . getLong ( "UPDATED_TIMESTAMP" ) = = 0 ) {
if ( rs . getLong ( "UPDATED_TIMESTAMP" ) = = 0 ) {
operation . setReceivedTimeStamp ( "" ) ;
operation . setReceivedTimeStamp ( "" ) ;
} else {
} else {
operation . setReceivedTimeStamp (
operation . setReceivedTimeStamp (
new Timestamp ( ( rs . getLong ( "UPDATED_TIMESTAMP" ) * 1000 ) ) . toString ( ) ) ;
new Timestamp ( ( rs . getLong ( "UPDATED_TIMESTAMP" ) * 1000 ) ) . toString ( ) ) ;
}
}
operation . setCode ( rs . getString ( "OPERATION_CODE" ) ) ;
operation . setInitiatedBy ( rs . getString ( "INITIATED_BY" ) ) ;
operation . setStatus ( Operation . Status . PENDING ) ;
operation . setStatus ( Operation . Status . PENDING ) ;
OperationDAOUtil . setActivityId ( operation , rs . getInt ( "ID" ) ) ;
}
}
return operation ;
return operation ;
} catch ( SQLException e ) {
} catch ( SQLException e ) {
@ -1975,8 +1902,9 @@ public class GenericOperationDAOImpl implements OperationDAO {
List < Operation > operations = new ArrayList < > ( ) ;
List < Operation > operations = new ArrayList < > ( ) ;
try {
try {
Connection conn = OperationManagementDAOFactory . getConnection ( ) ;
Connection conn = OperationManagementDAOFactory . getConnection ( ) ;
String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, OPERATION_CODE, o.INITIATED_BY," +
String sql = "SELECT o.ID, TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, OPERATION_CODE, " +
" om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM " +
"o.INITIATED_BY, o.OPERATION_DETAILS, o.OPERATION_PROPERTIES, " +
"om.ID AS OM_MAPPING_ID, om.UPDATED_TIMESTAMP FROM " +
"(SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, INITIATED_BY " +
"(SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, INITIATED_BY " +
"FROM DM_OPERATION o WHERE o.TYPE = ?) o INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
"FROM DM_OPERATION o WHERE o.TYPE = ?) o INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
"WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC" ;
"WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC" ;
@ -1988,19 +1916,14 @@ public class GenericOperationDAOImpl implements OperationDAO {
rs = stmt . executeQuery ( ) ;
rs = stmt . executeQuery ( ) ;
while ( rs . next ( ) ) {
while ( rs . next ( ) ) {
operation = new Operation ( ) ;
operation = OperationDAOUtil . getOperation ( rs ) ;
operation . setId ( rs . getInt ( "ID" ) ) ;
operation . setStatus ( status ) ;
operation . setType ( Operation . Type . valueOf ( rs . getString ( "TYPE" ) ) ) ;
operation . setCreatedTimeStamp ( new Timestamp ( rs . getLong ( "CREATED_TIMESTAMP" ) * 1000L ) . toString ( ) ) ;
if ( rs . getLong ( "UPDATED_TIMESTAMP" ) = = 0 ) {
if ( rs . getLong ( "UPDATED_TIMESTAMP" ) = = 0 ) {
operation . setReceivedTimeStamp ( "" ) ;
operation . setReceivedTimeStamp ( "" ) ;
} else {
} else {
operation . setReceivedTimeStamp (
operation . setReceivedTimeStamp (
new Timestamp ( ( rs . getLong ( "UPDATED_TIMESTAMP" ) * 1000 ) ) . toString ( ) ) ;
new Timestamp ( ( rs . getLong ( "UPDATED_TIMESTAMP" ) * 1000 ) ) . toString ( ) ) ;
}
}
operation . setCode ( rs . getString ( "OPERATION_CODE" ) ) ;
operation . setInitiatedBy ( rs . getString ( "INITIATED_BY" ) ) ;
OperationDAOUtil . setActivityId ( operation , rs . getInt ( "ID" ) ) ;
operations . add ( operation ) ;
operations . add ( operation ) ;
}
}
} catch ( SQLException e ) {
} catch ( SQLException e ) {
@ -2013,7 +1936,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
}
}
@Override
@Override
public Map < Integer , List < OperationMapping > > getOperationMappingsByStatus ( Operation . Status opStatus , Operation . PushNotificationStatus pushNotificationStatus ,
public Map < Integer , List < OperationMapping > > getOperationMappingsByStatus ( Operation . Status opStatus ,
Operation . PushNotificationStatus pushNotificationStatus ,
int limit ) throws OperationManagementDAOException {
int limit ) throws OperationManagementDAOException {
PreparedStatement stmt = null ;
PreparedStatement stmt = null ;
ResultSet rs = null ;
ResultSet rs = null ;
@ -2059,7 +1983,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
@Override
@Override
public Map < Integer , List < OperationMapping > > getAllocatedOperationMappingsByStatus ( Operation . Status opStatus ,
public Map < Integer , List < OperationMapping > > getAllocatedOperationMappingsByStatus ( Operation . Status opStatus ,
Operation . PushNotificationStatus pushNotificationStatus , int limit , int activeServerCount , int serverIndex )
Operation . PushNotificationStatus pushNotificationStatus ,
int limit , int activeServerCount , int serverIndex )
throws OperationManagementDAOException {
throws OperationManagementDAOException {
PreparedStatement stmt = null ;
PreparedStatement stmt = null ;
ResultSet rs = null ;
ResultSet rs = null ;