Commit f880fc2e429113a080eeab1bc54dea609f102739
1 parent
17866a97
Was added method for delete of entity view
Showing
1 changed file
with
31 additions
and
11 deletions
... | ... | @@ -15,18 +15,21 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.controller; |
17 | 17 | |
18 | +import com.google.common.util.concurrent.ListenableFuture; | |
19 | +import org.springframework.http.HttpStatus; | |
18 | 20 | import org.springframework.security.access.prepost.PreAuthorize; |
19 | -import org.springframework.web.bind.annotation.PathVariable; | |
20 | -import org.springframework.web.bind.annotation.RequestBody; | |
21 | -import org.springframework.web.bind.annotation.RequestMapping; | |
22 | -import org.springframework.web.bind.annotation.RequestMethod; | |
23 | -import org.springframework.web.bind.annotation.ResponseBody; | |
24 | -import org.springframework.web.bind.annotation.RestController; | |
21 | +import org.springframework.web.bind.annotation.*; | |
25 | 22 | import org.thingsboard.server.common.data.EntityType; |
26 | 23 | import org.thingsboard.server.common.data.EntityView; |
27 | 24 | import org.thingsboard.server.common.data.audit.ActionType; |
28 | 25 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
26 | +import org.thingsboard.server.common.data.id.CustomerId; | |
29 | 27 | import org.thingsboard.server.common.data.id.EntityViewId; |
28 | +import org.thingsboard.server.common.data.id.TenantId; | |
29 | +import org.thingsboard.server.service.security.model.SecurityUser; | |
30 | + | |
31 | +import java.util.ArrayList; | |
32 | +import java.util.List; | |
30 | 33 | |
31 | 34 | /** |
32 | 35 | * Created by Victor Basanets on 8/28/2017. |
... | ... | @@ -55,24 +58,41 @@ public class EntityViewController extends BaseController { |
55 | 58 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") |
56 | 59 | @RequestMapping(value = "/entity-view", method = RequestMethod.POST) |
57 | 60 | @ResponseBody |
58 | - public EntityView saveEntityView(@RequestBody EntityView entityView) | |
59 | - throws ThingsboardException { | |
60 | - | |
61 | + public EntityView saveEntityView(@RequestBody EntityView entityView) throws ThingsboardException { | |
61 | 62 | try { |
62 | 63 | entityView.setTenantId(getCurrentUser().getTenantId()); |
63 | 64 | EntityView savedEntityView = checkNotNull(entityViewService.saveEntityView(entityView)); |
64 | - | |
65 | 65 | logEntityAction(savedEntityView.getId(), savedEntityView, null, |
66 | 66 | entityView.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null); |
67 | 67 | |
68 | 68 | return savedEntityView; |
69 | 69 | |
70 | 70 | } catch (Exception e) { |
71 | - | |
72 | 71 | logEntityAction(emptyId(EntityType.ENTITY_VIEW), entityView, null, |
73 | 72 | entityView.getId() == null ? ActionType.ADDED : ActionType.UPDATED, e); |
74 | 73 | |
75 | 74 | throw handleException(e); |
76 | 75 | } |
77 | 76 | } |
77 | + | |
78 | + @PreAuthorize("hasAuthority('TENANT_ADMIN')") | |
79 | + @RequestMapping(value = "/entity-view/{entityViewId}", method = RequestMethod.DELETE) | |
80 | + @ResponseStatus(value = HttpStatus.OK) | |
81 | + public void deleteEntityView(@PathVariable(ENTITY_VIEW_ID) String strEntityViewId) throws ThingsboardException { | |
82 | + checkParameter(ENTITY_VIEW_ID, strEntityViewId); | |
83 | + try { | |
84 | + EntityViewId entityViewId = new EntityViewId(toUUID(strEntityViewId)); | |
85 | + EntityView entityView = checkEntityViewId(entityViewId); | |
86 | + entityViewService.deleteEntityView(entityViewId); | |
87 | + | |
88 | + logEntityAction(entityViewId, entityView, entityView.getCustomerId(), | |
89 | + ActionType.DELETED,null, strEntityViewId); | |
90 | + } catch (Exception e) { | |
91 | + logEntityAction(emptyId(EntityType.ENTITY_VIEW), | |
92 | + null, | |
93 | + null, | |
94 | + ActionType.DELETED, e, strEntityViewId); | |
95 | + throw handleException(e); | |
96 | + } | |
97 | + } | |
78 | 98 | } | ... | ... |