Skip to content

Commit

Permalink
#1083 Correct handling of create/drop of databases and collections.
Browse files Browse the repository at this point in the history
  • Loading branch information
schetnikovich committed Apr 28, 2016
1 parent 8cedcc5 commit 866828c
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 4 deletions.
15 changes: 15 additions & 0 deletions src/robomongo/core/domain/MongoDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,19 @@ namespace Robomongo
{
_collections.push_back(collection);
}

void MongoDatabase::handle(CreateCollectionResponse *event) {
genericResponseHandler(event, "Failed to create collection.");
}

void MongoDatabase::handle(DropCollectionResponse *event) {
genericResponseHandler(event, "Failed to drop collection.");
}

void MongoDatabase::genericResponseHandler(Event *event, const std::string &userFriendlyMessage) {
if (!event->isError())
return;

_bus->publish(new OperationFailedEvent(this, event->error().errorMessage(), userFriendlyMessage));
}
}
3 changes: 3 additions & 0 deletions src/robomongo/core/domain/MongoDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,13 @@ namespace Robomongo
void handle(LoadUsersResponse *event);
void handle(LoadFunctionsResponse *event);
void handle(CreateUserResponse *event);
void handle(CreateCollectionResponse *event);
void handle(DropCollectionResponse *event);

private:
void clearCollections();
void addCollection(MongoCollection *collection);
void genericResponseHandler(Event *event, const std::string &userFriendlyMessage);

private:
MongoServer *_server;
Expand Down
15 changes: 15 additions & 0 deletions src/robomongo/core/domain/MongoServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,19 @@ namespace Robomongo {
AppRegistry::instance().settingsManager()->mongoTimeoutSec(),
AppRegistry::instance().settingsManager()->shellTimeoutSec());
}

void MongoServer::handle(CreateDatabaseResponse *event) {
genericResponseHandler(event, "Failed to create database.");
}

void MongoServer::handle(DropDatabaseResponse *event) {
genericResponseHandler(event, "Failed to drop database.");
}

void MongoServer::genericResponseHandler(Event *event, const std::string &userFriendlyMessage) {
if (!event->isError())
return;

_bus->publish(new OperationFailedEvent(this, event->error().errorMessage(), userFriendlyMessage));
}
}
11 changes: 9 additions & 2 deletions src/robomongo/core/domain/MongoServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ namespace Robomongo
{
class MongoWorker;
class MongoDatabase;
class EventBus;
class App;

// Messages
class EstablishConnectionResponse;
class LoadDatabaseNamesResponse;
class InsertDocumentResponse;
class EventBus;
class App;
class CreateDatabaseResponse;
class DropDatabaseResponse;

/**
* @brief MongoServer represents active connection to MongoDB server.
Expand Down Expand Up @@ -71,10 +75,13 @@ namespace Robomongo
void handle(LoadDatabaseNamesResponse *event);
void handle(InsertDocumentResponse *event);
void handle(RemoveDocumentResponse *event);
void handle(CreateDatabaseResponse *event);
void handle(DropDatabaseResponse *event);

private:
void clearDatabases();
void addDatabase(MongoDatabase *database);
void genericResponseHandler(Event *event, const std::string &userFriendlyMessage);

MongoWorker *_client;
ConnectionSettings *_settings;
Expand Down
1 change: 1 addition & 0 deletions src/robomongo/core/events/MongoEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ namespace Robomongo
R_REGISTER_EVENT(ListenSshConnectionResponse)
R_REGISTER_EVENT(LogEvent)
R_REGISTER_EVENT(StopScriptRequest)
R_REGISTER_EVENT(OperationFailedEvent)
}
14 changes: 14 additions & 0 deletions src/robomongo/core/events/MongoEvents.h
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,20 @@ namespace Robomongo
Event(sender) { }
};

class OperationFailedEvent : public Event
{
R_EVENT

public:
OperationFailedEvent(QObject *sender, const std::string &technicalErrorMessage, const std::string &userFriendlyErrorMessage) :
technicalErrorMessage(technicalErrorMessage),
userFriendlyErrorMessage(userFriendlyErrorMessage),
Event(sender) { }

std::string technicalErrorMessage;
std::string userFriendlyErrorMessage;
};

class QueryWidgetUpdatedEvent : public Event
{
R_EVENT
Expand Down
2 changes: 1 addition & 1 deletion src/robomongo/core/mongodb/MongoWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ namespace Robomongo
{
try {
boost::scoped_ptr<MongoClient> client(getClient());
client->createCollection(event->getNs().toString(), event->getSize(), event->getCapped(),
client->createCollection(event->getNs().toString(), event->getSize(), event->getCapped(),
event->getMaxDocNum(), event->getExtraOptions());
client->done();

Expand Down
10 changes: 10 additions & 0 deletions src/robomongo/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ namespace Robomongo
AppRegistry::instance().bus()->subscribe(this, ScriptExecutedEvent::Type);
AppRegistry::instance().bus()->subscribe(this, ScriptExecutingEvent::Type);
AppRegistry::instance().bus()->subscribe(this, QueryWidgetUpdatedEvent::Type);
AppRegistry::instance().bus()->subscribe(this, OperationFailedEvent::Type);
}

void MainWindow::createStylesMenu()
Expand Down Expand Up @@ -921,6 +922,15 @@ namespace Robomongo
_executeAction->setDisabled(false);
}

void MainWindow::handle(OperationFailedEvent *event)
{
std::stringstream ss;
ss << event->userFriendlyErrorMessage << std::endl << std::endl
<< "Error:" << std::endl << event->technicalErrorMessage;

QMessageBox::information(NULL, "Operation failed", QtUtils::toQString(ss.str()));
}

void MainWindow::handle(QueryWidgetUpdatedEvent *event)
{
_orientationAction->setEnabled(event->numOfResults() > 1);
Expand Down
3 changes: 3 additions & 0 deletions src/robomongo/gui/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ namespace Robomongo
class ConnectionFailedEvent;
class ScriptExecutingEvent;
class ScriptExecutedEvent;
class OperationFailedEvent;

class QueryWidgetUpdatedEvent;
class WorkAreaTabWidget;
class ConnectionMenu;
Expand Down Expand Up @@ -66,6 +68,7 @@ namespace Robomongo
void handle(ScriptExecutingEvent *event);
void handle(ScriptExecutedEvent *event);
void handle(QueryWidgetUpdatedEvent *event);
void handle(OperationFailedEvent *event);
private Q_SLOTS:
void updateMenus();
void setUtcTimeZone();
Expand Down
2 changes: 1 addition & 1 deletion src/robomongo/gui/dialogs/CreateCollectionDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace Robomongo
CreateCollectionDialog::CreateCollectionDialog(const QString &serverName, double dbVersion, const std::string& storageEngine,
const QString &database, const QString &collection, QWidget *parent) :
QDialog(parent), _dbVersion(dbVersion), _storageEngine(storageEngine),
_activeFrame(_storageEngineFrame), _activeObj(&_storageEngineObj)
_activeFrame(NULL), _activeObj(&_storageEngineObj)
{
setWindowTitle(tr("Create Collection"));
setMinimumWidth(300);
Expand Down

0 comments on commit 866828c

Please sign in to comment.