diff --git a/api/Cloud API Demo.postman_collection.json b/api/Cloud API Demo.postman_collection.json
index 445ea40..a1535ea 100644
--- a/api/Cloud API Demo.postman_collection.json
+++ b/api/Cloud API Demo.postman_collection.json
@@ -761,6 +761,125 @@
}
},
"response": []
+ },
+ {
+ "name": "Get All Firmwares",
+ "request": {
+ "method": "GET",
+ "header": [],
+ "url": {
+ "raw": "{{base_url}}{{manage_version}}/workspaces/{{workspace_id}}/firmwares?page=1&page_size=50",
+ "host": [
+ "{{base_url}}{{manage_version}}"
+ ],
+ "path": [
+ "workspaces",
+ "{{workspace_id}}",
+ "firmwares"
+ ],
+ "query": [
+ {
+ "key": "device_name",
+ "value": null,
+ "disabled": true
+ },
+ {
+ "key": "product_version",
+ "value": null,
+ "disabled": true
+ },
+ {
+ "key": "status",
+ "value": "true",
+ "disabled": true
+ },
+ {
+ "key": "page",
+ "value": "1"
+ },
+ {
+ "key": "page_size",
+ "value": "50"
+ }
+ ]
+ }
+ },
+ "response": []
+ },
+ {
+ "name": "Import Firmware File",
+ "request": {
+ "method": "POST",
+ "header": [],
+ "body": {
+ "mode": "formdata",
+ "formdata": [
+ {
+ "key": "file",
+ "type": "file",
+ "src": []
+ },
+ {
+ "key": "release_note",
+ "value": "123",
+ "type": "text"
+ },
+ {
+ "key": "device_name",
+ "value": "DJI Dock",
+ "type": "text"
+ },
+ {
+ "key": "status",
+ "value": "0",
+ "type": "text"
+ }
+ ]
+ },
+ "url": {
+ "raw": "{{base_url}}{{manage_version}}/workspaces/{{workspace_id}}/firmwares/file/upload",
+ "host": [
+ "{{base_url}}{{manage_version}}"
+ ],
+ "path": [
+ "workspaces",
+ "{{workspace_id}}",
+ "firmwares",
+ "file",
+ "upload"
+ ]
+ }
+ },
+ "response": []
+ },
+ {
+ "name": "Change Firmware Status",
+ "request": {
+ "method": "PUT",
+ "header": [],
+ "body": {
+ "mode": "raw",
+ "raw": "{\r\n \"status\": false\r\n}",
+ "options": {
+ "raw": {
+ "language": "json"
+ }
+ }
+ },
+ "url": {
+ "raw": "{{base_url}}{{manage_version}}/workspaces/{{workspace_id}}/firmwares/{{firmware_id}}",
+ "host": [
+ "{{base_url}}{{manage_version}}"
+ ],
+ "path": [
+ "workspaces",
+ "{{workspace_id}}",
+ "firmwares",
+ "{{firmware_id}}"
+ ]
+ }
+ },
+ "response": []
}
],
"auth": {
@@ -768,7 +887,7 @@
"apikey": [
{
"key": "value",
- "value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ3b3Jrc3BhY2VfaWQiOiJlM2RlYTBmNS0zN2YyLTRkNzktYWU1OC00OTBhZjMyMjgwNjkiLCJzdWIiOiJDbG91ZEFwaVNhbXBsZSIsInVzZXJfdHlwZSI6IjEiLCJuYmYiOjE2Njc0NzcwNTUsImxvZyI6IkxvZ2dlcltjb20uZGppLnNhbXBsZS5jb21tb24ubW9kZWwuQ3VzdG9tQ2xhaW1dIiwiaXNzIjoiREpJIiwiaWQiOiJhMTU1OWU3Yy04ZGQ4LTQ3ODAtYjk1Mi0xMDBjYzQ3OTdkYTIiLCJleHAiOjE2Njc1NjM0NTUsImlhdCI6MTY2NzQ3NzA1NSwidXNlcm5hbWUiOiJhZG1pblBDIn0.VMJ0ZKn895uvkMDjg2fw3p4trVCUx9ltVFKeP7QmYpo",
+ "value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ3b3Jrc3BhY2VfaWQiOiJlM2RlYTBmNS0zN2YyLTRkNzktYWU1OC00OTBhZjMyMjgwNjkiLCJzdWIiOiJDbG91ZEFwaVNhbXBsZSIsInVzZXJfdHlwZSI6IjEiLCJuYmYiOjE2NzAzMTU2MDEsImxvZyI6IkxvZ2dlcltjb20uZGppLnNhbXBsZS5jb21tb24ubW9kZWwuQ3VzdG9tQ2xhaW1dIiwiaXNzIjoiREpJIiwiaWQiOiJhMTU1OWU3Yy04ZGQ4LTQ3ODAtYjk1Mi0xMDBjYzQ3OTdkYTIiLCJleHAiOjE2NzA0MDIwMDEsImlhdCI6MTY3MDMxNTYwMSwidXNlcm5hbWUiOiJhZG1pblBDIn0.yh8SkHZVsoIXo_vtlTGNB-ZX92XayalGe_q7mNRVcdI",
"type": "string"
},
{
@@ -1539,6 +1658,27 @@
}
},
"response": []
+ },
+ {
+ "name": "Set Media Highest",
+ "request": {
+ "method": "POST",
+ "header": [],
+ "url": {
+ "raw": "{{base_url}}{{wayline_version}}/workspaces/{{workspace_id}}/jobs/{{job_id}}/media-highest",
+ "host": [
+ "{{base_url}}{{wayline_version}}"
+ ],
+ "path": [
+ "workspaces",
+ "{{workspace_id}}",
+ "jobs",
+ "{{job_id}}",
+ "media-highest"
+ ]
+ }
+ },
+ "response": []
}
],
"auth": {
@@ -1585,16 +1725,25 @@
"request": {
"method": "POST",
"header": [],
+ "body": {
+ "mode": "raw",
+ "raw": "{\r\n \"action\": 0\r\n}",
+ "options": {
+ "raw": {
+ "language": "json"
+ }
+ }
+ },
"url": {
- "raw": "{{base_url}}{{control_version}}/devices/4TADK7E000000H/jobs/debug_mode_close",
+ "raw": "{{base_url}}{{control_version}}/devices/{{device_sn}}/jobs/alarm_state_switch",
"host": [
"{{base_url}}{{control_version}}"
],
"path": [
"devices",
- "4TADK7E000000H",
+ "{{device_sn}}",
"jobs",
- "debug_mode_close"
+ "alarm_state_switch"
]
}
},
@@ -1606,7 +1755,7 @@
"apikey": [
{
"key": "value",
- "value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ3b3Jrc3BhY2VfaWQiOiJlM2RlYTBmNS0zN2YyLTRkNzktYWU1OC00OTBhZjMyMjgwNjkiLCJzdWIiOiJDbG91ZEFwaVNhbXBsZSIsInVzZXJfdHlwZSI6IjEiLCJuYmYiOjE2Njg0MzE5MzQsImxvZyI6IkxvZ2dlcltjb20uZGppLnNhbXBsZS5jb21tb24ubW9kZWwuQ3VzdG9tQ2xhaW1dIiwiaXNzIjoiREpJIiwiaWQiOiJhMTU1OWU3Yy04ZGQ4LTQ3ODAtYjk1Mi0xMDBjYzQ3OTdkYTIiLCJleHAiOjE2Njg1MTgzMzQsImlhdCI6MTY2ODQzMTkzNCwidXNlcm5hbWUiOiJhZG1pblBDIn0.QU9xHBeQPHJ2V1vXQcGGWRQ-gYEOWDpaTTXIQga85BU",
+ "value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ3b3Jrc3BhY2VfaWQiOiJlM2RlYTBmNS0zN2YyLTRkNzktYWU1OC00OTBhZjMyMjgwNjkiLCJzdWIiOiJDbG91ZEFwaVNhbXBsZSIsInVzZXJfdHlwZSI6IjEiLCJuYmYiOjE2Njk2MzMzMzQsImxvZyI6IkxvZ2dlcltjb20uZGppLnNhbXBsZS5jb21tb24ubW9kZWwuQ3VzdG9tQ2xhaW1dIiwiaXNzIjoiREpJIiwiaWQiOiJhMTU1OWU3Yy04ZGQ4LTQ3ODAtYjk1Mi0xMDBjYzQ3OTdkYTIiLCJleHAiOjE2Njk3MTk3MzQsImlhdCI6MTY2OTYzMzMzNCwidXNlcm5hbWUiOiJhZG1pblBDIn0.OoIfdpyI5eL6bFm8akq8_stzClQU41YpIJkx6_kxVHU",
"type": "string"
},
{
diff --git a/pom.xml b/pom.xml
index dd1207c..66e3efa 100644
--- a/pom.xml
+++ b/pom.xml
@@ -11,7 +11,7 @@
com.dji
cloud-api-sample
- 1.3.0
+ 1.3.1
cloud-api-sample
diff --git a/sql/cloud_sample.sql b/sql/cloud_sample.sql
index 47d2656..b4fda63 100644
--- a/sql/cloud_sample.sql
+++ b/sql/cloud_sample.sql
@@ -148,12 +148,14 @@ CREATE TABLE `manage_device_firmware` (
`firmware_id` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT 'uuid',
`file_name` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'undefined' COMMENT 'The file name of the firmware package, including the file suffix',
`firmware_version` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT 'It needs to be formatted according to the official firmware version. 00.00.0000',
- `file_url` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT 'The download address for the firmware package.',
+ `object_key` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 'The object key of the firmware package in the bucket.',
`file_size` int NOT NULL COMMENT 'The size of the firmware package.',
`file_md5` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT 'The md5 of the firmware package.',
`device_name` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT 'model of the device. This parameter corresponds to the device name in the device dictionary table.',
+ `workspace_id` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`release_note` varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT 'The release note of the firmware package.',
`release_date` bigint NOT NULL COMMENT 'The release date of the firmware package.',
+ `user_name` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 'The name of the creator.',
`status` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Availability of the firmware package. 1: available; 0: unavailable',
`create_time` bigint NOT NULL,
`update_time` bigint NOT NULL,
@@ -161,15 +163,6 @@ CREATE TABLE `manage_device_firmware` (
UNIQUE KEY `UNIQUE_firmware_id` (`firmware_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COMMENT='Firmware file information';
-LOCK TABLES `manage_device_firmware` WRITE;
-/*!40000 ALTER TABLE `manage_device_firmware` DISABLE KEYS */;
-
-INSERT INTO `manage_device_firmware` (`id`, `firmware_id`, `file_name`, `firmware_version`, `file_url`, `file_size`, `file_md5`, `device_name`, `release_note`, `release_date`, `status`, `create_time`, `update_time`)
-VALUES
- (1,'1','Matrice_M30_Series_UAV_V04.01.00.20_Only_For_Pilot.zip','04.01.0020','https://terra-sz-hc1pro-cloudapi.oss-cn-shenzhen.aliyuncs.com/c0af9fe0d7eb4f35a8fe5b695e4d0b96/docker/Matrice_M30_Series_UAV_V04.01.00.20_Only_For_Pilot.zip',605830726,'601630a5c753cd6665974cc8fd791bf5','Matrice 30','release note',1663232356810,1,1663232356810,1663232356810);
-
-/*!40000 ALTER TABLE `manage_device_firmware` ENABLE KEYS */;
-UNLOCK TABLES;
# manage_device_hms
diff --git a/src/main/java/com/dji/sample/component/ApplicationBootInitial.java b/src/main/java/com/dji/sample/component/ApplicationBootInitial.java
index f35aa3c..d99f58d 100644
--- a/src/main/java/com/dji/sample/component/ApplicationBootInitial.java
+++ b/src/main/java/com/dji/sample/component/ApplicationBootInitial.java
@@ -18,9 +18,6 @@ public class ApplicationBootInitial implements CommandLineRunner {
@Autowired
private IDeviceService deviceService;
- @Autowired
- private RedisOpsUtils redisOps;
-
/**
* Subscribe to the devices that exist in the redis when the program starts,
* to prevent the data from being different from the pilot side due to program interruptions.
@@ -31,7 +28,7 @@ public class ApplicationBootInitial implements CommandLineRunner {
public void run(String... args) throws Exception {
int start = RedisConst.DEVICE_ONLINE_PREFIX.length();
- redisOps.getAllKeys(RedisConst.DEVICE_ONLINE_PREFIX + "*")
+ RedisOpsUtils.getAllKeys(RedisConst.DEVICE_ONLINE_PREFIX + "*")
.forEach(key -> deviceService.subscribeTopicOnline(key.substring(start)));
}
diff --git a/src/main/java/com/dji/sample/component/GlobalExceptionHandler.java b/src/main/java/com/dji/sample/component/GlobalExceptionHandler.java
index b0a9fbf..953fd2d 100644
--- a/src/main/java/com/dji/sample/component/GlobalExceptionHandler.java
+++ b/src/main/java/com/dji/sample/component/GlobalExceptionHandler.java
@@ -1,6 +1,7 @@
package com.dji.sample.component;
import com.dji.sample.common.model.ResponseResult;
+import org.springframework.validation.BindException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
@@ -32,8 +33,9 @@ public class GlobalExceptionHandler {
return ResponseResult.error("A null object appeared.");
}
- @ExceptionHandler(MethodArgumentNotValidException.class)
- public ResponseResult methodArgumentNotValidExceptionHandler(MethodArgumentNotValidException e) {
+ @ExceptionHandler({MethodArgumentNotValidException.class, BindException.class})
+ public ResponseResult methodArgumentNotValidExceptionHandler(BindException e) {
+ e.printStackTrace();
return ResponseResult.error(e.getBindingResult().getAllErrors().get(0).getDefaultMessage());
}
diff --git a/src/main/java/com/dji/sample/component/GlobalScheduleService.java b/src/main/java/com/dji/sample/component/GlobalScheduleService.java
index 2813388..81229ab 100644
--- a/src/main/java/com/dji/sample/component/GlobalScheduleService.java
+++ b/src/main/java/com/dji/sample/component/GlobalScheduleService.java
@@ -6,6 +6,7 @@ import com.dji.sample.component.redis.RedisOpsUtils;
import com.dji.sample.manage.model.dto.DeviceDTO;
import com.dji.sample.manage.model.enums.DeviceDomainEnum;
import com.dji.sample.manage.service.IDeviceService;
+import com.dji.sample.wayline.service.IWaylineJobService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
@@ -27,10 +28,10 @@ public class GlobalScheduleService {
private IDeviceService deviceService;
@Autowired
- private RedisOpsUtils redisOps;
+ private IMqttTopicService topicService;
@Autowired
- private IMqttTopicService topicService;
+ private IWaylineJobService waylineJobService;
/**
* Check the status of the devices every 30 seconds. It is recommended to use cache.
@@ -39,17 +40,17 @@ public class GlobalScheduleService {
private void deviceStatusListen() {
int start = RedisConst.DEVICE_ONLINE_PREFIX.length();
- redisOps.getAllKeys(RedisConst.DEVICE_ONLINE_PREFIX + "*").forEach(key -> {
- long expire = redisOps.getExpire(key);
+ RedisOpsUtils.getAllKeys(RedisConst.DEVICE_ONLINE_PREFIX + "*").forEach(key -> {
+ long expire = RedisOpsUtils.getExpire(key);
if (expire <= 30) {
- DeviceDTO device = (DeviceDTO) redisOps.get(key);
+ DeviceDTO device = (DeviceDTO) RedisOpsUtils.get(key);
if (device.getDomain().equals(DeviceDomainEnum.SUB_DEVICE.getDesc())) {
deviceService.subDeviceOffline(key.substring(start));
} else {
deviceService.unsubscribeTopicOffline(key.substring(start));
deviceService.pushDeviceOfflineTopo(device.getWorkspaceId(), device.getDeviceSn());
}
- redisOps.del(key);
+ RedisOpsUtils.del(key);
}
});
diff --git a/src/main/java/com/dji/sample/component/mqtt/config/MqttMessageChannel.java b/src/main/java/com/dji/sample/component/mqtt/config/MqttMessageChannel.java
index 51b138d..8e168e8 100644
--- a/src/main/java/com/dji/sample/component/mqtt/config/MqttMessageChannel.java
+++ b/src/main/java/com/dji/sample/component/mqtt/config/MqttMessageChannel.java
@@ -167,4 +167,9 @@ public class MqttMessageChannel {
return new DirectChannel();
}
+ @Bean(name = ChannelName.INBOUND_EVENTS_HIGHEST_PRIORITY_UPLOAD_FLIGHT_TASK_MEDIA)
+ public MessageChannel eventsHighestPriorityUploadFlightTaskMedia() {
+ return new DirectChannel();
+ }
+
}
diff --git a/src/main/java/com/dji/sample/component/mqtt/model/ChannelName.java b/src/main/java/com/dji/sample/component/mqtt/model/ChannelName.java
index cb5a0f0..aeee108 100644
--- a/src/main/java/com/dji/sample/component/mqtt/model/ChannelName.java
+++ b/src/main/java/com/dji/sample/component/mqtt/model/ChannelName.java
@@ -74,4 +74,6 @@ public class ChannelName {
public static final String INBOUND_PROPERTY_SET_REPLY = "inboundPropertySetReply";
public static final String INBOUND_REQUESTS_CONFIG = "inboundRequestsConfig";
+
+ public static final String INBOUND_EVENTS_HIGHEST_PRIORITY_UPLOAD_FLIGHT_TASK_MEDIA = "inboundEventsHighestPriorityUploadFlightTaskMedia";
}
diff --git a/src/main/java/com/dji/sample/component/mqtt/model/DeviceTopicEnum.java b/src/main/java/com/dji/sample/component/mqtt/model/DeviceTopicEnum.java
index 00ab2a7..8598905 100644
--- a/src/main/java/com/dji/sample/component/mqtt/model/DeviceTopicEnum.java
+++ b/src/main/java/com/dji/sample/component/mqtt/model/DeviceTopicEnum.java
@@ -29,7 +29,7 @@ public enum DeviceTopicEnum {
PROPERTY_SET_REPLY(Pattern.compile("^" + THING_MODEL_PRE + PRODUCT + REGEX_SN + PROPERTY_SUF + SET_SUF + _REPLY_SUF + "$"), ChannelName.INBOUND_PROPERTY_SET_REPLY),
- UNKNOWN(null, ChannelName.DEFAULT);
+ UNKNOWN(Pattern.compile("^.*$"), ChannelName.DEFAULT);
Pattern pattern;
diff --git a/src/main/java/com/dji/sample/component/mqtt/model/EventsMethodEnum.java b/src/main/java/com/dji/sample/component/mqtt/model/EventsMethodEnum.java
index 1cb654f..d0782e0 100644
--- a/src/main/java/com/dji/sample/component/mqtt/model/EventsMethodEnum.java
+++ b/src/main/java/com/dji/sample/component/mqtt/model/EventsMethodEnum.java
@@ -43,6 +43,8 @@ public enum EventsMethodEnum {
FILE_UPLOAD_PROGRESS("fileupload_progress", ChannelName.INBOUND_EVENTS_FILE_UPLOAD_PROGRESS),
+ HIGHEST_PRIORITY_UPLOAD_FLIGHT_TASK_MEDIA("highest_priority_upload_flighttask_media", ChannelName.INBOUND_EVENTS_HIGHEST_PRIORITY_UPLOAD_FLIGHT_TASK_MEDIA),
+
UNKNOWN("Unknown", ChannelName.DEFAULT);
private String method;
diff --git a/src/main/java/com/dji/sample/component/oss/model/OssConfiguration.java b/src/main/java/com/dji/sample/component/oss/model/OssConfiguration.java
index 491ee44..da668c9 100644
--- a/src/main/java/com/dji/sample/component/oss/model/OssConfiguration.java
+++ b/src/main/java/com/dji/sample/component/oss/model/OssConfiguration.java
@@ -1,6 +1,5 @@
package com.dji.sample.component.oss.model;
-import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@@ -11,82 +10,81 @@ import org.springframework.stereotype.Component;
*/
@ConfigurationProperties(prefix = "oss")
@Component
-@Data
public class OssConfiguration {
/**
* @see com.dji.sample.component.oss.model.enums.OssTypeEnum
*/
- private String provider;
+ public static String provider;
/**
* Whether to use the object storage service.
*/
- private boolean enable;
+ public static boolean enable;
/**
* The protocol needs to be included at the beginning of the address.
*/
- private String endpoint;
+ public static String endpoint;
- private String accessKey;
+ public static String accessKey;
- private String secretKey;
+ public static String secretKey;
- private String region;
+ public static String region;
- private Long expire;
+ public static Long expire;
- private String roleSessionName;
+ public static String roleSessionName;
- private String roleArn;
+ public static String roleArn;
- private String bucket;
+ public static String bucket;
- private String objectDirPrefix;
+ public static String objectDirPrefix;
public void setProvider(String provider) {
- this.provider = provider;
+ OssConfiguration.provider = provider;
}
public void setEnable(boolean enable) {
- this.enable = enable;
+ OssConfiguration.enable = enable;
}
public void setEndpoint(String endpoint) {
- this.endpoint = endpoint;
+ OssConfiguration.endpoint = endpoint;
}
public void setAccessKey(String accessKey) {
- this.accessKey = accessKey;
+ OssConfiguration.accessKey = accessKey;
}
public void setSecretKey(String secretKey) {
- this.secretKey = secretKey;
+ OssConfiguration.secretKey = secretKey;
}
public void setRegion(String region) {
- this.region = region;
+ OssConfiguration.region = region;
}
public void setExpire(Long expire) {
- this.expire = expire;
+ OssConfiguration.expire = expire;
}
public void setRoleSessionName(String roleSessionName) {
- this.roleSessionName = roleSessionName;
+ OssConfiguration.roleSessionName = roleSessionName;
}
public void setRoleArn(String roleArn) {
- this.roleArn = roleArn;
+ OssConfiguration.roleArn = roleArn;
}
public void setBucket(String bucket) {
- this.bucket = bucket;
+ OssConfiguration.bucket = bucket;
}
public void setObjectDirPrefix(String objectDirPrefix) {
- this.objectDirPrefix = objectDirPrefix;
+ OssConfiguration.objectDirPrefix = objectDirPrefix;
}
}
diff --git a/src/main/java/com/dji/sample/component/oss/service/IOssService.java b/src/main/java/com/dji/sample/component/oss/service/IOssService.java
index f8441dd..5d8e415 100644
--- a/src/main/java/com/dji/sample/component/oss/service/IOssService.java
+++ b/src/main/java/com/dji/sample/component/oss/service/IOssService.java
@@ -45,4 +45,6 @@ public interface IOssService {
InputStream getObject(String bucket, String objectKey);
void putObject(String bucket, String objectKey, InputStream input);
+
+ void createClient();
}
diff --git a/src/main/java/com/dji/sample/component/oss/service/impl/AliyunOssServiceImpl.java b/src/main/java/com/dji/sample/component/oss/service/impl/AliyunOssServiceImpl.java
index d855261..6717849 100644
--- a/src/main/java/com/dji/sample/component/oss/service/impl/AliyunOssServiceImpl.java
+++ b/src/main/java/com/dji/sample/component/oss/service/impl/AliyunOssServiceImpl.java
@@ -3,7 +3,6 @@ package com.dji.sample.component.oss.service.impl;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
-import com.aliyun.oss.model.OSSObject;
import com.aliyun.oss.model.ObjectMetadata;
import com.aliyun.oss.model.PutObjectRequest;
import com.aliyun.oss.model.PutObjectResult;
@@ -18,14 +17,12 @@ import com.dji.sample.component.oss.model.enums.OssTypeEnum;
import com.dji.sample.component.oss.service.IOssService;
import com.dji.sample.media.model.CredentialsDTO;
import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
-import org.springframework.util.StringUtils;
-import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Date;
+import java.util.Objects;
/**
* @author sean
@@ -36,9 +33,8 @@ import java.util.Date;
@Slf4j
public class AliyunOssServiceImpl implements IOssService {
- @Autowired
- public OssConfiguration configuration;
-
+ private OSS ossClient;
+
@Override
public String getOssType() {
return OssTypeEnum.ALIYUN.getType();
@@ -49,16 +45,16 @@ public class AliyunOssServiceImpl implements IOssService {
try {
DefaultProfile profile = DefaultProfile.getProfile(
- configuration.getRegion(), configuration.getAccessKey(), configuration.getSecretKey());
+ OssConfiguration.region, OssConfiguration.accessKey, OssConfiguration.secretKey);
IAcsClient client = new DefaultAcsClient(profile);
AssumeRoleRequest request = new AssumeRoleRequest();
- request.setDurationSeconds(configuration.getExpire());
- request.setRoleArn(configuration.getRoleArn());
- request.setRoleSessionName(configuration.getRoleSessionName());
+ request.setDurationSeconds(OssConfiguration.expire);
+ request.setRoleArn(OssConfiguration.roleArn);
+ request.setRoleSessionName(OssConfiguration.roleSessionName);
AssumeRoleResponse response = client.getAcsResponse(request);
- return new CredentialsDTO(response.getCredentials(), configuration.getExpire());
+ return new CredentialsDTO(response.getCredentials(), OssConfiguration.expire);
} catch (ClientException e) {
log.debug("Failed to obtain sts.");
@@ -69,10 +65,6 @@ public class AliyunOssServiceImpl implements IOssService {
@Override
public URL getObjectUrl(String bucket, String objectKey) {
- if (!StringUtils.hasText(bucket) || !StringUtils.hasText(objectKey)) {
- return null;
- }
- OSS ossClient = this.createClient();
// First check if the object can be fetched.
boolean isExist = ossClient.doesObjectExist(bucket, objectKey);
if (!isExist) {
@@ -80,50 +72,37 @@ public class AliyunOssServiceImpl implements IOssService {
}
return ossClient.generatePresignedUrl(bucket, objectKey,
- new Date(System.currentTimeMillis() + configuration.getExpire() * 1000));
+ new Date(System.currentTimeMillis() + OssConfiguration.expire * 1000));
}
@Override
public Boolean deleteObject(String bucket, String objectKey) {
- OSS ossClient = this.createClient();
if (!ossClient.doesObjectExist(bucket, objectKey)) {
- ossClient.shutdown();
return true;
}
ossClient.deleteObject(bucket, objectKey);
- ossClient.shutdown();
return true;
}
@Override
public InputStream getObject(String bucket, String objectKey) {
- OSS ossClient = this.createClient();
- OSSObject object = ossClient.getObject(bucket, objectKey);
-
- try (InputStream input = object.getObjectContent()) {
- return input;
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- ossClient.shutdown();
- }
- return InputStream.nullInputStream();
+ return ossClient.getObject(bucket, objectKey).getObjectContent();
}
@Override
public void putObject(String bucket, String objectKey, InputStream input) {
- OSS ossClient = this.createClient();
if (ossClient.doesObjectExist(bucket, objectKey)) {
- ossClient.shutdown();
throw new RuntimeException("The filename already exists.");
}
PutObjectResult objectResult = ossClient.putObject(new PutObjectRequest(bucket, objectKey, input, new ObjectMetadata()));
- ossClient.shutdown();
log.info("Upload File: {}", objectResult.getETag());
}
- private OSS createClient() {
- return new OSSClientBuilder()
- .build(configuration.getEndpoint(), configuration.getAccessKey(), configuration.getSecretKey());
+ public void createClient() {
+ if (Objects.nonNull(this.ossClient)) {
+ return;
+ }
+ this.ossClient = new OSSClientBuilder()
+ .build(OssConfiguration.endpoint, OssConfiguration.accessKey, OssConfiguration.secretKey);
}
}
diff --git a/src/main/java/com/dji/sample/component/oss/service/impl/AmazonS3ServiceImpl.java b/src/main/java/com/dji/sample/component/oss/service/impl/AmazonS3ServiceImpl.java
index b9cdfd3..fa896b6 100644
--- a/src/main/java/com/dji/sample/component/oss/service/impl/AmazonS3ServiceImpl.java
+++ b/src/main/java/com/dji/sample/component/oss/service/impl/AmazonS3ServiceImpl.java
@@ -17,16 +17,15 @@ import com.dji.sample.component.oss.model.enums.OssTypeEnum;
import com.dji.sample.component.oss.service.IOssService;
import com.dji.sample.media.model.CredentialsDTO;
import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
-import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
+import java.util.Objects;
/**
* @author sean
@@ -37,9 +36,8 @@ import java.util.List;
@Service
public class AmazonS3ServiceImpl implements IOssService {
- @Autowired
- private OssConfiguration configuration;
-
+ private AmazonS3 client;
+
@Override
public String getOssType() {
return OssTypeEnum.AWS.getType();
@@ -49,71 +47,55 @@ public class AmazonS3ServiceImpl implements IOssService {
public CredentialsDTO getCredentials() {
AWSSecurityTokenService stsClient = AWSSecurityTokenServiceClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(
- new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey())))
- .withRegion(configuration.getRegion()).build();
+ new BasicAWSCredentials(OssConfiguration.accessKey, OssConfiguration.secretKey)))
+ .withRegion(OssConfiguration.region).build();
AssumeRoleRequest request = new AssumeRoleRequest()
- .withRoleArn(configuration.getRoleArn())
- .withRoleSessionName(configuration.getRoleSessionName())
- .withDurationSeconds(Math.toIntExact(configuration.getExpire()));
+ .withRoleArn(OssConfiguration.roleArn)
+ .withRoleSessionName(OssConfiguration.roleSessionName)
+ .withDurationSeconds(Math.toIntExact(OssConfiguration.expire));
AssumeRoleResult result = stsClient.assumeRole(request);
Credentials credentials = result.getCredentials();
- stsClient.shutdown();
return new CredentialsDTO(credentials);
}
@Override
public URL getObjectUrl(String bucket, String objectKey) {
- AmazonS3 client = this.createClient();
- URL url = client.generatePresignedUrl(bucket, objectKey,
- new Date(System.currentTimeMillis() + configuration.getExpire() * 1000), HttpMethod.GET);
- client.shutdown();
- return url;
+ return client.generatePresignedUrl(bucket, objectKey,
+ new Date(System.currentTimeMillis() + OssConfiguration.expire * 1000), HttpMethod.GET);
}
@Override
public Boolean deleteObject(String bucket, String objectKey) {
- AmazonS3 client = this.createClient();
if (!client.doesObjectExist(bucket, objectKey)) {
- client.shutdown();
return true;
}
client.deleteObject(bucket, objectKey);
- client.shutdown();
return true;
}
public InputStream getObject(String bucket, String objectKey) {
- AmazonS3 client = this.createClient();
- S3Object object = client.getObject(bucket, objectKey);
- try (InputStream input = object.getObjectContent().getDelegateStream()) {
- return input;
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- client.shutdown();
- }
- return InputStream.nullInputStream();
+ return client.getObject(bucket, objectKey).getObjectContent().getDelegateStream();
}
@Override
public void putObject(String bucket, String objectKey, InputStream input) {
- AmazonS3 client = this.createClient();
if (client.doesObjectExist(bucket, objectKey)) {
- client.shutdown();
throw new RuntimeException("The filename already exists.");
}
PutObjectResult objectResult = client.putObject(new PutObjectRequest(bucket, objectKey, input, new ObjectMetadata()));
- client.shutdown();
log.info("Upload File: {}", objectResult.toString());
}
- private AmazonS3 createClient() {
- return AmazonS3ClientBuilder.standard()
+ public void createClient() {
+ if (Objects.nonNull(this.client)) {
+ return;
+ }
+ this.client = AmazonS3ClientBuilder.standard()
.withCredentials(
new AWSStaticCredentialsProvider(
- new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey())))
- .withRegion(configuration.getRegion())
+ new BasicAWSCredentials(OssConfiguration.accessKey, OssConfiguration.secretKey)))
+ .withRegion(OssConfiguration.region)
.build();
}
@@ -122,7 +104,7 @@ public class AmazonS3ServiceImpl implements IOssService {
*/
@PostConstruct
private void configCORS() {
- if (!configuration.isEnable() || !OssTypeEnum.AWS.getType().equals(configuration.getProvider())) {
+ if (!OssConfiguration.enable || !OssTypeEnum.AWS.getType().equals(OssConfiguration.provider)) {
return;
}
List allowedMethods = new ArrayList<>();
@@ -136,10 +118,8 @@ public class AmazonS3ServiceImpl implements IOssService {
.withAllowedHeaders(List.of(AuthInterceptor.PARAM_TOKEN))
.withAllowedMethods(allowedMethods);
- AmazonS3 client = this.createClient();
-
- client.setBucketCrossOriginConfiguration(this.configuration.getBucket(),
+ client.setBucketCrossOriginConfiguration(OssConfiguration.bucket,
new BucketCrossOriginConfiguration().withRules(rule));
- client.shutdown();
+
}
}
diff --git a/src/main/java/com/dji/sample/component/oss/service/impl/MinIOServiceImpl.java b/src/main/java/com/dji/sample/component/oss/service/impl/MinIOServiceImpl.java
index b162751..cafeb66 100644
--- a/src/main/java/com/dji/sample/component/oss/service/impl/MinIOServiceImpl.java
+++ b/src/main/java/com/dji/sample/component/oss/service/impl/MinIOServiceImpl.java
@@ -9,7 +9,6 @@ import io.minio.credentials.AssumeRoleProvider;
import io.minio.errors.*;
import io.minio.http.Method;
import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.ByteArrayInputStream;
@@ -30,10 +29,7 @@ import java.util.Objects;
public class MinIOServiceImpl implements IOssService {
private MinioClient client;
-
- @Autowired
- private OssConfiguration configuration;
-
+
@Override
public String getOssType() {
return OssTypeEnum.MINIO.getType();
@@ -42,10 +38,10 @@ public class MinIOServiceImpl implements IOssService {
@Override
public CredentialsDTO getCredentials() {
try {
- AssumeRoleProvider provider = new AssumeRoleProvider(configuration.getEndpoint(), configuration.getAccessKey(),
- configuration.getSecretKey(), Math.toIntExact(configuration.getExpire()),
- null, configuration.getRegion(), null, null, null, null);
- return new CredentialsDTO(provider.fetch(), configuration.getExpire());
+ AssumeRoleProvider provider = new AssumeRoleProvider(OssConfiguration.endpoint, OssConfiguration.accessKey,
+ OssConfiguration.secretKey, Math.toIntExact(OssConfiguration.expire),
+ null, OssConfiguration.region, null, null, null, null);
+ return new CredentialsDTO(provider.fetch(), OssConfiguration.expire);
} catch (NoSuchAlgorithmException e) {
log.debug("Failed to obtain sts.");
e.printStackTrace();
@@ -57,26 +53,22 @@ public class MinIOServiceImpl implements IOssService {
public URL getObjectUrl(String bucket, String objectKey) {
try {
return new URL(
- this.createClient()
- .getPresignedObjectUrl(
+ client.getPresignedObjectUrl(
GetPresignedObjectUrlArgs.builder()
.method(Method.GET)
.bucket(bucket)
.object(objectKey)
- .expiry(Math.toIntExact(configuration.getExpire()))
+ .expiry(Math.toIntExact(OssConfiguration.expire))
.build()));
} catch (ErrorResponseException | InsufficientDataException | InternalException |
InvalidKeyException | InvalidResponseException | IOException |
NoSuchAlgorithmException | XmlParserException | ServerException e) {
- log.error("The file does not exist on the OssConfiguration.");
- e.printStackTrace();
+ throw new RuntimeException("The file does not exist on the OssConfiguration.");
}
- return null;
}
@Override
public Boolean deleteObject(String bucket, String objectKey) {
- MinioClient client = this.createClient();
try {
client.removeObject(RemoveObjectArgs.builder().bucket(bucket).object(objectKey).build());
} catch (MinioException | NoSuchAlgorithmException | IOException | InvalidKeyException e) {
@@ -90,7 +82,7 @@ public class MinIOServiceImpl implements IOssService {
@Override
public InputStream getObject(String bucket, String objectKey) {
try {
- GetObjectResponse object = this.createClient().getObject(GetObjectArgs.builder().bucket(bucket).object(objectKey).build());
+ GetObjectResponse object = client.getObject(GetObjectArgs.builder().bucket(bucket).object(objectKey).build());
return new ByteArrayInputStream(object.readAllBytes());
} catch (ErrorResponseException | InsufficientDataException | InternalException | InvalidKeyException | InvalidResponseException | IOException | NoSuchAlgorithmException | ServerException | XmlParserException e) {
e.printStackTrace();
@@ -101,7 +93,6 @@ public class MinIOServiceImpl implements IOssService {
@Override
public void putObject(String bucket, String objectKey, InputStream input) {
try {
- MinioClient client = this.createClient();
client.statObject(StatObjectArgs.builder().bucket(bucket).object(objectKey).build());
throw new RuntimeException("The filename already exists.");
} catch (MinioException | InvalidKeyException | IOException | NoSuchAlgorithmException e) {
@@ -117,15 +108,14 @@ public class MinIOServiceImpl implements IOssService {
}
}
- private MinioClient createClient() {
+ public void createClient() {
if (Objects.nonNull(this.client)) {
- return this.client;
+ return;
}
this.client = MinioClient.builder()
- .endpoint(configuration.getEndpoint())
- .credentials(configuration.getAccessKey(), configuration.getSecretKey())
- .region(configuration.getRegion())
+ .endpoint(OssConfiguration.endpoint)
+ .credentials(OssConfiguration.accessKey, OssConfiguration.secretKey)
+ .region(OssConfiguration.region)
.build();
- return this.client;
}
}
diff --git a/src/main/java/com/dji/sample/component/oss/service/impl/OssAspectHandler.java b/src/main/java/com/dji/sample/component/oss/service/impl/OssAspectHandler.java
index f7f9223..b3a5b25 100644
--- a/src/main/java/com/dji/sample/component/oss/service/impl/OssAspectHandler.java
+++ b/src/main/java/com/dji/sample/component/oss/service/impl/OssAspectHandler.java
@@ -18,16 +18,14 @@ public class OssAspectHandler {
@Autowired
private OssServiceContext ossServiceContext;
- @Autowired
- private OssConfiguration configuration;
-
@Before("execution(public * com.dji.sample.component.oss.service.impl.OssServiceContext.*(..))")
public void before() {
- if (!this.configuration.isEnable()) {
+ if (!OssConfiguration.enable) {
throw new IllegalArgumentException("Please enable OssConfiguration.");
}
if (this.ossServiceContext.getOssService() == null) {
throw new IllegalArgumentException("Please check the OssConfiguration configuration.");
}
+ this.ossServiceContext.createClient();
}
}
diff --git a/src/main/java/com/dji/sample/component/oss/service/impl/OssServiceContext.java b/src/main/java/com/dji/sample/component/oss/service/impl/OssServiceContext.java
index e131889..28333ca 100644
--- a/src/main/java/com/dji/sample/component/oss/service/impl/OssServiceContext.java
+++ b/src/main/java/com/dji/sample/component/oss/service/impl/OssServiceContext.java
@@ -6,6 +6,7 @@ import com.dji.sample.component.oss.service.IOssService;
import com.dji.sample.media.model.CredentialsDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
import java.io.InputStream;
import java.net.URL;
@@ -22,16 +23,13 @@ public class OssServiceContext {
private IOssService ossService;
- private OssConfiguration configuration;
-
@Autowired
public OssServiceContext(List ossServices, OssConfiguration configuration) {
- this.configuration = configuration;
- if (!configuration.isEnable()) {
+ if (!OssConfiguration.enable) {
return;
}
this.ossService = ossServices.stream()
- .filter(ossService -> ossService.getOssType().equals(configuration.getProvider()))
+ .filter(ossService -> ossService.getOssType().equals(OssConfiguration.provider))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Oss provider is illegal. Optional: " +
Arrays.toString(Arrays.stream(OssTypeEnum.values()).map(OssTypeEnum::getType).toArray())));
@@ -46,6 +44,9 @@ public class OssServiceContext {
}
public URL getObjectUrl(String bucket, String objectKey) {
+ if (!StringUtils.hasText(bucket) || !StringUtils.hasText(objectKey)) {
+ throw new IllegalArgumentException();
+ }
return this.ossService.getObjectUrl(bucket, objectKey);
}
@@ -60,4 +61,8 @@ public class OssServiceContext {
public void putObject(String bucket, String objectKey, InputStream stream) {
this.ossService.putObject(bucket, objectKey, stream);
}
+
+ void createClient() {
+ this.ossService.createClient();
+ }
}
diff --git a/src/main/java/com/dji/sample/component/redis/RedisConst.java b/src/main/java/com/dji/sample/component/redis/RedisConst.java
index 1fce89d..39c686b 100644
--- a/src/main/java/com/dji/sample/component/redis/RedisConst.java
+++ b/src/main/java/com/dji/sample/component/redis/RedisConst.java
@@ -38,4 +38,8 @@ public final class RedisConst {
public static final String WAYLINE_JOB = "wayline_job";
public static final String OSD_PREFIX = "osd" + DELIMITER;
+
+ public static final String MEDIA_FILE_PREFIX = "media_file" + DELIMITER;
+
+ public static final String MEDIA_HIGHEST_PRIORITY_PREFIX = "media_highest_priority" + DELIMITER;
}
diff --git a/src/main/java/com/dji/sample/component/redis/RedisOpsUtils.java b/src/main/java/com/dji/sample/component/redis/RedisOpsUtils.java
index 5e329c9..f71dd1c 100644
--- a/src/main/java/com/dji/sample/component/redis/RedisOpsUtils.java
+++ b/src/main/java/com/dji/sample/component/redis/RedisOpsUtils.java
@@ -17,8 +17,12 @@ import java.util.concurrent.TimeUnit;
@Component
public class RedisOpsUtils {
+ private static RedisTemplate redisTemplate;
+
@Autowired
- private RedisTemplate redisTemplate;
+ public void setRedisTemplate(RedisTemplate redisTemplate) {
+ RedisOpsUtils.redisTemplate = redisTemplate;
+ }
/**
* HSET
@@ -26,7 +30,7 @@ public class RedisOpsUtils {
* @param field
* @param value
*/
- public void hashSet(String key, String field, Object value) {
+ public static void hashSet(String key, String field, Object value) {
redisTemplate.opsForHash().put(key, field, value);
}
@@ -36,7 +40,7 @@ public class RedisOpsUtils {
* @param field
* @return
*/
- public Object hashGet(String key, String field) {
+ public static Object hashGet(String key, String field) {
return redisTemplate.opsForHash().get(key, field);
}
@@ -45,7 +49,7 @@ public class RedisOpsUtils {
* @param key
* @return
*/
- public Set