Commit ec2e097229d9f86122141aa18bba0b94dfb16b6d
Committed by
Andrew Shvayka
1 parent
90c84f84
UI: Add parse persistent RPC status for send RPC command
Showing
3 changed files
with
18 additions
and
29 deletions
@@ -69,27 +69,11 @@ public class RpcV2Controller extends AbstractRpcController { | @@ -69,27 +69,11 @@ public class RpcV2Controller extends AbstractRpcController { | ||
69 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") | 69 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") |
70 | @RequestMapping(value = "/persistent/{rpcId}", method = RequestMethod.GET) | 70 | @RequestMapping(value = "/persistent/{rpcId}", method = RequestMethod.GET) |
71 | @ResponseBody | 71 | @ResponseBody |
72 | - public ResponseEntity<Rpc> getPersistedRpc(@PathVariable("rpcId") String strRpc) throws ThingsboardException { | 72 | + public Rpc getPersistedRpc(@PathVariable("rpcId") String strRpc) throws ThingsboardException { |
73 | checkParameter("RpcId", strRpc); | 73 | checkParameter("RpcId", strRpc); |
74 | try { | 74 | try { |
75 | RpcId rpcId = new RpcId(UUID.fromString(strRpc)); | 75 | RpcId rpcId = new RpcId(UUID.fromString(strRpc)); |
76 | - Rpc rpc = checkRpcId(rpcId, Operation.READ); | ||
77 | - HttpStatus status; | ||
78 | - switch (rpc.getStatus()) { | ||
79 | - case FAILED: | ||
80 | - status = HttpStatus.BAD_GATEWAY; | ||
81 | - break; | ||
82 | - case TIMEOUT: | ||
83 | - status = HttpStatus.GATEWAY_TIMEOUT; | ||
84 | - break; | ||
85 | - case QUEUED: | ||
86 | - case DELIVERED: | ||
87 | - status = HttpStatus.ACCEPTED; | ||
88 | - break; | ||
89 | - default: | ||
90 | - status = HttpStatus.OK; | ||
91 | - } | ||
92 | - return new ResponseEntity<>(rpc, status); | 76 | + return checkRpcId(rpcId, Operation.READ); |
93 | } catch (Exception e) { | 77 | } catch (Exception e) { |
94 | throw handleException(e); | 78 | throw handleException(e); |
95 | } | 79 | } |
@@ -35,7 +35,7 @@ import { | @@ -35,7 +35,7 @@ import { | ||
35 | LegendKeyData, | 35 | LegendKeyData, |
36 | widgetType | 36 | widgetType |
37 | } from '@app/shared/models/widget.models'; | 37 | } from '@app/shared/models/widget.models'; |
38 | -import { HttpErrorResponse, HttpResponse } from '@angular/common/http'; | 38 | +import { HttpErrorResponse } from '@angular/common/http'; |
39 | import { | 39 | import { |
40 | calculateIntervalStartEndTime, | 40 | calculateIntervalStartEndTime, |
41 | calculateTsOffset, | 41 | calculateTsOffset, |
@@ -69,7 +69,7 @@ import { | @@ -69,7 +69,7 @@ import { | ||
69 | } from '@shared/models/query/query.models'; | 69 | } from '@shared/models/query/query.models'; |
70 | import { filter, map, switchMap, takeUntil } from 'rxjs/operators'; | 70 | import { filter, map, switchMap, takeUntil } from 'rxjs/operators'; |
71 | import { AlarmDataListener } from '@core/api/alarm-data.service'; | 71 | import { AlarmDataListener } from '@core/api/alarm-data.service'; |
72 | -import { PersistentRpc } from '@shared/models/rpc.models'; | 72 | +import { RpcStatus } from '@shared/models/rpc.models'; |
73 | 73 | ||
74 | const moment = moment_; | 74 | const moment = moment_; |
75 | 75 | ||
@@ -710,8 +710,17 @@ export class WidgetSubscription implements IWidgetSubscription { | @@ -710,8 +710,17 @@ export class WidgetSubscription implements IWidgetSubscription { | ||
710 | if (persistent && persistentPollingInterval > 0) { | 710 | if (persistent && persistentPollingInterval > 0) { |
711 | return timer(persistentPollingInterval / 2, persistentPollingInterval).pipe( | 711 | return timer(persistentPollingInterval / 2, persistentPollingInterval).pipe( |
712 | switchMap(() => this.ctx.deviceService.getPersistedRpc(response.rpcId, true)), | 712 | switchMap(() => this.ctx.deviceService.getPersistedRpc(response.rpcId, true)), |
713 | - filter((persistentResponse: HttpResponse<PersistentRpc>) => persistentResponse.status !== 202), | ||
714 | - map(persistentResponse => persistentResponse.body.response), | 713 | + filter(persistentRespons => |
714 | + persistentRespons.status !== RpcStatus.DELIVERED && persistentRespons.status !== RpcStatus.QUEUED), | ||
715 | + switchMap(persistentResponse => { | ||
716 | + if (persistentResponse.status === RpcStatus.TIMEOUT) { | ||
717 | + return throwError({status: 504}); | ||
718 | + } else if (persistentResponse.status === RpcStatus.FAILED) { | ||
719 | + return throwError({status: 502, statusText: persistentResponse.response.error}); | ||
720 | + } else { | ||
721 | + return of(persistentResponse.response); | ||
722 | + } | ||
723 | + }), | ||
715 | takeUntil(rpcSubject) | 724 | takeUntil(rpcSubject) |
716 | ); | 725 | ); |
717 | } | 726 | } |
@@ -17,7 +17,7 @@ | @@ -17,7 +17,7 @@ | ||
17 | import { Injectable } from '@angular/core'; | 17 | import { Injectable } from '@angular/core'; |
18 | import { defaultHttpOptionsFromConfig, RequestConfig } from './http-utils'; | 18 | import { defaultHttpOptionsFromConfig, RequestConfig } from './http-utils'; |
19 | import { Observable, ReplaySubject } from 'rxjs'; | 19 | import { Observable, ReplaySubject } from 'rxjs'; |
20 | -import { HttpClient, HttpResponse } from '@angular/common/http'; | 20 | +import { HttpClient } from '@angular/common/http'; |
21 | import { PageLink } from '@shared/models/page/page-link'; | 21 | import { PageLink } from '@shared/models/page/page-link'; |
22 | import { PageData } from '@shared/models/page/page-data'; | 22 | import { PageData } from '@shared/models/page/page-data'; |
23 | import { | 23 | import { |
@@ -138,12 +138,8 @@ export class DeviceService { | @@ -138,12 +138,8 @@ export class DeviceService { | ||
138 | return this.http.post<Device>(`/api/rpc/twoway/${deviceId}`, requestBody, defaultHttpOptionsFromConfig(config)); | 138 | return this.http.post<Device>(`/api/rpc/twoway/${deviceId}`, requestBody, defaultHttpOptionsFromConfig(config)); |
139 | } | 139 | } |
140 | 140 | ||
141 | - public getPersistedRpc(rpcId: string, fullResponse = false, | ||
142 | - config?: RequestConfig): Observable<PersistentRpc | HttpResponse<PersistentRpc>> { | ||
143 | - return this.http.get<PersistentRpc>(`/api/rpc/persistent/${rpcId}`, { | ||
144 | - ...defaultHttpOptionsFromConfig(config), | ||
145 | - observe: fullResponse ? 'response' : undefined | ||
146 | - }); | 141 | + public getPersistedRpc(rpcId: string, fullResponse = false, config?: RequestConfig): Observable<PersistentRpc> { |
142 | + return this.http.get<PersistentRpc>(`/api/rpc/persistent/${rpcId}`, defaultHttpOptionsFromConfig(config)); | ||
147 | } | 143 | } |
148 | 144 | ||
149 | public findByQuery(query: DeviceSearchQuery, | 145 | public findByQuery(query: DeviceSearchQuery, |