Browse Source

- set_PayloadOxum() also sets BagSize

- set_BagSize() uses unsigned long int now
master
parent
commit
998276ccc8
2 changed files with 28 additions and 6 deletions
  1. +4
    -3
      src/include/bagmetadata.hpp
  2. +24
    -3
      src/lib/bagmetadata.cpp

+ 4
- 3
src/include/bagmetadata.hpp View File

@@ -1,15 +1,15 @@
// Copyright (C) 2018 Andreas Romeyke (art1@andreas-romeyke.de), 2018.
//
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef LIBCBAG_BAGMETADATA
@@ -86,6 +86,7 @@ class Bagmetadata{
void set_BaggingDate( string );
void set_ExternalIdentifier( string );
void set_BagSize( string );
void set_BagSize( unsigned long int); // count of bytes, the method calcs the human readable string
void set_PayloadOxum( oxum_t );
void set_BagGroupIdentifier( string );
void set_BagCount( string );


+ 24
- 3
src/lib/bagmetadata.cpp View File

@@ -1,15 +1,15 @@
// Copyright (C) 2018 Andreas Romeyke (art1@andreas-romeyke.de), 2018.
//
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "bagmetadata.hpp"
@@ -139,6 +139,7 @@ oxum_t Bagmetadata::get_PayloadOxum() {

void Bagmetadata::set_PayloadOxum( oxum_t oxum ) {
this->metadata[ "Payload-Oxum" ] = to_string( oxum.octetcount ) + "." + to_string( oxum.streamcount );
this->set_BagSize( oxum.octetcount );
}

bool Bagmetadata::store( string basedir ) {
@@ -282,6 +283,8 @@ string Bagmetadata::get_ExternalDescription() {
if(it != this->metadata.end()) { return it->second; }
return "";
}

// TODO: should return YY-MM-DD
string Bagmetadata::get_BaggingDate() {
map<string, string>::iterator it;
it = this->metadata.find("BaggingDate");
@@ -306,6 +309,8 @@ string Bagmetadata::get_BagGroupIdentifier() {
if(it != this->metadata.end()) { return it->second; }
return "";
}

// TODO: return N of T or N of ?
string Bagmetadata::get_BagCount() {
map<string, string>::iterator it;
it = this->metadata.find("BagCount");
@@ -350,6 +355,7 @@ void Bagmetadata::set_ExternalDescription(string ExternalDescription) {
this->metadata["ExternalDescription"] = ExternalDescription;
}

// TODO: set YYYY-MM-DD
void Bagmetadata::set_BaggingDate(string BaggingDate) {
this->metadata["BaggingDate"] = BaggingDate;
}
@@ -362,10 +368,25 @@ void Bagmetadata::set_BagSize(string BagSize) {
this->metadata["BagSize"] = BagSize;
}

void Bagmetadata::set_BagSize( unsigned long int bytes) {
if (bytes > (1024*1024*1024*1024) ) {
this->metadata["BagSize"] = to_string (bytes/ (1024*1024*1024*1024)) + " TB";
} else if (bytes > (1024*1024*1024) ) {
this->metadata["BagSize"] = to_string (bytes/ (1024*1024*1024)) + " GB";
} else if (bytes > (1024*1024) ) {
this->metadata["BagSize"] = to_string (bytes/ (1024*1024)) + " MB";
} else if (bytes > (1024) ) {
this->metadata["BagSize"] = to_string (bytes/ (1024)) + " kB";
} else {
this->metadata["BagSize"] = to_string (bytes) + " B";
}
}

void Bagmetadata::set_BagGroupIdentifier(string BagGroupIdentifier) {
this->metadata["BagGroupIdentifier"] = BagGroupIdentifier;
}

// TODO: fix BagCount, needs "N of T" or "N of ?" where N, T is replaced by an int
void Bagmetadata::set_BagCount(string BagCount) {
this->metadata["BagCount"] = BagCount;
}


Loading…
Cancel
Save