mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge branch 'carbon-kernel-4.4.3' of https://github.com/wso2/carbon-device-mgt into carbon-kernel-4.4.3
This commit is contained in:
commit
282f53bf09
@ -113,12 +113,6 @@ public interface DeviceManagementService {
|
||||
required = false)
|
||||
@QueryParam("user")
|
||||
String user,
|
||||
@ApiParam(
|
||||
name = "roleName",
|
||||
value = "Role name of the devices to be fetched.",
|
||||
required = false)
|
||||
@QueryParam("roleName")
|
||||
String roleName,
|
||||
@ApiParam(
|
||||
name = "ownership",
|
||||
allowableValues = "BYOD, COPE",
|
||||
|
||||
@ -65,7 +65,6 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
||||
@QueryParam("name") String name,
|
||||
@QueryParam("type") String type,
|
||||
@QueryParam("user") String user,
|
||||
@QueryParam("roleName") String roleName,
|
||||
@QueryParam("ownership") String ownership,
|
||||
@QueryParam("status") String status,
|
||||
@QueryParam("since") String since,
|
||||
|
||||
@ -40,11 +40,9 @@ public class EnrolmentInfo implements Serializable {
|
||||
@ApiModelProperty(name = "id", value = "ID of the device in the WSO2 EMM device information database.",
|
||||
required = true)
|
||||
private int id;
|
||||
@ApiModelProperty(name = "device", value = "Enrolled device.", required = true)
|
||||
private Device device;
|
||||
@ApiModelProperty(name = "dateOfEnrolment", value = "Date of the device enrollment.", required = true )
|
||||
@ApiModelProperty(name = "dateOfEnrolment", value = "Date of the device enrollment. This value is not necessary.", required = false )
|
||||
private Long dateOfEnrolment;
|
||||
@ApiModelProperty(name = "dateOfLastUpdate", value = "Date of the device's last update.", required = true )
|
||||
@ApiModelProperty(name = "dateOfLastUpdate", value = "Date of the device's last update. This value is not necessary.", required = false )
|
||||
private Long dateOfLastUpdate;
|
||||
@ApiModelProperty(name = "ownership", value = "Defines the ownership details. The ownership type can be any of the" +
|
||||
" following values.\n" +
|
||||
@ -60,8 +58,7 @@ public class EnrolmentInfo implements Serializable {
|
||||
public EnrolmentInfo() {
|
||||
}
|
||||
|
||||
public EnrolmentInfo(Device device, String owner, OwnerShip ownership, Status status) {
|
||||
this.device = device;
|
||||
public EnrolmentInfo(String owner, OwnerShip ownership, Status status) {
|
||||
this.owner = owner;
|
||||
this.ownership = ownership;
|
||||
this.status = status;
|
||||
@ -115,14 +112,6 @@ public class EnrolmentInfo implements Serializable {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
public Device getDevice() {
|
||||
return device;
|
||||
}
|
||||
|
||||
public void setDevice(Device device) {
|
||||
this.device = device;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof EnrolmentInfo) {
|
||||
|
||||
@ -73,18 +73,16 @@ public class EnrollmentDAOImpl implements EnrollmentDAO {
|
||||
int status = -1;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String sql = "UPDATE DM_ENROLMENT SET OWNERSHIP = ?, STATUS = ?, " +
|
||||
"DATE_OF_ENROLMENT = ?, DATE_OF_LAST_UPDATE = ? WHERE DEVICE_ID = ? AND OWNER = ? AND TENANT_ID = ?" +
|
||||
" AND ID = ?";
|
||||
String sql = "UPDATE DM_ENROLMENT SET OWNERSHIP = ?, STATUS = ?, DATE_OF_LAST_UPDATE = ? WHERE DEVICE_ID = ?" +
|
||||
" AND OWNER = ? AND TENANT_ID = ? AND ID = ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, enrolmentInfo.getOwnership().toString());
|
||||
stmt.setString(2, enrolmentInfo.getStatus().toString());
|
||||
stmt.setTimestamp(3, new Timestamp(enrolmentInfo.getDateOfEnrolment()));
|
||||
stmt.setTimestamp(4, new Timestamp(new Date().getTime()));
|
||||
stmt.setInt(5, deviceId);
|
||||
stmt.setString(6, enrolmentInfo.getOwner());
|
||||
stmt.setInt(7, tenantId);
|
||||
stmt.setInt(8, enrolmentInfo.getId());
|
||||
stmt.setTimestamp(3, new Timestamp(new Date().getTime()));
|
||||
stmt.setInt(4, deviceId);
|
||||
stmt.setString(5, enrolmentInfo.getOwner());
|
||||
stmt.setInt(6, tenantId);
|
||||
stmt.setInt(7, enrolmentInfo.getId());
|
||||
stmt.executeUpdate();
|
||||
return status;
|
||||
} catch (SQLException e) {
|
||||
@ -102,14 +100,12 @@ public class EnrollmentDAOImpl implements EnrollmentDAO {
|
||||
int status = -1;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String sql = "UPDATE DM_ENROLMENT SET OWNERSHIP = ?, STATUS = ?, " +
|
||||
"DATE_OF_ENROLMENT = ?, DATE_OF_LAST_UPDATE = ? WHERE ID = ?";
|
||||
String sql = "UPDATE DM_ENROLMENT SET OWNERSHIP = ?, STATUS = ?, DATE_OF_LAST_UPDATE = ? WHERE ID = ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, enrolmentInfo.getOwnership().toString());
|
||||
stmt.setString(2, enrolmentInfo.getStatus().toString());
|
||||
stmt.setTimestamp(3, new Timestamp(enrolmentInfo.getDateOfEnrolment()));
|
||||
stmt.setTimestamp(4, new Timestamp(new Date().getTime()));
|
||||
stmt.setInt(5, enrolmentInfo.getId());
|
||||
stmt.setTimestamp(3, new Timestamp(new Date().getTime()));
|
||||
stmt.setInt(4, enrolmentInfo.getId());
|
||||
stmt.executeUpdate();
|
||||
return status;
|
||||
} catch (SQLException e) {
|
||||
|
||||
@ -32,6 +32,8 @@ import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
|
||||
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
|
||||
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException;
|
||||
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
|
||||
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
||||
import org.wso2.carbon.device.mgt.core.config.task.TaskConfiguration;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||
@ -106,16 +108,34 @@ public class OperationManagerImpl implements OperationManager {
|
||||
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 hasExistingTaskOperation;
|
||||
int enrolmentId;
|
||||
if (operationDto.getControl() ==
|
||||
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Control.NO_REPEAT) {
|
||||
isNotRepeated = true;
|
||||
}
|
||||
|
||||
//TODO have to create a sql to load device details from deviceDAO using single query.
|
||||
String operationCode = operationDto.getCode();
|
||||
for (DeviceIdentifier deviceId : deviceIds) {
|
||||
Device device = getDevice(deviceId);
|
||||
if (operationDto.getControl() ==
|
||||
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Control.NO_REPEAT) {
|
||||
operationDAO.updateEnrollmentOperationsStatus(device.getEnrolmentInfo().getId(), operationDto.getCode(),
|
||||
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING,
|
||||
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.REPEATED);
|
||||
enrolmentId = device.getEnrolmentInfo().getId();
|
||||
//Do not repeat the task operations
|
||||
if (isScheduledOperation) {
|
||||
hasExistingTaskOperation = operationDAO.updateTaskOperation(enrolmentId, operationCode);
|
||||
if (!hasExistingTaskOperation) {
|
||||
operationMappingDAO.addOperationMapping(operationId, enrolmentId);
|
||||
}
|
||||
} else if (isNotRepeated) {
|
||||
operationDAO.updateEnrollmentOperationsStatus(enrolmentId, operationCode,
|
||||
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING,
|
||||
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.REPEATED);
|
||||
operationMappingDAO.addOperationMapping(operationId, enrolmentId);
|
||||
} else {
|
||||
operationMappingDAO.addOperationMapping(operationId, enrolmentId);
|
||||
}
|
||||
operationMappingDAO.addOperationMapping(operationId, device.getEnrolmentInfo().getId());
|
||||
if (notificationStrategy != null) {
|
||||
try {
|
||||
notificationStrategy.execute(new NotificationContext(deviceId, operation));
|
||||
@ -129,7 +149,7 @@ public class OperationManagerImpl implements OperationManager {
|
||||
OperationManagementDAOFactory.commitTransaction();
|
||||
Activity activity = new Activity();
|
||||
activity.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + operationId);
|
||||
activity.setCode(operationDto.getCode());
|
||||
activity.setCode(operationCode);
|
||||
activity.setCreatedTimeStamp(new Date().toString());
|
||||
activity.setType(Activity.Type.valueOf(operationDto.getType().toString()));
|
||||
return activity;
|
||||
@ -788,4 +808,15 @@ public class OperationManagerImpl implements OperationManager {
|
||||
return enrolmentId;
|
||||
}
|
||||
|
||||
private boolean isTaskScheduledOperation(Operation operation) {
|
||||
TaskConfiguration taskConfiguration = DeviceConfigurationManager.getInstance().getDeviceManagementConfig().
|
||||
getTaskConfiguration();
|
||||
for (TaskConfiguration.Operation op:taskConfiguration.getOperations()) {
|
||||
if (operation.getCode().equals(op.getOperationName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -60,6 +60,8 @@ public interface OperationDAO {
|
||||
void updateEnrollmentOperationsStatus(int enrolmentId, String operationCode, Operation.Status existingStatus,
|
||||
Operation.Status newStatus) throws OperationManagementDAOException;
|
||||
|
||||
boolean updateTaskOperation(int enrolmentId, String operationCode) throws OperationManagementDAOException;
|
||||
|
||||
void addOperationResponse(int enrolmentId, int operationId, Object operationResponse)
|
||||
throws OperationManagementDAOException;
|
||||
|
||||
|
||||
@ -154,6 +154,44 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateTaskOperation(int enrolmentId, String operationCode)
|
||||
throws OperationManagementDAOException {
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
boolean result = false;
|
||||
try {
|
||||
Connection connection = OperationManagementDAOFactory.getConnection();
|
||||
String query = "SELECT EOM.ID FROM DM_ENROLMENT_OP_MAPPING AS EOM INNER JOIN DM_OPERATION DM " +
|
||||
"ON DM.ID = EOM.OPERATION_ID WHERE EOM.ENROLMENT_ID = ? AND DM.OPERATION_CODE = ? AND " +
|
||||
"EOM.STATUS = ?;";
|
||||
stmt = connection.prepareStatement(query);
|
||||
stmt.setInt(1, enrolmentId);
|
||||
stmt.setString(2, operationCode);
|
||||
stmt.setString(3, Operation.Status.PENDING.toString());
|
||||
// This will return only one result always.
|
||||
rs = stmt.executeQuery();
|
||||
int id = 0;
|
||||
if (rs.next()) {
|
||||
id = rs.getInt("ID");
|
||||
}
|
||||
if (id != 0) {
|
||||
stmt = connection.prepareStatement("UPDATE DM_ENROLMENT_OP_MAPPING SET UPDATED_TIMESTAMP = ? " +
|
||||
"WHERE ID = ?");
|
||||
stmt.setLong(1, System.currentTimeMillis() / 1000);
|
||||
stmt.setInt(2, id);
|
||||
stmt.executeUpdate();
|
||||
result = true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new OperationManagementDAOException("Error occurred while update device mapping operation status " +
|
||||
"metadata", e);
|
||||
} finally {
|
||||
OperationManagementDAOUtil.cleanupResources(stmt);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOperationResponse(int enrolmentId, int operationId, Object operationResponse)
|
||||
throws OperationManagementDAOException {
|
||||
|
||||
@ -41,7 +41,7 @@ public class EnrolmentPersistenceTests extends BaseDeviceManagementTest {
|
||||
|
||||
/* Initializing source enrolment configuration bean to be tested */
|
||||
EnrolmentInfo source =
|
||||
new EnrolmentInfo(null, owner, EnrolmentInfo.OwnerShip.BYOD,
|
||||
new EnrolmentInfo(owner, EnrolmentInfo.OwnerShip.BYOD,
|
||||
EnrolmentInfo.Status.CREATED);
|
||||
|
||||
/* Adding dummy enrolment configuration to the device management metadata store */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user