Search in sources :

Example 21 with AssetId

use of org.thingsboard.server.common.data.id.AssetId in project thingsboard by thingsboard.

the class AssetController method getAssetsByIds.

@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/assets", params = { "assetIds" }, method = RequestMethod.GET)
@ResponseBody
public List<Asset> getAssetsByIds(@RequestParam("assetIds") String[] strAssetIds) throws ThingsboardException {
    checkArrayParameter("assetIds", strAssetIds);
    try {
        SecurityUser user = getCurrentUser();
        TenantId tenantId = user.getTenantId();
        CustomerId customerId = user.getCustomerId();
        List<AssetId> assetIds = new ArrayList<>();
        for (String strAssetId : strAssetIds) {
            assetIds.add(new AssetId(toUUID(strAssetId)));
        }
        ListenableFuture<List<Asset>> assets;
        if (customerId == null || customerId.isNullUid()) {
            assets = assetService.findAssetsByTenantIdAndIdsAsync(tenantId, assetIds);
        } else {
            assets = assetService.findAssetsByTenantIdCustomerIdAndIdsAsync(tenantId, customerId, assetIds);
        }
        return checkNotNull(assets.get());
    } catch (Exception e) {
        throw handleException(e);
    }
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) SecurityUser(org.thingsboard.server.service.security.model.SecurityUser) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CustomerId(org.thingsboard.server.common.data.id.CustomerId) AssetId(org.thingsboard.server.common.data.id.AssetId) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

AssetId (org.thingsboard.server.common.data.id.AssetId)21 EntityRelation (org.thingsboard.server.common.data.relation.EntityRelation)13 Test (org.junit.Test)12 Asset (org.thingsboard.server.common.data.asset.Asset)8 CustomerId (org.thingsboard.server.common.data.id.CustomerId)6 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)5 TenantId (org.thingsboard.server.common.data.id.TenantId)5 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)5 ThingsboardException (org.thingsboard.server.exception.ThingsboardException)5 Customer (org.thingsboard.server.common.data.Customer)4 EntityRelationsQuery (org.thingsboard.server.common.data.relation.EntityRelationsQuery)2 EntityTypeFilter (org.thingsboard.server.common.data.relation.EntityTypeFilter)2 RelationsSearchParameters (org.thingsboard.server.common.data.relation.RelationsSearchParameters)2 Function (com.google.common.base.Function)1 AsyncFunction (com.google.common.util.concurrent.AsyncFunction)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1