Merge pull request #1253 from geethkokila/master

Adding a audit trail for operation
merge-requests/7/head
Geeth 6 years ago committed by GitHub
commit 5d70a252ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -73,6 +73,13 @@ public class Activity {
@JsonProperty("activityStatuses")
private List<ActivityStatus> activityStatus;
@ApiModelProperty(
name = "initiatedBy",
value = "Initiated user",
required = true)
@JsonProperty("initiatedBy")
private String initiatedBy;
public String getActivityId() {
return activityId;
}
@ -112,5 +119,13 @@ public class Activity {
public void setActivityStatus(List<ActivityStatus> activityStatus) {
this.activityStatus = activityStatus;
}
public String getInitiatedBy() {
return initiatedBy;
}
public void setInitiatedBy(String initiatedBy) {
this.initiatedBy = initiatedBy;
}
}

@ -90,6 +90,12 @@ public class Operation implements Serializable {
@ApiModelProperty(name = "activityId", value = "The identifier used to identify the operation uniquely.",
required = true)
private String activityId;
@ApiModelProperty(name = "initiatedBy", value = "This identifies the person whom operation initiated. This could be " +
"EMM server or the one who initiated the API call to add an operation.",
required = true)
private String initiatedBy;
private List<OperationResponse> responses;
@Override
@ -267,6 +273,14 @@ public class Operation implements Serializable {
this.responses = responses;
}
public String getInitiatedBy() {
return initiatedBy;
}
public void setInitiatedBy(String initiatedBy) {
this.initiatedBy = initiatedBy;
}
@Override
public String toString() {
return "Operation{" +

@ -51,6 +51,7 @@ public class Operation implements Serializable {
private Object payLoad;
private Object operationResponse;
private String activityId;
private String initiatedBy;
public String getCode() {
return code;
@ -148,4 +149,11 @@ public class Operation implements Serializable {
this.activityId = activityId;
}
public String getInitiatedBy() {
return initiatedBy;
}
public void setInitiatedBy(String initiatedBy) {
this.initiatedBy = initiatedBy;
}
}

@ -82,6 +82,7 @@ public class OperationManagerImpl implements OperationManager {
private static final Log log = LogFactory.getLog(OperationManagerImpl.class);
private static final int CACHE_VALIDITY_PERIOD = 5 * 60 * 1000;
private static final String NOTIFIER_TYPE_LOCAL = "LOCAL";
private static final String SYSTEM = "system";
private OperationDAO commandOperationDAO;
private OperationDAO configOperationDAO;
@ -171,11 +172,24 @@ public class OperationManagerImpl implements OperationManager {
return activity;
}
boolean isScheduledOperation = this.isTaskScheduledOperation(operation);
String initiatedBy = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
if (initiatedBy == null && isScheduledOperation) {
if(log.isDebugEnabled()) {
log.debug("initiatedBy : " + SYSTEM);
}
operation.setInitiatedBy(SYSTEM);
} else {
if(log.isDebugEnabled()) {
log.debug("initiatedBy : " + initiatedBy);
}
operation.setInitiatedBy(initiatedBy);
}
OperationManagementDAOFactory.beginTransaction();
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operationDto =
OperationDAOUtil.convertOperation(operation);
int operationId = this.lookupOperationDAO(operation).addOperation(operationDto);
boolean isScheduledOperation = this.isTaskScheduledOperation(operation);
boolean isNotRepeated = false;
boolean isScheduled = false;
NotificationStrategy notificationStrategy = getNotificationStrategy();

@ -63,13 +63,14 @@ public class GenericOperationDAOImpl implements OperationDAO {
ResultSet rs = null;
try {
Connection connection = OperationManagementDAOFactory.getConnection();
String sql = "INSERT INTO DM_OPERATION(TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE) " +
"VALUES (?, ?, ?, ?)";
String sql = "INSERT INTO DM_OPERATION(TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, " +
"INITIATED_BY) VALUES (?, ?, ?, ?, ?)";
stmt = connection.prepareStatement(sql, new String[]{"id"});
stmt.setString(1, operation.getType().toString());
stmt.setTimestamp(2, new Timestamp(new Date().getTime()));
stmt.setTimestamp(3, null);
stmt.setString(4, operation.getCode());
stmt.setString(5, operation.getInitiatedBy());
stmt.executeUpdate();
rs = stmt.getGeneratedKeys();
@ -245,7 +246,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
"de.DEVICE_ID, d.DEVICE_IDENTIFICATION, \n" +
"d.DEVICE_TYPE_ID, dt.NAME AS DEVICE_TYPE_NAME, eom.STATUS, eom.CREATED_TIMESTAMP, \n" +
"eom.UPDATED_TIMESTAMP, op.OPERATION_CODE, op.TYPE AS OPERATION_TYPE, dor.OPERATION_RESPONSE, \n" +
"dor.RECEIVED_TIMESTAMP FROM DM_ENROLMENT_OP_MAPPING eom \n" +
"dor.RECEIVED_TIMESTAMP, op.INITIATED_BY FROM DM_ENROLMENT_OP_MAPPING eom \n" +
"INNER JOIN DM_OPERATION op ON op.ID=eom.OPERATION_ID\n" +
"INNER JOIN DM_ENROLMENT de ON de.ID=eom.ENROLMENT_ID\n" +
"INNER JOIN DM_DEVICE d ON d.ID=de.DEVICE_ID \n" +
@ -268,6 +269,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE")));
activity.setCreatedTimeStamp(new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString());
activity.setCode(rs.getString("OPERATION_CODE"));
activity.setInitiatedBy(rs.getString("INITIATED_BY"));
}
if (enrolmentId != rs.getInt("ENROLMENT_ID")) {
activityStatus = new ActivityStatus();
@ -325,7 +327,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
+ "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, "
+ "eom.UPDATED_TIMESTAMP, op.OPERATION_CODE, op.TYPE AS OPERATION_TYPE, "
+ "dor.OPERATION_RESPONSE, dor.RECEIVED_TIMESTAMP FROM "
+ "dor.OPERATION_RESPONSE, op.INITIATED_BY, dor.RECEIVED_TIMESTAMP FROM "
+ "DM_ENROLMENT_OP_MAPPING eom INNER JOIN DM_OPERATION op "
+ "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 \n"
@ -359,6 +361,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
activity.setCreatedTimeStamp(
new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString());
activity.setCode(rs.getString("OPERATION_CODE"));
activity.setInitiatedBy(rs.getString("INITIATED_BY"));
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(rs.getString("DEVICE_IDENTIFICATION"));
@ -448,7 +451,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
"de.DEVICE_ID, d.DEVICE_IDENTIFICATION, \n" +
"d.DEVICE_TYPE_ID, dt.NAME AS DEVICE_TYPE_NAME, eom.STATUS, eom.CREATED_TIMESTAMP, \n" +
"eom.UPDATED_TIMESTAMP, op.OPERATION_CODE, op.TYPE AS OPERATION_TYPE, dor.OPERATION_RESPONSE, \n" +
"dor.RECEIVED_TIMESTAMP FROM DM_ENROLMENT_OP_MAPPING AS eom \n" +
"dor.RECEIVED_TIMESTAMP, op.INITIATED_BY FROM DM_ENROLMENT_OP_MAPPING AS eom \n" +
"INNER JOIN DM_OPERATION AS op ON op.ID=eom.OPERATION_ID\n" +
"INNER JOIN DM_ENROLMENT AS de ON de.ID=eom.ENROLMENT_ID\n" +
"INNER JOIN DM_DEVICE AS d ON d.ID=de.DEVICE_ID \n" +
@ -472,6 +475,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE")));
activity.setCreatedTimeStamp(new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString());
activity.setCode(rs.getString("OPERATION_CODE"));
activity.setInitiatedBy(rs.getString("INITIATED_BY"));
}
if (enrolmentId != rs.getInt("ENROLMENT_ID")) {
activityStatus = new ActivityStatus();
@ -535,7 +539,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
" opr.DEVICE_TYPE, " +
" ops.RECEIVED_TIMESTAMP, " +
" ops.ID OP_RES_ID, " +
" ops.OPERATION_RESPONSE " +
" ops.OPERATION_RESPONSE, " +
" opr.INITIATED_BY " +
" FROM " +
" (SELECT " +
" opm.ID MAPPING_ID, " +
@ -544,6 +549,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
" opm.UPDATED_TIMESTAMP, " +
" opm.OPERATION_ID, " +
" op.OPERATION_CODE, " +
" op.INITIATED_BY, " +
" op.TYPE OPERATION_TYPE, " +
" opm.STATUS, " +
" en.DEVICE_ID, " +
@ -595,6 +601,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE")));
activity.setCreatedTimeStamp(new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString());
activity.setCode(rs.getString("OPERATION_CODE"));
activity.setInitiatedBy(rs.getString("INITIATED_BY"));
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(rs.getString("DEVICE_IDENTIFICATION"));

@ -91,7 +91,7 @@ public class MySQLOperationDAOImpl extends GenericOperationDAOImpl {
+ "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, "
+ "eom.UPDATED_TIMESTAMP, op.OPERATION_CODE, op.TYPE AS OPERATION_TYPE, "
+ "dor.OPERATION_RESPONSE, dor.RECEIVED_TIMESTAMP FROM "
+ "dor.OPERATION_RESPONSE, dor.RECEIVED_TIMESTAMP, op.INITIATED_BY FROM "
+ "DM_ENROLMENT_OP_MAPPING eom INNER JOIN DM_OPERATION op "
+ "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 \n"
@ -132,6 +132,7 @@ public class MySQLOperationDAOImpl extends GenericOperationDAOImpl {
activity.setCreatedTimeStamp(
new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString());
activity.setCode(rs.getString("OPERATION_CODE"));
activity.setInitiatedBy(rs.getString("INITIATED_BY"));
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(rs.getString("DEVICE_IDENTIFICATION"));
@ -164,6 +165,7 @@ public class MySQLOperationDAOImpl extends GenericOperationDAOImpl {
activity.setCreatedTimeStamp(
new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString());
activity.setCode(rs.getString("OPERATION_CODE"));
activity.setInitiatedBy(rs.getString("INITIATED_BY"));
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(rs.getString("DEVICE_IDENTIFICATION"));
@ -227,6 +229,7 @@ public class MySQLOperationDAOImpl extends GenericOperationDAOImpl {
" opr.UPDATED_TIMESTAMP, " +
" opr.OPERATION_ID, " +
" opr.OPERATION_CODE, " +
" opr.INITIATED_BY, " +
" opr.OPERATION_TYPE, " +
" opr.STATUS, " +
" opr.DEVICE_ID, " +
@ -243,6 +246,7 @@ public class MySQLOperationDAOImpl extends GenericOperationDAOImpl {
" opm.UPDATED_TIMESTAMP, " +
" opm.OPERATION_ID, " +
" op.OPERATION_CODE, " +
" op.INITIATED_BY, " +
" op.TYPE OPERATION_TYPE, " +
" opm.STATUS, " +
" en.DEVICE_ID, " +
@ -295,6 +299,7 @@ public class MySQLOperationDAOImpl extends GenericOperationDAOImpl {
activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE")));
activity.setCreatedTimeStamp(new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString());
activity.setCode(rs.getString("OPERATION_CODE"));
activity.setInitiatedBy(rs.getString("INITIATED_BY"));
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(rs.getString("DEVICE_IDENTIFICATION"));
@ -326,6 +331,7 @@ public class MySQLOperationDAOImpl extends GenericOperationDAOImpl {
activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE")));
activity.setCreatedTimeStamp(new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString());
activity.setCode(rs.getString("OPERATION_CODE"));
activity.setInitiatedBy(rs.getString("INITIATED_BY"));
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(rs.getString("DEVICE_IDENTIFICATION"));

@ -68,6 +68,7 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION (
CREATED_TIMESTAMP TIMESTAMP NOT NULL,
RECEIVED_TIMESTAMP TIMESTAMP NULL,
OPERATION_CODE VARCHAR(1000) NOT NULL,
INITIATED_BY VARCHAR(100) NULL,
PRIMARY KEY (ID)
);

@ -75,6 +75,7 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION (
CREATED_TIMESTAMP TIMESTAMP NOT NULL,
RECEIVED_TIMESTAMP TIMESTAMP NULL,
OPERATION_CODE VARCHAR(1000) NOT NULL,
INITIATED_BY VARCHAR(100) NULL,
PRIMARY KEY (ID)
);

@ -68,6 +68,7 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION (
CREATED_TIMESTAMP TIMESTAMP NOT NULL,
RECEIVED_TIMESTAMP TIMESTAMP NULL,
OPERATION_CODE VARCHAR(1000) NOT NULL,
INITIATED_BY VARCHAR(100) NULL,
PRIMARY KEY (ID)
);

@ -93,6 +93,7 @@ CREATE TABLE DM_OPERATION (
CREATED_TIMESTAMP DATETIME2 NOT NULL,
RECEIVED_TIMESTAMP DATETIME2 NULL,
OPERATION_CODE VARCHAR(50) NOT NULL,
INITIATED_BY VARCHAR(100) NULL,
PRIMARY KEY (ID)
);

@ -83,6 +83,7 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION (
CREATED_TIMESTAMP TIMESTAMP NOT NULL,
RECEIVED_TIMESTAMP TIMESTAMP NULL,
OPERATION_CODE VARCHAR(50) NOT NULL,
INITIATED_BY VARCHAR(100) NULL,
PRIMARY KEY (ID)
)ENGINE = InnoDB;

@ -145,6 +145,7 @@ CREATE TABLE DM_OPERATION (
CREATED_TIMESTAMP TIMESTAMP(0) NOT NULL,
RECEIVED_TIMESTAMP TIMESTAMP(0) NULL,
OPERATION_CODE VARCHAR2(1000) NOT NULL,
INITIATED_BY VARCHAR2(100) NULL,
CONSTRAINT PK_DM_OPERATION PRIMARY KEY (ID)
)
/

@ -66,7 +66,8 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION (
TYPE VARCHAR(50) NOT NULL,
CREATED_TIMESTAMP TIMESTAMP NOT NULL,
RECEIVED_TIMESTAMP TIMESTAMP NULL,
OPERATION_CODE VARCHAR(1000) NOT NULL
OPERATION_CODE VARCHAR(1000) NOT NULL,
INITIATED_BY VARCHAR(50) NULL
);
CREATE TABLE IF NOT EXISTS DM_CONFIG_OPERATION (

Loading…
Cancel
Save