Skip to content

Commit 4dd9703

Browse files
authored
Add MoveRowsCommand to query (#66)
- Add MoveRowsCommand to query - Add optional auditBehavior and auditUserComment to SaveRowsCommand
1 parent 31b2ebd commit 4dd9703

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
## version 6.1.0-SNAPSHOT
44
*Released*: TBD
55
* [Issue 49238](https://www.labkey.org/home/Developer/issues/issues-details.view?issueId=49238): Fix so all command responses correctly decode as UTF-8.
6+
* Add MoveRowsCommand to query
7+
* Earliest compatible LabKey Server version: 24.1.0
68

79
## version 6.0.0
810
*Released*: 1 December 2023
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2023 LabKey Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.labkey.remoteapi.query;
17+
18+
import org.json.JSONObject;
19+
20+
/**
21+
* Command for moving rows from a compatible schema table. The user associated
22+
* with the connection used when executing this command must have
23+
* permission to update data for the source container and insert data
24+
* for the target container.
25+
*/
26+
public class MoveRowsCommand extends SaveRowsCommand
27+
{
28+
private final String _targetContainerPath;
29+
30+
/**
31+
* Constructs a MoveRowsCommand for the given targetContainerPath, schemaName, and queryName.
32+
* See the {@link SaveRowsCommand} for more details.
33+
* @param targetContainerPath The targetContainerPath
34+
* @param schemaName The schemaName
35+
* @param queryName The queryName.
36+
* @see SaveRowsCommand
37+
*/
38+
public MoveRowsCommand(String targetContainerPath, String schemaName, String queryName)
39+
{
40+
super(schemaName, queryName, "moveRows");
41+
_targetContainerPath = targetContainerPath;
42+
}
43+
44+
@Override
45+
public JSONObject getJsonObject()
46+
{
47+
final JSONObject jsonObject = super.getJsonObject();
48+
jsonObject.put("targetContainerPath", _targetContainerPath);
49+
return jsonObject;
50+
}
51+
}

src/org/labkey/remoteapi/query/SaveRowsCommand.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,19 @@
8383
*/
8484
public abstract class SaveRowsCommand extends PostCommand<SaveRowsResponse>
8585
{
86+
public enum AuditBehavior
87+
{
88+
NONE,
89+
SUMMARY,
90+
DETAILED
91+
}
92+
8693
private String _schemaName;
8794
private String _queryName;
8895
private Map<String, Object> _extraContext;
8996
private List<Map<String, Object>> _rows = new ArrayList<>();
97+
private AuditBehavior _auditBehavior;
98+
private String _auditUserComment;
9099

91100
/**
92101
* Constructs a new SaveRowsCommand for a given schema, query and action name.
@@ -185,6 +194,36 @@ public void addRow(Map<String, Object> row)
185194
_rows.add(row);
186195
}
187196

197+
public AuditBehavior getAuditBehavior()
198+
{
199+
return _auditBehavior;
200+
}
201+
202+
/**
203+
* Used to override the audit behavior for the schema/query.
204+
* Note that any audit behavior type that is configured via an XML file for the given schema/query
205+
* will take precedence over this value. See TableInfo.getAuditBehavior() for more details.
206+
* @param auditBehavior Valid values include "NONE", "SUMMARY", and "DETAILED"
207+
*/
208+
public void setAuditBehavior(AuditBehavior auditBehavior)
209+
{
210+
_auditBehavior = auditBehavior;
211+
}
212+
213+
public String getAuditUserComment()
214+
{
215+
return _auditUserComment;
216+
}
217+
218+
/**
219+
* Used to provide a comment that will be attached to certain detailed audit log records
220+
* @param auditUserComment The comment to attach to the detailed audit log records
221+
*/
222+
public void setAuditUserComment(String auditUserComment)
223+
{
224+
_auditUserComment = auditUserComment;
225+
}
226+
188227
/**
189228
* Dynamically builds the JSON object to send based on the current
190229
* schema name, query name and rows list.
@@ -198,6 +237,10 @@ public JSONObject getJsonObject()
198237
json.put("queryName", getQueryName());
199238
if (getExtraContext() != null)
200239
json.put("extraContext", getExtraContext());
240+
if (getAuditBehavior() != null)
241+
json.put("auditBehavior", getAuditBehavior());
242+
if (getAuditUserComment() != null)
243+
json.put("auditUserComment", getAuditUserComment());
201244

202245
//unfortunately, JSON simple is so simple that it doesn't
203246
//encode maps into JSON objects on the fly,

0 commit comments

Comments
 (0)