Search in sources :

Example 6 with TbResourceInfo

use of org.thingsboard.server.common.data.TbResourceInfo in project thingsboard by thingsboard.

the class BaseController method checkResourceInfoId.

TbResourceInfo checkResourceInfoId(TbResourceId resourceId, Operation operation) throws ThingsboardException {
    try {
        validateId(resourceId, "Incorrect resourceId " + resourceId);
        TbResourceInfo resourceInfo = resourceService.findResourceInfoById(getCurrentUser().getTenantId(), resourceId);
        checkNotNull(resourceInfo, "Resource with id [" + resourceId + "] is not found");
        accessControlService.checkPermission(getCurrentUser(), Resource.TB_RESOURCE, operation, resourceId, resourceInfo);
        return resourceInfo;
    } catch (Exception e) {
        throw handleException(e, false);
    }
}
Also used : TbResourceInfo(org.thingsboard.server.common.data.TbResourceInfo) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException) MessagingException(javax.mail.MessagingException) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 7 with TbResourceInfo

use of org.thingsboard.server.common.data.TbResourceInfo in project thingsboard by thingsboard.

the class BaseTbResourceControllerTest method testFindTenantTbResources.

@Test
public void testFindTenantTbResources() throws Exception {
    List<TbResourceInfo> resources = new ArrayList<>();
    for (int i = 0; i < 173; i++) {
        TbResource resource = new TbResource();
        resource.setTitle("Resource" + i);
        resource.setResourceType(ResourceType.JKS);
        resource.setFileName(i + DEFAULT_FILE_NAME);
        resource.setData("Test Data");
        resources.add(new TbResourceInfo(save(resource)));
    }
    List<TbResourceInfo> loadedResources = new ArrayList<>();
    PageLink pageLink = new PageLink(24);
    PageData<TbResourceInfo> pageData;
    do {
        pageData = doGetTypedWithPageLink("/api/resource?", new TypeReference<PageData<TbResourceInfo>>() {
        }, pageLink);
        loadedResources.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageLink.nextPageLink();
        }
    } while (pageData.hasNext());
    Collections.sort(resources, idComparator);
    Collections.sort(loadedResources, idComparator);
    Assert.assertEquals(resources, loadedResources);
}
Also used : TbResourceInfo(org.thingsboard.server.common.data.TbResourceInfo) ArrayList(java.util.ArrayList) PageLink(org.thingsboard.server.common.data.page.PageLink) TypeReference(com.fasterxml.jackson.core.type.TypeReference) TbResource(org.thingsboard.server.common.data.TbResource) Test(org.junit.Test)

Example 8 with TbResourceInfo

use of org.thingsboard.server.common.data.TbResourceInfo in project thingsboard by thingsboard.

the class TbResourceInfoEntity method toData.

@Override
public TbResourceInfo toData() {
    TbResourceInfo resource = new TbResourceInfo(new TbResourceId(id));
    resource.setCreatedTime(createdTime);
    resource.setTenantId(TenantId.fromUUID(tenantId));
    resource.setTitle(title);
    resource.setResourceType(ResourceType.valueOf(resourceType));
    resource.setResourceKey(resourceKey);
    resource.setSearchText(searchText);
    return resource;
}
Also used : TbResourceInfo(org.thingsboard.server.common.data.TbResourceInfo) TbResourceId(org.thingsboard.server.common.data.id.TbResourceId)

Aggregations

TbResourceInfo (org.thingsboard.server.common.data.TbResourceInfo)8 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 TbResource (org.thingsboard.server.common.data.TbResource)5 PageLink (org.thingsboard.server.common.data.page.PageLink)5 TypeReference (com.fasterxml.jackson.core.type.TypeReference)3 Tenant (org.thingsboard.server.common.data.Tenant)3 TenantId (org.thingsboard.server.common.data.id.TenantId)3 ThingsboardException (org.thingsboard.server.common.data.exception.ThingsboardException)2 TbResourceId (org.thingsboard.server.common.data.id.TbResourceId)2 AbstractControllerTest (org.thingsboard.server.controller.AbstractControllerTest)2 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)2 DaoSqlTest (org.thingsboard.server.dao.service.DaoSqlTest)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Function (com.google.common.base.Function)1 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1