Search in sources :

Example 1 with ComponentDescriptor

use of org.thingsboard.server.common.data.plugin.ComponentDescriptor in project thingsboard by thingsboard.

the class CassandraBaseComponentDescriptorDao method findById.

@Override
public ComponentDescriptor findById(ComponentDescriptorId componentId) {
    log.debug("Search component entity by id [{}]", componentId);
    ComponentDescriptor componentDescriptor = super.findById(componentId.getId());
    if (log.isTraceEnabled()) {
        log.trace("Search result: [{}] for component entity [{}]", componentDescriptor != null, componentDescriptor);
    } else {
        log.debug(SEARCH_RESULT, componentDescriptor != null);
    }
    return componentDescriptor;
}
Also used : ComponentDescriptor(org.thingsboard.server.common.data.plugin.ComponentDescriptor)

Example 2 with ComponentDescriptor

use of org.thingsboard.server.common.data.plugin.ComponentDescriptor in project thingsboard by thingsboard.

the class BaseRuleService method validateRuleAndPluginState.

private void validateRuleAndPluginState(RuleMetaData rule) {
    if (org.springframework.util.StringUtils.isEmpty(rule.getPluginToken())) {
        return;
    }
    PluginMetaData pluginMd = pluginService.findPluginByApiToken(rule.getPluginToken());
    if (pluginMd == null) {
        throw new IncorrectParameterException("Rule points to non-existent plugin!");
    }
    if (!pluginMd.getTenantId().equals(systemTenantId) && !pluginMd.getTenantId().equals(rule.getTenantId())) {
        throw new IncorrectParameterException("Rule access plugin that belongs to different tenant!");
    }
    if (rule.getState() == ComponentLifecycleState.ACTIVE && pluginMd.getState() != ComponentLifecycleState.ACTIVE) {
        throw new IncorrectParameterException("Can't save active rule that points to inactive plugin!");
    }
    ComponentDescriptor pluginDescriptor = componentDescriptorService.findByClazz(pluginMd.getClazz());
    String actionClazz = getIfValid(ComponentType.ACTION.name(), rule.getAction(), "clazz", JsonNode::isTextual, JsonNode::asText);
    if (!Arrays.asList(pluginDescriptor.getActions().split(",")).contains(actionClazz)) {
        throw new IncorrectParameterException("Rule's action is not supported by plugin with token " + rule.getPluginToken() + "!");
    }
}
Also used : IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) ComponentDescriptor(org.thingsboard.server.common.data.plugin.ComponentDescriptor) PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 3 with ComponentDescriptor

use of org.thingsboard.server.common.data.plugin.ComponentDescriptor in project thingsboard by thingsboard.

the class BaseComponentDescriptorControllerTest method testGetByClazz.

@Test
public void testGetByClazz() throws Exception {
    ComponentDescriptor descriptor = doGet("/api/component/" + TelemetryStoragePlugin.class.getName(), ComponentDescriptor.class);
    Assert.assertNotNull(descriptor);
    Assert.assertNotNull(descriptor.getId());
    Assert.assertNotNull(descriptor.getName());
    Assert.assertEquals(ComponentScope.TENANT, descriptor.getScope());
    Assert.assertEquals(ComponentType.PLUGIN, descriptor.getType());
    Assert.assertEquals(descriptor.getClazz(), descriptor.getClazz());
}
Also used : ComponentDescriptor(org.thingsboard.server.common.data.plugin.ComponentDescriptor) Test(org.junit.Test)

Example 4 with ComponentDescriptor

use of org.thingsboard.server.common.data.plugin.ComponentDescriptor in project thingsboard by thingsboard.

the class DefaultActorServiceTest method testBasicPostWithSyncSession.

@Test
public void testBasicPostWithSyncSession() throws Exception {
    SessionContext ssnCtx = mock(SessionContext.class);
    KvEntry entry1 = new StringDataEntry("key1", "value1");
    KvEntry entry2 = new StringDataEntry("key2", "value2");
    BasicTelemetryUploadRequest telemetry = new BasicTelemetryUploadRequest();
    long ts = 42;
    telemetry.add(ts, entry1);
    telemetry.add(ts, entry2);
    BasicAdaptorToSessionActorMsg msg = new BasicAdaptorToSessionActorMsg(ssnCtx, telemetry);
    DeviceId deviceId = new DeviceId(UUID.randomUUID());
    DeviceCredentialsFilter filter = new DeviceTokenCredentials("token1");
    Device device = mock(Device.class);
    when(device.getId()).thenReturn(deviceId);
    when(device.getTenantId()).thenReturn(tenantId);
    when(ssnCtx.getSessionId()).thenReturn(new DummySessionID("session1"));
    when(ssnCtx.getSessionType()).thenReturn(SessionType.SYNC);
    when(deviceAuthService.process(filter)).thenReturn(DeviceAuthResult.of(deviceId));
    when(deviceService.findDeviceById(deviceId)).thenReturn(device);
    ObjectMapper ruleMapper = new ObjectMapper();
    when(ruleMock.getFilters()).thenReturn(ruleMapper.readTree(FILTERS_CONFIGURATION));
    when(ruleMock.getAction()).thenReturn(ruleMapper.readTree(ACTION_CONFIGURATION));
    ComponentDescriptor filterComp = new ComponentDescriptor();
    filterComp.setClazz("org.thingsboard.server.extensions.core.filter.MsgTypeFilter");
    filterComp.setType(ComponentType.FILTER);
    when(componentService.getComponent("org.thingsboard.server.extensions.core.filter.MsgTypeFilter")).thenReturn(Optional.of(filterComp));
    ComponentDescriptor actionComp = new ComponentDescriptor();
    actionComp.setClazz("org.thingsboard.server.extensions.core.action.telemetry.TelemetryPluginAction");
    actionComp.setType(ComponentType.ACTION);
    when(componentService.getComponent("org.thingsboard.server.extensions.core.action.telemetry.TelemetryPluginAction")).thenReturn(Optional.of(actionComp));
    ObjectMapper pluginMapper = new ObjectMapper();
    JsonNode pluginAdditionalInfo = pluginMapper.readTree(PLUGIN_CONFIGURATION);
    when(pluginMock.getConfiguration()).thenReturn(pluginAdditionalInfo);
    when(pluginMock.getClazz()).thenReturn(TelemetryStoragePlugin.class.getName());
    when(attributesService.findAll(deviceId, DataConstants.CLIENT_SCOPE)).thenReturn(Futures.immediateFuture(Collections.emptyList()));
    when(attributesService.findAll(deviceId, DataConstants.SHARED_SCOPE)).thenReturn(Futures.immediateFuture(Collections.emptyList()));
    when(attributesService.findAll(deviceId, DataConstants.SERVER_SCOPE)).thenReturn(Futures.immediateFuture(Collections.emptyList()));
    initActorSystem();
    Thread.sleep(1000);
    actorService.process(new BasicToDeviceActorSessionMsg(device, msg));
    // Check that device data was saved to DB;
    List<TsKvEntry> expected = new ArrayList<>();
    expected.add(new BasicTsKvEntry(ts, entry1));
    expected.add(new BasicTsKvEntry(ts, entry2));
    verify(tsService, Mockito.timeout(5000)).save(deviceId, expected, 0L);
}
Also used : BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) Device(org.thingsboard.server.common.data.Device) ComponentDescriptor(org.thingsboard.server.common.data.plugin.ComponentDescriptor) BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) KvEntry(org.thingsboard.server.common.data.kv.KvEntry) TelemetryStoragePlugin(org.thingsboard.server.extensions.core.plugin.telemetry.TelemetryStoragePlugin) JsonNode(com.fasterxml.jackson.databind.JsonNode) DeviceCredentialsFilter(org.thingsboard.server.common.data.security.DeviceCredentialsFilter) StringDataEntry(org.thingsboard.server.common.data.kv.StringDataEntry) BasicTelemetryUploadRequest(org.thingsboard.server.common.msg.core.BasicTelemetryUploadRequest) DeviceTokenCredentials(org.thingsboard.server.common.data.security.DeviceTokenCredentials) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 5 with ComponentDescriptor

use of org.thingsboard.server.common.data.plugin.ComponentDescriptor in project thingsboard by thingsboard.

the class JpaBaseComponentDescriptorDaoTest method createComponentDescriptor.

private void createComponentDescriptor(ComponentType type, ComponentScope scope, int index) {
    ComponentDescriptor component = new ComponentDescriptor();
    component.setId(new ComponentDescriptorId(UUIDs.timeBased()));
    component.setType(type);
    component.setScope(scope);
    component.setName("COMPONENT_" + index);
    componentDescriptorDao.save(component);
}
Also used : ComponentDescriptor(org.thingsboard.server.common.data.plugin.ComponentDescriptor) ComponentDescriptorId(org.thingsboard.server.common.data.id.ComponentDescriptorId)

Aggregations

ComponentDescriptor (org.thingsboard.server.common.data.plugin.ComponentDescriptor)19 Test (org.junit.Test)5 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ComponentDescriptorId (org.thingsboard.server.common.data.id.ComponentDescriptorId)3 TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)2 PluginMetaData (org.thingsboard.server.common.data.plugin.PluginMetaData)2 AbstractJpaDaoTest (org.thingsboard.server.dao.AbstractJpaDaoTest)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 List (java.util.List)1 MessagingException (javax.mail.MessagingException)1 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)1 AnnotationTypeFilter (org.springframework.core.type.filter.AnnotationTypeFilter)1 Device (org.thingsboard.server.common.data.Device)1 BasicTsKvEntry (org.thingsboard.server.common.data.kv.BasicTsKvEntry)1 KvEntry (org.thingsboard.server.common.data.kv.KvEntry)1 StringDataEntry (org.thingsboard.server.common.data.kv.StringDataEntry)1 TsKvEntry (org.thingsboard.server.common.data.kv.TsKvEntry)1 ComponentType (org.thingsboard.server.common.data.plugin.ComponentType)1 DeviceCredentialsFilter (org.thingsboard.server.common.data.security.DeviceCredentialsFilter)1