Search in sources :

Example 21 with WidgetsBundle

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

the class WidgetsBundleServiceImpl method findSystemWidgetsBundles.

@Override
public List<WidgetsBundle> findSystemWidgetsBundles() {
    log.trace("Executing findSystemWidgetsBundles");
    List<WidgetsBundle> widgetsBundles = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(DEFAULT_WIDGETS_BUNDLE_LIMIT);
    TextPageData<WidgetsBundle> pageData;
    do {
        pageData = findSystemWidgetsBundlesByPageLink(pageLink);
        widgetsBundles.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    return widgetsBundles;
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) ArrayList(java.util.ArrayList) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle)

Example 22 with WidgetsBundle

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

the class WidgetsBundleServiceImpl method findAllTenantWidgetsBundlesByTenantId.

@Override
public List<WidgetsBundle> findAllTenantWidgetsBundlesByTenantId(TenantId tenantId) {
    log.trace("Executing findAllTenantWidgetsBundlesByTenantId, tenantId [{}]", tenantId);
    Validator.validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
    List<WidgetsBundle> widgetsBundles = new ArrayList<>();
    TextPageLink pageLink = new TextPageLink(DEFAULT_WIDGETS_BUNDLE_LIMIT);
    TextPageData<WidgetsBundle> pageData;
    do {
        pageData = findAllTenantWidgetsBundlesByTenantIdAndPageLink(tenantId, pageLink);
        widgetsBundles.addAll(pageData.getData());
        if (pageData.hasNext()) {
            pageLink = pageData.getNextPageLink();
        }
    } while (pageData.hasNext());
    return widgetsBundles;
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) ArrayList(java.util.ArrayList) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle)

Example 23 with WidgetsBundle

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

the class WidgetsBundleServiceImpl method deleteWidgetsBundle.

@Override
public void deleteWidgetsBundle(WidgetsBundleId widgetsBundleId) {
    log.trace("Executing deleteWidgetsBundle [{}]", widgetsBundleId);
    Validator.validateId(widgetsBundleId, "Incorrect widgetsBundleId " + widgetsBundleId);
    WidgetsBundle widgetsBundle = findWidgetsBundleById(widgetsBundleId);
    if (widgetsBundle == null) {
        throw new IncorrectParameterException("Unable to delete non-existent widgets bundle.");
    }
    widgetTypeService.deleteWidgetTypesByTenantIdAndBundleAlias(widgetsBundle.getTenantId(), widgetsBundle.getAlias());
    widgetsBundleDao.removeById(widgetsBundleId.getId());
}
Also used : IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle)

Example 24 with WidgetsBundle

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

the class WidgetsBundleEntity method toData.

@Override
public WidgetsBundle toData() {
    WidgetsBundle widgetsBundle = new WidgetsBundle(new WidgetsBundleId(id));
    widgetsBundle.setCreatedTime(UUIDs.unixTimestamp(id));
    if (tenantId != null) {
        widgetsBundle.setTenantId(new TenantId(tenantId));
    }
    widgetsBundle.setAlias(alias);
    widgetsBundle.setTitle(title);
    if (image != null) {
        byte[] imageByteArray = new byte[image.remaining()];
        image.get(imageByteArray);
        widgetsBundle.setImage(imageByteArray);
    }
    return 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 25 with WidgetsBundle

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

the class BaseWidgetTypeServiceTest method testFindWidgetTypeById.

@Test
public void testFindWidgetTypeById() throws IOException {
    WidgetsBundle widgetsBundle = new WidgetsBundle();
    widgetsBundle.setTenantId(tenantId);
    widgetsBundle.setTitle("Widgets bundle");
    WidgetsBundle savedWidgetsBundle = widgetsBundleService.saveWidgetsBundle(widgetsBundle);
    WidgetType widgetType = new WidgetType();
    widgetType.setTenantId(tenantId);
    widgetType.setBundleAlias(savedWidgetsBundle.getAlias());
    widgetType.setName("Widget Type");
    widgetType.setDescriptor(new ObjectMapper().readValue("{ \"someKey\": \"someValue\" }", JsonNode.class));
    WidgetType savedWidgetType = widgetTypeService.saveWidgetType(widgetType);
    WidgetType foundWidgetType = widgetTypeService.findWidgetTypeById(savedWidgetType.getId());
    Assert.assertNotNull(foundWidgetType);
    Assert.assertEquals(savedWidgetType, foundWidgetType);
    widgetsBundleService.deleteWidgetsBundle(savedWidgetsBundle.getId());
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) WidgetType(org.thingsboard.server.common.data.widget.WidgetType) WidgetsBundle(org.thingsboard.server.common.data.widget.WidgetsBundle) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

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