Add Devices filtering by a Custom Property feature to API and dao layer #208
Merged
pahansith
merged 6 commits from pramilaniroshan/device-mgt-core:custom-propery-search
into master
1 year ago
Loading…
Reference in new issue
There is no content yet.
Delete Branch 'pramilaniroshan/device-mgt-core:custom-propery-search'
Deleting a branch is permanent. It CANNOT be undone. Continue?
Purpose
Description
This modifed API accept any custom property key value pair as a encoded JSON String for filtering devices
/devicescustomProperty=%7B%22FIRMWARE_APP_VERSION%22%3A%22122%22%2C%22FIRMWARE_VERSION%22%3A%22123%22%7D
Add Custom property to mdm-ui-config.xml
DefinedValue = Key_value in DM_DEVECE_INFO table
DisplayValue = UI display text for filtering
Type = Dont change
// Add custom property to the paginationRequest object
request.addCustomProperty(propertyName, propertyValue);
}
}catch (IOException e){
Fix formatting issue
request.addCustomProperty(propertyName, propertyValue);
}
}catch (IOException e){
log.error("Error Adding custom property to the paginationRequest object");
We have ignored this Error, is it correct?
} else {
//Filter by serial number or any Custom Property in DM_DEVICE_INFO
if (serial != null || !request.getCustomProperty().isEmpty()) {
sql = sql + "FROM DM_DEVICE d INNER JOIN DM_DEVICE_TYPE t ON d.DEVICE_TYPE_ID = t.ID WHERE ";
Format the query
if (serial != null || !request.getCustomProperty().isEmpty()) {
sql = sql + "FROM DM_DEVICE d INNER JOIN DM_DEVICE_TYPE t ON d.DEVICE_TYPE_ID = t.ID WHERE ";
if (serial != null) {
sql += "EXISTS ( SELECT VALUE_FIELD FROM DM_DEVICE_INFO di WHERE di.DEVICE_ID = d.ID ";
Is this function available for all other DBs as well? If it doesn't support then this query should move from the GenericDAOImple and modify the logic.
This function available for H2 database and mysql
request.addCustomProperty(propertyName, propertyValue);
}
} catch (IOException e) {
String msg = "Error Adding custom property to the paginationRequest object";
Improve the error message to indicate that that error occurred while converting customProperty string to Java Map
"SELECT VALUE_FIELD " +
"FROM DM_DEVICE_INFO di " +
"WHERE di.DEVICE_ID = d.ID ";
sql += "AND di.KEY_FIELD = 'serial' " +
What is the reason for concat two times in the same if block?
isSerialProvided = true;
}
if (!request.getCustomProperty().isEmpty()) {
if (serial != null) {
Can be simplified using the isSerialProvided boolean
No we can't use isSerialProvided. because firstly we check if serial != null and set isSerialProvided = true
if (serial != null) {
sql += "AND ";
}
int conditionCount = 0;
Since this variable is only used to detect the first iteration of the loop, this can be simplified with a boolean variable.
"SELECT VALUE_FIELD " +
"FROM DM_DEVICE_INFO di " +
"WHERE di.DEVICE_ID = d.ID ";
sql += "AND di.KEY_FIELD = '" + entry.getKey() + "' " +
What is the reason for concat two times in the same if block?
"SELECT VALUE_FIELD " +
"FROM DM_DEVICE_INFO di " +
"WHERE di.DEVICE_ID = d1.DEVICE_ID ";
sql += "AND di.KEY_FIELD = 'serial' " +
What is the reason for concat two times in the same if block?
"SELECT VALUE_FIELD " +
"FROM DM_DEVICE_INFO di " +
"WHERE di.DEVICE_ID = d.ID ";
sql += "AND di.KEY_FIELD = 'serial' " +
What is the reason for concat two times in the same if block?
}
int conditionCount = 0;
for (Map.Entry<String, String> entry : request.getCustomProperty().entrySet()) {
if (conditionCount > 0) {
Since this variable only used to detect the first iteration of the loop, this can be simplified with a boolean variable.
}
//Filter Group with serial number or any Custom Property in DM_DEVICE_INFO
if (serial != null || !request.getCustomProperty().isEmpty()) {
if (serial != null) {
Can be simplified using isStatusProvided boolean
"SELECT VALUE_FIELD " +
"FROM DM_DEVICE_INFO di " +
"WHERE di.DEVICE_ID = d1.DEVICE_ID ";
sql += "AND di.KEY_FIELD = 'serial' " +
What is the reason for concat two times in the same if block?
fccae9b8c0
into master 1 year agoReviewers
fccae9b8c0
.