refactoring: EntityViewController comments4 - saveEntityView from controller
This commit is contained in:
parent
d3a5597b51
commit
d58eb37cb8
@ -202,8 +202,7 @@ public class EntityViewController extends BaseController {
|
|||||||
EntityViewId entityViewId = new EntityViewId(toUUID(strEntityViewId));
|
EntityViewId entityViewId = new EntityViewId(toUUID(strEntityViewId));
|
||||||
checkEntityViewId(entityViewId, Operation.ASSIGN_TO_CUSTOMER);
|
checkEntityViewId(entityViewId, Operation.ASSIGN_TO_CUSTOMER);
|
||||||
|
|
||||||
EntityView savedEntityView = checkNotNull(entityViewService.assignEntityViewToCustomer(getTenantId(), entityViewId, customerId));
|
return tbEntityViewService.assignEntityViewToCustomer(getTenantId(), entityViewId, customer, getCurrentUser());
|
||||||
return tbEntityViewService.assignEntityViewToCustomer(getTenantId(), savedEntityView, customer, getCurrentUser());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "Unassign Entity View from customer (unassignEntityViewFromCustomer)",
|
@ApiOperation(value = "Unassign Entity View from customer (unassignEntityViewFromCustomer)",
|
||||||
@ -222,8 +221,8 @@ public class EntityViewController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Customer customer = checkCustomerId(entityView.getCustomerId(), Operation.READ);
|
Customer customer = checkCustomerId(entityView.getCustomerId(), Operation.READ);
|
||||||
EntityView savedEntityView = checkNotNull(entityViewService.unassignEntityViewFromCustomer(getTenantId(), entityView.getId()));
|
|
||||||
return tbEntityViewService.unassignEntityViewFromCustomer(getTenantId(), savedEntityView, customer, getCurrentUser());
|
return tbEntityViewService.unassignEntityViewFromCustomer(getTenantId(), entityViewId, customer, getCurrentUser());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "Get Customer Entity Views (getCustomerEntityViews)",
|
@ApiOperation(value = "Get Customer Entity Views (getCustomerEntityViews)",
|
||||||
@ -425,11 +424,11 @@ public class EntityViewController extends BaseController {
|
|||||||
checkParameter(ENTITY_VIEW_ID, strEntityViewId);
|
checkParameter(ENTITY_VIEW_ID, strEntityViewId);
|
||||||
EntityViewId entityViewId = new EntityViewId(toUUID(strEntityViewId));
|
EntityViewId entityViewId = new EntityViewId(toUUID(strEntityViewId));
|
||||||
checkEntityViewId(entityViewId, Operation.ASSIGN_TO_CUSTOMER);
|
checkEntityViewId(entityViewId, Operation.ASSIGN_TO_CUSTOMER);
|
||||||
|
|
||||||
Customer publicCustomer = customerService.findOrCreatePublicCustomer(getTenantId());
|
Customer publicCustomer = customerService.findOrCreatePublicCustomer(getTenantId());
|
||||||
EntityView savedEntityView = checkNotNull(entityViewService.assignEntityViewToCustomer(getTenantId(),
|
|
||||||
entityViewId, publicCustomer.getId()));
|
|
||||||
return tbEntityViewService.assignEntityViewToPublicCustomer(getTenantId(), getCurrentUser().getCustomerId(),
|
return tbEntityViewService.assignEntityViewToPublicCustomer(getTenantId(), getCurrentUser().getCustomerId(),
|
||||||
publicCustomer, savedEntityView, getCurrentUser());
|
publicCustomer, entityViewId, getCurrentUser());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "Assign entity view to edge (assignEntityViewToEdge)",
|
@ApiOperation(value = "Assign entity view to edge (assignEntityViewToEdge)",
|
||||||
@ -452,8 +451,8 @@ public class EntityViewController extends BaseController {
|
|||||||
|
|
||||||
EntityViewId entityViewId = new EntityViewId(toUUID(strEntityViewId));
|
EntityViewId entityViewId = new EntityViewId(toUUID(strEntityViewId));
|
||||||
checkEntityViewId(entityViewId, Operation.READ);
|
checkEntityViewId(entityViewId, Operation.READ);
|
||||||
EntityView savedEntityView = checkNotNull(entityViewService.assignEntityViewToEdge(getTenantId(), entityViewId, edgeId));
|
|
||||||
return tbEntityViewService.assignEntityViewToEdge(getTenantId(), getCurrentUser().getCustomerId(), savedEntityView, edge, getCurrentUser());
|
return tbEntityViewService.assignEntityViewToEdge(getTenantId(), getCurrentUser().getCustomerId(), entityViewId, edge, getCurrentUser());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "Unassign entity view from edge (unassignEntityViewFromEdge)",
|
@ApiOperation(value = "Unassign entity view from edge (unassignEntityViewFromEdge)",
|
||||||
@ -477,9 +476,7 @@ public class EntityViewController extends BaseController {
|
|||||||
EntityViewId entityViewId = new EntityViewId(toUUID(strEntityViewId));
|
EntityViewId entityViewId = new EntityViewId(toUUID(strEntityViewId));
|
||||||
EntityView entityView = checkEntityViewId(entityViewId, Operation.READ);
|
EntityView entityView = checkEntityViewId(entityViewId, Operation.READ);
|
||||||
|
|
||||||
EntityView savedEntityView = checkNotNull(entityViewService.unassignEntityViewFromEdge(getTenantId(), entityViewId, edgeId));
|
return tbEntityViewService.unassignEntityViewFromEdge(getTenantId(), entityView.getCustomerId(), entityView, edge, getCurrentUser());
|
||||||
|
|
||||||
return tbEntityViewService.unassignEntityViewFromEdge(getTenantId(), entityView.getCustomerId(), entityView, savedEntityView, edge, getCurrentUser());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
||||||
|
|||||||
@ -121,13 +121,12 @@ public class DefaultTbEntityViewService extends AbstractTbEntityService implemen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntityView assignEntityViewToCustomer(TenantId tenantId, EntityView savedEntityView, Customer customer, SecurityUser user) throws ThingsboardException {
|
public EntityView assignEntityViewToCustomer(TenantId tenantId, EntityViewId entityViewId, Customer customer, SecurityUser user) throws ThingsboardException {
|
||||||
ActionType actionType = ActionType.ASSIGNED_TO_CUSTOMER;
|
ActionType actionType = ActionType.ASSIGNED_TO_CUSTOMER;
|
||||||
CustomerId customerId = customer.getId();
|
CustomerId customerId = customer.getId();
|
||||||
EntityViewId entityViewId = savedEntityView.getId();
|
|
||||||
try {
|
try {
|
||||||
|
EntityView savedEntityView = checkNotNull(entityViewService.assignEntityViewToCustomer(tenantId, entityViewId, customerId));
|
||||||
notificationEntityService.notifyAssignOrUnassignEntityToCustomer(tenantId, entityViewId, customerId, savedEntityView,
|
notificationEntityService.notifyAssignOrUnassignEntityToCustomer(tenantId, entityViewId, customerId, savedEntityView,
|
||||||
actionType, EdgeEventActionType.ASSIGNED_TO_CUSTOMER, user, true, customerId.toString(), customer.getName());
|
actionType, EdgeEventActionType.ASSIGNED_TO_CUSTOMER, user, true, customerId.toString(), customer.getName());
|
||||||
return savedEntityView;
|
return savedEntityView;
|
||||||
@ -140,10 +139,11 @@ public class DefaultTbEntityViewService extends AbstractTbEntityService implemen
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntityView assignEntityViewToPublicCustomer(TenantId tenantId, CustomerId customerId, Customer publicCustomer,
|
public EntityView assignEntityViewToPublicCustomer(TenantId tenantId, CustomerId customerId, Customer publicCustomer,
|
||||||
EntityView savedEntityView, SecurityUser user) throws ThingsboardException {
|
EntityViewId entityViewId, SecurityUser user) throws ThingsboardException {
|
||||||
ActionType actionType = ActionType.ASSIGNED_TO_CUSTOMER;
|
ActionType actionType = ActionType.ASSIGNED_TO_CUSTOMER;
|
||||||
EntityViewId entityViewId = savedEntityView.getId();
|
|
||||||
try {
|
try {
|
||||||
|
EntityView savedEntityView = checkNotNull(entityViewService.assignEntityViewToCustomer(tenantId,
|
||||||
|
entityViewId, publicCustomer.getId()));
|
||||||
notificationEntityService.notifyAssignOrUnassignEntityToCustomer(tenantId, entityViewId, customerId, savedEntityView,
|
notificationEntityService.notifyAssignOrUnassignEntityToCustomer(tenantId, entityViewId, customerId, savedEntityView,
|
||||||
actionType, null, user, false, savedEntityView.getEntityId().toString(),
|
actionType, null, user, false, savedEntityView.getEntityId().toString(),
|
||||||
publicCustomer.getId().toString(), publicCustomer.getName());
|
publicCustomer.getId().toString(), publicCustomer.getName());
|
||||||
@ -156,10 +156,10 @@ public class DefaultTbEntityViewService extends AbstractTbEntityService implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntityView assignEntityViewToEdge(TenantId tenantId, CustomerId customerId, EntityView savedEntityView, Edge edge, SecurityUser user) throws ThingsboardException {
|
public EntityView assignEntityViewToEdge(TenantId tenantId, CustomerId customerId, EntityViewId entityViewId, Edge edge, SecurityUser user) throws ThingsboardException {
|
||||||
ActionType actionType = ActionType.ASSIGNED_TO_EDGE;
|
ActionType actionType = ActionType.ASSIGNED_TO_EDGE;
|
||||||
EdgeId edgeId = edge.getId();
|
EdgeId edgeId = edge.getId();
|
||||||
EntityViewId entityViewId = savedEntityView.getId();
|
EntityView savedEntityView = checkNotNull(entityViewService.assignEntityViewToEdge(tenantId, entityViewId, edgeId));
|
||||||
try {
|
try {
|
||||||
notificationEntityService.notifyAssignOrUnassignEntityToEdge(tenantId, entityViewId, customerId,
|
notificationEntityService.notifyAssignOrUnassignEntityToEdge(tenantId, entityViewId, customerId,
|
||||||
edgeId, savedEntityView, actionType, EdgeEventActionType.ASSIGNED_TO_EDGE, user, savedEntityView.getEntityId().toString(),
|
edgeId, savedEntityView, actionType, EdgeEventActionType.ASSIGNED_TO_EDGE, user, savedEntityView.getEntityId().toString(),
|
||||||
@ -174,11 +174,12 @@ public class DefaultTbEntityViewService extends AbstractTbEntityService implemen
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntityView unassignEntityViewFromEdge(TenantId tenantId, CustomerId customerId, EntityView entityView,
|
public EntityView unassignEntityViewFromEdge(TenantId tenantId, CustomerId customerId, EntityView entityView,
|
||||||
EntityView savedEntityView, Edge edge, SecurityUser user) throws ThingsboardException {
|
Edge edge, SecurityUser user) throws ThingsboardException {
|
||||||
ActionType actionType = ActionType.UNASSIGNED_FROM_EDGE;
|
ActionType actionType = ActionType.UNASSIGNED_FROM_EDGE;
|
||||||
EntityViewId entityViewId = entityView.getId();
|
EntityViewId entityViewId = entityView.getId();
|
||||||
EdgeId edgeId = edge.getId();
|
EdgeId edgeId = edge.getId();
|
||||||
try {
|
try {
|
||||||
|
EntityView savedEntityView = checkNotNull(entityViewService.unassignEntityViewFromEdge(tenantId, entityViewId, edgeId));
|
||||||
notificationEntityService.notifyAssignOrUnassignEntityToEdge(tenantId, entityViewId, customerId,
|
notificationEntityService.notifyAssignOrUnassignEntityToEdge(tenantId, entityViewId, customerId,
|
||||||
edgeId, entityView, actionType, EdgeEventActionType.UNASSIGNED_FROM_EDGE, user, entityViewId.toString(),
|
edgeId, entityView, actionType, EdgeEventActionType.UNASSIGNED_FROM_EDGE, user, entityViewId.toString(),
|
||||||
edgeId.toString(), edge.getName());
|
edgeId.toString(), edge.getName());
|
||||||
@ -191,10 +192,10 @@ public class DefaultTbEntityViewService extends AbstractTbEntityService implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntityView unassignEntityViewFromCustomer(TenantId tenantId, EntityView savedEntityView, Customer customer, SecurityUser user) throws ThingsboardException {
|
public EntityView unassignEntityViewFromCustomer(TenantId tenantId, EntityViewId entityViewId, Customer customer, SecurityUser user) throws ThingsboardException {
|
||||||
ActionType actionType = ActionType.UNASSIGNED_FROM_CUSTOMER;
|
ActionType actionType = ActionType.UNASSIGNED_FROM_CUSTOMER;
|
||||||
EntityViewId entityViewId = savedEntityView.getId();
|
|
||||||
try {
|
try {
|
||||||
|
EntityView savedEntityView = checkNotNull(entityViewService.unassignEntityViewFromCustomer(tenantId, entityViewId));
|
||||||
notificationEntityService.notifyAssignOrUnassignEntityToCustomer(tenantId, entityViewId, customer.getId(), savedEntityView,
|
notificationEntityService.notifyAssignOrUnassignEntityToCustomer(tenantId, entityViewId, customer.getId(), savedEntityView,
|
||||||
actionType, EdgeEventActionType.UNASSIGNED_FROM_CUSTOMER, user, true, customer.getId().toString(), customer.getName());
|
actionType, EdgeEventActionType.UNASSIGNED_FROM_CUSTOMER, user, true, customer.getId().toString(), customer.getName());
|
||||||
return savedEntityView;
|
return savedEntityView;
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import org.thingsboard.server.common.data.EntityView;
|
|||||||
import org.thingsboard.server.common.data.edge.Edge;
|
import org.thingsboard.server.common.data.edge.Edge;
|
||||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
||||||
import org.thingsboard.server.common.data.id.CustomerId;
|
import org.thingsboard.server.common.data.id.CustomerId;
|
||||||
|
import org.thingsboard.server.common.data.id.EntityViewId;
|
||||||
import org.thingsboard.server.common.data.id.TenantId;
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
import org.thingsboard.server.service.security.model.SecurityUser;
|
import org.thingsboard.server.service.security.model.SecurityUser;
|
||||||
|
|
||||||
@ -29,18 +30,18 @@ public interface TbEntityViewService {
|
|||||||
|
|
||||||
void delete (EntityView entity, SecurityUser user) throws ThingsboardException;
|
void delete (EntityView entity, SecurityUser user) throws ThingsboardException;
|
||||||
|
|
||||||
EntityView assignEntityViewToCustomer(TenantId tenantId, EntityView savedEntityView, Customer customer,
|
EntityView assignEntityViewToCustomer(TenantId tenantId, EntityViewId entityViewId, Customer customer,
|
||||||
SecurityUser user) throws ThingsboardException;
|
SecurityUser user) throws ThingsboardException;
|
||||||
|
|
||||||
EntityView assignEntityViewToPublicCustomer(TenantId tenantId, CustomerId customerId, Customer publicCustomer,
|
EntityView assignEntityViewToPublicCustomer(TenantId tenantId, CustomerId customerId, Customer publicCustomer,
|
||||||
EntityView savedEntityView, SecurityUser user) throws ThingsboardException;
|
EntityViewId entityViewId, SecurityUser user) throws ThingsboardException;
|
||||||
|
|
||||||
EntityView assignEntityViewToEdge(TenantId tenantId, CustomerId customerId, EntityView savedEntityView, Edge edge,
|
EntityView assignEntityViewToEdge(TenantId tenantId, CustomerId customerId, EntityViewId entityViewId, Edge edge,
|
||||||
SecurityUser user) throws ThingsboardException;
|
SecurityUser user) throws ThingsboardException;
|
||||||
|
|
||||||
EntityView unassignEntityViewFromEdge(TenantId tenantId, CustomerId customerId, EntityView entityView,
|
EntityView unassignEntityViewFromEdge(TenantId tenantId, CustomerId customerId, EntityView entityView,
|
||||||
EntityView savedEntityView, Edge edge, SecurityUser user) throws ThingsboardException;
|
Edge edge, SecurityUser user) throws ThingsboardException;
|
||||||
|
|
||||||
EntityView unassignEntityViewFromCustomer(TenantId tenantId, EntityView savedEntityView, Customer customer,
|
EntityView unassignEntityViewFromCustomer(TenantId tenantId, EntityViewId entityViewId, Customer customer,
|
||||||
SecurityUser user) throws ThingsboardException;
|
SecurityUser user) throws ThingsboardException;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user