Merge pull request #209 from vran-dev/issue-208
feature: support export specified tables
This commit is contained in:
commit
1f18009125
|
@ -74,7 +74,10 @@ public class DocumentController {
|
||||||
public ResponseEntity<StreamingResponseBody> getDocumentFiles(@PathVariable Integer projectId,
|
public ResponseEntity<StreamingResponseBody> getDocumentFiles(@PathVariable Integer projectId,
|
||||||
@RequestParam(required = false)
|
@RequestParam(required = false)
|
||||||
Long version,
|
Long version,
|
||||||
@RequestParam DocumentFileType fileType) {
|
@RequestParam(required = false)
|
||||||
|
List<Integer> tableIds,
|
||||||
|
@RequestParam
|
||||||
|
DocumentFileType fileType) {
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
String projectName = projectService.getOne(projectId).getName();
|
String projectName = projectService.getOne(projectId).getName();
|
||||||
String fileName = projectName + "." + fileType.getFileExtension();
|
String fileName = projectName + "." + fileType.getFileExtension();
|
||||||
|
@ -84,7 +87,7 @@ public class DocumentController {
|
||||||
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
||||||
return ResponseEntity.ok()
|
return ResponseEntity.ok()
|
||||||
.headers(headers)
|
.headers(headers)
|
||||||
.body(out -> documentService.export(projectId, version, fileType, out));
|
.body(out -> documentService.export(projectId, version, tableIds, fileType, out));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(Routes.Document.EXPORT_TYPES)
|
@GetMapping(Routes.Document.EXPORT_TYPES)
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
<!doctype html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/favicon.ico"><title>databasir</title><script defer="defer" type="module" src="/js/chunk-vendors.661f96f0.js"></script><script defer="defer" type="module" src="/js/app.98502fba.js"></script><link href="/css/chunk-vendors.113af7af.css" rel="stylesheet"><link href="/css/app.ee11d130.css" rel="stylesheet"><script defer="defer" src="/js/chunk-vendors-legacy.fc4c9525.js" nomodule></script><script defer="defer" src="/js/app-legacy.25171435.js" nomodule></script></head><body><noscript><strong>We're sorry but databasir doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>
|
<!doctype html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/favicon.ico"><title>databasir</title><script defer="defer" type="module" src="/js/chunk-vendors.661f96f0.js"></script><script defer="defer" type="module" src="/js/app.7bd4174c.js"></script><link href="/css/chunk-vendors.113af7af.css" rel="stylesheet"><link href="/css/app.ee11d130.css" rel="stylesheet"><script defer="defer" src="/js/chunk-vendors-legacy.fc4c9525.js" nomodule></script><script defer="defer" src="/js/app-legacy.9cbae090.js" nomodule></script></head><body><noscript><strong>We're sorry but databasir doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -4,7 +4,6 @@ import com.databasir.common.SystemException;
|
||||||
import com.databasir.core.domain.document.data.DatabaseDocumentResponse;
|
import com.databasir.core.domain.document.data.DatabaseDocumentResponse;
|
||||||
import com.databasir.core.domain.document.data.TableDocumentResponse;
|
import com.databasir.core.domain.document.data.TableDocumentResponse;
|
||||||
import com.databasir.core.domain.document.generator.DocumentFileGenerator;
|
import com.databasir.core.domain.document.generator.DocumentFileGenerator;
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.sourceforge.plantuml.FileFormatOption;
|
import net.sourceforge.plantuml.FileFormatOption;
|
||||||
import net.sourceforge.plantuml.SourceStringReader;
|
import net.sourceforge.plantuml.SourceStringReader;
|
||||||
|
@ -34,13 +33,24 @@ public abstract class BasePlantUmlFileGenerator implements DocumentFileGenerator
|
||||||
|
|
||||||
protected abstract FileFormatOption fileFormatOption();
|
protected abstract FileFormatOption fileFormatOption();
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class ErDsl {
|
public class ErDsl {
|
||||||
|
|
||||||
private final DocumentFileGenerateContext context;
|
private final DocumentFileGenerateContext context;
|
||||||
|
|
||||||
private Set<String> foreignKeyRelations = new HashSet<>(16);
|
private Set<String> foreignKeyRelations = new HashSet<>(16);
|
||||||
|
|
||||||
|
private Set<String> tables = new HashSet<>(16);
|
||||||
|
|
||||||
|
public ErDsl(DocumentFileGenerateContext context) {
|
||||||
|
this.context = context;
|
||||||
|
Set<String> tables = context.getDatabaseDocument()
|
||||||
|
.getTables()
|
||||||
|
.stream()
|
||||||
|
.map(TableDocumentResponse::getName)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
this.tables = tables;
|
||||||
|
}
|
||||||
|
|
||||||
public String toDsl() {
|
public String toDsl() {
|
||||||
DatabaseDocumentResponse databaseDocument = context.getDatabaseDocument();
|
DatabaseDocumentResponse databaseDocument = context.getDatabaseDocument();
|
||||||
StringBuilder dslBuilder = new StringBuilder(1024);
|
StringBuilder dslBuilder = new StringBuilder(1024);
|
||||||
|
@ -115,7 +125,10 @@ public abstract class BasePlantUmlFileGenerator implements DocumentFileGenerator
|
||||||
dslBuilder.append("}");
|
dslBuilder.append("}");
|
||||||
dslBuilder.append(LINE);
|
dslBuilder.append(LINE);
|
||||||
|
|
||||||
table.getForeignKeys().forEach(fk -> {
|
table.getForeignKeys()
|
||||||
|
.stream()
|
||||||
|
.filter(fk -> tables.contains(fk.getFkTableName()) && tables.contains(fk.getPkTableName()))
|
||||||
|
.forEach(fk -> {
|
||||||
String fkTableName = fk.getFkTableName();
|
String fkTableName = fk.getFkTableName();
|
||||||
String fkColumnName = fk.getFkColumnName();
|
String fkColumnName = fk.getFkColumnName();
|
||||||
String pkTableName = fk.getPkTableName();
|
String pkTableName = fk.getPkTableName();
|
||||||
|
|
|
@ -15,6 +15,7 @@ import com.databasir.core.domain.document.data.*;
|
||||||
import com.databasir.core.domain.document.data.TableDocumentResponse.ForeignKeyDocumentResponse;
|
import com.databasir.core.domain.document.data.TableDocumentResponse.ForeignKeyDocumentResponse;
|
||||||
import com.databasir.core.domain.document.event.DocumentUpdated;
|
import com.databasir.core.domain.document.event.DocumentUpdated;
|
||||||
import com.databasir.core.domain.document.generator.DocumentFileGenerator;
|
import com.databasir.core.domain.document.generator.DocumentFileGenerator;
|
||||||
|
import com.databasir.core.domain.document.generator.DocumentFileGenerator.DocumentFileGenerateContext;
|
||||||
import com.databasir.core.domain.document.generator.DocumentFileType;
|
import com.databasir.core.domain.document.generator.DocumentFileType;
|
||||||
import com.databasir.core.infrastructure.connection.DatabaseConnectionService;
|
import com.databasir.core.infrastructure.connection.DatabaseConnectionService;
|
||||||
import com.databasir.core.infrastructure.converter.JsonConverter;
|
import com.databasir.core.infrastructure.converter.JsonConverter;
|
||||||
|
@ -526,11 +527,27 @@ public class DocumentService {
|
||||||
|
|
||||||
public void export(Integer projectId,
|
public void export(Integer projectId,
|
||||||
Long version,
|
Long version,
|
||||||
|
List<Integer> tableIds,
|
||||||
DocumentFileType type,
|
DocumentFileType type,
|
||||||
OutputStream out) {
|
OutputStream out) {
|
||||||
getOneByProjectId(projectId, version)
|
DatabaseDocumentResponse doc;
|
||||||
.ifPresent(doc -> {
|
if (tableIds == null || CollectionUtils.isEmpty(tableIds)) {
|
||||||
var context = DocumentFileGenerator.DocumentFileGenerateContext.builder()
|
doc = getOneByProjectId(projectId, version)
|
||||||
|
.orElseThrow(DomainErrors.DOCUMENT_VERSION_IS_INVALID::exception);
|
||||||
|
} else {
|
||||||
|
DatabaseDocumentPojo databaseDoc;
|
||||||
|
if (version == null) {
|
||||||
|
databaseDoc = databaseDocumentDao.selectNotArchivedByProjectId(projectId)
|
||||||
|
.orElseThrow(DomainErrors.DOCUMENT_VERSION_IS_INVALID::exception);
|
||||||
|
} else {
|
||||||
|
databaseDoc = databaseDocumentDao.selectOptionalByProjectIdAndVersion(projectId, version)
|
||||||
|
.orElseThrow(DomainErrors.DOCUMENT_VERSION_IS_INVALID::exception);
|
||||||
|
}
|
||||||
|
Integer databaseDocId = databaseDoc.getId();
|
||||||
|
List<TableDocumentResponse> tableDocs = getTableDetails(projectId, databaseDocId, tableIds);
|
||||||
|
doc = documentResponseConverter.of(databaseDoc, tableDocs);
|
||||||
|
}
|
||||||
|
var context = DocumentFileGenerateContext.builder()
|
||||||
.documentFileType(type)
|
.documentFileType(type)
|
||||||
.databaseDocument(doc)
|
.databaseDocument(doc)
|
||||||
.build();
|
.build();
|
||||||
|
@ -538,7 +555,6 @@ public class DocumentService {
|
||||||
.filter(g -> g.support(type))
|
.filter(g -> g.support(type))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.ifPresent(generator -> generator.generate(context, out));
|
.ifPresent(generator -> generator.generate(context, out));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TableResponse> getTableAndColumns(Integer projectId, Long version) {
|
public List<TableResponse> getTableAndColumns(Integer projectId, Long version) {
|
||||||
|
|
|
@ -43,6 +43,14 @@ public class DatabaseDocumentDao extends BaseDao<DatabaseDocumentPojo> {
|
||||||
.fetchOptionalInto(DatabaseDocumentPojo.class);
|
.fetchOptionalInto(DatabaseDocumentPojo.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Optional<Integer> selectIdByProjectIdAndVersion(Integer projectId,
|
||||||
|
Long version) {
|
||||||
|
return getDslContext()
|
||||||
|
.select(DATABASE_DOCUMENT.ID).from(DATABASE_DOCUMENT)
|
||||||
|
.where(DATABASE_DOCUMENT.PROJECT_ID.eq(projectId).and(DATABASE_DOCUMENT.VERSION.eq(version)))
|
||||||
|
.fetchOptionalInto(Integer.class);
|
||||||
|
}
|
||||||
|
|
||||||
public void update(DatabaseDocumentPojo toPojo) {
|
public void update(DatabaseDocumentPojo toPojo) {
|
||||||
DatabaseDocumentRecord record = getDslContext().newRecord(DATABASE_DOCUMENT, toPojo);
|
DatabaseDocumentRecord record = getDslContext().newRecord(DATABASE_DOCUMENT, toPojo);
|
||||||
record.changed(DATABASE_DOCUMENT.ID, false);
|
record.changed(DATABASE_DOCUMENT.ID, false);
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 7bac0c7f123c89a1e70c82d43f2c7c7d061dd943
|
Subproject commit 05b6e6761238bcda003a787cb66c51a002c810c7
|
Loading…
Reference in New Issue