MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / workspaceResolve

Method workspaceResolve

app/src/API/Handlers/AssistantHandler.cpp:148–208  ·  view source on GitHub ↗

* @brief Resolve a workspace by id (workspaceId) or case-insensitive title (workspace). */

Source from the content-addressed store, hash-verified

146 * @brief Resolve a workspace by id (workspaceId) or case-insensitive title (workspace).
147 */
148API::CommandResponse API::Handlers::AssistantHandler::workspaceResolve(const QString& id,
149 const QJsonObject& params)
150{
151 const bool hasId = params.contains(QStringLiteral("workspaceId"));
152 const bool hasTitle = params.contains(QStringLiteral("workspace"));
153 if (!hasId && !hasTitle)
154 return CommandResponse::makeError(
155 id,
156 ErrorCode::MissingParam,
157 QStringLiteral("Provide one of: workspaceId (integer) or workspace (title)."));
158
159 const auto listResp =
160 forward(QStringLiteral("project.workspace.list"), QStringLiteral("inner"), QJsonObject());
161 if (!listResp.success)
162 return rewrap(id, listResp);
163
164 const auto workspaces = workspacesFromListResponse(listResp);
165
166 QJsonArray matches;
167 if (hasId) {
168 const int wid = params.value(QStringLiteral("workspaceId")).toInt();
169 for (const auto& v : workspaces) {
170 const auto ws = v.toObject();
171 if (ws.value(QStringLiteral("id")).toInt() == wid)
172 matches.append(ws);
173 }
174 } else {
175 const auto needle = params.value(QStringLiteral("workspace")).toString();
176 for (const auto& v : workspaces) {
177 const auto ws = v.toObject();
178 if (ws.value(QStringLiteral("title")).toString().compare(needle, Qt::CaseInsensitive) == 0)
179 matches.append(ws);
180 }
181 }
182
183 if (matches.isEmpty()) {
184 QJsonObject data;
185 data[QStringLiteral("candidates")] = workspaces;
186 return CommandResponse::makeError(
187 id,
188 ErrorCode::InvalidParam,
189 QStringLiteral("No workspace matched. Pick one from data.candidates by id or title."),
190 data);
191 }
192
193 if (matches.size() > 1) {
194 QJsonObject data;
195 data[QStringLiteral("matches")] = matches;
196 return CommandResponse::makeError(
197 id,
198 ErrorCode::InvalidParam,
199 QStringLiteral("Ambiguous match (%1 workspaces share that title). "
200 "Re-call with workspaceId.")
201 .arg(matches.size()),
202 data);
203 }
204
205 QJsonObject result;

Callers

nothing calls this directly

Calls 11

forwardFunction · 0.85
QJsonObjectClass · 0.85
rewrapFunction · 0.85
isEmptyMethod · 0.80
firstMethod · 0.80
containsMethod · 0.45
valueMethod · 0.45
appendMethod · 0.45
compareMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected