##// END OF EJS Templates
CatalogueController: add few basic methods + commit the one not yet implemented
trabillard -
r1161:043d6b3a4bf6
parent child
Show More
@@ -1,67 +1,70
1 #ifndef SCIQLOP_CATALOGUECONTROLLER_H
1 #ifndef SCIQLOP_CATALOGUECONTROLLER_H
2 #define SCIQLOP_CATALOGUECONTROLLER_H
2 #define SCIQLOP_CATALOGUECONTROLLER_H
3
3
4 #include "CoreGlobal.h"
4 #include "CoreGlobal.h"
5
5
6 #include <Data/SqpRange.h>
6 #include <Data/SqpRange.h>
7
7
8 #include <QLoggingCategory>
8 #include <QLoggingCategory>
9 #include <QObject>
9 #include <QObject>
10 #include <QUuid>
10 #include <QUuid>
11
11
12 #include <Common/spimpl.h>
12 #include <Common/spimpl.h>
13
13
14 #include <memory>
14 #include <memory>
15
15
16 class DBCatalogue;
16 class DBCatalogue;
17 class DBEvent;
17 class DBEvent;
18
18
19 Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueController)
19 Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueController)
20
20
21 class DataSourceItem;
21 class DataSourceItem;
22 class Variable;
22 class Variable;
23
23
24 /**
24 /**
25 * @brief The CatalogueController class aims to handle catalogues and event using the CatalogueAPI
25 * @brief The CatalogueController class aims to handle catalogues and event using the CatalogueAPI
26 * library.
26 * library.
27 */
27 */
28 class SCIQLOP_CORE_EXPORT CatalogueController : public QObject {
28 class SCIQLOP_CORE_EXPORT CatalogueController : public QObject {
29 Q_OBJECT
29 Q_OBJECT
30 public:
30 public:
31 explicit CatalogueController(QObject *parent = 0);
31 explicit CatalogueController(QObject *parent = 0);
32 virtual ~CatalogueController();
32 virtual ~CatalogueController();
33
33
34 // DB
34 // DB
35 QStringList getRepositories() const;
35 // QStringList getRepositories() const;
36 void addDB(const QString &dbPath);
36 void addDB(const QString &dbPath);
37 void saveDB(const QString &destinationPath, const QString &repository);
37 void saveDB(const QString &destinationPath, const QString &repository);
38
38
39 // Event
39 // Event
40 bool createEvent(const QString &name);
40 // bool createEvent(const QString &name);
41 std::list<std::shared_ptr<DBEvent> > retrieveEvents(const QString &repository) const;
41 std::list<std::shared_ptr<DBEvent> > retrieveEvents(const QString &repository) const;
42 std::list<std::shared_ptr<DBEvent> > retrieveAllEvents() const;
42 std::list<std::shared_ptr<DBEvent> > retrieveAllEvents() const;
43 void updateEvent(std::shared_ptr<DBEvent> event);
43 std::list<std::shared_ptr<DBEvent> >
44 void trashEvent(std::shared_ptr<DBEvent> event);
44 retrieveEventsFromCatalogue(const QString &repository,
45 void removeEvent(std::shared_ptr<DBEvent> event);
45 std::shared_ptr<DBCatalogue> catalogue) const;
46 void restore(QUuid eventId);
46 // void updateEvent(std::shared_ptr<DBEvent> event);
47 void saveEvent(std::shared_ptr<DBEvent> event);
47 // void trashEvent(std::shared_ptr<DBEvent> event);
48 // void removeEvent(std::shared_ptr<DBEvent> event);
49 // void restore(QUuid eventId);
50 // void saveEvent(std::shared_ptr<DBEvent> event);
48
51
49 // Catalogue
52 // Catalogue
50 bool createCatalogue(const QString &name, QVector<QUuid> eventList);
53 // bool createCatalogue(const QString &name, QVector<QUuid> eventList);
51 void getCatalogues(const QString &repository) const;
54 std::list<std::shared_ptr<DBCatalogue> > getCatalogues(const QString &repository) const;
52 void removeEvent(QUuid catalogueId, const QString &repository);
55 // void removeEvent(QUuid catalogueId, const QString &repository);
53 void saveCatalogue(std::shared_ptr<DBEvent> event);
56 // void saveCatalogue(std::shared_ptr<DBEvent> event);
54
57
55 public slots:
58 public slots:
56 /// Manage init/end of the controller
59 /// Manage init/end of the controller
57 void initialize();
60 void initialize();
58 void finalize();
61 void finalize();
59
62
60 private:
63 private:
61 void waitForFinish();
64 void waitForFinish();
62
65
63 class CatalogueControllerPrivate;
66 class CatalogueControllerPrivate;
64 spimpl::unique_impl_ptr<CatalogueControllerPrivate> impl;
67 spimpl::unique_impl_ptr<CatalogueControllerPrivate> impl;
65 };
68 };
66
69
67 #endif // SCIQLOP_CATALOGUECONTROLLER_H
70 #endif // SCIQLOP_CATALOGUECONTROLLER_H
@@ -1,139 +1,162
1 #include <Catalogue/CatalogueController.h>
1 #include <Catalogue/CatalogueController.h>
2
2
3 #include <Variable/Variable.h>
3 #include <Variable/Variable.h>
4
4
5 #include <CatalogueDao.h>
5 #include <CatalogueDao.h>
6
6
7 #include <ComparaisonPredicate.h>
7 #include <ComparaisonPredicate.h>
8 #include <CompoundPredicate.h>
8 #include <CompoundPredicate.h>
9 #include <DBCatalogue.h>
9 #include <DBCatalogue.h>
10 #include <DBEvent.h>
10 #include <DBEvent.h>
11 #include <DBTag.h>
11 #include <DBTag.h>
12 #include <IRequestPredicate.h>
12 #include <IRequestPredicate.h>
13
13
14 #include <QMutex>
14 #include <QMutex>
15 #include <QThread>
15 #include <QThread>
16
16
17 #include <QDir>
17 #include <QDir>
18 #include <QStandardPaths>
18 #include <QStandardPaths>
19
19
20 Q_LOGGING_CATEGORY(LOG_CatalogueController, "CatalogueController")
20 Q_LOGGING_CATEGORY(LOG_CatalogueController, "CatalogueController")
21
21
22 namespace {
22 namespace {
23
23
24 static QString REPOSITORY_WORK_SUFFIX = QString{"Work"};
24 static QString REPOSITORY_WORK_SUFFIX = QString{"Work"};
25
25
26 }
26 }
27
27
28 class CatalogueController::CatalogueControllerPrivate {
28 class CatalogueController::CatalogueControllerPrivate {
29 public:
29 public:
30 QMutex m_WorkingMutex;
30 QMutex m_WorkingMutex;
31 CatalogueDao m_CatalogueDao;
31 CatalogueDao m_CatalogueDao;
32
32
33 std::list<QString> m_RepositoryList;
33 std::list<QString> m_RepositoryList;
34 };
34 };
35
35
36 CatalogueController::CatalogueController(QObject *parent)
36 CatalogueController::CatalogueController(QObject *parent)
37 : impl{spimpl::make_unique_impl<CatalogueControllerPrivate>()}
37 : impl{spimpl::make_unique_impl<CatalogueControllerPrivate>()}
38 {
38 {
39 qCDebug(LOG_CatalogueController()) << tr("CatalogueController construction")
39 qCDebug(LOG_CatalogueController()) << tr("CatalogueController construction")
40 << QThread::currentThread();
40 << QThread::currentThread();
41 }
41 }
42
42
43 CatalogueController::~CatalogueController()
43 CatalogueController::~CatalogueController()
44 {
44 {
45 qCDebug(LOG_CatalogueController()) << tr("CatalogueController destruction")
45 qCDebug(LOG_CatalogueController()) << tr("CatalogueController destruction")
46 << QThread::currentThread();
46 << QThread::currentThread();
47 this->waitForFinish();
47 this->waitForFinish();
48 }
48 }
49
49
50 void CatalogueController::addDB(const QString &dbPath)
50 void CatalogueController::addDB(const QString &dbPath)
51 {
51 {
52 QDir dbDir(dbPath);
52 QDir dbDir(dbPath);
53 if (dbDir.exists()) {
53 if (dbDir.exists()) {
54 auto dirName = dbDir.dirName();
54 auto dirName = dbDir.dirName();
55
55
56 if (std::find(impl->m_RepositoryList.cbegin(), impl->m_RepositoryList.cend(), dirName)
56 if (std::find(impl->m_RepositoryList.cbegin(), impl->m_RepositoryList.cend(), dirName)
57 != impl->m_RepositoryList.cend()) {
57 != impl->m_RepositoryList.cend()) {
58 qCCritical(LOG_CatalogueController())
58 qCCritical(LOG_CatalogueController())
59 << tr("Impossible to addDB that is already loaded");
59 << tr("Impossible to addDB that is already loaded");
60 }
60 }
61
61
62 if (!impl->m_CatalogueDao.addDB(dbPath, dirName)) {
62 if (!impl->m_CatalogueDao.addDB(dbPath, dirName)) {
63 qCCritical(LOG_CatalogueController())
63 qCCritical(LOG_CatalogueController())
64 << tr("Impossible to addDB %1 from %2 ").arg(dirName, dbPath);
64 << tr("Impossible to addDB %1 from %2 ").arg(dirName, dbPath);
65 }
65 }
66 else {
66 else {
67 impl->m_RepositoryList.push_back(dirName);
67 impl->m_RepositoryList.push_back(dirName);
68 }
68 }
69 }
69 }
70 else {
70 else {
71 qCCritical(LOG_CatalogueController()) << tr("Impossible to addDB that not exists: ")
71 qCCritical(LOG_CatalogueController()) << tr("Impossible to addDB that not exists: ")
72 << dbPath;
72 << dbPath;
73 }
73 }
74 }
74 }
75
75
76 void CatalogueController::saveDB(const QString &destinationPath, const QString &repository)
76 void CatalogueController::saveDB(const QString &destinationPath, const QString &repository)
77 {
77 {
78 if (!impl->m_CatalogueDao.saveDB(destinationPath, repository)) {
78 if (!impl->m_CatalogueDao.saveDB(destinationPath, repository)) {
79 qCCritical(LOG_CatalogueController())
79 qCCritical(LOG_CatalogueController())
80 << tr("Impossible to saveDB %1 from %2 ").arg(repository, destinationPath);
80 << tr("Impossible to saveDB %1 from %2 ").arg(repository, destinationPath);
81 }
81 }
82 }
82 }
83
83
84 std::list<std::shared_ptr<DBEvent> >
84 std::list<std::shared_ptr<DBEvent> >
85 CatalogueController::retrieveEvents(const QString &repository) const
85 CatalogueController::retrieveEvents(const QString &repository) const
86 {
86 {
87 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
87 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
88 auto events = impl->m_CatalogueDao.getEvents(repository);
88 auto events = impl->m_CatalogueDao.getEvents(repository);
89 for (auto event : events) {
89 for (auto event : events) {
90 eventsShared.push_back(std::make_shared<DBEvent>(event));
90 eventsShared.push_back(std::make_shared<DBEvent>(event));
91 }
91 }
92 return eventsShared;
92 return eventsShared;
93 }
93 }
94
94
95 std::list<std::shared_ptr<DBEvent> > CatalogueController::retrieveAllEvents() const
95 std::list<std::shared_ptr<DBEvent> > CatalogueController::retrieveAllEvents() const
96 {
96 {
97 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
97 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
98 for (auto repository : impl->m_RepositoryList) {
98 for (auto repository : impl->m_RepositoryList) {
99 eventsShared.splice(eventsShared.end(), retrieveEvents(repository));
99 eventsShared.splice(eventsShared.end(), retrieveEvents(repository));
100 }
100 }
101
101
102 return eventsShared;
102 return eventsShared;
103 }
103 }
104
104
105 std::list<std::shared_ptr<DBEvent> >
106 CatalogueController::retrieveEventsFromCatalogue(const QString &repository,
107 std::shared_ptr<DBCatalogue> catalogue) const
108 {
109 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
110 auto events = impl->m_CatalogueDao.getCatalogueEvents(*catalogue);
111 for (auto event : events) {
112 eventsShared.push_back(std::make_shared<DBEvent>(event));
113 }
114 return eventsShared;
115 }
116
117 std::list<std::shared_ptr<DBCatalogue> >
118 CatalogueController::getCatalogues(const QString &repository) const
119 {
120 auto cataloguesShared = std::list<std::shared_ptr<DBCatalogue> >{};
121 auto catalogues = impl->m_CatalogueDao.getCatalogues(repository);
122 for (auto catalogue : catalogues) {
123 cataloguesShared.push_back(std::make_shared<DBCatalogue>(catalogue));
124 }
125 return cataloguesShared;
126 }
127
105 void CatalogueController::initialize()
128 void CatalogueController::initialize()
106 {
129 {
107 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init")
130 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init")
108 << QThread::currentThread();
131 << QThread::currentThread();
109 impl->m_WorkingMutex.lock();
132 impl->m_WorkingMutex.lock();
110 impl->m_CatalogueDao.initialize();
133 impl->m_CatalogueDao.initialize();
111 auto defaultRepositoryLocation
134 auto defaultRepositoryLocation
112 = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
135 = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
113
136
114 QDir defaultRepositoryLocationDir;
137 QDir defaultRepositoryLocationDir;
115 if (defaultRepositoryLocationDir.mkpath(defaultRepositoryLocation)) {
138 if (defaultRepositoryLocationDir.mkpath(defaultRepositoryLocation)) {
116 defaultRepositoryLocationDir.cd(defaultRepositoryLocation);
139 defaultRepositoryLocationDir.cd(defaultRepositoryLocation);
117 auto defaultRepository = defaultRepositoryLocationDir.absoluteFilePath(REPOSITORY_DEFAULT);
140 auto defaultRepository = defaultRepositoryLocationDir.absoluteFilePath(REPOSITORY_DEFAULT);
118 qCInfo(LOG_CatalogueController())
141 qCInfo(LOG_CatalogueController())
119 << tr("Persistant data loading from: ") << defaultRepository;
142 << tr("Persistant data loading from: ") << defaultRepository;
120 this->addDB(defaultRepository);
143 this->addDB(defaultRepository);
121 }
144 }
122 else {
145 else {
123 qCWarning(LOG_CatalogueController())
146 qCWarning(LOG_CatalogueController())
124 << tr("Cannot load the persistent default repository from ")
147 << tr("Cannot load the persistent default repository from ")
125 << defaultRepositoryLocation;
148 << defaultRepositoryLocation;
126 }
149 }
127
150
128 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END");
151 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END");
129 }
152 }
130
153
131 void CatalogueController::finalize()
154 void CatalogueController::finalize()
132 {
155 {
133 impl->m_WorkingMutex.unlock();
156 impl->m_WorkingMutex.unlock();
134 }
157 }
135
158
136 void CatalogueController::waitForFinish()
159 void CatalogueController::waitForFinish()
137 {
160 {
138 QMutexLocker locker{&impl->m_WorkingMutex};
161 QMutexLocker locker{&impl->m_WorkingMutex};
139 }
162 }
General Comments 3
Under Review
author

Auto status change to "Under Review"

Approved

Status change > Approved

You need to be logged in to leave comments. Login now