Improvements to TbCustomerService
This commit is contained in:
parent
ff1f71b510
commit
23485d43b0
@ -149,10 +149,10 @@ public class CustomerController extends BaseController {
|
||||
@RequestMapping(value = "/customer", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Customer saveCustomer(@ApiParam(value = "A JSON value representing the customer.") @RequestBody Customer customer) throws ThingsboardException {
|
||||
customer.setTenantId(getCurrentUser().getTenantId());
|
||||
checkEntity(customer.getId(), customer, Resource.CUSTOMER);
|
||||
return tbCustomerService.save(customer, getCurrentUser());
|
||||
}
|
||||
customer.setTenantId(getCurrentUser().getTenantId());
|
||||
checkEntity(customer.getId(), customer, Resource.CUSTOMER);
|
||||
return tbCustomerService.save(customer, getCurrentUser());
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Delete Customer (deleteCustomer)",
|
||||
notes = "Deletes the Customer and all customer Users. " +
|
||||
@ -164,27 +164,11 @@ public class CustomerController extends BaseController {
|
||||
public void deleteCustomer(@ApiParam(value = CUSTOMER_ID_PARAM_DESCRIPTION)
|
||||
@PathVariable(CUSTOMER_ID) String strCustomerId) throws ThingsboardException {
|
||||
checkParameter(CUSTOMER_ID, strCustomerId);
|
||||
CustomerId customerId = new CustomerId(toUUID(strCustomerId));
|
||||
Customer customer = checkCustomerId(customerId, Operation.DELETE);
|
||||
try {
|
||||
CustomerId customerId = new CustomerId(toUUID(strCustomerId));
|
||||
Customer customer = checkCustomerId(customerId, Operation.DELETE);
|
||||
|
||||
List<EdgeId> relatedEdgeIds = findRelatedEdgeIds(getTenantId(), customerId);
|
||||
|
||||
customerService.deleteCustomer(getTenantId(), customerId);
|
||||
|
||||
logEntityAction(customerId, customer,
|
||||
customer.getId(),
|
||||
ActionType.DELETED, null, strCustomerId);
|
||||
|
||||
sendDeleteNotificationMsg(getTenantId(), customerId, relatedEdgeIds);
|
||||
tbClusterService.broadcastEntityStateChangeEvent(getTenantId(), customerId, ComponentLifecycleEvent.DELETED);
|
||||
tbCustomerService.delete(customer, getCurrentUser());
|
||||
} catch (Exception e) {
|
||||
|
||||
logEntityAction(emptyId(EntityType.CUSTOMER),
|
||||
null,
|
||||
null,
|
||||
ActionType.DELETED, e, strCustomerId);
|
||||
|
||||
throw handleException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Copyright © 2016-2022 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.service.entitiy;
|
||||
|
||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
||||
import org.thingsboard.server.service.security.model.SecurityUser;
|
||||
|
||||
public interface SimpleTbEntityService<T> {
|
||||
|
||||
T save(T entity, SecurityUser user) throws ThingsboardException;
|
||||
|
||||
}
|
||||
@ -16,16 +16,16 @@
|
||||
package org.thingsboard.server.service.entitiy.alarm;
|
||||
|
||||
import org.thingsboard.server.common.data.alarm.Alarm;
|
||||
import org.thingsboard.server.common.data.asset.Asset;
|
||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
||||
import org.thingsboard.server.service.entitiy.SimpleTbEntityService;
|
||||
import org.thingsboard.server.service.security.model.SecurityUser;
|
||||
|
||||
public interface TbAlarmService {
|
||||
public interface TbAlarmService extends SimpleTbEntityService<Alarm> {
|
||||
|
||||
Alarm save (Alarm alarm, SecurityUser user) throws ThingsboardException;
|
||||
void ack(Alarm alarm, SecurityUser user) throws ThingsboardException;
|
||||
|
||||
void ack (Alarm alarm, SecurityUser user) throws ThingsboardException;
|
||||
void clear(Alarm alarm, SecurityUser user) throws ThingsboardException;
|
||||
|
||||
void clear (Alarm alarm, SecurityUser user) throws ThingsboardException;
|
||||
|
||||
Boolean delete (Alarm alarm, SecurityUser user) throws ThingsboardException;
|
||||
Boolean delete(Alarm alarm, SecurityUser user) throws ThingsboardException;
|
||||
}
|
||||
|
||||
@ -22,10 +22,10 @@ import org.thingsboard.server.common.data.edge.Edge;
|
||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
||||
import org.thingsboard.server.common.data.id.AssetId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.service.entitiy.SimpleTbEntityService;
|
||||
import org.thingsboard.server.service.security.model.SecurityUser;
|
||||
|
||||
public interface TbAssetService {
|
||||
Asset save(Asset asset, SecurityUser user) throws ThingsboardException;
|
||||
public interface TbAssetService extends SimpleTbEntityService<Asset> {
|
||||
|
||||
ListenableFuture<Void> delete(Asset asset, SecurityUser user) throws ThingsboardException;
|
||||
|
||||
|
||||
@ -17,10 +17,11 @@ package org.thingsboard.server.service.entitiy.customer;
|
||||
|
||||
import org.thingsboard.server.common.data.Customer;
|
||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
||||
import org.thingsboard.server.service.entitiy.SimpleTbEntityService;
|
||||
import org.thingsboard.server.service.security.model.SecurityUser;
|
||||
|
||||
public interface TbCustomerService {
|
||||
Customer save (Customer customer, SecurityUser user) throws ThingsboardException;
|
||||
public interface TbCustomerService extends SimpleTbEntityService<Customer> {
|
||||
|
||||
void delete(Customer customer, SecurityUser user) throws ThingsboardException;
|
||||
|
||||
void delete (Customer customer, SecurityUser user) throws ThingsboardException;
|
||||
}
|
||||
|
||||
@ -19,7 +19,9 @@ import org.thingsboard.server.common.data.Tenant;
|
||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
||||
|
||||
public interface TbTenantService {
|
||||
|
||||
Tenant save(Tenant tenant) throws ThingsboardException;
|
||||
|
||||
void delete(Tenant tenant) throws ThingsboardException;
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user