Lwm2m: back&front: update filter for objectIds
This commit is contained in:
parent
1ed44010e4
commit
a8e093910a
@ -49,14 +49,15 @@ import java.util.Map;
|
||||
public class DeviceLwm2mController extends BaseController {
|
||||
|
||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
||||
@RequestMapping(value = "/lwm2m/deviceProfile", params = {"objectIds"}, method = RequestMethod.GET)
|
||||
@RequestMapping(value = "/lwm2m/deviceProfile", params = {"sortOrder", "sortProperty"}, method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public List<LwM2mObject> getLwm2mListObjects(@RequestParam int[] objectIds,
|
||||
@RequestParam(required = false) String textSearch,
|
||||
@RequestParam(required = false) String sortProperty,
|
||||
@RequestParam(required = false) String sortOrder) throws ThingsboardException {
|
||||
public List<LwM2mObject> getLwm2mListObjects(@RequestParam String sortOrder,
|
||||
@RequestParam String sortProperty,
|
||||
@RequestParam(required = false) int[] objectIds,
|
||||
@RequestParam(required = false) String searchText)
|
||||
throws ThingsboardException {
|
||||
try {
|
||||
return lwM2MModelsRepository.getLwm2mObjects(objectIds, textSearch, sortProperty, sortOrder);
|
||||
return lwM2MModelsRepository.getLwm2mObjects(objectIds, searchText, sortProperty, sortOrder);
|
||||
} catch (Exception e) {
|
||||
throw handleException(e);
|
||||
}
|
||||
@ -67,11 +68,11 @@ public class DeviceLwm2mController extends BaseController {
|
||||
@ResponseBody
|
||||
public PageData<LwM2mObject> getLwm2mListObjects(@RequestParam int pageSize,
|
||||
@RequestParam int page,
|
||||
@RequestParam(required = false) String textSearch,
|
||||
@RequestParam(required = false) String searchText,
|
||||
@RequestParam(required = false) String sortProperty,
|
||||
@RequestParam(required = false) String sortOrder) throws ThingsboardException {
|
||||
try {
|
||||
PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder);
|
||||
PageLink pageLink = createPageLink(pageSize, page, searchText, sortProperty, sortOrder);
|
||||
return checkNotNull(lwM2MModelsRepository.findDeviceLwm2mObjects(getTenantId(), pageLink));
|
||||
} catch (Exception e) {
|
||||
throw handleException(e);
|
||||
|
||||
@ -81,10 +81,14 @@ public class LwM2MModelsRepository {
|
||||
* if textSearch is null then it uses AllList from List<ObjectModel>)
|
||||
*/
|
||||
public List<LwM2mObject> getLwm2mObjects(int[] objectIds, String textSearch, String sortProperty, String sortOrder) {
|
||||
return getLwm2mObjects((objectIds.length > 0 && textSearch != null && !textSearch.isEmpty()) ?
|
||||
(ObjectModel element) -> IntStream.of(objectIds).anyMatch(x -> x == element.id) || element.name.contains(textSearch) :
|
||||
(objectIds.length > 0) ?
|
||||
(ObjectModel element) -> IntStream.of(objectIds).anyMatch(x -> x == element.id) :
|
||||
if (objectIds == null && textSearch != null && !textSearch.isEmpty()) {
|
||||
objectIds = getObjectIdFromTextSearch(textSearch);
|
||||
}
|
||||
int[] finalObjectIds = objectIds;
|
||||
return getLwm2mObjects((objectIds != null && objectIds.length > 0 && textSearch != null && !textSearch.isEmpty()) ?
|
||||
(ObjectModel element) -> IntStream.of(finalObjectIds).anyMatch(x -> x == element.id) || element.name.toLowerCase().contains(textSearch.toLowerCase()) :
|
||||
(objectIds != null && objectIds.length > 0) ?
|
||||
(ObjectModel element) -> IntStream.of(finalObjectIds).anyMatch(x -> x == element.id) :
|
||||
(textSearch != null && !textSearch.isEmpty()) ?
|
||||
(ObjectModel element) -> element.name.contains(textSearch) :
|
||||
null,
|
||||
@ -165,7 +169,10 @@ public class LwM2MModelsRepository {
|
||||
* PageNumber = 1, PageSize = List<LwM2mObject>.size()
|
||||
*/
|
||||
public PageData<LwM2mObject> findLwm2mListObjects(PageLink pageLink) {
|
||||
PageImpl page = new PageImpl(getLwm2mObjects(getObjectIdFromTextSearch(pageLink.getTextSearch()), pageLink.getTextSearch(), pageLink.getSortOrder().getProperty(), pageLink.getSortOrder().getDirection().name()));
|
||||
PageImpl page = new PageImpl(getLwm2mObjects(getObjectIdFromTextSearch(pageLink.getTextSearch()),
|
||||
pageLink.getTextSearch(),
|
||||
pageLink.getSortOrder().getProperty(),
|
||||
pageLink.getSortOrder().getDirection().name()));
|
||||
PageData pageData = new PageData(page.getContent(), page.getTotalPages(), page.getTotalElements(), page.hasNext());
|
||||
return pageData;
|
||||
}
|
||||
|
||||
@ -21,7 +21,7 @@ import { defaultHttpOptionsFromConfig, RequestConfig } from './http-utils';
|
||||
import { Observable } from 'rxjs';
|
||||
import { PageData } from '@shared/models/page/page-data';
|
||||
import { DeviceProfile, DeviceProfileInfo, DeviceTransportType } from '@shared/models/device.models';
|
||||
import { isDefinedAndNotNull } from '@core/utils';
|
||||
import { isDefinedAndNotNull, isEmptyStr } from '@core/utils';
|
||||
import { ObjectLwM2M, ServerSecurityConfig } from '@home/components/profile/device/lwm2m/profile-config.models';
|
||||
import { SortOrder } from '@shared/models/page/sort-order';
|
||||
|
||||
@ -43,14 +43,14 @@ export class DeviceProfileService {
|
||||
return this.http.get<DeviceProfile>(`/api/deviceProfile/${deviceProfileId}`, defaultHttpOptionsFromConfig(config));
|
||||
}
|
||||
|
||||
public getLwm2mObjects(objectIds: number[] = [], searchText?: string, sortOrder?: SortOrder, config?: RequestConfig):
|
||||
public getLwm2mObjects(sortOrder: SortOrder, objectIds?: number[], searchText?: string, config?: RequestConfig):
|
||||
Observable<Array<ObjectLwM2M>> {
|
||||
let url = `/api/lwm2m/deviceProfile/?objectIds=${objectIds}`;
|
||||
if (isDefinedAndNotNull(searchText)) {
|
||||
url += `&searchText=${searchText}`;
|
||||
let url = `/api/lwm2m/deviceProfile/?sortProperty=${sortOrder.property}&sortOrder=${sortOrder.direction}`;
|
||||
if (isDefinedAndNotNull(objectIds) && objectIds.length > 0) {
|
||||
url += `&objectIds=${objectIds}`;
|
||||
}
|
||||
if (isDefinedAndNotNull(sortOrder)) {
|
||||
url += `&sortProperty=${sortOrder.property}&sortOrder=${sortOrder.direction}`;
|
||||
if (isDefinedAndNotNull(searchText) && !isEmptyStr(searchText)) {
|
||||
url += `&searchText=${searchText}`;
|
||||
}
|
||||
return this.http.get<Array<ObjectLwM2M>>(url, defaultHttpOptionsFromConfig(config));
|
||||
}
|
||||
|
||||
@ -74,7 +74,8 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
|
||||
this.requiredValue = coerceBooleanProperty(value);
|
||||
}
|
||||
|
||||
private propagateChange = (v: any) => { };
|
||||
private propagateChange = (v: any) => {
|
||||
};
|
||||
|
||||
constructor(private store: Store<AppState>,
|
||||
private fb: FormBuilder,
|
||||
@ -130,8 +131,8 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
|
||||
writeValue(value: any | null): void {
|
||||
this.configurationValue = (Object.keys(value).length === 0) ? getDefaultProfileConfig() : value;
|
||||
this.lwm2mDeviceConfigFormGroup.patchValue({
|
||||
configurationJson: this.configurationValue
|
||||
}, {emitEvent: false});
|
||||
configurationJson: this.configurationValue
|
||||
}, {emitEvent: false});
|
||||
this.initWriteValue();
|
||||
}
|
||||
|
||||
@ -143,7 +144,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
|
||||
property: 'id',
|
||||
direction: Direction.ASC
|
||||
};
|
||||
this.deviceProfileService.getLwm2mObjects(modelValue.objectIds, null, sortOrder).subscribe(
|
||||
this.deviceProfileService.getLwm2mObjects(sortOrder, modelValue.objectIds, null).subscribe(
|
||||
(objectsList) => {
|
||||
modelValue.objectsList = objectsList;
|
||||
this.updateWriteValue(modelValue);
|
||||
@ -300,9 +301,9 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
|
||||
|
||||
private addInstances = (attribute: string[], telemetry: string[], clientObserveAttrTelemetry: ObjectLwM2M[]): void => {
|
||||
const instancesPath = attribute.concat(telemetry)
|
||||
.filter(instance => !instance.includes('/0/'))
|
||||
.map(instance => this.convertPathToInstance(instance))
|
||||
.sort();
|
||||
.filter(instance => !instance.includes('/0/'))
|
||||
.map(instance => this.convertPathToInstance(instance))
|
||||
.sort();
|
||||
|
||||
new Set(instancesPath).forEach(path => {
|
||||
const pathParameter = Array.from(path.split('/'), Number);
|
||||
|
||||
@ -19,12 +19,11 @@ import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR, Valida
|
||||
import { coerceBooleanProperty } from '@angular/cdk/coercion';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { AppState } from '@core/core.state';
|
||||
import { Observable } from 'rxjs';
|
||||
import { filter, map, mergeMap, share, tap } from 'rxjs/operators';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { filter, mergeMap, share, tap } from 'rxjs/operators';
|
||||
import { ObjectLwM2M } from './profile-config.models';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { DeviceProfileService } from '@core/http/device-profile.service';
|
||||
import { PageLink } from '@shared/models/page/page-link';
|
||||
import { Direction } from '@shared/models/page/sort-order';
|
||||
|
||||
@Component({
|
||||
@ -115,6 +114,7 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
|
||||
this.disabled = isDisabled;
|
||||
if (isDisabled) {
|
||||
this.lwm2mListFormGroup.disable({emitEvent: false});
|
||||
this.clear();
|
||||
} else {
|
||||
this.lwm2mListFormGroup.enable({emitEvent: false});
|
||||
}
|
||||
@ -168,16 +168,14 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
|
||||
return object ? object.name : undefined;
|
||||
}
|
||||
|
||||
// @TODO: add support page size
|
||||
// @TODO: filter for id + name
|
||||
private fetchListObjects = (searchText?: string): Observable<Array<ObjectLwM2M>> => {
|
||||
this.searchText = searchText;
|
||||
const pageLink = new PageLink(50, 0, searchText, {
|
||||
const sortOrder = {
|
||||
property: 'name',
|
||||
direction: Direction.ASC
|
||||
});
|
||||
return this.deviceProfileService.getLwm2mObjectsPage(pageLink, {ignoreLoading: true}).pipe(
|
||||
map(pageData => pageData.data)
|
||||
};
|
||||
return this.deviceProfileService.getLwm2mObjects(sortOrder, null, searchText).pipe(
|
||||
mergeMap(objectsList => of(objectsList))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user