Commit ceadc391f3ec4b738c8721d7e02830667931eba7
1 parent
4c2effd9
Added EdgeInfo, fix for CustomerIsPublic
Showing
14 changed files
with
82 additions
and
34 deletions
... | ... | @@ -50,6 +50,7 @@ import org.thingsboard.server.common.data.asset.Asset; |
50 | 50 | import org.thingsboard.server.common.data.asset.AssetInfo; |
51 | 51 | import org.thingsboard.server.common.data.audit.ActionType; |
52 | 52 | import org.thingsboard.server.common.data.edge.Edge; |
53 | +import org.thingsboard.server.common.data.edge.EdgeInfo; | |
53 | 54 | import org.thingsboard.server.common.data.edge.EdgeEventActionType; |
54 | 55 | import org.thingsboard.server.common.data.edge.EdgeEventType; |
55 | 56 | import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; |
... | ... | @@ -643,6 +644,18 @@ public abstract class BaseController { |
643 | 644 | } |
644 | 645 | } |
645 | 646 | |
647 | + EdgeInfo checkEdgeInfoId(EdgeId edgeId, Operation operation) throws ThingsboardException { | |
648 | + try { | |
649 | + validateId(edgeId, "Incorrect edgeId " + edgeId); | |
650 | + EdgeInfo edge = edgeService.findEdgeInfoById(getCurrentUser().getTenantId(), edgeId); | |
651 | + checkNotNull(edge); | |
652 | + accessControlService.checkPermission(getCurrentUser(), Resource.EDGE, operation, edgeId, edge); | |
653 | + return edge; | |
654 | + } catch (Exception e) { | |
655 | + throw handleException(e, false); | |
656 | + } | |
657 | + } | |
658 | + | |
646 | 659 | DashboardInfo checkDashboardInfoId(DashboardId dashboardId, Operation operation) throws ThingsboardException { |
647 | 660 | try { |
648 | 661 | validateId(dashboardId, "Incorrect dashboardId " + dashboardId); | ... | ... |
... | ... | @@ -36,10 +36,7 @@ import org.thingsboard.server.common.data.edge.EdgeEventActionType; |
36 | 36 | import org.thingsboard.server.common.data.edge.EdgeSearchQuery; |
37 | 37 | import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; |
38 | 38 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
39 | -import org.thingsboard.server.common.data.id.CustomerId; | |
40 | -import org.thingsboard.server.common.data.id.EdgeId; | |
41 | -import org.thingsboard.server.common.data.id.RuleChainId; | |
42 | -import org.thingsboard.server.common.data.id.TenantId; | |
39 | +import org.thingsboard.server.common.data.id.*; | |
43 | 40 | import org.thingsboard.server.common.data.page.PageData; |
44 | 41 | import org.thingsboard.server.common.data.page.PageLink; |
45 | 42 | import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent; |
... | ... | @@ -77,6 +74,19 @@ public class EdgeController extends BaseController { |
77 | 74 | } |
78 | 75 | } |
79 | 76 | |
77 | + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") | |
78 | + @RequestMapping(value = "/edge/info/{edgeId}", method = RequestMethod.GET) | |
79 | + @ResponseBody | |
80 | + public EdgeInfo getEdgeInfoById(@PathVariable(EDGE_ID) String strEdgeId) throws ThingsboardException { | |
81 | + checkParameter(EDGE_ID, strEdgeId); | |
82 | + try { | |
83 | + EdgeId edgeId = new EdgeId(toUUID(strEdgeId)); | |
84 | + return checkEdgeInfoId(edgeId, Operation.READ); | |
85 | + } catch (Exception e) { | |
86 | + throw handleException(e); | |
87 | + } | |
88 | + } | |
89 | + | |
80 | 90 | @PreAuthorize("hasAuthority('TENANT_ADMIN')") |
81 | 91 | @RequestMapping(value = "/edge", method = RequestMethod.POST) |
82 | 92 | @ResponseBody | ... | ... |
... | ... | @@ -20,12 +20,7 @@ import org.thingsboard.server.common.data.EntitySubtype; |
20 | 20 | import org.thingsboard.server.common.data.edge.Edge; |
21 | 21 | import org.thingsboard.server.common.data.edge.EdgeInfo; |
22 | 22 | import org.thingsboard.server.common.data.edge.EdgeSearchQuery; |
23 | -import org.thingsboard.server.common.data.id.CustomerId; | |
24 | -import org.thingsboard.server.common.data.id.DashboardId; | |
25 | -import org.thingsboard.server.common.data.id.EdgeId; | |
26 | -import org.thingsboard.server.common.data.id.EntityId; | |
27 | -import org.thingsboard.server.common.data.id.RuleChainId; | |
28 | -import org.thingsboard.server.common.data.id.TenantId; | |
23 | +import org.thingsboard.server.common.data.id.*; | |
29 | 24 | import org.thingsboard.server.common.data.page.PageData; |
30 | 25 | import org.thingsboard.server.common.data.page.PageLink; |
31 | 26 | |
... | ... | @@ -36,6 +31,8 @@ public interface EdgeService { |
36 | 31 | |
37 | 32 | Edge findEdgeById(TenantId tenantId, EdgeId edgeId); |
38 | 33 | |
34 | + EdgeInfo findEdgeInfoById(TenantId tenantId, EdgeId edgeId); | |
35 | + | |
39 | 36 | ListenableFuture<Edge> findEdgeByIdAsync(TenantId tenantId, EdgeId edgeId); |
40 | 37 | |
41 | 38 | Edge findEdgeByTenantIdAndName(TenantId tenantId, String name); | ... | ... |
... | ... | @@ -34,6 +34,7 @@ import org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileCon |
34 | 34 | import org.thingsboard.server.dao.asset.AssetService; |
35 | 35 | import org.thingsboard.server.dao.dashboard.DashboardService; |
36 | 36 | import org.thingsboard.server.dao.device.DeviceService; |
37 | +import org.thingsboard.server.dao.edge.EdgeService; | |
37 | 38 | import org.thingsboard.server.dao.entity.AbstractEntityService; |
38 | 39 | import org.thingsboard.server.dao.entityview.EntityViewService; |
39 | 40 | import org.thingsboard.server.dao.exception.DataValidationException; |
... | ... | @@ -80,6 +81,9 @@ public class CustomerServiceImpl extends AbstractEntityService implements Custom |
80 | 81 | private DashboardService dashboardService; |
81 | 82 | |
82 | 83 | @Autowired |
84 | + private EdgeService edgeService; | |
85 | + | |
86 | + @Autowired | |
83 | 87 | @Lazy |
84 | 88 | private TbTenantProfileCache tenantProfileCache; |
85 | 89 | ... | ... |
... | ... | @@ -43,6 +43,15 @@ public interface EdgeDao extends Dao<Edge> { |
43 | 43 | Edge save(TenantId tenantId, Edge edge); |
44 | 44 | |
45 | 45 | /** |
46 | + * Find edge info by id. | |
47 | + * | |
48 | + * @param tenantId the tenant id | |
49 | + * @param edgeId the edge id | |
50 | + * @return the edge info object | |
51 | + */ | |
52 | + EdgeInfo findEdgeInfoById(TenantId tenantId, UUID edgeId); | |
53 | + | |
54 | + /** | |
46 | 55 | * Find edges by tenantId and page link. |
47 | 56 | * |
48 | 57 | * @param tenantId the tenantId | ... | ... |
... | ... | @@ -44,14 +44,7 @@ import org.thingsboard.server.common.data.User; |
44 | 44 | import org.thingsboard.server.common.data.edge.Edge; |
45 | 45 | import org.thingsboard.server.common.data.edge.EdgeInfo; |
46 | 46 | import org.thingsboard.server.common.data.edge.EdgeSearchQuery; |
47 | -import org.thingsboard.server.common.data.id.CustomerId; | |
48 | -import org.thingsboard.server.common.data.id.DashboardId; | |
49 | -import org.thingsboard.server.common.data.id.EdgeId; | |
50 | -import org.thingsboard.server.common.data.id.EntityId; | |
51 | -import org.thingsboard.server.common.data.id.IdBased; | |
52 | -import org.thingsboard.server.common.data.id.RuleChainId; | |
53 | -import org.thingsboard.server.common.data.id.TenantId; | |
54 | -import org.thingsboard.server.common.data.id.UserId; | |
47 | +import org.thingsboard.server.common.data.id.*; | |
55 | 48 | import org.thingsboard.server.common.data.page.PageData; |
56 | 49 | import org.thingsboard.server.common.data.page.PageLink; |
57 | 50 | import org.thingsboard.server.common.data.relation.EntityRelation; |
... | ... | @@ -144,6 +137,13 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic |
144 | 137 | } |
145 | 138 | |
146 | 139 | @Override |
140 | + public EdgeInfo findEdgeInfoById(TenantId tenantId, EdgeId edgeId) { | |
141 | + log.trace("Executing findEdgeInfoById [{}]", edgeId); | |
142 | + validateId(edgeId, INCORRECT_EDGE_ID + edgeId); | |
143 | + return edgeDao.findEdgeInfoById(tenantId, edgeId.getId()); | |
144 | + } | |
145 | + | |
146 | + @Override | |
147 | 147 | public ListenableFuture<Edge> findEdgeByIdAsync(TenantId tenantId, EdgeId edgeId) { |
148 | 148 | log.trace("Executing findEdgeById [{}]", edgeId); |
149 | 149 | validateId(edgeId, INCORRECT_EDGE_ID + edgeId); | ... | ... |
... | ... | @@ -36,6 +36,12 @@ public interface EdgeRepository extends PagingAndSortingRepository<EdgeEntity, U |
36 | 36 | @Param("textSearch") String textSearch, |
37 | 37 | Pageable pageable); |
38 | 38 | |
39 | + @Query("SELECT new org.thingsboard.server.dao.model.sql.EdgeInfoEntity(d, c.title, c.additionalInfo) " + | |
40 | + "FROM EdgeEntity d " + | |
41 | + "LEFT JOIN CustomerEntity c on c.id = d.customerId " + | |
42 | + "WHERE d.id = :edgeId") | |
43 | + EdgeInfoEntity findEdgeInfoById(@Param("edgeId") UUID edgeId); | |
44 | + | |
39 | 45 | @Query("SELECT d FROM EdgeEntity d WHERE d.tenantId = :tenantId " + |
40 | 46 | "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") |
41 | 47 | Page<EdgeEntity> findByTenantId(@Param("tenantId") UUID tenantId, | ... | ... |
... | ... | @@ -68,6 +68,11 @@ public class JpaEdgeDao extends JpaAbstractSearchTextDao<EdgeEntity, Edge> imple |
68 | 68 | } |
69 | 69 | |
70 | 70 | @Override |
71 | + public EdgeInfo findEdgeInfoById(TenantId tenantId, UUID edgeId) { | |
72 | + return DaoUtil.getData(edgeRepository.findEdgeInfoById(edgeId)); | |
73 | + } | |
74 | + | |
75 | + @Override | |
71 | 76 | public PageData<Edge> findEdgesByTenantId(UUID tenantId, PageLink pageLink) { |
72 | 77 | return DaoUtil.toPageData( |
73 | 78 | edgeRepository.findByTenantId( | ... | ... |
... | ... | @@ -14,8 +14,8 @@ |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 | |
17 | -const forwardUrl = "http://localhost:8081"; | |
18 | -const wsForwardUrl = "ws://localhost:8081"; | |
17 | +const forwardUrl = "http://localhost:8080"; | |
18 | +const wsForwardUrl = "ws://localhost:8080"; | |
19 | 19 | const ruleNodeUiforwardUrl = forwardUrl; |
20 | 20 | |
21 | 21 | const PROXY_CONFIG = { | ... | ... |
... | ... | @@ -38,8 +38,12 @@ export class EdgeService { |
38 | 38 | defaultHttpOptionsFromConfig(config)); |
39 | 39 | } |
40 | 40 | |
41 | - public getEdge(edgeId: string, config?: RequestConfig): Observable<EdgeInfo> { | |
42 | - return this.http.get<EdgeInfo>(`/api/edge/${edgeId}`, defaultHttpOptionsFromConfig(config)); | |
41 | + public getEdge(edgeId: string, config?: RequestConfig): Observable<Edge> { | |
42 | + return this.http.get<Edge>(`/api/edge/${edgeId}`, defaultHttpOptionsFromConfig(config)); | |
43 | + } | |
44 | + | |
45 | + public getEdgeInfo(edgeId: string, config?: RequestConfig): Observable<EdgeInfo> { | |
46 | + return this.http.get<EdgeInfo>(`/api/edge/info/${edgeId}`, defaultHttpOptionsFromConfig(config)); | |
43 | 47 | } |
44 | 48 | |
45 | 49 | public saveEdge(edge: Edge, config?: RequestConfig): Observable<Edge> { |
... | ... | @@ -72,7 +76,7 @@ export class EdgeService { |
72 | 76 | } |
73 | 77 | |
74 | 78 | public makeEdgePublic(edgeId: string, config?: RequestConfig): Observable<Edge> { |
75 | - return this.http.post<Edge>(`/api/customer/public/edge/${edgeId}`, | |
79 | + return this.http.post<Edge>(`/api/customer/public/edge/${edgeId}`, null, | |
76 | 80 | defaultHttpOptionsFromConfig(config)); |
77 | 81 | } |
78 | 82 | ... | ... |
... | ... | @@ -415,7 +415,7 @@ export class ImportExportService { |
415 | 415 | this.store.dispatch(new ActionNotificationShow( |
416 | 416 | {message: this.translate.instant('rulechain.invalid-rulechain-type-error', { expectedRuleChainType: expectedRuleChainType }), |
417 | 417 | type: 'error'})); |
418 | - throw new Error('Invalid rule chain file'); | |
418 | + throw new Error('Invalid rule chain type'); | |
419 | 419 | } else { |
420 | 420 | return this.ruleChainService.resolveRuleChainMetadata(ruleChainImport.metadata).pipe( |
421 | 421 | map((resolvedMetadata) => { | ... | ... |
... | ... | @@ -27,9 +27,9 @@ import { RuleChainsTableConfigResolver } from "@home/pages/rulechain/rulechains- |
27 | 27 | import { DashboardPageComponent } from "@home/pages/dashboard/dashboard-page.component"; |
28 | 28 | import { dashboardBreadcumbLabelFunction, DashboardResolver } from "@home/pages/dashboard/dashboard-routing.module"; |
29 | 29 | import { BreadCrumbConfig } from "@shared/components/breadcrumb"; |
30 | -import {RuleChainPageComponent} from "@home/pages/rulechain/rulechain-page.component"; | |
31 | -import {ConfirmOnExitGuard} from "@core/guards/confirm-on-exit.guard"; | |
32 | -import {ruleChainType} from "@shared/models/rule-chain.models"; | |
30 | +import { RuleChainPageComponent } from "@home/pages/rulechain/rulechain-page.component"; | |
31 | +import { ConfirmOnExitGuard } from "@core/guards/confirm-on-exit.guard"; | |
32 | +import { ruleChainType } from "@shared/models/rule-chain.models"; | |
33 | 33 | import { |
34 | 34 | importRuleChainBreadcumbLabelFunction, |
35 | 35 | ResolvedRuleChainMetaDataResolver, | ... | ... |
... | ... | @@ -86,13 +86,13 @@ export class EdgesTableConfigResolver implements Resolve<EntityTableConfig<EdgeI |
86 | 86 | this.config.deleteEntitiesTitle = count => this.translate.instant('edge.delete-edges-title', {count}); |
87 | 87 | this.config.deleteEntitiesContent = () => this.translate.instant('edge.delete-edges-text'); |
88 | 88 | |
89 | - this.config.loadEntity = id => this.edgeService.getEdge(id.id); | |
89 | + this.config.loadEntity = id => this.edgeService.getEdgeInfo(id.id); | |
90 | 90 | this.config.saveEntity = edge => { |
91 | 91 | return this.edgeService.saveEdge(edge).pipe( |
92 | 92 | tap(() => { |
93 | 93 | this.broadcast.broadcast('edgeSaved'); |
94 | 94 | }), |
95 | - mergeMap((savedEdge) => this.edgeService.getEdge(savedEdge.id.id) | |
95 | + mergeMap((savedEdge) => this.edgeService.getEdgeInfo(savedEdge.id.id) | |
96 | 96 | )); |
97 | 97 | }; |
98 | 98 | this.config.onEntityAction = action => this.onEdgeAction(action); | ... | ... |
... | ... | @@ -45,7 +45,7 @@ import { |
45 | 45 | AddEntitiesToEdgeDialogData |
46 | 46 | } from "@home/dialogs/add-entities-to-edge-dialog.component"; |
47 | 47 | import {MatDialog} from "@angular/material/dialog"; |
48 | -import {isDefined, isUndefined} from "@core/utils"; | |
48 | +import {isUndefined} from "@core/utils"; | |
49 | 49 | import {PageLink} from "@shared/models/page/page-link"; |
50 | 50 | import {Edge} from "@shared/models/edge.models"; |
51 | 51 | |
... | ... | @@ -490,17 +490,17 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig< |
490 | 490 | |
491 | 491 | isNonRootRuleChain(ruleChain: RuleChain) { |
492 | 492 | if (this.config.componentsData.ruleChainScope === 'edge') { |
493 | - return (isDefined(this.config.componentsData.edge.rootRuleChainId) && this.config.componentsData.edge.rootRuleChainId != null && this.config.componentsData.edge.rootRuleChainId.id != ruleChain.id.id); | |
493 | + return this.config.componentsData.edge.rootRuleChainId && true && this.config.componentsData.edge.rootRuleChainId.id != ruleChain.id.id; | |
494 | 494 | } |
495 | - return (isDefined(ruleChain)) && !ruleChain.root; | |
495 | + return !ruleChain.root; | |
496 | 496 | } |
497 | 497 | |
498 | 498 | isDefaultEdgeRuleChain(ruleChain) { |
499 | - return (isDefined(ruleChain)) && !ruleChain.root && this.config.componentsData.defaultEdgeRuleChainIds.includes(ruleChain.id.id); | |
499 | + return !ruleChain.root && this.config.componentsData.defaultEdgeRuleChainIds.includes(ruleChain.id.id); | |
500 | 500 | } |
501 | 501 | |
502 | 502 | isNonDefaultEdgeRuleChain(ruleChain) { |
503 | - return (isDefined(ruleChain)) && !ruleChain.root && !this.config.componentsData.defaultEdgeRuleChainIds.includes(ruleChain.id.id); | |
503 | + return !ruleChain.root && !this.config.componentsData.defaultEdgeRuleChainIds.includes(ruleChain.id.id); | |
504 | 504 | } |
505 | 505 | |
506 | 506 | fetchRuleChains(pageLink: PageLink) { | ... | ... |