diff --git a/pom.xml b/pom.xml index 7ab9d95..e62560e 100644 --- a/pom.xml +++ b/pom.xml @@ -28,6 +28,7 @@ udf-starter-rms udf-starter-cors udf-starter-amqp-rabbitmq + udf-starter-file diff --git a/udf-starter-cors/src/main/java/com/egridcloud/udf/core/cors/CorsConfig.java b/udf-starter-cors/src/main/java/com/egridcloud/udf/cors/CorsConfig.java similarity index 95% rename from udf-starter-cors/src/main/java/com/egridcloud/udf/core/cors/CorsConfig.java rename to udf-starter-cors/src/main/java/com/egridcloud/udf/cors/CorsConfig.java index 257fd89..72719fa 100644 --- a/udf-starter-cors/src/main/java/com/egridcloud/udf/core/cors/CorsConfig.java +++ b/udf-starter-cors/src/main/java/com/egridcloud/udf/cors/CorsConfig.java @@ -4,7 +4,7 @@ * Created by Administrator * Copyright (C) 2016 egridcloud.com, All rights reserved. */ -package com.egridcloud.udf.core.cors; +package com.egridcloud.udf.cors; import java.util.Iterator; import java.util.Map; diff --git a/udf-starter-file/.checkstyle b/udf-starter-file/.checkstyle new file mode 100644 index 0000000..5b35a1b --- /dev/null +++ b/udf-starter-file/.checkstyle @@ -0,0 +1,7 @@ + + + + + + + diff --git a/udf-starter-file/.gitignore b/udf-starter-file/.gitignore new file mode 100644 index 0000000..c541155 --- /dev/null +++ b/udf-starter-file/.gitignore @@ -0,0 +1,4 @@ +/target/ +/bin/ +/.classpath +/.project diff --git a/udf-starter-file/pom.xml b/udf-starter-file/pom.xml new file mode 100644 index 0000000..9fee18d --- /dev/null +++ b/udf-starter-file/pom.xml @@ -0,0 +1,24 @@ + + + 4.0.0 + + udf-starter-file + udf-starter-file + jar + http://www.egridcloud.com + + + com.egridcloud.udf + udf-starter + 1.0 + + + + + + com.egridcloud.udf + udf-starter-core + + + diff --git a/udf-starter-file/src/main/java/com/egridcloud/udf/file/FileException.java b/udf-starter-file/src/main/java/com/egridcloud/udf/file/FileException.java new file mode 100644 index 0000000..e288e56 --- /dev/null +++ b/udf-starter-file/src/main/java/com/egridcloud/udf/file/FileException.java @@ -0,0 +1,66 @@ +/** + * FileException.java + * Created at 2016-03-01 + * Created by wangkang + * Copyright (C) 2016 egridcloud.com, All rights reserved. + */ +package com.egridcloud.udf.file; + +/** + *

+ * ClassName: FileException + *

+ *

+ * Description: 文件异常 + *

+ *

+ * Author: wangkang + *

+ *

+ * Date: 2016年3月23日 + *

+ */ +public class FileException extends RuntimeException { + + /** + *

+ * Field serialVersionUID: 序列号 + *

+ */ + private static final long serialVersionUID = 1L; + + /** + *

+ * Description: 构造函数 + *

+ * + * @param message 异常信息 + */ + public FileException(String message) { + super(message); + } + + /** + *

+ * Description: 构造函数 + *

+ * + * @param cause 堆栈 + */ + public FileException(Throwable cause) { + super(cause); + } + + /** + *

+ * Description: 构造函数 + *

+ * + * @param message 异常信息 + * @param cause 堆栈 + */ + public FileException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/udf-starter-file/src/main/java/com/egridcloud/udf/file/FileProperties.java b/udf-starter-file/src/main/java/com/egridcloud/udf/file/FileProperties.java new file mode 100644 index 0000000..4c939a7 --- /dev/null +++ b/udf-starter-file/src/main/java/com/egridcloud/udf/file/FileProperties.java @@ -0,0 +1,83 @@ +/** + * Config.java + * Created at 2016-11-19 + * Created by Administrator + * Copyright (C) 2016 egridcloud.com, All rights reserved. + */ +package com.egridcloud.udf.file; + +import java.io.Serializable; +import java.util.Map; + +import javax.validation.constraints.NotNull; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; +import org.springframework.validation.annotation.Validated; + +import com.egridcloud.udf.file.mate.PathMate; + +/** + * 描述 : Config + * + * @author Administrator + * + */ +@Component +@ConfigurationProperties(prefix = "com.egridcloud.file.properties") +@Validated +public class FileProperties implements Serializable { + + /** + * 描述 : ID + */ + private static final long serialVersionUID = 1L; + + /** + * 描述 : 根路径 + */ + @NotNull + private String rootPath; + + /** + * 描述 : 文件路径 ( key : pathCode ) + */ + private Map path; + + /** + * 描述 : 获取rootPath + * + * @return the rootPath + */ + public String getRootPath() { + return rootPath; + } + + /** + * 描述 : 设置rootPath + * + * @param rootPath the rootPath to set + */ + public void setRootPath(String rootPath) { + this.rootPath = rootPath; + } + + /** + * 描述 : 获取path + * + * @return the path + */ + public Map getPath() { + return path; + } + + /** + * 描述 : 设置path + * + * @param path the path to set + */ + public void setPath(Map path) { + this.path = path; + } + +} diff --git a/udf-starter-file/src/main/java/com/egridcloud/udf/file/mate/PathMate.java b/udf-starter-file/src/main/java/com/egridcloud/udf/file/mate/PathMate.java new file mode 100644 index 0000000..b6abd9c --- /dev/null +++ b/udf-starter-file/src/main/java/com/egridcloud/udf/file/mate/PathMate.java @@ -0,0 +1,93 @@ +/** + * PathMate.java + * Created at 2017-05-26 + * Created by Administrator + * Copyright (C) 2016 egridcloud.com, All rights reserved. + */ +package com.egridcloud.udf.file.mate; + +import java.io.Serializable; + +/** + * 描述 : PathMate + * + * @author Administrator + * + */ +public class PathMate implements Serializable { + + /** + * 描述 : ID + */ + private static final long serialVersionUID = 1L; + + /** + * 描述 : 应用名称 + */ + private String owner; + + /** + * 描述 : 文件路径 + */ + private String path; + + /** + * 描述 : 描述 + */ + private String description; + + /** + * 描述 : 获取owner + * + * @return the owner + */ + public String getOwner() { + return owner; + } + + /** + * 描述 : 设置owner + * + * @param owner the owner to set + */ + public void setOwner(String owner) { + this.owner = owner; + } + + /** + * 描述 : 获取path + * + * @return the path + */ + public String getPath() { + return path; + } + + /** + * 描述 : 设置path + * + * @param path the path to set + */ + public void setPath(String path) { + this.path = path; + } + + /** + * 描述 : 获取description + * + * @return the description + */ + public String getDescription() { + return description; + } + + /** + * 描述 : 设置description + * + * @param description the description to set + */ + public void setDescription(String description) { + this.description = description; + } + +} diff --git a/udf-starter-file/src/main/java/com/egridcloud/udf/file/service/FileService.java b/udf-starter-file/src/main/java/com/egridcloud/udf/file/service/FileService.java new file mode 100644 index 0000000..195dcd2 --- /dev/null +++ b/udf-starter-file/src/main/java/com/egridcloud/udf/file/service/FileService.java @@ -0,0 +1,48 @@ +/** + * FileService.java + * Created at 2017-05-26 + * Created by Administrator + * Copyright (C) 2016 egridcloud.com, All rights reserved. + */ +package com.egridcloud.udf.file.service; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import com.egridcloud.udf.file.FileException; +import com.egridcloud.udf.file.FileProperties; + +/** + * 描述 : FileService + * + * @author Administrator + * + */ +@Service +public class FileService { + + /** + * 描述 : fileProperties + */ + @Autowired + private FileProperties fileProperties; + + /** + * 描述 : 验证 + * + * @param pathCode 路径代码 + * @param file 文件 + */ + public void verification(String pathCode, MultipartFile file) { + //验证pathCode是否存在 + if (!fileProperties.getPath().containsKey(pathCode)) { + throw new FileException("pathCode : " + pathCode + " not defined"); + } + //文件是否为空 + if (file.isEmpty()) { + throw new FileException("file is empty"); + } + } + +} diff --git a/udf-starter-file/src/main/java/com/egridcloud/udf/file/web/FileController.java b/udf-starter-file/src/main/java/com/egridcloud/udf/file/web/FileController.java new file mode 100644 index 0000000..7576bb9 --- /dev/null +++ b/udf-starter-file/src/main/java/com/egridcloud/udf/file/web/FileController.java @@ -0,0 +1,36 @@ +/** + * FileController.java + * Created at 2017-05-26 + * Created by Administrator + * Copyright (C) 2016 egridcloud.com, All rights reserved. + */ +package com.egridcloud.udf.file.web; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +import com.egridcloud.udf.core.RestResponse; +import com.egridcloud.udf.file.service.FileService; + +/** + * 描述 : FileController + * + * @author Administrator + * + */ +@RestController +public class FileController implements IFileController { + + /** + * 描述 : fileService + */ + @Autowired + private FileService fileService; + + @Override + public RestResponse upload(String pathCode, Boolean cover, MultipartFile file) { + return new RestResponse<>(pathCode); + } + +} diff --git a/udf-starter-file/src/main/java/com/egridcloud/udf/file/web/IFileController.java b/udf-starter-file/src/main/java/com/egridcloud/udf/file/web/IFileController.java new file mode 100644 index 0000000..b827866 --- /dev/null +++ b/udf-starter-file/src/main/java/com/egridcloud/udf/file/web/IFileController.java @@ -0,0 +1,56 @@ +/** + * IFileController.java + * Created at 2017-05-26 + * Created by Administrator + * Copyright (C) 2016 egridcloud.com, All rights reserved. + */ +package com.egridcloud.udf.file.web; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.multipart.MultipartFile; + +import com.egridcloud.udf.core.RestResponse; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; + +/** + * 描述 : IFileController + * + * @author Administrator + * + */ +@Api(value = "文件服务", consumes = "application/json", produces = "application/json", + protocols = "http") +@RequestMapping(value = "/service/file") +public interface IFileController { + + /** + * 描述 : 上传文件 + * + * @param pathCode 路径代码 + * @param cover 是否覆盖 + * @param file 文件 + * @return 结果 + */ + @ApiOperation(value = "FILE_1", notes = "上传文件") + @ApiImplicitParams({ + @ApiImplicitParam(paramType = "header", name = "rmsApplicationName", value = "rms应用名称", + required = true, dataType = "string"), + @ApiImplicitParam(paramType = "header", name = "rmsSign", value = "rms认证秘钥", required = true, + dataType = "string"), + @ApiImplicitParam(paramType = "header", name = "rmsServiceCode", value = "rms接口编号", + required = true, dataType = "string"), + @ApiImplicitParam(paramType = "form", name = "pathCode", value = "路径代码", required = true, + dataType = "string"), + @ApiImplicitParam(paramType = "form", name = "cover", value = "是否覆盖", required = true, + dataType = "boolean"), + @ApiImplicitParam(paramType = "form", name = "file", value = "文件", required = true, + dataType = "__file") }) + @RequestMapping(value = "upload", method = RequestMethod.POST) + public RestResponse upload(String pathCode, Boolean cover, MultipartFile file); + +}