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
Collaborator

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

<DeviceInfoConfigurations>
	<DeviceInfoItem>
            <DefinedValue>FIRMWARE_VERSION</DefinedValue>
            <DisplayValue>label_firmware_version</DisplayValue>
            <Type>deviceDetailsMap</Type>
        </DeviceInfoItem>
        <DeviceInfoItem>
            <DefinedValue>FIRMWARE_APP_VERSION</DefinedValue>
            <DisplayValue>label_app_version</DisplayValue>
            <Type>deviceDetailsMap</Type>
        </DeviceInfoItem>
        <DeviceInfoItem>
            <DefinedValue>FIRMWARE_SYSTEM_VERSION</DefinedValue>
            <DisplayValue>label_firmware_system_version</DisplayValue>
            <Type>deviceDetailsMap</Type>
        </DeviceInfoItem>
</DeviceInfoConfigurations>

DefinedValue = Key_value in DM_DEVECE_INFO table
DisplayValue = UI display text for filtering
Type = Dont change

## Purpose * Related ticket https://roadmap.entgra.net/issues/10262 ## 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 ``` <DeviceInfoConfigurations> <DeviceInfoItem> <DefinedValue>FIRMWARE_VERSION</DefinedValue> <DisplayValue>label_firmware_version</DisplayValue> <Type>deviceDetailsMap</Type> </DeviceInfoItem> <DeviceInfoItem> <DefinedValue>FIRMWARE_APP_VERSION</DefinedValue> <DisplayValue>label_app_version</DisplayValue> <Type>deviceDetailsMap</Type> </DeviceInfoItem> <DeviceInfoItem> <DefinedValue>FIRMWARE_SYSTEM_VERSION</DefinedValue> <DisplayValue>label_firmware_system_version</DisplayValue> <Type>deviceDetailsMap</Type> </DeviceInfoItem> </DeviceInfoConfigurations> ``` DefinedValue = Key_value in DM_DEVECE_INFO table DisplayValue = UI display text for filtering Type = Dont change
pramilaniroshan added 1 commit 1 year ago
pramilaniroshan added 1 commit 1 year ago
tcdlpds requested changes 1 year ago
// Add custom property to the paginationRequest object
request.addCustomProperty(propertyName, propertyValue);
}
}catch (IOException e){
Owner

Fix formatting issue

Fix formatting issue
pramilaniroshan marked this conversation as resolved
request.addCustomProperty(propertyName, propertyValue);
}
}catch (IOException e){
log.error("Error Adding custom property to the paginationRequest object");
Owner

We have ignored this Error, is it correct?

We have ignored this Error, is it correct?
pramilaniroshan marked this conversation as resolved
} 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 ";
Owner

Format the query

Format the query
pramilaniroshan marked this conversation as resolved
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 ";
Owner

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.

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.
Poster
Collaborator

This function available for H2 database and mysql

This function available for H2 database and mysql
pramilaniroshan marked this conversation as resolved
pramilaniroshan added 2 commits 1 year ago
pramilaniroshan added 1 commit 1 year ago
pahansith requested changes 1 year ago
request.addCustomProperty(propertyName, propertyValue);
}
} catch (IOException e) {
String msg = "Error Adding custom property to the paginationRequest object";
Owner

Improve the error message to indicate that that error occurred while converting customProperty string to Java Map

Improve the error message to indicate that that error occurred while converting customProperty string to Java Map
pramilaniroshan marked this conversation as resolved
"SELECT VALUE_FIELD " +
"FROM DM_DEVICE_INFO di " +
"WHERE di.DEVICE_ID = d.ID ";
sql += "AND di.KEY_FIELD = 'serial' " +
Owner

What is the reason for concat two times in the same if block?

What is the reason for concat two times in the same if block?
pramilaniroshan marked this conversation as resolved
isSerialProvided = true;
}
if (!request.getCustomProperty().isEmpty()) {
if (serial != null) {
Owner

Can be simplified using the isSerialProvided boolean

Can be simplified using the isSerialProvided boolean
Poster
Collaborator

No we can't use isSerialProvided. because firstly we check if serial != null and set isSerialProvided = true

No we can't use isSerialProvided. because firstly we check if serial != null and set isSerialProvided = true
pramilaniroshan marked this conversation as resolved
if (serial != null) {
sql += "AND ";
}
int conditionCount = 0;
Owner

Since this variable is only used to detect the first iteration of the loop, this can be simplified with a boolean variable.

Since this variable is only used to detect the first iteration of the loop, this can be simplified with a boolean variable.
pramilaniroshan marked this conversation as resolved
"SELECT VALUE_FIELD " +
"FROM DM_DEVICE_INFO di " +
"WHERE di.DEVICE_ID = d.ID ";
sql += "AND di.KEY_FIELD = '" + entry.getKey() + "' " +
Owner

What is the reason for concat two times in the same if block?

What is the reason for concat two times in the same if block?
pramilaniroshan marked this conversation as resolved
"SELECT VALUE_FIELD " +
"FROM DM_DEVICE_INFO di " +
"WHERE di.DEVICE_ID = d1.DEVICE_ID ";
sql += "AND di.KEY_FIELD = 'serial' " +
Owner

What is the reason for concat two times in the same if block?

What is the reason for concat two times in the same if block?
pramilaniroshan marked this conversation as resolved
"SELECT VALUE_FIELD " +
"FROM DM_DEVICE_INFO di " +
"WHERE di.DEVICE_ID = d.ID ";
sql += "AND di.KEY_FIELD = 'serial' " +
Owner

What is the reason for concat two times in the same if block?

What is the reason for concat two times in the same if block?
pramilaniroshan marked this conversation as resolved
}
int conditionCount = 0;
for (Map.Entry<String, String> entry : request.getCustomProperty().entrySet()) {
if (conditionCount > 0) {
Owner

Since this variable only used to detect the first iteration of the loop, this can be simplified with a boolean variable.

Since this variable only used to detect the first iteration of the loop, this can be simplified with a boolean variable.
pramilaniroshan marked this conversation as resolved
}
//Filter Group with serial number or any Custom Property in DM_DEVICE_INFO
if (serial != null || !request.getCustomProperty().isEmpty()) {
if (serial != null) {
Owner

Can be simplified using isStatusProvided boolean

Can be simplified using isStatusProvided boolean
pramilaniroshan marked this conversation as resolved
"SELECT VALUE_FIELD " +
"FROM DM_DEVICE_INFO di " +
"WHERE di.DEVICE_ID = d1.DEVICE_ID ";
sql += "AND di.KEY_FIELD = 'serial' " +
Owner

What is the reason for concat two times in the same if block?

What is the reason for concat two times in the same if block?
pramilaniroshan marked this conversation as resolved
pramilaniroshan added 1 commit 1 year ago
pahansith merged commit fccae9b8c0 into master 1 year ago

Reviewers

tcdlpds requested changes 1 year ago
pahansith requested changes 1 year ago
The pull request has been merged as fccae9b8c0.
Sign in to join this conversation.
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date

No due date set.

Dependencies

No dependencies set.

Reference: community/device-mgt-core#208
Loading…
There is no content yet.