From 4edae3f518353bb21a02fcda2dfcff83c5a72fc3 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 26 Jan 2012 12:08:39 +0100 Subject: New onCommit scripting system. --- server/src/sessionserialiser.cc | 47 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'server/src/sessionserialiser.cc') diff --git a/server/src/sessionserialiser.cc b/server/src/sessionserialiser.cc index 36d0a0d..386a115 100644 --- a/server/src/sessionserialiser.cc +++ b/server/src/sessionserialiser.cc @@ -88,7 +88,8 @@ Session *SessionSerialiser::loadStr(const std::string &xml) j->setPatientID(XDEC(parser.patientid)); std::vector::iterator i = parser.entries.begin(); while(i != parser.entries.end()) { - j->addEntry(XDEC(i->resume), XDEC(i->macro), XDEC(i->user), i->index); + j->addEntry(XDEC(i->resume), XDEC(i->macro), XDEC(i->user), i->index, + i->oncommit); i++; } @@ -122,6 +123,50 @@ std::string SessionSerialiser::saveStr(Session *session) " macro=\"" + XENC(i->second.macro) + "\"" " user=\"" + XENC(i->second.user) + "\">\n"; xml += " " + XENC(i->second.resume) + "\n"; + LUAOnCommit *oncommit = i->second.oncommit; + if(oncommit != NULL) { + xml += " \n"; + + xml += " \n"; + std::map::iterator ei = + oncommit->_env.begin(); + while(ei != oncommit->_env.end()) { + std::string id; + switch(ei->first) { + case LUAScript::ENV_PATIENTID: id = "ENV_PATIENTID"; break; + case LUAScript::ENV_TEMPLATE: id = "ENV_TEMPLATE"; break; + case LUAScript::ENV_MACRO: id = "ENV_MACRO"; break; + case LUAScript::ENV_USER: id = "ENV_USER"; break; + } + + xml += " "+ + XENC(ei->second) + "\n"; + ei++; + } + xml += " \n"; + + xml += " \n"; + std::map::iterator vi = + oncommit->values.begin(); + while(vi != oncommit->values.end()) { + xml += " first) + "\">"+ + XENC(vi->second) + "\n"; + vi++; + } + xml += " \n"; + + xml += " \n"; + std::vector >::iterator si = + oncommit->scripts.begin(); + while(si != oncommit->scripts.end()) { + xml += " \n"; + si++; + } + xml += " \n"; + + xml += " \n"; + } xml += " \n"; i++; -- cgit v1.2.3 From 40211cd5598c5349358e1d33b6353a4c729b17b3 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 9 Aug 2012 11:24:11 +0200 Subject: Added SessionHeaderParser for faster session xml file content searching. --- server/src/sessionserialiser.cc | 42 ++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) (limited to 'server/src/sessionserialiser.cc') diff --git a/server/src/sessionserialiser.cc b/server/src/sessionserialiser.cc index 386a115..d5150ac 100644 --- a/server/src/sessionserialiser.cc +++ b/server/src/sessionserialiser.cc @@ -34,6 +34,7 @@ #include "journal.h" #include "sessionparser.h" +#include "sessionheaderparser.h" #include "database.h" #include "xml_encode_decode.h" @@ -255,25 +256,36 @@ Session *SessionSerialiser::findFromTupple(const std::string &patientid, DEBUG(sessionserialiser, "Is xml file\n"); - // Load session file - FILE *fp = fopen(filename.c_str(), "r"); - std::string xml; - while(!feof(fp)) { - char str[64]; - memset(str, 0, sizeof(str)); - fread(str, sizeof(str) - 1, 1, fp); - xml += str; + std::string pid; + std::string tpl; + + SessionHeaderParser p(filename); + try { + p.parse(); + pid = p.getPatientID(); + tpl = p.getTemplate(); + } catch( ... ) { + continue; } - fclose(fp); - Session *session = loadStr(xml); + if(patientid == pid && templ == tpl) { + // Load session file + FILE *fp = fopen(filename.c_str(), "r"); + std::string xml; + while(!feof(fp)) { + char str[64]; + memset(str, 0, sizeof(str)); + fread(str, sizeof(str) - 1, 1, fp); + xml += str; + } + fclose(fp); + + Session *session = loadStr(xml); - DEBUG(sessionserialiser, "PatientID %s - Template %s\n", - session->patientid.c_str(), - session->templ.c_str()); + DEBUG(sessionserialiser, "PatientID %s - Template %s\n", + session->patientid.c_str(), + session->templ.c_str()); - if(session->patientid == patientid && - session->templ == templ) { closedir(dir); unlink(filename.c_str()); return session; -- cgit v1.2.3 From 05182c2214c5983c8ce7376c42805ad9802c75e5 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 9 Aug 2012 12:04:43 +0200 Subject: Added session files to admin session list. --- server/src/sessionserialiser.cc | 53 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 5 deletions(-) (limited to 'server/src/sessionserialiser.cc') diff --git a/server/src/sessionserialiser.cc b/server/src/sessionserialiser.cc index d5150ac..6288ddd 100644 --- a/server/src/sessionserialiser.cc +++ b/server/src/sessionserialiser.cc @@ -216,6 +216,11 @@ void SessionSerialiser::save(Session *session) // write xml to file FILE *fp = fopen(filename.c_str(), "w"); + if(!fp) { + ERR(sessionserialiser, "Could not write session to file %s\n", + filename.c_str()); + return; + } fwrite(xml.data(), xml.size(), 1, fp); fclose(fp); } @@ -256,19 +261,17 @@ Session *SessionSerialiser::findFromTupple(const std::string &patientid, DEBUG(sessionserialiser, "Is xml file\n"); - std::string pid; - std::string tpl; + SessionHeaderParser::Header header; SessionHeaderParser p(filename); try { p.parse(); - pid = p.getPatientID(); - tpl = p.getTemplate(); + header = p.getHeader(); } catch( ... ) { continue; } - if(patientid == pid && templ == tpl) { + if(header.patientid == patientid && header.templ == templ) { // Load session file FILE *fp = fopen(filename.c_str(), "r"); std::string xml; @@ -298,6 +301,46 @@ Session *SessionSerialiser::findFromTupple(const std::string &patientid, return NULL; } +std::map +SessionSerialiser::sessionFiles() +{ + std::map list; + + DIR *dir = opendir(path.c_str()); + if(!dir) { + ERR(sessionserialiser, "Could not open directory: %s - %s\n", + path.c_str(), strerror(errno)); + return list; + } + + struct dirent *dirent; + while( (dirent = readdir(dir)) != NULL ) { + + std::string filename = path+"/"+dirent->d_name; + + if(isxmlfile(filename)) { + + SessionHeaderParser::Header header; + + SessionHeaderParser p(filename); + try { + p.parse(); + header = p.getHeader(); + } catch( ... ) { + continue; + } + + list[filename] = header; + } + } + + closedir(dir); + + return list; + +} + + #ifdef TEST_SESSIONSERIALISER //deps: session.cc journal.cc debug.cc configuration.cc mutex.cc journal_commit.cc sessionparser.cc saxparser.cc xml_encode_decode.cc database.cc pracrodaopgsql.cc pracrodaotest.cc pracrodao.cc journal_uploadserver.cc log.cc environment.cc semaphore.cc artefact.cc macrolist.cc templatelist.cc entitylist.cc inotify.cc versionstr.cc exception.cc macroheaderparser.cc templateheaderparser.cc //cflags: -I.. $(PTHREAD_CFLAGS) $(EXPAT_CFLAGS) $(PQXX_CFLAGS) -DWITHOUT_ARTEFACT -- cgit v1.2.3