fineract-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ptuom...@apache.org
Subject [fineract] 01/04: Clean up ImageData (FINERACT-1201)
Date Fri, 06 Nov 2020 03:27:26 GMT
This is an automated email from the ASF dual-hosted git repository.

ptuomola pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract.git

commit 0af9aa3d0c4bb96bc6010fca5fde3f3c30ea7e1e
Author: Michael Vorburger <mike@vorburger.ch>
AuthorDate: Sun Oct 18 01:15:09 2020 +0200

    Clean up ImageData (FINERACT-1201)
---
 .../infrastructure/core/domain/JdbcSupport.java    |  4 +---
 .../documentmanagement/data/ImageData.java         | 24 +++++++++-------------
 .../service/ImageReadPlatformServiceImpl.java      |  8 ++++----
 3 files changed, 15 insertions(+), 21 deletions(-)

diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/JdbcSupport.java
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/JdbcSupport.java
index bfb733c..4179d7e 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/JdbcSupport.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/domain/JdbcSupport.java
@@ -37,9 +37,7 @@ import org.springframework.jdbc.support.JdbcUtils;
  */
 public final class JdbcSupport {
 
-    private JdbcSupport() {
-
-    }
+    private JdbcSupport() {}
 
     public static ZonedDateTime getDateTime(final ResultSet rs, final String columnName)
throws SQLException {
         ZonedDateTime dateTime = null;
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/data/ImageData.java
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/data/ImageData.java
index 7b46840..8c6851d 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/data/ImageData.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/data/ImageData.java
@@ -40,28 +40,25 @@ public class ImageData {
 
     private static final Logger LOG = LoggerFactory.getLogger(ImageData.class);
 
-    @SuppressWarnings("unused")
-    private final Long imageId;
     private final String location;
-    private final Integer storageType;
+    private final StorageType storageType;
     private final String entityDisplayName;
 
     private File file;
     private ContentRepositoryUtils.ImageFileExtension fileExtension;
     private InputStream inputStream;
 
-    public ImageData(final Long imageId, final String location, final Integer storageType,
final String entityDisplayName) {
-        this.imageId = imageId;
+    public ImageData(final String location, final StorageType storageType, final String entityDisplayName)
{
         this.location = location;
         this.storageType = storageType;
         this.entityDisplayName = entityDisplayName;
     }
 
-    public byte[] getContent() {
+    private byte[] getContent() {
         try {
-            if (this.storageType.equals(StorageType.S3.getValue()) && this.inputStream
!= null) {
+            if (this.storageType.equals(StorageType.S3) && this.inputStream != null)
{
                 return IOUtils.toByteArray(this.inputStream);
-            } else if (this.storageType.equals(StorageType.FILE_SYSTEM.getValue()) &&
this.file != null) {
+            } else if (this.storageType.equals(StorageType.FILE_SYSTEM) && this.file
!= null) {
                 final FileInputStream fileInputStream = new FileInputStream(this.file);
                 return IOUtils.toByteArray(fileInputStream);
             }
@@ -71,14 +68,13 @@ public class ImageData {
         return null;
     }
 
-    public byte[] resizeImage(InputStream in, int maxWidth, int maxHeight) throws IOException
{
+    private byte[] resizeImage(InputStream in, int maxWidth, int maxHeight) throws IOException
{
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         resizeImage(in, out, maxWidth, maxHeight);
         return out.toByteArray();
     }
 
-    public void resizeImage(InputStream in, OutputStream out, int maxWidth, int maxHeight)
throws IOException {
-
+    private void resizeImage(InputStream in, OutputStream out, int maxWidth, int maxHeight)
throws IOException {
         BufferedImage src = ImageIO.read(in);
         if (src.getWidth() <= maxWidth && src.getHeight() <= maxHeight) {
             out.write(getContent());
@@ -108,14 +104,14 @@ public class ImageData {
             return getContent();
         }
         byte[] out = null;
-        if (this.storageType.equals(StorageType.S3.getValue()) && this.inputStream
!= null) {
+        if (this.storageType.equals(StorageType.S3) && this.inputStream != null)
{
             try {
                 out = resizeImage(this.inputStream, maxWidth != null ? maxWidth : Integer.MAX_VALUE,
                         maxHeight != null ? maxHeight : Integer.MAX_VALUE);
             } catch (IOException e) {
                 LOG.error("Error occured.", e);
             }
-        } else if (this.storageType.equals(StorageType.FILE_SYSTEM.getValue()) &&
this.file != null) {
+        } else if (this.storageType.equals(StorageType.FILE_SYSTEM) && this.file
!= null) {
             FileInputStream fis = null;
             try {
                 fis = new FileInputStream(this.file);
@@ -157,7 +153,7 @@ public class ImageData {
     }
 
     public StorageType storageType() {
-        return StorageType.fromInt(this.storageType);
+        return this.storageType;
     }
 
     public String name() {
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/service/ImageReadPlatformServiceImpl.java
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/service/ImageReadPlatformServiceImpl.java
index 2e8b692..fe286bf 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/service/ImageReadPlatformServiceImpl.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/service/ImageReadPlatformServiceImpl.java
@@ -26,6 +26,7 @@ import org.apache.fineract.infrastructure.documentmanagement.api.ImagesApiResour
 import org.apache.fineract.infrastructure.documentmanagement.contentrepository.ContentRepository;
 import org.apache.fineract.infrastructure.documentmanagement.contentrepository.ContentRepositoryFactory;
 import org.apache.fineract.infrastructure.documentmanagement.data.ImageData;
+import org.apache.fineract.infrastructure.documentmanagement.domain.StorageType;
 import org.apache.fineract.organisation.staff.domain.Staff;
 import org.apache.fineract.organisation.staff.domain.StaffRepositoryWrapper;
 import org.apache.fineract.portfolio.client.domain.Client;
@@ -75,11 +76,10 @@ public class ImageReadPlatformServiceImpl implements ImageReadPlatformService
{
 
         @Override
         public ImageData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int
rowNum) throws SQLException {
-
-            final Long id = JdbcSupport.getLong(rs, "id");
             final String location = rs.getString("location");
-            final Integer storageType = JdbcSupport.getInteger(rs, "storageType");
-            return new ImageData(id, location, storageType, this.entityDisplayName);
+            final Integer storageTypeInt = JdbcSupport.getInteger(rs, "storageType");
+            StorageType storageType = storageTypeInt != null ? StorageType.fromInt(storageTypeInt)
: null;
+            return new ImageData(location, storageType, this.entityDisplayName);
         }
     }
 


Mime
View raw message