Remove unused fileName and resourceId from ContentRepository deleteFile() & deleteImage() (FINERACT-1201)
This commit is contained in:
committed by
Percy Enoabane
parent
bf0c7e240f
commit
3e1444a6e4
+5
-2
@@ -26,6 +26,9 @@ import org.apache.fineract.infrastructure.documentmanagement.data.FileData;
|
|||||||
import org.apache.fineract.infrastructure.documentmanagement.data.ImageData;
|
import org.apache.fineract.infrastructure.documentmanagement.data.ImageData;
|
||||||
import org.apache.fineract.infrastructure.documentmanagement.domain.StorageType;
|
import org.apache.fineract.infrastructure.documentmanagement.domain.StorageType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repository which stores Files (AKA Documents) and Images.
|
||||||
|
*/
|
||||||
public interface ContentRepository {
|
public interface ContentRepository {
|
||||||
|
|
||||||
// TODO:Vishwas Need to move these settings to the Database
|
// TODO:Vishwas Need to move these settings to the Database
|
||||||
@@ -36,7 +39,7 @@ public interface ContentRepository {
|
|||||||
|
|
||||||
String saveFile(InputStream uploadedInputStream, DocumentCommand documentCommand);
|
String saveFile(InputStream uploadedInputStream, DocumentCommand documentCommand);
|
||||||
|
|
||||||
void deleteFile(String fileName, String documentPath);
|
void deleteFile(String documentPath);
|
||||||
|
|
||||||
FileData fetchFile(DocumentData documentData);
|
FileData fetchFile(DocumentData documentData);
|
||||||
|
|
||||||
@@ -44,7 +47,7 @@ public interface ContentRepository {
|
|||||||
|
|
||||||
String saveImage(Base64EncodedImage base64EncodedImage, Long resourceId, String imageName);
|
String saveImage(Base64EncodedImage base64EncodedImage, Long resourceId, String imageName);
|
||||||
|
|
||||||
void deleteImage(Long resourceId, String location);
|
void deleteImage(String location);
|
||||||
|
|
||||||
ImageData fetchImage(ImageData imageData);
|
ImageData fetchImage(ImageData imageData);
|
||||||
|
|
||||||
|
|||||||
+10
-13
@@ -78,25 +78,22 @@ public class FileSystemContentRepository implements ContentRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteImage(final Long resourceId, final String location) {
|
public void deleteImage(final String location) {
|
||||||
final boolean fileDeleted = deleteFile(location);
|
deleteFileInternal(location);
|
||||||
if (!fileDeleted) {
|
|
||||||
// no need to throw an Error, simply log a warning
|
|
||||||
LOG.warn("Unable to delete image associated with clients with Id {}", resourceId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteFile(final String fileName, final String documentPath) {
|
public void deleteFile(final String documentPath) {
|
||||||
final boolean fileDeleted = deleteFile(documentPath);
|
deleteFileInternal(documentPath);
|
||||||
if (!fileDeleted) {
|
|
||||||
throw new ContentManagementException(fileName, null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean deleteFile(final String documentPath) {
|
private void deleteFileInternal(final String documentPath) {
|
||||||
final File fileToBeDeleted = new File(documentPath);
|
final File fileToBeDeleted = new File(documentPath);
|
||||||
return fileToBeDeleted.delete();
|
final boolean fileDeleted = fileToBeDeleted.delete();
|
||||||
|
if (!fileDeleted) {
|
||||||
|
// no need to throw an Error, what's a caller going to do about it, so simply log a warning
|
||||||
|
LOG.warn("Unable to delete file {}", documentPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+2
-2
@@ -73,7 +73,7 @@ public class S3ContentRepository implements ContentRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteFile(final String documentName, final String documentPath) {
|
public void deleteFile(final String documentPath) {
|
||||||
deleteObject(documentPath);
|
deleteObject(documentPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,7 +99,7 @@ public class S3ContentRepository implements ContentRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteImage(final Long resourceId, final String location) {
|
public void deleteImage(final String location) {
|
||||||
deleteObject(location);
|
deleteObject(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -128,7 +128,7 @@ public class DocumentWritePlatformServiceJpaRepositoryImpl implements DocumentWr
|
|||||||
|
|
||||||
if (inputStream != null && documentCommand.isFileNameChanged()) {
|
if (inputStream != null && documentCommand.isFileNameChanged()) {
|
||||||
final ContentRepository contentRepository = this.contentRepositoryFactory.getRepository(documentStoreType);
|
final ContentRepository contentRepository = this.contentRepositoryFactory.getRepository(documentStoreType);
|
||||||
contentRepository.deleteFile(documentCommand.getName(), oldLocation);
|
contentRepository.deleteFile(oldLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.documentRepository.saveAndFlush(documentForUpdate);
|
this.documentRepository.saveAndFlush(documentForUpdate);
|
||||||
@@ -157,7 +157,7 @@ public class DocumentWritePlatformServiceJpaRepositoryImpl implements DocumentWr
|
|||||||
this.documentRepository.delete(document);
|
this.documentRepository.delete(document);
|
||||||
|
|
||||||
final ContentRepository contentRepository = this.contentRepositoryFactory.getRepository(document.storageType());
|
final ContentRepository contentRepository = this.contentRepositoryFactory.getRepository(document.storageType());
|
||||||
contentRepository.deleteFile(document.getName(), document.getLocation());
|
contentRepository.deleteFile(document.getLocation());
|
||||||
return new CommandProcessingResult(document.getId());
|
return new CommandProcessingResult(document.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -99,7 +99,7 @@ public class ImageWritePlatformServiceJpaRepositoryImpl implements ImageWritePla
|
|||||||
if (image != null) {
|
if (image != null) {
|
||||||
final ContentRepository contentRepository = this.contentRepositoryFactory
|
final ContentRepository contentRepository = this.contentRepositoryFactory
|
||||||
.getRepository(StorageType.fromInt(image.getStorageType()));
|
.getRepository(StorageType.fromInt(image.getStorageType()));
|
||||||
contentRepository.deleteImage(clientId, image.getLocation());
|
contentRepository.deleteImage(image.getLocation());
|
||||||
this.imageRepository.delete(image);
|
this.imageRepository.delete(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,7 +126,7 @@ public class ImageWritePlatformServiceJpaRepositoryImpl implements ImageWritePla
|
|||||||
if (image != null) {
|
if (image != null) {
|
||||||
final ContentRepository contentRepository = this.contentRepositoryFactory
|
final ContentRepository contentRepository = this.contentRepositoryFactory
|
||||||
.getRepository(StorageType.fromInt(image.getStorageType()));
|
.getRepository(StorageType.fromInt(image.getStorageType()));
|
||||||
contentRepository.deleteImage(entityId, image.getLocation());
|
contentRepository.deleteImage(image.getLocation());
|
||||||
}
|
}
|
||||||
return owner;
|
return owner;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user