|
1 | 1 | package org.labkey.remoteapi.query; |
2 | 2 |
|
3 | 3 | import org.json.JSONObject; |
4 | | -import org.labkey.remoteapi.CommandException; |
5 | | -import org.labkey.remoteapi.Connection; |
6 | 4 | import org.labkey.remoteapi.PostCommand; |
7 | 5 |
|
8 | | -import java.io.IOException; |
9 | 6 | import java.util.ArrayList; |
10 | 7 | import java.util.List; |
11 | 8 | import java.util.Map; |
|
49 | 46 | * ))); |
50 | 47 | * updateCmd.setAuditBehavior(SaveRowsCommand.AuditBehavior.DETAILED); |
51 | 48 | * updateCmd.setAuditUserComment("Updated promoter region coordinates based on new assembly"); |
52 | | - * saveCmd.addCommand(updateCmd); |
| 49 | + * saveCmd.addCommands(updateCmd); |
53 | 50 | * |
54 | 51 | * // Delete obsolete annotation |
55 | 52 | * saveCmd.addCommand(new Command(CommandType.Delete, "genome", "GeneAnnotations", |
@@ -156,105 +153,136 @@ public enum CommandType |
156 | 153 | Delete |
157 | 154 | } |
158 | 155 |
|
159 | | - public static class Command extends BaseRowsCommand |
| 156 | + // N.B. You may be inclined to have this share implementation with BaseRowsCommand; however, I would caution |
| 157 | + // against doing so. This class does not represent a command like a PostCommand or a GetCommand but rather |
| 158 | + // aligns with the "commands" made on a request to the save rows endpoint. |
| 159 | + public static class Command |
160 | 160 | { |
| 161 | + BaseRowsCommand.AuditBehavior _auditBehavior; |
| 162 | + String _auditUserComment; |
161 | 163 | final CommandType _commandType; |
162 | 164 | String _containerPath; |
| 165 | + Map<String, Object> _extraContext; |
| 166 | + List<Map<String, Object>> _rows; |
| 167 | + final String _queryName; |
| 168 | + final String _schemaName; |
163 | 169 | Boolean _skipReselectRows; |
164 | 170 |
|
165 | 171 | public Command(CommandType commandType, String schemaName, String queryName, List<Map<String, Object>> rows) |
166 | 172 | { |
167 | | - super(schemaName, queryName, null); |
168 | 173 | assert null != commandType; |
| 174 | + assert null != schemaName && !schemaName.isEmpty(); |
| 175 | + assert null != queryName && !queryName.isEmpty(); |
| 176 | + |
169 | 177 | _commandType = commandType; |
170 | | - setRows(rows); |
| 178 | + _schemaName = schemaName; |
| 179 | + _queryName = queryName; |
| 180 | + _rows = rows; |
171 | 181 | } |
172 | 182 |
|
173 | 183 | public JSONObject getJsonObject() |
174 | 184 | { |
175 | | - JSONObject json = super.getJsonObject(); |
| 185 | + JSONObject json = new JSONObject(); |
| 186 | + |
176 | 187 | json.put("command", getCommandType().name().toLowerCase()); |
| 188 | + json.put("schemaName", getSchemaName()); |
| 189 | + json.put("queryName", getQueryName()); |
| 190 | + json.put("rows", BaseRowsCommand.rowsToJson(getRows())); |
| 191 | + |
| 192 | + if (getAuditBehavior() != null) |
| 193 | + json.put("auditBehavior", getAuditBehavior()); |
| 194 | + |
| 195 | + BaseRowsCommand.stringToJson(json, "auditUserComment", getAuditUserComment()); |
| 196 | + BaseRowsCommand.stringToJson(json, "containerPath", getContainerPath()); |
177 | 197 |
|
178 | | - if (getContainerPath() != null && !getContainerPath().isEmpty()) |
179 | | - json.put("containerPath", getContainerPath()); |
| 198 | + if (getExtraContext() != null && !getExtraContext().isEmpty()) |
| 199 | + json.put("extraContext", getExtraContext()); |
180 | 200 |
|
181 | 201 | if (isSkipReselectRows() != null) |
182 | 202 | json.put("skipReselectRows", isSkipReselectRows()); |
183 | 203 |
|
184 | 204 | return json; |
185 | 205 | } |
186 | 206 |
|
187 | | - public CommandType getCommandType() |
| 207 | + public BaseRowsCommand.AuditBehavior getAuditBehavior() |
188 | 208 | { |
189 | | - return _commandType; |
| 209 | + return _auditBehavior; |
190 | 210 | } |
191 | 211 |
|
192 | | - public String getContainerPath() |
| 212 | + public Command setAuditBehavior(BaseRowsCommand.AuditBehavior auditBehavior) |
193 | 213 | { |
194 | | - return _containerPath; |
| 214 | + _auditBehavior = auditBehavior; |
| 215 | + return this; |
195 | 216 | } |
196 | 217 |
|
197 | | - public void setContainerPath(String containerPath) |
| 218 | + public String getAuditUserComment() |
198 | 219 | { |
199 | | - _containerPath = containerPath; |
| 220 | + return _auditUserComment; |
200 | 221 | } |
201 | 222 |
|
202 | | - public Boolean isSkipReselectRows() |
| 223 | + public Command setAuditUserComment(String auditUserComment) |
203 | 224 | { |
204 | | - return _skipReselectRows; |
| 225 | + _auditUserComment = auditUserComment; |
| 226 | + return this; |
205 | 227 | } |
206 | 228 |
|
207 | | - public void setSkipReselectRows(Boolean skipReselectRows) |
| 229 | + public CommandType getCommandType() |
208 | 230 | { |
209 | | - _skipReselectRows = skipReselectRows; |
| 231 | + return _commandType; |
210 | 232 | } |
211 | 233 |
|
212 | | - @Override |
213 | | - public String getActionName() |
| 234 | + public String getContainerPath() |
214 | 235 | { |
215 | | - throw new UnsupportedOperationException(unsupportedMethodMessage()); |
| 236 | + return _containerPath; |
216 | 237 | } |
217 | 238 |
|
218 | | - @Override |
219 | | - public String getControllerName() |
| 239 | + public Command setContainerPath(String containerPath) |
220 | 240 | { |
221 | | - throw new UnsupportedOperationException(unsupportedMethodMessage()); |
| 241 | + _containerPath = containerPath; |
| 242 | + return this; |
222 | 243 | } |
223 | 244 |
|
224 | | - @Override |
225 | | - public RowsResponse execute(Connection connection, String folderPath) throws IOException, CommandException |
| 245 | + public Map<String, Object> getExtraContext() |
226 | 246 | { |
227 | | - throw new UnsupportedOperationException(unsupportedMethodMessage()); |
| 247 | + return _extraContext; |
228 | 248 | } |
229 | 249 |
|
230 | | - @Override |
231 | | - public double getRequiredVersion() |
| 250 | + public Command setExtraContext(Map<String, Object> extraContext) |
232 | 251 | { |
233 | | - throw new UnsupportedOperationException(unsupportedMethodMessage()); |
| 252 | + _extraContext = extraContext; |
| 253 | + return this; |
234 | 254 | } |
235 | 255 |
|
236 | | - @Override |
237 | | - public void setRequiredVersion(double requiredVersion) |
| 256 | + public String getQueryName() |
238 | 257 | { |
239 | | - throw new UnsupportedOperationException(unsupportedMethodMessage()); |
| 258 | + return _queryName; |
240 | 259 | } |
241 | 260 |
|
242 | | - @Override |
243 | | - public Integer getTimeout() |
| 261 | + public String getSchemaName() |
244 | 262 | { |
245 | | - throw new UnsupportedOperationException(unsupportedMethodMessage()); |
| 263 | + return _schemaName; |
246 | 264 | } |
247 | 265 |
|
248 | | - @Override |
249 | | - public void setTimeout(Integer timeout) |
| 266 | + public List<Map<String, Object>> getRows() |
250 | 267 | { |
251 | | - throw new UnsupportedOperationException(unsupportedMethodMessage()); |
| 268 | + return _rows; |
252 | 269 | } |
253 | 270 |
|
254 | | - private String unsupportedMethodMessage() |
| 271 | + public Command setRows(List<Map<String, Object>> rows) |
255 | 272 | { |
256 | | - // "Command does not support methodName()." |
257 | | - return Command.class.getSimpleName() + " does not support " + new Throwable().getStackTrace()[1].getMethodName() + "()."; |
| 273 | + _rows = rows; |
| 274 | + return this; |
| 275 | + } |
| 276 | + |
| 277 | + public Boolean isSkipReselectRows() |
| 278 | + { |
| 279 | + return _skipReselectRows; |
| 280 | + } |
| 281 | + |
| 282 | + public Command setSkipReselectRows(Boolean skipReselectRows) |
| 283 | + { |
| 284 | + _skipReselectRows = skipReselectRows; |
| 285 | + return this; |
258 | 286 | } |
259 | 287 | } |
260 | 288 | } |
0 commit comments