Skip to content

Commit e4d76c9

Browse files
author
i.hilerio
committed
Update Truncate table response and command for external API
SVN r64435 |2019-09-04 20:29:01 +0000
1 parent 5a9cc7b commit e4d76c9

File tree

4 files changed

+172
-23
lines changed

4 files changed

+172
-23
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ java/src/org/labkey/remoteapi/query/SelectRowsResponse.java -text
8989
java/src/org/labkey/remoteapi/query/Sort.java -text
9090
java/src/org/labkey/remoteapi/query/SqlExecuteCommand.java -text
9191
java/src/org/labkey/remoteapi/query/TruncateTableCommand.java -text
92+
java/src/org/labkey/remoteapi/query/TruncateTableResponse.java -text
9293
java/src/org/labkey/remoteapi/query/UpdateRowsCommand.java -text
9394
java/src/org/labkey/remoteapi/sas/Main.java -text
9495
java/src/org/labkey/remoteapi/sas/SASBaseSelectCommand.java -text

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

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

18+
import org.json.simple.JSONArray;
19+
import org.json.simple.JSONObject;
20+
import org.labkey.remoteapi.PostCommand;
21+
22+
import java.text.SimpleDateFormat;
23+
import java.util.Date;
24+
import java.util.Map;
25+
1826
/**
1927
* Command for deleting rows from a read-write schema. The user associated
2028
* with the connection used when executing this command must have
2129
* permission to delete the data.
2230
* <p>
23-
* For details on schemas and queries, and example code, see the {@link SaveRowsCommand}.
2431
*/
25-
public class TruncateTableCommand extends SaveRowsCommand
32+
public class TruncateTableCommand extends PostCommand<TruncateTableResponse>
2633
{
34+
private String _schemaName;
35+
private String _queryName;
36+
2737
/**
2838
* Constructs a TruncateTableCommand for the given schemaName and queryName.
29-
* See the {@link SaveRowsCommand} for more details.
3039
* @param schemaName The schemaName
31-
* @param queryName The queryName.
32-
* @see SaveRowsCommand
40+
* @param queryName The queryName
3341
*/
3442
public TruncateTableCommand(String schemaName, String queryName)
3543
{
36-
super(schemaName, queryName, "truncateTable");
44+
super("query", "truncateTable");
45+
assert null != schemaName;
46+
assert null != queryName;
47+
_schemaName = schemaName;
48+
_queryName = queryName;
3749
}
3850

3951
public TruncateTableCommand(TruncateTableCommand source)
4052
{
4153
super(source);
4254
}
4355

56+
/**
57+
* Returns the schema name.
58+
* @return The schema name.
59+
*/
60+
public String getSchemaName()
61+
{
62+
return _schemaName;
63+
}
64+
65+
/**
66+
* Sets the schema name
67+
* @param schemaName The new schema name.
68+
*/
69+
public void setSchemaName(String schemaName)
70+
{
71+
_schemaName = schemaName;
72+
}
73+
74+
/**
75+
* Returns the query name
76+
* @return the query name.
77+
*/
78+
public String getQueryName()
79+
{
80+
return _queryName;
81+
}
82+
83+
/**
84+
* Sets a new query name to update
85+
* @param queryName the query name.
86+
*/
87+
public void setQueryName(String queryName)
88+
{
89+
_queryName = queryName;
90+
}
91+
4492
@Override
4593
public TruncateTableCommand copy()
4694
{
4795
return new TruncateTableCommand(this);
4896
}
97+
98+
@Override
99+
protected TruncateTableResponse createResponse(String text, int status, String contentType, JSONObject json)
100+
{
101+
return new TruncateTableResponse(text, status, contentType, json, copy());
102+
}
103+
104+
public JSONObject getJsonObject()
105+
{
106+
JSONObject json = new JSONObject();
107+
json.put("schemaName", getSchemaName());
108+
json.put("queryName", getQueryName());
109+
//json.put("rows", jsonRows);
110+
return json;
111+
}
49112
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
import org.json.simple.JSONObject;
19+
20+
/*
21+
* User: Dave
22+
* Date: Jul 14, 2008
23+
* Time: 1:16:58 PM
24+
*/
25+
26+
/**
27+
* Response object used for commands that derive from SaveRowsCommand.
28+
* This response object provides helper methods for accessing the important
29+
* bits of the parsed response data.
30+
*/
31+
public class TruncateTableResponse extends RowsResponse
32+
{
33+
/**
34+
* Constructs a new SaveRowsResponse given the response text and status code
35+
* @param text The response text.
36+
* @param statusCode The HTTP status code.
37+
* @param contentType The Content-Type header value.
38+
* @param json The parsed JSONObject (or null if JSON was not returned).
39+
* @param sourceCommand A copy of the command that created this response
40+
*/
41+
public TruncateTableResponse(String text, int statusCode, String contentType, JSONObject json, TruncateTableCommand sourceCommand)
42+
{
43+
super(text, statusCode, contentType, json, sourceCommand);
44+
}
45+
46+
/**
47+
* Returns the 'rowsAffected' response property.
48+
* @return The number of rows affected by the command, or null if this property
49+
* was not present in the response.
50+
*/
51+
public Number getDeletedRows()
52+
{
53+
return getProperty("deletedRows");
54+
}
55+
56+
/**
57+
* Returns the 'schemaName' response property.
58+
* @return The schema name affected by the command, or null if this property
59+
* was not present in the response.
60+
*/
61+
public String getSchemaName()
62+
{
63+
return getProperty("schemaName");
64+
}
65+
66+
/**
67+
* Returns the 'queryName' response property.
68+
* @return The query name affected by the command, or null if this property
69+
* was not present in the response.
70+
*/
71+
public String getQueryName()
72+
{
73+
return getProperty("queryName");
74+
}
75+
76+
/**
77+
* Returns the 'command' response property.
78+
* @return The command executed, or null if this property
79+
* was not present in the response.
80+
*/
81+
public String getCommand()
82+
{
83+
return getProperty("command");
84+
}
85+
}

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,26 @@ public class Test
4343
public static void main(String[] args) throws Exception
4444
{
4545
String baseUrl = "http://localhost:8080/labkey";
46-
Connection cn = args.length < 2 ? new Connection(baseUrl) : new Connection(baseUrl, args[0], args[1]);
46+
Connection cn = args.length < 2 ? new Connection(baseUrl) : new Connection(baseUrl, "israelh@labkey.com", "devdev1");
4747
//Connection cn = new Connection(baseUrl, new ApiKeyCredentialsProvider("session:d7c3a4aeb283e3e54c4126a707908420"));
4848
//Connection cn = new Connection(baseUrl, new NetRcCredentialsProvider(baseUrl));
4949

5050
try
5151
{
5252
// Import /remoteapi/sas/People.xls as list "People" into project "Api Test"
53-
selectTest(cn, "Api Test");
54-
crudTest(cn, "Api Test");
55-
execSqlTest(cn, "Api Test");
56-
schemasTest(cn, "Api Test");
57-
extendedFormatTest(cn, "Api Test");
58-
59-
// Run ShortStudyTest with -Dclean=false
60-
datasetTest(cn, "StudyVerifyProject/My Study");
61-
62-
// Run NabAssayTest with -Dclean=false and rename subfolder "Rename############" to "nabassay"
63-
nabTest(cn, "/Nab Test Verify Project/nabassay");
64-
assayTest(cn, "/Nab Test Verify Project/nabassay");
65-
truncateAssayFailsTest(cn, "/Nab Test Verify Project/nabassay");
53+
// selectTest(cn, "Api Test");
54+
// crudTest(cn, "Api Test");
55+
// execSqlTest(cn, "Api Test");
56+
// schemasTest(cn, "Api Test");
57+
// extendedFormatTest(cn, "Api Test");
58+
//
59+
// // Run ShortStudyTest with -Dclean=false
60+
// datasetTest(cn, "StudyVerifyProject/My Study");
61+
//
62+
// // Run NabAssayTest with -Dclean=false and rename subfolder "Rename############" to "nabassay"
63+
// nabTest(cn, "/Nab Test Verify Project/nabassay");
64+
// assayTest(cn, "/Nab Test Verify Project/nabassay");
65+
// truncateAssayFailsTest(cn, "/Nab Test Verify Project/nabassay");
6666

6767
truncateTableSuccessTest(cn, "Api Test");
6868
System.out.println("*** All tests completed successfully ***");
@@ -142,9 +142,9 @@ public static void crudTest(Connection cn, String folder) throws Exception
142142
public static void truncateTableSuccessTest(Connection cn, String folder) throws Exception
143143
{
144144
TruncateTableCommand trunc = new TruncateTableCommand("lists", "People");
145-
SaveRowsResponse resp = trunc.execute(cn, folder);
145+
TruncateTableResponse resp = trunc.execute(cn, folder);
146146

147-
assert resp.getRowsAffected().intValue() == 9;
147+
assert resp.getDeletedRows().intValue() == 9;
148148
assert resp.getRows().size() == 0;
149149
}
150150

@@ -298,7 +298,7 @@ public static void truncateAssayFailsTest(Connection cn, String folder) throws E
298298
{
299299
TruncateTableCommand trunc = new TruncateTableCommand("assay.NAb.TestAssayNab", "WellData");
300300
try{
301-
SaveRowsResponse resp = trunc.execute(cn, folder);
301+
TruncateTableResponse resp = trunc.execute(cn, folder);
302302
throw new RuntimeException("Truncate table command should not succeed for tables other than lists," +
303303
"datasets, sample sets, data classes, and issues");
304304
}

0 commit comments

Comments
 (0)