Skip to content

Commit 1f30c82

Browse files
authored
Issue 47030: Have the Java SelectRowsCommand use POST (#46)
1 parent 34e83c7 commit 1f30c82

File tree

6 files changed

+137
-59
lines changed

6 files changed

+137
-59
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
# The LabKey Remote API Library for Java - Change Log
22

3-
## version 4.3.0-SNAPSHOT
3+
## version 4.4.0-SNAPSHOT
44
*Released*: TBD
55

6+
## version 4.3.0
7+
*Released*: 11 January 2023
8+
* [Issue 47030](https://www.labkey.org/home/Developer/issues/issues-details.view?issueId=47030): Switch `SelectRowsCommand` and `NAbRunsCommand` to always use POST
9+
* Add support for `includeTotalCount`, `includeMetadata`, and `ignoreFilter` flags to `BaseQueryCommand` and reconcile duplicate parameter handling code vs. SelectRowsCommand
10+
* Add support for `includeTitle` and `includeViewDataUrl` flags to `GetQueriesCommand`
11+
612
## version 4.2.0
713
*Released*: 10 January 2023
814
* Refactor repository layout, removing unnecessary `labkey-client-api` folder

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ repositories {
4848

4949
group "org.labkey.api"
5050

51-
version "4.3.0-SNAPSHOT"
51+
version "4.4.0-SNAPSHOT"
5252

5353
dependencies {
5454
api "org.json:json:${jsonObjectVersion}"

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

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,25 @@
1515
*/
1616
package org.labkey.remoteapi.query;
1717

18-
import org.labkey.remoteapi.Command;
1918
import org.labkey.remoteapi.CommandResponse;
19+
import org.labkey.remoteapi.PostCommand;
2020

2121
import java.util.ArrayList;
2222
import java.util.HashMap;
2323
import java.util.List;
2424
import java.util.Map;
2525

26-
public abstract class BaseQueryCommand<ResponseType extends CommandResponse> extends Command<ResponseType>
26+
public abstract class BaseQueryCommand<ResponseType extends CommandResponse> extends PostCommand<ResponseType>
2727
{
2828
protected int _maxRows = -1;
2929
protected int _offset = 0;
3030
protected List<Sort> _sorts;
3131
protected List<Filter> _filters;
3232
protected ContainerFilter _containerFilter;
3333
private Map<String, String> _queryParameters = new HashMap<>();
34+
private boolean _ignoreFilter = false;
35+
private boolean _includeMetadata = true;
36+
private boolean _includeTotalCount = true;
3437

3538
public BaseQueryCommand(BaseQueryCommand<ResponseType> source)
3639
{
@@ -213,6 +216,48 @@ public void setContainerFilter(ContainerFilter containerFilter)
213216
_containerFilter = containerFilter;
214217
}
215218

219+
public boolean isIgnoreFilter()
220+
{
221+
return _ignoreFilter;
222+
}
223+
224+
/**
225+
* Pass true to ignore any filter that may be part of the chosen view. Defaults to false.
226+
* @param ignoreFilter Set to 'true' to ignore the view filter.
227+
*/
228+
public void setIgnoreFilter(boolean ignoreFilter)
229+
{
230+
_ignoreFilter = ignoreFilter;
231+
}
232+
233+
public boolean isIncludeMetadata()
234+
{
235+
return _includeMetadata;
236+
}
237+
238+
/**
239+
* Pass false to omit metadata for the selected columns. Defaults to true.
240+
* @param includeMetadata Set to 'false' to omit column metadata.
241+
*/
242+
public void setIncludeMetadata(boolean includeMetadata)
243+
{
244+
_includeMetadata = includeMetadata;
245+
}
246+
247+
public boolean isIncludeTotalCount()
248+
{
249+
return _includeTotalCount;
250+
}
251+
252+
/**
253+
* Pass false to omit total count from the response. Default is true.
254+
* @param includeTotalCount Set to 'false' to omit total count.
255+
*/
256+
public void setIncludeTotalCount(boolean includeTotalCount)
257+
{
258+
_includeTotalCount = includeTotalCount;
259+
}
260+
216261
/**
217262
@return Map of name (string)/value pairs for the values of parameters if the SQL references underlying queries
218263
that are parameterized.
@@ -238,26 +283,39 @@ public Map<String, Object> getParameters()
238283
Map<String, Object> params = super.getParameters();
239284

240285
if (getOffset() > 0)
241-
params.put("offset", getOffset());
286+
params.put("query.offset", getOffset());
287+
242288
if (getMaxRows() >= 0)
243-
params.put("maxRows", getMaxRows());
244-
if(null != getSorts() && getSorts().size() > 0)
289+
params.put("query.maxRows", getMaxRows());
290+
else
291+
params.put("query.showRows", "all");
292+
293+
if (null != getSorts() && getSorts().size() > 0)
245294
params.put("query.sort", Sort.getSortQueryStringParam(getSorts()));
246295

247-
if(null != getFilters())
296+
if (null != getFilters())
248297
{
249298
for(Filter filter : getFilters())
250299
params.put("query." + filter.getQueryStringParamName(), filter.getQueryStringParamValue());
251300
}
252301

253-
if(getContainerFilter() != null)
302+
if (getContainerFilter() != null)
254303
params.put("containerFilter", getContainerFilter().name());
255304

256305
for (Map.Entry<String, String> entry : getQueryParameters().entrySet())
257306
{
258307
params.put("query.param." + entry.getKey(), entry.getValue());
259308
}
260309

310+
if (!isIncludeTotalCount())
311+
params.put("includeTotalCount", isIncludeTotalCount());
312+
313+
if (!isIncludeMetadata())
314+
params.put("includeMetadata", isIncludeMetadata());
315+
316+
if (isIgnoreFilter())
317+
params.put("query.ignoreFilter", isIgnoreFilter());
318+
261319
return params;
262320
}
263321
}

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

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@
2727
public class GetQueriesCommand extends Command<GetQueriesResponse>
2828
{
2929
private String _schemaName;
30-
private boolean _includeUserQueries = true;
3130
private boolean _includeColumns = true;
31+
private boolean _includeTitle = true;
32+
private boolean _includeUserQueries = true;
33+
private boolean _includeViewDataUrl = true;
3234

3335
/**
3436
* Constructs the command given a particular schema name.
@@ -50,6 +52,36 @@ public void setSchemaName(String schemaName)
5052
_schemaName = schemaName;
5153
}
5254

55+
public boolean isIncludeColumns()
56+
{
57+
return _includeColumns;
58+
}
59+
60+
/**
61+
* Pass false to omit information about the columns within each query. By default,
62+
* column information is included.
63+
* @param includeColumns 'false' to omit column information.
64+
*/
65+
public void setIncludeColumns(boolean includeColumns)
66+
{
67+
_includeColumns = includeColumns;
68+
}
69+
70+
public boolean isIncludeTitle()
71+
{
72+
return _includeTitle;
73+
}
74+
75+
/**
76+
* Pass false to omit custom query titles. Titles will be returned, but their values will be identical to names.
77+
* Default is true.
78+
* @param includeTitle 'false' to omit custom query titles.
79+
*/
80+
public void setIncludeTitle(boolean includeTitle)
81+
{
82+
_includeTitle = includeTitle;
83+
}
84+
5385
public boolean isIncludeUserQueries()
5486
{
5587
return _includeUserQueries;
@@ -58,26 +90,25 @@ public boolean isIncludeUserQueries()
5890
/**
5991
* Pass false to this method to omit user-defined queries from the results. By default,
6092
* user-defined queries are included.
61-
* @param includeUserQueries Set to false to omit user-defined queries.
93+
* @param includeUserQueries Set to 'false' to omit user-defined queries.
6294
*/
6395
public void setIncludeUserQueries(boolean includeUserQueries)
6496
{
6597
_includeUserQueries = includeUserQueries;
6698
}
6799

68-
public boolean isIncludeColumns()
100+
public boolean isIncludeViewDataUrl()
69101
{
70-
return _includeColumns;
102+
return _includeViewDataUrl;
71103
}
72104

73105
/**
74-
* Pass false to omit information about the columns within each query. By default,
75-
* column information is included.
76-
* @param includeColumns 'false' to omit column information.
106+
* Pass false to omit view data URLs from the results. Default is true.
107+
* @param includeViewDataUrl Set to 'false' to omit view data URLs.
77108
*/
78-
public void setIncludeColumns(boolean includeColumns)
109+
public void setIncludeViewDataUrl(boolean includeViewDataUrl)
79110
{
80-
_includeColumns = includeColumns;
111+
_includeViewDataUrl = includeViewDataUrl;
81112
}
82113

83114
@Override
@@ -88,11 +119,15 @@ public Map<String, Object> getParameters()
88119
Map<String, Object> params = new HashMap<>();
89120
params.put("schemaName", getSchemaName());
90121

91-
if(!isIncludeColumns())
122+
if (!isIncludeColumns())
92123
params.put("includeColumns", isIncludeColumns());
93-
if(!isIncludeUserQueries())
124+
if (!isIncludeTitle())
125+
params.put("includeTitle", isIncludeTitle());
126+
if (!isIncludeUserQueries())
94127
params.put("includeUserQueries", isIncludeUserQueries());
95-
128+
if (!isIncludeViewDataUrl())
129+
params.put("includeViewDataUrl", isIncludeViewDataUrl());
130+
96131
return params;
97132
}
98133

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

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.json.JSONObject;
1919

2020
import java.util.ArrayList;
21-
import java.util.HashMap;
2221
import java.util.List;
2322
import java.util.Map;
2423

@@ -187,12 +186,15 @@ protected SelectRowsResponse createResponse(String text, int status, String cont
187186
@Override
188187
public Map<String, Object> getParameters()
189188
{
190-
Map<String, Object> params = new HashMap<>();
189+
Map<String, Object> params = super.getParameters();
190+
191191
params.put("schemaName", getSchemaName());
192192
params.put("query.queryName", getQueryName());
193-
if(null != getViewName())
193+
194+
if (null != getViewName())
194195
params.put("query.viewName", getViewName());
195-
if(null != getColumns() && getColumns().size() > 0)
196+
197+
if (null != getColumns() && getColumns().size() > 0)
196198
{
197199
StringBuilder collist = new StringBuilder();
198200
String sep = "";
@@ -204,30 +206,7 @@ public Map<String, Object> getParameters()
204206
}
205207
params.put("query.columns", collist);
206208
}
207-
if(getMaxRows() >= 0)
208-
params.put("query.maxRows", getMaxRows());
209-
else
210-
params.put("query.showRows", "all");
211-
if(getOffset() > 0)
212-
params.put("query.offset", getOffset());
213-
if(null != getSorts() && getSorts().size() > 0)
214-
params.put("query.sort", Sort.getSortQueryStringParam(getSorts()));
215-
216-
if(null != getFilters())
217-
{
218-
for(Filter filter : getFilters())
219-
params.put("query." + filter.getQueryStringParamName(), filter.getQueryStringParamValue());
220-
}
221-
222-
if (getContainerFilter() != null)
223-
params.put("containerFilter", getContainerFilter().name());
224-
225-
for (Map.Entry<String, String> entry : getQueryParameters().entrySet())
226-
{
227-
params.put("query.param." + entry.getKey(), entry.getValue());
228-
}
229209

230210
return params;
231211
}
232-
233212
}

src/org/labkey/remoteapi/test/Test.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package org.labkey.remoteapi.test;
1717

18-
import org.json.JSONObject;
1918
import org.labkey.remoteapi.CommandException;
2019
import org.labkey.remoteapi.Connection;
2120
import org.labkey.remoteapi.assay.AssayListCommand;
@@ -59,7 +58,7 @@ public static void main(String[] args) throws Exception
5958

6059
try
6160
{
62-
// Import /remoteapi/sas/People.xls as list "People" into project "Api Test"
61+
// Import /remoteapi/labkey-api-java/People.xls as list "People" into project "Api Test"
6362
selectTest(cn, "Api Test");
6463
crudTest(cn, "Api Test");
6564
execSqlTest(cn, "Api Test");
@@ -83,7 +82,7 @@ public static void main(String[] args) throws Exception
8382
}
8483
}
8584

86-
// Assumes that /remoteapi/sas/People.xls has been imported as a list into folder
85+
// Assumes that /remoteapi/labkey-api-java/People.xls has been imported as a list into folder
8786
public static void selectTest(Connection cn, String folder) throws Exception
8887
{
8988
SelectRowsCommand cmd = new SelectRowsCommand("lists", "People");
@@ -103,7 +102,7 @@ public static void selectTest(Connection cn, String folder) throws Exception
103102
}
104103
}
105104

106-
// Assumes that /remoteapi/sas/People.xls has been imported as a list into folder
105+
// Assumes that /remoteapi/labkey-api-java/People.xls has been imported as a list into folder
107106
public static void crudTest(Connection cn, String folder) throws Exception
108107
{
109108
int rowCount = 0;
@@ -148,16 +147,16 @@ public static void crudTest(Connection cn, String folder) throws Exception
148147
assert srresp.getRowCount().intValue() == rowCount;
149148
}
150149

151-
// Assumes that /remoteapi/sas/People.xls has been imported as a list into folder
150+
// Assumes that /remoteapi/labkey-api-java/People.xls has been imported as a list into folder
152151
public static void truncateTableSuccessTest(Connection cn, String folder) throws Exception
153152
{
154153
TruncateTableCommand trunc = new TruncateTableCommand("lists", "People");
155154
TruncateTableResponse resp = trunc.execute(cn, folder);
156155

157-
assert resp.getDeletedRowCount().intValue() == 9;
156+
assert resp.getDeletedRowCount() == 9;
158157
}
159158

160-
// Assumes that /remoteapi/sas/People.xls has been imported as a list into folder
159+
// Assumes that /remoteapi/labkey-api-java/People.xls has been imported as a list into folder
161160
public static void execSqlTest(Connection cn, String folder) throws Exception
162161
{
163162
ExecuteSqlCommand cmd = new ExecuteSqlCommand("lists");
@@ -166,7 +165,7 @@ public static void execSqlTest(Connection cn, String folder) throws Exception
166165
System.out.println(resp.getRows());
167166
}
168167

169-
// Assumes that /remoteapi/sas/People.xls has been imported as a list into folder
168+
// Assumes that /remoteapi/labkey-api-java/People.xls has been imported as a list into folder
170169
private static void schemasTest(Connection cn, String folder) throws Exception
171170
{
172171
GetSchemasCommand cmd = new GetSchemasCommand();
@@ -188,7 +187,7 @@ private static void schemasTest(Connection cn, String folder) throws Exception
188187
}
189188
}
190189

191-
// Assumes that /remoteapi/sas/People.xls has been imported as a list into folder
190+
// Assumes that /remoteapi/labkey-api-java/People.xls has been imported as a list into folder
192191
private static void extendedFormatTest(Connection cn, String folder) throws Exception
193192
{
194193
SelectRowsCommand cmd = new SelectRowsCommand("lists", "People");
@@ -199,7 +198,7 @@ private static void extendedFormatTest(Connection cn, String folder) throws Exce
199198
{
200199
for (Map.Entry<String, Object> entry : row.entrySet())
201200
{
202-
Object value = ((JSONObject)entry.getValue()).get("value");
201+
Object value = ((Map<String, Object>)entry.getValue()).get("value");
203202
System.out.println(entry.getKey() + " = " + value + " (type: " + (null == value ? "null" : value.getClass().getName()) + ")");
204203
}
205204
}
@@ -306,7 +305,8 @@ public static void assayTest(Connection cn, String folder) throws Exception
306305
public static void truncateAssayFailsTest(Connection cn, String folder) throws Exception
307306
{
308307
TruncateTableCommand trunc = new TruncateTableCommand("assay.NAb.TestAssayNab", "WellData");
309-
try{
308+
try
309+
{
310310
TruncateTableResponse resp = trunc.execute(cn, folder);
311311
throw new RuntimeException("Truncate table command should not succeed for tables other than lists," +
312312
"datasets, sample sets, data classes, and issues");

0 commit comments

Comments
 (0)