@ -19,10 +19,12 @@
package org.wso2.carbon.device.mgt.analytics.dashboard.dao ;
import org.wso2.carbon.context.PrivilegedCarbonContext ;
import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DetailedDeviceEntry ;
import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DeviceCountByGroupEntry ;
import org.wso2.carbon.device.mgt.analytics.dashboard.bean.FilterSet ;
import org.wso2.carbon.device.mgt.analytics.dashboard.exception.InvalidParameterValueException ;
import org.wso2.carbon.device.mgt.analytics.dashboard.bean.BasicFilterSet ;
import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DeviceWithDetails ;
import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DeviceCountByGroup ;
import org.wso2.carbon.device.mgt.analytics.dashboard.bean.ExtendedFilterSet ;
import org.wso2.carbon.device.mgt.analytics.dashboard.exception.InvalidFeatureCodeValueException ;
import org.wso2.carbon.device.mgt.analytics.dashboard.exception.InvalidPotentialVulnerabilityValueException ;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil ;
import java.sql.Connection ;
@ -37,40 +39,40 @@ import java.util.Map;
public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceDAO {
@Override
public DeviceCountByGroup Entry getTotalDeviceCount ( ) throws SQLException {
public DeviceCountByGroup getTotalDeviceCount ( ) throws SQLException {
int totalDeviceCount ;
try {
totalDeviceCount = this . getFilteredDeviceCount ( null ) ;
} catch ( InvalidP arameter ValueException e ) {
} catch ( InvalidP otentialVulnerability ValueException e ) {
throw new AssertionError ( e ) ;
}
DeviceCountByGroup Entry deviceCountByGroup Entry = new DeviceCountByGroup Entry ( ) ;
deviceCountByGroup Entry . setGroup ( "total" ) ;
deviceCountByGroup Entry . setDisplayNameForGroup ( "Total" ) ;
deviceCountByGroup Entry . setDeviceCount ( totalDeviceCount ) ;
DeviceCountByGroup deviceCountByGroup = new DeviceCountByGroup ( ) ;
deviceCountByGroup . setGroup ( "total" ) ;
deviceCountByGroup . setDisplayNameForGroup ( "Total" ) ;
deviceCountByGroup . setDeviceCount ( totalDeviceCount ) ;
return deviceCountByGroup Entry ;
return deviceCountByGroup ;
}
@Override
public DeviceCountByGroup Entry getDeviceCount ( FilterSet f ilterSet)
throws InvalidP arameter ValueException, SQLException {
public DeviceCountByGroup getDeviceCount ( ExtendedFilterSet extendedF ilterSet)
throws InvalidP otentialVulnerability ValueException, SQLException {
int filteredDeviceCount = this . getFilteredDeviceCount ( f ilterSet) ;
int filteredDeviceCount = this . getFilteredDeviceCount ( extendedF ilterSet) ;
DeviceCountByGroup Entry deviceCountByGroup Entry = new DeviceCountByGroup Entry ( ) ;
deviceCountByGroup Entry . setGroup ( "filtered" ) ;
deviceCountByGroup Entry . setDisplayNameForGroup ( "Filtered" ) ;
deviceCountByGroup Entry . setDeviceCount ( filteredDeviceCount ) ;
DeviceCountByGroup deviceCountByGroup = new DeviceCountByGroup ( ) ;
deviceCountByGroup . setGroup ( "filtered" ) ;
deviceCountByGroup . setDisplayNameForGroup ( "Filtered" ) ;
deviceCountByGroup . setDeviceCount ( filteredDeviceCount ) ;
return deviceCountByGroup Entry ;
return deviceCountByGroup ;
}
private int getFilteredDeviceCount ( FilterSet f ilterSet)
throws InvalidP arameter ValueException, SQLException {
private int getFilteredDeviceCount ( ExtendedFilterSet extendedF ilterSet)
throws InvalidP otentialVulnerability ValueException, SQLException {
Map < String , Object > filters = this . extractDatabaseFiltersFromBean ( f ilterSet) ;
Map < String , Object > filters = this . extractDatabaseFiltersFromBean ( extendedF ilterSet) ;
Connection con ;
PreparedStatement stmt = null ;
@ -115,14 +117,14 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
}
@Override
public DeviceCountByGroup Entry getFeatureNonCompliantDeviceCount ( String nonCompliantF eatureCode,
FilterSet filterSet ) throws InvalidParameter ValueException, SQLException {
public DeviceCountByGroup getFeatureNonCompliantDeviceCount ( String f eatureCode,
BasicFilterSet basicFilterSet ) throws InvalidFeatureCode ValueException, SQLException {
if ( nonCompliantFeatureCode = = null | | nonCompliantF eatureCode. isEmpty ( ) ) {
throw new Invalid ParameterValueException( "Non-compliant f eature code should not be either null or empty.") ;
if ( featureCode = = null | | f eatureCode. isEmpty ( ) ) {
throw new Invalid FeatureCodeValueException( "F eature code should not be either null or empty.") ;
}
Map < String , Object > filters = this . extractDatabaseFiltersFromBean ( f ilterSet) ;
Map < String , Object > filters = this . extractDatabaseFiltersFromBean ( basicF ilterSet) ;
Connection con ;
PreparedStatement stmt = null ;
@ -143,7 +145,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
stmt = con . prepareStatement ( sql ) ;
// [2] appending filter column values, if exist
stmt . setInt ( 1 , tenantId ) ;
stmt . setString ( 2 , nonCompliantF eatureCode) ;
stmt . setString ( 2 , f eatureCode) ;
if ( filters ! = null & & filters . values ( ) . size ( ) > 0 ) {
int i = 3 ;
for ( Object value : filters . values ( ) ) {
@ -165,21 +167,21 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
DeviceManagementDAOUtil . cleanupResources ( stmt , rs ) ;
}
DeviceCountByGroup Entry deviceCountByGroup Entry = new DeviceCountByGroup Entry ( ) ;
deviceCountByGroup Entry . setGroup ( "feature-non-compliant-and-filtered" ) ;
deviceCountByGroup Entry . setDisplayNameForGroup ( "Feature-non-compliant-and-filtered" ) ;
deviceCountByGroup Entry . setDeviceCount ( filteredDeviceCount ) ;
DeviceCountByGroup deviceCountByGroup = new DeviceCountByGroup ( ) ;
deviceCountByGroup . setGroup ( "feature-non-compliant-and-filtered" ) ;
deviceCountByGroup . setDisplayNameForGroup ( "Feature-non-compliant-and-filtered" ) ;
deviceCountByGroup . setDeviceCount ( filteredDeviceCount ) ;
return deviceCountByGroup Entry ;
return deviceCountByGroup ;
}
@Override
public List < DeviceCountByGroup Entry > getDeviceCountsByConnectivityStatuses ( ) throws SQLException {
public List < DeviceCountByGroup > getDeviceCountsByConnectivityStatuses ( ) throws SQLException {
Connection con ;
PreparedStatement stmt = null ;
ResultSet rs = null ;
int tenantId = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( ) ;
List < DeviceCountByGroup Entry > deviceCountsByConnectivityStatuses = new ArrayList < > ( ) ;
List < DeviceCountByGroup > deviceCountsByConnectivityStatuses = new ArrayList < > ( ) ;
try {
con = this . getConnection ( ) ;
String sql = "SELECT CONNECTIVITY_STATUS, COUNT(DEVICE_ID) AS DEVICE_COUNT FROM " +
@ -191,9 +193,9 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
// executing query
rs = stmt . executeQuery ( ) ;
// fetching query results
DeviceCountByGroup Entry deviceCountByConnectivityStatus ;
DeviceCountByGroup deviceCountByConnectivityStatus ;
while ( rs . next ( ) ) {
deviceCountByConnectivityStatus = new DeviceCountByGroup Entry ( ) ;
deviceCountByConnectivityStatus = new DeviceCountByGroup ( ) ;
deviceCountByConnectivityStatus . setGroup ( rs . getString ( "CONNECTIVITY_STATUS" ) ) ;
deviceCountByConnectivityStatus . setDisplayNameForGroup ( rs . getString ( "CONNECTIVITY_STATUS" ) ) ;
deviceCountByConnectivityStatus . setDeviceCount ( rs . getInt ( "DEVICE_COUNT" ) ) ;
@ -206,20 +208,20 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
}
@Override
public List < DeviceCountByGroup Entry > getDeviceCountsByPotentialVulnerabilities ( ) throws SQLException {
public List < DeviceCountByGroup > getDeviceCountsByPotentialVulnerabilities ( ) throws SQLException {
// getting non-compliant device count
DeviceCountByGroup Entry nonCompliantDeviceCount = new DeviceCountByGroup Entry ( ) ;
DeviceCountByGroup nonCompliantDeviceCount = new DeviceCountByGroup ( ) ;
nonCompliantDeviceCount . setGroup ( GadgetDataServiceDAOConstants . PotentialVulnerability . NON_COMPLIANT ) ;
nonCompliantDeviceCount . setDisplayNameForGroup ( "Non-compliant" ) ;
nonCompliantDeviceCount . setDeviceCount ( getNonCompliantDeviceCount ( ) ) ;
// getting unmonitored device count
DeviceCountByGroup Entry unmonitoredDeviceCount = new DeviceCountByGroup Entry ( ) ;
DeviceCountByGroup unmonitoredDeviceCount = new DeviceCountByGroup ( ) ;
unmonitoredDeviceCount . setGroup ( GadgetDataServiceDAOConstants . PotentialVulnerability . UNMONITORED ) ;
unmonitoredDeviceCount . setDisplayNameForGroup ( "Unmonitored" ) ;
unmonitoredDeviceCount . setDeviceCount ( getUnmonitoredDeviceCount ( ) ) ;
List < DeviceCountByGroup Entry > deviceCountsByPotentialVulnerabilities = new ArrayList < > ( ) ;
List < DeviceCountByGroup > deviceCountsByPotentialVulnerabilities = new ArrayList < > ( ) ;
deviceCountsByPotentialVulnerabilities . add ( nonCompliantDeviceCount ) ;
deviceCountsByPotentialVulnerabilities . add ( unmonitoredDeviceCount ) ;
@ -227,36 +229,38 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
}
private int getNonCompliantDeviceCount ( ) throws SQLException {
FilterSet filterSet = new FilterSet ( ) ;
filterSet . setPotentialVulnerability ( GadgetDataServiceDAOConstants . PotentialVulnerability . NON_COMPLIANT ) ;
ExtendedFilterSet extendedFilterSet = new ExtendedFilterSet ( ) ;
extendedFilterSet . setPotentialVulnerability ( GadgetDataServiceDAOConstants .
PotentialVulnerability . NON_COMPLIANT ) ;
try {
return this . getFilteredDeviceCount ( f ilterSet) ;
} catch ( InvalidP arameter ValueException e ) {
return this . getFilteredDeviceCount ( extendedF ilterSet) ;
} catch ( InvalidP otentialVulnerability ValueException e ) {
throw new AssertionError ( e ) ;
}
}
private int getUnmonitoredDeviceCount ( ) throws SQLException {
FilterSet filterSet = new FilterSet ( ) ;
filterSet . setPotentialVulnerability ( GadgetDataServiceDAOConstants . PotentialVulnerability . UNMONITORED ) ;
ExtendedFilterSet extendedFilterSet = new ExtendedFilterSet ( ) ;
extendedFilterSet . setPotentialVulnerability ( GadgetDataServiceDAOConstants .
PotentialVulnerability . UNMONITORED ) ;
try {
return this . getFilteredDeviceCount ( f ilterSet) ;
} catch ( InvalidP arameter ValueException e ) {
return this . getFilteredDeviceCount ( extendedF ilterSet) ;
} catch ( InvalidP otentialVulnerability ValueException e ) {
throw new AssertionError ( e ) ;
}
}
@Override
public List < DeviceCountByGroup Entry > getDeviceCountsByPlatforms ( FilterSet f ilterSet)
throws InvalidParameter ValueException, SQLException {
public List < DeviceCountByGroup > getDeviceCountsByPlatforms ( ExtendedFilterSet extendedF ilterSet)
throws InvalidPotentialVulnerability ValueException, SQLException {
Map < String , Object > filters = this . extractDatabaseFiltersFromBean ( f ilterSet) ;
Map < String , Object > filters = this . extractDatabaseFiltersFromBean ( extendedF ilterSet) ;
Connection con ;
PreparedStatement stmt = null ;
ResultSet rs = null ;
int tenantId = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( ) ;
List < DeviceCountByGroup Entry > filteredDeviceCountsByPlatforms = new ArrayList < > ( ) ;
List < DeviceCountByGroup > filteredDeviceCountsByPlatforms = new ArrayList < > ( ) ;
try {
con = this . getConnection ( ) ;
String sql , advancedSqlFiltering = "" ;
@ -286,9 +290,9 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
// executing query
rs = stmt . executeQuery ( ) ;
// fetching query results
DeviceCountByGroup Entry filteredDeviceCountByPlatform ;
DeviceCountByGroup filteredDeviceCountByPlatform ;
while ( rs . next ( ) ) {
filteredDeviceCountByPlatform = new DeviceCountByGroup Entry ( ) ;
filteredDeviceCountByPlatform = new DeviceCountByGroup ( ) ;
filteredDeviceCountByPlatform . setGroup ( rs . getString ( "PLATFORM" ) ) ;
filteredDeviceCountByPlatform . setDisplayNameForGroup ( rs . getString ( "PLATFORM" ) . toUpperCase ( ) ) ;
filteredDeviceCountByPlatform . setDeviceCount ( rs . getInt ( "DEVICE_COUNT" ) ) ;
@ -301,21 +305,21 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
}
@Override
public List < DeviceCountByGroup Entry >
getFeatureNonCompliantDeviceCountsByPlatforms ( String nonCompliantF eatureCode,
FilterSet filterSet ) throws InvalidParameter ValueException, SQLException {
public List < DeviceCountByGroup >
getFeatureNonCompliantDeviceCountsByPlatforms ( String f eatureCode,
BasicFilterSet basicFilterSet ) throws InvalidFeatureCode ValueException, SQLException {
if ( nonCompliantFeatureCode = = null | | nonCompliantF eatureCode. isEmpty ( ) ) {
throw new Invalid ParameterValueException( "Non-compliant f eature code should not be either null or empty.") ;
if ( featureCode = = null | | f eatureCode. isEmpty ( ) ) {
throw new Invalid FeatureCodeValueException( "F eature code should not be either null or empty.") ;
}
Map < String , Object > filters = this . extractDatabaseFiltersFromBean ( f ilterSet) ;
Map < String , Object > filters = this . extractDatabaseFiltersFromBean ( basicF ilterSet) ;
Connection con ;
PreparedStatement stmt = null ;
ResultSet rs = null ;
int tenantId = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( ) ;
List < DeviceCountByGroup Entry > filteredDeviceCountsByPlatforms = new ArrayList < > ( ) ;
List < DeviceCountByGroup > filteredDeviceCountsByPlatforms = new ArrayList < > ( ) ;
try {
con = this . getConnection ( ) ;
String sql , advancedSqlFiltering = "" ;
@ -332,7 +336,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
stmt = con . prepareStatement ( sql ) ;
// [2] appending filter column values, if exist
stmt . setInt ( 1 , tenantId ) ;
stmt . setString ( 2 , nonCompliantF eatureCode) ;
stmt . setString ( 2 , f eatureCode) ;
if ( filters ! = null & & filters . values ( ) . size ( ) > 0 ) {
int i = 3 ;
for ( Object value : filters . values ( ) ) {
@ -347,9 +351,9 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
// executing query
rs = stmt . executeQuery ( ) ;
// fetching query results
DeviceCountByGroup Entry filteredDeviceCountByPlatform ;
DeviceCountByGroup filteredDeviceCountByPlatform ;
while ( rs . next ( ) ) {
filteredDeviceCountByPlatform = new DeviceCountByGroup Entry ( ) ;
filteredDeviceCountByPlatform = new DeviceCountByGroup ( ) ;
filteredDeviceCountByPlatform . setGroup ( rs . getString ( "PLATFORM" ) ) ;
filteredDeviceCountByPlatform . setDisplayNameForGroup ( rs . getString ( "PLATFORM" ) . toUpperCase ( ) ) ;
filteredDeviceCountByPlatform . setDeviceCount ( rs . getInt ( "DEVICE_COUNT" ) ) ;
@ -362,16 +366,16 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
}
@Override
public List < DeviceCountByGroup Entry > getDeviceCountsByOwnershipTypes ( FilterSet f ilterSet)
throws InvalidParameter ValueException, SQLException {
public List < DeviceCountByGroup > getDeviceCountsByOwnershipTypes ( ExtendedFilterSet extendedF ilterSet)
throws InvalidPotentialVulnerability ValueException, SQLException {
Map < String , Object > filters = this . extractDatabaseFiltersFromBean ( f ilterSet) ;
Map < String , Object > filters = this . extractDatabaseFiltersFromBean ( extendedF ilterSet) ;
Connection con ;
PreparedStatement stmt = null ;
ResultSet rs = null ;
int tenantId = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( ) ;
List < DeviceCountByGroup Entry > filteredDeviceCountsByOwnershipTypes = new ArrayList < > ( ) ;
List < DeviceCountByGroup > filteredDeviceCountsByOwnershipTypes = new ArrayList < > ( ) ;
try {
con = this . getConnection ( ) ;
String sql , advancedSqlFiltering = "" ;
@ -402,9 +406,9 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
// executing query
rs = stmt . executeQuery ( ) ;
// fetching query results
DeviceCountByGroup Entry filteredDeviceCountByOwnershipType ;
DeviceCountByGroup filteredDeviceCountByOwnershipType ;
while ( rs . next ( ) ) {
filteredDeviceCountByOwnershipType = new DeviceCountByGroup Entry ( ) ;
filteredDeviceCountByOwnershipType = new DeviceCountByGroup ( ) ;
filteredDeviceCountByOwnershipType . setGroup ( rs . getString ( "OWNERSHIP" ) ) ;
filteredDeviceCountByOwnershipType . setDisplayNameForGroup ( rs . getString ( "OWNERSHIP" ) ) ;
filteredDeviceCountByOwnershipType . setDeviceCount ( rs . getInt ( "DEVICE_COUNT" ) ) ;
@ -417,21 +421,21 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
}
@Override
public List < DeviceCountByGroup Entry >
getFeatureNonCompliantDeviceCountsByOwnershipTypes ( String nonCompliantF eatureCode,
FilterSet filterSet ) throws InvalidParameter ValueException, SQLException {
public List < DeviceCountByGroup >
getFeatureNonCompliantDeviceCountsByOwnershipTypes ( String f eatureCode,
BasicFilterSet basicFilterSet ) throws InvalidFeatureCode ValueException, SQLException {
if ( nonCompliantFeatureCode = = null | | nonCompliantF eatureCode. isEmpty ( ) ) {
throw new Invalid ParameterValueException( "Non-compliant f eature code should not be either null or empty.") ;
if ( featureCode = = null | | f eatureCode. isEmpty ( ) ) {
throw new Invalid FeatureCodeValueException( "F eature code should not be either null or empty.") ;
}
Map < String , Object > filters = this . extractDatabaseFiltersFromBean ( f ilterSet) ;
Map < String , Object > filters = this . extractDatabaseFiltersFromBean ( basicF ilterSet) ;
Connection con ;
PreparedStatement stmt = null ;
ResultSet rs = null ;
int tenantId = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( ) ;
List < DeviceCountByGroup Entry > filteredDeviceCountsByOwnershipTypes = new ArrayList < > ( ) ;
List < DeviceCountByGroup > filteredDeviceCountsByOwnershipTypes = new ArrayList < > ( ) ;
try {
con = this . getConnection ( ) ;
String sql , advancedSqlFiltering = "" ;
@ -448,7 +452,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
stmt = con . prepareStatement ( sql ) ;
// [2] appending filter column values, if exist
stmt . setInt ( 1 , tenantId ) ;
stmt . setString ( 2 , nonCompliantF eatureCode) ;
stmt . setString ( 2 , f eatureCode) ;
if ( filters ! = null & & filters . values ( ) . size ( ) > 0 ) {
int i = 3 ;
for ( Object value : filters . values ( ) ) {
@ -463,9 +467,9 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
// executing query
rs = stmt . executeQuery ( ) ;
// fetching query results
DeviceCountByGroup Entry filteredDeviceCountByOwnershipType ;
DeviceCountByGroup filteredDeviceCountByOwnershipType ;
while ( rs . next ( ) ) {
filteredDeviceCountByOwnershipType = new DeviceCountByGroup Entry ( ) ;
filteredDeviceCountByOwnershipType = new DeviceCountByGroup ( ) ;
filteredDeviceCountByOwnershipType . setGroup ( rs . getString ( "OWNERSHIP" ) ) ;
filteredDeviceCountByOwnershipType . setDisplayNameForGroup ( rs . getString ( "OWNERSHIP" ) ) ;
filteredDeviceCountByOwnershipType . setDeviceCount ( rs . getInt ( "DEVICE_COUNT" ) ) ;
@ -478,16 +482,16 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
}
@Override
public List < De tailedDeviceEntry> getDevicesWithDetails ( FilterSet f ilterSet)
throws InvalidParameter ValueException, SQLException {
public List < De viceWithDetails> getDevicesWithDetails ( ExtendedFilterSet extendedF ilterSet)
throws InvalidPotentialVulnerability ValueException, SQLException {
Map < String , Object > filters = this . extractDatabaseFiltersFromBean ( f ilterSet) ;
Map < String , Object > filters = this . extractDatabaseFiltersFromBean ( extendedF ilterSet) ;
Connection con ;
PreparedStatement stmt = null ;
ResultSet rs = null ;
int tenantId = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( ) ;
List < De tailedDeviceEntry > filteredDevicesWithDetails = new ArrayList < > ( ) ;
List < De viceWithDetails > filteredDevicesWithDetails = new ArrayList < > ( ) ;
try {
con = this . getConnection ( ) ;
String sql ;
@ -517,9 +521,9 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
// executing query
rs = stmt . executeQuery ( ) ;
// fetching query results
De tailedDeviceEntry filteredDeviceWithDetails ;
De viceWithDetails filteredDeviceWithDetails ;
while ( rs . next ( ) ) {
filteredDeviceWithDetails = new De tailedDeviceEntry ( ) ;
filteredDeviceWithDetails = new De viceWithDetails ( ) ;
filteredDeviceWithDetails . setDeviceId ( rs . getInt ( "DEVICE_ID" ) ) ;
filteredDeviceWithDetails . setDeviceIdentification ( rs . getString ( "DEVICE_IDENTIFICATION" ) ) ;
filteredDeviceWithDetails . setPlatform ( rs . getString ( "PLATFORM" ) ) ;
@ -534,20 +538,20 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
}
@Override
public List < De tailedDeviceEntry> getFeatureNonCompliantDevicesWithDetails ( String nonCompliantF eatureCode,
FilterSet filterSet ) throws InvalidParameter ValueException, SQLException {
public List < De viceWithDetails> getFeatureNonCompliantDevicesWithDetails ( String f eatureCode,
BasicFilterSet basicFilterSet ) throws InvalidFeatureCode ValueException, SQLException {
if ( nonCompliantFeatureCode = = null | | nonCompliantF eatureCode. isEmpty ( ) ) {
throw new Invalid ParameterValueException( "Non-compliant f eature code should not be either null or empty.") ;
if ( featureCode = = null | | f eatureCode. isEmpty ( ) ) {
throw new Invalid FeatureCodeValueException( "F eature code should not be either null or empty.") ;
}
Map < String , Object > filters = this . extractDatabaseFiltersFromBean ( f ilterSet) ;
Map < String , Object > filters = this . extractDatabaseFiltersFromBean ( basicF ilterSet) ;
Connection con ;
PreparedStatement stmt = null ;
ResultSet rs = null ;
int tenantId = PrivilegedCarbonContext . getThreadLocalCarbonContext ( ) . getTenantId ( ) ;
List < De tailedDeviceEntry > filteredDevicesWithDetails = new ArrayList < > ( ) ;
List < De viceWithDetails > filteredDevicesWithDetails = new ArrayList < > ( ) ;
try {
con = this . getConnection ( ) ;
String sql ;
@ -564,7 +568,7 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
stmt = con . prepareStatement ( sql ) ;
// [2] appending filter column values, if exist
stmt . setInt ( 1 , tenantId ) ;
stmt . setString ( 2 , nonCompliantF eatureCode) ;
stmt . setString ( 2 , f eatureCode) ;
if ( filters ! = null & & filters . values ( ) . size ( ) > 0 ) {
int i = 3 ;
for ( Object value : filters . values ( ) ) {
@ -579,9 +583,9 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
// executing query
rs = stmt . executeQuery ( ) ;
// fetching query results
De tailedDeviceEntry filteredDeviceWithDetails ;
De viceWithDetails filteredDeviceWithDetails ;
while ( rs . next ( ) ) {
filteredDeviceWithDetails = new De tailedDeviceEntry ( ) ;
filteredDeviceWithDetails = new De viceWithDetails ( ) ;
filteredDeviceWithDetails . setDeviceId ( rs . getInt ( "DEVICE_ID" ) ) ;
filteredDeviceWithDetails . setDeviceIdentification ( rs . getString ( "DEVICE_IDENTIFICATION" ) ) ;
filteredDeviceWithDetails . setPlatform ( rs . getString ( "PLATFORM" ) ) ;
@ -595,46 +599,56 @@ public abstract class AbstractGadgetDataServiceDAO implements GadgetDataServiceD
return filteredDevicesWithDetails ;
}
protected Map < String , Object > extractDatabaseFiltersFromBean ( FilterSet filterSet )
throws InvalidParameterValueException {
if ( filterSet = = null ) {
protected Map < String , Object > extractDatabaseFiltersFromBean ( BasicFilterSet basicFilterSet ) {
if ( basicFilterSet = = null ) {
return null ;
}
Map < String , Object > filters = new LinkedHashMap < > ( ) ;
String connectivityStatus = f ilterSet. getConnectivityStatus ( ) ;
if ( connectivityStatus ! = null ) {
String connectivityStatus = basicF ilterSet. getConnectivityStatus ( ) ;
if ( connectivityStatus ! = null & & ! connectivityStatus . isEmpty ( ) ) {
filters . put ( "CONNECTIVITY_STATUS" , connectivityStatus ) ;
}
String potentialVulnerability = filterSet . getPotentialVulnerability ( ) ;
if ( potentialVulnerability ! = null ) {
String platform = basicFilterSet . getPlatform ( ) ;
if ( platform ! = null & & ! platform . isEmpty ( ) ) {
filters . put ( "PLATFORM" , platform ) ;
}
String ownership = basicFilterSet . getOwnership ( ) ;
if ( ownership ! = null & & ! ownership . isEmpty ( ) ) {
filters . put ( "OWNERSHIP" , ownership ) ;
}
return filters ;
}
protected Map < String , Object > extractDatabaseFiltersFromBean ( ExtendedFilterSet extendedFilterSet )
throws InvalidPotentialVulnerabilityValueException {
if ( extendedFilterSet = = null ) {
return null ;
}
Map < String , Object > filters = this . extractDatabaseFiltersFromBean ( ( BasicFilterSet ) extendedFilterSet ) ;
String potentialVulnerability = extendedFilterSet . getPotentialVulnerability ( ) ;
if ( potentialVulnerability ! = null & & ! potentialVulnerability . isEmpty ( ) ) {
if ( GadgetDataServiceDAOConstants . PotentialVulnerability . NON_COMPLIANT . equals ( potentialVulnerability ) | |
GadgetDataServiceDAOConstants . PotentialVulnerability . UNMONITORED . equals ( potentialVulnerability ) ) {
GadgetDataServiceDAOConstants . PotentialVulnerability . UNMONITORED . equals ( potentialVulnerability ) ) {
if ( GadgetDataServiceDAOConstants . PotentialVulnerability . NON_COMPLIANT . equals ( potentialVulnerability ) ) {
filters . put ( "IS_COMPLIANT" , 0 ) ;
} else {
filters . put ( "POLICY_ID" , - 1 ) ;
}
} else {
throw new InvalidParameterValueException ( "Invalid use of value for potential vulnerability. " +
"Value of potential vulnerability could only be either " +
throw new InvalidP otentialVulnerability ValueException( "Invalid use of value for potential " +
" vulnerability. Value of potential vulnerability could only be either " +
GadgetDataServiceDAOConstants . PotentialVulnerability . NON_COMPLIANT + " or " +
GadgetDataServiceDAOConstants . PotentialVulnerability . UNMONITORED + "." ) ;
}
}
String platform = filterSet . getPlatform ( ) ;
if ( platform ! = null ) {
filters . put ( "PLATFORM" , platform ) ;
}
String ownership = filterSet . getOwnership ( ) ;
if ( ownership ! = null ) {
filters . put ( "OWNERSHIP" , ownership ) ;
}
return filters ;
}