Search in sources :

Example 1 with WidgetTypeDetails

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

the class WidgetTypeDetailsEntity method toData.

@Override
public WidgetTypeDetails toData() {
    BaseWidgetType baseWidgetType = super.toBaseWidgetType();
    WidgetTypeDetails widgetTypeDetails = new WidgetTypeDetails(baseWidgetType);
    widgetTypeDetails.setImage(image);
    widgetTypeDetails.setDescription(description);
    widgetTypeDetails.setDescriptor(descriptor);
    return widgetTypeDetails;
}
Also used : BaseWidgetType(org.thingsboard.server.common.data.widget.BaseWidgetType) WidgetTypeDetails(org.thingsboard.server.common.data.widget.WidgetTypeDetails)

Example 2 with WidgetTypeDetails

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

the class BaseController method checkWidgetTypeId.

WidgetTypeDetails checkWidgetTypeId(WidgetTypeId widgetTypeId, Operation operation) throws ThingsboardException {
    try {
        validateId(widgetTypeId, "Incorrect widgetTypeId " + widgetTypeId);
        WidgetTypeDetails widgetTypeDetails = widgetTypeService.findWidgetTypeDetailsById(getCurrentUser().getTenantId(), widgetTypeId);
        checkNotNull(widgetTypeDetails, "Widget type with id [" + widgetTypeId + "] is not found");
        accessControlService.checkPermission(getCurrentUser(), Resource.WIDGET_TYPE, operation, widgetTypeId, widgetTypeDetails);
        return widgetTypeDetails;
    } catch (Exception e) {
        throw handleException(e, false);
    }
}
Also used : WidgetTypeDetails(org.thingsboard.server.common.data.widget.WidgetTypeDetails) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException) MessagingException(javax.mail.MessagingException) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 3 with WidgetTypeDetails

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

the class BaseWidgetTypeServiceTest method testSaveWidgetType.

@Test
public void testSaveWidgetType() throws IOException {
    WidgetsBundle widgetsBundle = new WidgetsBundle();
    widgetsBundle.setTenantId(tenantId);
    widgetsBundle.setTitle("Widgets bundle");
    WidgetsBundle savedWidgetsBundle = widgetsBundleService.saveWidgetsBundle(widgetsBundle);
    WidgetTypeDetails widgetType = new WidgetTypeDetails();
    widgetType.setTenantId(tenantId);
    widgetType.setBundleAlias(savedWidgetsBundle.getAlias());
    widgetType.setName("Widget Type");
    widgetType.setDescriptor(new ObjectMapper().readValue("{ \"someKey\": \"someValue\" }", JsonNode.class));
    WidgetTypeDetails savedWidgetType = widgetTypeService.saveWidgetType(widgetType);
    Assert.assertNotNull(savedWidgetType);
    Assert.assertNotNull(savedWidgetType.getId());
    Assert.assertNotNull(savedWidgetType.getAlias());
    Assert.assertTrue(savedWidgetType.getCreatedTime() > 0);
    Assert.assertEquals(widgetType.getTenantId(), savedWidgetType.getTenantId());
    Assert.assertEquals(widgetType.getName(), savedWidgetType.getName());
    Assert.assertEquals(widgetType.getDescriptor(), savedWidgetType.getDescriptor());
    Assert.assertEquals(savedWidgetsBundle.getAlias(), savedWidgetType.getBundleAlias());
    savedWidgetType.setName("New Widget Type");
    widgetTypeService.saveWidgetType(savedWidgetType);
    WidgetType foundWidgetType = widgetTypeService.findWidgetTypeById(tenantId, savedWidgetType.getId());
    Assert.assertEquals(foundWidgetType.getName(), savedWidgetType.getName());
    widgetsBundleService.deleteWidgetsBundle(tenantId, 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) WidgetTypeDetails(org.thingsboard.server.common.data.widget.WidgetTypeDetails) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 4 with WidgetTypeDetails

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

the class BaseWidgetTypeServiceTest method testUpdateWidgetTypeBundleAlias.

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

Example 5 with WidgetTypeDetails

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

the class BaseWidgetTypeServiceTest method testFindWidgetTypeByTenantIdBundleAliasAndAlias.

@Test
public void testFindWidgetTypeByTenantIdBundleAliasAndAlias() throws IOException {
    WidgetsBundle widgetsBundle = new WidgetsBundle();
    widgetsBundle.setTenantId(tenantId);
    widgetsBundle.setTitle("Widgets bundle");
    WidgetsBundle savedWidgetsBundle = widgetsBundleService.saveWidgetsBundle(widgetsBundle);
    WidgetTypeDetails widgetType = new WidgetTypeDetails();
    widgetType.setTenantId(tenantId);
    widgetType.setBundleAlias(savedWidgetsBundle.getAlias());
    widgetType.setName("Widget Type");
    widgetType.setDescriptor(new ObjectMapper().readValue("{ \"someKey\": \"someValue\" }", JsonNode.class));
    WidgetType savedWidgetType = new WidgetType(widgetTypeService.saveWidgetType(widgetType));
    WidgetType foundWidgetType = widgetTypeService.findWidgetTypeByTenantIdBundleAliasAndAlias(tenantId, savedWidgetsBundle.getAlias(), savedWidgetType.getAlias());
    Assert.assertNotNull(foundWidgetType);
    Assert.assertEquals(savedWidgetType, foundWidgetType);
    widgetsBundleService.deleteWidgetsBundle(tenantId, 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) WidgetTypeDetails(org.thingsboard.server.common.data.widget.WidgetTypeDetails) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

WidgetTypeDetails (org.thingsboard.server.common.data.widget.WidgetTypeDetails)30 JsonNode (com.fasterxml.jackson.databind.JsonNode)26 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)25 Test (org.junit.Test)25 WidgetsBundle (org.thingsboard.server.common.data.widget.WidgetsBundle)12 WidgetType (org.thingsboard.server.common.data.widget.WidgetType)6 ArrayList (java.util.ArrayList)2 ThingsboardException (org.thingsboard.server.common.data.exception.ThingsboardException)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ApiOperation (io.swagger.annotations.ApiOperation)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 MessagingException (javax.mail.MessagingException)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1 WidgetTypeId (org.thingsboard.server.common.data.id.WidgetTypeId)1 BaseWidgetType (org.thingsboard.server.common.data.widget.BaseWidgetType)1 DataValidationException (org.thingsboard.server.dao.exception.DataValidationException)1 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)1