Merge branch 'carbon-kernel-4.4.3' of https://github.com/wso2/carbon-device-mgt into carbon-kernel-4.4.3

revert-70aa11f8
hasuniea 8 years ago
commit 282f53bf09

@ -113,12 +113,6 @@ public interface DeviceManagementService {
required = false) required = false)
@QueryParam("user") @QueryParam("user")
String user, String user,
@ApiParam(
name = "roleName",
value = "Role name of the devices to be fetched.",
required = false)
@QueryParam("roleName")
String roleName,
@ApiParam( @ApiParam(
name = "ownership", name = "ownership",
allowableValues = "BYOD, COPE", allowableValues = "BYOD, COPE",

@ -65,7 +65,6 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
@QueryParam("name") String name, @QueryParam("name") String name,
@QueryParam("type") String type, @QueryParam("type") String type,
@QueryParam("user") String user, @QueryParam("user") String user,
@QueryParam("roleName") String roleName,
@QueryParam("ownership") String ownership, @QueryParam("ownership") String ownership,
@QueryParam("status") String status, @QueryParam("status") String status,
@QueryParam("since") String since, @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.", @ApiModelProperty(name = "id", value = "ID of the device in the WSO2 EMM device information database.",
required = true) required = true)
private int id; private int id;
@ApiModelProperty(name = "device", value = "Enrolled device.", required = true) @ApiModelProperty(name = "dateOfEnrolment", value = "Date of the device enrollment. This value is not necessary.", required = false )
private Device device;
@ApiModelProperty(name = "dateOfEnrolment", value = "Date of the device enrollment.", required = true )
private Long dateOfEnrolment; 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; private Long dateOfLastUpdate;
@ApiModelProperty(name = "ownership", value = "Defines the ownership details. The ownership type can be any of the" + @ApiModelProperty(name = "ownership", value = "Defines the ownership details. The ownership type can be any of the" +
" following values.\n" + " following values.\n" +
@ -60,8 +58,7 @@ public class EnrolmentInfo implements Serializable {
public EnrolmentInfo() { public EnrolmentInfo() {
} }
public EnrolmentInfo(Device device, String owner, OwnerShip ownership, Status status) { public EnrolmentInfo(String owner, OwnerShip ownership, Status status) {
this.device = device;
this.owner = owner; this.owner = owner;
this.ownership = ownership; this.ownership = ownership;
this.status = status; this.status = status;
@ -115,14 +112,6 @@ public class EnrolmentInfo implements Serializable {
this.owner = owner; this.owner = owner;
} }
public Device getDevice() {
return device;
}
public void setDevice(Device device) {
this.device = device;
}
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj instanceof EnrolmentInfo) { if (obj instanceof EnrolmentInfo) {

@ -73,18 +73,16 @@ public class EnrollmentDAOImpl implements EnrollmentDAO {
int status = -1; int status = -1;
try { try {
conn = this.getConnection(); conn = this.getConnection();
String sql = "UPDATE DM_ENROLMENT SET OWNERSHIP = ?, STATUS = ?, " + String sql = "UPDATE DM_ENROLMENT SET OWNERSHIP = ?, STATUS = ?, DATE_OF_LAST_UPDATE = ? WHERE DEVICE_ID = ?" +
"DATE_OF_ENROLMENT = ?, DATE_OF_LAST_UPDATE = ? WHERE DEVICE_ID = ? AND OWNER = ? AND TENANT_ID = ?" + " AND OWNER = ? AND TENANT_ID = ? AND ID = ?";
" AND ID = ?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, enrolmentInfo.getOwnership().toString()); stmt.setString(1, enrolmentInfo.getOwnership().toString());
stmt.setString(2, enrolmentInfo.getStatus().toString()); stmt.setString(2, enrolmentInfo.getStatus().toString());
stmt.setTimestamp(3, new Timestamp(enrolmentInfo.getDateOfEnrolment())); stmt.setTimestamp(3, new Timestamp(new Date().getTime()));
stmt.setTimestamp(4, new Timestamp(new Date().getTime())); stmt.setInt(4, deviceId);
stmt.setInt(5, deviceId); stmt.setString(5, enrolmentInfo.getOwner());
stmt.setString(6, enrolmentInfo.getOwner()); stmt.setInt(6, tenantId);
stmt.setInt(7, tenantId); stmt.setInt(7, enrolmentInfo.getId());
stmt.setInt(8, enrolmentInfo.getId());
stmt.executeUpdate(); stmt.executeUpdate();
return status; return status;
} catch (SQLException e) { } catch (SQLException e) {
@ -102,14 +100,12 @@ public class EnrollmentDAOImpl implements EnrollmentDAO {
int status = -1; int status = -1;
try { try {
conn = this.getConnection(); conn = this.getConnection();
String sql = "UPDATE DM_ENROLMENT SET OWNERSHIP = ?, STATUS = ?, " + String sql = "UPDATE DM_ENROLMENT SET OWNERSHIP = ?, STATUS = ?, DATE_OF_LAST_UPDATE = ? WHERE ID = ?";
"DATE_OF_ENROLMENT = ?, DATE_OF_LAST_UPDATE = ? WHERE ID = ?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, enrolmentInfo.getOwnership().toString()); stmt.setString(1, enrolmentInfo.getOwnership().toString());
stmt.setString(2, enrolmentInfo.getStatus().toString()); stmt.setString(2, enrolmentInfo.getStatus().toString());
stmt.setTimestamp(3, new Timestamp(enrolmentInfo.getDateOfEnrolment())); stmt.setTimestamp(3, new Timestamp(new Date().getTime()));
stmt.setTimestamp(4, new Timestamp(new Date().getTime())); stmt.setInt(4, enrolmentInfo.getId());
stmt.setInt(5, enrolmentInfo.getId());
stmt.executeUpdate(); stmt.executeUpdate();
return status; return status;
} catch (SQLException e) { } 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.NotificationStrategy;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException; 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.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.DeviceDAO;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; 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 = org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operationDto =
OperationDAOUtil.convertOperation(operation); OperationDAOUtil.convertOperation(operation);
int operationId = this.lookupOperationDAO(operation).addOperation(operationDto); 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. //TODO have to create a sql to load device details from deviceDAO using single query.
String operationCode = operationDto.getCode();
for (DeviceIdentifier deviceId : deviceIds) { for (DeviceIdentifier deviceId : deviceIds) {
Device device = getDevice(deviceId); Device device = getDevice(deviceId);
if (operationDto.getControl() == enrolmentId = device.getEnrolmentInfo().getId();
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Control.NO_REPEAT) { //Do not repeat the task operations
operationDAO.updateEnrollmentOperationsStatus(device.getEnrolmentInfo().getId(), operationDto.getCode(), if (isScheduledOperation) {
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING, hasExistingTaskOperation = operationDAO.updateTaskOperation(enrolmentId, operationCode);
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.REPEATED); 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) { if (notificationStrategy != null) {
try { try {
notificationStrategy.execute(new NotificationContext(deviceId, operation)); notificationStrategy.execute(new NotificationContext(deviceId, operation));
@ -129,7 +149,7 @@ public class OperationManagerImpl implements OperationManager {
OperationManagementDAOFactory.commitTransaction(); OperationManagementDAOFactory.commitTransaction();
Activity activity = new Activity(); Activity activity = new Activity();
activity.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + operationId); activity.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + operationId);
activity.setCode(operationDto.getCode()); activity.setCode(operationCode);
activity.setCreatedTimeStamp(new Date().toString()); activity.setCreatedTimeStamp(new Date().toString());
activity.setType(Activity.Type.valueOf(operationDto.getType().toString())); activity.setType(Activity.Type.valueOf(operationDto.getType().toString()));
return activity; return activity;
@ -788,4 +808,15 @@ public class OperationManagerImpl implements OperationManager {
return enrolmentId; 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, void updateEnrollmentOperationsStatus(int enrolmentId, String operationCode, Operation.Status existingStatus,
Operation.Status newStatus) throws OperationManagementDAOException; Operation.Status newStatus) throws OperationManagementDAOException;
boolean updateTaskOperation(int enrolmentId, String operationCode) throws OperationManagementDAOException;
void addOperationResponse(int enrolmentId, int operationId, Object operationResponse) void addOperationResponse(int enrolmentId, int operationId, Object operationResponse)
throws OperationManagementDAOException; 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 @Override
public void addOperationResponse(int enrolmentId, int operationId, Object operationResponse) public void addOperationResponse(int enrolmentId, int operationId, Object operationResponse)
throws OperationManagementDAOException { throws OperationManagementDAOException {

@ -41,7 +41,7 @@ public class EnrolmentPersistenceTests extends BaseDeviceManagementTest {
/* Initializing source enrolment configuration bean to be tested */ /* Initializing source enrolment configuration bean to be tested */
EnrolmentInfo source = EnrolmentInfo source =
new EnrolmentInfo(null, owner, EnrolmentInfo.OwnerShip.BYOD, new EnrolmentInfo(owner, EnrolmentInfo.OwnerShip.BYOD,
EnrolmentInfo.Status.CREATED); EnrolmentInfo.Status.CREATED);
/* Adding dummy enrolment configuration to the device management metadata store */ /* Adding dummy enrolment configuration to the device management metadata store */

Loading…
Cancel
Save