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);
}
}
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);
}
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;
}
Aggregations