@@ -313,23 +313,32 @@ void populateVirtualTable(TableStructure table) throws ModuleException, FileNotF
313313 getDID (doc ).toString ());
314314 lstCells .add (dIDCell );
315315
316- // document blob
317- String mainFolder = pathStrategy .getMainFolder ().getPath ().toString ();
318- String siardFolderName = mainFolder .substring (0 , mainFolder .length () - 1 ) + getMID (doc );
319- Path siardFolderPath = Paths .get (siardFolderName );
320- Path binPath = siardFolderPath
321- .resolve (Paths .get (SIARDDKConstants .DOCUMENTS_FOLDER_NAME , getDCf (doc ), getDID (doc ).toString (),
322- SIARDDKConstants .DEFAULT_DOCUMENT_NAME + SIARDDKConstants .FILE_EXTENSION_SEPARATOR + getAFt (doc )));
323-
324- if (!binPath .startsWith (siardFolderPath .resolve (Paths .get (SIARDDKConstants .DOCUMENTS_FOLDER_NAME )))) {
325- throw new ModuleException ().withMessage ("Invalid path for file: " + binPath );
326- }
327-
328316 try {
317+ // document blob
318+ String mainFolder = pathStrategy .getMainFolder ().getPath ().toString ();
319+ String siardFolderName = mainFolder .substring (0 , mainFolder .length () - 1 ) + getMID (doc );
320+ Path siardFolderPath = Paths .get (siardFolderName );
321+ Path docPath = siardFolderPath
322+ .resolve (Paths .get (SIARDDKConstants .DOCUMENTS_FOLDER_NAME , getDCf (doc ), getDID (doc ).toString ()));
323+
324+ if (!docPath .startsWith (siardFolderPath .resolve (Paths .get (SIARDDKConstants .DOCUMENTS_FOLDER_NAME )))) {
325+ throw new ModuleException ().withMessage ("Invalid path for folder: " + docPath );
326+ }
327+
328+ String digest = "" ;
329+ File docFolder = new File (docPath .toString ());
330+ if (docFolder .exists () && docFolder .isDirectory ()) {
331+ File [] fileList = docFolder .listFiles ();
332+ if (fileList != null && fileList .length == 1 ) {
333+ docPath = docPath .resolve (Paths .get (fileList [0 ].getName ()));
334+ digest = DigestUtils .sha1Hex (Files .newInputStream (docPath ));
335+ }
336+ }
337+
329338 Cell blobCell = new BinaryCell (
330339 SIARDDKConstants .BLOB_EXTENSION + SIARDDKConstants .FILE_EXTENSION_SEPARATOR + rowCounter ,
331- new DummyInputStreamProvider (), binPath .toString (), Files .size (binPath ) ,
332- DigestUtils .sha1Hex ( Files . newInputStream ( binPath )), DigestUtils . getSha1Digest ().toString ());
340+ new DummyInputStreamProvider (), docPath .toString (), Files .size (docPath ), digest ,
341+ DigestUtils .getSha1Digest ().toString ());
333342 lstCells .add (blobCell );
334343
335344 // set and handle row
0 commit comments