From ccbefb9bdf029355b625df9a7465c004d48aba53 Mon Sep 17 00:00:00 2001 From: lanyuanxiaoyao Date: Thu, 21 Nov 2024 19:15:49 +0800 Subject: [PATCH] =?UTF-8?q?feat(web):=20=E5=A2=9E=E5=8A=A0type=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E7=94=A8=E4=BA=8E=E5=8C=BA=E5=88=86=E4=B8=8D=E5=90=8C?= =?UTF-8?q?=E7=9A=84=E5=AD=90=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/resource/entity/DataResource.java | 25 +++++++++++++------ .../entity/format/CsvResourceFormat.java | 7 +++++- .../entity/format/JsonLineResourceFormat.java | 7 +++++- .../entity/format/JsonResourceFormat.java | 8 ++++-- .../entity/format/LineResourceFormat.java | 6 ++++- .../entity/format/NoneResourceFormat.java | 6 ++++- .../entity/format/ResourceFormat.java | 8 +++--- .../resource/entity/type/ApiResourceType.java | 5 ++++ .../entity/type/DatabaseResourceType.java | 9 +++++-- .../entity/type/FileResourceType.java | 13 +++++++--- .../resource/entity/type/FtpResourceType.java | 5 ++++ .../entity/type/HDFSResourceType.java | 18 +++++++++---- .../resource/entity/type/ResourceType.java | 13 ++++++++-- 13 files changed, 100 insertions(+), 30 deletions(-) diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/DataResource.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/DataResource.java index 881db23..bdfcf23 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/DataResource.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/DataResource.java @@ -1,22 +1,25 @@ package com.eshore.gringotts.web.domain.resource.entity; import com.eshore.gringotts.core.Constants; -import com.eshore.gringotts.web.domain.entity.SimpleEntity; +import com.eshore.gringotts.web.domain.base.entity.SimpleEntity; import com.eshore.gringotts.web.domain.resource.entity.format.ResourceFormat; import com.eshore.gringotts.web.domain.resource.entity.type.ResourceType; +import com.eshore.gringotts.web.domain.upload.entity.DataFile; +import javax.persistence.CascadeType; import javax.persistence.Column; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; +import javax.persistence.ConstraintMode; +import javax.persistence.Entity; +import javax.persistence.EntityListeners; +import javax.persistence.FetchType; +import javax.persistence.ForeignKey; import javax.persistence.JoinColumn; import javax.persistence.OneToOne; +import javax.persistence.Table; import lombok.Getter; import lombok.Setter; import lombok.ToString; import org.hibernate.annotations.DynamicUpdate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; -import javax.persistence.Entity; -import javax.persistence.EntityListeners; -import javax.persistence.Table; @Getter @Setter @@ -29,10 +32,16 @@ public class DataResource extends SimpleEntity { @Column(nullable = false) private String name; private String description; - @OneToOne + @OneToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY) @JoinColumn(nullable = false) + @ToString.Exclude private ResourceType type; - @OneToOne + @OneToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY) @JoinColumn(nullable = false) + @ToString.Exclude private ResourceFormat format; + @OneToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY) + @JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) + @ToString.Exclude + private DataFile example; } diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/format/CsvResourceFormat.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/format/CsvResourceFormat.java index 2b03d39..4cfe753 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/format/CsvResourceFormat.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/format/CsvResourceFormat.java @@ -21,6 +21,11 @@ import lombok.ToString; @NoArgsConstructor @Entity @DiscriminatorValue("CSV") -public class CsvResourceFormat extends ResourceFormat{ +public class CsvResourceFormat extends ResourceFormat { private String schema; + + @Override + public Type getFormatType() { + return Type.CSV; + } } diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/format/JsonLineResourceFormat.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/format/JsonLineResourceFormat.java index 2f6d65c..c4000b7 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/format/JsonLineResourceFormat.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/format/JsonLineResourceFormat.java @@ -21,6 +21,11 @@ import lombok.ToString; @NoArgsConstructor @Entity @DiscriminatorValue("JSON_LINE") -public class JsonLineResourceFormat extends ResourceFormat{ +public class JsonLineResourceFormat extends ResourceFormat { private String schema; + + @Override + public Type getFormatType() { + return Type.JSON_LINE; + } } diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/format/JsonResourceFormat.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/format/JsonResourceFormat.java index 47e71db..d57d769 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/format/JsonResourceFormat.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/format/JsonResourceFormat.java @@ -1,6 +1,5 @@ package com.eshore.gringotts.web.domain.resource.entity.format; -import javax.persistence.Column; import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; import lombok.AllArgsConstructor; @@ -22,6 +21,11 @@ import lombok.ToString; @NoArgsConstructor @Entity @DiscriminatorValue("JSON") -public class JsonResourceFormat extends ResourceFormat{ +public class JsonResourceFormat extends ResourceFormat { private String schema; + + @Override + public Type getFormatType() { + return Type.JSON; + } } diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/format/LineResourceFormat.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/format/LineResourceFormat.java index 4be708a..9483dc9 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/format/LineResourceFormat.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/format/LineResourceFormat.java @@ -17,5 +17,9 @@ import lombok.ToString; @ToString @Entity @DiscriminatorValue("LINE") -public class LineResourceFormat extends ResourceFormat{ +public class LineResourceFormat extends ResourceFormat { + @Override + public Type getFormatType() { + return Type.LINE; + } } diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/format/NoneResourceFormat.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/format/NoneResourceFormat.java index b32b3ac..3c7e699 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/format/NoneResourceFormat.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/format/NoneResourceFormat.java @@ -17,5 +17,9 @@ import lombok.ToString; @ToString @Entity @DiscriminatorValue("NONE") -public class NoneResourceFormat extends ResourceFormat{ +public class NoneResourceFormat extends ResourceFormat { + @Override + public Type getFormatType() { + return Type.NONE; + } } diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/format/ResourceFormat.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/format/ResourceFormat.java index 0d17cc7..622168d 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/format/ResourceFormat.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/format/ResourceFormat.java @@ -1,12 +1,10 @@ package com.eshore.gringotts.web.domain.resource.entity.format; import com.eshore.gringotts.core.Constants; -import com.eshore.gringotts.web.domain.entity.IdOnlyEntity; +import com.eshore.gringotts.web.domain.base.entity.IdOnlyEntity; import javax.persistence.DiscriminatorColumn; import javax.persistence.DiscriminatorType; import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.Table; @@ -27,7 +25,7 @@ import lombok.ToString; @Table(name = Constants.TABLE_PREFIX + "resource_format") @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING) -public class ResourceFormat extends IdOnlyEntity { +public abstract class ResourceFormat extends IdOnlyEntity { public enum Type { NONE, LINE, @@ -35,4 +33,6 @@ public class ResourceFormat extends IdOnlyEntity { JSON_LINE, CSV, } + + public abstract Type getFormatType(); } diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/type/ApiResourceType.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/type/ApiResourceType.java index ba18215..c410d89 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/type/ApiResourceType.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/type/ApiResourceType.java @@ -22,4 +22,9 @@ public class ApiResourceType extends ResourceType { private String url; private String username; private String password; + + @Override + public Type getResourceType() { + return Type.API; + } } diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/type/DatabaseResourceType.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/type/DatabaseResourceType.java index 1f6542a..2a67340 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/type/DatabaseResourceType.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/type/DatabaseResourceType.java @@ -26,9 +26,14 @@ public class DatabaseResourceType extends ResourceType { private String password; @Column(nullable = false) @Enumerated(EnumType.STRING) - private Type type; + private DatabaseType databaseType; - public enum Type { + @Override + public Type getResourceType() { + return Type.DATABASE; + } + + public enum DatabaseType { MYSQL, POSTGRESQL, ORACLE, diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/type/FileResourceType.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/type/FileResourceType.java index 9b54a3b..8a81afd 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/type/FileResourceType.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/type/FileResourceType.java @@ -1,7 +1,8 @@ package com.eshore.gringotts.web.domain.resource.entity.type; import com.eshore.gringotts.core.Constants; -import javax.persistence.Column; +import com.eshore.gringotts.web.domain.upload.entity.DataFile; +import javax.persistence.ConstraintMode; import javax.persistence.Entity; import javax.persistence.Table; import lombok.AllArgsConstructor; @@ -18,6 +19,12 @@ import lombok.ToString; @Entity @Table(name = Constants.TABLE_PREFIX + "resource_type_file") public class FileResourceType extends ResourceType { - @Column(nullable = false) - private String path; + @OneToOne + @JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) + private DataFile file; + + @Override + public Type getResourceType() { + return Type.FILE; + } } diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/type/FtpResourceType.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/type/FtpResourceType.java index f1a4c48..24f3447 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/type/FtpResourceType.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/type/FtpResourceType.java @@ -24,4 +24,9 @@ public class FtpResourceType extends ResourceType { private String password; private String path; private String regexFilter; + + @Override + public Type getResourceType() { + return Type.FTP; + } } diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/type/HDFSResourceType.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/type/HDFSResourceType.java index 63530ed..ed76e73 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/type/HDFSResourceType.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/type/HDFSResourceType.java @@ -1,7 +1,8 @@ package com.eshore.gringotts.web.domain.resource.entity.type; import com.eshore.gringotts.core.Constants; -import javax.persistence.Column; +import com.eshore.gringotts.web.domain.upload.entity.DataFile; +import javax.persistence.ConstraintMode; import javax.persistence.Entity; import javax.persistence.Table; import lombok.AllArgsConstructor; @@ -18,8 +19,15 @@ import lombok.ToString; @Entity @Table(name = Constants.TABLE_PREFIX + "resource_type_hdfs") public class HDFSResourceType extends ResourceType { - @Column(nullable = false) - private String coreSite; - @Column(nullable = false) - private String hdfsSite; + @OneToOne + @JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) + private DataFile coreSite; + @OneToOne + @JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) + private DataFile hdfsSite; + + @Override + public Type getResourceType() { + return Type.HDFS; + } } diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/type/ResourceType.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/type/ResourceType.java index de5d979..51bb4e9 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/type/ResourceType.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/entity/type/ResourceType.java @@ -1,7 +1,7 @@ package com.eshore.gringotts.web.domain.resource.entity.type; import com.eshore.gringotts.core.Constants; -import com.eshore.gringotts.web.domain.entity.IdOnlyEntity; +import com.eshore.gringotts.web.domain.base.entity.IdOnlyEntity; import javax.persistence.Entity; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; @@ -22,5 +22,14 @@ import lombok.ToString; @Entity @Table(name = Constants.TABLE_PREFIX + "resource_type") @Inheritance(strategy = InheritanceType.JOINED) -public class ResourceType extends IdOnlyEntity { +public abstract class ResourceType extends IdOnlyEntity { + public abstract Type getResourceType(); + + public enum Type { + API, + DATABASE, + FILE, + FTP, + HDFS, + } }