From 62a2ad405a80119fa719fe2646b02958947a26c6 Mon Sep 17 00:00:00 2001 From: "art1@andreas-romeyke.de" Date: Thu, 31 May 2018 21:05:57 +0200 Subject: [PATCH] - added validate() method to bag --- src/include/bag.hpp | 3 +- src/include/bagmetadata.hpp | 1 + src/include/manifest.hpp | 1 + src/include/payload.hpp | 4 ++- src/lib/bagmetadata.cpp | 5 +++ src/lib/load_bag.cpp | 1 + src/lib/manifest.cpp | 5 +++ src/lib/payload.cpp | 5 +++ src/lib/validate_bag.cpp | 70 +++++++++++++++++++++++++++++++++++++ 9 files changed, 93 insertions(+), 2 deletions(-) diff --git a/src/include/bag.hpp b/src/include/bag.hpp index 9d6844a..d7179c7 100644 --- a/src/include/bag.hpp +++ b/src/include/bag.hpp @@ -22,10 +22,11 @@ class Bag { string tag_file_character_encoding; class Payload *payload_p;; class Payloadmanifest *payloadmanifest_p; + // next elements are optional class Tagmanifest *tagmanifest_p; class Bagmetadata *bagmetadata_p; class Fetchfile *fetchfile_p; - class Othertags *othertags_p; //TODO: optional + class Othertags *othertags_p; public: Bag(); Bag(string dfname); diff --git a/src/include/bagmetadata.hpp b/src/include/bagmetadata.hpp index 96ec83a..1a563f5 100644 --- a/src/include/bagmetadata.hpp +++ b/src/include/bagmetadata.hpp @@ -30,6 +30,7 @@ class Bagmetadata{ Bagmetadata( string basedir ); bool has_bagmetadata(); map get_metadata(); + bool validate(); }; #endif diff --git a/src/include/manifest.hpp b/src/include/manifest.hpp index ffb61f1..cfe4647 100644 --- a/src/include/manifest.hpp +++ b/src/include/manifest.hpp @@ -10,6 +10,7 @@ class Manifest{ map manifest_algorithm_files; public: virtual map get_checksum_file_pairs(checksum_algorithms algorithm); + virtual bool validate(); }; #endif diff --git a/src/include/payload.hpp b/src/include/payload.hpp index c30ef97..f7f36ef 100644 --- a/src/include/payload.hpp +++ b/src/include/payload.hpp @@ -16,6 +16,8 @@ class Payload{ Payload( string basedir ); list get_all_relative_paths(); list get_all_absolute_paths(); + bool validate(); }; #endif -// vim: set tabstop=4 +// vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab + diff --git a/src/lib/bagmetadata.cpp b/src/lib/bagmetadata.cpp index 8e729cc..90ec2f5 100644 --- a/src/lib/bagmetadata.cpp +++ b/src/lib/bagmetadata.cpp @@ -75,4 +75,9 @@ Bagmetadata::Bagmetadata( string basedir ) { map Bagmetadata::get_metadata() { return this->metadata; } + +bool Bagmetadata::validate() { + // TODO + return true; +} // vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab diff --git a/src/lib/load_bag.cpp b/src/lib/load_bag.cpp index 8ec96d2..77b0af9 100644 --- a/src/lib/load_bag.cpp +++ b/src/lib/load_bag.cpp @@ -75,6 +75,7 @@ Bag::Bag( string dfname ) { Bag::payloadmanifest_p->get_checksum_file_pairs( md5 ); Bag::tagmanifest_p->get_checksum_file_pairs( md5 ); + cout << "The bag '"<validate() ? "valid" : "invalid") << endl; } diff --git a/src/lib/manifest.cpp b/src/lib/manifest.cpp index fb674ac..6859d10 100644 --- a/src/lib/manifest.cpp +++ b/src/lib/manifest.cpp @@ -32,4 +32,9 @@ map Manifest::get_checksum_file_pairs(checksum_algorithms alg) { } return checksum_file_pairs; } + +bool Manifest::validate() { + // TODO + return true; +} // vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab diff --git a/src/lib/payload.cpp b/src/lib/payload.cpp index 2c7abc0..c027c90 100644 --- a/src/lib/payload.cpp +++ b/src/lib/payload.cpp @@ -48,4 +48,9 @@ list Payload::get_all_absolute_paths() { } return strpaths; } + +bool Payload::validate() { + // TODO + return true; +} // vim: set tabstop=4 diff --git a/src/lib/validate_bag.cpp b/src/lib/validate_bag.cpp index e69de29..6428bd8 100644 --- a/src/lib/validate_bag.cpp +++ b/src/lib/validate_bag.cpp @@ -0,0 +1,70 @@ +#include "bag.hpp" + + + + +bool Bag::validate() { + bool is_valid = true; + if (this->bagit_version_major != 0) { + is_valid = false; + } + if (this->bagit_version_minor != 97) { + is_valid = false; + } + if (0 != tag_file_character_encoding.compare( "UTF-8" )) { + is_valid = false; + } + if (NULL == this->payload_p) { + is_valid = false; + } else { + bool ret = this->payload_p->validate(); + if (ret == false) { + is_valid = false; + } + } + if (NULL == this->payloadmanifest_p) { + is_valid = false; + } else { + bool ret = this->payloadmanifest_p->validate(); + if (ret == false) { + is_valid = false; + } + } + // next elements are optional + if (NULL == this->tagmanifest_p) { + } else { + bool ret = this->tagmanifest_p->validate(); + if (ret == false) { + is_valid = false; + } + } + if (NULL == this->bagmetadata_p) { + } else { + bool ret = this->bagmetadata_p->validate(); + if (ret == false) { + is_valid = false; + } + } + /* + if (NULL == this->fetchfile_p) { + } else { + bool ret = this->fetchfile_p->validate(); + if (ret == false) { + is_valid = false; + } + } + + if (NULL == this->othertags_p) { + } else { + bool ret = this->othertags_p->validate(); + if (ret == false) { + is_valid = false; + } + } + */ + + return is_valid; +} + +// vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab +