Clear code

This commit is contained in:
Vladyslav_Prykhodko 2023-07-21 18:56:06 +03:00
parent 26044fc035
commit 03b49f1ddd
6 changed files with 17 additions and 60 deletions

View File

@ -42,7 +42,6 @@ import org.thingsboard.server.service.security.system.SystemSecurityService;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Map;
import static org.thingsboard.server.controller.ControllerConstants.DEVICE_ID; import static org.thingsboard.server.controller.ControllerConstants.DEVICE_ID;
import static org.thingsboard.server.controller.ControllerConstants.DEVICE_ID_PARAM_DESCRIPTION; import static org.thingsboard.server.controller.ControllerConstants.DEVICE_ID_PARAM_DESCRIPTION;

View File

@ -134,7 +134,6 @@ public class DeviceController extends BaseController {
private final TbDeviceService tbDeviceService; private final TbDeviceService tbDeviceService;
@ApiOperation(value = "Get Device (getDeviceById)", @ApiOperation(value = "Get Device (getDeviceById)",
notes = "Fetch the Device object based on the provided Device Id. " + notes = "Fetch the Device object based on the provided Device Id. " +
"If the user has the authority of 'TENANT_ADMIN', the server checks that the device is owned by the same tenant. " + "If the user has the authority of 'TENANT_ADMIN', the server checks that the device is owned by the same tenant. " +

View File

@ -15,84 +15,43 @@
*/ */
package org.thingsboard.server.controller; package org.thingsboard.server.controller;
import com.datastax.oss.driver.api.core.uuid.Uuids;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.MoreExecutors;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.mockito.AdditionalAnswers; import org.mockito.AdditionalAnswers;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.TestPropertySource;
import org.thingsboard.common.util.JacksonUtil; import org.thingsboard.common.util.JacksonUtil;
import org.thingsboard.common.util.ThingsBoardExecutors; import org.thingsboard.common.util.ThingsBoardExecutors;
import org.thingsboard.server.common.data.Customer;
import org.thingsboard.server.common.data.Device; import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.common.data.DeviceInfo;
import org.thingsboard.server.common.data.DeviceProfile; import org.thingsboard.server.common.data.DeviceProfile;
import org.thingsboard.server.common.data.DeviceProfileType; import org.thingsboard.server.common.data.DeviceProfileType;
import org.thingsboard.server.common.data.DeviceTransportType; import org.thingsboard.server.common.data.DeviceTransportType;
import org.thingsboard.server.common.data.EntitySubtype;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.OtaPackageInfo;
import org.thingsboard.server.common.data.SaveDeviceWithCredentialsRequest;
import org.thingsboard.server.common.data.SaveOtaPackageInfoRequest;
import org.thingsboard.server.common.data.StringUtils;
import org.thingsboard.server.common.data.Tenant; import org.thingsboard.server.common.data.Tenant;
import org.thingsboard.server.common.data.User; import org.thingsboard.server.common.data.User;
import org.thingsboard.server.common.data.audit.ActionType;
import org.thingsboard.server.common.data.device.credentials.BasicMqttCredentials; import org.thingsboard.server.common.data.device.credentials.BasicMqttCredentials;
import org.thingsboard.server.common.data.device.profile.CoapDeviceProfileTransportConfiguration; import org.thingsboard.server.common.data.device.profile.CoapDeviceProfileTransportConfiguration;
import org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileConfiguration; import org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileConfiguration;
import org.thingsboard.server.common.data.device.profile.DeviceProfileData; import org.thingsboard.server.common.data.device.profile.DeviceProfileData;
import org.thingsboard.server.common.data.device.profile.MqttDeviceProfileTransportConfiguration; import org.thingsboard.server.common.data.device.profile.MqttDeviceProfileTransportConfiguration;
import org.thingsboard.server.common.data.edge.Edge;
import org.thingsboard.server.common.data.id.CustomerId;
import org.thingsboard.server.common.data.id.DeviceCredentialsId;
import org.thingsboard.server.common.data.id.DeviceId;
import org.thingsboard.server.common.data.id.DeviceProfileId; import org.thingsboard.server.common.data.id.DeviceProfileId;
import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.page.PageData; import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.common.data.relation.EntityRelation;
import org.thingsboard.server.common.data.relation.RelationTypeGroup;
import org.thingsboard.server.common.data.security.Authority; import org.thingsboard.server.common.data.security.Authority;
import org.thingsboard.server.common.data.security.DeviceCredentials; import org.thingsboard.server.common.data.security.DeviceCredentials;
import org.thingsboard.server.common.data.security.DeviceCredentialsType; import org.thingsboard.server.common.data.security.DeviceCredentialsType;
import org.thingsboard.server.common.data.sync.ie.importing.csv.BulkImportColumnType;
import org.thingsboard.server.common.data.sync.ie.importing.csv.BulkImportRequest;
import org.thingsboard.server.common.data.sync.ie.importing.csv.BulkImportResult;
import org.thingsboard.server.dao.device.DeviceDao; import org.thingsboard.server.dao.device.DeviceDao;
import org.thingsboard.server.dao.exception.DataValidationException;
import org.thingsboard.server.dao.exception.DeviceCredentialsValidationException;
import org.thingsboard.server.dao.model.ModelConstants;
import org.thingsboard.server.dao.service.DaoSqlTest; import org.thingsboard.server.dao.service.DaoSqlTest;
import org.thingsboard.server.service.gateway_device.GatewayNotificationsService;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.thingsboard.server.common.data.ota.OtaPackageType.FIRMWARE;
import static org.thingsboard.server.common.data.ota.OtaPackageType.SOFTWARE;
import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
import static org.thingsboard.server.dao.util.DeviceConnectivityUtil.COAP; import static org.thingsboard.server.dao.util.DeviceConnectivityUtil.COAP;
import static org.thingsboard.server.dao.util.DeviceConnectivityUtil.COAPS; import static org.thingsboard.server.dao.util.DeviceConnectivityUtil.COAPS;
import static org.thingsboard.server.dao.util.DeviceConnectivityUtil.DOCKER; import static org.thingsboard.server.dao.util.DeviceConnectivityUtil.DOCKER;

View File

@ -84,6 +84,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import static org.thingsboard.server.common.data.ota.OtaPackageType.FIRMWARE; import static org.thingsboard.server.common.data.ota.OtaPackageType.FIRMWARE;
import static org.thingsboard.server.common.data.ota.OtaPackageType.SOFTWARE; import static org.thingsboard.server.common.data.ota.OtaPackageType.SOFTWARE;
import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
@ContextConfiguration(classes = {DeviceControllerTest.Config.class}) @ContextConfiguration(classes = {DeviceControllerTest.Config.class})
@DaoSqlTest @DaoSqlTest
public class DeviceControllerTest extends AbstractControllerTest { public class DeviceControllerTest extends AbstractControllerTest {

View File

@ -20,7 +20,6 @@ import org.thingsboard.server.common.data.Device;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Map;
public interface DeviceConnectivityService { public interface DeviceConnectivityService {

View File

@ -144,8 +144,8 @@
</div> </div>
<ng-container <ng-container
*ngTemplateOutlet="executeCommand; context: {cmd: { *ngTemplateOutlet="executeCommand; context: {cmd: {
noSecLabel: 'MQTT', noSec: this.commands.mqtt.mqtt, noSecLabel: 'MQTT', noSec: commands.mqtt.mqtt,
secLabel: 'MQTTs', sec: this.commands.mqtt.mqtts, secLabel: 'MQTTs', sec: commands.mqtt.mqtts,
doc: {text: 'device.connectivity.mqtts-x509-command', href: 'https://thingsboard.io/docs/user-guide/mqtt-over-ssl/'}}}"> doc: {text: 'device.connectivity.mqtts-x509-command', href: 'https://thingsboard.io/docs/user-guide/mqtt-over-ssl/'}}}">
</ng-container> </ng-container>
</div> </div>
@ -165,8 +165,8 @@
</div> </div>
<ng-container <ng-container
*ngTemplateOutlet="executeCommand; context: {cmd: { *ngTemplateOutlet="executeCommand; context: {cmd: {
noSecLabel: 'MQTT', noSec: this.commands.mqtt.mqtt, noSecLabel: 'MQTT', noSec: commands.mqtt.mqtt,
secLabel: 'MQTTs', sec: this.commands.mqtt.mqtts, secLabel: 'MQTTs', sec: commands.mqtt.mqtts,
doc: {text: 'device.connectivity.mqtts-x509-command', href: 'https://thingsboard.io/docs/user-guide/mqtt-over-ssl/'}}}"> doc: {text: 'device.connectivity.mqtts-x509-command', href: 'https://thingsboard.io/docs/user-guide/mqtt-over-ssl/'}}}">
</ng-container> </ng-container>
</div> </div>
@ -186,14 +186,14 @@
</div> </div>
<ng-container <ng-container
*ngTemplateOutlet="executeCommand; context: {cmd: { *ngTemplateOutlet="executeCommand; context: {cmd: {
noSecLabel: 'MQTT', noSec: this.commands.mqtt.mqtt, noSecLabel: 'MQTT', noSec: commands.mqtt.mqtt,
secLabel: 'MQTTs', sec: this.commands.mqtt.mqtts, secLabel: 'MQTTs', sec: commands.mqtt.mqtts,
doc: {text: 'device.connectivity.mqtts-x509-command', href: 'https://thingsboard.io/docs/user-guide/mqtt-over-ssl/'}}}"> doc: {text: 'device.connectivity.mqtts-x509-command', href: 'https://thingsboard.io/docs/user-guide/mqtt-over-ssl/'}}}">
</ng-container> </ng-container>
</div> </div>
</ng-template> </ng-template>
</mat-tab> </mat-tab>
<mat-tab *ngIf="!!this.commands.mqtt.docker"> <mat-tab *ngIf="!!commands.mqtt.docker">
<ng-template mat-tab-label> <ng-template mat-tab-label>
<mat-icon class="tabs-icon" svgIcon="docker"></mat-icon> <mat-icon class="tabs-icon" svgIcon="docker"></mat-icon>
Docker Docker
@ -202,8 +202,8 @@
<div class="tb-form-panel no-padding no-border tb-tab-body"> <div class="tb-form-panel no-padding no-border tb-tab-body">
<ng-container <ng-container
*ngTemplateOutlet="executeCommand; context: {cmd: { *ngTemplateOutlet="executeCommand; context: {cmd: {
noSecLabel: 'MQTT', noSec: this.commands.mqtt.docker.mqtt, noSecLabel: 'MQTT', noSec: commands.mqtt.docker.mqtt,
secLabel: 'MQTTs', sec: this.commands.mqtt.docker.mqtts, secLabel: 'MQTTs', sec: commands.mqtt.docker.mqtts,
doc: {text: 'device.connectivity.mqtts-x509-command', href: 'https://thingsboard.io/docs/user-guide/mqtt-over-ssl/'}}}"> doc: {text: 'device.connectivity.mqtts-x509-command', href: 'https://thingsboard.io/docs/user-guide/mqtt-over-ssl/'}}}">
</ng-container> </ng-container>
</div> </div>
@ -228,8 +228,8 @@
</div> </div>
<ng-container <ng-container
*ngTemplateOutlet="executeCommand; context: {cmd: { *ngTemplateOutlet="executeCommand; context: {cmd: {
noSecLabel: 'CoAP', noSec: this.commands.coap.coap, noSecLabel: 'CoAP', noSec: commands.coap.coap,
secLabel: 'CoAPs', sec: this.commands.coap.coaps, secLabel: 'CoAPs', sec: commands.coap.coaps,
doc: {text: 'device.connectivity.coaps-x509-command', href: 'https://thingsboard.io/docs/user-guide/ssl/coap-x509-certificates/'}}}"> doc: {text: 'device.connectivity.coaps-x509-command', href: 'https://thingsboard.io/docs/user-guide/ssl/coap-x509-certificates/'}}}">
</ng-container> </ng-container>
</div> </div>
@ -249,14 +249,14 @@
</div> </div>
<ng-container <ng-container
*ngTemplateOutlet="executeCommand; context: {cmd: { *ngTemplateOutlet="executeCommand; context: {cmd: {
noSecLabel: 'CoAP', noSec: this.commands.coap.coap, noSecLabel: 'CoAP', noSec: commands.coap.coap,
secLabel: 'CoAPs', sec: this.commands.coap.coaps, secLabel: 'CoAPs', sec: commands.coap.coaps,
doc: {text: 'device.connectivity.coaps-x509-command', href: 'https://thingsboard.io/docs/user-guide/ssl/coap-x509-certificates/'}}}"> doc: {text: 'device.connectivity.coaps-x509-command', href: 'https://thingsboard.io/docs/user-guide/ssl/coap-x509-certificates/'}}}">
</ng-container> </ng-container>
</div> </div>
</ng-template> </ng-template>
</mat-tab> </mat-tab>
<mat-tab *ngIf="!!this.commands.coap.docker"> <mat-tab *ngIf="!!commands.coap.docker">
<ng-template mat-tab-label> <ng-template mat-tab-label>
<mat-icon class="tabs-icon" svgIcon="docker"></mat-icon> <mat-icon class="tabs-icon" svgIcon="docker"></mat-icon>
Docker Docker
@ -265,8 +265,8 @@
<div class="tb-form-panel no-padding no-border tb-tab-body"> <div class="tb-form-panel no-padding no-border tb-tab-body">
<ng-container <ng-container
*ngTemplateOutlet="executeCommand; context: {cmd: { *ngTemplateOutlet="executeCommand; context: {cmd: {
noSecLabel: 'CoAP', noSec: this.commands.coap.docker.coap, noSecLabel: 'CoAP', noSec: commands.coap.docker.coap,
secLabel: 'CoAPs', sec: this.commands.coap.docker.coaps, secLabel: 'CoAPs', sec: commands.coap.docker.coaps,
doc: {text: 'device.connectivity.coaps-x509-command', href: 'https://thingsboard.io/docs/user-guide/ssl/coap-x509-certificates/'}}}"> doc: {text: 'device.connectivity.coaps-x509-command', href: 'https://thingsboard.io/docs/user-guide/ssl/coap-x509-certificates/'}}}">
</ng-container> </ng-container>
</div> </div>