|
|
|
@ -156,9 +156,11 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|
|
|
|
device.getDeviceIdentifier() + "', which belongs to " + "platform '" +
|
|
|
|
|
device.getType() + " upon the user '" + device.getEnrolmentInfo().getOwner() + "'");
|
|
|
|
|
}
|
|
|
|
|
} catch (TransactionManagementException | DeviceManagementDAOException e) {
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
|
DeviceManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
log.error("Error occurred while adding enrolment related metadata", e);
|
|
|
|
|
throw new DeviceManagementException("Error occurred while adding enrolment related metadata", e);
|
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
|
throw new DeviceManagementException("Error occurred while initiating transaction", e);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
@ -173,10 +175,12 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|
|
|
|
int deviceId = deviceDAO.addDevice(type.getId(), device, tenantId);
|
|
|
|
|
enrolmentId = enrolmentDAO.addEnrollment(deviceId, device.getEnrolmentInfo(), tenantId);
|
|
|
|
|
DeviceManagementDAOFactory.commitTransaction();
|
|
|
|
|
} catch (DeviceManagementDAOException | TransactionManagementException e) {
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
|
DeviceManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
log.error("Error occurred while adding metadata of '" + device.getType() + "' device carrying " +
|
|
|
|
|
"the identifier '" + device.getDeviceIdentifier() + "'", e);
|
|
|
|
|
throw new DeviceManagementException("Error occurred while adding metadata of '" + device.getType() +
|
|
|
|
|
"' device carrying the identifier '" + device.getDeviceIdentifier() + "'", e);
|
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
|
throw new DeviceManagementException("Error occurred while initiating transaction", e);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
@ -214,10 +218,12 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|
|
|
|
enrolmentDAO.updateEnrollment(deviceId, device.getEnrolmentInfo(), tenantId);
|
|
|
|
|
|
|
|
|
|
DeviceManagementDAOFactory.commitTransaction();
|
|
|
|
|
} catch (DeviceManagementDAOException | TransactionManagementException e) {
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
|
DeviceManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
throw new DeviceManagementException("Error occurred while modifying the device " +
|
|
|
|
|
"'" + device.getId() + "'", e);
|
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
|
throw new DeviceManagementException("Error occurred while initiating transaction", e);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
@ -247,10 +253,12 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|
|
|
|
deviceDAO.updateDevice(deviceType.getId(), device, tenantId);
|
|
|
|
|
|
|
|
|
|
DeviceManagementDAOFactory.commitTransaction();
|
|
|
|
|
} catch (DeviceManagementDAOException | TransactionManagementException e) {
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
|
DeviceManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
throw new DeviceManagementException("Error occurred while dis-enrolling '" + deviceId.getType() +
|
|
|
|
|
"' device with the identifier '" + deviceId.getId() + "'", e);
|
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
|
throw new DeviceManagementException("Error occurred while initiating transaction", e);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
@ -302,14 +310,16 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|
|
|
|
List<Device> allDevices;
|
|
|
|
|
try {
|
|
|
|
|
DeviceManagementDAOFactory.openConnection();
|
|
|
|
|
|
|
|
|
|
allDevices = deviceDAO.getDevices(this.getTenantId());
|
|
|
|
|
} catch (DeviceManagementDAOException | SQLException e) {
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
|
throw new DeviceManagementException("Error occurred while retrieving device list pertaining to " +
|
|
|
|
|
"the current tenant", e);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new DeviceManagementException("Error occurred while opening a connection to the data source", e);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (Device device : allDevices) {
|
|
|
|
|
DeviceManager deviceManager = this.getDeviceManager(device.getType());
|
|
|
|
|
if (deviceManager == null) {
|
|
|
|
@ -338,9 +348,11 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|
|
|
|
try {
|
|
|
|
|
DeviceManagementDAOFactory.openConnection();
|
|
|
|
|
allDevices = deviceDAO.getDevices(deviceType, this.getTenantId());
|
|
|
|
|
} catch (DeviceManagementDAOException | SQLException e) {
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
|
throw new DeviceManagementException("Error occurred while retrieving all devices of type '" +
|
|
|
|
|
deviceType + "' that are being managed within the scope of current tenant", e);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new DeviceManagementException("Error occurred while opening a connection to the data source", e);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
@ -415,7 +427,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|
|
|
|
.getProperty("line.separator")).append(messageFooter3.trim());
|
|
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
log.error("IO error in processing enrol email message " + emailMessageProperties);
|
|
|
|
|
throw new DeviceManagementException("Error replacing tags in email template '" +
|
|
|
|
|
emailMessageProperties.getSubject() + "'", e);
|
|
|
|
|
}
|
|
|
|
@ -479,7 +490,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|
|
|
|
messageBuilder.append(System.getProperty("line.separator")).append(messageFooter3.trim());
|
|
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
log.error("IO error in processing enrol email message " + emailMessageProperties);
|
|
|
|
|
throw new DeviceManagementException("Error replacing tags in email template '" +
|
|
|
|
|
emailMessageProperties.getSubject() + "'", e);
|
|
|
|
|
}
|
|
|
|
@ -494,9 +504,11 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|
|
|
|
try {
|
|
|
|
|
DeviceManagementDAOFactory.openConnection();
|
|
|
|
|
device = deviceDAO.getDevice(deviceId, this.getTenantId());
|
|
|
|
|
} catch (DeviceManagementDAOException | SQLException e) {
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
|
throw new DeviceManagementException("Error occurred while obtaining the device for id " +
|
|
|
|
|
"'" + deviceId.getId() + "'", e);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new DeviceManagementException("Error occurred while opening a connection to the data source", e);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
@ -571,9 +583,11 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|
|
|
|
|
|
|
|
|
DeviceManagementDAOFactory.commitTransaction();
|
|
|
|
|
return success;
|
|
|
|
|
} catch (DeviceManagementDAOException | TransactionManagementException e) {
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
|
DeviceManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
throw new DeviceManagementException("Error occurred while setting enrollment status", e);
|
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
|
throw new DeviceManagementException("Error occurred while initiating transaction", e);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
@ -620,8 +634,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int addOperation(Operation operation, List<DeviceIdentifier> devices) throws
|
|
|
|
|
OperationManagementException {
|
|
|
|
|
public int addOperation(Operation operation,
|
|
|
|
|
List<DeviceIdentifier> devices) throws OperationManagementException {
|
|
|
|
|
return DeviceManagementDataHolder.getInstance().getOperationManager().addOperation(operation, devices);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -652,8 +666,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Operation getOperationByDeviceAndOperationId(DeviceIdentifier deviceId, int operationId)
|
|
|
|
|
throws OperationManagementException {
|
|
|
|
|
public Operation getOperationByDeviceAndOperationId(DeviceIdentifier deviceId,
|
|
|
|
|
int operationId) throws OperationManagementException {
|
|
|
|
|
return DeviceManagementDataHolder.getInstance().getOperationManager().getOperationByDeviceAndOperationId(
|
|
|
|
|
deviceId, operationId);
|
|
|
|
|
}
|
|
|
|
@ -678,9 +692,11 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|
|
|
|
try {
|
|
|
|
|
DeviceManagementDAOFactory.openConnection();
|
|
|
|
|
userDevices = deviceDAO.getDevicesOfUser(username, this.getTenantId());
|
|
|
|
|
} catch (DeviceManagementDAOException | SQLException e) {
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
|
throw new DeviceManagementException("Error occurred while retrieving the list of devices that " +
|
|
|
|
|
"belong to the user '" + username + "'", e);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new DeviceManagementException("Error occurred while opening a connection to the data source", e);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
@ -749,8 +765,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|
|
|
|
try {
|
|
|
|
|
DeviceManagementDAOFactory.openConnection();
|
|
|
|
|
return deviceDAO.getDeviceCount(this.getTenantId());
|
|
|
|
|
} catch (DeviceManagementDAOException | SQLException e) {
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
|
throw new DeviceManagementException("Error occurred while retrieving the device count", e);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new DeviceManagementException("Error occurred while opening a connection to the data source", e);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
@ -763,9 +781,11 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|
|
|
|
try {
|
|
|
|
|
DeviceManagementDAOFactory.openConnection();
|
|
|
|
|
allDevices = deviceDAO.getDevicesByName(deviceName, this.getTenantId());
|
|
|
|
|
} catch (DeviceManagementDAOException | SQLException e) {
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
|
throw new DeviceManagementException("Error occurred while fetching the list of devices that matches to '"
|
|
|
|
|
+ deviceName + "'", e);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new DeviceManagementException("Error occurred while opening a connection to the data source", e);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
@ -785,14 +805,22 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|
|
|
|
@Override
|
|
|
|
|
public void updateDeviceEnrolmentInfo(Device device, EnrolmentInfo.Status status) throws DeviceManagementException {
|
|
|
|
|
try {
|
|
|
|
|
DeviceManagementDAOFactory.beginTransaction();
|
|
|
|
|
|
|
|
|
|
DeviceType deviceType = deviceTypeDAO.getDeviceType(device.getType());
|
|
|
|
|
device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime());
|
|
|
|
|
device.getEnrolmentInfo().setStatus(status);
|
|
|
|
|
deviceDAO.updateDevice(deviceType.getId(), device, this.getTenantId());
|
|
|
|
|
} catch (DeviceManagementDAOException deviceDaoEx) {
|
|
|
|
|
String errorMsg = "Error occured update device enrolment status : " + device.getId();
|
|
|
|
|
log.error(errorMsg, deviceDaoEx);
|
|
|
|
|
throw new DeviceManagementException(errorMsg, deviceDaoEx);
|
|
|
|
|
|
|
|
|
|
DeviceManagementDAOFactory.commitTransaction();
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
|
DeviceManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
throw new DeviceManagementException("Error occurred update device enrolment status : '" +
|
|
|
|
|
device.getId() + "'", e);
|
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
|
throw new DeviceManagementException("Error occurred while initiating transaction", e);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -823,12 +851,13 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|
|
|
|
try {
|
|
|
|
|
DeviceManagementDAOFactory.openConnection();
|
|
|
|
|
allDevices = deviceDAO.getDevicesByStatus(status, this.getTenantId());
|
|
|
|
|
} catch (DeviceManagementDAOException | SQLException e) {
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
|
throw new DeviceManagementException(
|
|
|
|
|
"Error occurred while fetching the list of devices that matches to status: '" + status + "'", e);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new DeviceManagementException("Error occurred while opening a connection to the data source", e);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (Device device : allDevices) {
|
|
|
|
|