Commit a8e093910a27e0c2ef6314e521d4a8c942e5daa0

Authored by nickAS21
1 parent 1ed44010

Lwm2m: back&front: update filter for objectIds

... ... @@ -49,14 +49,15 @@ import java.util.Map;
49 49 public class DeviceLwm2mController extends BaseController {
50 50
51 51 @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
52   - @RequestMapping(value = "/lwm2m/deviceProfile", params = {"objectIds"}, method = RequestMethod.GET)
  52 + @RequestMapping(value = "/lwm2m/deviceProfile", params = {"sortOrder", "sortProperty"}, method = RequestMethod.GET)
53 53 @ResponseBody
54   - public List<LwM2mObject> getLwm2mListObjects(@RequestParam int[] objectIds,
55   - @RequestParam(required = false) String textSearch,
56   - @RequestParam(required = false) String sortProperty,
57   - @RequestParam(required = false) String sortOrder) throws ThingsboardException {
  54 + public List<LwM2mObject> getLwm2mListObjects(@RequestParam String sortOrder,
  55 + @RequestParam String sortProperty,
  56 + @RequestParam(required = false) int[] objectIds,
  57 + @RequestParam(required = false) String searchText)
  58 + throws ThingsboardException {
58 59 try {
59   - return lwM2MModelsRepository.getLwm2mObjects(objectIds, textSearch, sortProperty, sortOrder);
  60 + return lwM2MModelsRepository.getLwm2mObjects(objectIds, searchText, sortProperty, sortOrder);
60 61 } catch (Exception e) {
61 62 throw handleException(e);
62 63 }
... ... @@ -67,11 +68,11 @@ public class DeviceLwm2mController extends BaseController {
67 68 @ResponseBody
68 69 public PageData<LwM2mObject> getLwm2mListObjects(@RequestParam int pageSize,
69 70 @RequestParam int page,
70   - @RequestParam(required = false) String textSearch,
  71 + @RequestParam(required = false) String searchText,
71 72 @RequestParam(required = false) String sortProperty,
72 73 @RequestParam(required = false) String sortOrder) throws ThingsboardException {
73 74 try {
74   - PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder);
  75 + PageLink pageLink = createPageLink(pageSize, page, searchText, sortProperty, sortOrder);
75 76 return checkNotNull(lwM2MModelsRepository.findDeviceLwm2mObjects(getTenantId(), pageLink));
76 77 } catch (Exception e) {
77 78 throw handleException(e);
... ...
... ... @@ -81,10 +81,14 @@ public class LwM2MModelsRepository {
81 81 * if textSearch is null then it uses AllList from List<ObjectModel>)
82 82 */
83 83 public List<LwM2mObject> getLwm2mObjects(int[] objectIds, String textSearch, String sortProperty, String sortOrder) {
84   - return getLwm2mObjects((objectIds.length > 0 && textSearch != null && !textSearch.isEmpty()) ?
85   - (ObjectModel element) -> IntStream.of(objectIds).anyMatch(x -> x == element.id) || element.name.contains(textSearch) :
86   - (objectIds.length > 0) ?
87   - (ObjectModel element) -> IntStream.of(objectIds).anyMatch(x -> x == element.id) :
  84 + if (objectIds == null && textSearch != null && !textSearch.isEmpty()) {
  85 + objectIds = getObjectIdFromTextSearch(textSearch);
  86 + }
  87 + int[] finalObjectIds = objectIds;
  88 + return getLwm2mObjects((objectIds != null && objectIds.length > 0 && textSearch != null && !textSearch.isEmpty()) ?
  89 + (ObjectModel element) -> IntStream.of(finalObjectIds).anyMatch(x -> x == element.id) || element.name.toLowerCase().contains(textSearch.toLowerCase()) :
  90 + (objectIds != null && objectIds.length > 0) ?
  91 + (ObjectModel element) -> IntStream.of(finalObjectIds).anyMatch(x -> x == element.id) :
88 92 (textSearch != null && !textSearch.isEmpty()) ?
89 93 (ObjectModel element) -> element.name.contains(textSearch) :
90 94 null,
... ... @@ -165,7 +169,10 @@ public class LwM2MModelsRepository {
165 169 * PageNumber = 1, PageSize = List<LwM2mObject>.size()
166 170 */
167 171 public PageData<LwM2mObject> findLwm2mListObjects(PageLink pageLink) {
168   - PageImpl page = new PageImpl(getLwm2mObjects(getObjectIdFromTextSearch(pageLink.getTextSearch()), pageLink.getTextSearch(), pageLink.getSortOrder().getProperty(), pageLink.getSortOrder().getDirection().name()));
  172 + PageImpl page = new PageImpl(getLwm2mObjects(getObjectIdFromTextSearch(pageLink.getTextSearch()),
  173 + pageLink.getTextSearch(),
  174 + pageLink.getSortOrder().getProperty(),
  175 + pageLink.getSortOrder().getDirection().name()));
169 176 PageData pageData = new PageData(page.getContent(), page.getTotalPages(), page.getTotalElements(), page.hasNext());
170 177 return pageData;
171 178 }
... ...
... ... @@ -21,7 +21,7 @@ import { defaultHttpOptionsFromConfig, RequestConfig } from './http-utils';
21 21 import { Observable } from 'rxjs';
22 22 import { PageData } from '@shared/models/page/page-data';
23 23 import { DeviceProfile, DeviceProfileInfo, DeviceTransportType } from '@shared/models/device.models';
24   -import { isDefinedAndNotNull } from '@core/utils';
  24 +import { isDefinedAndNotNull, isEmptyStr } from '@core/utils';
25 25 import { ObjectLwM2M, ServerSecurityConfig } from '@home/components/profile/device/lwm2m/profile-config.models';
26 26 import { SortOrder } from '@shared/models/page/sort-order';
27 27
... ... @@ -43,14 +43,14 @@ export class DeviceProfileService {
43 43 return this.http.get<DeviceProfile>(`/api/deviceProfile/${deviceProfileId}`, defaultHttpOptionsFromConfig(config));
44 44 }
45 45
46   - public getLwm2mObjects(objectIds: number[] = [], searchText?: string, sortOrder?: SortOrder, config?: RequestConfig):
  46 + public getLwm2mObjects(sortOrder: SortOrder, objectIds?: number[], searchText?: string, config?: RequestConfig):
47 47 Observable<Array<ObjectLwM2M>> {
48   - let url = `/api/lwm2m/deviceProfile/?objectIds=${objectIds}`;
49   - if (isDefinedAndNotNull(searchText)) {
50   - url += `&searchText=${searchText}`;
  48 + let url = `/api/lwm2m/deviceProfile/?sortProperty=${sortOrder.property}&sortOrder=${sortOrder.direction}`;
  49 + if (isDefinedAndNotNull(objectIds) && objectIds.length > 0) {
  50 + url += `&objectIds=${objectIds}`;
51 51 }
52   - if (isDefinedAndNotNull(sortOrder)) {
53   - url += `&sortProperty=${sortOrder.property}&sortOrder=${sortOrder.direction}`;
  52 + if (isDefinedAndNotNull(searchText) && !isEmptyStr(searchText)) {
  53 + url += `&searchText=${searchText}`;
54 54 }
55 55 return this.http.get<Array<ObjectLwM2M>>(url, defaultHttpOptionsFromConfig(config));
56 56 }
... ...
... ... @@ -74,7 +74,8 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
74 74 this.requiredValue = coerceBooleanProperty(value);
75 75 }
76 76
77   - private propagateChange = (v: any) => { };
  77 + private propagateChange = (v: any) => {
  78 + };
78 79
79 80 constructor(private store: Store<AppState>,
80 81 private fb: FormBuilder,
... ... @@ -130,8 +131,8 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
130 131 writeValue(value: any | null): void {
131 132 this.configurationValue = (Object.keys(value).length === 0) ? getDefaultProfileConfig() : value;
132 133 this.lwm2mDeviceConfigFormGroup.patchValue({
133   - configurationJson: this.configurationValue
134   - }, {emitEvent: false});
  134 + configurationJson: this.configurationValue
  135 + }, {emitEvent: false});
135 136 this.initWriteValue();
136 137 }
137 138
... ... @@ -143,7 +144,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
143 144 property: 'id',
144 145 direction: Direction.ASC
145 146 };
146   - this.deviceProfileService.getLwm2mObjects(modelValue.objectIds, null, sortOrder).subscribe(
  147 + this.deviceProfileService.getLwm2mObjects(sortOrder, modelValue.objectIds, null).subscribe(
147 148 (objectsList) => {
148 149 modelValue.objectsList = objectsList;
149 150 this.updateWriteValue(modelValue);
... ... @@ -300,9 +301,9 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
300 301
301 302 private addInstances = (attribute: string[], telemetry: string[], clientObserveAttrTelemetry: ObjectLwM2M[]): void => {
302 303 const instancesPath = attribute.concat(telemetry)
303   - .filter(instance => !instance.includes('/0/'))
304   - .map(instance => this.convertPathToInstance(instance))
305   - .sort();
  304 + .filter(instance => !instance.includes('/0/'))
  305 + .map(instance => this.convertPathToInstance(instance))
  306 + .sort();
306 307
307 308 new Set(instancesPath).forEach(path => {
308 309 const pathParameter = Array.from(path.split('/'), Number);
... ...
... ... @@ -19,12 +19,11 @@ import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR, Valida
19 19 import { coerceBooleanProperty } from '@angular/cdk/coercion';
20 20 import { Store } from '@ngrx/store';
21 21 import { AppState } from '@core/core.state';
22   -import { Observable } from 'rxjs';
23   -import { filter, map, mergeMap, share, tap } from 'rxjs/operators';
  22 +import { Observable, of } from 'rxjs';
  23 +import { filter, mergeMap, share, tap } from 'rxjs/operators';
24 24 import { ObjectLwM2M } from './profile-config.models';
25 25 import { TranslateService } from '@ngx-translate/core';
26 26 import { DeviceProfileService } from '@core/http/device-profile.service';
27   -import { PageLink } from '@shared/models/page/page-link';
28 27 import { Direction } from '@shared/models/page/sort-order';
29 28
30 29 @Component({
... ... @@ -115,6 +114,7 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
115 114 this.disabled = isDisabled;
116 115 if (isDisabled) {
117 116 this.lwm2mListFormGroup.disable({emitEvent: false});
  117 + this.clear();
118 118 } else {
119 119 this.lwm2mListFormGroup.enable({emitEvent: false});
120 120 }
... ... @@ -168,16 +168,14 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V
168 168 return object ? object.name : undefined;
169 169 }
170 170
171   - // @TODO: add support page size
172   - // @TODO: filter for id + name
173 171 private fetchListObjects = (searchText?: string): Observable<Array<ObjectLwM2M>> => {
174 172 this.searchText = searchText;
175   - const pageLink = new PageLink(50, 0, searchText, {
  173 + const sortOrder = {
176 174 property: 'name',
177 175 direction: Direction.ASC
178   - });
179   - return this.deviceProfileService.getLwm2mObjectsPage(pageLink, {ignoreLoading: true}).pipe(
180   - map(pageData => pageData.data)
  176 + };
  177 + return this.deviceProfileService.getLwm2mObjects(sortOrder, null, searchText).pipe(
  178 + mergeMap(objectsList => of(objectsList))
181 179 );
182 180 }
183 181
... ...