Browse Source

- added store()

- renamed create_new() to add_payload()
- added add_bagmetadata()
- added add_fetchfile()
- added add_othertags()
- using default values in Bag-constructor
- enhanced example create_a_bag.cpp
master
Andreas Romeyke 2 years ago
parent
commit
4b3cddde19
3 changed files with 37 additions and 11 deletions
  1. +9
    -2
      src/examples/create_a_bag.cpp
  2. +5
    -2
      src/include/bag.hpp
  3. +23
    -7
      src/lib/bag.cpp

+ 9
- 2
src/examples/create_a_bag.cpp View File

@@ -31,8 +31,15 @@ int main(int argc, const char *argv[]) {
bag.reset_logstream();
Payload payload( bagit_dir );
payload.import_data_dir( data_dir );
bag.create_new( &payload );
bag.store( bagit_dir );
bag.add_payload( &payload );
Bagmetadata bagmetadata( bagit_dir );
Checksum checksum;
oxum_t oxum = checksum.oxum_of_filelist( payload.get_all_absolute_paths() );
bagmetadata.set_PayloadOxum( oxum );
bagmetadata.set_SourceOrganization( "Test University" );
bag.add_bagmetadata( &bagmetadata );
bag.validate();
bag.store();
stringstream log;
bag.get_logstream( log );
cout << log.str() << endl;


+ 5
- 2
src/include/bag.hpp View File

@@ -42,12 +42,15 @@ class Bag {
class Fetchfile *fetchfile_p{};
class Othertags *othertags_p{};
public:
Bag();
Bag(string dfname);
list<string> get_all_bag_files();
bool store( string basedir);
bool store();
bool validate();
void create_new(Payload * payload_p);
void add_payload(Payload * payload_p);
void add_bagmetadata( Bagmetadata * bagmetadata_p);
void add_fetchfile( Fetchfile * fetchfile_p);
void add_othertags( Othertags * othertags_p);
void get_logstream( stringstream & log);
void reset_logstream();
};


+ 23
- 7
src/lib/bag.cpp View File

@@ -30,6 +30,11 @@ Bag::Bag( string dfname ) {
// log << "load constructor (" << dfname << ")" << endl;
// read in file bagit.txt
string bagit_txt_path = dfname + "bagit.txt";
/* add default metadata and stuff */
this->base_dir = dfname;
this->bagit_version_major = 0;
this->bagit_version_minor = 97;
this->tag_file_character_encoding = "UTF-8";
//log << "parse " << bagit_txt_path << endl;
ifstream bagit_txt_file;
bagit_txt_file.open( bagit_txt_path );
@@ -102,8 +107,7 @@ list<string> Bag::get_all_bag_files() {
return files;
}

bool Bag::store( string basedir ) {

bool Bag::store( const string basedir ) {
fs::path p{ basedir };
fs::file_status s = fs::status( p );
if (fs::is_directory( s)) {
@@ -174,6 +178,9 @@ bool Bag::store( string basedir ) {
return true;
}

bool Bag::store() {
return Bag::store( this->base_dir );
}

bool Bag::validate() {
bool is_valid = true;
@@ -299,14 +306,23 @@ bool Bag::validate() {
return is_valid;
}

void Bag::create_new( Payload * payload_p ) {
void Bag::add_payload( Payload * payload_p ) {
this->payload_p = payload_p;
/* add metadata and stuff */
this->bagit_version_major = 0;
this->bagit_version_minor = 97;
this->tag_file_character_encoding = "UTF-8";
}

void Bag::add_bagmetadata( Bagmetadata * bagmetadata_p ) {
this->bagmetadata_p = bagmetadata_p;
}

void Bag::add_fetchfile( Fetchfile * fetchfile_p ) {
this->fetchfile_p = fetchfile_p;
}

void Bag::add_othertags( Othertags * othertags_p ) {
this->othertags_p = othertags_p;
}


void Bag::get_logstream( stringstream & log ) {
log << this->log.rdbuf();
}


Loading…
Cancel
Save