Browse Source

Merge pull request #15450 from thingsboard/port-openapi-master

API improvements porting merge
pull/15468/head
Viacheslav Klimov 1 month ago
committed by GitHub
parent
commit
55a73c0300
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 16
      application/src/main/java/org/thingsboard/server/config/SwaggerConfiguration.java
  2. 11
      application/src/main/java/org/thingsboard/server/controller/UserController.java
  3. 2
      application/src/main/java/org/thingsboard/server/controller/WidgetTypeController.java
  4. 7
      application/src/main/java/org/thingsboard/server/service/sync/ie/DefaultEntitiesExportImportService.java
  5. 28
      application/src/test/java/org/thingsboard/server/client/CalculatedFieldApiClientTest.java
  6. 6
      common/data/src/main/java/org/thingsboard/server/common/data/oauth2/OAuth2Client.java
  7. 2
      pom.xml

16
application/src/main/java/org/thingsboard/server/config/SwaggerConfiguration.java

@ -600,6 +600,22 @@ public class SwaggerConfiguration {
if (baseType != null) {
return baseType;
}
// Check if other oneOf items extend this candidate via allOf (parent-child without discriminator)
if (candidate != null) {
boolean isParent = oneOfSchemas.stream()
.filter(s -> s.get$ref() != null && !s.get$ref().equals(ref))
.anyMatch(s -> {
String otherName = s.get$ref().substring(s.get$ref().lastIndexOf('/') + 1);
Schema<?> otherSchema = schemas.get(otherName);
return otherSchema != null && otherSchema.getAllOf() != null &&
otherSchema.getAllOf().stream().anyMatch(
a -> a.get$ref() != null && a.get$ref().endsWith("/" + refName));
});
if (isParent) {
return refName;
}
}
}
return null;
}

11
application/src/main/java/org/thingsboard/server/controller/UserController.java

@ -549,8 +549,7 @@ public class UserController extends BaseController {
userSettingsService.deleteUserSettings(currentUser.getTenantId(), currentUser.getId(), type, Arrays.asList(paths.split(",")));
}
@ApiOperation(value = "Get information about last visited and starred dashboards (getUserDashboardsInfo)",
notes = "Fetch the list of last visited and starred dashboards. Both lists are limited to 10 items." + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
@Hidden
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
@GetMapping(value = "/user/dashboards")
public UserDashboardsInfo getUserDashboardsInfo() throws ThingsboardException {
@ -558,6 +557,14 @@ public class UserController extends BaseController {
return userSettingsService.findUserDashboardsInfo(currentUser.getTenantId(), currentUser.getId());
}
@ApiOperation(value = "Get information about last visited and starred dashboards (getLastVisitedDashboards)",
notes = "Fetch the list of last visited and starred dashboards. Both lists are limited to 10 items." + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
@GetMapping(value = "/user/lastVisitedDashboards")
public UserDashboardsInfo getLastVisitedDashboards() throws ThingsboardException {
return getUserDashboardsInfo();
}
@ApiOperation(value = "Report action of User over the dashboard (reportUserDashboardAction)",
notes = "Report action of User over the dashboard. " + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")

2
application/src/main/java/org/thingsboard/server/controller/WidgetTypeController.java

@ -242,7 +242,7 @@ public class WidgetTypeController extends AutoCommitController {
@ApiOperation(value = "Get all Widget types for specified Bundle (getBundleWidgetTypes)",
notes = "Returns an array of Widget Type objects that belong to specified Widget Bundle." + WIDGET_TYPE_DESCRIPTION + " " + SYSTEM_OR_TENANT_AUTHORITY_PARAGRAPH)
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
@GetMapping(value = "/widgetsBundles/{widgetsBundleId}/widgetTypes")
@GetMapping(value = "/widgetsBundle/{widgetsBundleId}/widgetTypes")
public List<WidgetType> getBundleWidgetTypes(
@Parameter(description = "Widget Bundle Id", required = true)
@PathVariable("widgetsBundleId") String strWidgetsBundleId) throws ThingsboardException {

7
application/src/main/java/org/thingsboard/server/service/sync/ie/DefaultEntitiesExportImportService.java

@ -64,7 +64,7 @@ public class DefaultEntitiesExportImportService implements EntitiesExportImportS
private final RateLimitService rateLimitService;
private final TbLogEntityActionService logEntityActionService;
protected static final List<EntityType> SUPPORTED_ENTITY_TYPES = List.of(
public static final List<EntityType> SUPPORTED_ENTITY_TYPES = List.of(
EntityType.CUSTOMER, EntityType.RULE_CHAIN, EntityType.TB_RESOURCE,
EntityType.DASHBOARD, EntityType.ASSET_PROFILE, EntityType.ASSET,
EntityType.DEVICE_PROFILE, EntityType.OTA_PACKAGE, EntityType.DEVICE,
@ -131,7 +131,10 @@ public class DefaultEntitiesExportImportService implements EntitiesExportImportS
@Override
public Comparator<EntityType> getEntityTypeComparatorForImport() {
return Comparator.comparing(SUPPORTED_ENTITY_TYPES::indexOf);
return Comparator.comparingInt(type -> {
int index = SUPPORTED_ENTITY_TYPES.indexOf(type);
return index >= 0 ? index : Integer.MAX_VALUE;
});
}
@SuppressWarnings("unchecked")

28
application/src/test/java/org/thingsboard/server/client/CalculatedFieldApiClientTest.java

@ -17,10 +17,8 @@ package org.thingsboard.server.client;
import org.junit.Test;
import org.thingsboard.client.model.AlarmCalculatedFieldConfiguration;
import org.thingsboard.client.model.AlarmConditionValueAlarmRuleSchedule;
import org.thingsboard.client.model.AlarmRuleDefinition;
import org.thingsboard.client.model.AlarmRuleSimpleCondition;
import org.thingsboard.client.model.AlarmRuleSpecificTimeSchedule;
import org.thingsboard.client.model.AlarmConditionValueAlarmSchedule;
import org.thingsboard.client.model.AlarmRule;
import org.thingsboard.client.model.AlarmSeverity;
import org.thingsboard.client.model.Argument;
import org.thingsboard.client.model.ArgumentType;
@ -30,7 +28,9 @@ import org.thingsboard.client.model.Device;
import org.thingsboard.client.model.EntityType;
import org.thingsboard.client.model.PageDataCalculatedField;
import org.thingsboard.client.model.ReferencedEntityKey;
import org.thingsboard.client.model.SimpleAlarmCondition;
import org.thingsboard.client.model.SimpleCalculatedFieldConfiguration;
import org.thingsboard.client.model.SpecificTimeSchedule;
import org.thingsboard.client.model.TbelAlarmConditionExpression;
import org.thingsboard.client.model.TimeSeriesOutput;
import org.thingsboard.server.dao.service.DaoSqlTest;
@ -198,12 +198,12 @@ public class CalculatedFieldApiClientTest extends AbstractApiClientTest {
// create rule: HIGH_TEMPERATURE when temp > 50 (TBEL expression)
TbelAlarmConditionExpression createExpression = new TbelAlarmConditionExpression();
createExpression.setExpression("return temp > 50;");
AlarmRuleSimpleCondition createCondition = new AlarmRuleSimpleCondition();
SimpleAlarmCondition createCondition = new SimpleAlarmCondition();
createCondition.setExpression(createExpression);
AlarmRuleSpecificTimeSchedule specificTimeSchedule = new AlarmRuleSpecificTimeSchedule().addDaysOfWeekItem(3);
AlarmConditionValueAlarmRuleSchedule schedule = new AlarmConditionValueAlarmRuleSchedule().staticValue(specificTimeSchedule);
SpecificTimeSchedule specificTimeSchedule = new SpecificTimeSchedule().addDaysOfWeekItem(3);
AlarmConditionValueAlarmSchedule schedule = new AlarmConditionValueAlarmSchedule().staticValue(specificTimeSchedule);
createCondition.setSchedule(schedule);
AlarmRuleDefinition createRule = new AlarmRuleDefinition();
AlarmRule createRule = new AlarmRule();
createRule.setCondition(createCondition);
createRule.setAlarmDetails("Temperature is too high: ${temp}");
config.setCreateRules(Map.of(
@ -213,9 +213,9 @@ public class CalculatedFieldApiClientTest extends AbstractApiClientTest {
// clear rule: when temp drops below 30
TbelAlarmConditionExpression clearExpression = new TbelAlarmConditionExpression();
clearExpression.setExpression("return temp < 30;");
AlarmRuleSimpleCondition clearCondition = new AlarmRuleSimpleCondition();
SimpleAlarmCondition clearCondition = new SimpleAlarmCondition();
clearCondition.setExpression(clearExpression);
AlarmRuleDefinition clearRule = new AlarmRuleDefinition();
AlarmRule clearRule = new AlarmRule();
clearRule.setCondition(clearCondition);
config.setClearRule(clearRule);
@ -236,8 +236,8 @@ public class CalculatedFieldApiClientTest extends AbstractApiClientTest {
assertEquals(cf.getName(), created.getName());
assertEquals(CalculatedFieldType.ALARM, created.getType());
AlarmCalculatedFieldConfiguration configuration = (AlarmCalculatedFieldConfiguration) created.getConfiguration();
AlarmConditionValueAlarmRuleSchedule createdSchedule = configuration.getCreateRules().get(AlarmSeverity.CRITICAL.name()).getCondition().getSchedule();
AlarmRuleSpecificTimeSchedule staticSchedule = (AlarmRuleSpecificTimeSchedule) createdSchedule.getStaticValue();
AlarmConditionValueAlarmSchedule createdSchedule = configuration.getCreateRules().get(AlarmSeverity.CRITICAL.name()).getCondition().getSchedule();
SpecificTimeSchedule staticSchedule = (SpecificTimeSchedule) createdSchedule.getStaticValue();
assertEquals(Set.of(3), staticSchedule.getDaysOfWeek());
// get by id and verify configuration
@ -257,9 +257,9 @@ public class CalculatedFieldApiClientTest extends AbstractApiClientTest {
// update: add a second create rule for CRITICAL_TEMPERATURE
TbelAlarmConditionExpression criticalExpression = new TbelAlarmConditionExpression();
criticalExpression.setExpression("return temp > 80;");
AlarmRuleSimpleCondition criticalCondition = new AlarmRuleSimpleCondition();
SimpleAlarmCondition criticalCondition = new SimpleAlarmCondition();
criticalCondition.setExpression(criticalExpression);
AlarmRuleDefinition criticalRule = new AlarmRuleDefinition();
AlarmRule criticalRule = new AlarmRule();
criticalRule.setCondition(criticalCondition);
fetchedConfig.putCreateRulesItem(AlarmSeverity.INDETERMINATE.name(), criticalRule);
fetched.setConfiguration(fetchedConfig);

6
common/data/src/main/java/org/thingsboard/server/common/data/oauth2/OAuth2Client.java

@ -93,7 +93,10 @@ public class OAuth2Client extends BaseDataWithAdditionalInfo<OAuth2ClientId> imp
@Schema(description = "List of platforms for which usage of the OAuth2 client is allowed (empty for all allowed)")
@Length(fieldName = "platforms")
private List<PlatformType> platforms;
@Schema(description = "Additional info of OAuth2 client (e.g. providerName)", requiredMode = Schema.RequiredMode.REQUIRED)
@Schema(description = "Additional info of OAuth2 client. " +
"Must include: 'providerName' (string, name of the OAuth2 provider).",
requiredMode = Schema.RequiredMode.REQUIRED,
example = "{\"providerName\":\"Google\"}")
private JsonNode additionalInfo;
public OAuth2Client() {
@ -128,4 +131,5 @@ public class OAuth2Client extends BaseDataWithAdditionalInfo<OAuth2ClientId> imp
public String getName() {
return title;
}
}

2
pom.xml

@ -62,7 +62,7 @@
<pkg.implementationTitle>${project.name}</pkg.implementationTitle>
<pkg.unixLogFolder>/var/log/${pkg.name}</pkg.unixLogFolder>
<pkg.installFolder>/usr/share/${pkg.name}</pkg.installFolder>
<thingsboard.client.version>4.4.0-SNAPSHOT</thingsboard.client.version>
<thingsboard.client.version>4.3.1.2-SNAPSHOT</thingsboard.client.version> <!-- TODO: update to 4.4.0-SNAPSHOT -->
<spring-boot.version>3.5.13</spring-boot.version>
<javax.xml.bind-api.version>2.4.0-b180830.0359</javax.xml.bind-api.version>
<jjwt.version>0.12.5</jjwt.version>

Loading…
Cancel
Save