<commit_before>#include "Arangodbdriver.h"
#include <QtCore/QDebug>
#include <QtCore/QUrl>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>

using namespace arangodb;

namespace internal {

class ArangodbdriverPrivate
{
    public:
        QString protocol;
        QString host;
        qint32 port;
        QNetworkAccessManager networkManager;

        QString standardUrl;

        void createStandardUrl() {
            standardUrl = protocol + QString("://") + host + QString(":") + QString::number(port) + QString("/_api");
        }
};

}

Arangodbdriver::Arangodbdriver(QString protocol, QString host, qint32 port) :
    d(new internal::ArangodbdriverPrivate)
{
    d->protocol = protocol;
    d->host = host;
    d->port = port;

    d->createStandardUrl();
}

Arangodbdriver::~Arangodbdriver()
{
    delete d;
}

Document *Arangodbdriver::getDocument(QString id)
{
    Document *doc = new Document(this);

    QUrl url(d->standardUrl + QString("/document/") + id);
    QNetworkReply *reply = d->networkManager.get(QNetworkRequest(url));

    connect(reply, &QNetworkReply::finished,
            doc, &Document::_ar_dataIsAvailable
            );

    connect(doc, &Document::saveData,
            this, &Arangodbdriver::_ar_save
            );

    connect(doc, &Document::deleteData,
            this, &Arangodbdriver::_ar_delete
            );

    return doc;
}

Document *Arangodbdriver::createDocument(QString collection)
{
    Document *doc = new Document(collection, this);

    connect(doc, &Document::saveData,
            this, &Arangodbdriver::_ar_save
            );

    connect(doc, &Document::deleteData,
            this, &Arangodbdriver::_ar_delete
            );

    return doc;
}

void Arangodbdriver::_ar_save(Document *doc)
{
    if ( doc->isCreated() ) {
        }
    else {
            QByteArray jsonData = doc->toJsonString();
            QByteArray jsonDataSize = QByteArray::number(jsonData.size());
            QUrl url(d->standardUrl + QString("/document?collection=") + doc->collection());
            QNetworkRequest request(url);
            request.setRawHeader("Content-Type", "application/json");
            request.setRawHeader("Content-Length", jsonDataSize);
            QNetworkReply *reply = d->networkManager.post(request, jsonData);

            connect(reply, &QNetworkReply::finished,
                    doc, &Document::_ar_dataIsAvailable
                    );
        }
}

void Arangodbdriver::_ar_delete(Document *doc)
{
    QUrl url(d->standardUrl + QString("/document/") + doc->docID());
    QNetworkRequest request(url);
    QNetworkReply *reply = d->networkManager.deleteResource(request);

    connect(reply, &QNetworkReply::finished,
            doc, &Document::_ar_dataDeleted
            );
}<commit_msg>Update mechanisme (issue - MR-4)<commit_after>#include "Arangodbdriver.h"
#include <QtCore/QDebug>
#include <QtCore/QUrl>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>

using namespace arangodb;

namespace internal {

class ArangodbdriverPrivate
{
    public:
        QString protocol;
        QString host;
        qint32 port;
        QNetworkAccessManager networkManager;

        QString standardUrl;

        void createStandardUrl() {
            standardUrl = protocol + QString("://") + host + QString(":") + QString::number(port) + QString("/_api");
        }
};

}

Arangodbdriver::Arangodbdriver(QString protocol, QString host, qint32 port) :
    d(new internal::ArangodbdriverPrivate)
{
    d->protocol = protocol;
    d->host = host;
    d->port = port;

    d->createStandardUrl();
}

Arangodbdriver::~Arangodbdriver()
{
    delete d;
}

Document *Arangodbdriver::getDocument(QString id)
{
    Document *doc = new Document(this);

    QUrl url(d->standardUrl + QString("/document/") + id);
    QNetworkReply *reply = d->networkManager.get(QNetworkRequest(url));

    connect(reply, &QNetworkReply::finished,
            doc, &Document::_ar_dataIsAvailable
            );

    connect(doc, &Document::saveData,
            this, &Arangodbdriver::_ar_save
            );

    connect(doc, &Document::deleteData,
            this, &Arangodbdriver::_ar_delete
            );

    return doc;
}

Document *Arangodbdriver::createDocument(QString collection)
{
    Document *doc = new Document(collection, this);

    connect(doc, &Document::saveData,
            this, &Arangodbdriver::_ar_save
            );

    connect(doc, &Document::deleteData,
            this, &Arangodbdriver::_ar_delete
            );

    return doc;
}

void Arangodbdriver::_ar_save(Document *doc)
{
    QByteArray jsonData = doc->toJsonString();
    QByteArray jsonDataSize = QByteArray::number(jsonData.size());

    if ( doc->isCreated() ) {
            QUrl url(d->standardUrl + QString("/document/") + doc->docID());
            QNetworkRequest request(url);
            request.setRawHeader("Content-Type", "application/json");
            request.setRawHeader("Content-Length", jsonDataSize);

            QNetworkReply *reply = d->networkManager.put(request, jsonData);

            connect(reply, &QNetworkReply::finished,
                    doc, &Document::_ar_dataIsAvailable
                    );
        }
    else {
            QUrl url(d->standardUrl + QString("/document?collection=") + doc->collection());
            QNetworkRequest request(url);
            request.setRawHeader("Content-Type", "application/json");
            request.setRawHeader("Content-Length", jsonDataSize);

            QNetworkReply *reply = d->networkManager.post(request, jsonData);

            connect(reply, &QNetworkReply::finished,
                    doc, &Document::_ar_dataIsAvailable
                    );
        }
}

void Arangodbdriver::_ar_delete(Document *doc)
{
    QUrl url(d->standardUrl + QString("/document/") + doc->docID());
    QNetworkRequest request(url);
    QNetworkReply *reply = d->networkManager.deleteResource(request);

    connect(reply, &QNetworkReply::finished,
            doc, &Document::_ar_dataDeleted
            );
}
{'fraction_non_alphanumeric': 0.1273235729560783, 'fraction_numerical': 0.0014805066622799803, 'mean_word_length': 2.85297845373891, 'pattern_counts': {'":': 4, '<': 11, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4516707', 'n_tokens_mistral': 1794, 'n_tokens_neox': 1778, 'n_words': 315}