Fix code formating

This commit is contained in:
Ondřej Fischer 2019-11-06 16:48:53 +01:00
parent 8364523839
commit 8e21275b6a
10 changed files with 109 additions and 109 deletions

View File

@ -27,9 +27,9 @@ int DatabaseManager::saveSubject(std::shared_ptr<Subject> subject, const QString
rtn = -1;
}else{
query.prepare(QString("INSERT INTO %1 (id, description, last_update, name, pin, last_modified, deleted) "
"VALUES (:id, :description, :last_update, :name, :pin, :last_modified, :deleted)").arg(table));
"VALUES (:id, :description, :last_update, :name, :pin, :last_modified, :deleted)").arg(table));
rtn = 1;
}
}
query.bindValue(":id", id);
query.bindValue(":description", subject->getDescription());
query.bindValue(":name", subject->getName());
@ -49,11 +49,11 @@ int DatabaseManager::saveToken(std::shared_ptr<Token> token, const QString& tabl
int rtn;
if (checkIfExists(id, table)){
query.prepare(QString("UPDATE %1 SET id = :id, auth_errors = :auth_errors, description = :description, enabled = :enabled, last_update = :last_update, name = :name, no_validity = :no_validity, time_to_live = :time_to_live, token_bits = :token_bits, token_data = :token_data, token_type = :token_type, subject_id = :subject_id, last_modified = :last_modified, deleted = :deleted "
"WHERE id = :id").arg(table));
"WHERE id = :id").arg(table));
rtn = -1;
}else{
query.prepare(QString("INSERT INTO %1 (id, auth_errors, description, enabled, last_update, name, no_validity, time_to_live, token_bits, token_data, token_type, subject_id, last_modified, deleted) "
"VALUES (:id, :auth_errors, :description, :enabled, :last_update, :name, :no_validity, :time_to_live, :token_bits, :token_data, :token_type, :subject_id, :last_modified, :deleted)").arg(table));
"VALUES (:id, :auth_errors, :description, :enabled, :last_update, :name, :no_validity, :time_to_live, :token_bits, :token_data, :token_type, :subject_id, :last_modified, :deleted)").arg(table));
rtn = 1;
}
query.bindValue(":id", id);
@ -141,21 +141,21 @@ bool DatabaseManager::executeQuery(QSqlQuery &query, const QString &statement)
QString msg = QString("Source: Database Manager, Error: %1").arg(query.lastError().text());
log(QString(msg));
emit error();
}
}
}
return true;
}
if (dryMode){
qDebug() << statement;
if (dryMode){
qDebug() << statement;
}
if (!dryMode || statement.startsWith("SELECT")){
if (!query.exec(statement)){
QString msg = QString("Source: Database Manager, Error: %1").arg(query.lastError().text());
log(QString(msg));
emit error();
}
if (!dryMode || statement.startsWith("SELECT")){
if (!query.exec(statement)){
QString msg = QString("Source: Database Manager, Error: %1").arg(query.lastError().text());
log(QString(msg));
emit error();
}
}
return true;
}
return true;
}
void DatabaseManager::dropTables()
@ -171,33 +171,33 @@ void DatabaseManager::createTables()
QSqlQuery query;
executeQuery(query, "CREATE TABLE colnod_subject ("
"id character(36) primary key NOT NULL,"
"description character varying(255),"
"last_update timestamp NOT NULL,"
"name character varying(255),"
"pin character varying(255),"
"last_modified timestamp,"
"deleted BOOLEAN)");
"id character(36) primary key NOT NULL,"
"description character varying(255),"
"last_update timestamp NOT NULL,"
"name character varying(255),"
"pin character varying(255),"
"last_modified timestamp,"
"deleted BOOLEAN)");
executeQuery(query, "CREATE TABLE colnod_token ("
"id CHAR(36) primary key NOT NULL,"
"auth_errors INTEGER NOT NULL,"
"description VARCHAR(255),"
"enabled BOOLEAN NOT NULL,"
"last_update timestamp NOT NULL,"
"name VARCHAR(255),"
"no_validity BOOLEAN NOT NULL,"
"time_to_live INTEGER NOT NULL,"
"token_bits INTEGER,"
"token_data VARCHAR(255),"
"token_type VARCHAR(255),"
"subject_id CHAR(36),"
"last_modified timestamp,"
"deleted BOOLEAN)");
"id CHAR(36) primary key NOT NULL,"
"auth_errors INTEGER NOT NULL,"
"description VARCHAR(255),"
"enabled BOOLEAN NOT NULL,"
"last_update timestamp NOT NULL,"
"name VARCHAR(255),"
"no_validity BOOLEAN NOT NULL,"
"time_to_live INTEGER NOT NULL,"
"token_bits INTEGER,"
"token_data VARCHAR(255),"
"token_type VARCHAR(255),"
"subject_id CHAR(36),"
"last_modified timestamp,"
"deleted BOOLEAN)");
executeQuery(query, "CREATE TABLE colnod_subject_attribute ("
"id VARCHAR(255) primary key,"
"attribute_key VARCHAR(255),"
"attribute_value VARCHAR(255),"
"subject_id CHAR(36))");
"id VARCHAR(255) primary key,"
"attribute_key VARCHAR(255),"
"attribute_value VARCHAR(255),"
"subject_id CHAR(36))");
}
// return last_sync time
@ -225,7 +225,7 @@ QSqlQuery DatabaseManager::getUpdatedTokens()
{
QSqlQuery query;
executeQuery(query, "SELECT id, auth_errors, description, enabled, last_update, name, no_validity, time_to_live, token_bits, token_data, token_type, subject_id, last_modified, deleted "
"FROM colnod_token WHERE EXTRACT(EPOCH FROM last_modified) * 1000 > EXTRACT(EPOCH FROM last_update) * 1000");
"FROM colnod_token WHERE EXTRACT(EPOCH FROM last_modified) * 1000 > EXTRACT(EPOCH FROM last_update) * 1000");
return query;
}

View File

@ -86,7 +86,7 @@ void DataManager::fillTokensToChangeDB()
tokensFromDBToDeleteFromColnod.append(token->idToStringWithoutBraces());
}
else{
tokensToUpdateFromDBToColnod.insert(token->idToStringWithoutBraces(), token);
tokensToUpdateFromDBToColnod.insert(token->idToStringWithoutBraces(), token);
}
}
qDebug() << "DB:" << tokensToUpdateFromDBToColnod.size() << "tokens to update";
@ -95,7 +95,7 @@ void DataManager::fillTokensToChangeDB()
void DataManager::fillSubjectsToUpdateDB()
{
// Not needed yet
// Not needed yet
}
// load working set with subjest to delete from Colnod
@ -150,18 +150,18 @@ void DataManager::pushSubjectsToDB()
for (const auto& subject : subjectsToUpdateFromColnodToDB)
{
if (db->saveSubject(subject, "colnod_subject") > 0){
added++;
if (dryMode)
qInfo() << "Adding subject:" << subject->idToStringWithoutBraces() << "to DB";
else
Logger::logToDb(Logger::makeSubjectMsg( subject->idToStringWithoutBraces(),"added", "DB"));
added++;
if (dryMode)
qInfo() << "Adding subject:" << subject->idToStringWithoutBraces() << "to DB";
else
Logger::logToDb(Logger::makeSubjectMsg( subject->idToStringWithoutBraces(),"added", "DB"));
}
else{
updated++;
if (dryMode)
qInfo() << "Updating subject:" << subject->idToStringWithoutBraces() << "to DB";
else
Logger::logToDb(Logger::makeSubjectMsg( subject->idToStringWithoutBraces(),"updated", "DB"));
updated++;
if (dryMode)
qInfo() << "Updating subject:" << subject->idToStringWithoutBraces() << "to DB";
else
Logger::logToDb(Logger::makeSubjectMsg( subject->idToStringWithoutBraces(),"updated", "DB"));
}
db->saveSubjectAttributes(subject, "colnod_subject_attribute");
}
@ -183,21 +183,21 @@ void DataManager::pushTokensToDB()
for (const auto& token : tokensToUpdateFromColnodToDB)
{
QString text;
// 1 = adding token
// -1 = updating token
if (db->saveToken(token, "colnod_token") == 1){
added++;
text = "Added";
}
else {
updated++;
text = "Updating";
}
if (dryMode)
qInfo() << text << "token:" << token->idToStringWithoutBraces() << "to DB";
else
Logger::logToDb(Logger::makeTokenMsg(token->idToStringWithoutBraces(), text, "DB"));
QString text;
// 1 = adding token
// -1 = updating token
if (db->saveToken(token, "colnod_token") == 1){
added++;
text = "Added";
}
else {
updated++;
text = "Updating";
}
if (dryMode)
qInfo() << text << "token:" << token->idToStringWithoutBraces() << "to DB";
else
Logger::logToDb(Logger::makeTokenMsg(token->idToStringWithoutBraces(), text, "DB"));
}
qInfo() << "DB:" << added << "tokens added/edited";
qInfo() << "DB:" << updated << "tokens updated";
@ -268,8 +268,8 @@ void DataManager::clear()
subjectsFromColnodToDeleteFromDB.clear();
tokensToUpdateFromColnodToDB.clear();
tokensFromColnodToDeleteFromDB.clear();
//subjectsDB.clear(); // not need yet
// subjectsToDeleteDB.clear(); // not need yet
//subjectsDB.clear(); // not need yet
// subjectsToDeleteDB.clear(); // not need yet
tokensToUpdateFromDBToColnod.clear();
tokensFromDBToDeleteFromColnod.clear();
allTokensFromColnodById.clear();

View File

@ -8,7 +8,7 @@
class Entity : public QObject {
Q_OBJECT
Q_OBJECT
public:
using QObject::QObject;

View File

@ -14,8 +14,8 @@ std::shared_ptr<Response> RequestManager::login()
QString hash = encryptedPassword(this->password);
authHeader = getLoginHeader(this->user, hash);
QJsonObject reqBody = {
{"password", hash},
{"username", this->user}
{"password", hash},
{"username", this->user}
};
request.setUrl(this->host + "/AaaManager/authSession");
request.setRawHeader("Authorization", authHeader.toLocal8Bit());
@ -36,7 +36,7 @@ std::shared_ptr<Response> RequestManager::login()
loginStatus = true;
emit successLogin();
reply->deleteLater();
});
});
connect(this, &RequestManager::successLogin, loginResponse.get(), &Response::ready);
connect(this, &RequestManager::successLogin, this, &RequestManager::prepareAuthHeader);
return loginResponse;
@ -82,7 +82,7 @@ Response* RequestManager::postRequestReturnLogic(const QString& endpoint, const
connect(this, &RequestManager::successLogin, [=](){
response->setReply(postRequest(endpoint, data));
connect(response->getReply(), &QNetworkReply::finished, response, &Response::ready);
});
});
}
else
{
@ -106,7 +106,7 @@ QString RequestManager::getFromJson(const QString& json, const QString &member)
QString RequestManager::encryptedPassword(const QString& password)
{
return QCryptographicHash::hash(password.toLocal8Bit(), QCryptographicHash::Sha512).toHex().toUpper();
return QCryptographicHash::hash(password.toLocal8Bit(), QCryptographicHash::Sha512).toHex().toUpper();
}
QString RequestManager::getLoginHeader(const QString& username, const QString& hash)
@ -233,7 +233,7 @@ Response* RequestManager::getAccessGroupMembershipUpdated(uint64_t time)
Response* RequestManager::getAccessGroupMembershipDeleted(uint64_t time)
{
return postRequestReturnLogic("/AccessManager/getAccessGroupMembershipDeleted", makeTimestampJson(time));
return postRequestReturnLogic("/AccessManager/getAccessGroupMembershipDeleted", makeTimestampJson(time));
}
Response* RequestManager::setTokens(const QHash<QString, std::shared_ptr<Token>> &tokens)

View File

@ -36,7 +36,7 @@ public:
RequestManager();
// this should be in ColnodAPI class BEGIN
// this should be in ColnodAPI class BEGIN
Response* getSubjects();
Response* getTokens();
Response* getTokenSubject();
@ -56,10 +56,10 @@ public:
Response* setTokens(const QHash<QString, std::shared_ptr<Token>> &tokens);
Response* deleteTokens(const QList<QString> &ids);
// END
// END
private:
// should be public
// should be public
QNetworkReply* postRequest(const QString& endpoint, const QByteArray& json = QByteArray());
Response* postRequestReturnLogic(const QString& endpoint, const QByteArray& data = QByteArray());
@ -69,7 +69,7 @@ private:
QString encryptedPassword(const QString& password);
QString getLoginHeader(const QString& username, const QString& hash);
// in colnod api as well
// in colnod api as well
QByteArray makeTimestampJson(uint64_t time);
QByteArray makeTokensJson(const QHash<QString, std::shared_ptr<Token>> &tokens); // maybe better to be in Token class
QByteArray makeIdsJson(const QList<QString> &ids); // Entity class

View File

@ -138,5 +138,5 @@ void Token::setSubjectId(const QUuid &subjectId) {
}
QString Token::subjectIdToStringWithoutBraces(){
return subjectId.toString().mid(1,36);
return subjectId.toString().mid(1,36);
}

View File

@ -9,7 +9,7 @@
class Token : public Entity {
public:
// using Entity::Entity;
// using Entity::Entity;
Token() = default;
Token(const QString& name, QString tokenData, const QString& decription = "mobile");

View File

@ -342,7 +342,7 @@ void UnitTest::debugConnection()
void UnitTest::saveDataToDB()
{
// dataMan->localSaveTokens();
// dataMan->localSaveTokens();
QVERIFY(true);
}

View File

@ -2,16 +2,16 @@
void ComplexTest::initTestCase()
{
// auto reqMan1 = new RequestManager;
// QList<QString> ids;
// ids.append("582c982d-6fd7-4856-8548-7ce542791c7a");
// ids.append("3ff23b41-3da3-4b33-82ce-d8e2d8c9a546");
// Response* deleteTokensResp = reqMan1->deleteTokens(ids);
// QSignalSpy deleteTokensRespSpy(deleteTokensResp, &Response::ready);
// QCOMPARE(deleteTokensRespSpy.count(), 0);
// deleteTokensRespSpy.wait(timeout);
// QTest::qWait(2500);
// Logger *logger = Logger::getLogger();
// auto reqMan1 = new RequestManager;
// QList<QString> ids;
// ids.append("582c982d-6fd7-4856-8548-7ce542791c7a");
// ids.append("3ff23b41-3da3-4b33-82ce-d8e2d8c9a546");
// Response* deleteTokensResp = reqMan1->deleteTokens(ids);
// QSignalSpy deleteTokensRespSpy(deleteTokensResp, &Response::ready);
// QCOMPARE(deleteTokensRespSpy.count(), 0);
// deleteTokensRespSpy.wait(timeout);
// QTest::qWait(2500);
// Logger *logger = Logger::getLogger();
start = QDateTime::currentMSecsSinceEpoch()-2000;
api = new SyncManager();
qDebug() << start;
@ -21,15 +21,15 @@ void ComplexTest::initTestCase()
void ComplexTest::cleanupTestCase()
{
// QList<QString> ids;
// ids.append("582c982d-6fd7-4856-8548-7ce542791c7a");
// ids.append("3ff23b41-3da3-4b33-82ce-d8e2d8c9a546");
// auto reqMan = new RequestManager;
// Response* deleteTokensResp = reqMan->deleteTokens(ids);
// QSignalSpy deleteTokensRespSpy(deleteTokensResp, &Response::ready);
// QCOMPARE(deleteTokensRespSpy.count(), 0);
// deleteTokensRespSpy.wait(timeout);
// QCOMPARE(deleteTokensRespSpy.count(), 1);
// QList<QString> ids;
// ids.append("582c982d-6fd7-4856-8548-7ce542791c7a");
// ids.append("3ff23b41-3da3-4b33-82ce-d8e2d8c9a546");
// auto reqMan = new RequestManager;
// Response* deleteTokensResp = reqMan->deleteTokens(ids);
// QSignalSpy deleteTokensRespSpy(deleteTokensResp, &Response::ready);
// QCOMPARE(deleteTokensRespSpy.count(), 0);
// deleteTokensRespSpy.wait(timeout);
// QCOMPARE(deleteTokensRespSpy.count(), 1);
}
void ComplexTest::complexTest()

View File

@ -44,11 +44,11 @@ private slots:
private:
//QString host = "http://localhost:8080"; //colnod server (ssh -L 8080:192.168.254.11:8443 penta-master)
QString host = "https://192.168.1.3:8443"; //local testing server
QString password = "spaceti1";
QString email = "spaceti";
//QString host = "http://localhost:8080"; //colnod server (ssh -L 8080:192.168.254.11:8443 penta-master)
QString host = "https://192.168.1.3:8443"; //local testing server
QString password = "spaceti1";
QString email = "spaceti";
static constexpr int timeout = 10000;
static constexpr qint64 epochMS = 1568646217767;
static constexpr int timeout = 10000;
static constexpr qint64 epochMS = 1568646217767;
};