|
|
@ -1,24 +1,25 @@ |
|
|
|
#include "bag.hpp"
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
|
|
|
|
bool Bag::validate( list<string> & log ) { |
|
|
|
bool Bag::validate( stringstream & log ) { |
|
|
|
bool is_valid = true; |
|
|
|
if (this->bagit_version_major != 0) { |
|
|
|
log.push_back( "Bagit major version 0 is expected, but got: " + to_string(this->bagit_version_major)); |
|
|
|
log << "Bagit major version 0 is expected, but got: " << to_string(this->bagit_version_major) << endl; |
|
|
|
is_valid = false; |
|
|
|
} |
|
|
|
if (this->bagit_version_minor != 97) { |
|
|
|
log.push_back( "Bagit minor version 97 is expected, but got: " + to_string(this->bagit_version_minor)); |
|
|
|
log << "Bagit minor version 97 is expected, but got: " << to_string(this->bagit_version_minor) << endl; |
|
|
|
is_valid = false; |
|
|
|
} |
|
|
|
if (0 != tag_file_character_encoding.compare( "UTF-8" )) { |
|
|
|
log.push_back( "Bagit character encoding UTF-8 is expected, but got: " + this->tag_file_character_encoding); |
|
|
|
log << "Bagit character encoding UTF-8 is expected, but got: " << this->tag_file_character_encoding << endl; |
|
|
|
is_valid = false; |
|
|
|
} |
|
|
|
if (NULL == this->payload_p) { |
|
|
|
log.push_back( "Bagit payload directory 'data/' is expected, but could not found"); |
|
|
|
log << "Bagit payload directory 'data/' is expected, but could not found" << endl; |
|
|
|
is_valid = false; |
|
|
|
} else { |
|
|
|
bool ret = this->payload_p->validate( log ); |
|
|
@ -30,7 +31,7 @@ bool Bag::validate( list<string> & log ) { |
|
|
|
is_valid = false; |
|
|
|
} else { |
|
|
|
// checksums check
|
|
|
|
log.push_back( "Bagit payload manifest"); |
|
|
|
log << "Bagit payload manifest" << endl; |
|
|
|
bool ret = this->payloadmanifest_p->validate( log ); |
|
|
|
if (ret == false) { |
|
|
|
is_valid = false; |
|
|
@ -61,7 +62,7 @@ bool Bag::validate( list<string> & log ) { |
|
|
|
int cmp_res = (*it1).compare( *it2); |
|
|
|
//cout << "COMP: "<<cmp_res<<" file='"<< (*it1) << "' checksummed file='" << (*it2) << "'" << endl;
|
|
|
|
if ( cmp_res < 0) { |
|
|
|
log.push_back("Bagit warning, file '" + (*it1) + "' in payload has no checksum entry in payload manifest"); |
|
|
|
log << "Bagit warning, file '" << (*it1) << "' in payload has no checksum entry in payload manifest" << endl; |
|
|
|
it1++; |
|
|
|
} else if ( cmp_res > 0) { |
|
|
|
it2++; |
|
|
@ -75,7 +76,7 @@ bool Bag::validate( list<string> & log ) { |
|
|
|
// next elements are optional
|
|
|
|
if (NULL == this->tagmanifest_p) { |
|
|
|
} else { |
|
|
|
log.push_back( "Bagit tag manifest"); |
|
|
|
log << "Bagit tag manifest" << endl; |
|
|
|
bool ret = this->tagmanifest_p->validate( log ); |
|
|
|
if (ret == false) { |
|
|
|
is_valid = false; |
|
|
@ -94,11 +95,11 @@ bool Bag::validate( list<string> & log ) { |
|
|
|
oxum_t expected_oxum = this->bagmetadata_p->get_oxum(); |
|
|
|
oxum_t calculated_oxum = c.oxum_of_filelist( files ); |
|
|
|
if (expected_oxum.octetcount != calculated_oxum.octetcount) { |
|
|
|
log.push_back("Bagit payload oxum octectcount=" + to_string(expected_oxum.octetcount) + " expected, but " + to_string(calculated_oxum.octetcount) + " found"); |
|
|
|
log << "Bagit payload oxum octectcount=" << to_string(expected_oxum.octetcount) << " expected, but " << to_string(calculated_oxum.octetcount) << " found" << endl; |
|
|
|
is_valid = false; |
|
|
|
} |
|
|
|
if (expected_oxum.streamcount != calculated_oxum.streamcount) { |
|
|
|
log.push_back("Bagit payload oxum streamcount=" + to_string(expected_oxum.streamcount) + " expected, but " + to_string(calculated_oxum.streamcount) + " found"); |
|
|
|
log << "Bagit payload oxum streamcount=" << to_string(expected_oxum.streamcount) << " expected, but " << to_string(calculated_oxum.streamcount) << " found" << endl; |
|
|
|
is_valid = false; |
|
|
|
} |
|
|
|
|
|
|
|