-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: alexeykozyurov <[email protected]>
- Loading branch information
1 parent
413a1d7
commit 6bb7624
Showing
104 changed files
with
3,252 additions
and
377 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/config/MinioConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.opendatadiscovery.oddplatform.config; | ||
|
||
import io.minio.MinioAsyncClient; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@ConditionalOnProperty(value = "attachment.storage", havingValue = "REMOTE") | ||
public class MinioConfig { | ||
@Value("${attachment.remote.url}") | ||
private String url; | ||
@Value("${attachment.remote.access-key}") | ||
private String accessKey; | ||
@Value("${attachment.remote.secret-key}") | ||
private String secretKey; | ||
|
||
@Bean | ||
public MinioAsyncClient minioClient() { | ||
return MinioAsyncClient.builder() | ||
.endpoint(url) | ||
.credentials(accessKey, secretKey) | ||
.build(); | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
...ain/java/org/opendatadiscovery/oddplatform/controller/DataEntityAttachmentController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package org.opendatadiscovery.oddplatform.controller; | ||
|
||
import java.util.UUID; | ||
import lombok.RequiredArgsConstructor; | ||
import org.opendatadiscovery.oddplatform.api.contract.api.DataEntityAttachmentApi; | ||
import org.opendatadiscovery.oddplatform.api.contract.model.DataEntityAttachments; | ||
import org.opendatadiscovery.oddplatform.api.contract.model.DataEntityFile; | ||
import org.opendatadiscovery.oddplatform.api.contract.model.DataEntityLink; | ||
import org.opendatadiscovery.oddplatform.api.contract.model.DataEntityLinkFormData; | ||
import org.opendatadiscovery.oddplatform.api.contract.model.DataEntityLinkListFormData; | ||
import org.opendatadiscovery.oddplatform.api.contract.model.DataEntityUpload; | ||
import org.opendatadiscovery.oddplatform.api.contract.model.DataEntityUploadFormData; | ||
import org.opendatadiscovery.oddplatform.api.contract.model.DataEntityUploadOptions; | ||
import org.opendatadiscovery.oddplatform.service.attachment.AttachmentService; | ||
import org.springframework.core.io.Resource; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.http.codec.multipart.Part; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.server.ServerWebExchange; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class DataEntityAttachmentController implements DataEntityAttachmentApi { | ||
private final AttachmentService attachmentService; | ||
|
||
@Override | ||
public Mono<ResponseEntity<DataEntityAttachments>> getAttachments(final Long dataEntityId, | ||
final ServerWebExchange exchange) { | ||
return attachmentService.getDataEntityAttachments(dataEntityId) | ||
.map(ResponseEntity::ok); | ||
} | ||
|
||
@Override | ||
public Mono<ResponseEntity<DataEntityUploadOptions>> getUploadOptions(final Long dataEntityId, | ||
final ServerWebExchange exchange) { | ||
return attachmentService.getUploadOptions() | ||
.map(ResponseEntity::ok); | ||
} | ||
|
||
@Override | ||
public Mono<ResponseEntity<DataEntityUpload>> initiateFileUpload(final Long dataEntityId, | ||
final Mono<DataEntityUploadFormData> formDataMono, | ||
final ServerWebExchange exchange) { | ||
return formDataMono | ||
.flatMap(formData -> attachmentService.initiateFileUpload(formData, dataEntityId)) | ||
.map(ResponseEntity::ok); | ||
} | ||
|
||
@Override | ||
public Mono<ResponseEntity<Void>> uploadFileChunk(final Long dataEntityId, | ||
final UUID uploadId, | ||
final Mono<Part> fileMono, | ||
final String index, | ||
final ServerWebExchange exchange) { | ||
return fileMono | ||
.flatMap(file -> attachmentService.uploadFileChunk(uploadId, file, Integer.parseInt(index))) | ||
.map(ResponseEntity::ok); | ||
} | ||
|
||
@Override | ||
public Mono<ResponseEntity<DataEntityFile>> completeFileUpload(final Long dataEntityId, | ||
final UUID uploadId, | ||
final ServerWebExchange exchange) { | ||
return attachmentService.completeFileUpload(uploadId) | ||
.map(ResponseEntity::ok); | ||
} | ||
|
||
@Override | ||
public Mono<ResponseEntity<Resource>> downloadFile(final Long dataEntityId, | ||
final Long fileId, | ||
final ServerWebExchange exchange) { | ||
return attachmentService.downloadFile(fileId).map(dto -> ResponseEntity.ok() | ||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + dto.fileName()) | ||
.contentType(MediaType.APPLICATION_OCTET_STREAM) | ||
.body(dto.resource())); | ||
} | ||
|
||
@Override | ||
public Mono<ResponseEntity<Void>> deleteFile(final Long dataEntityId, | ||
final Long fileId, | ||
final ServerWebExchange exchange) { | ||
return attachmentService.deleteFile(fileId) | ||
.thenReturn(ResponseEntity.noContent().build()); | ||
} | ||
|
||
@Override | ||
public Mono<ResponseEntity<Flux<DataEntityLink>>> saveLinks(final Long dataEntityId, | ||
final Mono<DataEntityLinkListFormData> formData, | ||
final ServerWebExchange exchange) { | ||
return formData | ||
.map(fd -> attachmentService.saveLinks(dataEntityId, fd)) | ||
.map(ResponseEntity::ok); | ||
} | ||
|
||
@Override | ||
public Mono<ResponseEntity<DataEntityLink>> updateLink(final Long dataEntityId, | ||
final Long linkId, | ||
final Mono<DataEntityLinkFormData> dataEntityLinkFormData, | ||
final ServerWebExchange exchange) { | ||
return dataEntityLinkFormData | ||
.flatMap(fd -> attachmentService.updateLink(linkId, fd)) | ||
.map(ResponseEntity::ok); | ||
} | ||
|
||
@Override | ||
public Mono<ResponseEntity<Void>> deleteLink(final Long dataEntityId, | ||
final Long linkId, | ||
final ServerWebExchange exchange) { | ||
return attachmentService.deleteLink(linkId) | ||
.thenReturn(ResponseEntity.noContent().build()); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/dto/FileDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.opendatadiscovery.oddplatform.dto; | ||
|
||
import org.springframework.core.io.Resource; | ||
|
||
public record FileDto(Resource resource, String fileName) { | ||
} |
27 changes: 27 additions & 0 deletions
27
odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/dto/FileUploadStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.opendatadiscovery.oddplatform.dto; | ||
|
||
import java.util.Arrays; | ||
import java.util.Optional; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
@Getter | ||
public enum FileUploadStatus { | ||
PROCESSING(1), | ||
COMPLETED(2); | ||
|
||
@Getter | ||
private final short code; | ||
|
||
FileUploadStatus(final int code) { | ||
this.code = ((short) code); | ||
} | ||
|
||
public static Optional<FileUploadStatus> fromCode(final short code) { | ||
return Arrays.stream(FileUploadStatus.values()) | ||
.filter(s -> s.getCode() == code) | ||
.findFirst(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...latform-api/src/main/java/org/opendatadiscovery/oddplatform/exception/MinioException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.opendatadiscovery.oddplatform.exception; | ||
|
||
public class MinioException extends RuntimeException { | ||
|
||
public MinioException(final Throwable cause) { | ||
super(cause); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/mapper/FileMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.opendatadiscovery.oddplatform.mapper; | ||
|
||
import java.util.UUID; | ||
import lombok.RequiredArgsConstructor; | ||
import org.opendatadiscovery.oddplatform.api.contract.model.DataEntityFile; | ||
import org.opendatadiscovery.oddplatform.api.contract.model.DataEntityUploadFormData; | ||
import org.opendatadiscovery.oddplatform.model.tables.pojos.FilePojo; | ||
import org.opendatadiscovery.oddplatform.service.attachment.FilePathConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
import static org.opendatadiscovery.oddplatform.dto.FileUploadStatus.PROCESSING; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class FileMapper { | ||
private final FilePathConstructor pathConstructor; | ||
|
||
public DataEntityFile mapToDto(final FilePojo pojo) { | ||
final DataEntityFile file = new DataEntityFile(); | ||
file.setId(pojo.getId()); | ||
file.setName(pojo.getName()); | ||
return file; | ||
} | ||
|
||
public FilePojo mapToProcessingPojo(final DataEntityUploadFormData fileMetadata, | ||
final UUID uploadId, | ||
final long dataEntityId) { | ||
final FilePojo filePojo = new FilePojo(); | ||
filePojo.setDataEntityId(dataEntityId); | ||
filePojo.setName(fileMetadata.getFileName()); | ||
filePojo.setPath(pathConstructor.getFilePath(fileMetadata.getFileName(), dataEntityId)); | ||
filePojo.setUploadId(uploadId); | ||
filePojo.setStatus(PROCESSING.getCode()); | ||
return filePojo; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/mapper/LinkMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.opendatadiscovery.oddplatform.mapper; | ||
|
||
import org.mapstruct.Mapper; | ||
import org.mapstruct.MappingTarget; | ||
import org.opendatadiscovery.oddplatform.api.contract.model.DataEntityLink; | ||
import org.opendatadiscovery.oddplatform.api.contract.model.DataEntityLinkFormData; | ||
import org.opendatadiscovery.oddplatform.model.tables.pojos.LinkPojo; | ||
|
||
@Mapper(config = MapperConfig.class) | ||
public interface LinkMapper { | ||
DataEntityLink mapToDto(final LinkPojo pojo); | ||
|
||
LinkPojo mapToPojo(final DataEntityLinkFormData formData, final long dataEntityId); | ||
|
||
LinkPojo applyToPojo(final DataEntityLinkFormData formData, | ||
@MappingTarget final LinkPojo pojo); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...i/src/main/java/org/opendatadiscovery/oddplatform/repository/reactive/FileRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.opendatadiscovery.oddplatform.repository.reactive; | ||
|
||
import java.util.UUID; | ||
import org.opendatadiscovery.oddplatform.model.tables.pojos.FilePojo; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
public interface FileRepository extends ReactiveCRUDRepository<FilePojo> { | ||
Mono<FilePojo> getFileByDataEntityAndName(final long dataEntityId, final String fileName); | ||
|
||
Mono<FilePojo> getFileByUploadId(final UUID uploadId); | ||
|
||
Flux<FilePojo> getDataEntityFiles(final long dataEntityId); | ||
} |
Oops, something went wrong.