Search in sources :

Example 16 with WidgetTypeDetails

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

the class BaseWidgetTypeControllerTest method testFindWidgetTypeById.

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

Example 17 with WidgetTypeDetails

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

the class BaseWidgetTypeControllerTest method testUpdateWidgetTypeAlias.

@Test
public void testUpdateWidgetTypeAlias() throws Exception {
    WidgetTypeDetails widgetType = new WidgetTypeDetails();
    widgetType.setBundleAlias(savedWidgetsBundle.getAlias());
    widgetType.setName("Widget Type");
    widgetType.setDescriptor(new ObjectMapper().readValue("{ \"someKey\": \"someValue\" }", JsonNode.class));
    WidgetTypeDetails savedWidgetType = doPost("/api/widgetType", widgetType, WidgetTypeDetails.class);
    savedWidgetType.setAlias("some_alias");
    doPost("/api/widgetType", savedWidgetType).andExpect(status().isBadRequest()).andExpect(statusReason(containsString("Update of widget type alias is prohibited")));
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) WidgetTypeDetails(org.thingsboard.server.common.data.widget.WidgetTypeDetails) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 18 with WidgetTypeDetails

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

the class WidgetTypeController method saveWidgetType.

@ApiOperation(value = "Create Or Update Widget Type (saveWidgetType)", notes = "Create or update the Widget Type. " + WIDGET_TYPE_DESCRIPTION + " " + "When creating the Widget Type, platform generates Widget Type Id as " + UUID_WIKI_LINK + "The newly created Widget Type Id will be present in the response. " + "Specify existing Widget Type id to update the Widget Type. " + "Referencing non-existing Widget Type Id will cause 'Not Found' error." + "\n\nWidget Type alias is unique in the scope of Widget Bundle. " + "Special Tenant Id '13814000-1dd2-11b2-8080-808080808080' is automatically used if the create request is sent by user with 'SYS_ADMIN' authority." + SYSTEM_OR_TENANT_AUTHORITY_PARAGRAPH)
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
@RequestMapping(value = "/widgetType", method = RequestMethod.POST)
@ResponseBody
public WidgetTypeDetails saveWidgetType(@ApiParam(value = "A JSON value representing the Widget Type Details.", required = true) @RequestBody WidgetTypeDetails widgetTypeDetails) throws ThingsboardException {
    try {
        if (Authority.SYS_ADMIN.equals(getCurrentUser().getAuthority())) {
            widgetTypeDetails.setTenantId(TenantId.SYS_TENANT_ID);
        } else {
            widgetTypeDetails.setTenantId(getCurrentUser().getTenantId());
        }
        checkEntity(widgetTypeDetails.getId(), widgetTypeDetails, Resource.WIDGET_TYPE);
        WidgetTypeDetails savedWidgetTypeDetails = widgetTypeService.saveWidgetType(widgetTypeDetails);
        sendEntityNotificationMsg(getTenantId(), savedWidgetTypeDetails.getId(), widgetTypeDetails.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED);
        return checkNotNull(savedWidgetTypeDetails);
    } catch (Exception e) {
        throw handleException(e);
    }
}
Also used : WidgetTypeDetails(org.thingsboard.server.common.data.widget.WidgetTypeDetails) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 19 with WidgetTypeDetails

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

the class WidgetTypeEdgeProcessor method processWidgetTypeToEdge.

public DownlinkMsg processWidgetTypeToEdge(EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType edgeEdgeEventActionType) {
    WidgetTypeId widgetTypeId = new WidgetTypeId(edgeEvent.getEntityId());
    DownlinkMsg downlinkMsg = null;
    switch(edgeEdgeEventActionType) {
        case ADDED:
        case UPDATED:
            WidgetTypeDetails widgetTypeDetails = widgetTypeService.findWidgetTypeDetailsById(edgeEvent.getTenantId(), widgetTypeId);
            if (widgetTypeDetails != null) {
                WidgetTypeUpdateMsg widgetTypeUpdateMsg = widgetTypeMsgConstructor.constructWidgetTypeUpdateMsg(msgType, widgetTypeDetails);
                downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addWidgetTypeUpdateMsg(widgetTypeUpdateMsg).build();
            }
            break;
        case DELETED:
            WidgetTypeUpdateMsg widgetTypeUpdateMsg = widgetTypeMsgConstructor.constructWidgetTypeDeleteMsg(widgetTypeId);
            downlinkMsg = DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addWidgetTypeUpdateMsg(widgetTypeUpdateMsg).build();
            break;
    }
    return downlinkMsg;
}
Also used : WidgetTypeUpdateMsg(org.thingsboard.server.gen.edge.v1.WidgetTypeUpdateMsg) DownlinkMsg(org.thingsboard.server.gen.edge.v1.DownlinkMsg) WidgetTypeId(org.thingsboard.server.common.data.id.WidgetTypeId) WidgetTypeDetails(org.thingsboard.server.common.data.widget.WidgetTypeDetails)

Example 20 with WidgetTypeDetails

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

the class BaseWidgetTypeControllerTest method testSaveWidgetTypeWithInvalidBundleAlias.

@Test
public void testSaveWidgetTypeWithInvalidBundleAlias() throws Exception {
    WidgetTypeDetails widgetType = new WidgetTypeDetails();
    widgetType.setBundleAlias("some_alias");
    widgetType.setName("Widget Type");
    widgetType.setDescriptor(new ObjectMapper().readValue("{ \"someKey\": \"someValue\" }", JsonNode.class));
    doPost("/api/widgetType", widgetType).andExpect(status().isBadRequest()).andExpect(statusReason(containsString("Widget type is referencing to non-existent widgets bundle")));
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) 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