Skip to content

Commit 72b0db1

Browse files
committed
TestUser connection
1 parent f3ad888 commit 72b0db1

3 files changed

Lines changed: 39 additions & 1 deletion

File tree

src/org/labkey/test/util/TestUser.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.labkey.remoteapi.Connection;
55
import org.labkey.remoteapi.security.CreateUserResponse;
66
import org.labkey.test.WebDriverWrapper;
7+
import org.labkey.test.WebTestHelper;
78

89
import java.io.IOException;
910

@@ -102,6 +103,15 @@ public String getPassword()
102103
return _password;
103104
}
104105

106+
/**
107+
* Create a non-impersonating API connection for the user.
108+
* @return new Connection
109+
*/
110+
public Connection getUserConnection()
111+
{
112+
return new Connection(WebTestHelper.getBaseURL(), getEmail(), getPassword());
113+
}
114+
105115
public TestUser addPermission(String role, String containerPath)
106116
{
107117
new ApiPermissionsHelper(getWrapper()).addMemberToRole(getEmail(), role, PermissionsHelper.MemberType.user, containerPath);

src/org/labkey/test/util/exp/SampleTypeAPIHelper.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
import java.util.HashSet;
2121
import java.util.List;
2222
import java.util.Map;
23+
import java.util.NoSuchElementException;
2324
import java.util.TreeMap;
25+
import java.util.stream.Collectors;
2426

2527
public class SampleTypeAPIHelper
2628
{
@@ -177,4 +179,30 @@ public static Map<String, Integer> getRowIdsForSamples(String containerPath, Str
177179
return rowIds;
178180
}
179181

182+
/**
183+
* Get sample state IDs defined in the specified folder. Useful for updating sample status via API
184+
* @param containerPath Path to the folder where the sample statuses are defined
185+
*/
186+
public static Map<String, Integer> getSampleStateIds(String containerPath) throws IOException, CommandException
187+
{
188+
Connection cn = WebTestHelper.getRemoteApiConnection();
189+
SelectRowsCommand insertCmd = new SelectRowsCommand("core", "DataStates");
190+
return insertCmd.execute(cn, containerPath).getRows().stream().collect(Collectors.toMap(row ->
191+
(String) row.get("label"), row -> (Integer) row.get("rowId")));
192+
}
193+
194+
/**
195+
* Get sample state ID defined in the specified folder. Useful for updating sample status via API
196+
* @param name Label of the sample state
197+
* @param containerPath Path to the folder where the sample statuses are defined
198+
*/
199+
public static Integer getSampleStateId(String name, String containerPath) throws IOException, CommandException
200+
{
201+
Map<String, Integer> sampleStateIds = getSampleStateIds(containerPath);
202+
if(sampleStateIds.containsKey(name))
203+
return sampleStateIds.get(name);
204+
else
205+
throw new NoSuchElementException("Sample state '%s' not defined in '%s': %s".formatted(name, containerPath, sampleStateIds.keySet()));
206+
}
207+
180208
}

src/org/labkey/test/util/query/QueryApiHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public <T> RowsResponse updateRows(List<Map<String, T>> rows) throws IOException
105105
return updateRowsCommand.execute(_connection, _containerPath);
106106
}
107107

108-
public <T> RowsResponse moveRows(String targetContainerPath, List<Map<String, T>> rows) throws IOException, CommandException
108+
public <T> RowsResponse moveRows(List<Map<String, T>> rows, String targetContainerPath) throws IOException, CommandException
109109
{
110110
MoveRowsCommand moveRowsCommand = new MoveRowsCommand(targetContainerPath, _schema, _query);
111111
moveRowsCommand.setRows(makeApiRows(rows));

0 commit comments

Comments
 (0)