|
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; |
4 | 6 | import org.labkey.remoteapi.PostCommand; |
5 | 7 |
|
| 8 | +import java.io.IOException; |
6 | 9 | import java.util.ArrayList; |
7 | 10 | import java.util.List; |
8 | 11 | import java.util.Map; |
@@ -153,136 +156,105 @@ public enum CommandType |
153 | 156 | Delete |
154 | 157 | } |
155 | 158 |
|
156 | | - public static class Command |
| 159 | + public static class Command extends BaseRowsCommand |
157 | 160 | { |
158 | | - BaseRowsCommand.AuditBehavior _auditBehavior; |
159 | | - String _auditUserComment; |
160 | 161 | final CommandType _commandType; |
161 | 162 | String _containerPath; |
162 | | - Map<String, Object> _extraContext; |
163 | | - List<Map<String, Object>> _rows; |
164 | | - final String _queryName; |
165 | | - final String _schemaName; |
166 | 163 | Boolean _skipReselectRows; |
167 | 164 |
|
168 | 165 | public Command(CommandType commandType, String schemaName, String queryName, List<Map<String, Object>> rows) |
169 | 166 | { |
| 167 | + super(schemaName, queryName, null); |
170 | 168 | assert null != commandType; |
171 | | - assert null != schemaName && !schemaName.isEmpty(); |
172 | | - assert null != queryName && !queryName.isEmpty(); |
173 | | - |
174 | 169 | _commandType = commandType; |
175 | | - _schemaName = schemaName; |
176 | | - _queryName = queryName; |
177 | | - _rows = rows; |
| 170 | + setRows(rows); |
178 | 171 | } |
179 | 172 |
|
180 | 173 | public JSONObject getJsonObject() |
181 | 174 | { |
182 | | - JSONObject json = new JSONObject(); |
183 | | - |
| 175 | + JSONObject json = super.getJsonObject(); |
184 | 176 | 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()); |
194 | 177 |
|
195 | 178 | if (getContainerPath() != null && !getContainerPath().isEmpty()) |
196 | 179 | json.put("containerPath", getContainerPath()); |
197 | 180 |
|
198 | | - if (getExtraContext() != null && !getExtraContext().isEmpty()) |
199 | | - json.put("extraContext", getExtraContext()); |
200 | | - |
201 | 181 | if (isSkipReselectRows() != null) |
202 | 182 | json.put("skipReselectRows", isSkipReselectRows()); |
203 | 183 |
|
204 | 184 | return json; |
205 | 185 | } |
206 | 186 |
|
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() |
219 | 188 | { |
220 | | - return _auditUserComment; |
| 189 | + return _commandType; |
221 | 190 | } |
222 | 191 |
|
223 | | - public Command setAuditUserComment(String auditUserComment) |
| 192 | + public String getContainerPath() |
224 | 193 | { |
225 | | - _auditUserComment = auditUserComment; |
226 | | - return this; |
| 194 | + return _containerPath; |
227 | 195 | } |
228 | 196 |
|
229 | | - public CommandType getCommandType() |
| 197 | + public void setContainerPath(String containerPath) |
230 | 198 | { |
231 | | - return _commandType; |
| 199 | + _containerPath = containerPath; |
232 | 200 | } |
233 | 201 |
|
234 | | - public String getContainerPath() |
| 202 | + public Boolean isSkipReselectRows() |
235 | 203 | { |
236 | | - return _containerPath; |
| 204 | + return _skipReselectRows; |
237 | 205 | } |
238 | 206 |
|
239 | | - public Command setContainerPath(String containerPath) |
| 207 | + public void setSkipReselectRows(Boolean skipReselectRows) |
240 | 208 | { |
241 | | - _containerPath = containerPath; |
242 | | - return this; |
| 209 | + _skipReselectRows = skipReselectRows; |
243 | 210 | } |
244 | 211 |
|
245 | | - public Map<String, Object> getExtraContext() |
| 212 | + @Override |
| 213 | + public String getActionName() |
246 | 214 | { |
247 | | - return _extraContext; |
| 215 | + throw new UnsupportedOperationException(unsupportedMethodMessage()); |
248 | 216 | } |
249 | 217 |
|
250 | | - public Command setExtraContext(Map<String, Object> extraContext) |
| 218 | + @Override |
| 219 | + public String getControllerName() |
251 | 220 | { |
252 | | - _extraContext = extraContext; |
253 | | - return this; |
| 221 | + throw new UnsupportedOperationException(unsupportedMethodMessage()); |
254 | 222 | } |
255 | 223 |
|
256 | | - public String getQueryName() |
| 224 | + @Override |
| 225 | + public RowsResponse execute(Connection connection, String folderPath) throws IOException, CommandException |
257 | 226 | { |
258 | | - return _queryName; |
| 227 | + throw new UnsupportedOperationException(unsupportedMethodMessage()); |
259 | 228 | } |
260 | 229 |
|
261 | | - public String getSchemaName() |
| 230 | + @Override |
| 231 | + public double getRequiredVersion() |
262 | 232 | { |
263 | | - return _schemaName; |
| 233 | + throw new UnsupportedOperationException(unsupportedMethodMessage()); |
264 | 234 | } |
265 | 235 |
|
266 | | - public List<Map<String, Object>> getRows() |
| 236 | + @Override |
| 237 | + public void setRequiredVersion(double requiredVersion) |
267 | 238 | { |
268 | | - return _rows; |
| 239 | + throw new UnsupportedOperationException(unsupportedMethodMessage()); |
269 | 240 | } |
270 | 241 |
|
271 | | - public Command setRows(List<Map<String, Object>> rows) |
| 242 | + @Override |
| 243 | + public Integer getTimeout() |
272 | 244 | { |
273 | | - _rows = rows; |
274 | | - return this; |
| 245 | + throw new UnsupportedOperationException(unsupportedMethodMessage()); |
275 | 246 | } |
276 | 247 |
|
277 | | - public Boolean isSkipReselectRows() |
| 248 | + @Override |
| 249 | + public void setTimeout(Integer timeout) |
278 | 250 | { |
279 | | - return _skipReselectRows; |
| 251 | + throw new UnsupportedOperationException(unsupportedMethodMessage()); |
280 | 252 | } |
281 | 253 |
|
282 | | - public Command setSkipReselectRows(Boolean skipReselectRows) |
| 254 | + private String unsupportedMethodMessage() |
283 | 255 | { |
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() + "()."; |
286 | 258 | } |
287 | 259 | } |
288 | 260 | } |
0 commit comments