Search in sources :

Example 41 with WidgetsBundle

use of org.thingsboard.server.common.data.widget.WidgetsBundle in project thingsboard by thingsboard.

the class JpaWidgetsBundleDaoTest method testFindWidgetsBundlesByTenantId.

@Test
@DatabaseSetup(value = "classpath:dbunit/widgets_bundle.xml", type = DatabaseOperation.DELETE_ALL)
public void testFindWidgetsBundlesByTenantId() {
    UUID tenantId1 = UUIDs.timeBased();
    UUID tenantId2 = UUIDs.timeBased();
    // Create a bunch of widgetBundles
    for (int i = 0; i < 10; i++) {
        createWidgetBundles(3, tenantId1, "WB1_");
        createWidgetBundles(5, tenantId2, "WB2_");
        createSystemWidgetBundles(10, "WB_SYS_");
    }
    assertEquals(180, widgetsBundleDao.find().size());
    TextPageLink textPageLink1 = new TextPageLink(40, "WB");
    List<WidgetsBundle> widgetsBundles1 = widgetsBundleDao.findTenantWidgetsBundlesByTenantId(tenantId1, textPageLink1);
    assertEquals(30, widgetsBundles1.size());
    TextPageLink textPageLink2 = new TextPageLink(40, "WB");
    List<WidgetsBundle> widgetsBundles2 = widgetsBundleDao.findTenantWidgetsBundlesByTenantId(tenantId2, textPageLink2);
    assertEquals(40, widgetsBundles2.size());
    TextPageLink textPageLink3 = new TextPageLink(40, "WB", widgetsBundles2.get(39).getId().getId(), null);
    List<WidgetsBundle> widgetsBundles3 = widgetsBundleDao.findTenantWidgetsBundlesByTenantId(tenantId2, textPageLink3);
    assertEquals(10, widgetsBundles3.size());
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) NULL_UUID(org.thingsboard.server.dao.model.ModelConstants.NULL_UUID) UUID(java.util.UUID) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle) AbstractJpaDaoTest(org.thingsboard.server.dao.AbstractJpaDaoTest) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Example 42 with WidgetsBundle

use of org.thingsboard.server.common.data.widget.WidgetsBundle in project thingsboard by thingsboard.

the class JpaWidgetsBundleDaoTest method createSystemWidgetBundles.

private void createSystemWidgetBundles(int count, String prefix) {
    for (int i = 0; i < count; i++) {
        WidgetsBundle widgetsBundle = new WidgetsBundle();
        widgetsBundle.setAlias(prefix + i);
        widgetsBundle.setTitle(prefix + i);
        widgetsBundle.setTenantId(new TenantId(NULL_UUID));
        widgetsBundle.setId(new WidgetsBundleId(UUIDs.timeBased()));
        widgetsBundleDao.save(widgetsBundle);
    }
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) WidgetsBundleId(org.thingsboard.server.common.data.id.WidgetsBundleId) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle)

Example 43 with WidgetsBundle

use of org.thingsboard.server.common.data.widget.WidgetsBundle in project thingsboard by thingsboard.

the class JpaWidgetsBundleDaoTest method testFindSystemWidgetsBundles.

@Test
@DatabaseSetup(value = "classpath:dbunit/widgets_bundle.xml", type = DatabaseOperation.DELETE_ALL)
public void testFindSystemWidgetsBundles() {
    createSystemWidgetBundles(30, "WB_");
    assertEquals(30, widgetsBundleDao.find().size());
    // Get first page
    TextPageLink textPageLink1 = new TextPageLink(10, "WB");
    List<WidgetsBundle> widgetsBundles1 = widgetsBundleDao.findSystemWidgetsBundles(textPageLink1);
    assertEquals(10, widgetsBundles1.size());
    // Get next page
    TextPageLink textPageLink2 = new TextPageLink(10, "WB", widgetsBundles1.get(9).getId().getId(), null);
    List<WidgetsBundle> widgetsBundles2 = widgetsBundleDao.findSystemWidgetsBundles(textPageLink2);
    assertEquals(10, widgetsBundles2.size());
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle) AbstractJpaDaoTest(org.thingsboard.server.dao.AbstractJpaDaoTest) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Example 44 with WidgetsBundle

use of org.thingsboard.server.common.data.widget.WidgetsBundle in project thingsboard by thingsboard.

the class JpaWidgetsBundleDaoTest method createWidgetBundles.

private void createWidgetBundles(int count, UUID tenantId, String prefix) {
    for (int i = 0; i < count; i++) {
        WidgetsBundle widgetsBundle = new WidgetsBundle();
        widgetsBundle.setAlias(prefix + i);
        widgetsBundle.setTitle(prefix + i);
        widgetsBundle.setId(new WidgetsBundleId(UUIDs.timeBased()));
        widgetsBundle.setTenantId(new TenantId(tenantId));
        widgetsBundleDao.save(widgetsBundle);
    }
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) WidgetsBundleId(org.thingsboard.server.common.data.id.WidgetsBundleId) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle)

Example 45 with WidgetsBundle

use of org.thingsboard.server.common.data.widget.WidgetsBundle in project thingsboard by thingsboard.

the class BaseController method checkWidgetsBundleId.

WidgetsBundle checkWidgetsBundleId(WidgetsBundleId widgetsBundleId, boolean modify) throws ThingsboardException {
    try {
        validateId(widgetsBundleId, "Incorrect widgetsBundleId " + widgetsBundleId);
        WidgetsBundle widgetsBundle = widgetsBundleService.findWidgetsBundleById(widgetsBundleId);
        checkWidgetsBundle(widgetsBundle, modify);
        return widgetsBundle;
    } catch (Exception e) {
        throw handleException(e, false);
    }
}
Also used : WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle) MessagingException(javax.mail.MessagingException) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException)

Aggregations

WidgetsBundle (org.thingsboard.server.common.data.widget.WidgetsBundle)48 Test (org.junit.Test)38 TenantId (org.thingsboard.server.common.data.id.TenantId)13 JsonNode (com.fasterxml.jackson.databind.JsonNode)12 ArrayList (java.util.ArrayList)12 WidgetType (org.thingsboard.server.common.data.widget.WidgetType)12 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)11 TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)11 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)5 AbstractJpaDaoTest (org.thingsboard.server.dao.AbstractJpaDaoTest)5 List (java.util.List)4 Tenant (org.thingsboard.server.common.data.Tenant)4 WidgetsBundleId (org.thingsboard.server.common.data.id.WidgetsBundleId)4 TypeReference (com.fasterxml.jackson.core.type.TypeReference)3 UUID (java.util.UUID)3 NULL_UUID (org.thingsboard.server.dao.model.ModelConstants.NULL_UUID)3 DatabaseTearDown (com.github.springtestdbunit.annotation.DatabaseTearDown)2 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1