|
54 | 54 | import org.roda.core.storage.Resource; |
55 | 55 | import org.roda.core.storage.StorageService; |
56 | 56 | import org.roda.core.storage.StorageServiceUtils; |
57 | | -import org.roda.core.storage.StorageServiceWrapper; |
58 | 57 | import org.roda.core.util.IdUtils; |
59 | 58 | import org.slf4j.Logger; |
60 | 59 | import org.slf4j.LoggerFactory; |
@@ -997,24 +996,26 @@ public Path getHistoryMetadataPath() { |
997 | 996 |
|
998 | 997 | @Override |
999 | 998 | public void importBinaryVersion(StorageService fromService, StoragePath storagePath, String version) |
1000 | | - throws AlreadyExistsException, GenericException, RequestNotValidException, AuthorizationDeniedException { |
1001 | | - FileStorageService storageService; |
1002 | | - if (fromService instanceof FileStorageService) { |
1003 | | - storageService = (FileStorageService) fromService; |
1004 | | - } else if (fromService instanceof StorageServiceWrapper) { |
1005 | | - storageService = (FileStorageService) ((StorageServiceWrapper) fromService).getWrappedStorageService(); |
1006 | | - } else { |
1007 | | - throw new GenericException("Cannot import binary version from " + fromService.getClass().getName()); |
1008 | | - } |
| 999 | + throws AlreadyExistsException, GenericException, RequestNotValidException, AuthorizationDeniedException, |
| 1000 | + NotFoundException { |
| 1001 | + try { |
| 1002 | + Path targetDataPath = FSUtils.getEntityPath(historyDataPath, storagePath, version); |
| 1003 | + Path targetMetadataPath = FSUtils.getBinaryHistoryMetadataPath(historyDataPath, historyMetadataPath, |
| 1004 | + targetDataPath); |
1009 | 1005 |
|
1010 | | - Path sourceDataPath = FSUtils.getEntityPath(storageService.getHistoryDataPath(), storagePath, version); |
1011 | | - Path targetDataPath = FSUtils.getEntityPath(historyDataPath, storagePath, version); |
1012 | | - FSUtils.copy(sourceDataPath, targetDataPath, true); |
| 1006 | + BinaryVersion binaryVersion = fromService.getBinaryVersion(storagePath, version); |
1013 | 1007 |
|
1014 | | - Path sourceMetadataPath = FSUtils.getBinaryHistoryMetadataPath(storageService.getHistoryDataPath(), |
1015 | | - storageService.getHistoryMetadataPath(), sourceDataPath); |
1016 | | - Path targetMetadataPath = FSUtils.getBinaryHistoryMetadataPath(historyDataPath, historyMetadataPath, |
1017 | | - targetDataPath); |
1018 | | - FSUtils.copy(sourceMetadataPath, targetMetadataPath, true); |
| 1008 | + // write binary data to target path |
| 1009 | + Files.createDirectories(targetDataPath.getParent()); |
| 1010 | + ContentPayload payload = binaryVersion.getBinary().getContent(); |
| 1011 | + payload.writeToPath(targetDataPath); |
| 1012 | + |
| 1013 | + // write metadata to target path |
| 1014 | + Files.createDirectories(targetMetadataPath.getParent()); |
| 1015 | + JsonUtils.writeObjectToFile(binaryVersion, targetMetadataPath); |
| 1016 | + |
| 1017 | + } catch (IOException e) { |
| 1018 | + throw new GenericException("Could not import binary version", e); |
| 1019 | + } |
1019 | 1020 | } |
1020 | 1021 | } |
0 commit comments