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
This commit is contained in:
committed by
Yemdjih Kaze Nasser
parent
df0bcb1b97
commit
619fe44d0e
@@ -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:+'
|
||||
|
||||
+5
-4
@@ -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
|
||||
|
||||
+8
-7
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user