Add equation explaining text to the comments and fix fomratting issues

Text will explain equation step by step by using.
Added missing comments, formatted code lines, formatted license
and added more comments.
feature/appm-store/pbac
Yohan Avishke 5 years ago
parent e8a260dbc4
commit 2fab3029ff

@ -1,5 +1,4 @@
/* /*
*
* Copyright (c) 2020, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. * Copyright (c) 2020, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
* *
* Entgra (pvt) Ltd. licenses this file to you under the Apache License, * Entgra (pvt) Ltd. licenses this file to you under the Apache License,
@ -42,5 +41,5 @@ public class BadRequestException extends Exception {
public BadRequestException(String message, Throwable cause) { public BadRequestException(String message, Throwable cause) {
super(message, cause); super(message, cause);
} }
} }

@ -57,6 +57,7 @@ public interface ReportManagementService {
* @param request {@link PaginationRequest} * @param request {@link PaginationRequest}
* @return {@link PaginationResult} * @return {@link PaginationResult}
* @throws ReportManagementException Might occur during the business logic or building database query * @throws ReportManagementException Might occur during the business logic or building database query
* @throws BadRequestException Might occur if the given os version or the device type doesn't match
*/ */
PaginationResult getDevicesExpiredByOSVersion(PaginationRequest request) PaginationResult getDevicesExpiredByOSVersion(PaginationRequest request)
throws ReportManagementException, BadRequestException; throws ReportManagementException, BadRequestException;

@ -867,6 +867,8 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
try { try {
Long osValue = (Long) request.getProperty(Constants.OS_VALUE); Long osValue = (Long) request.getProperty(Constants.OS_VALUE);
Connection conn = getConnection(); Connection conn = getConnection();
/* following variable is used to identify the datasource type.This is due to a
convert function performed in the query which will depend on the datasource */
String dataSourceType = conn.getMetaData().getDatabaseProductName(); String dataSourceType = conn.getMetaData().getDatabaseProductName();
String sql="SELECT " + String sql="SELECT " +
"d1.DEVICE_TYPE, " + "d1.DEVICE_TYPE, " +
@ -938,6 +940,8 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
throws DeviceManagementDAOException { throws DeviceManagementDAOException {
try { try {
Connection conn = getConnection(); Connection conn = getConnection();
/* following variable is used to identify the datasource type.This is due to a
convert function performed in the query which will depend on the datasource */
String dataSourceType = conn.getMetaData().getDatabaseProductName(); String dataSourceType = conn.getMetaData().getDatabaseProductName();
String sql = "SELECT " + String sql = "SELECT " +
"COUNT(ddi.DEVICE_ID) AS DEVICE_COUNT " + "COUNT(ddi.DEVICE_ID) AS DEVICE_COUNT " +
@ -964,11 +968,10 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
ps.setLong(4, osValue); ps.setLong(4, osValue);
try (ResultSet rs = ps.executeQuery()) { try (ResultSet rs = ps.executeQuery()) {
int deviceCount = 0;
if (rs.next()) { if (rs.next()) {
deviceCount = rs.getInt("DEVICE_COUNT"); return rs.getInt("DEVICE_COUNT");
} }
return deviceCount; return 0;
} }
} }
} catch (SQLException e) { } catch (SQLException e) {

@ -925,11 +925,10 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
ps.setLong(4, osValue); ps.setLong(4, osValue);
try (ResultSet rs = ps.executeQuery()) { try (ResultSet rs = ps.executeQuery()) {
int deviceCount = 0;
if (rs.next()) { if (rs.next()) {
deviceCount = rs.getInt("DEVICE_COUNT"); return rs.getInt("DEVICE_COUNT");
} }
return deviceCount; return 0;
} }
} }
} catch (SQLException e) { } catch (SQLException e) {

@ -909,11 +909,10 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
ps.setLong(4, osValue); ps.setLong(4, osValue);
try (ResultSet rs = ps.executeQuery()) { try (ResultSet rs = ps.executeQuery()) {
int deviceCount = 0;
if (rs.next()) { if (rs.next()) {
deviceCount = rs.getInt("DEVICE_COUNT"); return rs.getInt("DEVICE_COUNT");
} }
return deviceCount; return 0;
} }
} }
} catch (SQLException e) { } catch (SQLException e) {

@ -725,11 +725,10 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
ps.setLong(4, osValue); ps.setLong(4, osValue);
try (ResultSet rs = ps.executeQuery()) { try (ResultSet rs = ps.executeQuery()) {
int deviceCount = 0;
if (rs.next()) { if (rs.next()) {
deviceCount = rs.getInt("DEVICE_COUNT"); return rs.getInt("DEVICE_COUNT");
} }
return deviceCount; return 0;
} }
} }
} catch (SQLException e) { } catch (SQLException e) {

@ -1,5 +1,4 @@
/* /*
*
* Copyright (c) 2020, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. * Copyright (c) 2020, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
* *
* Entgra (pvt) Ltd. licenses this file to you under the Apache License, * Entgra (pvt) Ltd. licenses this file to you under the Apache License,
@ -15,10 +14,8 @@
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*
*/ */
package org.wso2.carbon.device.mgt.core.report.mgt; package org.wso2.carbon.device.mgt.core.report.mgt;
public class Constants { public class Constants {
@ -33,3 +30,4 @@ public class Constants {
public static final int NUM_OF_OS_VERSION_DIGITS= 5; public static final int NUM_OF_OS_VERSION_DIGITS= 5;
public static final int NUM_OF_OS_VERSION_POSITIONS = 3; public static final int NUM_OF_OS_VERSION_POSITIONS = 3;
} }

@ -731,7 +731,18 @@ public final class DeviceManagerUtil {
int osVersionsLength = osVersions.length; int osVersionsLength = osVersions.length;
/* /*
* <h1>Following loop will work for the value generation</h1> * <h1>Equation explanation</h1>
*
* <p>
Eg: {@code osVersion == "5.1.1"} will generate an array of {@code ["5","1","1"]}
Following loop for the above result can be broken down as below
* Iteration 1 : {@code Math.pow} result = 5 00000 00000, {@code sum} = 5 00000 00000
* Iteration 2 : {@code Math.pow} result = 1 00000, {@code sum} = 5 00001 00000
* Iteration 3 : {@code Math.pow} result = 1, {@code sum} = 5 00001 00001
To generate the above results I have multiplied the array values with powers of 10.
The constraints used to generate the power of 10 is explained below,
* </p>
*
* <p> * <p>
{@code Constants.NUM_OF_OS_VERSION_POSITIONS - (i + 1)} was done in-order to identify {@code Constants.NUM_OF_OS_VERSION_POSITIONS - (i + 1)} was done in-order to identify
which position of the OS version is been used for generation process, so correct number which position of the OS version is been used for generation process, so correct number
@ -762,7 +773,19 @@ public final class DeviceManagerUtil {
StringJoiner joiner = new StringJoiner("."); StringJoiner joiner = new StringJoiner(".");
/* /*
* <h1>Following loop will break the generated value into parts and will recreate the OS version</h1> * <h1>Equation explanation</h1>
*
* <p>
Eg: {@code osVersionValue == "5 00001 00001"}
Following loop will divide to break down the above number to regenerate the os version
* Iteration 1 : {@code osVersion} = 5 , {@code osVersionValue} = 00001 00001
* Iteration 2 : {@code osVersion} = 1 , {@code osVersionValue} = 00001
* Iteration 3 : {@code osVersion} = 1 , {@code osVersionValue} = 0
Final array = {@code ["5","1","1"]}
To generate the above results I have divided the generated value with powers of 10.
The constraints used to generate the power of 10 is explained below,
* </p>
*
* <p> * <p>
{@code 10, (i - 1) * Constants.NUM_OF_OS_VERSION_DIGITS} this will break the generated value {@code 10, (i - 1) * Constants.NUM_OF_OS_VERSION_DIGITS} this will break the generated value
creating each OS version position in following order main OS version, minor OS version, creating each OS version position in following order main OS version, minor OS version,

Loading…
Cancel
Save