Skip to content

Commit bbfa45b

Browse files
author
i.hilerio
committed
Merge in java updates for truncateTableCommand with UTs
SVN r64364 |2019-08-23 22:21:44 +0000
1 parent 83ee3bf commit bbfa45b

File tree

4 files changed

+85
-6
lines changed

4 files changed

+85
-6
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ java/src/org/labkey/remoteapi/query/SelectRowsCommand.java -text
8080
java/src/org/labkey/remoteapi/query/SelectRowsResponse.java -text
8181
java/src/org/labkey/remoteapi/query/Sort.java -text
8282
java/src/org/labkey/remoteapi/query/SqlExecuteCommand.java -text
83+
java/src/org/labkey/remoteapi/query/TruncateTableCommand.java -text
8384
java/src/org/labkey/remoteapi/query/UpdateRowsCommand.java -text
8485
java/src/org/labkey/remoteapi/sas/Main.java -text
8586
java/src/org/labkey/remoteapi/sas/SASBaseSelectCommand.java -text

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,14 @@ private void caseInsensitizeRowMaps()
192192
{
193193
//copy the row maps into case-insensitive hash maps
194194
List<Map<String,Object>> ciRows = new ArrayList<>();
195-
196-
for(Map<String,Object> row : getRows())
195+
196+
if (getRows() != null)
197197
{
198-
//copy the row map into a case-insensitive hash map
199-
ciRows.add(new CaseInsensitiveHashMap<>(row));
198+
for(Map<String,Object> row : getRows())
199+
{
200+
//copy the row map into a case-insensitive hash map
201+
ciRows.add(new CaseInsensitiveHashMap<>(row));
202+
}
200203
}
201204

202205
//reset the rows array
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2008-2009 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+
/**
19+
* Command for deleting rows from a read-write schema. The user associated
20+
* with the connection used when executing this command must have
21+
* permission to delete the data.
22+
* <p>
23+
* For details on schemas and queries, and example code, see the {@link SaveRowsCommand}.
24+
*/
25+
public class TruncateTableCommand extends SaveRowsCommand
26+
{
27+
/**
28+
* Constructs a TruncateTableCommand for the given schemaName and queryName.
29+
* See the {@link SaveRowsCommand} for more details.
30+
* @param schemaName The schemaName
31+
* @param queryName The queryName.
32+
* @see SaveRowsCommand
33+
*/
34+
public TruncateTableCommand(String schemaName, String queryName)
35+
{
36+
super(schemaName, queryName, "truncateTable");
37+
}
38+
39+
public TruncateTableCommand(TruncateTableCommand source)
40+
{
41+
super(source);
42+
}
43+
44+
@Override
45+
public TruncateTableCommand copy()
46+
{
47+
return new TruncateTableCommand(this);
48+
}
49+
}

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public static void main(String[] args) throws Exception
4444
{
4545
String baseUrl = "http://localhost:8080/labkey";
4646
Connection cn = args.length < 2 ? new Connection(baseUrl) : new Connection(baseUrl, args[0], args[1]);
47-
// Connection cn = new Connection(baseUrl, new ApiKeyCredentialsProvider("session:d7c3a4aeb283e3e54c4126a707908420"));
48-
// Connection cn = new Connection(baseUrl, new NetRcCredentialsProvider(baseUrl));
47+
//Connection cn = new Connection(baseUrl, new ApiKeyCredentialsProvider("session:d7c3a4aeb283e3e54c4126a707908420"));
48+
//Connection cn = new Connection(baseUrl, new NetRcCredentialsProvider(baseUrl));
4949

5050
try
5151
{
@@ -62,7 +62,9 @@ public static void main(String[] args) throws Exception
6262
// Run NabAssayTest with -Dclean=false and rename subfolder "Rename############" to "nabassay"
6363
nabTest(cn, "/Nab Test Verify Project/nabassay");
6464
assayTest(cn, "/Nab Test Verify Project/nabassay");
65+
truncateAssayFailsTest(cn, "/Nab Test Verify Project/nabassay");
6566

67+
truncateTableSuccessTest(cn, "Api Test");
6668
System.out.println("*** All tests completed successfully ***");
6769
}
6870
catch(CommandException e)
@@ -136,6 +138,16 @@ public static void crudTest(Connection cn, String folder) throws Exception
136138
assert srresp.getRowCount().intValue() == rowCount;
137139
}
138140

141+
// Assumes that /remoteapi/sas/People.xls has been imported as a list into folder
142+
public static void truncateTableSuccessTest(Connection cn, String folder) throws Exception
143+
{
144+
TruncateTableCommand trunc = new TruncateTableCommand("lists", "People");
145+
SaveRowsResponse resp = trunc.execute(cn, folder);
146+
147+
assert resp.getRowsAffected().intValue() == 9;
148+
assert resp.getRows().size() == 0;
149+
}
150+
139151
// Assumes that /remoteapi/sas/People.xls has been imported as a list into folder
140152
public static void execSqlTest(Connection cn, String folder) throws Exception
141153
{
@@ -280,4 +292,18 @@ public static void assayTest(Connection cn, String folder) throws Exception
280292
AssayListResponse resp = cmd.execute(cn, folder);
281293
System.out.println(resp.getDefinitions());
282294
}
295+
296+
// Assumes that folder has been populated with assays
297+
public static void truncateAssayFailsTest(Connection cn, String folder) throws Exception
298+
{
299+
TruncateTableCommand trunc = new TruncateTableCommand("assay.NAb.TestAssayNab", "WellData");
300+
try{
301+
SaveRowsResponse resp = trunc.execute(cn, folder);
302+
}
303+
catch (CommandException e)
304+
{
305+
assert e.getStatusCode() == 500;
306+
assert e.getLocalizedMessage().equals("The query 'WellData' in the schema 'assay.NAb.TestAssayNab' is not truncatable.");
307+
}
308+
}
283309
}

0 commit comments

Comments
 (0)