@Test public void shouldStoreFileToDisk() throws Exception { MultipartFile file1 = mock(MultipartFile.class); MultipartFile file2 = mock(MultipartFile.class); String fileStoreId2 = UUID.randomUUID().toString(); String fileStoreId1 = UUID.randomUUID().toString(); List<Artifact> listOfMockedArtifacts = Arrays.asList( new Artifact(file1, new FileLocation(fileStoreId1, MODULE, TAG, TENANT_ID,FILENAME,FILE_SOURCE)), new Artifact(file2, new FileLocation(fileStoreId2, MODULE, TAG, TENANT_ID,FILENAME,FILE_SOURCE)) ); diskFileStoreRepository.write(listOfMockedArtifacts); verify(fileRepository).write(file1, Paths.get(FILE_STORAGE_MOUNT_PATH, FILENAME)); verify(fileRepository).write(file2, Paths.get(FILE_STORAGE_MOUNT_PATH, FILENAME)); }
public List<Artifact> write(List<org.egov.filestore.domain.model.Artifact> artifacts) { List<org.egov.filestore.persistence.entity.Artifact> persistList = new ArrayList<>(); artifacts.forEach(artifact -> { MultipartFile multipartFile = artifact.getMultipartFile(); FileLocation fileLocation = artifact.getFileLocation(); if (isS3Enabled) { s3Repository.writeToS3(multipartFile, fileLocation); fileLocation.setFileSource(AwsS3Source); } else { Path path = getPath(fileLocation); fileRepository.write(multipartFile, path); fileLocation.setFileSource(diskFileStorage); } persistList.add(mapToEntity(artifact)); }); return persistList; }
DiskFileStoreRepository { public List<Artifact> write(List<org.egov.filestore.domain.model.Artifact> artifacts) { List<org.egov.filestore.persistence.entity.Artifact> persistList = new ArrayList<>(); artifacts.forEach(artifact -> { MultipartFile multipartFile = artifact.getMultipartFile(); FileLocation fileLocation = artifact.getFileLocation(); if (isS3Enabled) { s3Repository.writeToS3(multipartFile, fileLocation); fileLocation.setFileSource(AwsS3Source); } else { Path path = getPath(fileLocation); fileRepository.write(multipartFile, path); fileLocation.setFileSource(diskFileStorage); } persistList.add(mapToEntity(artifact)); }); return persistList; } }
DiskFileStoreRepository { public List<Artifact> write(List<org.egov.filestore.domain.model.Artifact> artifacts) { List<org.egov.filestore.persistence.entity.Artifact> persistList = new ArrayList<>(); artifacts.forEach(artifact -> { MultipartFile multipartFile = artifact.getMultipartFile(); FileLocation fileLocation = artifact.getFileLocation(); if (isS3Enabled) { s3Repository.writeToS3(multipartFile, fileLocation); fileLocation.setFileSource(AwsS3Source); } else { Path path = getPath(fileLocation); fileRepository.write(multipartFile, path); fileLocation.setFileSource(diskFileStorage); } persistList.add(mapToEntity(artifact)); }); return persistList; } DiskFileStoreRepository(FileRepository fileRepository,
                                   @Value("${file.storage.mount.path}") String fileMountPath); }
DiskFileStoreRepository { public List<Artifact> write(List<org.egov.filestore.domain.model.Artifact> artifacts) { List<org.egov.filestore.persistence.entity.Artifact> persistList = new ArrayList<>(); artifacts.forEach(artifact -> { MultipartFile multipartFile = artifact.getMultipartFile(); FileLocation fileLocation = artifact.getFileLocation(); if (isS3Enabled) { s3Repository.writeToS3(multipartFile, fileLocation); fileLocation.setFileSource(AwsS3Source); } else { Path path = getPath(fileLocation); fileRepository.write(multipartFile, path); fileLocation.setFileSource(diskFileStorage); } persistList.add(mapToEntity(artifact)); }); return persistList; } DiskFileStoreRepository(FileRepository fileRepository,
                                   @Value("${file.storage.mount.path}") String fileMountPath); List<Artifact> write(List<org.egov.filestore.domain.model.Artifact> artifacts); Resource read(FileLocation fileLocation); }
DiskFileStoreRepository { public List<Artifact> write(List<org.egov.filestore.domain.model.Artifact> artifacts) { List<org.egov.filestore.persistence.entity.Artifact> persistList = new ArrayList<>(); artifacts.forEach(artifact -> { MultipartFile multipartFile = artifact.getMultipartFile(); FileLocation fileLocation = artifact.getFileLocation(); if (isS3Enabled) { s3Repository.writeToS3(multipartFile, fileLocation); fileLocation.setFileSource(AwsS3Source); } else { Path path = getPath(fileLocation); fileRepository.write(multipartFile, path); fileLocation.setFileSource(diskFileStorage); } persistList.add(mapToEntity(artifact)); }); return persistList; } DiskFileStoreRepository(FileRepository fileRepository,
                                   @Value("${file.storage.mount.path}") String fileMountPath); List<Artifact> write(List<org.egov.filestore.domain.model.Artifact> artifacts); Resource read(FileLocation fileLocation);  }