Skip to content

Commit

Permalink
Compatibilité New Structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno De Bel authored and Bruno De Bel committed Feb 2, 2018
1 parent 3896e11 commit f7a794b
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 123 deletions.
13 changes: 9 additions & 4 deletions loadInventory/inventoryparser.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "inventoryparser.h"
#include <string>
#include <iostream>
#include <cstdio>
#include <map>
#include "../common_files/xmltostr.h"
using namespace xercesc;
Expand Down Expand Up @@ -36,14 +37,17 @@ class StateParserDocumentState : public StateParserInventoryRootState{
return tmp;
}

std::string buildUnique(std::string type,std::string date,std::string seq,std::string sysnum){
std::string buildUnique(std::string type,std::string date,std::string seq,std::string sysnum,std::string paperid){

if ( type.compare("Monograph") == 0){
return sysnum;
}

char* str = strdup (type.c_str());

char ret[200];
sprintf_s(ret, "%s_%s", date.c_str(), seq.c_str());
sprintf_s(ret, "%s/%s/%s_%s", _strlwr(str), paperid.c_str(), date.c_str(), seq.c_str());
free(str);

return ret;
}
Expand All @@ -64,7 +68,8 @@ class StateParserDocumentState : public StateParserInventoryRootState{
allValue.push_back(getMap(CTX.keyValues,"title"));
allValue.push_back(getMap(CTX.keyValues,"titleCollection"));
allValue.push_back(getMap(CTX.keyValues,"subTitle"));
allValue.push_back(getMap(CTX.keyValues,"paperID"));
std::string paperID=getMap(CTX.keyValues,"paperID");
allValue.push_back(paperID);
allValue.push_back(getMap(CTX.keyValues,"languages"));
allValue.push_back(getMap(CTX.keyValues,"issueNumber"));
std::string date = getMapDate(CTX.keyValues);
Expand All @@ -74,7 +79,7 @@ class StateParserDocumentState : public StateParserInventoryRootState{
std::string sysnum = getMap(CTX.keyValues,"systemNumber");
allValue.push_back(sysnum);
std::string seq = getMap(CTX.keyValues,"sequenceNumber");
allValue.push_back(buildUnique(type,date,seq,sysnum));
allValue.push_back(buildUnique(type,date,seq,sysnum,paperID));

(CTX . sql) -> Store( allValue);

Expand Down
32 changes: 15 additions & 17 deletions project/inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@
std::string inventory::toString(std::string name){
std::stringstream ss;
ss<<"INVENTORY:"<<name<<std::endl;
ss<<"BIBREC_245a:"<<BIBREC_245a<<std::endl;
ss<<"BIBREC_100a:"<<BIBREC_100a<<std::endl;
ss<<"BIBREC_260b:"<<BIBREC_260b<<std::endl;
//ss<<"ITEM_barcode:"<<ITEM_barcode<<std::endl;
ss<<"BIBREC_SYS_NUM:"<<BIBREC_SYS_NUM<<std::endl;
ss<<"TITLE:"<<title<<std::endl;
ss<<"SUBTITLE:"<<subtitle<<std::endl;
ss<<"UNIQUE:"<<uniquebuildkey<<std::endl;

for ( std::map<std::string,std::string>::iterator it = languageTerm.begin() ; it != languageTerm.end(); it ++) {

ss<<"languageTerm:"<<it->first<<std::endl;

}
ss<<"BIBREC_008_7_10:"<<BIBREC_008_7_10<<std::endl;
ss<<"AUTHOR:"<<author<<std::endl;
ss<<"END INVENTORY:"<<name<<std::endl;
return ss.str();
}
Expand All @@ -40,21 +39,20 @@ void inventoryMapping::setCurrentInventory(std::string type){

void inventoryMapping::setCurrentInventoryValue(std::string field, std::string value){
if ( currentInventory == 0) return;

if ( field.compare("recordIdentifier")==0 ) currentInventory->uniquebuildkey=value;

if ( field.compare("title")==0 ) currentInventory->title=value;
if ( field.compare("subtitle")==0 ) currentInventory->subtitle=value;
if ( field.compare("barcode")==0 ) currentInventory->barcode=value;
if ( field.compare("dateIssued")==0 ) currentInventory->formaldate=value;

if ( field.compare("author")==0 ) currentInventory->author=value;

if ( field.compare("nonSort")==0 ) currentInventory->nonSort=value;
if ( field.compare("BIBREC_245a")==0 ) currentInventory->BIBREC_245a=value;
//if ( field.compare("BIBREC_245b")==0 ) currentInventory->BIBREC_245b=value;
if ( field.compare("BIBREC_100a")==0) currentInventory->BIBREC_100a=value;
//if ( field.compare("BIBREC_100a-2")==0) currentInventory->BIBREC_100a_2=value;
if ( field.compare("BIBREC_260b")==0) currentInventory->BIBREC_260b=value;
//if ( field.compare("BIBREC_260c")==0) currentInventory->BIBREC_260c=value;
//if ( field.compare("ITEM_barcode")==0) currentInventory->ITEM_barcode=value;
if ( field.compare("BIBREC_SYS_NUM")==0) currentInventory->BIBREC_SYS_NUM=value;
if ( field.compare("languageTerm")==0) {
currentInventory->languageTerm[value]=value;//
}
if ( field.compare("BIBREC_008_7_10")==0) currentInventory->BIBREC_008_7_10 =value;
;

}


Expand Down
19 changes: 11 additions & 8 deletions project/inventory.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@

class inventory{
public:
std::string nonSort;
std::string BIBREC_245a;
std::string BIBREC_100a;
std::string BIBREC_260b;
std::string BIBREC_008_7_10;
std::string ITEM_barcode;
std::string BIBREC_SYS_NUM; //could be ITEM_barcode depending of the section
std::map<std::string,std::string> languageTerm; //std::string BIBREC_008_35_37;
std::string author;
std::string title;
std::string titlecollection;
std::string subtitle;
std::string paperid;
std::string barcode;
std::string issuenumber;
std::string formaldate;
std::string type;
std::string uniquebuildkey;
std::map<std::string,std::string> languageTerm;
std::string toString(std::string name);
int checked;
};
Expand Down
41 changes: 5 additions & 36 deletions project/metsparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,34 +232,6 @@ class StateParsermodStateInventoryMarc:public StateParsermodState{
};
};

/*
class StateParsermodStateInventoryType:public StateParsermodState{
private:
std::string localType;
public:
StateParsermodStateInventoryType(){}
virtual void startElement (const char* const name, const xercesc::Attributes &atts ){
const char *val = getAttributeValue("type", atts);
if (val != 0)
{
localType=std::string(val);
}
};
virtual void endElement (const char* const name){
if ( localType.compare("given")==0 ){
CTX.inventory.setCurrentInventoryValue("BIBREC_100a-1",CTX.addStringData);
}else if ( localType.compare("family")==0 ){
CTX.inventory.setCurrentInventoryValue("BIBREC_100a-2",CTX.addStringData);
}
StateParsermodState::endElement(name);
};
};
*/


StateParserState* StateParsermodState::getNext(const char* const name){
static std::map<string,StateParsermodState*> map;
Expand All @@ -271,15 +243,12 @@ StateParserState* StateParsermodState::getNext(const char* const name){
_onlyOnes(std::map<string,StateParsermodState*>& map){
//static int i = 0;
//std::cerr << "Only Ones :"<< ++i << std::endl;
map["nonSort"]= new StateParsermodStateInventory("nonSort");
map["title"]= new StateParsermodStateInventory("BIBREC_245a");
//map["subTitle"]= new StateParsermodStateInventory("BIBREC_245b"); // sub state machine
map["identifier"]= new StateParsermodStateInventory("BIBREC_SYS_NUM");
map["recordIdentifier"]= new StateParsermodStateInventory("recordIdentifier");
map["title"]= new StateParsermodStateInventory("title");
map["identifier"]= new StateParsermodStateInventory("identifier");
map["languageTerm"]=new StateParsermodStateInventory("languageTerm");
map["publisher"]= new StateParsermodStateInventory("BIBREC_260b");
//map["dateIssued"]= new StateParsermodStateInventory("BIBREC_260c");
map["namePart"]= new StateParsermodStateInventory("BIBREC_100a"); // case of type
map["dateIssued"]= new StateParsermodStateInventory("BIBREC_008_7_10");
map["dateIssued"]= new StateParsermodStateInventory("dateIssued");
map["author"]= new StateParsermodStateInventory("author");
}
} onlyOnes (map);

Expand Down
27 changes: 13 additions & 14 deletions project/sql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ void database::dberror(std::string sql){

bool database::getInventory(std::string _sysnum, inventory& _inventory){
bool ret = false;
static std::string sql = "SELECT BIBREC_SYS_NUM,ITEM_barcode,BIBREC_CALL_NUM,"
" languageTerm,BIBREC_008_7_10,BIBREC_100a,BIBREC_245a,"
" BIBREC_260b,CHECKED"
" from BOOKSINVENTORY where BIBREC_SYS_NUM=?";
static std::string sql = "SELECT UNIQUEBUILDKEY,AUTHOR,PAPERID,"
" LANGUAGES,FORMALDATE,TYPE,"
" CHECKED"
" from INVENTORY where UNIQUEBUILDKEY=?";

const char *szErrMsg =0;
sqlite3_stmt *pStmt =0;
Expand All @@ -207,19 +207,18 @@ bool database::getInventory(std::string _sysnum, inventory& _inventory){
{
int col=0;

_inventory.BIBREC_SYS_NUM = safe_sqlite3_column_text(pStmt, col++);
_inventory.ITEM_barcode = safe_sqlite3_column_text(pStmt, col++);
std::string dummy = safe_sqlite3_column_text(pStmt, col++);
_inventory.uniquebuildkey = safe_sqlite3_column_text(pStmt, col++);
_inventory.author = safe_sqlite3_column_text(pStmt, col++);
_inventory.paperid = safe_sqlite3_column_text(pStmt, col++);

std::string lang = safe_sqlite3_column_text(pStmt, col++);
std::stringstream ss(lang);
std::string item;
while (std::getline(ss, item, ',')) {
_inventory.languageTerm[item]=item;
}
_inventory.BIBREC_008_7_10 = safe_sqlite3_column_text(pStmt, col++);
_inventory.BIBREC_100a = safe_sqlite3_column_text(pStmt, col++);
_inventory.BIBREC_245a = safe_sqlite3_column_text(pStmt, col++);
_inventory.BIBREC_260b = safe_sqlite3_column_text(pStmt, col++);
_inventory.formaldate = safe_sqlite3_column_text(pStmt, col++);
_inventory.type = safe_sqlite3_column_text(pStmt, col++);
_inventory.checked = sqlite3_column_int(pStmt, col++);

//std::cerr << _inventory.toString("DATABASE") << std::endl;
Expand Down Expand Up @@ -264,8 +263,8 @@ bool database::insertMetsInventory(int id_mets, std::string _sysnum){

bool database::InventoryChecked(std::string _sysnum){
bool ret = false;
static std::string sql = "UPDATE BOOKSINVENTORY SET CHECKED=1"
" where BIBREC_SYS_NUM=?";
static std::string sql = "UPDATE INVENTORY SET CHECKED=1"
" where UNIQUEBUILDKEY=?";

const char *szErrMsg =0;
sqlite3_stmt *pStmt =0;
Expand Down Expand Up @@ -524,7 +523,7 @@ bool database::insertALLData(datafactory *df,metsparserContext& ctx,int number)
updateMets(current_id_mets,df);
if ( ctx.inventory.isActif() ){
//TODO Call unique function
insertMetsInventory(current_id_mets,ctx.inventory.inventoryMODSMD_COLLECTION.BIBREC_SYS_NUM);
insertMetsInventory(current_id_mets,ctx.inventory.inventoryMODSMD_COLLECTION.uniquebuildkey);
};
insertLinkedFiles(current_id_mets,df);
datafactory_set<Article> dfarticle = df->get_set<Article>();
Expand Down
53 changes: 12 additions & 41 deletions project/verifyBook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ void verifyBook::check(int check,metsparserContext& context){
init (context);

// check if BIBREC_SYSNUM in database
std::string BIBREC_SYSNUM = context.inventory.inventoryMODSMD_COLLECTION.BIBREC_SYS_NUM;
if (!db->getInventory(BIBREC_SYSNUM,invent)){
hError -> getError(cat_bookinventory,"METS","DMDSEC MODSMD_COLLECTION", "BIBREC_SYSNUM not found:" + BIBREC_SYSNUM ,context.currentMetsFile,BIBREC_SYSNUM);
std::string UNIQ = context.inventory.inventoryMODSMD_PRINT.uniquebuildkey; // MUST depend from type
if (!db->getInventory(UNIQ,invent)){
hError -> getError(cat_bookinventory,"METS","DMDSEC MODSMD_PRINT", "UNIQKEY not found:" + UNIQ ,context.currentMetsFile,UNIQ);
return; // skip all
};

db->InventoryChecked(BIBREC_SYSNUM); // update checked flag in bookinventory to be able to show the rate of full campaign
db->InventoryChecked(UNIQ); // update checked flag in bookinventory to be able to show the rate of full campaign


/* //TODO rebuild all those test
std::string title = buildTitle( context.inventory.inventoryMODSMD_COLLECTION);
if ( invent.BIBREC_245a.compare(title)) {
hError -> getError(cat_bookinventoryTitle,"METS","DMDSEC MODSMD_COLLECTION", "wrong title:" + context.inventory.inventoryMODSMD_COLLECTION.BIBREC_245a +" against :"+ invent.BIBREC_245a ,context.currentMetsFile,context.inventory.inventoryMODSMD_COLLECTION.BIBREC_245a);
Expand All @@ -40,17 +42,9 @@ void verifyBook::check(int check,metsparserContext& context){
if ( invent.BIBREC_100a.compare(context.inventory.inventoryMODSMD_PRINT.BIBREC_100a)) {
hError -> getError(cat_bookinventoryData,"METS","DMDSEC MODSMD_PRINT", "wrong BIBREC_100a:" + context.inventory.inventoryMODSMD_PRINT.BIBREC_100a +" against :"+ invent.BIBREC_100a ,context.currentMetsFile,context.inventory.inventoryMODSMD_PRINT.BIBREC_100a);
}
*/

// TODO compare must be base on any kind order of list

for ( std::map<std::string,std::string>::iterator it = context.inventory.inventoryMODSMD_COLLECTION.languageTerm.begin() ; it != context.inventory.inventoryMODSMD_COLLECTION.languageTerm.end() ;it++){

if ( invent.languageTerm.find(it->first) == invent.languageTerm.end() ) {
hError -> getError(cat_bookinventoryData,"METS","DMDSEC MODSMD_COLLECTION", "wrong languageTerm:" + it->first ,context.currentMetsFile,it->first);

}

};

for ( std::map<std::string,std::string>::iterator it = context.inventory.inventoryMODSMD_PRINT.languageTerm.begin() ; it != context.inventory.inventoryMODSMD_PRINT.languageTerm.end() ;it++){

Expand All @@ -61,41 +55,18 @@ void verifyBook::check(int check,metsparserContext& context){

};

for ( std::map<std::string,std::string>::iterator it = invent.languageTerm.begin() ; it != invent.languageTerm.end(); it++ ){

if ( context.inventory.inventoryMODSMD_PRINT.languageTerm.find(it->first) == context.inventory.inventoryMODSMD_PRINT.languageTerm.end() ){
hError -> getError(cat_bookinventoryData,"METS","DMDSEC MOD_SMD_PRINT", "wrong languageTerm:not present" + it->first ,context.currentMetsFile,it->first);
};

if ( context.inventory.inventoryMODSMD_COLLECTION.languageTerm.find(it->first) == context.inventory.inventoryMODSMD_COLLECTION.languageTerm.end() ){
hError -> getError(cat_bookinventoryData,"METS","DMDSEC MODSMD_COLLECTION", "wrong languageTerm:not present" + it->first ,context.currentMetsFile,it->first);
};
};


if ( invent.ITEM_barcode.compare(context.inventory.inventoryMODSMD_PRINT.BIBREC_SYS_NUM /* put there in the xml */ )) {
hError -> getError(cat_bookinventoryData,"METS","DMDSEC MODSMD_PRINT", "wrong BARCODE:" + context.inventory.inventoryMODSMD_PRINT.BIBREC_SYS_NUM +" against :"+ invent.ITEM_barcode,context.currentMetsFile,context.inventory.inventoryMODSMD_PRINT.BIBREC_SYS_NUM);
}

if ( invent.BIBREC_260b.compare(context.inventory.inventoryMODSMD_PRINT.BIBREC_260b )) {
hError -> getError(cat_bookinventoryData,"METS","DMDSEC MODSMD_PRINT", "wrong BIBREC_260b:" + context.inventory.inventoryMODSMD_PRINT.BIBREC_260b +" against :"+ invent.BIBREC_260b ,context.currentMetsFile,context.inventory.inventoryMODSMD_PRINT.BIBREC_260b);
}

if ( invent.BIBREC_SYS_NUM.compare(context.inventory.inventoryMARCMD_ALEPHSYNC.BIBREC_SYS_NUM )) {
hError -> getError(cat_bookinventoryData,"METS","DMDSEC MARCMD_ALEPHSYNC", "wrong BIBREC_SYS_NUM:" + context.inventory.inventoryMARCMD_ALEPHSYNC.BIBREC_SYS_NUM +" against :"+ invent.BIBREC_SYS_NUM,context.currentMetsFile,context.inventory.inventoryMARCMD_ALEPHSYNC.BIBREC_SYS_NUM);
}

}

std::string verifyBook::buildTitle(inventory& invent){

std::string ret;

if ( invent.nonSort.empty()) {
return invent.BIBREC_245a ;
}
ret = invent.nonSort + " " + invent.BIBREC_245a;
return ret;
//if ( invent.nonSort.empty()) {
return invent.title ;
//}
//ret = invent.nonSort + " " + invent.BIBREC_245a;
//return ret;
}

void verifyBook::init(metsparserContext& context){
Expand Down
8 changes: 5 additions & 3 deletions project/verifyFolder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ void verifyFolder::check(int check ,metsparserContext& context){
std::string search = "/\\";

int pos = path.find_last_of(search);
std::string bibrec = context.inventory.getInventory("MODSMD_COLLECTION")->BIBREC_SYS_NUM;
std::string uniq = context.inventory.getInventory("MODSMD_PRINT")->uniquebuildkey;
int poss = uniq.find_last_of('/');

uniq = uniq.substr(poss+1);
if ( pos + 1 < path.length() ){
std::string sub = path.substr(pos+1);
if ( sub.compare( bibrec ) == 0 ) return ; // hoping that inventory is correcltly provided
if ( sub.compare( uniq ) == 0 ) return ; // hoping that inventory is correcltly provided
};

hError->getError(cat_wrongFolderName,"METS","FOLDER", path + " is not BIBREC_SYS_NUM : "+ bibrec ,context.currentMetsFile,bibrec);
hError->getError(cat_wrongFolderName,"METS","FOLDER", path + " is not UNIQ : "+ uniq ,context.currentMetsFile,uniq);

}

0 comments on commit f7a794b

Please sign in to comment.