summaryrefslogtreecommitdiffstats
path: root/sinksh/syntax_modules
diff options
context:
space:
mode:
Diffstat (limited to 'sinksh/syntax_modules')
-rw-r--r--sinksh/syntax_modules/sink_create.cpp53
1 files changed, 46 insertions, 7 deletions
diff --git a/sinksh/syntax_modules/sink_create.cpp b/sinksh/syntax_modules/sink_create.cpp
index cd2cd80..1411b2e 100644
--- a/sinksh/syntax_modules/sink_create.cpp
+++ b/sinksh/syntax_modules/sink_create.cpp
@@ -36,6 +36,8 @@
36#include "state.h" 36#include "state.h"
37#include "syntaxtree.h" 37#include "syntaxtree.h"
38 38
39using namespace Sink;
40
39namespace SinkCreate 41namespace SinkCreate
40{ 42{
41 43
@@ -54,7 +56,7 @@ bool create(const QStringList &allArgs, State &state)
54 auto args = allArgs; 56 auto args = allArgs;
55 auto type = args.takeFirst(); 57 auto type = args.takeFirst();
56 auto &store = SinkshUtils::getStore(type); 58 auto &store = SinkshUtils::getStore(type);
57 Sink::ApplicationDomain::ApplicationDomainType::Ptr object; 59 ApplicationDomain::ApplicationDomainType::Ptr object;
58 auto resource = args.takeFirst().toLatin1(); 60 auto resource = args.takeFirst().toLatin1();
59 object = store.getObject(resource); 61 object = store.getObject(resource);
60 62
@@ -67,7 +69,7 @@ bool create(const QStringList &allArgs, State &state)
67 result.waitForFinished(); 69 result.waitForFinished();
68 if (result.errorCode()) { 70 if (result.errorCode()) {
69 state.printError(QObject::tr("An error occurred while creating the entity: %1").arg(result.errorMessage()), 71 state.printError(QObject::tr("An error occurred while creating the entity: %1").arg(result.errorMessage()),
70 "akonaid_create_e" + QString::number(result.errorCode())); 72 "sink_create_e" + QString::number(result.errorCode()));
71 } 73 }
72 74
73 return true; 75 return true;
@@ -83,19 +85,55 @@ bool resource(const QStringList &args, State &state)
83 auto &store = SinkshUtils::getStore("resource"); 85 auto &store = SinkshUtils::getStore("resource");
84 86
85 auto resourceType = args.at(0); 87 auto resourceType = args.at(0);
86 Sink::ApplicationDomain::ApplicationDomainType::Ptr object = store.getObject("");
87 object->setProperty("type", resourceType);
88 88
89 auto map = SinkshUtils::keyValueMapFromArgs(args); 89 auto map = SinkshUtils::keyValueMapFromArgs(args);
90
91 auto identifier = map.take("identifier").toLatin1();
92
93 auto object = ApplicationDomain::ApplicationDomainType::createEntity<ApplicationDomain::SinkResource>("", identifier);
94 object.setResourceType(resourceType);
95
90 for (auto i = map.begin(); i != map.end(); ++i) { 96 for (auto i = map.begin(); i != map.end(); ++i) {
91 object->setProperty(i.key().toLatin1(), i.value()); 97 object.setProperty(i.key().toLatin1(), i.value());
92 } 98 }
93 99
94 auto result = store.create(*object).exec(); 100 auto result = store.create(object).exec();
101 result.waitForFinished();
102 if (result.errorCode()) {
103 state.printError(QObject::tr("An error occurred while creating the entity: %1").arg(result.errorMessage()),
104 "sink_create_e" + QString::number(result.errorCode()));
105 }
106
107 return true;
108}
109
110bool account(const QStringList &args, State &state)
111{
112 if (args.isEmpty()) {
113 state.printError(QObject::tr("An account can not be created without a type"), "sinkcreate/01");
114 return false;
115 }
116
117 auto &store = SinkshUtils::getStore("account");
118
119 auto type = args.at(0);
120
121 auto map = SinkshUtils::keyValueMapFromArgs(args);
122
123 auto identifier = map.take("identifier").toLatin1();
124
125 auto object = ApplicationDomain::ApplicationDomainType::createEntity<ApplicationDomain::SinkAccount>("", identifier);
126 object.setAccountType(type);
127
128 for (auto i = map.begin(); i != map.end(); ++i) {
129 object.setProperty(i.key().toLatin1(), i.value());
130 }
131
132 auto result = store.create(object).exec();
95 result.waitForFinished(); 133 result.waitForFinished();
96 if (result.errorCode()) { 134 if (result.errorCode()) {
97 state.printError(QObject::tr("An error occurred while creating the entity: %1").arg(result.errorMessage()), 135 state.printError(QObject::tr("An error occurred while creating the entity: %1").arg(result.errorMessage()),
98 "akonaid_create_e" + QString::number(result.errorCode())); 136 "sink_create_e" + QString::number(result.errorCode()));
99 } 137 }
100 138
101 return true; 139 return true;
@@ -108,6 +146,7 @@ Syntax::List syntax()
108 146
109 Syntax create("create", QObject::tr("Create items in a resource"), &SinkCreate::create); 147 Syntax create("create", QObject::tr("Create items in a resource"), &SinkCreate::create);
110 create.children << Syntax("resource", QObject::tr("Creates a new resource"), &SinkCreate::resource); 148 create.children << Syntax("resource", QObject::tr("Creates a new resource"), &SinkCreate::resource);
149 create.children << Syntax("account", QObject::tr("Creates a new account"), &SinkCreate::account);
111 150
112 syntax << create; 151 syntax << create;
113 return syntax; 152 return syntax;