1 #include "confluence-agent.h"
6 #include <iostream> // FIXME-2 for debugging...
8 #include "branchitem.h"
9 #include "confluence-user.h"
11 #include "mainwindow.h"
14 #include "warningdialog.h"
16 extern Main *mainWindow;
17 extern QDir vymBaseDir;
18 extern QString confluencePassword;
19 extern Settings settings;
22 bool ConfluenceAgent::available()
24 if (!QSslSocket::supportsSsl())
26 if ( settings.value("/atlassian/confluence/username", "").toString().isEmpty())
29 if ( settings.value("/atlassian/confluence/url", "").toString().isEmpty())
35 ConfluenceAgent::ConfluenceAgent() {
36 //qDebug() << "Constr. ConfluenceAgent jobType=";
40 ConfluenceAgent::ConfluenceAgent(BranchItem *bi)
42 //qDebug() << "Constr. ConfluenceAgent selbi = " << bi;
45 qWarning("Const ConfluenceAgent: bi == nullptr");
46 // This will leave the agent hanging around undeleted...
55 ConfluenceAgent::~ConfluenceAgent()
57 // qDebug() << "Destr ConfluenceAgent." << jobType;
62 void ConfluenceAgent::init()
70 networkManager = new QNetworkAccessManager(this);
72 modelID = 0; // invalid ID
74 killTimer = new QTimer(this);
75 killTimer->setInterval(15000);
76 killTimer->setSingleShot(true);
78 QObject::connect(killTimer, SIGNAL(timeout()), this, SLOT(timeout()));
80 apiURL = baseURL + "/rest/api";
81 baseURL = settings.value("/atlassian/confluence/url", "baseURL").toString();
84 attachmentsAgent = nullptr;
85 currentUploadAttachmentIndex = -1;
89 settings.value("/atlassian/confluence/authUsingPAT", true).toBool();
92 settings.value("/atlassian/confluence/PAT", "undefined").toString();
95 settings.value("/atlassian/confluence/username", "user_johnDoe").toString();
96 if (!confluencePassword.isEmpty())
97 password = confluencePassword;
100 settings.value("/atlassian/confluence/password", "").toString();
103 if (!authUsingPAT && password.isEmpty()) {
104 // Set global password
105 if (!mainWindow->settingsConfluence())
110 void ConfluenceAgent::setJobType(JobType jt)
115 void ConfluenceAgent::setBranch(BranchItem *bi)
118 qWarning() << "ConfluenceAgent::setBranch bi == nullptr";
121 branchID = bi->getID();
122 VymModel *model = bi->getModel();
123 modelID = model->getModelID();
127 void ConfluenceAgent::setModelID(uint id)
132 void ConfluenceAgent::setPageURL(const QString &u)
137 void ConfluenceAgent::setNewPageName(const QString &t)
142 void ConfluenceAgent::setUploadPagePath(const QString &fp)
147 void ConfluenceAgent::addUploadAttachmentPath(const QString &fp)
149 uploadAttachmentPaths << fp;
152 void ConfluenceAgent::startJob()
155 unknownStepWarningFinishJob();
162 void ConfluenceAgent::continueJob(int nextStep)
176 // qDebug() << "CA::contJob " << jobType << " Step: " << jobStep;
179 case CopyPagenameToHeading:
181 startGetPageSourceRequest(pageURL);
185 startGetPageDetailsRequest();
189 model = mainWindow->getModel(modelID);
191 BranchItem *bi = (BranchItem *)(model->findID(branchID));
194 QString h = spaceKey + ": " + pageObj["title"].toString();
195 model->setHeading(h, bi);
197 qWarning() << "CA::continueJob couldn't find branch "
200 qWarning() << "CA::continueJob couldn't find model " << modelID;
204 unknownStepWarningFinishJob();
209 if (pageURL.isEmpty()) {
210 qWarning() << "CA::contJob NewPage: pageURL is empty";
214 if (newPageName.isEmpty()) {
215 qWarning() << "CA::contJob NewPage: newPageName is empty";
220 mainWindow->statusMessage(
221 QString("Starting to create Confluence page %1").arg(pageURL));
223 // Check if parent page with url already exists and get pageID, spaceKey
224 startGetPageSourceRequest(pageURL);
228 // Create new page with parent url
229 startCreatePageRequest();
234 pageID = pageObj["id"].toString();
236 // Upload attachments?
237 if (uploadAttachmentPaths.count() > 0) {
238 attachmentsAgent = new ConfluenceAgent;
239 attachmentsAgent->setJobType(ConfluenceAgent::UploadAttachments);
240 attachmentsAgent->pageID = pageID;
241 attachmentsAgent->uploadAttachmentPaths = uploadAttachmentPaths;
243 connect(attachmentsAgent, &ConfluenceAgent::attachmentsSuccess,
244 this, &ConfluenceAgent::attachmentsUploadSuccess);
245 connect(attachmentsAgent, &ConfluenceAgent::attachmentsFailure,
246 this, &ConfluenceAgent::attachmentsUploadFailure);
247 attachmentsAgent->startJob();
250 // Proceed to next step
254 // qDebug() << "CA::finished Created page with ID: " << pageObj["id"].toString();
255 // cout << QJsonDocument(pageObj).toJson(QJsonDocument::Indented).toStdString();
256 model = mainWindow->getModel(modelID);
258 pageURL = QString("https://%1/pages/viewpage.action?pageId=%2")
259 .arg(baseURL).arg(pageObj["id"].toString());
260 QString command = QString("vym.currentMap().exportMap(\"ConfluenceUpdatePage\",\"%1\")")
262 QString dest = QString("Page title: \"%1\"\nUrl: \"%2\"")
263 .arg(pageObj["title"].toString()).arg(pageURL);
264 QString desc = tr("Update existing confluence page");
265 model->setExportLastCommand(command);
266 model->setExportLastDestination(dest);
267 model->setExportLastDescription(desc);
268 mainWindow->updateActions();
271 mainWindow->statusMessage(
272 QString("Created Confluence page %1").arg(pageURL));
278 unknownStepWarningFinishJob();
283 if (pageURL.isEmpty()) {
284 qWarning() << "CA::contJob UpdatePage: pageURL is empty";
289 mainWindow->statusMessage(
290 QString("Starting to update Confluence page %1").arg(pageURL));
292 // Check if page with url already exists and get pageID, spaceKey
293 startGetPageSourceRequest(pageURL);
297 // Get title, which is required by Confluence to update a page
298 startGetPageDetailsRequest();
302 // Upload attachments?
303 if (uploadAttachmentPaths.count() > 0) {
304 attachmentsAgent = new ConfluenceAgent;
305 attachmentsAgent->setJobType(ConfluenceAgent::UploadAttachments);
306 attachmentsAgent->pageID = pageID;
307 attachmentsAgent->uploadAttachmentPaths = uploadAttachmentPaths;
309 connect(attachmentsAgent, &ConfluenceAgent::attachmentsSuccess,
310 this, &ConfluenceAgent::attachmentsUploadSuccess);
311 connect(attachmentsAgent, &ConfluenceAgent::attachmentsFailure,
312 this, &ConfluenceAgent::attachmentsUploadFailure);
313 attachmentsAgent->startJob();
319 // Update page with parent url
320 if (newPageName.isEmpty())
321 newPageName = pageObj["title"].toString();
322 startUpdatePageRequest();
326 //qDebug() << "CA::finished Updated page with ID: " << pageObj["id"].toString();
327 mainWindow->statusMessage(
328 QString("Updated Confluence page %1").arg(pageURL));
330 model = mainWindow->getModel(modelID);
332 pageURL = QString("https://%1/pages/viewpage.action?pageId=%2")
333 .arg(baseURL).arg(pageObj["id"].toString());
334 QString command = QString("vym.currentMap().exportMap(\"ConfluenceUpdatePage\",\"%1\")")
336 QString dest = QString("Page title: \"%1\"\nUrl: \"%2\"").arg(pageObj["title"].toString())
338 QString desc = tr("Update existing confluence page");
339 model->setExportLastCommand(command);
340 model->setExportLastDestination(dest);
341 model->setExportLastDescription(desc);
342 mainWindow->updateActions();
347 unknownStepWarningFinishJob();
352 // qDebug() << "CA:: begin getting UserInfo";
353 startGetUserInfoRequest();
357 QJsonArray array = pageObj["results"].toArray();
362 for (int i = 0; i < array.size(); ++i) {
363 userObj = array[i].toObject();
365 u = userObj["user"].toObject();
366 user.setTitle( userObj["title"].toString());
367 user.setURL( "https://" + baseURL + "/"
368 + "display/~" + u["username"].toString());
369 user.setUserKey( u["userKey"].toString());
370 user.setUserName( u["username"].toString());
371 user.setDisplayName( u["displayName"].toString());
374 emit (foundUsers(userList));
378 unknownStepWarningFinishJob();
381 case UploadAttachments:
384 if (uploadAttachmentPaths.count() <= 0) {
385 qWarning() << "ConfluenceAgent: No attachments to upload!";
386 emit(attachmentsFailure());
391 // Prepare to upload first attachment in list
392 currentUploadAttachmentIndex = 0;
394 // Try to get info for attachments
395 startGetAttachmentsInfoRequest();
399 // Entry point for looping over list of attachments to upload
401 if (currentUploadAttachmentIndex >= uploadAttachmentPaths.count()) {
402 // All uploaded, let's finish uploading
403 emit(attachmentsSuccess());
406 currentAttachmentPath = uploadAttachmentPaths.at(currentUploadAttachmentIndex);
407 currentAttachmentTitle = basename(currentAttachmentPath);
409 // Create attachment with image of map, if required
410 if (attachmentsTitles.count() == 0 ||
411 !attachmentsTitles.contains(currentAttachmentTitle)) {
412 // Create new attachment
413 startCreateAttachmentRequest();
415 // Update existing attachment
416 startUpdateAttachmentRequest();
421 unknownStepWarningFinishJob();
425 qWarning() << "ConfluenceAgent::continueJob unknown jobType " << jobType;
429 void ConfluenceAgent::finishJob()
434 void ConfluenceAgent::unknownStepWarningFinishJob()
436 qWarning() << "CA::contJob unknown step in jobType = "
438 << "jobStep = " << jobStep;
442 void ConfluenceAgent::getUsers(const QString &usrQuery)
444 userQuery = usrQuery;
445 if (usrQuery.contains(QRegExp("\\W+"))) {
446 qWarning() << "ConfluenceAgent::getUsers Forbidden characters in " << usrQuery;
450 setJobType(GetUserInfo);
454 QNetworkRequest ConfluenceAgent::createRequest(const QUrl &url)
456 QNetworkRequest request = QNetworkRequest(url);
460 headerData = QString("Bearer %1").arg(personalAccessToken);
462 QString concatenated = username + ":" + password;
463 QByteArray data = concatenated.toLocal8Bit().toBase64();
464 headerData = "Basic " + data;
466 request.setRawHeader("Authorization", headerData.toLocal8Bit());
471 void ConfluenceAgent::startGetPageSourceRequest(QUrl requestedURL)
473 //qDebug() << "CA::startGetPageSourceRequest " << requestedURL;
474 if (!requestedURL.toString().startsWith("http"))
475 requestedURL.setPath("https://" + requestedURL.path());
477 QUrl url = requestedURL;
479 QNetworkRequest request = createRequest(url);
482 qDebug() << "CA::startGetPageSourceRequest: url = " + request.url().toString();
486 connect(networkManager, &QNetworkAccessManager::finished,
487 this, &ConfluenceAgent::pageSourceReceived);
489 networkManager->get(request);
492 void ConfluenceAgent::pageSourceReceived(QNetworkReply *reply)
494 if (debug) qDebug() << "CA::pageSourceReceived";
497 networkManager->disconnect();
498 reply->deleteLater();
500 QByteArray fullReply = reply->readAll();
501 if (!wasRequestSuccessful(reply, "receive page source", fullReply))
505 QRegExp rx("\\sname=\"ajs-page-id\"\\scontent=\"(\\d*)\"");
508 if (rx.indexIn(fullReply, 0) != -1) {
513 << "ConfluenceAgent::pageSourceReveived Couldn't find page ID";
514 //qWarning() << fullReply;
519 rx.setPattern("meta\\s*id=\"confluence-space-key\"\\s* "
520 "name=\"confluence-space-key\"\\s*content=\"(.*)\"");
521 if (rx.indexIn(fullReply, 0) != -1) {
522 spaceKey = rx.cap(1);
525 qWarning() << "ConfluenceAgent::pageSourceReveived Couldn't find "
526 "space key in response";
527 qWarning() << fullReply;
532 const QVariant redirectionTarget =
533 reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
538 void ConfluenceAgent::startGetPageDetailsRequest()
540 if (debug) qDebug() << "CA::startGetPageDetailsRequest" << pageID;
542 // Authentication in URL (only SSL!)
543 QString url = "https://"
545 + "/content/" + pageID + "?expand=metadata.labels,version";
547 QNetworkRequest request = createRequest(url);
549 connect(networkManager, &QNetworkAccessManager::finished,
550 this, &ConfluenceAgent::pageDetailsReceived);
554 networkManager->get(request);
557 void ConfluenceAgent::pageDetailsReceived(QNetworkReply *reply)
559 if (debug) qDebug() << "CA::pageDetailsReceived";
562 networkManager->disconnect();
563 reply->deleteLater();
565 QByteArray fullReply = reply->readAll();
566 if (!wasRequestSuccessful(reply, "receive page details", fullReply))
570 jsdoc = QJsonDocument::fromJson(fullReply);
572 pageObj = jsdoc.object();
573 // cout << jsdoc.toJson(QJsonDocument::Indented).toStdString();
578 void ConfluenceAgent::startCreatePageRequest()
580 // qDebug() << "CA::startCreatePageRequest";
582 QString url = "https://" + baseURL + apiURL + "/content";
584 QNetworkRequest request = createRequest(url);
585 request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
588 payload["type"] = "page";
589 payload["title"] = newPageName;
591 // Build array with ID of parent page
592 QJsonObject ancestorsID;
593 ancestorsID["id"] = pageID;
594 QJsonArray ancestorsArray;
595 ancestorsArray.append(ancestorsID);
596 payload["ancestors"] = ancestorsArray;
598 // Build object with space key
600 skey["key"] = spaceKey;
601 payload["space"] = skey;
605 if (!loadStringFromDisk(uploadPagePath, body))
607 qWarning() << "ConfluenceAgent: Couldn't read file to upload:" << uploadPagePath;
612 QJsonObject innerStorageObj
615 {"representation", "storage"}
617 QJsonObject outerStorageObj;
618 outerStorageObj["storage"] = innerStorageObj;
619 payload["body"] = outerStorageObj;
621 QJsonDocument doc(payload);
622 QByteArray data = doc.toJson();
624 connect(networkManager, &QNetworkAccessManager::finished,
625 this, &ConfluenceAgent::pageUploaded);
629 networkManager->post(request, data);
632 void ConfluenceAgent::startUpdatePageRequest()
634 if (debug) qDebug() << "CA::startUpdatePageRequest";
636 QString url = "https://" + baseURL + apiURL + "/content" + "/" + pageID;
638 QNetworkRequest request = createRequest(url);
641 QNetworkRequest::ContentTypeHeader,
642 "application/json; charset=utf-8");
645 payload["id"] = pageID;
646 payload["type"] = "page";
647 payload["title"] = newPageName;
649 // Build version object
650 QJsonObject newVersionObj;
651 QJsonObject oldVersionObj = pageObj["version"].toObject();
653 newVersionObj["number"] = oldVersionObj["number"].toInt() + 1;
654 payload["version"] = newVersionObj;
656 // Build object with space key
658 skey["key"] = spaceKey;
659 payload["space"] = skey;
663 if (!loadStringFromDisk(uploadPagePath, body))
665 qWarning() << "ConfluenceAgent: Couldn't read file to upload:" << uploadPagePath;
670 QJsonObject innerStorageObj
673 {"representation", "storage"}
675 QJsonObject outerStorageObj;
676 outerStorageObj["storage"] = innerStorageObj;
677 payload["body"] = outerStorageObj;
679 QJsonDocument doc(payload);
680 QByteArray data = doc.toJson();
682 connect(networkManager, &QNetworkAccessManager::finished,
683 this, &ConfluenceAgent::pageUploaded);
687 networkManager->put(request, data);
690 void ConfluenceAgent::pageUploaded(QNetworkReply *reply)
692 if (debug) qDebug() << "CA::pageUploaded";
695 networkManager->disconnect();
696 reply->deleteLater();
698 QByteArray fullReply = reply->readAll();
699 if (!wasRequestSuccessful(reply, "upload page", fullReply))
703 jsdoc = QJsonDocument::fromJson(fullReply);
704 pageObj = jsdoc.object();
705 // cout << jsdoc.toJson(QJsonDocument::Indented).toStdString();
709 void ConfluenceAgent::startGetUserInfoRequest()
711 if (debug) qDebug() << "CA::startGetInfoRequest for " << userQuery;
713 QString url = "https://" + baseURL + apiURL
714 + "/search?cql=user.fullname~" + userQuery;
716 networkManager->disconnect();
718 QNetworkRequest request = createRequest(url);
720 connect(networkManager, &QNetworkAccessManager::finished,
721 this, &ConfluenceAgent::userInfoReceived);
725 networkManager->get(request);
728 void ConfluenceAgent::userInfoReceived(QNetworkReply *reply)
730 if (debug) qDebug() << "CA::UserInfopageReceived";
733 networkManager->disconnect();
734 reply->deleteLater();
736 QByteArray fullReply = reply->readAll();
737 if (!wasRequestSuccessful(reply, "receive user info", fullReply))
741 jsdoc = QJsonDocument::fromJson(fullReply);
742 pageObj = jsdoc.object();
746 void ConfluenceAgent::startGetAttachmentsInfoRequest()
748 if (debug) qDebug() << "CA::startGetAttachmentIdRequest";
750 QString url = "https://" + baseURL + apiURL + "/content" + "/" + pageID + "/child/attachment";
752 QNetworkRequest request = createRequest(url);
753 request.setRawHeader("X-Atlassian-Token", "no-check");
755 connect(networkManager, &QNetworkAccessManager::finished,
756 this, &ConfluenceAgent::attachmentsInfoReceived);
760 QNetworkReply *reply = networkManager->get(request);
763 void ConfluenceAgent::attachmentsInfoReceived(QNetworkReply *reply)
765 if (debug) qDebug() << "CA::attachmentsInfoReceived";
768 networkManager->disconnect();
769 reply->deleteLater();
771 QByteArray fullReply = reply->readAll();
772 if (!wasRequestSuccessful(reply, "get attachment info", fullReply))
776 jsdoc = QJsonDocument::fromJson(fullReply);
778 attachmentObj = jsdoc.object();
779 int attachmentsCount = jsdoc["size"].toInt();
780 //cout << jsdoc.toJson(QJsonDocument::Indented).toStdString();
781 for (int i = 0; i < attachmentsCount; i++) {
782 attachmentsTitles << jsdoc["results"][i]["title"].toString();
783 attachmentsIds << jsdoc["results"][i]["id"].toString();
784 //qDebug() << " Title: " << attachmentsTitles.last() <<
785 // " Id: " << attachmentsIds.last();
791 void ConfluenceAgent::startCreateAttachmentRequest()
793 if (debug) qDebug() << "CA::startCreateAttachmentRequest";
795 QString url = "https://" + baseURL + apiURL + "/content" + "/" + pageID + "/child/attachment";
797 QNetworkRequest request = createRequest(url);
798 request.setRawHeader("X-Atlassian-Token", "no-check");
800 QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
805 QNetworkRequest::ContentDispositionHeader,
807 // Name must be "file"
809 QString("form-data; name=\"file\"; filename=\"%1\"")
810 .arg(currentAttachmentTitle)));
812 QNetworkRequest::ContentTypeHeader,
813 QVariant("image/jpeg"));
815 QFile *file = new QFile(currentAttachmentPath);
816 if (!file->open(QIODevice::ReadOnly)) {
817 qWarning() << "Problem opening attachment: " << currentAttachmentPath;
818 QMessageBox::warning(
819 nullptr, tr("Warning"),
820 QString("Could not open attachment file \"%1\" in page with ID: %2").arg(currentAttachmentTitle).arg(pageID));
824 imagePart.setBodyDevice(file);
826 qDebug() << " title=" << currentAttachmentTitle;
827 qDebug() << " path=" << currentAttachmentPath;
828 qDebug() << " url=" << url;
829 qDebug() << " file size=" << file->size();
831 multiPart->append(imagePart);
832 file->setParent(multiPart); // delete later with the multiPart
834 connect(networkManager, &QNetworkAccessManager::finished,
835 this, &ConfluenceAgent::attachmentCreated);
839 QNetworkReply *reply = networkManager->post(request, multiPart);
841 multiPart->setParent(reply);
844 void ConfluenceAgent::attachmentCreated(QNetworkReply *reply)
846 if (debug) qDebug() << "CA::attachmentCreated";
849 networkManager->disconnect();
850 reply->deleteLater();
852 QByteArray fullReply = reply->readAll();
853 if (reply->error() == QNetworkReply::ProtocolInvalidOperationError) {
854 if (fullReply.contains(
855 QString("Cannot add a new attachment with same file name as an existing attachment").toLatin1())) {
856 // Replace existing attachment
857 qWarning() << "Attachment with name " << currentAttachmentTitle << " already exists.";
858 qWarning() << "AttachmentID unknown, stopping now";
863 if (!wasRequestSuccessful(reply, "create attachment", fullReply))
868 jsdoc = QJsonDocument::fromJson(fullReply);
869 attachmentObj = jsdoc.object();
871 //qDebug() << "CA::attachmentCreated Successful:";
872 //cout << jsdoc.toJson(QJsonDocument::Indented).toStdString();
873 //cout << attachmentObj["results"].toArray().toStdString();
875 currentUploadAttachmentIndex++;
880 void ConfluenceAgent::startUpdateAttachmentRequest()
882 if (debug) qDebug() << "CA::startUpdateAttachmentRequest";
884 for (int i = 0; i < attachmentsTitles.count(); i++) {
885 // qDebug() << " - " << attachmentsTitles.at(i);
886 if (attachmentsTitles.at(i) == currentAttachmentTitle) {
887 currentAttachmentId = attachmentsIds.at(i);
892 if (currentAttachmentId.isEmpty()) {
893 QMessageBox::warning(
894 nullptr, tr("Warning"),
895 QString("Could not find existing attachment \"%1\" in page with ID: %2").arg(currentAttachmentTitle).arg(pageID));
900 QString url = "https://" + baseURL + apiURL + "/content" + "/" + pageID + "/child/attachment/" + currentAttachmentId + "/data";
902 QNetworkRequest request = createRequest(url);
903 request.setRawHeader("X-Atlassian-Token", "no-check");
905 QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
909 QNetworkRequest::ContentDispositionHeader,
911 // Name must be "file"
913 QString("form-data; name=\"file\"; filename=\"%1\"")
914 .arg(currentAttachmentTitle)));
916 QNetworkRequest::ContentTypeHeader,
917 QVariant("image/jpeg"));
919 QFile *file = new QFile(currentAttachmentPath);
920 if (!file->open(QIODevice::ReadOnly)) {
921 qWarning() << "Problem opening attachment: " << currentAttachmentPath;
922 QMessageBox::warning(
923 nullptr, tr("Warning"),
924 QString("Could not open attachment file \"%1\" in page with ID: %2").arg(currentAttachmentTitle).arg(pageID));
928 imagePart.setBodyDevice(file);
930 qDebug() << " title=" << currentAttachmentTitle;
931 qDebug() << " path=" << currentAttachmentPath;
932 qDebug() << " url=" << url;
933 qDebug() << " file size=" << file->size();
935 multiPart->append(imagePart);
936 file->setParent(multiPart);
938 connect(networkManager, &QNetworkAccessManager::finished,
939 this, &ConfluenceAgent::attachmentUpdated);
943 QNetworkReply *reply = networkManager->post(request, multiPart);
945 multiPart->setParent(reply);
948 void ConfluenceAgent::attachmentUpdated(QNetworkReply *reply)
950 if (debug) qDebug() << "CA::attachmentUpdated";
953 networkManager->disconnect();
954 reply->deleteLater();
956 QByteArray fullReply = reply->readAll();
957 if (!wasRequestSuccessful(reply, "update attachment", fullReply))
961 jsdoc = QJsonDocument::fromJson(fullReply);
962 attachmentObj = jsdoc.object();
964 //cout << jsdoc.toJson(QJsonDocument::Indented).toStdString();
966 currentUploadAttachmentIndex++;
971 void ConfluenceAgent::attachmentsUploadSuccess() // slot called from attachmentsAgent
976 void ConfluenceAgent::attachmentsUploadFailure() // slot called from attachmentsAgent
978 qWarning() << "CA::attachmentsUpload failed";
982 bool ConfluenceAgent::wasRequestSuccessful(QNetworkReply *reply, const QString &requestDesc, const QByteArray &fullReply)
984 if (reply->error()) {
986 // Additionally print full error on console
987 qWarning() << " Step: " << requestDesc;
988 qWarning() << " Error: " << reply->error();
989 qWarning() << " Errorstring: " << reply->errorString();
991 qDebug() << " Request Url: " << reply->url() ;
992 qDebug() << " Operation: " << reply->operation() ;
994 qDebug() << " readAll: ";
996 jsdoc = QJsonDocument::fromJson(fullReply);
997 QString fullReplyFormatted = QString(jsdoc.toJson(QJsonDocument::Indented));
998 cout << fullReplyFormatted.toStdString();
1001 qDebug() << "Request headers: ";
1002 QList<QByteArray> reqHeaders = reply->rawHeaderList();
1003 foreach( QByteArray reqName, reqHeaders )
1005 QByteArray reqValue = reply->rawHeader( reqName );
1006 qDebug() << " " << reqName << ": " << reqValue;
1010 if (reply->error() == QNetworkReply::AuthenticationRequiredError)
1011 QMessageBox::warning(
1012 nullptr, tr("Warning"),
1013 tr("Authentication problem when contacting Confluence") + "\n\n" +
1016 QString msg = QString("QNetworkReply error when trying to \"%1\"\n\n").arg(requestDesc);
1018 warn.setText(msg + "\n\n" + fullReplyFormatted);
1019 warn.showCancelButton(false);
1029 void ConfluenceAgent::timeout()
1031 qWarning() << "ConfluenceAgent timeout!! jobType = " << jobType;
1035 void ConfluenceAgent::sslErrors(QNetworkReply *reply, const QList<QSslError> &errors)
1037 QString errorString;
1038 foreach (const QSslError &error, errors) {
1039 if (!errorString.isEmpty())
1040 errorString += '\n';
1041 errorString += error.errorString();
1044 reply->ignoreSslErrors();
1045 qWarning() << "ConfluenceAgent: One or more SSL errors has occurred: " << errorString;
1046 qWarning() << "Errors ignored.";