Added getCustomerEdgeInfos() implementation
This commit is contained in:
parent
c1fe4a5dde
commit
74b150b384
@ -373,6 +373,33 @@ public class EdgeController extends BaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
||||||
|
@RequestMapping(value = "/customer/{customerId}/edgeInfos", params = {"pageSize", "page"}, method = RequestMethod.GET)
|
||||||
|
@ResponseBody
|
||||||
|
public PageData<EdgeInfo> getCustomerEdgeInfos(
|
||||||
|
@PathVariable("customerId") String strCustomerId,
|
||||||
|
@RequestParam int pageSize,
|
||||||
|
@RequestParam int page,
|
||||||
|
@RequestParam(required = false) String type,
|
||||||
|
@RequestParam(required = false) String textSearch,
|
||||||
|
@RequestParam(required = false) String sortProperty,
|
||||||
|
@RequestParam(required = false) String sortOrder) throws ThingsboardException {
|
||||||
|
checkParameter("customerId", strCustomerId);
|
||||||
|
try {
|
||||||
|
TenantId tenantId = getCurrentUser().getTenantId();
|
||||||
|
CustomerId customerId = new CustomerId(toUUID(strCustomerId));
|
||||||
|
checkCustomerId(customerId, Operation.READ);
|
||||||
|
PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder);
|
||||||
|
if (type != null && type.trim().length() > 0) {
|
||||||
|
return checkNotNull(edgeService.findEdgeInfosByTenantIdAndCustomerIdAndType(tenantId, customerId, type, pageLink));
|
||||||
|
} else {
|
||||||
|
return checkNotNull(edgeService.findEdgeInfosByTenantIdAndCustomerId(tenantId, customerId, pageLink));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw handleException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
||||||
@RequestMapping(value = "/edges", params = {"edgeIds"}, method = RequestMethod.GET)
|
@RequestMapping(value = "/edges", params = {"edgeIds"}, method = RequestMethod.GET)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
|
|||||||
@ -66,6 +66,10 @@ public interface EdgeService {
|
|||||||
|
|
||||||
PageData<Edge> findEdgesByTenantIdAndCustomerIdAndType(TenantId tenantId, CustomerId customerId, String type, PageLink pageLink);
|
PageData<Edge> findEdgesByTenantIdAndCustomerIdAndType(TenantId tenantId, CustomerId customerId, String type, PageLink pageLink);
|
||||||
|
|
||||||
|
PageData<EdgeInfo> findEdgeInfosByTenantIdAndCustomerId(TenantId tenantId, CustomerId customerId, PageLink pageLink);
|
||||||
|
|
||||||
|
PageData<EdgeInfo> findEdgeInfosByTenantIdAndCustomerIdAndType(TenantId tenantId, CustomerId customerId, String type, PageLink pageLink);
|
||||||
|
|
||||||
ListenableFuture<List<Edge>> findEdgesByTenantIdCustomerIdAndIdsAsync(TenantId tenantId, CustomerId customerId, List<EdgeId> edgeIds);
|
ListenableFuture<List<Edge>> findEdgesByTenantIdCustomerIdAndIdsAsync(TenantId tenantId, CustomerId customerId, List<EdgeId> edgeIds);
|
||||||
|
|
||||||
void unassignCustomerEdges(TenantId tenantId, CustomerId customerId);
|
void unassignCustomerEdges(TenantId tenantId, CustomerId customerId);
|
||||||
|
|||||||
@ -91,6 +91,26 @@ public interface EdgeDao extends Dao<Edge> {
|
|||||||
*/
|
*/
|
||||||
PageData<Edge> findEdgesByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, PageLink pageLink);
|
PageData<Edge> findEdgesByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, PageLink pageLink);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find edge infos by tenantId, customerId and page link.
|
||||||
|
*
|
||||||
|
* @param tenantId the tenantId
|
||||||
|
* @param customerId the customerId
|
||||||
|
* @param pageLink the page link
|
||||||
|
* @return the list of edge info objects
|
||||||
|
*/
|
||||||
|
PageData<EdgeInfo> findEdgeInfosByTenantIdAndCustomerId(UUID tenantId, UUID customerId, PageLink pageLink);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find edge infos by tenantId, customerId, type and page link.
|
||||||
|
*
|
||||||
|
* @param tenantId the tenantId
|
||||||
|
* @param customerId the customerId
|
||||||
|
* @param type the type
|
||||||
|
* @param pageLink the page link
|
||||||
|
* @return the list of edge info objects
|
||||||
|
*/
|
||||||
|
PageData<EdgeInfo> findEdgeInfosByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, PageLink pageLink);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find edges by tenantId, customerId and edges Ids.
|
* Find edges by tenantId, customerId and edges Ids.
|
||||||
|
|||||||
@ -270,6 +270,25 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic
|
|||||||
return edgeDao.findEdgesByTenantIdAndCustomerIdAndType(tenantId.getId(), customerId.getId(), type, pageLink);
|
return edgeDao.findEdgesByTenantIdAndCustomerIdAndType(tenantId.getId(), customerId.getId(), type, pageLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageData<EdgeInfo> findEdgeInfosByTenantIdAndCustomerId(TenantId tenantId, CustomerId customerId, PageLink pageLink) {
|
||||||
|
log.trace("Executing findEdgeInfosByTenantIdAndCustomerId, tenantId [{}], customerId [{}], pageLink [{}]", tenantId, customerId, pageLink);
|
||||||
|
validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
|
||||||
|
validateId(customerId, INCORRECT_CUSTOMER_ID + customerId);
|
||||||
|
validatePageLink(pageLink);
|
||||||
|
return edgeDao.findEdgeInfosByTenantIdAndCustomerId(tenantId.getId(), customerId.getId(), pageLink);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageData<EdgeInfo> findEdgeInfosByTenantIdAndCustomerIdAndType(TenantId tenantId, CustomerId customerId, String type, PageLink pageLink) {
|
||||||
|
log.trace("Executing findEdgeInfosByTenantIdAndCustomerIdAndType, tenantId [{}], customerId [{}], type [{}], pageLink [{}]", tenantId, customerId, type, pageLink);
|
||||||
|
validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
|
||||||
|
validateId(customerId, INCORRECT_CUSTOMER_ID + customerId);
|
||||||
|
validateString(type, "Incorrect type " + type);
|
||||||
|
validatePageLink(pageLink);
|
||||||
|
return edgeDao.findEdgeInfosByTenantIdAndCustomerIdAndType(tenantId.getId(), customerId.getId(), type, pageLink);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ListenableFuture<List<Edge>> findEdgesByTenantIdCustomerIdAndIdsAsync(TenantId tenantId, CustomerId customerId, List<EdgeId> edgeIds) {
|
public ListenableFuture<List<Edge>> findEdgesByTenantIdCustomerIdAndIdsAsync(TenantId tenantId, CustomerId customerId, List<EdgeId> edgeIds) {
|
||||||
log.trace("Executing findEdgesByTenantIdCustomerIdAndIdsAsync, tenantId [{}], customerId [{}], edgeIds [{}]", tenantId, customerId, edgeIds);
|
log.trace("Executing findEdgesByTenantIdCustomerIdAndIdsAsync, tenantId [{}], customerId [{}], edgeIds [{}]", tenantId, customerId, edgeIds);
|
||||||
|
|||||||
@ -80,6 +80,30 @@ public interface EdgeRepository extends PagingAndSortingRepository<EdgeEntity, U
|
|||||||
@Param("textSearch") String textSearch,
|
@Param("textSearch") String textSearch,
|
||||||
Pageable pageable);
|
Pageable pageable);
|
||||||
|
|
||||||
|
@Query("SELECT new org.thingsboard.server.dao.model.sql.EdgeInfoEntity(a, c.title, c.additionalInfo) " +
|
||||||
|
"FROM EdgeEntity a " +
|
||||||
|
"LEFT JOIN CustomerEntity c on c.id = a.customerId " +
|
||||||
|
"WHERE a.tenantId = :tenantId " +
|
||||||
|
"AND a.customerId = :customerId " +
|
||||||
|
"AND LOWER(a.searchText) LIKE LOWER(CONCAT(:searchText, '%'))")
|
||||||
|
Page<EdgeInfoEntity> findEdgeInfosByTenantIdAndCustomerId(@Param("tenantId") UUID tenantId,
|
||||||
|
@Param("customerId") UUID customerId,
|
||||||
|
@Param("searchText") String searchText,
|
||||||
|
Pageable pageable);
|
||||||
|
|
||||||
|
@Query("SELECT new org.thingsboard.server.dao.model.sql.EdgeInfoEntity(a, c.title, c.additionalInfo) " +
|
||||||
|
"FROM EdgeEntity a " +
|
||||||
|
"LEFT JOIN CustomerEntity c on c.id = a.customerId " +
|
||||||
|
"WHERE a.tenantId = :tenantId " +
|
||||||
|
"AND a.customerId = :customerId " +
|
||||||
|
"AND a.type = :type " +
|
||||||
|
"AND LOWER(a.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))")
|
||||||
|
Page<EdgeInfoEntity> findEdgeInfosByTenantIdAndCustomerIdAndType(@Param("tenantId") UUID tenantId,
|
||||||
|
@Param("customerId") UUID customerId,
|
||||||
|
@Param("type") String type,
|
||||||
|
@Param("textSearch") String textSearch,
|
||||||
|
Pageable pageable);
|
||||||
|
|
||||||
@Query("SELECT DISTINCT d.type FROM EdgeEntity d WHERE d.tenantId = :tenantId")
|
@Query("SELECT DISTINCT d.type FROM EdgeEntity d WHERE d.tenantId = :tenantId")
|
||||||
List<String> findTenantEdgeTypes(@Param("tenantId") UUID tenantId);
|
List<String> findTenantEdgeTypes(@Param("tenantId") UUID tenantId);
|
||||||
|
|
||||||
|
|||||||
@ -124,6 +124,27 @@ public class JpaEdgeDao extends JpaAbstractSearchTextDao<EdgeEntity, Edge> imple
|
|||||||
DaoUtil.toPageable(pageLink)));
|
DaoUtil.toPageable(pageLink)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageData<EdgeInfo> findEdgeInfosByTenantIdAndCustomerId(UUID tenantId, UUID customerId, PageLink pageLink) {
|
||||||
|
return DaoUtil.toPageData(
|
||||||
|
edgeRepository.findEdgeInfosByTenantIdAndCustomerId(
|
||||||
|
tenantId,
|
||||||
|
customerId,
|
||||||
|
Objects.toString(pageLink.getTextSearch(), ""),
|
||||||
|
DaoUtil.toPageable(pageLink, EdgeInfoEntity.edgeInfoColumnMap)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageData<EdgeInfo> findEdgeInfosByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, PageLink pageLink) {
|
||||||
|
return DaoUtil.toPageData(
|
||||||
|
edgeRepository.findEdgeInfosByTenantIdAndCustomerIdAndType(
|
||||||
|
tenantId,
|
||||||
|
customerId,
|
||||||
|
type,
|
||||||
|
Objects.toString(pageLink.getTextSearch(), ""),
|
||||||
|
DaoUtil.toPageable(pageLink, EdgeInfoEntity.edgeInfoColumnMap)));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ListenableFuture<List<EntitySubtype>> findTenantEdgeTypesAsync(UUID tenantId) {
|
public ListenableFuture<List<EntitySubtype>> findTenantEdgeTypesAsync(UUID tenantId) {
|
||||||
return service.submit(() -> convertTenantEdgeTypesToDto(tenantId, edgeRepository.findTenantEdgeTypes(tenantId)));
|
return service.submit(() -> convertTenantEdgeTypesToDto(tenantId, edgeRepository.findTenantEdgeTypes(tenantId)));
|
||||||
|
|||||||
@ -2343,7 +2343,7 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public PageData<Edge> getCustomerEdges(CustomerId customerId, String edgeType, PageLink pageLink) {
|
public PageData<Edge> getCustomerEdges(CustomerId customerId, PageLink pageLink, String edgeType) {
|
||||||
Map<String, String> params = new HashMap<>();
|
Map<String, String> params = new HashMap<>();
|
||||||
params.put("customerId", customerId.getId().toString());
|
params.put("customerId", customerId.getId().toString());
|
||||||
params.put("type", edgeType);
|
params.put("type", edgeType);
|
||||||
|
|||||||
@ -64,6 +64,12 @@ export class EdgeService {
|
|||||||
defaultHttpOptionsFromConfig(config));
|
defaultHttpOptionsFromConfig(config));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getCustomerEdgeInfos(customerId: string, pageLink: PageLink, type: string = '',
|
||||||
|
config?: RequestConfig): Observable<PageData<EdgeInfo>> {
|
||||||
|
return this.http.get<PageData<EdgeInfo>>(`/api/customer/${customerId}/edgeInfos${pageLink.toQuery()}&type=${type}`,
|
||||||
|
defaultHttpOptionsFromConfig(config));
|
||||||
|
}
|
||||||
|
|
||||||
public assignEdgeToCustomer(customerId: string, edgeId: string, config?: RequestConfig): Observable<Edge> {
|
public assignEdgeToCustomer(customerId: string, edgeId: string, config?: RequestConfig): Observable<Edge> {
|
||||||
return this.http.post<Edge>(`/api/customer/${customerId}/edge/${edgeId}`, null, defaultHttpOptionsFromConfig(config));
|
return this.http.post<Edge>(`/api/customer/${customerId}/edge/${edgeId}`, null, defaultHttpOptionsFromConfig(config));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -290,7 +290,7 @@ export class EntityService {
|
|||||||
case EntityType.EDGE:
|
case EntityType.EDGE:
|
||||||
pageLink.sortOrder.property = 'name';
|
pageLink.sortOrder.property = 'name';
|
||||||
if (authUser.authority === Authority.CUSTOMER_USER) {
|
if (authUser.authority === Authority.CUSTOMER_USER) {
|
||||||
entitiesObservable = this.edgeService.getCustomerEdges(customerId, pageLink, subType, config);
|
entitiesObservable = this.edgeService.getCustomerEdgeInfos(customerId, pageLink, subType, config);
|
||||||
} else {
|
} else {
|
||||||
entitiesObservable = this.edgeService.getTenantEdgeInfos(pageLink, subType, config);
|
entitiesObservable = this.edgeService.getTenantEdgeInfos(pageLink, subType, config);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -171,7 +171,7 @@ export class EdgesTableConfigResolver implements Resolve<EntityTableConfig<EdgeI
|
|||||||
}
|
}
|
||||||
if (edgeScope === 'customer') {
|
if (edgeScope === 'customer') {
|
||||||
this.config.entitiesFetchFunction = pageLink =>
|
this.config.entitiesFetchFunction = pageLink =>
|
||||||
this.edgeService.getCustomerEdges(this.customerId, pageLink, this.config.componentsData.edgeType);
|
this.edgeService.getCustomerEdgeInfos(this.customerId, pageLink, this.config.componentsData.edgeType);
|
||||||
this.config.deleteEntity = id => this.edgeService.unassignEdgeFromCustomer(id.id);
|
this.config.deleteEntity = id => this.edgeService.unassignEdgeFromCustomer(id.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user