Skip to content

Commit

Permalink
[#3516] Support data field filter for JDBC based registry management API
Browse files Browse the repository at this point in the history
Implement backend filter for H2 & Postgresql:
- field/value filter
- value filter of type bool/number/string
- enable filter wildcards for string value
- add documentation

Also-by: Matthias Feurer <[email protected]>
Signed-off-by: George Dimitropoulos <[email protected]>
  • Loading branch information
gdimitropoulos-sotec authored Jul 27, 2023
1 parent bb9e720 commit 3f2eee3
Show file tree
Hide file tree
Showing 8 changed files with 578 additions and 285 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

countDevicesOfTenantWithFilter: |
SELECT COUNT(*) AS deviceCount FROM %1$s
WHERE
tenant_id=:tenant_id
AND
LOCATE(CONCAT_WS(':', :field, REPLACE(:value, '"')), REPLACE(data, '"'))
OR
REPLACE(data, '"') LIKE CONCAT('%%', :field, ':', REPLACE(:value, '"'))
findDevicesOfTenantWithFilter: |
SELECT *
FROM %s
WHERE
tenant_id=:tenant_id
AND
LOCATE(CONCAT_WS(':', :field, REPLACE(:value, '"')), REPLACE(data, '"'))
OR
REPLACE(data, '"') LIKE CONCAT('%%', :field, ':', REPLACE(:value, '"'))
ORDER BY device_id ASC
LIMIT :page_size
OFFSET :page_offset
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,23 @@ resolveGroups: |
tenant_id=:tenant_id
AND
group_id in (select unnest((string_to_array(:group_ids,','))::varchar[]))
countDevicesOfTenantWithFilter: |
SELECT COUNT(*) AS deviceCount FROM %1$s
WHERE
tenant_id=:tenant_id
AND
data->>:field LIKE CAST(:value AS VARCHAR) OR
jsonb_extract_path(data,'ext')->>:field LIKE CAST(:value as varchar)
findDevicesOfTenantWithFilter: |
SELECT *
FROM %s
WHERE
tenant_id=:tenant_id
AND
data->>:field LIKE CAST(:value AS VARCHAR) OR
jsonb_extract_path(data,'ext')->>:field LIKE CAST(:value as varchar)
ORDER BY device_id ASC
LIMIT :page_size
OFFSET :page_offset
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,6 @@ findDevicesOfTenant: |
FROM %s
WHERE
tenant_id=:tenant_id
ORDER BY device_id
ORDER BY device_id ASC
LIMIT :page_size
OFFSET :page_offset
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected Future<OperationResult<Id>> processCreateDevice(final DeviceKey key, f
Optional.of(r.getVersion()))
)

.recover(e -> Services.recover(e));
.recover(Services::recover);

}

Expand Down Expand Up @@ -112,7 +112,7 @@ protected Future<OperationResult<Id>> processUpdateDevice(final DeviceKey key, f
Optional.empty(),
Optional.of(r.getVersion())))

.recover(e -> Services.recover(e));
.recover(Services::recover);

}

Expand All @@ -131,7 +131,7 @@ protected Future<Result<Void>> processDeleteDevice(final DeviceKey key, final Op
return Result.<Void>from(HttpURLConnection.HTTP_NO_CONTENT);
}
})
.recover(e -> Services.recover(e));
.recover(Services::recover);

}

Expand All @@ -141,7 +141,7 @@ protected Future<Result<Void>> processDeleteDevicesOfTenant(final String tenantI
return this.store
.dropTenant(tenantId, span.context())
.map(r -> Result.<Void>from(HttpURLConnection.HTTP_NO_CONTENT))
.recover(e -> Services.recover(e));
.recover(Services::recover);
}

@Override
Expand All @@ -151,22 +151,22 @@ protected String generateDeviceId(final String tenantId) {

@Override
protected Future<OperationResult<SearchResult<DeviceWithId>>> processSearchDevices(
final String tenantId,
final int pageSize,
final int pageOffset,
final List<Filter> filters,
final List<Sort> sortOptions,
final Span span) {
final String tenantId,
final int pageSize,
final int pageOffset,
final List<Filter> filters,
final List<Sort> sortOptions,
final Span span) {

Objects.requireNonNull(tenantId);
Objects.requireNonNull(span);

return store.findDevices(tenantId, pageSize, pageOffset, span.context())
.map(result -> OperationResult.ok(
HttpURLConnection.HTTP_OK,
result,
Optional.empty(),
Optional.empty()))
.recover(e -> Services.recover(e));
return store.findDevices(tenantId, pageSize, pageOffset, filters, span.context())
.map(result -> OperationResult.ok(
HttpURLConnection.HTTP_OK,
result,
Optional.empty(),
Optional.empty()))
.recover(Services::recover);
}
}
Loading

0 comments on commit 3f2eee3

Please sign in to comment.