Browse Source

Merge remote-tracking branch 'origin/port-openapi' into port-openapi-master

pull/15450/head
Viacheslav Klimov 6 months ago
parent
commit
614d413306
Failed to extract signature
  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) { if (baseType != null) {
return baseType; 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; 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(","))); userSettingsService.deleteUserSettings(currentUser.getTenantId(), currentUser.getId(), type, Arrays.asList(paths.split(",")));
} }
@ApiOperation(value = "Get information about last visited and starred dashboards (getUserDashboardsInfo)", @Hidden
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')") @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
@GetMapping(value = "/user/dashboards") @GetMapping(value = "/user/dashboards")
public UserDashboardsInfo getUserDashboardsInfo() throws ThingsboardException { public UserDashboardsInfo getUserDashboardsInfo() throws ThingsboardException {
@ -558,6 +557,14 @@ public class UserController extends BaseController {
return userSettingsService.findUserDashboardsInfo(currentUser.getTenantId(), currentUser.getId()); 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)", @ApiOperation(value = "Report action of User over the dashboard (reportUserDashboardAction)",
notes = "Report action of User over the dashboard. " + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH) notes = "Report action of User over the dashboard. " + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") @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)", @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) 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')") @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
@GetMapping(value = "/widgetsBundles/{widgetsBundleId}/widgetTypes") @GetMapping(value = "/widgetsBundle/{widgetsBundleId}/widgetTypes")
public List<WidgetType> getBundleWidgetTypes( public List<WidgetType> getBundleWidgetTypes(
@Parameter(description = "Widget Bundle Id", required = true) @Parameter(description = "Widget Bundle Id", required = true)
@PathVariable("widgetsBundleId") String strWidgetsBundleId) throws ThingsboardException { @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 RateLimitService rateLimitService;
private final TbLogEntityActionService logEntityActionService; 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.CUSTOMER, EntityType.RULE_CHAIN, EntityType.TB_RESOURCE,
EntityType.DASHBOARD, EntityType.ASSET_PROFILE, EntityType.ASSET, EntityType.DASHBOARD, EntityType.ASSET_PROFILE, EntityType.ASSET,
EntityType.DEVICE_PROFILE, EntityType.OTA_PACKAGE, EntityType.DEVICE, EntityType.DEVICE_PROFILE, EntityType.OTA_PACKAGE, EntityType.DEVICE,
@ -131,7 +131,10 @@ public class DefaultEntitiesExportImportService implements EntitiesExportImportS
@Override @Override
public Comparator<EntityType> getEntityTypeComparatorForImport() { 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") @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.junit.Test;
import org.thingsboard.client.model.AlarmCalculatedFieldConfiguration; import org.thingsboard.client.model.AlarmCalculatedFieldConfiguration;
import org.thingsboard.client.model.AlarmConditionValueAlarmRuleSchedule; import org.thingsboard.client.model.AlarmConditionValueAlarmSchedule;
import org.thingsboard.client.model.AlarmRuleDefinition; import org.thingsboard.client.model.AlarmRule;
import org.thingsboard.client.model.AlarmRuleSimpleCondition;
import org.thingsboard.client.model.AlarmRuleSpecificTimeSchedule;
import org.thingsboard.client.model.AlarmSeverity; import org.thingsboard.client.model.AlarmSeverity;
import org.thingsboard.client.model.Argument; import org.thingsboard.client.model.Argument;
import org.thingsboard.client.model.ArgumentType; 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.EntityType;
import org.thingsboard.client.model.PageDataCalculatedField; import org.thingsboard.client.model.PageDataCalculatedField;
import org.thingsboard.client.model.ReferencedEntityKey; import org.thingsboard.client.model.ReferencedEntityKey;
import org.thingsboard.client.model.SimpleAlarmCondition;
import org.thingsboard.client.model.SimpleCalculatedFieldConfiguration; import org.thingsboard.client.model.SimpleCalculatedFieldConfiguration;
import org.thingsboard.client.model.SpecificTimeSchedule;
import org.thingsboard.client.model.TbelAlarmConditionExpression; import org.thingsboard.client.model.TbelAlarmConditionExpression;
import org.thingsboard.client.model.TimeSeriesOutput; import org.thingsboard.client.model.TimeSeriesOutput;
import org.thingsboard.server.dao.service.DaoSqlTest; 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) // create rule: HIGH_TEMPERATURE when temp > 50 (TBEL expression)
TbelAlarmConditionExpression createExpression = new TbelAlarmConditionExpression(); TbelAlarmConditionExpression createExpression = new TbelAlarmConditionExpression();
createExpression.setExpression("return temp > 50;"); createExpression.setExpression("return temp > 50;");
AlarmRuleSimpleCondition createCondition = new AlarmRuleSimpleCondition(); SimpleAlarmCondition createCondition = new SimpleAlarmCondition();
createCondition.setExpression(createExpression); createCondition.setExpression(createExpression);
AlarmRuleSpecificTimeSchedule specificTimeSchedule = new AlarmRuleSpecificTimeSchedule().addDaysOfWeekItem(3); SpecificTimeSchedule specificTimeSchedule = new SpecificTimeSchedule().addDaysOfWeekItem(3);
AlarmConditionValueAlarmRuleSchedule schedule = new AlarmConditionValueAlarmRuleSchedule().staticValue(specificTimeSchedule); AlarmConditionValueAlarmSchedule schedule = new AlarmConditionValueAlarmSchedule().staticValue(specificTimeSchedule);
createCondition.setSchedule(schedule); createCondition.setSchedule(schedule);
AlarmRuleDefinition createRule = new AlarmRuleDefinition(); AlarmRule createRule = new AlarmRule();
createRule.setCondition(createCondition); createRule.setCondition(createCondition);
createRule.setAlarmDetails("Temperature is too high: ${temp}"); createRule.setAlarmDetails("Temperature is too high: ${temp}");
config.setCreateRules(Map.of( config.setCreateRules(Map.of(
@ -213,9 +213,9 @@ public class CalculatedFieldApiClientTest extends AbstractApiClientTest {
// clear rule: when temp drops below 30 // clear rule: when temp drops below 30
TbelAlarmConditionExpression clearExpression = new TbelAlarmConditionExpression(); TbelAlarmConditionExpression clearExpression = new TbelAlarmConditionExpression();
clearExpression.setExpression("return temp < 30;"); clearExpression.setExpression("return temp < 30;");
AlarmRuleSimpleCondition clearCondition = new AlarmRuleSimpleCondition(); SimpleAlarmCondition clearCondition = new SimpleAlarmCondition();
clearCondition.setExpression(clearExpression); clearCondition.setExpression(clearExpression);
AlarmRuleDefinition clearRule = new AlarmRuleDefinition(); AlarmRule clearRule = new AlarmRule();
clearRule.setCondition(clearCondition); clearRule.setCondition(clearCondition);
config.setClearRule(clearRule); config.setClearRule(clearRule);
@ -236,8 +236,8 @@ public class CalculatedFieldApiClientTest extends AbstractApiClientTest {
assertEquals(cf.getName(), created.getName()); assertEquals(cf.getName(), created.getName());
assertEquals(CalculatedFieldType.ALARM, created.getType()); assertEquals(CalculatedFieldType.ALARM, created.getType());
AlarmCalculatedFieldConfiguration configuration = (AlarmCalculatedFieldConfiguration) created.getConfiguration(); AlarmCalculatedFieldConfiguration configuration = (AlarmCalculatedFieldConfiguration) created.getConfiguration();
AlarmConditionValueAlarmRuleSchedule createdSchedule = configuration.getCreateRules().get(AlarmSeverity.CRITICAL.name()).getCondition().getSchedule(); AlarmConditionValueAlarmSchedule createdSchedule = configuration.getCreateRules().get(AlarmSeverity.CRITICAL.name()).getCondition().getSchedule();
AlarmRuleSpecificTimeSchedule staticSchedule = (AlarmRuleSpecificTimeSchedule) createdSchedule.getStaticValue(); SpecificTimeSchedule staticSchedule = (SpecificTimeSchedule) createdSchedule.getStaticValue();
assertEquals(Set.of(3), staticSchedule.getDaysOfWeek()); assertEquals(Set.of(3), staticSchedule.getDaysOfWeek());
// get by id and verify configuration // get by id and verify configuration
@ -257,9 +257,9 @@ public class CalculatedFieldApiClientTest extends AbstractApiClientTest {
// update: add a second create rule for CRITICAL_TEMPERATURE // update: add a second create rule for CRITICAL_TEMPERATURE
TbelAlarmConditionExpression criticalExpression = new TbelAlarmConditionExpression(); TbelAlarmConditionExpression criticalExpression = new TbelAlarmConditionExpression();
criticalExpression.setExpression("return temp > 80;"); criticalExpression.setExpression("return temp > 80;");
AlarmRuleSimpleCondition criticalCondition = new AlarmRuleSimpleCondition(); SimpleAlarmCondition criticalCondition = new SimpleAlarmCondition();
criticalCondition.setExpression(criticalExpression); criticalCondition.setExpression(criticalExpression);
AlarmRuleDefinition criticalRule = new AlarmRuleDefinition(); AlarmRule criticalRule = new AlarmRule();
criticalRule.setCondition(criticalCondition); criticalRule.setCondition(criticalCondition);
fetchedConfig.putCreateRulesItem(AlarmSeverity.INDETERMINATE.name(), criticalRule); fetchedConfig.putCreateRulesItem(AlarmSeverity.INDETERMINATE.name(), criticalRule);
fetched.setConfiguration(fetchedConfig); 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)") @Schema(description = "List of platforms for which usage of the OAuth2 client is allowed (empty for all allowed)")
@Length(fieldName = "platforms") @Length(fieldName = "platforms")
private List<PlatformType> 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; private JsonNode additionalInfo;
public OAuth2Client() { public OAuth2Client() {
@ -128,4 +131,5 @@ public class OAuth2Client extends BaseDataWithAdditionalInfo<OAuth2ClientId> imp
public String getName() { public String getName() {
return title; return title;
} }
} }

2
pom.xml

@ -62,7 +62,7 @@
<pkg.implementationTitle>${project.name}</pkg.implementationTitle> <pkg.implementationTitle>${project.name}</pkg.implementationTitle>
<pkg.unixLogFolder>/var/log/${pkg.name}</pkg.unixLogFolder> <pkg.unixLogFolder>/var/log/${pkg.name}</pkg.unixLogFolder>
<pkg.installFolder>/usr/share/${pkg.name}</pkg.installFolder> <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> <spring-boot.version>3.5.13</spring-boot.version>
<javax.xml.bind-api.version>2.4.0-b180830.0359</javax.xml.bind-api.version> <javax.xml.bind-api.version>2.4.0-b180830.0359</javax.xml.bind-api.version>
<jjwt.version>0.12.5</jjwt.version> <jjwt.version>0.12.5</jjwt.version>

Loading…
Cancel
Save