324 changed files with 6650 additions and 2119 deletions
File diff suppressed because one or more lines are too long
@ -0,0 +1,45 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2023 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.controller; |
||||
|
|
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.security.access.prepost.PreAuthorize; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RequestMethod; |
||||
|
import org.springframework.web.bind.annotation.ResponseBody; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
import org.thingsboard.server.common.data.UsageInfo; |
||||
|
import org.thingsboard.server.common.data.exception.ThingsboardException; |
||||
|
import org.thingsboard.server.dao.usage.UsageInfoService; |
||||
|
import org.thingsboard.server.queue.util.TbCoreComponent; |
||||
|
|
||||
|
@RestController |
||||
|
@TbCoreComponent |
||||
|
@RequestMapping("/api") |
||||
|
@Slf4j |
||||
|
public class UsageInfoController extends BaseController { |
||||
|
|
||||
|
@Autowired |
||||
|
private UsageInfoService usageInfoService; |
||||
|
|
||||
|
@PreAuthorize("hasAuthority('TENANT_ADMIN')") |
||||
|
@RequestMapping(value = "/usage", method = RequestMethod.GET) |
||||
|
@ResponseBody |
||||
|
public UsageInfo getTenantUsageInfo() throws ThingsboardException { |
||||
|
return checkNotNull(usageInfoService.getUsageInfo(getCurrentUser().getTenantId())); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,202 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2023 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.service.entitiy.user; |
||||
|
|
||||
|
import com.fasterxml.jackson.databind.JsonNode; |
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.thingsboard.common.util.JacksonUtil; |
||||
|
import org.thingsboard.server.common.data.HasTitle; |
||||
|
import org.thingsboard.server.common.data.StringUtils; |
||||
|
import org.thingsboard.server.common.data.id.DashboardId; |
||||
|
import org.thingsboard.server.common.data.id.TenantId; |
||||
|
import org.thingsboard.server.common.data.id.UserId; |
||||
|
import org.thingsboard.server.common.data.settings.AbstractUserDashboardInfo; |
||||
|
import org.thingsboard.server.common.data.settings.LastVisitedDashboardInfo; |
||||
|
import org.thingsboard.server.common.data.settings.StarredDashboardInfo; |
||||
|
import org.thingsboard.server.common.data.settings.UserDashboardAction; |
||||
|
import org.thingsboard.server.common.data.settings.UserDashboardsInfo; |
||||
|
import org.thingsboard.server.common.data.settings.UserSettings; |
||||
|
import org.thingsboard.server.common.data.settings.UserSettingsType; |
||||
|
import org.thingsboard.server.dao.dashboard.DashboardService; |
||||
|
import org.thingsboard.server.dao.user.UserSettingsService; |
||||
|
import org.thingsboard.server.queue.util.TbCoreComponent; |
||||
|
|
||||
|
import java.util.Comparator; |
||||
|
import java.util.HashMap; |
||||
|
import java.util.HashSet; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
import java.util.Set; |
||||
|
import java.util.UUID; |
||||
|
import java.util.function.Function; |
||||
|
import java.util.function.Predicate; |
||||
|
import java.util.stream.Collectors; |
||||
|
|
||||
|
@Service |
||||
|
@TbCoreComponent |
||||
|
@AllArgsConstructor |
||||
|
@Slf4j |
||||
|
public class DefaultTbUserSettingsService implements TbUserSettingsService { |
||||
|
|
||||
|
private static final int MAX_DASHBOARD_INFO_LIST_SIZE = 10; |
||||
|
private static final Predicate<HasTitle> EMPTY_TITLE = i -> StringUtils.isEmpty(i.getTitle()); |
||||
|
|
||||
|
private final UserSettingsService settingsService; |
||||
|
private final DashboardService dashboardService; |
||||
|
|
||||
|
@Override |
||||
|
public UserSettings saveUserSettings(TenantId tenantId, UserSettings userSettings) { |
||||
|
return settingsService.saveUserSettings(tenantId, userSettings); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void updateUserSettings(TenantId tenantId, UserId userId, UserSettingsType type, JsonNode settings) { |
||||
|
settingsService.updateUserSettings(tenantId, userId, type, settings); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public UserSettings findUserSettings(TenantId tenantId, UserId userId, UserSettingsType type) { |
||||
|
return settingsService.findUserSettings(tenantId, userId, type); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void deleteUserSettings(TenantId tenantId, UserId userId, UserSettingsType type, List<String> jsonPaths) { |
||||
|
settingsService.deleteUserSettings(tenantId, userId, type, jsonPaths); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public UserDashboardsInfo findUserDashboardsInfo(TenantId tenantId, UserId id) { |
||||
|
UserSettings us = findUserSettings(tenantId, id, UserSettingsType.VISITED_DASHBOARDS); |
||||
|
if (us == null) { |
||||
|
return UserDashboardsInfo.EMPTY; |
||||
|
} |
||||
|
UserDashboardsInfo stored = JacksonUtil.convertValue(us.getSettings(), UserDashboardsInfo.class); |
||||
|
return refreshDashboardTitles(tenantId, stored); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public UserDashboardsInfo reportUserDashboardAction(TenantId tenantId, UserId id, DashboardId dashboardId, UserDashboardAction action) { |
||||
|
UserSettings us = findUserSettings(tenantId, id, UserSettingsType.VISITED_DASHBOARDS); |
||||
|
UserDashboardsInfo stored = null; |
||||
|
if (us != null) { |
||||
|
stored = JacksonUtil.convertValue(us.getSettings(), UserDashboardsInfo.class); |
||||
|
} |
||||
|
if (stored == null) { |
||||
|
stored = new UserDashboardsInfo(); |
||||
|
} |
||||
|
|
||||
|
switch (action) { |
||||
|
case STAR: |
||||
|
addToStarred(stored, dashboardId); |
||||
|
break; |
||||
|
case UNSTAR: |
||||
|
removeFromStarred(stored, dashboardId); |
||||
|
break; |
||||
|
case VISIT: |
||||
|
addToVisited(stored, dashboardId); |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
stored = refreshDashboardTitles(tenantId, stored); |
||||
|
|
||||
|
us = new UserSettings(); |
||||
|
us.setUserId(id); |
||||
|
us.setType(UserSettingsType.VISITED_DASHBOARDS); |
||||
|
us.setSettings(JacksonUtil.valueToTree(stored)); |
||||
|
saveUserSettings(tenantId, us); |
||||
|
return stored; |
||||
|
} |
||||
|
|
||||
|
private void addToVisited(UserDashboardsInfo stored, DashboardId dashboardId) { |
||||
|
UUID id = dashboardId.getId(); |
||||
|
long ts = System.currentTimeMillis(); |
||||
|
var opt = stored.getLast().stream().filter(filterById(id)).findFirst(); |
||||
|
if (opt.isPresent()) { |
||||
|
opt.get().setLastVisited(ts); |
||||
|
} else { |
||||
|
var newInfo = new LastVisitedDashboardInfo(); |
||||
|
newInfo.setId(id); |
||||
|
newInfo.setStarred(stored.getStarred().stream().anyMatch(filterById(id))); |
||||
|
newInfo.setLastVisited(System.currentTimeMillis()); |
||||
|
stored.getLast().add(newInfo); |
||||
|
} |
||||
|
stored.getLast().sort(Comparator.comparing(LastVisitedDashboardInfo::getLastVisited).reversed()); |
||||
|
if (stored.getLast().size() > MAX_DASHBOARD_INFO_LIST_SIZE) { |
||||
|
stored.setLast(stored.getLast().stream().limit(MAX_DASHBOARD_INFO_LIST_SIZE).collect(Collectors.toList())); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private void removeFromStarred(UserDashboardsInfo stored, DashboardId dashboardId) { |
||||
|
UUID id = dashboardId.getId(); |
||||
|
stored.getStarred().removeIf(filterById(id)); |
||||
|
stored.getLast().stream().filter(d -> id.equals(d.getId())).findFirst().ifPresent(d -> d.setStarred(false)); |
||||
|
} |
||||
|
|
||||
|
private void addToStarred(UserDashboardsInfo stored, DashboardId dashboardId) { |
||||
|
UUID id = dashboardId.getId(); |
||||
|
long ts = System.currentTimeMillis(); |
||||
|
var opt = stored.getStarred().stream().filter(filterById(id)).findFirst(); |
||||
|
if (opt.isPresent()) { |
||||
|
opt.get().setStarredAt(ts); |
||||
|
} else { |
||||
|
var newInfo = new StarredDashboardInfo(); |
||||
|
newInfo.setId(id); |
||||
|
newInfo.setStarredAt(System.currentTimeMillis()); |
||||
|
stored.getStarred().add(newInfo); |
||||
|
} |
||||
|
stored.getStarred().sort(Comparator.comparing(StarredDashboardInfo::getStarredAt).reversed()); |
||||
|
if (stored.getStarred().size() > MAX_DASHBOARD_INFO_LIST_SIZE) { |
||||
|
stored.setStarred(stored.getStarred().stream().limit(MAX_DASHBOARD_INFO_LIST_SIZE).collect(Collectors.toList())); |
||||
|
} |
||||
|
Set<UUID> starredMap = |
||||
|
stored.getStarred().stream().map(AbstractUserDashboardInfo::getId).collect(Collectors.toSet()); |
||||
|
stored.getLast().forEach(d -> d.setStarred(starredMap.contains(d.getId()))); |
||||
|
} |
||||
|
|
||||
|
private Predicate<AbstractUserDashboardInfo> filterById(UUID id) { |
||||
|
return d -> id.equals(d.getId()); |
||||
|
} |
||||
|
|
||||
|
private UserDashboardsInfo refreshDashboardTitles(TenantId tenantId, UserDashboardsInfo stored) { |
||||
|
if (stored == null) { |
||||
|
return UserDashboardsInfo.EMPTY; |
||||
|
} |
||||
|
stored.getLast().forEach(i -> i.setTitle(null)); |
||||
|
stored.getStarred().forEach(i -> i.setTitle(null)); |
||||
|
|
||||
|
Set<UUID> uniqueIds = new HashSet<>(); |
||||
|
stored.getLast().stream().map(AbstractUserDashboardInfo::getId).forEach(uniqueIds::add); |
||||
|
stored.getStarred().stream().map(AbstractUserDashboardInfo::getId).forEach(uniqueIds::add); |
||||
|
|
||||
|
Map<UUID, String> dashboardTitles = new HashMap<>(); |
||||
|
uniqueIds.forEach(id -> { |
||||
|
var title = dashboardService.findDashboardTitleById(tenantId, new DashboardId(id)); |
||||
|
if (StringUtils.isNotEmpty(title)) { |
||||
|
dashboardTitles.put(id, title); |
||||
|
} |
||||
|
} |
||||
|
); |
||||
|
|
||||
|
stored.getLast().forEach(i -> i.setTitle(dashboardTitles.get(i.getId()))); |
||||
|
stored.getLast().removeIf(EMPTY_TITLE); |
||||
|
stored.getStarred().forEach(i -> i.setTitle(dashboardTitles.get(i.getId()))); |
||||
|
stored.getStarred().removeIf(EMPTY_TITLE); |
||||
|
return stored; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,42 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2023 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.service.entitiy.user; |
||||
|
|
||||
|
import com.fasterxml.jackson.databind.JsonNode; |
||||
|
import org.thingsboard.server.common.data.id.DashboardId; |
||||
|
import org.thingsboard.server.common.data.id.TenantId; |
||||
|
import org.thingsboard.server.common.data.id.UserId; |
||||
|
import org.thingsboard.server.common.data.settings.UserDashboardAction; |
||||
|
import org.thingsboard.server.common.data.settings.UserDashboardsInfo; |
||||
|
import org.thingsboard.server.common.data.settings.UserSettings; |
||||
|
import org.thingsboard.server.common.data.settings.UserSettingsType; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
public interface TbUserSettingsService { |
||||
|
|
||||
|
void updateUserSettings(TenantId tenantId, UserId userId, UserSettingsType type, JsonNode settings); |
||||
|
|
||||
|
UserSettings saveUserSettings(TenantId tenantId, UserSettings userSettings); |
||||
|
|
||||
|
UserSettings findUserSettings(TenantId tenantId, UserId userId, UserSettingsType type); |
||||
|
|
||||
|
void deleteUserSettings(TenantId tenantId, UserId userId, UserSettingsType type, List<String> jsonPaths); |
||||
|
|
||||
|
UserDashboardsInfo findUserDashboardsInfo(TenantId tenantId, UserId id); |
||||
|
|
||||
|
UserDashboardsInfo reportUserDashboardAction(TenantId tenantId, UserId id, DashboardId dashboardId, UserDashboardAction action); |
||||
|
} |
||||
@ -0,0 +1,59 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2023 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.service.notification.rule.trigger; |
||||
|
|
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.thingsboard.server.common.data.notification.info.ApiUsageLimitNotificationInfo; |
||||
|
import org.thingsboard.server.common.data.notification.info.RuleOriginatedNotificationInfo; |
||||
|
import org.thingsboard.server.common.data.notification.rule.trigger.ApiUsageLimitNotificationRuleTriggerConfig; |
||||
|
import org.thingsboard.server.common.data.notification.rule.trigger.NotificationRuleTriggerType; |
||||
|
import org.thingsboard.server.common.msg.notification.trigger.ApiUsageLimitTrigger; |
||||
|
import org.thingsboard.server.dao.tenant.TenantService; |
||||
|
|
||||
|
import static org.apache.commons.collections.CollectionUtils.isEmpty; |
||||
|
|
||||
|
@Service |
||||
|
@RequiredArgsConstructor |
||||
|
public class ApiUsageLimitTriggerProcessor implements NotificationRuleTriggerProcessor<ApiUsageLimitTrigger, ApiUsageLimitNotificationRuleTriggerConfig> { |
||||
|
|
||||
|
private final TenantService tenantService; |
||||
|
|
||||
|
@Override |
||||
|
public boolean matchesFilter(ApiUsageLimitTrigger trigger, ApiUsageLimitNotificationRuleTriggerConfig triggerConfig) { |
||||
|
return (isEmpty(triggerConfig.getApiFeatures()) || triggerConfig.getApiFeatures().contains(trigger.getState().getApiFeature())) && |
||||
|
(isEmpty(triggerConfig.getNotifyOn()) || triggerConfig.getNotifyOn().contains(trigger.getStatus())); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public RuleOriginatedNotificationInfo constructNotificationInfo(ApiUsageLimitTrigger trigger) { |
||||
|
return ApiUsageLimitNotificationInfo.builder() |
||||
|
.feature(trigger.getState().getApiFeature()) |
||||
|
.recordKey(trigger.getState().getKey()) |
||||
|
.status(trigger.getStatus()) |
||||
|
.limit(trigger.getState().getThresholdAsString()) |
||||
|
.currentValue(trigger.getState().getValueAsString()) |
||||
|
.tenantId(trigger.getTenantId()) |
||||
|
.tenantName(tenantService.findTenantById(trigger.getTenantId()).getName()) |
||||
|
.build(); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public NotificationRuleTriggerType getTriggerType() { |
||||
|
return NotificationRuleTriggerType.API_USAGE_LIMIT; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,67 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2023 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.service.subscription; |
||||
|
|
||||
|
import lombok.Getter; |
||||
|
import lombok.Setter; |
||||
|
import lombok.ToString; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.thingsboard.server.common.data.query.AlarmCountQuery; |
||||
|
import org.thingsboard.server.dao.alarm.AlarmService; |
||||
|
import org.thingsboard.server.dao.attributes.AttributesService; |
||||
|
import org.thingsboard.server.dao.entity.EntityService; |
||||
|
import org.thingsboard.server.service.ws.WebSocketService; |
||||
|
import org.thingsboard.server.service.ws.WebSocketSessionRef; |
||||
|
import org.thingsboard.server.service.ws.telemetry.cmd.v2.AlarmCountUpdate; |
||||
|
|
||||
|
@Slf4j |
||||
|
@ToString(callSuper = true) |
||||
|
public class TbAlarmCountSubCtx extends TbAbstractSubCtx<AlarmCountQuery> { |
||||
|
|
||||
|
private final AlarmService alarmService; |
||||
|
|
||||
|
@Getter |
||||
|
@Setter |
||||
|
private volatile int result; |
||||
|
|
||||
|
public TbAlarmCountSubCtx(String serviceId, WebSocketService wsService, |
||||
|
EntityService entityService, TbLocalSubscriptionService localSubscriptionService, |
||||
|
AttributesService attributesService, SubscriptionServiceStatistics stats, AlarmService alarmService, |
||||
|
WebSocketSessionRef sessionRef, int cmdId) { |
||||
|
super(serviceId, wsService, entityService, localSubscriptionService, attributesService, stats, sessionRef, cmdId); |
||||
|
this.alarmService = alarmService; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void fetchData() { |
||||
|
result = (int) alarmService.countAlarmsByQuery(getTenantId(), getCustomerId(), query); |
||||
|
sendWsMsg(new AlarmCountUpdate(cmdId, result)); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
protected void update() { |
||||
|
int newCount = (int) alarmService.countAlarmsByQuery(getTenantId(), getCustomerId(), query); |
||||
|
if (newCount != result) { |
||||
|
result = newCount; |
||||
|
sendWsMsg(new AlarmCountUpdate(cmdId, result)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public boolean isDynamic() { |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,34 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2023 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.service.ws.telemetry.cmd.v2; |
||||
|
|
||||
|
import com.fasterxml.jackson.annotation.JsonCreator; |
||||
|
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
|
import lombok.Getter; |
||||
|
import org.thingsboard.server.common.data.query.AlarmCountQuery; |
||||
|
|
||||
|
public class AlarmCountCmd extends DataCmd { |
||||
|
|
||||
|
@Getter |
||||
|
private final AlarmCountQuery query; |
||||
|
|
||||
|
@JsonCreator |
||||
|
public AlarmCountCmd(@JsonProperty("cmdId") int cmdId, |
||||
|
@JsonProperty("query") AlarmCountQuery query) { |
||||
|
super(cmdId); |
||||
|
this.query = query; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,53 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2023 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.service.ws.telemetry.cmd.v2; |
||||
|
|
||||
|
import com.fasterxml.jackson.annotation.JsonCreator; |
||||
|
import com.fasterxml.jackson.annotation.JsonProperty; |
||||
|
import lombok.Getter; |
||||
|
import lombok.ToString; |
||||
|
import org.thingsboard.server.service.subscription.SubscriptionErrorCode; |
||||
|
|
||||
|
@ToString |
||||
|
public class AlarmCountUpdate extends CmdUpdate { |
||||
|
|
||||
|
@Getter |
||||
|
private int count; |
||||
|
|
||||
|
public AlarmCountUpdate(int cmdId, int count) { |
||||
|
super(cmdId, SubscriptionErrorCode.NO_ERROR.getCode(), null); |
||||
|
this.count = count; |
||||
|
} |
||||
|
|
||||
|
public AlarmCountUpdate(int cmdId, int errorCode, String errorMsg) { |
||||
|
super(cmdId, errorCode, errorMsg); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public CmdUpdateType getCmdUpdateType() { |
||||
|
return CmdUpdateType.ALARM_COUNT_DATA; |
||||
|
} |
||||
|
|
||||
|
@JsonCreator |
||||
|
public AlarmCountUpdate(@JsonProperty("cmdId") int cmdId, |
||||
|
@JsonProperty("count") int count, |
||||
|
@JsonProperty("errorCode") int errorCode, |
||||
|
@JsonProperty("errorMsg") String errorMsg) { |
||||
|
super(cmdId, errorCode, errorMsg); |
||||
|
this.count = count; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,26 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2023 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.dao.entity; |
||||
|
|
||||
|
import org.thingsboard.server.common.data.EntityType; |
||||
|
import org.thingsboard.server.common.data.id.TenantId; |
||||
|
|
||||
|
public interface EntityCountService { |
||||
|
|
||||
|
long countByTenantIdAndEntityType(TenantId tenantId, EntityType entityType); |
||||
|
|
||||
|
void publishCountEntityEvictEvent(TenantId tenantId, EntityType entityType); |
||||
|
} |
||||
@ -0,0 +1,48 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2023 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.common.data; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
|
||||
|
@Data |
||||
|
public class ApiUsageRecordState implements Serializable { |
||||
|
|
||||
|
private final ApiFeature apiFeature; |
||||
|
private final ApiUsageRecordKey key; |
||||
|
private final long threshold; |
||||
|
private final long value; |
||||
|
|
||||
|
public String getValueAsString() { |
||||
|
return valueAsString(value); |
||||
|
} |
||||
|
|
||||
|
public String getThresholdAsString() { |
||||
|
return valueAsString(threshold); |
||||
|
} |
||||
|
|
||||
|
private String valueAsString(long value) { |
||||
|
if (value > 1_000_000 && value % 1_000_000 < 10_000) { |
||||
|
return value / 1_000_000 + "M"; |
||||
|
} else if (value > 10_000) { |
||||
|
return String.format("%.2fM", ((double) value) / 1_000_000); |
||||
|
} else { |
||||
|
return value + ""; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,43 @@ |
|||||
|
/** |
||||
|
* Copyright © 2016-2023 The Thingsboard Authors |
||||
|
* |
||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
* you may not use this file except in compliance with the License. |
||||
|
* You may obtain a copy of the License at |
||||
|
* |
||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
* |
||||
|
* Unless required by applicable law or agreed to in writing, software |
||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
* See the License for the specific language governing permissions and |
||||
|
* limitations under the License. |
||||
|
*/ |
||||
|
package org.thingsboard.server.common.data; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
@Data |
||||
|
public class UsageInfo { |
||||
|
private long devices; |
||||
|
private long maxDevices; |
||||
|
private long assets; |
||||
|
private long maxAssets; |
||||
|
private long customers; |
||||
|
private long maxCustomers; |
||||
|
private long users; |
||||
|
private long maxUsers; |
||||
|
private long dashboards; |
||||
|
private long maxDashboards; |
||||
|
|
||||
|
private long transportMessages; |
||||
|
private long maxTransportMessages; |
||||
|
private long jsExecutions; |
||||
|
private long maxJsExecutions; |
||||
|
private long emails; |
||||
|
private long maxEmails; |
||||
|
private long sms; |
||||
|
private long maxSms; |
||||
|
private long alarms; |
||||
|
private long maxAlarms; |
||||
|
} |
||||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue