Commit a8e093910a27e0c2ef6314e521d4a8c942e5daa0
1 parent
1ed44010
Lwm2m: back&front: update filter for objectIds
Showing
5 changed files
with
43 additions
and
36 deletions
@@ -49,14 +49,15 @@ import java.util.Map; | @@ -49,14 +49,15 @@ import java.util.Map; | ||
49 | public class DeviceLwm2mController extends BaseController { | 49 | public class DeviceLwm2mController extends BaseController { |
50 | 50 | ||
51 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") | 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 | @ResponseBody | 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 | try { | 59 | try { |
59 | - return lwM2MModelsRepository.getLwm2mObjects(objectIds, textSearch, sortProperty, sortOrder); | 60 | + return lwM2MModelsRepository.getLwm2mObjects(objectIds, searchText, sortProperty, sortOrder); |
60 | } catch (Exception e) { | 61 | } catch (Exception e) { |
61 | throw handleException(e); | 62 | throw handleException(e); |
62 | } | 63 | } |
@@ -67,11 +68,11 @@ public class DeviceLwm2mController extends BaseController { | @@ -67,11 +68,11 @@ public class DeviceLwm2mController extends BaseController { | ||
67 | @ResponseBody | 68 | @ResponseBody |
68 | public PageData<LwM2mObject> getLwm2mListObjects(@RequestParam int pageSize, | 69 | public PageData<LwM2mObject> getLwm2mListObjects(@RequestParam int pageSize, |
69 | @RequestParam int page, | 70 | @RequestParam int page, |
70 | - @RequestParam(required = false) String textSearch, | 71 | + @RequestParam(required = false) String searchText, |
71 | @RequestParam(required = false) String sortProperty, | 72 | @RequestParam(required = false) String sortProperty, |
72 | @RequestParam(required = false) String sortOrder) throws ThingsboardException { | 73 | @RequestParam(required = false) String sortOrder) throws ThingsboardException { |
73 | try { | 74 | try { |
74 | - PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder); | 75 | + PageLink pageLink = createPageLink(pageSize, page, searchText, sortProperty, sortOrder); |
75 | return checkNotNull(lwM2MModelsRepository.findDeviceLwm2mObjects(getTenantId(), pageLink)); | 76 | return checkNotNull(lwM2MModelsRepository.findDeviceLwm2mObjects(getTenantId(), pageLink)); |
76 | } catch (Exception e) { | 77 | } catch (Exception e) { |
77 | throw handleException(e); | 78 | throw handleException(e); |
@@ -81,10 +81,14 @@ public class LwM2MModelsRepository { | @@ -81,10 +81,14 @@ public class LwM2MModelsRepository { | ||
81 | * if textSearch is null then it uses AllList from List<ObjectModel>) | 81 | * if textSearch is null then it uses AllList from List<ObjectModel>) |
82 | */ | 82 | */ |
83 | public List<LwM2mObject> getLwm2mObjects(int[] objectIds, String textSearch, String sortProperty, String sortOrder) { | 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 | (textSearch != null && !textSearch.isEmpty()) ? | 92 | (textSearch != null && !textSearch.isEmpty()) ? |
89 | (ObjectModel element) -> element.name.contains(textSearch) : | 93 | (ObjectModel element) -> element.name.contains(textSearch) : |
90 | null, | 94 | null, |
@@ -165,7 +169,10 @@ public class LwM2MModelsRepository { | @@ -165,7 +169,10 @@ public class LwM2MModelsRepository { | ||
165 | * PageNumber = 1, PageSize = List<LwM2mObject>.size() | 169 | * PageNumber = 1, PageSize = List<LwM2mObject>.size() |
166 | */ | 170 | */ |
167 | public PageData<LwM2mObject> findLwm2mListObjects(PageLink pageLink) { | 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 | PageData pageData = new PageData(page.getContent(), page.getTotalPages(), page.getTotalElements(), page.hasNext()); | 176 | PageData pageData = new PageData(page.getContent(), page.getTotalPages(), page.getTotalElements(), page.hasNext()); |
170 | return pageData; | 177 | return pageData; |
171 | } | 178 | } |
@@ -21,7 +21,7 @@ import { defaultHttpOptionsFromConfig, RequestConfig } from './http-utils'; | @@ -21,7 +21,7 @@ import { defaultHttpOptionsFromConfig, RequestConfig } from './http-utils'; | ||
21 | import { Observable } from 'rxjs'; | 21 | import { Observable } from 'rxjs'; |
22 | import { PageData } from '@shared/models/page/page-data'; | 22 | import { PageData } from '@shared/models/page/page-data'; |
23 | import { DeviceProfile, DeviceProfileInfo, DeviceTransportType } from '@shared/models/device.models'; | 23 | import { DeviceProfile, DeviceProfileInfo, DeviceTransportType } from '@shared/models/device.models'; |
24 | -import { isDefinedAndNotNull } from '@core/utils'; | 24 | +import { isDefinedAndNotNull, isEmptyStr } from '@core/utils'; |
25 | import { ObjectLwM2M, ServerSecurityConfig } from '@home/components/profile/device/lwm2m/profile-config.models'; | 25 | import { ObjectLwM2M, ServerSecurityConfig } from '@home/components/profile/device/lwm2m/profile-config.models'; |
26 | import { SortOrder } from '@shared/models/page/sort-order'; | 26 | import { SortOrder } from '@shared/models/page/sort-order'; |
27 | 27 | ||
@@ -43,14 +43,14 @@ export class DeviceProfileService { | @@ -43,14 +43,14 @@ export class DeviceProfileService { | ||
43 | return this.http.get<DeviceProfile>(`/api/deviceProfile/${deviceProfileId}`, defaultHttpOptionsFromConfig(config)); | 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 | Observable<Array<ObjectLwM2M>> { | 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 | return this.http.get<Array<ObjectLwM2M>>(url, defaultHttpOptionsFromConfig(config)); | 55 | return this.http.get<Array<ObjectLwM2M>>(url, defaultHttpOptionsFromConfig(config)); |
56 | } | 56 | } |
@@ -74,7 +74,8 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro | @@ -74,7 +74,8 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro | ||
74 | this.requiredValue = coerceBooleanProperty(value); | 74 | this.requiredValue = coerceBooleanProperty(value); |
75 | } | 75 | } |
76 | 76 | ||
77 | - private propagateChange = (v: any) => { }; | 77 | + private propagateChange = (v: any) => { |
78 | + }; | ||
78 | 79 | ||
79 | constructor(private store: Store<AppState>, | 80 | constructor(private store: Store<AppState>, |
80 | private fb: FormBuilder, | 81 | private fb: FormBuilder, |
@@ -130,8 +131,8 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro | @@ -130,8 +131,8 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro | ||
130 | writeValue(value: any | null): void { | 131 | writeValue(value: any | null): void { |
131 | this.configurationValue = (Object.keys(value).length === 0) ? getDefaultProfileConfig() : value; | 132 | this.configurationValue = (Object.keys(value).length === 0) ? getDefaultProfileConfig() : value; |
132 | this.lwm2mDeviceConfigFormGroup.patchValue({ | 133 | this.lwm2mDeviceConfigFormGroup.patchValue({ |
133 | - configurationJson: this.configurationValue | ||
134 | - }, {emitEvent: false}); | 134 | + configurationJson: this.configurationValue |
135 | + }, {emitEvent: false}); | ||
135 | this.initWriteValue(); | 136 | this.initWriteValue(); |
136 | } | 137 | } |
137 | 138 | ||
@@ -143,7 +144,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro | @@ -143,7 +144,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro | ||
143 | property: 'id', | 144 | property: 'id', |
144 | direction: Direction.ASC | 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 | (objectsList) => { | 148 | (objectsList) => { |
148 | modelValue.objectsList = objectsList; | 149 | modelValue.objectsList = objectsList; |
149 | this.updateWriteValue(modelValue); | 150 | this.updateWriteValue(modelValue); |
@@ -300,9 +301,9 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro | @@ -300,9 +301,9 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro | ||
300 | 301 | ||
301 | private addInstances = (attribute: string[], telemetry: string[], clientObserveAttrTelemetry: ObjectLwM2M[]): void => { | 302 | private addInstances = (attribute: string[], telemetry: string[], clientObserveAttrTelemetry: ObjectLwM2M[]): void => { |
302 | const instancesPath = attribute.concat(telemetry) | 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 | new Set(instancesPath).forEach(path => { | 308 | new Set(instancesPath).forEach(path => { |
308 | const pathParameter = Array.from(path.split('/'), Number); | 309 | const pathParameter = Array.from(path.split('/'), Number); |
@@ -19,12 +19,11 @@ import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR, Valida | @@ -19,12 +19,11 @@ import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR, Valida | ||
19 | import { coerceBooleanProperty } from '@angular/cdk/coercion'; | 19 | import { coerceBooleanProperty } from '@angular/cdk/coercion'; |
20 | import { Store } from '@ngrx/store'; | 20 | import { Store } from '@ngrx/store'; |
21 | import { AppState } from '@core/core.state'; | 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 | import { ObjectLwM2M } from './profile-config.models'; | 24 | import { ObjectLwM2M } from './profile-config.models'; |
25 | import { TranslateService } from '@ngx-translate/core'; | 25 | import { TranslateService } from '@ngx-translate/core'; |
26 | import { DeviceProfileService } from '@core/http/device-profile.service'; | 26 | import { DeviceProfileService } from '@core/http/device-profile.service'; |
27 | -import { PageLink } from '@shared/models/page/page-link'; | ||
28 | import { Direction } from '@shared/models/page/sort-order'; | 27 | import { Direction } from '@shared/models/page/sort-order'; |
29 | 28 | ||
30 | @Component({ | 29 | @Component({ |
@@ -115,6 +114,7 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V | @@ -115,6 +114,7 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V | ||
115 | this.disabled = isDisabled; | 114 | this.disabled = isDisabled; |
116 | if (isDisabled) { | 115 | if (isDisabled) { |
117 | this.lwm2mListFormGroup.disable({emitEvent: false}); | 116 | this.lwm2mListFormGroup.disable({emitEvent: false}); |
117 | + this.clear(); | ||
118 | } else { | 118 | } else { |
119 | this.lwm2mListFormGroup.enable({emitEvent: false}); | 119 | this.lwm2mListFormGroup.enable({emitEvent: false}); |
120 | } | 120 | } |
@@ -168,16 +168,14 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V | @@ -168,16 +168,14 @@ export class Lwm2mObjectListComponent implements ControlValueAccessor, OnInit, V | ||
168 | return object ? object.name : undefined; | 168 | return object ? object.name : undefined; |
169 | } | 169 | } |
170 | 170 | ||
171 | - // @TODO: add support page size | ||
172 | - // @TODO: filter for id + name | ||
173 | private fetchListObjects = (searchText?: string): Observable<Array<ObjectLwM2M>> => { | 171 | private fetchListObjects = (searchText?: string): Observable<Array<ObjectLwM2M>> => { |
174 | this.searchText = searchText; | 172 | this.searchText = searchText; |
175 | - const pageLink = new PageLink(50, 0, searchText, { | 173 | + const sortOrder = { |
176 | property: 'name', | 174 | property: 'name', |
177 | direction: Direction.ASC | 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 |