Skip to content

Commit

Permalink
Merge pull request #51 from qlands/master
Browse files Browse the repository at this point in the history
Few fixes
  • Loading branch information
qlands authored Jan 17, 2019
2 parents 4935f0e + 4e42a06 commit bfe6ad6
Show file tree
Hide file tree
Showing 13 changed files with 308 additions and 88 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ mysqldenormalize
jsontocsv
json2csv
mysqltoxlsx
jxformtomysql

#Other directories
old
Expand Down
2 changes: 1 addition & 1 deletion AWS_build_script.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ODK Tools - Installation script tested in Ubuntu server 16.04 and 18.04

sudo apt-get update
sudo apt-get install build-essential qt5-default qtbase5-private-dev qtdeclarative5-dev cmake mongodb jq libboost-all-dev unzip zlib1g-dev automake npm
sudo apt-get install build-essential qt5-default qtbase5-private-dev qtdeclarative5-dev libqt5sql5-mysql cmake mongodb jq libboost-all-dev unzip zlib1g-dev automake npm

cd /opt
sudo git clone https://github.com/qlands/odktools.git
Expand Down
5 changes: 4 additions & 1 deletion JSONToMySQL/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ int main(int argc, char *argv[])
TCLAP::SwitchArg overwriteSwitch("w","overwrite","Overwrite the log file", cmd, false);
TCLAP::SwitchArg oputSQLSwitch("S","outputSQL","Output each insert SQL to ./inputfile.json.sql", cmd, false);
TCLAP::ValueArg<std::string> mapDirArg("M","mapoutputdir","Map output directory",false,"./recordMaps","string");
TCLAP::ValueArg<std::string> uuIdsArg("U","uuidsfile","UUIDs output file",false,"./uuids.log","string");
TCLAP::ValueArg<std::string> outTypeArg("O","outputtype","OutputType: (h)uman readable or (m)achine readble",false,"m","string");

//These two parameters should be removed once the external script code works
Expand All @@ -70,6 +71,7 @@ int main(int argc, char *argv[])
cmd.add(inputArg);
cmd.add(mapDirArg);
cmd.add(outTypeArg);
cmd.add(uuIdsArg);
cmd.add(JSArg);

//Parsing the command lines
Expand All @@ -90,10 +92,11 @@ int main(int argc, char *argv[])
QString javaScript = QString::fromUtf8(JSArg.getValue().c_str());
QString mapDirectory = QString::fromUtf8(mapDirArg.getValue().c_str());
QString outputType = QString::fromUtf8(outTypeArg.getValue().c_str());
QString uuidsFile = QString::fromUtf8(uuIdsArg.getValue().c_str());

mainClass *task = new mainClass(&app);

task->setParameters(overwrite,json,manifest,host,port,user,password,schema,output,input,javaScript,oputSQLSwitch.getValue(),mapDirectory,outputType);
task->setParameters(overwrite,json,manifest,host,port,user,password,schema,output,input,javaScript,oputSQLSwitch.getValue(),mapDirectory,outputType, uuidsFile);

QObject::connect(task, SIGNAL(finished()), &app, SLOT(quit()));

Expand Down
28 changes: 26 additions & 2 deletions JSONToMySQL/mainclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,18 @@ void mainClass::run()
db.setUserName(user);
db.setPassword(password);
if (db.open())
{
{
QFile UUIDFile(UUIDsFile);
//The file is new so write from start
if (!UUIDFile.open(QIODevice::WriteOnly | QIODevice::Text))
{
log("Cannot create processing file");
returnCode = 1;
db.close();
emit finished();
}
QTextStream UUIDout(&UUIDFile); //Stream to the processing file

QStringList procList;
QFile file(input);
if (file.open(QIODevice::ReadOnly | QIODevice::Text))
Expand Down Expand Up @@ -268,6 +279,12 @@ void mainClass::run()
}
else
{
for (int aUUID = 0; aUUID <= UUIDList.count()-1; aUUID++)
{
UUIDout << UUIDList.at(aUUID) + "\n";
}
UUIDFile.close();

QFileInfo fi(json);
out << fi.baseName() + "\n";
file.close();
Expand Down Expand Up @@ -318,7 +335,7 @@ void mainClass::run()
emit finished();
}

void mainClass::setParameters(bool voverwrite, QString vjson, QString vmanifest, QString vhost, QString vport, QString vuser, QString vpassword, QString vschema, QString voutput, QString vinput, QString vjavaScript, bool voputSQLSwitch, QString mapDirectory, QString outputType)
void mainClass::setParameters(bool voverwrite, QString vjson, QString vmanifest, QString vhost, QString vport, QString vuser, QString vpassword, QString vschema, QString voutput, QString vinput, QString vjavaScript, bool voputSQLSwitch, QString mapDirectory, QString outputType, QString uuidsFile)
{
overwrite = voverwrite;
json = vjson;
Expand All @@ -334,6 +351,7 @@ void mainClass::setParameters(bool voverwrite, QString vjson, QString vmanifest,
outSQL = voputSQLSwitch;
mapOutputDir = mapDirectory;
this->outputType = outputType;
UUIDsFile = uuidsFile;
}


Expand Down Expand Up @@ -671,6 +689,7 @@ QList<TfieldDef > mainClass::createSQL(QSqlDatabase db, QVariantMap jsonData, QS
parts = key.value.split(".");
key.value = parts[0];
key.value = key.value.replace("T"," ");
key.value = key.value.replace("Z","");
}
}
key.uuid = table + "~" + strRecordUUID;
Expand Down Expand Up @@ -774,6 +793,7 @@ QList<TfieldDef > mainClass::createSQL(QSqlDatabase db, QVariantMap jsonData, QS
parts = fieldValue.split(".");
fieldValue = parts[0];
fieldValue = fieldValue.replace("T"," ");
fieldValue = fieldValue.replace("Z","");
}
}
insValue.value = fieldValue;
Expand Down Expand Up @@ -848,6 +868,8 @@ QList<TfieldDef > mainClass::createSQL(QSqlDatabase db, QVariantMap jsonData, QS
uuids.append(parentkeys[nkey].uuid);
}
storeRecord(uuids,table + "~" + strRecordUUID);
//Add the UUID to the list
UUIDList.append(table + "," + strRecordUUID);
}

//Now we process the MultiSelects
Expand Down Expand Up @@ -931,6 +953,8 @@ QList<TfieldDef > mainClass::createSQL(QSqlDatabase db, QVariantMap jsonData, QS
{
//Store the record in the map
storeRecord(table + "~" + strRecordUUID,mSelectTableName + "~" + uuidstr);
//Store the UUD
UUIDList.append(mSelectTableName + "," + uuidstr);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion JSONToMySQL/mainclass.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class mainClass : public QObject
void finishedWithError(int error);
public slots:
void run();
void setParameters(bool voverwrite, QString vjson, QString vmanifest, QString vhost, QString vport, QString vuser, QString vpassword, QString vschema, QString voutput, QString vinput, QString vjavaScript, bool voputSQLSwitch, QString mapDirectory, QString outputType);
void setParameters(bool voverwrite, QString vjson, QString vmanifest, QString vhost, QString vport, QString vuser, QString vpassword, QString vschema, QString voutput, QString vinput, QString vjavaScript, bool voputSQLSwitch, QString mapDirectory, QString outputType, QString uuidsFile);
private:

int getLastIndex(QString table);
Expand Down Expand Up @@ -123,6 +123,7 @@ public slots:
QTextStream sqlStream;
QDomDocument recordMap;
QDomElement recordMapRoot;
QStringList UUIDList;

QJSEngine JSEngine;

Expand All @@ -140,6 +141,7 @@ public slots:
QString javaScript;
QString mapOutputDir;
QString outputType;
QString UUIDsFile;
};

#endif // MAINCLASS_H
Binary file not shown.
Binary file not shown.
Binary file modified ODKToMySQL/examples/single-language/single-language.xlsx
Binary file not shown.
Loading

0 comments on commit bfe6ad6

Please sign in to comment.