Merge with upstream master

4.x.x
lasanthaDLPDS 5 years ago
commit 4e23dbf5af

@ -96,24 +96,24 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
@QueryParam("owner") String owner, @QueryParam("owner") String owner,
List<String> deviceIdentifiers){ List<String> deviceIdentifiers){
try { try {
if (DeviceMgtAPIUtils.getDeviceManagementService().updateEnrollment(owner, deviceIdentifiers)){ if (DeviceMgtAPIUtils.getDeviceManagementService().updateEnrollment(owner, deviceIdentifiers)) {
String msg = "Device owner is updated successfully."; String msg = "Device owner is updated successfully.";
return Response.status(Response.Status.OK).entity(msg).build(); return Response.status(Response.Status.OK).entity(msg).build();
} }
String msg = "Device owner updating is failed."; String msg = "Device owner updating is failed.";
log.error(msg); log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch(InvalidDeviceException e){ } catch (InvalidDeviceException e) {
String msg = "Invalid device identifiers are found with the request."; String msg = "Invalid device identifiers are found with the request.";
log.error(msg); log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
String msg = "Error occurred when updating device owners."; String msg = "Error occurred when updating device owners.";
log.error(msg); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (UserNotFoundException e) { } catch (UserNotFoundException e) {
String msg = "Couldn't found the owner in user store to update the owner of devices."; String msg = "Couldn't found the owner in user store to update the owner of devices.";
log.error(msg); log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} }
} }

@ -498,7 +498,8 @@ public interface DeviceDAO {
* @throws DeviceManagementDAOException throws {@link DeviceManagementDAOException} if connections establishment * @throws DeviceManagementDAOException throws {@link DeviceManagementDAOException} if connections establishment
* fails. * fails.
*/ */
List<Device> getDevicesByIdentifiers(List<String> deviceIdentifiers, int tenantId) throws DeviceManagementDAOException; List<Device> getDevicesByIdentifiers(List<String> deviceIdentifiers, int tenantId)
throws DeviceManagementDAOException;
/** /**
* This method is used to permanently delete the device and its related details * This method is used to permanently delete the device and its related details
@ -508,4 +509,3 @@ public interface DeviceDAO {
*/ */
void deleteDevice(DeviceIdentifier deviceIdentifier, int tenantId) throws DeviceManagementDAOException; void deleteDevice(DeviceIdentifier deviceIdentifier, int tenantId) throws DeviceManagementDAOException;
} }

@ -1507,8 +1507,8 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
} }
return devices; return devices;
} catch (SQLException e) { } catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while obtaining the DB connection when adding tags", throw new DeviceManagementDAOException("Error occurred while obtaining the DB connection to get devices for"
e); + " given device identifiers.", e);
} }
} }

@ -369,7 +369,11 @@ public class EnrollmentDAOImpl implements EnrollmentDAO {
try { try {
Connection conn = this.getConnection(); Connection conn = this.getConnection();
boolean updateStatus = true; boolean updateStatus = true;
String sql = "UPDATE DM_ENROLMENT SET OWNER = ? WHERE ID = ? AND TENANT_ID = ?"; String sql = "UPDATE "
+ "DM_ENROLMENT "
+ "SET OWNER = ? "
+ "WHERE ID = ? AND "
+ "TENANT_ID = ?";
try (PreparedStatement ps = conn.prepareStatement(sql)) { try (PreparedStatement ps = conn.prepareStatement(sql)) {
if (conn.getMetaData().supportsBatchUpdates()) { if (conn.getMetaData().supportsBatchUpdates()) {
for (Device device : devices) { for (Device device : devices) {
@ -381,6 +385,7 @@ public class EnrollmentDAOImpl implements EnrollmentDAO {
for (int i : ps.executeBatch()) { for (int i : ps.executeBatch()) {
if (i == 0 || i == Statement.SUCCESS_NO_INFO || i == Statement.EXECUTE_FAILED) { if (i == 0 || i == Statement.SUCCESS_NO_INFO || i == Statement.EXECUTE_FAILED) {
updateStatus = false; updateStatus = false;
break;
} }
} }
} else { } else {
@ -390,14 +395,15 @@ public class EnrollmentDAOImpl implements EnrollmentDAO {
ps.setInt(3, tenantId); ps.setInt(3, tenantId);
if (ps.executeUpdate() == 0) { if (ps.executeUpdate() == 0) {
updateStatus = false; updateStatus = false;
break;
} }
} }
} }
} }
return updateStatus; return updateStatus;
} catch (SQLException e) { } catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while obtaining the DB connection when adding tags", throw new DeviceManagementDAOException("Error occurred while obtaining the DB connection to update the "
e); + "owner of the device enrollment.", e);
} }
} }

@ -3090,12 +3090,12 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceManagementDAOFactory.rollbackTransaction(); DeviceManagementDAOFactory.rollbackTransaction();
return false; return false;
} catch (TransactionManagementException e) { } catch (TransactionManagementException e) {
String msg = "Error occurred while initiating transaction"; String msg = "Error occurred while initiating the transaction.";
log.error(msg, e); log.error(msg, e);
throw new DeviceManagementException(msg, e); throw new DeviceManagementException(msg, e);
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
String msg = "Error occurred either verifying existence of device ids or updating owner of the device."; String msg = "Error occurred either verifying existence of device ids or updating owner of the device.";
log.error(msg); log.error(msg, e);
throw new DeviceManagementException(msg, e); throw new DeviceManagementException(msg, e);
} finally { } finally {
DeviceManagementDAOFactory.closeConnection(); DeviceManagementDAOFactory.closeConnection();
@ -3118,7 +3118,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
return owner; return owner;
} catch (UserStoreException e) { } catch (UserStoreException e) {
String msg = "Error occurred when checking whether owner is exist or not. Owner: " + owner; String msg = "Error occurred when checking whether owner is exist or not. Owner: " + owner;
log.error(msg); log.error(msg, e);
throw new DeviceManagementException(msg, e); throw new DeviceManagementException(msg, e);
} }
} }

Loading…
Cancel
Save