Merge branch 'master' of github.com:thingsboard/thingsboard

This commit is contained in:
Igor Kulikov 2023-11-09 12:25:13 +02:00
commit 5bca0e1685
3 changed files with 59 additions and 3 deletions

View File

@ -17,6 +17,7 @@ package org.thingsboard.server.controller;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import org.apache.commons.io.IOUtils;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
@ -34,6 +35,7 @@ import org.thingsboard.server.common.data.TbResourceInfo;
import org.thingsboard.server.common.data.Tenant;
import org.thingsboard.server.common.data.User;
import org.thingsboard.server.common.data.audit.ActionType;
import org.thingsboard.server.common.data.lwm2m.LwM2mObject;
import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.common.data.security.Authority;
@ -614,6 +616,60 @@ public class TbResourceControllerTest extends AbstractControllerTest {
.andExpect(status().isForbidden());
}
@Test
public void testGetLwm2mListObjectsPage() throws Exception {
loginTenantAdmin();
List<TbResource> resources = loadLwm2mResources();
List<LwM2mObject> objects =
doGetTyped("/api/resource/lwm2m/page?pageSize=100&page=0", new TypeReference<>(){});
Assert.assertNotNull(objects);
Assert.assertEquals(resources.size(), objects.size());
removeLoadResources(resources);
}
@Test
public void testGetLwm2mListObjects() throws Exception {
loginTenantAdmin();
List<TbResource> resources = loadLwm2mResources();
List<LwM2mObject> objects =
doGetTyped("/api/resource/lwm2m?sortProperty=id&sortOrder=ASC&objectIds=3_1.0,5_1.0,19_1.1", new TypeReference<>(){});
Assert.assertNotNull(objects);
Assert.assertEquals(3, objects.size());
removeLoadResources(resources);
}
private List<TbResource> loadLwm2mResources() throws Exception {
var models = List.of("1", "2", "3", "5", "6", "9", "19", "3303");
List<TbResource> resources = new ArrayList<>(models.size());
for (String model : models) {
String fileName = model + ".xml";
byte[] bytes = IOUtils.toByteArray(getClass().getClassLoader().getResourceAsStream("lwm2m/" + fileName));
TbResource resource = new TbResource();
resource.setResourceType(ResourceType.LWM2M_MODEL);
resource.setFileName(fileName);
resource.setData(Base64.getEncoder().encodeToString(bytes));
resources.add(save(resource));
}
return resources;
}
private void removeLoadResources(List<TbResource> resources) throws Exception {
for (TbResourceInfo resource : resources) {
doDelete("/api/resource/" + resource.getId().getId().toString())
.andExpect(status().isOk());
}
}
private TbResource save(TbResource tbResource) throws Exception {
return doPostWithTypedResponse("/api/resource", tbResource, new TypeReference<>() {
});

View File

@ -45,7 +45,7 @@ public interface TbResourceRepository extends JpaRepository<TbResourceEntity, UU
@Param("tenantId") UUID tenantId,
@Param("systemAdminId") UUID sysAdminId,
@Param("resourceType") String resourceType,
@Param("searchText") String search,
@Param("searchText") String searchText,
Pageable pageable);
@Query("SELECT tr FROM TbResourceEntity tr " +
@ -61,7 +61,7 @@ public interface TbResourceRepository extends JpaRepository<TbResourceEntity, UU
List<TbResourceEntity> findResources(@Param("tenantId") UUID tenantId,
@Param("systemAdminId") UUID sysAdminId,
@Param("resourceType") String resourceType,
@Param("searchText") String search);
@Param("searchText") String searchText);
@Query("SELECT tr FROM TbResourceEntity tr " +
"WHERE tr.resourceType = :resourceType " +

View File

@ -5,7 +5,7 @@
"ng": "ng",
"start": "node --max_old_space_size=8048 ./node_modules/@angular/cli/bin/ng serve --configuration development --host 0.0.0.0 --open",
"build": "ng build",
"build:prod": "node --max_old_space_size=3072 ./node_modules/@angular/cli/bin/ng build --configuration production --vendor-chunk",
"build:prod": "node --max_old_space_size=4096 ./node_modules/@angular/cli/bin/ng build --configuration production --vendor-chunk",
"build:types": "node generate-types.js",
"test": "ng test",
"lint": "ng lint",