Search in sources :

Example 1 with WidgetType

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

the class WidgetTypeServiceImpl method deleteWidgetTypesByTenantIdAndBundleAlias.

@Override
public void deleteWidgetTypesByTenantIdAndBundleAlias(TenantId tenantId, String bundleAlias) {
    log.trace("Executing deleteWidgetTypesByTenantIdAndBundleAlias, tenantId [{}], bundleAlias [{}]", tenantId, bundleAlias);
    Validator.validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
    Validator.validateString(bundleAlias, INCORRECT_BUNDLE_ALIAS + bundleAlias);
    List<WidgetType> widgetTypes = widgetTypeDao.findWidgetTypesByTenantIdAndBundleAlias(tenantId.getId(), bundleAlias);
    for (WidgetType widgetType : widgetTypes) {
        deleteWidgetType(new WidgetTypeId(widgetType.getUuidId()));
    }
}
Also used : WidgetTypeId(org.thingsboard.server.common.data.id.WidgetTypeId) WidgetType(org.thingsboard.server.common.data.widget.WidgetType)

Example 2 with WidgetType

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

the class WidgetTypeEntity method toData.

@Override
public WidgetType toData() {
    WidgetType widgetType = new WidgetType(new WidgetTypeId(id));
    widgetType.setCreatedTime(UUIDs.unixTimestamp(id));
    if (tenantId != null) {
        widgetType.setTenantId(new TenantId(tenantId));
    }
    widgetType.setBundleAlias(bundleAlias);
    widgetType.setAlias(alias);
    widgetType.setName(name);
    widgetType.setDescriptor(descriptor);
    return widgetType;
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) WidgetTypeId(org.thingsboard.server.common.data.id.WidgetTypeId) WidgetType(org.thingsboard.server.common.data.widget.WidgetType)

Example 3 with WidgetType

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

the class WidgetTypeEntity method toData.

@Override
public WidgetType toData() {
    WidgetType widgetType = new WidgetType(new WidgetTypeId(getId()));
    widgetType.setCreatedTime(UUIDs.unixTimestamp(getId()));
    if (tenantId != null) {
        widgetType.setTenantId(new TenantId(toUUID(tenantId)));
    }
    widgetType.setBundleAlias(bundleAlias);
    widgetType.setAlias(alias);
    widgetType.setName(name);
    widgetType.setDescriptor(descriptor);
    return widgetType;
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) WidgetTypeId(org.thingsboard.server.common.data.id.WidgetTypeId) WidgetType(org.thingsboard.server.common.data.widget.WidgetType)

Example 4 with WidgetType

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

the class BaseWidgetTypeControllerTest method testFindWidgetTypeById.

@Test
public void testFindWidgetTypeById() throws Exception {
    WidgetType widgetType = new WidgetType();
    widgetType.setBundleAlias(savedWidgetsBundle.getAlias());
    widgetType.setName("Widget Type");
    widgetType.setDescriptor(new ObjectMapper().readValue("{ \"someKey\": \"someValue\" }", JsonNode.class));
    WidgetType savedWidgetType = doPost("/api/widgetType", widgetType, WidgetType.class);
    WidgetType foundWidgetType = doGet("/api/widgetType/" + savedWidgetType.getId().getId().toString(), WidgetType.class);
    Assert.assertNotNull(foundWidgetType);
    Assert.assertEquals(savedWidgetType, foundWidgetType);
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) WidgetType(org.thingsboard.server.common.data.widget.WidgetType) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 5 with WidgetType

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

the class BaseWidgetTypeControllerTest method testSaveWidgetTypeWithEmptyDescriptor.

@Test
public void testSaveWidgetTypeWithEmptyDescriptor() throws Exception {
    WidgetType widgetType = new WidgetType();
    widgetType.setBundleAlias(savedWidgetsBundle.getAlias());
    widgetType.setName("Widget Type");
    widgetType.setDescriptor(new ObjectMapper().readValue("{}", JsonNode.class));
    doPost("/api/widgetType", widgetType).andExpect(status().isBadRequest()).andExpect(statusReason(containsString("Widgets type descriptor can't be empty")));
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) WidgetType(org.thingsboard.server.common.data.widget.WidgetType) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

WidgetType (org.thingsboard.server.common.data.widget.WidgetType)32 Test (org.junit.Test)26 JsonNode (com.fasterxml.jackson.databind.JsonNode)25 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)24 WidgetsBundle (org.thingsboard.server.common.data.widget.WidgetsBundle)12 TenantId (org.thingsboard.server.common.data.id.TenantId)5 WidgetTypeId (org.thingsboard.server.common.data.id.WidgetTypeId)3 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)2 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 AbstractJpaDaoTest (org.thingsboard.server.dao.AbstractJpaDaoTest)2 ThingsboardException (org.thingsboard.server.exception.ThingsboardException)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 List (java.util.List)1 MessagingException (javax.mail.MessagingException)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 DataValidationException (org.thingsboard.server.dao.exception.DataValidationException)1 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)1