Skip to content

Commit 80c0352

Browse files
committed
Extend BaseRowsCommand
1 parent d38954d commit 80c0352

File tree

1 file changed

+41
-69
lines changed

1 file changed

+41
-69
lines changed

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

Lines changed: 41 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package org.labkey.remoteapi.query;
22

33
import org.json.JSONObject;
4+
import org.labkey.remoteapi.CommandException;
5+
import org.labkey.remoteapi.Connection;
46
import org.labkey.remoteapi.PostCommand;
57

8+
import java.io.IOException;
69
import java.util.ArrayList;
710
import java.util.List;
811
import java.util.Map;
@@ -153,136 +156,105 @@ public enum CommandType
153156
Delete
154157
}
155158

156-
public static class Command
159+
public static class Command extends BaseRowsCommand
157160
{
158-
BaseRowsCommand.AuditBehavior _auditBehavior;
159-
String _auditUserComment;
160161
final CommandType _commandType;
161162
String _containerPath;
162-
Map<String, Object> _extraContext;
163-
List<Map<String, Object>> _rows;
164-
final String _queryName;
165-
final String _schemaName;
166163
Boolean _skipReselectRows;
167164

168165
public Command(CommandType commandType, String schemaName, String queryName, List<Map<String, Object>> rows)
169166
{
167+
super(schemaName, queryName, null);
170168
assert null != commandType;
171-
assert null != schemaName && !schemaName.isEmpty();
172-
assert null != queryName && !queryName.isEmpty();
173-
174169
_commandType = commandType;
175-
_schemaName = schemaName;
176-
_queryName = queryName;
177-
_rows = rows;
170+
setRows(rows);
178171
}
179172

180173
public JSONObject getJsonObject()
181174
{
182-
JSONObject json = new JSONObject();
183-
175+
JSONObject json = super.getJsonObject();
184176
json.put("command", getCommandType().name().toLowerCase());
185-
json.put("schemaName", getSchemaName());
186-
json.put("queryName", getQueryName());
187-
json.put("rows", getRows());
188-
189-
if (getAuditBehavior() != null)
190-
json.put("auditBehavior", getAuditBehavior());
191-
192-
if (getAuditUserComment() != null && !getAuditUserComment().isEmpty())
193-
json.put("auditUserComment", getAuditUserComment());
194177

195178
if (getContainerPath() != null && !getContainerPath().isEmpty())
196179
json.put("containerPath", getContainerPath());
197180

198-
if (getExtraContext() != null && !getExtraContext().isEmpty())
199-
json.put("extraContext", getExtraContext());
200-
201181
if (isSkipReselectRows() != null)
202182
json.put("skipReselectRows", isSkipReselectRows());
203183

204184
return json;
205185
}
206186

207-
public BaseRowsCommand.AuditBehavior getAuditBehavior()
208-
{
209-
return _auditBehavior;
210-
}
211-
212-
public Command setAuditBehavior(BaseRowsCommand.AuditBehavior auditBehavior)
213-
{
214-
_auditBehavior = auditBehavior;
215-
return this;
216-
}
217-
218-
public String getAuditUserComment()
187+
public CommandType getCommandType()
219188
{
220-
return _auditUserComment;
189+
return _commandType;
221190
}
222191

223-
public Command setAuditUserComment(String auditUserComment)
192+
public String getContainerPath()
224193
{
225-
_auditUserComment = auditUserComment;
226-
return this;
194+
return _containerPath;
227195
}
228196

229-
public CommandType getCommandType()
197+
public void setContainerPath(String containerPath)
230198
{
231-
return _commandType;
199+
_containerPath = containerPath;
232200
}
233201

234-
public String getContainerPath()
202+
public Boolean isSkipReselectRows()
235203
{
236-
return _containerPath;
204+
return _skipReselectRows;
237205
}
238206

239-
public Command setContainerPath(String containerPath)
207+
public void setSkipReselectRows(Boolean skipReselectRows)
240208
{
241-
_containerPath = containerPath;
242-
return this;
209+
_skipReselectRows = skipReselectRows;
243210
}
244211

245-
public Map<String, Object> getExtraContext()
212+
@Override
213+
public String getActionName()
246214
{
247-
return _extraContext;
215+
throw new UnsupportedOperationException(unsupportedMethodMessage());
248216
}
249217

250-
public Command setExtraContext(Map<String, Object> extraContext)
218+
@Override
219+
public String getControllerName()
251220
{
252-
_extraContext = extraContext;
253-
return this;
221+
throw new UnsupportedOperationException(unsupportedMethodMessage());
254222
}
255223

256-
public String getQueryName()
224+
@Override
225+
public RowsResponse execute(Connection connection, String folderPath) throws IOException, CommandException
257226
{
258-
return _queryName;
227+
throw new UnsupportedOperationException(unsupportedMethodMessage());
259228
}
260229

261-
public String getSchemaName()
230+
@Override
231+
public double getRequiredVersion()
262232
{
263-
return _schemaName;
233+
throw new UnsupportedOperationException(unsupportedMethodMessage());
264234
}
265235

266-
public List<Map<String, Object>> getRows()
236+
@Override
237+
public void setRequiredVersion(double requiredVersion)
267238
{
268-
return _rows;
239+
throw new UnsupportedOperationException(unsupportedMethodMessage());
269240
}
270241

271-
public Command setRows(List<Map<String, Object>> rows)
242+
@Override
243+
public Integer getTimeout()
272244
{
273-
_rows = rows;
274-
return this;
245+
throw new UnsupportedOperationException(unsupportedMethodMessage());
275246
}
276247

277-
public Boolean isSkipReselectRows()
248+
@Override
249+
public void setTimeout(Integer timeout)
278250
{
279-
return _skipReselectRows;
251+
throw new UnsupportedOperationException(unsupportedMethodMessage());
280252
}
281253

282-
public Command setSkipReselectRows(Boolean skipReselectRows)
254+
private String unsupportedMethodMessage()
283255
{
284-
_skipReselectRows = skipReselectRows;
285-
return this;
256+
// "Command does not support methodName()."
257+
return Command.class.getSimpleName() + " does not support " + new Throwable().getStackTrace()[1].getMethodName() + "().";
286258
}
287259
}
288260
}

0 commit comments

Comments
 (0)