Skip to content
Snippets Groups Projects
Commit 2d46a6cf authored by Jan Reher's avatar Jan Reher
Browse files

Moved validateSerials from Protosoft package to APD Toolbox.

This should eliminate any issues preventing batch creation on office machines.
parent 3a33b0e9
No related branches found
No related tags found
1 merge request!4Many proven updates being brought into stable branch.
......@@ -28,6 +28,7 @@ add_executable(makeSerialList "makeseriallist.cxx")
add_executable(makeGridList "makeGridList.cxx")
add_executable(getIrradiationDose "getirradiationstatus.cxx")
add_executable(apdUnitCreator "apdUnitCreator.cpp")
add_executable(validateSerials "validateSerials.cpp")
add_executable(testXmlStructure "testxmlstructure.cxx")
......@@ -51,4 +52,4 @@ target_link_libraries(setArrivalForIrradiation proddbaccess proddbclient boost_p
target_link_libraries(setSentForAnalysisAfterIrradiation proddbaccess proddbclient boost_program_options Qt5::Gui Qt5::Widgets)
target_link_libraries(setIrradiationInfo proddbaccess proddbclient boost_program_options Qt5::Gui Qt5::Widgets)
target_link_libraries(setAnnealingInfo proddbaccess proddbclient boost_program_options Qt5::Gui Qt5::Widgets)
target_link_libraries(validateSerials proddbaccess)
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <fstream>
#include <QCoreApplication>
#include "ProdDbAccess.h"
#include "BulkDbAccess.h"
#include "toolbox.cpp"
using namespace std;
bool checkDuplicates(vector<string> serials);
bool validateWithDB(vector<string> serials);
int main(int argc, char* argv[]) {
if ( argc > 2 ) {
cerr << "ERROR: Too many parameters! Please only provide the name of a text file containing the serials needed." << endl;
exit(1);
}
std::string fileName = "";
if ( argc == 2)
fileName = string(argv[1]);
else
fileName = "serials.dat";
vector<string> apdSerials = loadSerialsFromFileName(fileName);
if (apdSerials.size() != 30) {
if (apdSerials.size() < 30)
cerr << "There are less than 30 APDs in this file. This might indicate an error. Do you want to continue?" << std::endl;
else
cerr << "There are more than 30 APDs in this file. There can only be up to 30 APDs in one batch. Do you want to continue?" << std::endl;
std::string answer;
cin >> answer;
if (answer != "yes" && answer != "y")
return 1;
}
if (!checkDuplicates(apdSerials)) {
cerr << "At least one APD was found at least twice. Since an APD can't be in two slots at once, this serial file is invalid and will not be checked against the database." << std::endl;
return 1;
}
if (!validateWithDB(apdSerials)) {
cerr << "At least one APD was naughty!" << endl;
return 1;
}
cerr << "Santa will visit all of these APDs." << endl;
return 0;
}
bool checkDuplicates(vector<string> serials) {
bool result = true;
for (auto outerIterator = serials.begin(); outerIterator != serials.end(); outerIterator++) {
for (auto innerIterator = outerIterator; innerIterator != serials.end(); innerIterator++) {
if (innerIterator != outerIterator && *innerIterator == *outerIterator) {
result = false;
cerr << "Serial " << *innerIterator << " appears at least twice!" << std::endl;
}
}
}
return result;
}
bool validateWithDB(vector<string> serials) {
AbsDbAccess* _dba = suitedDbAccess(serials.size());
bool result = true;
for (auto iterator = serials.begin(); iterator != serials.end(); iterator++) {
if (_dba->apdAvailable(stoul(*iterator))) {
cout << "Serial " << *iterator << " is good!" << endl;
}
else {
cerr << "Serial " << *iterator << " was not found or is not available! ERROR!" << endl;
result = false;
}
}
return result;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment