Search in sources :

Example 26 with PluginMetaData

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

the class PluginController method getPlugins.

@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
@RequestMapping(value = "/plugins", method = RequestMethod.GET)
@ResponseBody
public List<PluginMetaData> getPlugins() throws ThingsboardException {
    try {
        if (getCurrentUser().getAuthority() == Authority.SYS_ADMIN) {
            return checkNotNull(pluginService.findSystemPlugins());
        } else {
            TenantId tenantId = getCurrentUser().getTenantId();
            List<PluginMetaData> plugins = checkNotNull(pluginService.findAllTenantPluginsByTenantId(tenantId));
            plugins.stream().filter(plugin -> plugin.getTenantId().getId().equals(ModelConstants.NULL_UUID)).forEach(plugin -> plugin.setConfiguration(null));
            return plugins;
        }
    } catch (Exception e) {
        throw handleException(e);
    }
}
Also used : ThingsboardException(org.thingsboard.server.exception.ThingsboardException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) TextPageData(org.thingsboard.server.common.data.page.TextPageData) Authority(org.thingsboard.server.common.data.security.Authority) TenantId(org.thingsboard.server.common.data.id.TenantId) ComponentLifecycleEvent(org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) ActionType(org.thingsboard.server.common.data.audit.ActionType) PluginId(org.thingsboard.server.common.data.id.PluginId) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) EntityType(org.thingsboard.server.common.data.EntityType) PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) ModelConstants(org.thingsboard.server.dao.model.ModelConstants) TenantId(org.thingsboard.server.common.data.id.TenantId) PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 27 with PluginMetaData

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

the class PluginController method suspendPluginById.

@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
@RequestMapping(value = "/plugin/{pluginId}/suspend", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
public void suspendPluginById(@PathVariable(PLUGIN_ID) String strPluginId) throws ThingsboardException {
    checkParameter(PLUGIN_ID, strPluginId);
    try {
        PluginId pluginId = new PluginId(toUUID(strPluginId));
        PluginMetaData plugin = checkPlugin(pluginService.findPluginById(pluginId));
        pluginService.suspendPluginById(pluginId);
        actorService.onPluginStateChange(plugin.getTenantId(), plugin.getId(), ComponentLifecycleEvent.SUSPENDED);
        logEntityAction(plugin.getId(), plugin, null, ActionType.SUSPENDED, null, strPluginId);
    } catch (Exception e) {
        logEntityAction(emptyId(EntityType.PLUGIN), null, null, ActionType.SUSPENDED, e, strPluginId);
        throw handleException(e);
    }
}
Also used : PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) PluginId(org.thingsboard.server.common.data.id.PluginId) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 28 with PluginMetaData

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

the class JpaBasePluginDao method findById.

@Override
public PluginMetaData findById(PluginId pluginId) {
    log.debug("Search plugin meta-data entity by id [{}]", pluginId);
    PluginMetaData pluginMetaData = super.findById(pluginId.getId());
    if (log.isTraceEnabled()) {
        log.trace("Search result: [{}] for plugin entity [{}]", pluginMetaData != null, pluginMetaData);
    } else {
        log.debug(SEARCH_RESULT, pluginMetaData != null);
    }
    return pluginMetaData;
}
Also used : PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData)

Example 29 with PluginMetaData

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

the class RuleActorMessageProcessor method fetchPluginInfo.

private void fetchPluginInfo() {
    if (!StringUtils.isEmpty(ruleMd.getPluginToken())) {
        PluginMetaData pluginMd = systemContext.getPluginService().findPluginByApiToken(ruleMd.getPluginToken());
        pluginTenantId = pluginMd.getTenantId();
        pluginId = pluginMd.getId();
    }
}
Also used : PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData)

Example 30 with PluginMetaData

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

the class BasePluginService method checkRulesAndDelete.

private void checkRulesAndDelete(UUID pluginId) {
    PluginMetaData plugin = pluginDao.findById(pluginId);
    List<RuleMetaData> affectedRules = ruleDao.findRulesByPlugin(plugin.getApiToken());
    if (affectedRules.isEmpty()) {
        pluginDao.deleteById(pluginId);
    } else {
        throw new DataValidationException("Plugin deletion will affect existing rules!");
    }
}
Also used : DataValidationException(org.thingsboard.server.dao.exception.DataValidationException) PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData)

Aggregations

PluginMetaData (org.thingsboard.server.common.data.plugin.PluginMetaData)50 Test (org.junit.Test)24 TenantId (org.thingsboard.server.common.data.id.TenantId)17 AbstractServiceTest (org.thingsboard.server.dao.service.AbstractServiceTest)14 TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)13 RuleMetaData (org.thingsboard.server.common.data.rule.RuleMetaData)13 PluginId (org.thingsboard.server.common.data.id.PluginId)8 TelemetryStoragePlugin (org.thingsboard.server.extensions.core.plugin.telemetry.TelemetryStoragePlugin)8 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 ThingsboardException (org.thingsboard.server.exception.ThingsboardException)5 ArrayList (java.util.ArrayList)4 TextPageData (org.thingsboard.server.common.data.page.TextPageData)4 List (java.util.List)3 UUID (java.util.UUID)3 Before (org.junit.Before)3 Tenant (org.thingsboard.server.common.data.Tenant)3 ComponentDescriptor (org.thingsboard.server.common.data.plugin.ComponentDescriptor)3 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)2