Skip to content

Commit

Permalink
feat : remove lombok
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Mar 22, 2024
1 parent a2dcf12 commit 596e90a
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 59 deletions.
2 changes: 1 addition & 1 deletion aws-s3-project/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
docker/volume/
docker/volume/
26 changes: 2 additions & 24 deletions aws-s3-project/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
Expand Down Expand Up @@ -166,14 +162,6 @@
</goals>
</execution>
</executions>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.cyclonedx</groupId>
Expand All @@ -189,16 +177,6 @@
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>0.2.0</version>
</dependency>
</annotationProcessorPaths>
<compilerArgs>
<compilerArg>
Expand Down Expand Up @@ -324,7 +302,7 @@
<configuration>
<java>
<googleJavaFormat>
<version>1.18.1</version>
<version>1.19.2</version>
<style>AOSP</style>
</googleJavaFormat>
</java>
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand All @@ -58,30 +69,30 @@ public List<String> 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();
Assert.notNull(fileName, () -> "FileName Can't be null");
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()
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<FileInfo> findAllFiles() {
log.info("Retrieving all files info");
return fileInfoRepository.findAll();
Expand Down

0 comments on commit 596e90a

Please sign in to comment.