You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by ka...@apache.org on 2020/06/02 14:29:56 UTC

[fineract] branch develop updated (d439aa9 -> 956a841)

This is an automated email from the ASF dual-hosted git repository.

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


    from d439aa9  replace api-docs links to mifos.io with fineract.dev [FINERACT-840]
     new df0bcb1  FINERACT-965 Upgrade, Replace itext 2.1.7 with Openpdf 1.1.0
     new 619fe44  bump OpenPDF from 1.1.0 to 1.3.17 + swap Base64 [FINERACT-965]
     new 83de217  minor clean-up in StaffImageApiTest (re. FINERACT-965)
     new 956a841  improve StaffImageApiTest (for FINERACT-965 non-regression)

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 fineract-provider/build.gradle                     |  4 +--
 fineract-provider/dependencies.gradle              |  2 +-
 .../integrationtests/StaffImageApiTest.java        | 40 ++++++++--------------
 .../integrationtests/common/ImageHelper.java       | 10 +++---
 .../documentmanagement/api/ImagesApiResource.java  |  9 ++---
 .../FileSystemContentRepository.java               | 15 ++++----
 .../contentrepository/S3ContentRepository.java     |  4 +--
 7 files changed, 37 insertions(+), 47 deletions(-)


[fineract] 03/04: minor clean-up in StaffImageApiTest (re. FINERACT-965)

Posted by ka...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 83de217b64226208a85ba25e19f27c21a502ce1a
Author: Michael Vorburger <mi...@vorburger.ch>
AuthorDate: Mon Jun 1 13:52:23 2020 +0200

    minor clean-up in StaffImageApiTest (re. FINERACT-965)
---
 .../integrationtests/StaffImageApiTest.java        | 37 +++++++---------------
 1 file changed, 11 insertions(+), 26 deletions(-)

diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/StaffImageApiTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/StaffImageApiTest.java
index 4582010..8707a39 100644
--- a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/StaffImageApiTest.java
+++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/StaffImageApiTest.java
@@ -18,6 +18,8 @@
  */
 package org.apache.fineract.integrationtests;
 
+import static org.junit.Assert.assertNotNull;
+
 import io.restassured.builder.RequestSpecBuilder;
 import io.restassured.builder.ResponseSpecBuilder;
 import io.restassured.http.ContentType;
@@ -25,10 +27,7 @@ import io.restassured.specification.RequestSpecification;
 import io.restassured.specification.ResponseSpecification;
 import org.apache.fineract.integrationtests.common.ImageHelper;
 import org.apache.fineract.integrationtests.common.Utils;
-import org.apache.fineract.integrationtests.common.accounting.AccountHelper;
-import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
 import org.apache.fineract.integrationtests.common.organisation.StaffHelper;
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -36,8 +35,6 @@ public class StaffImageApiTest {
 
     private RequestSpecification requestSpec;
     private ResponseSpecification responseSpec;
-    private LoanTransactionHelper loanTransactionHelper;
-    private AccountHelper accountHelper;
 
     @Before
     public void setup() {
@@ -45,60 +42,48 @@ public class StaffImageApiTest {
         this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
         this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
         this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
-        this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
-        this.accountHelper = new AccountHelper(this.requestSpec, this.responseSpec);
-
     }
 
     @Test
     public void createStaffImage() {
-
         Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
         Integer imageId = ImageHelper.createImageForStaff(this.requestSpec, this.responseSpec, staffId);
-        Assert.assertNotNull("Image id should not be null", imageId);
-
+        assertNotNull("Image id should not be null", imageId);
     }
 
     @Test
     public void getStaffImage(){
         Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
         Integer imageId = ImageHelper.createImageForStaff(this.requestSpec, this.responseSpec, staffId);
-        Assert.assertNotNull("Image id should not be null", imageId);
+        assertNotNull("Image id should not be null", imageId);
         String imageAsText = ImageHelper.getStaffImageAsText(this.requestSpec, this.responseSpec, staffId);
-        Assert.assertNotNull("Image id should not be null", imageAsText);
+        assertNotNull("Image id should not be null", imageAsText);
     }
 
     @Test
     public void getStaffImageAsBinary(){
         Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
         Integer imageId = ImageHelper.createImageForStaff(this.requestSpec, this.responseSpec, staffId);
-        Assert.assertNotNull("Image id should not be null", imageId);
+        assertNotNull("Image id should not be null", imageId);
         byte[] imageAsBytes = ImageHelper.getStaffImageAsBinary(this.requestSpec, this.responseSpec, staffId);
-        Assert.assertNotNull("Image content should not be null", imageAsBytes);
+        assertNotNull("Image content should not be null", imageAsBytes);
     }
 
     @Test
     public void updateImage() {
-
         Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
         Integer imageId = ImageHelper.createImageForStaff(this.requestSpec, this.responseSpec, staffId);
-        Assert.assertNotNull("Image id should not be null", imageId);
+        assertNotNull("Image id should not be null", imageId);
         imageId = ImageHelper.updateImageForStaff(this.requestSpec, this.responseSpec, staffId);
-        Assert.assertNotNull("Image id should not be null", imageId);
-
+        assertNotNull("Image id should not be null", imageId);
     }
 
     @Test
     public void deleteStaffImage() {
-
         Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
         Integer imageId = ImageHelper.createImageForStaff(this.requestSpec, this.responseSpec, staffId);
-        Assert.assertNotNull("Image id should not be null", imageId);
+        assertNotNull("Image id should not be null", imageId);
         imageId = ImageHelper.deleteStaffImage(this.requestSpec, this.responseSpec, staffId);
-        Assert.assertNotNull("Image id should not be null", imageId);
-
+        assertNotNull("Image id should not be null", imageId);
     }
-
-
-
 }


[fineract] 02/04: bump OpenPDF from 1.1.0 to 1.3.17 + swap Base64 [FINERACT-965]

Posted by ka...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 619fe44d0e1fbfe8a34f594dfa0b3b81a5153cc4
Author: Michael Vorburger <mi...@vorburger.ch>
AuthorDate: Thu May 28 23:09:04 2020 +0200

    bump OpenPDF from 1.1.0 to 1.3.17 + swap Base64 [FINERACT-965]
    
    and replace com.lowagie.text.pdf.codec.Base64 with java.util.Base64
---
 fineract-provider/build.gradle                            |  2 +-
 .../documentmanagement/api/ImagesApiResource.java         |  9 +++++----
 .../contentrepository/FileSystemContentRepository.java    | 15 ++++++++-------
 .../contentrepository/S3ContentRepository.java            |  4 ++--
 4 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/fineract-provider/build.gradle b/fineract-provider/build.gradle
index 4dad4fa..3ca9e70 100644
--- a/fineract-provider/build.gradle
+++ b/fineract-provider/build.gradle
@@ -89,7 +89,7 @@ dependencyManagement {
         dependency 'org.apache.commons:commons-email:1.5'
         dependency 'org.apache.commons:commons-io:+'
         dependency 'org.drizzle.jdbc:drizzle-jdbc:1.4'
-        dependency 'com.github.librepdf:openpdf:1.1.0'
+        dependency 'com.github.librepdf:openpdf:1.3.17'
         dependency 'org.mnode.ical4j:ical4j:3.0.18'
         dependency 'org.flywaydb:flyway-core:6.4.1'
         dependency 'org.quartz-scheduler:quartz:+'
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/api/ImagesApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/api/ImagesApiResource.java
index f5db11f..6bd8f8e 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/api/ImagesApiResource.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/api/ImagesApiResource.java
@@ -18,12 +18,12 @@
  */
 package org.apache.fineract.infrastructure.documentmanagement.api;
 
-import com.lowagie.text.pdf.codec.Base64;
 import com.sun.jersey.core.header.FormDataContentDisposition;
 import com.sun.jersey.multipart.FormDataBodyPart;
 import com.sun.jersey.multipart.FormDataParam;
 import io.swagger.annotations.Api;
 import java.io.InputStream;
+import java.util.Base64;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
@@ -140,7 +140,8 @@ public class ImagesApiResource {
             imageDataURISuffix = ContentRepositoryUtils.ImageDataURIsuffix.PNG.getValue();
         }
 
-        final String clientImageAsBase64Text = imageDataURISuffix + Base64.encodeBytes(imageData.getContentOfSize(maxWidth, maxHeight));
+        byte[] resizedImage = imageData.getContentOfSize(maxWidth, maxHeight);
+        final String clientImageAsBase64Text = imageDataURISuffix + Base64.getMimeEncoder().encodeToString(resizedImage);
         return Response.ok(clientImageAsBase64Text).build();
     }
 
@@ -162,7 +163,7 @@ public class ImagesApiResource {
         final ResponseBuilder response = Response.ok(imageData.getContentOfSize(maxWidth, maxHeight));
         String dispositionType = "inline_octet".equals(output) ? "inline" : "attachment";
         response.header("Content-Disposition", dispositionType + "; filename=\"" + imageData.getEntityDisplayName()
-                + ImageFileExtension.JPEG + "\"");
+        + ImageFileExtension.JPEG + "\"");
 
         // TODO: Need a better way of determining image type
 
@@ -207,7 +208,7 @@ public class ImagesApiResource {
     }
 
     /*** Entities for document Management **/
-    public static enum EntityTypeForImages {
+    public enum EntityTypeForImages {
         STAFF, CLIENTS;
 
         @Override
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/contentrepository/FileSystemContentRepository.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/contentrepository/FileSystemContentRepository.java
index c52272c..54f8018 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/contentrepository/FileSystemContentRepository.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/contentrepository/FileSystemContentRepository.java
@@ -18,12 +18,12 @@
  */
 package org.apache.fineract.infrastructure.documentmanagement.contentrepository;
 
-import com.lowagie.text.pdf.codec.Base64;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.util.Base64;
 import org.apache.fineract.infrastructure.core.domain.Base64EncodedImage;
 import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
 import org.apache.fineract.infrastructure.documentmanagement.command.DocumentCommand;
@@ -76,14 +76,18 @@ public class FileSystemContentRepository implements ContentRepository {
         makeDirectories(uploadImageLocation);
 
         final String fileLocation = uploadImageLocation + File.separator + imageName + base64EncodedImage.getFileExtension();
+        final String base64EncodedImageString = base64EncodedImage.getBase64EncodedString();
         try {
             final OutputStream out = new FileOutputStream(new File(fileLocation));
-            final byte[] imgBytes = Base64.decode(base64EncodedImage.getBase64EncodedString());
+            final byte[] imgBytes = Base64.getMimeDecoder().decode(base64EncodedImageString);
             out.write(imgBytes);
             out.flush();
             out.close();
         } catch (final IOException ioe) {
             throw new ContentManagementException(imageName, ioe.getMessage());
+        } catch (IllegalArgumentException iae) {
+            logger.error("IllegalArgumentException due to invalid Base64 encoding: {}", base64EncodedImageString, iae);
+            throw iae;
         }
         return fileLocation;
     }
@@ -128,10 +132,6 @@ public class FileSystemContentRepository implements ContentRepository {
 
     /**
      * Generate the directory path for storing the new document
-     *
-     * @param entityType
-     * @param entityId
-     * @return
      */
     private String generateFileParentDirectory(final String entityType, final Long entityId) {
         return FileSystemContentRepository.FINERACT_BASE_DIR + File.separator
@@ -149,7 +149,7 @@ public class FileSystemContentRepository implements ContentRepository {
     }
 
     /**
-     * Recursively create the directory if it does not exist *
+     * Recursively create the directory if it does not exist.
      */
     private void makeDirectories(final String uploadDocumentLocation) {
         if (!new File(uploadDocumentLocation).isDirectory()) {
@@ -169,6 +169,7 @@ public class FileSystemContentRepository implements ContentRepository {
             out.flush();
             out.close();
         } catch (final IOException ioException) {
+            logger.warn("writeFileToFileSystem() IOException (logged because cause is not propagated in ContentManagementException)", ioException);
             throw new ContentManagementException(fileName, ioException.getMessage());
         }
     }
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/contentrepository/S3ContentRepository.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/contentrepository/S3ContentRepository.java
index 6732a52..b209526 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/contentrepository/S3ContentRepository.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/documentmanagement/contentrepository/S3ContentRepository.java
@@ -30,10 +30,10 @@ import com.amazonaws.services.s3.model.GetObjectRequest;
 import com.amazonaws.services.s3.model.ObjectMetadata;
 import com.amazonaws.services.s3.model.PutObjectRequest;
 import com.amazonaws.services.s3.model.S3Object;
-import com.lowagie.text.pdf.codec.Base64;
 import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.InputStream;
+import java.util.Base64;
 import org.apache.fineract.infrastructure.core.domain.Base64EncodedImage;
 import org.apache.fineract.infrastructure.documentmanagement.command.DocumentCommand;
 import org.apache.fineract.infrastructure.documentmanagement.data.DocumentData;
@@ -94,7 +94,7 @@ public class S3ContentRepository implements ContentRepository {
     public String saveImage(final Base64EncodedImage base64EncodedImage, final Long resourceId, final String imageName) {
         final String uploadImageLocation = generateClientImageParentDirectory(resourceId);
         final String fileLocation = uploadImageLocation + File.separator + imageName + base64EncodedImage.getFileExtension();
-        final InputStream toUploadInputStream = new ByteArrayInputStream(Base64.decode(base64EncodedImage.getBase64EncodedString()));
+        final InputStream toUploadInputStream = new ByteArrayInputStream(Base64.getMimeDecoder().decode(base64EncodedImage.getBase64EncodedString()));
 
         uploadDocument(imageName, toUploadInputStream, fileLocation);
         return fileLocation;


[fineract] 01/04: FINERACT-965 Upgrade, Replace itext 2.1.7 with Openpdf 1.1.0

Posted by ka...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit df0bcb1b97565b98d366e5c29c7df076911bdbcf
Author: nnatarajan <na...@gmail.com>
AuthorDate: Tue May 26 13:12:45 2020 -0600

    FINERACT-965 Upgrade, Replace itext 2.1.7 with Openpdf 1.1.0
---
 fineract-provider/build.gradle        | 4 ++--
 fineract-provider/dependencies.gradle | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/fineract-provider/build.gradle b/fineract-provider/build.gradle
index d1e53f9..4dad4fa 100644
--- a/fineract-provider/build.gradle
+++ b/fineract-provider/build.gradle
@@ -89,8 +89,7 @@ dependencyManagement {
         dependency 'org.apache.commons:commons-email:1.5'
         dependency 'org.apache.commons:commons-io:+'
         dependency 'org.drizzle.jdbc:drizzle-jdbc:1.4'
-        dependency 'com.lowagie:itext:2.1.7'
-        dependency 'com.lowagie:itext-rtf:2.1.7'
+        dependency 'com.github.librepdf:openpdf:1.1.0'
         dependency 'org.mnode.ical4j:ical4j:3.0.18'
         dependency 'org.flywaydb:flyway-core:6.4.1'
         dependency 'org.quartz-scheduler:quartz:+'
@@ -182,6 +181,7 @@ openjpa {
 jacoco {
     toolVersion = jacocoVersion
     reportsDir = file("$buildDir/reports/jacoco")
+
 }
 
 jacocoTestReport{
diff --git a/fineract-provider/dependencies.gradle b/fineract-provider/dependencies.gradle
index 56e83fc..2b14a63 100644
--- a/fineract-provider/dependencies.gradle
+++ b/fineract-provider/dependencies.gradle
@@ -66,7 +66,7 @@ dependencies {
             'org.flywaydb:flyway-core',
 
             'net.sf.ehcache:ehcache',
-            'com.lowagie:itext',
+            'com.github.librepdf:openpdf',
             'com.github.spullara.mustache.java:compiler',
             'com.jayway.jsonpath:json-path',
 


[fineract] 04/04: improve StaffImageApiTest (for FINERACT-965 non-regression)

Posted by ka...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 956a84114fe52c51591cfa37b8c331f95a6ffcaa
Author: Michael Vorburger <mi...@vorburger.ch>
AuthorDate: Mon Jun 1 14:01:13 2020 +0200

    improve StaffImageApiTest (for FINERACT-965 non-regression)
---
 .../apache/fineract/integrationtests/StaffImageApiTest.java    |  3 +++
 .../apache/fineract/integrationtests/common/ImageHelper.java   | 10 +++++-----
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/StaffImageApiTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/StaffImageApiTest.java
index 8707a39..d201031 100644
--- a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/StaffImageApiTest.java
+++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/StaffImageApiTest.java
@@ -18,6 +18,7 @@
  */
 package org.apache.fineract.integrationtests;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
 import io.restassured.builder.RequestSpecBuilder;
@@ -58,6 +59,7 @@ public class StaffImageApiTest {
         assertNotNull("Image id should not be null", imageId);
         String imageAsText = ImageHelper.getStaffImageAsText(this.requestSpec, this.responseSpec, staffId);
         assertNotNull("Image id should not be null", imageAsText);
+        assertEquals(ImageHelper.generateImageAsText(), imageAsText);
     }
 
     @Test
@@ -67,6 +69,7 @@ public class StaffImageApiTest {
         assertNotNull("Image id should not be null", imageId);
         byte[] imageAsBytes = ImageHelper.getStaffImageAsBinary(this.requestSpec, this.responseSpec, staffId);
         assertNotNull("Image content should not be null", imageAsBytes);
+        assertEquals(251, imageAsBytes.length);
     }
 
     @Test
diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ImageHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ImageHelper.java
index 42d523c..45f8592 100644
--- a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ImageHelper.java
+++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/ImageHelper.java
@@ -65,10 +65,10 @@ public class ImageHelper {
         return Utils.performServerDelete(requestSpec, responseSpec, URL, "resourceId");
     }
 
-    private static String generateImageAsText() {
-        return "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJ\n"
-                + "bWFnZVJlYWR5ccllPAAAAJ1JREFUeNpi+P//PwMIA4E9EG8E4idQDGLbw+WhiiqA+D8OXAFVAzbp\n"
-                + "DxBvB2JLIGaGYkuoGEjOhhFIHAbij0BdPgxYACMj42ogJQpifwBiXSDeC8JIbt4LxSC5DyxQjTeB\n"
-                + "+BeaYb+Q5EBOAVutCzMJHUNNPADzzDokiYdAfAmJvwLkGeTgWQfyKZICS6hYBTwc0QL8ORSjBDhA\n" + "gAEAOg13B6R/SAgAAAAASUVORK5CYII=";
+    public static String generateImageAsText() {
+        return "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJ\r\n"
+                + "bWFnZVJlYWR5ccllPAAAAJ1JREFUeNpi+P//PwMIA4E9EG8E4idQDGLbw+WhiiqA+D8OXAFVAzbp\r\n"
+                + "DxBvB2JLIGaGYkuoGEjOhhFIHAbij0BdPgxYACMj42ogJQpifwBiXSDeC8JIbt4LxSC5DyxQjTeB\r\n"
+                + "+BeaYb+Q5EBOAVutCzMJHUNNPADzzDokiYdAfAmJvwLkGeTgWQfyKZICS6hYBTwc0QL8ORSjBDhA\r\n" + "gAEAOg13B6R/SAgAAAAASUVORK5CYII=";
     }
 }