Merge branch 'application-mgt-new' of https://gitlab.com/nipunnadeen/carbon-device-mgt into appm-new

feature/appm-store/pbac
nipun 5 years ago
commit 4ac94746fa

@ -81,7 +81,6 @@ public class ReportManagementServiceImpl implements ReportManagementService {
String msg = "No devices have enrolled between " + fromDate + " to " + toDate +
" or doesn't match with" +
" given parameters";
log.error(msg);
return Response.status(Response.Status.OK).entity(msg).build();
} else {
devices.setList((List<Device>) result.getData());

@ -423,8 +423,10 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
devices.add(device);
}
} catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to status " +
"'" + request.getStatus() + "'", e);
String msg = "Error occurred while fetching the list of devices that matches to status " +
"'" + request.getStatus() + "'";
log.error(msg, e);
throw new DeviceManagementDAOException(msg, e);
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, null);
}
@ -552,8 +554,10 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
devices.add(device);
}
} catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices corresponding" +
"to the mentioned filtering criteria", e);
String msg = "Error occurred while fetching the list of devices corresponding" +
"to the mentioned filtering criteria";
log.error(msg, e);
throw new DeviceManagementDAOException(msg, e);
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}

@ -429,8 +429,10 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
devices.add(device);
}
} catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to status " +
"'" + request.getStatus() + "'", e);
String msg = "Error occurred while fetching the list of devices that matches to status " +
"'" + request.getStatus() + "'";
log.error(msg, e);
throw new DeviceManagementDAOException(msg, e);
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, null);
}
@ -557,11 +559,10 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
devices.add(device);
}
} catch (SQLException e) {
String msg = "Error occurred while retrieving information of all " +
"registered devices";
String msg = "Error occurred while fetching the list of devices corresponding" +
"to the mentioned filtering criteria";
log.error(msg, e);
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices corresponding" +
"to the mentioned filtering criteria", e);
throw new DeviceManagementDAOException(msg, e);
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}

@ -406,8 +406,10 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
devices.add(device);
}
} catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to status " +
"'" + request.getStatus() + "'", e);
String msg = "Error occurred while fetching the list of devices that matches to status " +
"'" + request.getStatus() + "'";
log.error(msg, e);
throw new DeviceManagementDAOException(msg, e);
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, null);
}
@ -535,13 +537,76 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
devices.add(device);
}
} catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices corresponding" +
"to the mentioned filtering criteria", e);
String msg = "Error occurred while fetching the list of devices corresponding" +
"to the mentioned filtering criteria";
log.error(msg, e);
throw new DeviceManagementDAOException(msg, e);
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
return devices;
}
@Override
public List<Device> getSubscribedDevices(int offsetValue, int limitValue,
List<Integer> deviceIds, int tenantId, String status)
throws DeviceManagementDAOException {
Connection conn;
try {
conn = this.getConnection();
int index = 1;
boolean isStatusProvided = false;
StringJoiner joiner = new StringJoiner(",",
"SELECT " +
"f.ID AS DEVICE_ID, f.NAME AS DEVICE_NAME, f.DESCRIPTION AS DESCRIPTION, " +
"f.DEVICE_TYPE_ID, f.DEVICE_IDENTIFICATION AS DEVICE_IDENTIFICATION, " +
"e.ID AS ENROLMENT_ID, e.OWNER, e.OWNERSHIP, e.DATE_OF_ENROLMENT, " +
"e.DATE_OF_LAST_UPDATE, e.STATUS, t.NAME AS DEVICE_TYPE " +
"FROM DM_ENROLMENT AS e,DM_DEVICE AS f, DM_DEVICE_TYPE t "+
"WHERE " +
"e.DEVICE_ID=f.ID AND " +
"e.DEVICE_ID IN (", ") AND e.TENANT_ID=?");
deviceIds.stream().map(ignored -> "?").forEach(joiner::add);
String query = joiner.toString();
if (status != null && !status.isEmpty()) {
query = query + " AND e.STATUS=?";
isStatusProvided = true;
}
query = query + " LIMIT ? OFFSET ?";
try (PreparedStatement ps = conn.prepareStatement(query)) {
for (Integer deviceId : deviceIds) {
ps.setObject(index++, deviceId);
}
ps.setInt(index++, tenantId);
if (isStatusProvided) {
ps.setString(index++, status);
}
ps.setInt(index++, offsetValue);
ps.setInt(index, limitValue);
try (ResultSet rs = ps.executeQuery()) {
List<Device> devices = new ArrayList<>();
while (rs.next()) {
devices.add(DeviceManagementDAOUtil.loadDevice(rs));
}
return devices;
}
}
} catch (SQLException e) {
String msg = "Error occurred while retrieving information of all registered devices " +
"according to device ids and the limit area.";
log.error(msg, e);
throw new DeviceManagementDAOException(msg, e);
}
}
@Override
public List<Device> getSubscribedDevices(int offsetValue, int limitValue,

@ -425,8 +425,10 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
devices.add(device);
}
} catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to status " +
"'" + request.getStatus() + "'", e);
String msg = "Error occurred while fetching the list of devices that matches to status " +
"'" + request.getStatus() + "'";
log.error(msg, e);
throw new DeviceManagementDAOException(msg, e);
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, null);
}
@ -490,8 +492,10 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
devices.add(device);
}
} catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices corresponding" +
"to the mentioned filtering criteria", e);
String msg = "Error occurred while fetching the list of devices corresponding" +
"to the mentioned filtering criteria";
log.error(msg, e);
throw new DeviceManagementDAOException(msg, e);
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}

Loading…
Cancel
Save