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,18 +15,21 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.controller; | 16 | package org.thingsboard.server.controller; |
17 | 17 | ||
18 | +import com.google.common.util.concurrent.ListenableFuture; | ||
19 | +import org.springframework.http.HttpStatus; | ||
18 | import org.springframework.security.access.prepost.PreAuthorize; | 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 | import org.thingsboard.server.common.data.EntityType; | 22 | import org.thingsboard.server.common.data.EntityType; |
26 | import org.thingsboard.server.common.data.EntityView; | 23 | import org.thingsboard.server.common.data.EntityView; |
27 | import org.thingsboard.server.common.data.audit.ActionType; | 24 | import org.thingsboard.server.common.data.audit.ActionType; |
28 | import org.thingsboard.server.common.data.exception.ThingsboardException; | 25 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
26 | +import org.thingsboard.server.common.data.id.CustomerId; | ||
29 | import org.thingsboard.server.common.data.id.EntityViewId; | 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 | * Created by Victor Basanets on 8/28/2017. | 35 | * Created by Victor Basanets on 8/28/2017. |
@@ -55,24 +58,41 @@ public class EntityViewController extends BaseController { | @@ -55,24 +58,41 @@ public class EntityViewController extends BaseController { | ||
55 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") | 58 | @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") |
56 | @RequestMapping(value = "/entity-view", method = RequestMethod.POST) | 59 | @RequestMapping(value = "/entity-view", method = RequestMethod.POST) |
57 | @ResponseBody | 60 | @ResponseBody |
58 | - public EntityView saveEntityView(@RequestBody EntityView entityView) | ||
59 | - throws ThingsboardException { | ||
60 | - | 61 | + public EntityView saveEntityView(@RequestBody EntityView entityView) throws ThingsboardException { |
61 | try { | 62 | try { |
62 | entityView.setTenantId(getCurrentUser().getTenantId()); | 63 | entityView.setTenantId(getCurrentUser().getTenantId()); |
63 | EntityView savedEntityView = checkNotNull(entityViewService.saveEntityView(entityView)); | 64 | EntityView savedEntityView = checkNotNull(entityViewService.saveEntityView(entityView)); |
64 | - | ||
65 | logEntityAction(savedEntityView.getId(), savedEntityView, null, | 65 | logEntityAction(savedEntityView.getId(), savedEntityView, null, |
66 | entityView.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null); | 66 | entityView.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null); |
67 | 67 | ||
68 | return savedEntityView; | 68 | return savedEntityView; |
69 | 69 | ||
70 | } catch (Exception e) { | 70 | } catch (Exception e) { |
71 | - | ||
72 | logEntityAction(emptyId(EntityType.ENTITY_VIEW), entityView, null, | 71 | logEntityAction(emptyId(EntityType.ENTITY_VIEW), entityView, null, |
73 | entityView.getId() == null ? ActionType.ADDED : ActionType.UPDATED, e); | 72 | entityView.getId() == null ? ActionType.ADDED : ActionType.UPDATED, e); |
74 | 73 | ||
75 | throw handleException(e); | 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 | } |