From 596e90ac611077d5ca747fae3c02858c3542cc2a Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Fri, 22 Mar 2024 07:27:27 +0000 Subject: [PATCH] feat : remove lombok --- aws-s3-project/.gitignore | 2 +- aws-s3-project/pom.xml | 26 +---------- .../config/ApplicationProperties.java | 7 +-- .../controller/FileInfoController.java | 7 ++- .../learning/awspring/entities/FileInfo.java | 46 +++++++++++++++---- .../awspring/service/AwsS3Service.java | 39 ++++++++++------ .../awspring/service/FileInfoService.java | 13 ++++-- 7 files changed, 81 insertions(+), 59 deletions(-) diff --git a/aws-s3-project/.gitignore b/aws-s3-project/.gitignore index 2cb4e262..b4a843df 100644 --- a/aws-s3-project/.gitignore +++ b/aws-s3-project/.gitignore @@ -1 +1 @@ -docker/volume/ \ No newline at end of file +docker/volume/ diff --git a/aws-s3-project/pom.xml b/aws-s3-project/pom.xml index 1c3107d8..afe6da3a 100644 --- a/aws-s3-project/pom.xml +++ b/aws-s3-project/pom.xml @@ -63,11 +63,7 @@ spring-boot-configuration-processor true - - org.projectlombok - lombok - true - + org.mapstruct mapstruct @@ -166,14 +162,6 @@ - - - - org.projectlombok - lombok - - - org.cyclonedx @@ -189,16 +177,6 @@ mapstruct-processor ${org.mapstruct.version} - - org.projectlombok - lombok - ${lombok.version} - - - org.projectlombok - lombok-mapstruct-binding - 0.2.0 - @@ -324,7 +302,7 @@ - 1.18.1 + 1.19.2 diff --git a/aws-s3-project/src/main/java/com/learning/awspring/config/ApplicationProperties.java b/aws-s3-project/src/main/java/com/learning/awspring/config/ApplicationProperties.java index bbd0d224..c1c60be8 100644 --- a/aws-s3-project/src/main/java/com/learning/awspring/config/ApplicationProperties.java +++ b/aws-s3-project/src/main/java/com/learning/awspring/config/ApplicationProperties.java @@ -1,11 +1,6 @@ package com.learning.awspring.config; -import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; -@Data @ConfigurationProperties("application") -public class ApplicationProperties { - - private String bucketName; -} +public record ApplicationProperties(String bucketName) {} diff --git a/aws-s3-project/src/main/java/com/learning/awspring/controller/FileInfoController.java b/aws-s3-project/src/main/java/com/learning/awspring/controller/FileInfoController.java index 6a8ba67e..93017a81 100644 --- a/aws-s3-project/src/main/java/com/learning/awspring/controller/FileInfoController.java +++ b/aws-s3-project/src/main/java/com/learning/awspring/controller/FileInfoController.java @@ -10,7 +10,6 @@ import java.io.IOException; import java.net.URISyntaxException; import java.util.List; -import lombok.RequiredArgsConstructor; import org.springframework.core.io.InputStreamResource; import org.springframework.http.CacheControl; import org.springframework.http.ContentDisposition; @@ -25,12 +24,16 @@ import org.springframework.web.multipart.MultipartFile; @RestController -@RequiredArgsConstructor public class FileInfoController { private final AwsS3Service awsS3Service; private final FileInfoService fileInfoService; + public FileInfoController(AwsS3Service awsS3Service, FileInfoService fileInfoService) { + this.awsS3Service = awsS3Service; + this.fileInfoService = fileInfoService; + } + @PostMapping( value = "/s3/upload", consumes = {MediaType.MULTIPART_FORM_DATA_VALUE}, diff --git a/aws-s3-project/src/main/java/com/learning/awspring/entities/FileInfo.java b/aws-s3-project/src/main/java/com/learning/awspring/entities/FileInfo.java index ef4f48f6..a2f2b580 100644 --- a/aws-s3-project/src/main/java/com/learning/awspring/entities/FileInfo.java +++ b/aws-s3-project/src/main/java/com/learning/awspring/entities/FileInfo.java @@ -6,18 +6,10 @@ import jakarta.persistence.Id; import jakarta.persistence.Table; import java.util.Objects; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.experimental.Accessors; import org.hibernate.proxy.HibernateProxy; -@Getter -@Setter -@Accessors(chain = true) @Table(name = "file_info") @Entity -@NoArgsConstructor public class FileInfo { @Id @@ -28,12 +20,50 @@ public class FileInfo { private String fileUrl; private boolean isUploadSuccessFull; + public FileInfo() {} + public FileInfo(String fileName, String fileUrl, boolean isUploadSuccessFull) { this.fileName = fileName; this.fileUrl = fileUrl; this.isUploadSuccessFull = isUploadSuccessFull; } + public Integer getId() { + return id; + } + + public FileInfo setId(Integer id) { + this.id = id; + return this; + } + + public String getFileName() { + return fileName; + } + + public FileInfo setFileName(String fileName) { + this.fileName = fileName; + return this; + } + + public String getFileUrl() { + return fileUrl; + } + + public FileInfo setFileUrl(String fileUrl) { + this.fileUrl = fileUrl; + return this; + } + + public boolean isUploadSuccessFull() { + return isUploadSuccessFull; + } + + public FileInfo setUploadSuccessFull(boolean isUploadSuccessFull) { + this.isUploadSuccessFull = isUploadSuccessFull; + return this; + } + @Override public final boolean equals(Object o) { if (this == o) { diff --git a/aws-s3-project/src/main/java/com/learning/awspring/service/AwsS3Service.java b/aws-s3-project/src/main/java/com/learning/awspring/service/AwsS3Service.java index e580680d..73bb4164 100644 --- a/aws-s3-project/src/main/java/com/learning/awspring/service/AwsS3Service.java +++ b/aws-s3-project/src/main/java/com/learning/awspring/service/AwsS3Service.java @@ -19,8 +19,8 @@ import java.time.Duration; import java.util.List; import java.util.Objects; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -32,23 +32,34 @@ import software.amazon.awssdk.core.exception.SdkClientException; @Service -@Slf4j -@RequiredArgsConstructor @Loggable public class AwsS3Service { + private static final Logger log = LoggerFactory.getLogger(AwsS3Service.class); + private final ApplicationProperties applicationProperties; private final FileInfoRepository fileInfoRepository; private final S3Template s3Template; private final RestTemplate restTemplate; + public AwsS3Service( + ApplicationProperties applicationProperties, + FileInfoRepository fileInfoRepository, + S3Template s3Template, + RestTemplate restTemplate) { + this.applicationProperties = applicationProperties; + this.fileInfoRepository = fileInfoRepository; + this.s3Template = s3Template; + this.restTemplate = restTemplate; + } + public S3Resource downloadFileFromS3Bucket(final String fileName) throws IOException { log.info( "Downloading file '{}' from bucket: '{}' ", fileName, - applicationProperties.getBucketName()); - if (this.s3Template.objectExists(applicationProperties.getBucketName(), fileName)) { - return this.s3Template.download(applicationProperties.getBucketName(), fileName); + applicationProperties.bucketName()); + if (this.s3Template.objectExists(applicationProperties.bucketName(), fileName)) { + return this.s3Template.download(applicationProperties.bucketName(), fileName); } else { throw new FileNotFoundException(fileName); } @@ -58,19 +69,19 @@ public List listObjects() { if (getBucketExists()) { log.info( "Retrieving object summaries for bucket '{}'", - applicationProperties.getBucketName()); - return this.s3Template.listObjects(applicationProperties.getBucketName(), "").stream() + applicationProperties.bucketName()); + return this.s3Template.listObjects(applicationProperties.bucketName(), "").stream() .map(s3Resource -> s3Resource.getLocation().getObject()) .toList(); } else { - throw new BucketNotFoundException(applicationProperties.getBucketName()); + throw new BucketNotFoundException(applicationProperties.bucketName()); } } public FileInfo uploadObjectToS3(MultipartFile multipartFile) throws SdkClientException, IOException { if (!getBucketExists()) { - String location = createBucket(applicationProperties.getBucketName()); + String location = createBucket(applicationProperties.bucketName()); log.info("Created bucket at {}", location); } String fileName = multipartFile.getOriginalFilename(); @@ -78,10 +89,10 @@ public FileInfo uploadObjectToS3(MultipartFile multipartFile) log.info( "Uploading file '{}' to bucket: '{}' ", fileName, - applicationProperties.getBucketName()); + applicationProperties.bucketName()); S3Resource s3Resource = this.s3Template.upload( - applicationProperties.getBucketName(), + applicationProperties.bucketName(), fileName, multipartFile.getInputStream(), ObjectMetadata.builder() @@ -133,7 +144,7 @@ public GenericResponse uploadFileWithPreSignedUrl( } private boolean getBucketExists() { - return this.s3Template.bucketExists(applicationProperties.getBucketName()); + return this.s3Template.bucketExists(applicationProperties.bucketName()); } private String createBucket(String bucketName) { diff --git a/aws-s3-project/src/main/java/com/learning/awspring/service/FileInfoService.java b/aws-s3-project/src/main/java/com/learning/awspring/service/FileInfoService.java index bae0adee..808938f2 100644 --- a/aws-s3-project/src/main/java/com/learning/awspring/service/FileInfoService.java +++ b/aws-s3-project/src/main/java/com/learning/awspring/service/FileInfoService.java @@ -3,16 +3,21 @@ import com.learning.awspring.entities.FileInfo; import com.learning.awspring.repository.FileInfoRepository; import java.util.List; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; @Service -@Slf4j -@RequiredArgsConstructor public class FileInfoService { + + private static final Logger log = LoggerFactory.getLogger(FileInfoService.class); + private final FileInfoRepository fileInfoRepository; + public FileInfoService(FileInfoRepository fileInfoRepository) { + this.fileInfoRepository = fileInfoRepository; + } + public List findAllFiles() { log.info("Retrieving all files info"); return fileInfoRepository.findAll();