mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Fixing the application memory usage and adding location based search
This commit is contained in:
parent
20a1f81a57
commit
aa63b5f592
@ -36,6 +36,8 @@ public class Application implements Serializable {
|
||||
private Properties appProperties;
|
||||
private String applicationIdentifier;
|
||||
|
||||
private int memoryUsage;
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
@ -111,6 +113,14 @@ public class Application implements Serializable {
|
||||
this.applicationIdentifier = applicationIdentifier;
|
||||
}
|
||||
|
||||
public int getMemoryUsage() {
|
||||
return memoryUsage;
|
||||
}
|
||||
|
||||
public void setMemoryUsage(int memoryUsage) {
|
||||
this.memoryUsage = memoryUsage;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
|
||||
@ -47,8 +47,8 @@ public class ApplicationDAOImpl implements ApplicationDAO {
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
stmt = conn.prepareStatement("INSERT INTO DM_APPLICATION (NAME, PLATFORM, CATEGORY, " +
|
||||
"VERSION, TYPE, LOCATION_URL, IMAGE_URL, TENANT_ID,APP_PROPERTIES,APP_IDENTIFIER) " +
|
||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?,?)");
|
||||
"VERSION, TYPE, LOCATION_URL, IMAGE_URL, TENANT_ID, APP_PROPERTIES, APP_IDENTIFIER, MEMORY_USAGE) " +
|
||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
|
||||
stmt.setString(1, application.getName());
|
||||
stmt.setString(2, application.getPlatform());
|
||||
@ -65,6 +65,7 @@ public class ApplicationDAOImpl implements ApplicationDAO {
|
||||
stmt.setBytes(9, bao.toByteArray());
|
||||
|
||||
stmt.setString(10, application.getApplicationIdentifier());
|
||||
stmt.setInt(11, application.getMemoryUsage());
|
||||
stmt.execute();
|
||||
|
||||
rs = stmt.getGeneratedKeys();
|
||||
@ -108,8 +109,8 @@ public class ApplicationDAOImpl implements ApplicationDAO {
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
stmt = conn.prepareStatement("INSERT INTO DM_APPLICATION (NAME, PLATFORM, CATEGORY, " +
|
||||
"VERSION, TYPE, LOCATION_URL, IMAGE_URL, TENANT_ID,APP_PROPERTIES,APP_IDENTIFIER) " +
|
||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?,?)", new String[] {"id"});
|
||||
"VERSION, TYPE, LOCATION_URL, IMAGE_URL, TENANT_ID,APP_PROPERTIES, APP_IDENTIFIER, MEMORY_USAGE) " +
|
||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", new String[]{"id"});
|
||||
|
||||
|
||||
for (Application application : applications) {
|
||||
@ -129,6 +130,7 @@ public class ApplicationDAOImpl implements ApplicationDAO {
|
||||
stmt.setBytes(9, bao.toByteArray());
|
||||
|
||||
stmt.setString(10, application.getApplicationIdentifier());
|
||||
stmt.setInt(11, application.getMemoryUsage());
|
||||
stmt.executeUpdate();
|
||||
|
||||
rs = stmt.getGeneratedKeys();
|
||||
@ -170,7 +172,7 @@ public class ApplicationDAOImpl implements ApplicationDAO {
|
||||
conn = this.getConnection();
|
||||
conn.setAutoCommit(false);
|
||||
stmt = conn.prepareStatement("DELETE DM_APPLICATION WHERE APP_IDENTIFIER = ? AND TENANT_ID = ?",
|
||||
new String[] {"id"});
|
||||
new String[]{"id"});
|
||||
|
||||
for (Application app : apps) {
|
||||
stmt.setString(1, app.getApplicationIdentifier());
|
||||
@ -206,7 +208,7 @@ public class ApplicationDAOImpl implements ApplicationDAO {
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
stmt = conn.prepareStatement("SELECT ID, NAME, APP_IDENTIFIER, PLATFORM, CATEGORY, VERSION, TYPE, " +
|
||||
"LOCATION_URL, IMAGE_URL, APP_PROPERTIES, TENANT_ID FROM DM_APPLICATION WHERE APP_IDENTIFIER = ? " +
|
||||
"LOCATION_URL, IMAGE_URL, APP_PROPERTIES, MEMORY_USAGE, TENANT_ID FROM DM_APPLICATION WHERE APP_IDENTIFIER = ? " +
|
||||
"AND TENANT_ID = ?");
|
||||
stmt.setString(1, identifier);
|
||||
stmt.setInt(2, tenantId);
|
||||
@ -238,7 +240,7 @@ public class ApplicationDAOImpl implements ApplicationDAO {
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
stmt = conn.prepareStatement("Select ID, NAME, APP_IDENTIFIER, PLATFORM, CATEGORY, VERSION, TYPE, " +
|
||||
"LOCATION_URL, IMAGE_URL, APP_PROPERTIES, TENANT_ID From DM_APPLICATION app " +
|
||||
"LOCATION_URL, IMAGE_URL, APP_PROPERTIES, MEMORY_USAGE, TENANT_ID From DM_APPLICATION app " +
|
||||
"INNER JOIN " +
|
||||
"(Select APPLICATION_ID From DM_DEVICE_APPLICATION_MAPPING WHERE DEVICE_ID=?) APPMAP " +
|
||||
"ON " +
|
||||
@ -284,6 +286,7 @@ public class ApplicationDAOImpl implements ApplicationDAO {
|
||||
application.setLocationUrl(rs.getString("LOCATION_URL"));
|
||||
application.setPlatform(rs.getString("PLATFORM"));
|
||||
application.setVersion(rs.getString("VERSION"));
|
||||
application.setMemoryUsage(rs.getInt("MEMORY_USAGE"));
|
||||
application.setApplicationIdentifier(rs.getString("APP_IDENTIFIER"));
|
||||
|
||||
} catch (IOException e) {
|
||||
|
||||
@ -86,7 +86,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
|
||||
@Override
|
||||
public void addDeviceProperties(Map<String, String> propertyMap, int deviceId) throws DeviceDetailsMgtDAOException {
|
||||
|
||||
if(propertyMap.isEmpty()){
|
||||
if (propertyMap.isEmpty()) {
|
||||
log.warn("Property map of device id :" + deviceId + " is empty.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -136,14 +136,5 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
|
||||
}
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void addDeviceApplications(DeviceApplication deviceApplication) throws DeviceDetailsMgtException {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public DeviceApplication getDeviceApplication(DeviceIdentifier deviceIdentifier) throws DeviceDetailsMgtException {
|
||||
// return null;
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
@ -24,4 +24,5 @@ public class Constants {
|
||||
public static String GENERAL = "GENERAL";
|
||||
public static String PROP_AND = "PROP_AND";
|
||||
public static String PROP_OR = "PROP_OR";
|
||||
public static String LOCATION = "LOCATION";
|
||||
}
|
||||
|
||||
@ -32,6 +32,8 @@ public interface QueryBuilder {
|
||||
|
||||
String processOR(List<Condition> conditions) throws InvalidOperatorException;
|
||||
|
||||
List<String> processLocation(Condition condition) throws InvalidOperatorException;
|
||||
|
||||
List<String> processANDProperties(List<Condition> conditions) throws InvalidOperatorException;
|
||||
|
||||
List<String> processORProperties(List<Condition> conditions) throws InvalidOperatorException;
|
||||
|
||||
@ -47,6 +47,7 @@ public class ProcessorImpl implements Processor {
|
||||
List<DeviceWrapper> generalDevices = new ArrayList<>();
|
||||
List<List<DeviceWrapper>> allANDDevices = new ArrayList<>();
|
||||
List<List<DeviceWrapper>> allORDevices = new ArrayList<>();
|
||||
List<DeviceWrapper> locationDevices = new ArrayList<>();
|
||||
try {
|
||||
Map<String, List<String>> queries = queryBuilder.buildQueries(searchContext.getConditions());
|
||||
DeviceManagementDAOFactory.openConnection();
|
||||
@ -66,6 +67,10 @@ public class ProcessorImpl implements Processor {
|
||||
allORDevices.add(orDevices);
|
||||
}
|
||||
}
|
||||
if (queries.containsKey(Constants.LOCATION)) {
|
||||
locationDevices = searchDAO.searchDevicePropertyTable(
|
||||
queries.get(Constants.LOCATION).get(0));
|
||||
}
|
||||
} catch (InvalidOperatorException e) {
|
||||
throw new SearchMgtException("Invalid operator was provided, so cannot execute the search.", e);
|
||||
} catch (SQLException e) {
|
||||
@ -84,6 +89,7 @@ public class ProcessorImpl implements Processor {
|
||||
deviceWrappers.put(Constants.GENERAL, generalDevices);
|
||||
deviceWrappers.put(Constants.PROP_AND, this.processANDSearch(allANDDevices));
|
||||
deviceWrappers.put(Constants.PROP_OR, this.processORSearch(allORDevices));
|
||||
deviceWrappers.put(Constants.LOCATION, locationDevices);
|
||||
|
||||
return aggregator.aggregate(deviceWrappers);
|
||||
}
|
||||
@ -157,5 +163,6 @@ public class ProcessorImpl implements Processor {
|
||||
}
|
||||
return maps;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -44,9 +44,13 @@ public class QueryBuilderImpl implements QueryBuilder {
|
||||
List<Condition> orColumns = new ArrayList<>();
|
||||
List<Condition> otherANDColumns = new ArrayList<>();
|
||||
List<Condition> otherORColumns = new ArrayList<>();
|
||||
Condition locConditon = new Condition();
|
||||
|
||||
if (conditions.size() == 1) {
|
||||
if (Utils.getDeviceDetailsColumnNames().containsKey(conditions.get(0)) ||
|
||||
|
||||
if (conditions.get(0).getKey().equalsIgnoreCase(Constants.LOCATION)) {
|
||||
locConditon = conditions.get(0);
|
||||
} else if (Utils.getDeviceDetailsColumnNames().containsKey(conditions.get(0)) ||
|
||||
Utils.getDeviceLocationColumnNames().containsKey(conditions.get(0))) {
|
||||
andColumns.add(conditions.get(0));
|
||||
} else {
|
||||
@ -54,7 +58,9 @@ public class QueryBuilderImpl implements QueryBuilder {
|
||||
}
|
||||
} else {
|
||||
for (Condition con : conditions) {
|
||||
if (Utils.getDeviceDetailsColumnNames().containsKey(con.getKey()) ||
|
||||
if (con.getKey().equalsIgnoreCase(Constants.LOCATION)) {
|
||||
locConditon = con;
|
||||
} else if (Utils.getDeviceDetailsColumnNames().containsKey(con.getKey()) ||
|
||||
Utils.getDeviceLocationColumnNames().containsKey(con.getKey())) {
|
||||
if (con.getState().equals(Condition.State.AND)) {
|
||||
andColumns.add(con);
|
||||
@ -80,11 +86,13 @@ public class QueryBuilderImpl implements QueryBuilder {
|
||||
this.processOR(orColumns)));
|
||||
queries.put(Constants.PROP_AND, this.processANDProperties(otherANDColumns));
|
||||
queries.put(Constants.PROP_OR, this.processORProperties(otherORColumns));
|
||||
queries.put(Constants.LOCATION, this.processLocation(locConditon));
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("General Query : " + queries.get(Constants.GENERAL));
|
||||
log.debug("Property with AND Query : " + queries.get(Constants.PROP_AND));
|
||||
log.debug("Property with OR Query : " + queries.get(Constants.PROP_OR));
|
||||
log.debug("Location related Query : " + queries.get(Constants.LOCATION));
|
||||
}
|
||||
|
||||
return queries;
|
||||
@ -125,6 +133,13 @@ public class QueryBuilderImpl implements QueryBuilder {
|
||||
return querySuffix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> processLocation(Condition condition) throws InvalidOperatorException {
|
||||
List<String> queryList = new ArrayList<>();
|
||||
queryList.add(this.buildLocationQuery(condition.getValue()));
|
||||
return queryList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> processANDProperties(List<Condition> conditions) throws InvalidOperatorException {
|
||||
return this.getQueryList(conditions);
|
||||
@ -146,6 +161,18 @@ public class QueryBuilderImpl implements QueryBuilder {
|
||||
return queryList;
|
||||
}
|
||||
|
||||
private String buildLocationQuery(String location) {
|
||||
|
||||
String query = this.getGenericQueryPart();
|
||||
query = query + " OR STREET1 LIKE \'%" + location + "%\'";
|
||||
query = query + " OR STREET2 LIKE \'%" + location + "%\'";
|
||||
query = query + " OR CITY LIKE \'%" + location + "%\'";
|
||||
query = query + " OR STATE LIKE \'%" + location + "%\'";
|
||||
query = query + " OR COUNTRY LIKE \'%" + location + "%\'";
|
||||
query = query + " OR ZIP LIKE \'%" + location + "%\'";
|
||||
return query;
|
||||
}
|
||||
|
||||
private String getGenericQueryPart() {
|
||||
|
||||
return "SELECT D.ID, D.DESCRIPTION, D.NAME, \n" +
|
||||
@ -159,18 +186,6 @@ public class QueryBuilderImpl implements QueryBuilder {
|
||||
"DM_DEVICE_TYPE AS DT WHERE D.TENANT_ID = " +
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
|
||||
// CREATE TABLE IF NOT EXISTS DM_DEVICE (
|
||||
// ID INTEGER auto_increment NOT NULL,
|
||||
// DESCRIPTION TEXT DEFAULT NULL,
|
||||
// NAME VARCHAR(100) DEFAULT NULL,
|
||||
// DEVICE_TYPE_ID INT(11) DEFAULT NULL,
|
||||
// DEVICE_IDENTIFICATION VARCHAR(300) DEFAULT NULL,
|
||||
// TENANT_ID INTEGER DEFAULT 0,
|
||||
// PRIMARY KEY (ID),
|
||||
// CONSTRAINT fk_DM_DEVICE_DM_DEVICE_TYPE2 FOREIGN KEY (DEVICE_TYPE_ID )
|
||||
// REFERENCES DM_DEVICE_TYPE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||
// );
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -190,4 +205,3 @@ public class QueryBuilderImpl implements QueryBuilder {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -36,15 +36,28 @@ public class ResultSetAggregatorImpl implements ResultSetAggregator {
|
||||
Map<Integer, DeviceWrapper> generalQueryMap = this.convertToMap(deviceWrappers.get(Constants.GENERAL));
|
||||
Map<Integer, DeviceWrapper> andMap = this.convertToMap(deviceWrappers.get(Constants.PROP_AND));
|
||||
Map<Integer, DeviceWrapper> orMap = this.convertToMap(deviceWrappers.get(Constants.PROP_OR));
|
||||
Map<Integer, DeviceWrapper> locationMap = this.convertToMap(deviceWrappers.get(Constants.LOCATION));
|
||||
|
||||
List<DeviceWrapper> finalResult = new ArrayList<>();
|
||||
for (Integer a : andMap.keySet()) {
|
||||
if (generalQueryMap.containsKey(a)) {
|
||||
finalResult.add(andMap.get(a));
|
||||
if (!finalResult.contains(a)) {
|
||||
finalResult.add(andMap.get(a));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Integer a : orMap.keySet()) {
|
||||
finalResult.add(orMap.get(a));
|
||||
if (!finalResult.contains(a)) {
|
||||
finalResult.add(orMap.get(a));
|
||||
}
|
||||
}
|
||||
|
||||
for (Integer a : locationMap.keySet()) {
|
||||
if (!finalResult.contains(a)) {
|
||||
finalResult.add(locationMap.get(a));
|
||||
}
|
||||
}
|
||||
|
||||
return finalResult;
|
||||
}
|
||||
|
||||
|
||||
@ -360,6 +360,7 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION (
|
||||
LOCATION_URL VARCHAR(100) DEFAULT NULL,
|
||||
IMAGE_URL VARCHAR(100) DEFAULT NULL,
|
||||
APP_PROPERTIES BLOB NULL,
|
||||
MEMORY_USAGE DECIMAL(5) NULL,
|
||||
TENANT_ID INTEGER NOT NULL,
|
||||
PRIMARY KEY (ID)
|
||||
);
|
||||
|
||||
@ -361,6 +361,7 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION (
|
||||
LOCATION_URL VARCHAR(100) DEFAULT NULL,
|
||||
IMAGE_URL VARCHAR(100) DEFAULT NULL,
|
||||
APP_PROPERTIES BLOB NULL,
|
||||
MEMORY_USAGE INTEGER(10) NULL,
|
||||
TENANT_ID INTEGER NOT NULL,
|
||||
PRIMARY KEY (ID)
|
||||
);
|
||||
|
||||
@ -349,6 +349,7 @@ CREATE TABLE DM_APPLICATION (
|
||||
LOCATION_URL VARCHAR(100) DEFAULT NULL,
|
||||
IMAGE_URL VARCHAR(100) DEFAULT NULL,
|
||||
APP_PROPERTIES VARBINARY(max) NULL,
|
||||
MEMORY_USAGE INTEGER(10) NULL,
|
||||
TENANT_ID INTEGER NOT NULL,
|
||||
PRIMARY KEY (ID)
|
||||
);
|
||||
|
||||
@ -356,6 +356,7 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION (
|
||||
LOCATION_URL VARCHAR(100) DEFAULT NULL,
|
||||
IMAGE_URL VARCHAR(100) DEFAULT NULL,
|
||||
APP_PROPERTIES BLOB NULL,
|
||||
MEMORY_USAGE INTEGER(10) NULL,
|
||||
TENANT_ID INTEGER NOT NULL,
|
||||
PRIMARY KEY (ID)
|
||||
)ENGINE = InnoDB;
|
||||
|
||||
@ -576,6 +576,7 @@ CREATE TABLE DM_APPLICATION (
|
||||
LOCATION_URL VARCHAR2(100) DEFAULT NULL,
|
||||
IMAGE_URL VARCHAR2(100) DEFAULT NULL,
|
||||
APP_PROPERTIES BLOB NULL,
|
||||
MEMORY_USAGE NUMBER(10) NULL,
|
||||
TENANT_ID NUMBER(10) NOT NULL,
|
||||
CONSTRAINT PK_DM_APPLICATION PRIMARY KEY (ID)
|
||||
)
|
||||
|
||||
@ -313,6 +313,7 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION (
|
||||
LOCATION_URL VARCHAR(100) DEFAULT NULL,
|
||||
IMAGE_URL VARCHAR(100) DEFAULT NULL,
|
||||
APP_PROPERTIES BYTEA NULL,
|
||||
MEMORY_USAGE INTEGER NULL,
|
||||
TENANT_ID INTEGER NOT NULL
|
||||
);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user