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