Skip to content

Commit

Permalink
feat(manager): support PerformClassAction
Browse files Browse the repository at this point in the history
  • Loading branch information
zexi committed Oct 26, 2023
1 parent d7f2cda commit 8a1f956
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.yunionyun.mcp</groupId>
<artifactId>mcclient</artifactId>
<version>3.2.4</version>
<version>3.2.5</version>
<packaging>jar</packaging>

<name>${project.groupId}:${project.artifactId}</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,23 @@ protected StringBuilder getContextPath(ManagerContext[] ctx) {
}

private JSONObject genBody(JSONObject params) {
return this.genBody(params, this.keyword);
}

private JSONObject genBody(JSONObject params, String key) {
if (params != null) {
JSONObject body = new JSONObject();
body.put(this.keyword, params);
body.put(key, params);
return body;
} else {
return null;
}
}

private JSONObject genPluralBody(JSONObject params) {
return this.genBody(params, this.keywordPlural);
}

public JSONObject GetByName(Session s, String name, JSONObject query, ManagerContext[] ctx)
throws McClientJavaBizException, IOException, JSONClientException {
JSONObject query2 = new JSONObject();
Expand Down Expand Up @@ -255,6 +263,18 @@ public JSONObject PerformAction(Session s, String id, String action, JSONObject
return this.PerformAction(s, id, action, params, new ManagerContext[]{});
}

public JSONObject PerformClassAction(Session s, String action, JSONObject params, ManagerContext[] ctx) throws McClientJavaBizException, IOException, JSONClientException {
StringBuilder url = this.getContextPath(ctx);
url.append(this.urlKey());
url.append("/");
url.append(action);
return this._post(s, url.toString(), genPluralBody(params), this.keyword);
}

public JSONObject PerformClassAction(Session s, String action, JSONObject params) throws McClientJavaBizException, IOException, JSONClientException {
return this.PerformClassAction(s, action, params, new ManagerContext[]{});
}

public JSONObject Update(Session s, String id, JSONObject params, ManagerContext[] ctx)
throws McClientJavaBizException, IOException, JSONClientException {
StringBuilder url = this.getContextPath(ctx);
Expand Down

0 comments on commit 8a1f956

Please sign in to comment.