Search in sources :

Example 56 with TenantId

use of org.thingsboard.server.common.data.id.TenantId in project thingsboard by thingsboard.

the class WidgetTypeController method getWidgetType.

@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/widgetType", params = { "isSystem", "bundleAlias", "alias" }, method = RequestMethod.GET)
@ResponseBody
public WidgetType getWidgetType(@RequestParam boolean isSystem, @RequestParam String bundleAlias, @RequestParam String alias) throws ThingsboardException {
    try {
        TenantId tenantId;
        if (isSystem) {
            tenantId = new TenantId(ModelConstants.NULL_UUID);
        } else {
            tenantId = getCurrentUser().getTenantId();
        }
        WidgetType widgetType = widgetTypeService.findWidgetTypeByTenantIdBundleAliasAndAlias(tenantId, bundleAlias, alias);
        checkWidgetType(widgetType, false);
        return widgetType;
    } catch (Exception e) {
        throw handleException(e);
    }
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) WidgetType(org.thingsboard.server.common.data.widget.WidgetType) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 57 with TenantId

use of org.thingsboard.server.common.data.id.TenantId 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 58 with TenantId

use of org.thingsboard.server.common.data.id.TenantId in project thingsboard by thingsboard.

the class DashboardController method getCustomerDashboards.

@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/customer/{customerId}/dashboards", params = { "limit" }, method = RequestMethod.GET)
@ResponseBody
public TimePageData<DashboardInfo> getCustomerDashboards(@PathVariable("customerId") String strCustomerId, @RequestParam int limit, @RequestParam(required = false) Long startTime, @RequestParam(required = false) Long endTime, @RequestParam(required = false, defaultValue = "false") boolean ascOrder, @RequestParam(required = false) String offset) throws ThingsboardException {
    checkParameter("customerId", strCustomerId);
    try {
        TenantId tenantId = getCurrentUser().getTenantId();
        CustomerId customerId = new CustomerId(toUUID(strCustomerId));
        checkCustomerId(customerId);
        TimePageLink pageLink = createPageLink(limit, startTime, endTime, ascOrder, offset);
        return checkNotNull(dashboardService.findDashboardsByTenantIdAndCustomerId(tenantId, customerId, pageLink).get());
    } catch (Exception e) {
        throw handleException(e);
    }
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) CustomerId(org.thingsboard.server.common.data.id.CustomerId) TimePageLink(org.thingsboard.server.common.data.page.TimePageLink) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 59 with TenantId

use of org.thingsboard.server.common.data.id.TenantId in project thingsboard by thingsboard.

the class TelemetryRuleMsgHandler method handleTelemetryUploadRequest.

@Override
public void handleTelemetryUploadRequest(PluginContext ctx, TenantId tenantId, RuleId ruleId, TelemetryUploadRequestRuleToPluginMsg msg) {
    TelemetryUploadRequest request = msg.getPayload();
    List<TsKvEntry> tsKvEntries = new ArrayList<>();
    for (Map.Entry<Long, List<KvEntry>> entry : request.getData().entrySet()) {
        for (KvEntry kv : entry.getValue()) {
            tsKvEntries.add(new BasicTsKvEntry(entry.getKey(), kv));
        }
    }
    ctx.saveTsData(msg.getDeviceId(), tsKvEntries, msg.getTtl(), new PluginCallback<Void>() {

        @Override
        public void onSuccess(PluginContext ctx, Void data) {
            ctx.reply(new ResponsePluginToRuleMsg(msg.getUid(), tenantId, ruleId, BasicStatusCodeResponse.onSuccess(request.getMsgType(), request.getRequestId())));
            subscriptionManager.onLocalSubscriptionUpdate(ctx, msg.getDeviceId(), SubscriptionType.TIMESERIES, s -> prepareSubscriptionUpdate(request, s));
        }

        @Override
        public void onFailure(PluginContext ctx, Exception e) {
            log.error("Failed to process telemetry upload request", e);
            ctx.reply(new ResponsePluginToRuleMsg(msg.getUid(), tenantId, ruleId, BasicStatusCodeResponse.onError(request.getMsgType(), request.getRequestId(), e)));
        }
    });
}
Also used : DeviceId(org.thingsboard.server.common.data.id.DeviceId) RuleId(org.thingsboard.server.common.data.id.RuleId) java.util(java.util) DataConstants(org.thingsboard.server.common.data.DataConstants) org.thingsboard.server.common.msg.core(org.thingsboard.server.common.msg.core) UpdateAttributesRequestRuleToPluginMsg(org.thingsboard.server.extensions.api.plugins.msg.UpdateAttributesRequestRuleToPluginMsg) SubscriptionManager(org.thingsboard.server.extensions.core.plugin.telemetry.SubscriptionManager) ResponsePluginToRuleMsg(org.thingsboard.server.extensions.api.plugins.msg.ResponsePluginToRuleMsg) BasicAttributeKVMsg(org.thingsboard.server.common.msg.kv.BasicAttributeKVMsg) Collectors(java.util.stream.Collectors) TenantId(org.thingsboard.server.common.data.id.TenantId) SubscriptionType(org.thingsboard.server.extensions.core.plugin.telemetry.sub.SubscriptionType) BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) Slf4j(lombok.extern.slf4j.Slf4j) GetAttributesRequestRuleToPluginMsg(org.thingsboard.server.extensions.api.plugins.msg.GetAttributesRequestRuleToPluginMsg) PluginContext(org.thingsboard.server.extensions.api.plugins.PluginContext) DefaultRuleMsgHandler(org.thingsboard.server.extensions.api.plugins.handlers.DefaultRuleMsgHandler) KvEntry(org.thingsboard.server.common.data.kv.KvEntry) PluginCallback(org.thingsboard.server.extensions.api.plugins.PluginCallback) TelemetryUploadRequestRuleToPluginMsg(org.thingsboard.server.extensions.api.plugins.msg.TelemetryUploadRequestRuleToPluginMsg) Subscription(org.thingsboard.server.extensions.core.plugin.telemetry.sub.Subscription) BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) PluginContext(org.thingsboard.server.extensions.api.plugins.PluginContext) BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) KvEntry(org.thingsboard.server.common.data.kv.KvEntry) ResponsePluginToRuleMsg(org.thingsboard.server.extensions.api.plugins.msg.ResponsePluginToRuleMsg)

Example 60 with TenantId

use of org.thingsboard.server.common.data.id.TenantId in project thingsboard by thingsboard.

the class AppActor method processDeviceMsg.

private void processDeviceMsg(ToDeviceActorMsg toDeviceActorMsg) {
    TenantId tenantId = toDeviceActorMsg.getTenantId();
    ActorRef tenantActor = getOrCreateTenantActor(tenantId);
    if (toDeviceActorMsg.getPayload().getMsgType().requiresRulesProcessing()) {
        tenantActor.tell(new RuleChainDeviceMsg(toDeviceActorMsg, ruleManager.getRuleChain(this.context())), context().self());
    } else {
        tenantActor.tell(toDeviceActorMsg, context().self());
    }
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) RuleChainDeviceMsg(org.thingsboard.server.actors.tenant.RuleChainDeviceMsg)

Aggregations

TenantId (org.thingsboard.server.common.data.id.TenantId)119 Test (org.junit.Test)44 TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)38 CustomerId (org.thingsboard.server.common.data.id.CustomerId)30 ArrayList (java.util.ArrayList)26 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)24 Tenant (org.thingsboard.server.common.data.Tenant)23 ThingsboardException (org.thingsboard.server.exception.ThingsboardException)23 PluginMetaData (org.thingsboard.server.common.data.plugin.PluginMetaData)16 Customer (org.thingsboard.server.common.data.Customer)14 User (org.thingsboard.server.common.data.User)14 WidgetsBundle (org.thingsboard.server.common.data.widget.WidgetsBundle)13 DeviceId (org.thingsboard.server.common.data.id.DeviceId)10 RuleMetaData (org.thingsboard.server.common.data.rule.RuleMetaData)10 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)10 AbstractServiceTest (org.thingsboard.server.dao.service.AbstractServiceTest)10 UserId (org.thingsboard.server.common.data.id.UserId)8 TimePageLink (org.thingsboard.server.common.data.page.TimePageLink)8 IOException (java.io.IOException)7 PluginId (org.thingsboard.server.common.data.id.PluginId)7