@Test public void testAddMetadata() { final String TEST_FILE = "item.pdf"; File dir = new File(testDir, "addmetadata"); dir.mkdir(); try{ FileUtils.copyFileToDirectory( new File(packagerResources, TEST_FILE), dir); } catch(IOException ex){ fail(ex.getMessage()); } try { if(Packager.createBag(dir) != null){ final String DEPOSIT_META = "jings"; final String VAULT_META = "crivvens"; final String FT_META = "help ma"; final String EXT_META = "boab"; Packager.addMetadata(dir, DEPOSIT_META, VAULT_META, FT_META, EXT_META); File df = new File(dir + File.separator + Packager.metadataDirName, Packager.depositMetaFileName); assertEquals(DEPOSIT_META, FileUtils.readFileToString(df)); File vf = new File(dir + File.separator + Packager.metadataDirName, Packager.vaultMetaFileName); assertEquals(VAULT_META, FileUtils.readFileToString(vf)); File ff = new File(dir + File.separator + Packager.metadataDirName, Packager.fileTypeMetaFileName); assertEquals(FT_META, FileUtils.readFileToString(ff)); File ef = new File(dir + File.separator + Packager.metadataDirName, Packager.externalMetaFileName); assertEquals(EXT_META, FileUtils.readFileToString(ef)); List<String> lines = FileUtils.readLines( new File(dir.getAbsolutePath() + File.separator + "tagmanifest-md5.txt")); assertTrue(lines.contains(DigestUtils.md5Hex(DEPOSIT_META) + " metadata" + File.separator + Packager.depositMetaFileName)); assertTrue(lines.contains(DigestUtils.md5Hex(VAULT_META) + " metadata" + File.separator + Packager.vaultMetaFileName)); assertTrue(lines.contains(DigestUtils.md5Hex(FT_META) + " metadata" + File.separator + Packager.fileTypeMetaFileName)); assertTrue(lines.contains(DigestUtils.md5Hex(EXT_META) + " metadata" + File.separator + Packager.externalMetaFileName)); } else{ fail("Bag creation failed"); } } catch(Exception ex) { ex.printStackTrace(); fail(ex.getMessage()); } }
public static boolean addMetadata(File bagDir, String depositMetadata, String vaultMetadata, String fileTypeMetadata, String externalMetadata) { boolean result = false; try { Path bagPath = bagDir.toPath(); Path metadataDirPath = bagPath.resolve(metadataDirName); File metadataDir = metadataDirPath.toFile(); metadataDir.mkdir(); File tagManifest = bagPath.resolve("tagmanifest-md5.txt").toFile(); SupportedAlgorithm alg = StandardSupportedAlgorithms.MD5; addMetaFile(tagManifest, metadataDirPath, depositMetaFileName, depositMetadata, alg); addMetaFile(tagManifest, metadataDirPath, vaultMetaFileName, vaultMetadata, alg); addMetaFile(tagManifest, metadataDirPath, fileTypeMetaFileName, fileTypeMetadata, alg); addMetaFile(tagManifest, metadataDirPath, externalMetaFileName, externalMetadata, alg); result = true; } catch (IOException e) { System.out.println(e.toString()); result = false; } return result; }
Packager { public static boolean addMetadata(File bagDir, String depositMetadata, String vaultMetadata, String fileTypeMetadata, String externalMetadata) { boolean result = false; try { Path bagPath = bagDir.toPath(); Path metadataDirPath = bagPath.resolve(metadataDirName); File metadataDir = metadataDirPath.toFile(); metadataDir.mkdir(); File tagManifest = bagPath.resolve("tagmanifest-md5.txt").toFile(); SupportedAlgorithm alg = StandardSupportedAlgorithms.MD5; addMetaFile(tagManifest, metadataDirPath, depositMetaFileName, depositMetadata, alg); addMetaFile(tagManifest, metadataDirPath, vaultMetaFileName, vaultMetadata, alg); addMetaFile(tagManifest, metadataDirPath, fileTypeMetaFileName, fileTypeMetadata, alg); addMetaFile(tagManifest, metadataDirPath, externalMetaFileName, externalMetadata, alg); result = true; } catch (IOException e) { System.out.println(e.toString()); result = false; } return result; } }
Packager { public static boolean addMetadata(File bagDir, String depositMetadata, String vaultMetadata, String fileTypeMetadata, String externalMetadata) { boolean result = false; try { Path bagPath = bagDir.toPath(); Path metadataDirPath = bagPath.resolve(metadataDirName); File metadataDir = metadataDirPath.toFile(); metadataDir.mkdir(); File tagManifest = bagPath.resolve("tagmanifest-md5.txt").toFile(); SupportedAlgorithm alg = StandardSupportedAlgorithms.MD5; addMetaFile(tagManifest, metadataDirPath, depositMetaFileName, depositMetadata, alg); addMetaFile(tagManifest, metadataDirPath, vaultMetaFileName, vaultMetadata, alg); addMetaFile(tagManifest, metadataDirPath, fileTypeMetaFileName, fileTypeMetadata, alg); addMetaFile(tagManifest, metadataDirPath, externalMetaFileName, externalMetadata, alg); result = true; } catch (IOException e) { System.out.println(e.toString()); result = false; } return result; }  }
Packager { public static boolean addMetadata(File bagDir, String depositMetadata, String vaultMetadata, String fileTypeMetadata, String externalMetadata) { boolean result = false; try { Path bagPath = bagDir.toPath(); Path metadataDirPath = bagPath.resolve(metadataDirName); File metadataDir = metadataDirPath.toFile(); metadataDir.mkdir(); File tagManifest = bagPath.resolve("tagmanifest-md5.txt").toFile(); SupportedAlgorithm alg = StandardSupportedAlgorithms.MD5; addMetaFile(tagManifest, metadataDirPath, depositMetaFileName, depositMetadata, alg); addMetaFile(tagManifest, metadataDirPath, vaultMetaFileName, vaultMetadata, alg); addMetaFile(tagManifest, metadataDirPath, fileTypeMetaFileName, fileTypeMetadata, alg); addMetaFile(tagManifest, metadataDirPath, externalMetaFileName, externalMetadata, alg); result = true; } catch (IOException e) { System.out.println(e.toString()); result = false; } return result; }  static Bag createBag(File dir); static boolean validateBag(File dir); static boolean addMetadata(File bagDir,
                                      String depositMetadata,
                                      String vaultMetadata,
                                      String fileTypeMetadata,
                                      String externalMetadata); static boolean addMetaFile(File tagManifest, Path metadataDirPath, String metadataFileName, String metadata, SupportedAlgorithm alg); static String computeFileHash(File file, SupportedAlgorithm alg); static boolean extractMetadata(File bagDir, File metaDir); static void main(String[] args); }
Packager { public static boolean addMetadata(File bagDir, String depositMetadata, String vaultMetadata, String fileTypeMetadata, String externalMetadata) { boolean result = false; try { Path bagPath = bagDir.toPath(); Path metadataDirPath = bagPath.resolve(metadataDirName); File metadataDir = metadataDirPath.toFile(); metadataDir.mkdir(); File tagManifest = bagPath.resolve("tagmanifest-md5.txt").toFile(); SupportedAlgorithm alg = StandardSupportedAlgorithms.MD5; addMetaFile(tagManifest, metadataDirPath, depositMetaFileName, depositMetadata, alg); addMetaFile(tagManifest, metadataDirPath, vaultMetaFileName, vaultMetadata, alg); addMetaFile(tagManifest, metadataDirPath, fileTypeMetaFileName, fileTypeMetadata, alg); addMetaFile(tagManifest, metadataDirPath, externalMetaFileName, externalMetadata, alg); result = true; } catch (IOException e) { System.out.println(e.toString()); result = false; } return result; }  static Bag createBag(File dir); static boolean validateBag(File dir); static boolean addMetadata(File bagDir,
                                      String depositMetadata,
                                      String vaultMetadata,
                                      String fileTypeMetadata,
                                      String externalMetadata); static boolean addMetaFile(File tagManifest, Path metadataDirPath, String metadataFileName, String metadata, SupportedAlgorithm alg); static String computeFileHash(File file, SupportedAlgorithm alg); static boolean extractMetadata(File bagDir, File metaDir); static void main(String[] args); static final String metadataDirName; static final String depositMetaFileName; static final String vaultMetaFileName; static final String fileTypeMetaFileName; static final String externalMetaFileName; }