Skip to content
Snippets Groups Projects
Commit 6cd07c97 authored by Raj Sundararajan's avatar Raj Sundararajan
Browse files

use rcp service to get users for rcpuser role setting

parent eb880c28
Branches
No related tags found
No related merge requests found
......@@ -36,10 +36,6 @@ public class SvcUserRcpUsrRoleSet extends PluginService {
public SvcUserRcpUsrRoleSet() throws Throwable {
_defn = new Interface();
_defn.add(new Interface.Element("rcp-url", StringType.DEFAULT,
"Url for the rcp api", 1, 1));
_defn.add(new Interface.Element("api-key", StringType.DEFAULT,
"Api key to access rcp api", 1, 1));
}
public Access access() {
......@@ -62,16 +58,12 @@ public class SvcUserRcpUsrRoleSet extends PluginService {
public void execute(XmlDoc.Element args, Inputs inputs, Outputs outputs, final XmlWriter w) throws Throwable {
removeRCPUsrRole();
String rcpUrl = args.stringValue("rcp-url");
String api_key = args.stringValue("api-key");
String response = getRcpUsers(rcpUrl,api_key);
Collection<XmlDoc.Element> response = getRcpUsers();
//w.add("rcpusers",response);
JSONObject jsonObject = new JSONObject(response);
for (Iterator<String> it = jsonObject.keys(); it.hasNext(); ) {
JSONObject j = jsonObject.getJSONObject(it.next());
String path = j.getString("path");
String rcao = j.getString("rcao");
Collection<String> users = getStringListFromJsonArray(j.getJSONArray("users_with_manage_resources_permission"));
for (XmlDoc.Element element : response) {
String path = element.value("path");
String rcao = element.value("rcao");
Collection<String> users = element.values("users-with-manage-resources-permission/user");
users.add(rcao);
String projectRole = Project.actualRoleName(path, Project.ProjectRoleType.RCPUSR);
for (String userEmail : users) {
......@@ -135,31 +127,17 @@ public class SvcUserRcpUsrRoleSet extends PluginService {
}
}
public Collection<String> getStringListFromJsonArray(JSONArray array){
Collection<String> list = new ArrayList<String>();
for (int i = 0; i < array.length(); i++) {
String s = array.getString(i);
list.add(s);
}
return list;
}
public String getRcpUsers(String rcpUrl,String apiKey) throws IOException, InterruptedException {
//https://rcp.research.unimelb.edu.au/data_resources/get_users_access/mediaflux
URL url = new URL(rcpUrl);
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestMethod("GET");
httpConn.setRequestProperty("Authorization", "Api-Key "+apiKey);
public Collection<XmlDoc.Element> getRcpUsers() throws Throwable {
//unimelb.rcp.allocation.users.list :product mediaflux
XmlDocMaker dm = new XmlDocMaker("args");
dm.add("product", "mediaflux");
InputStream responseStream = httpConn.getResponseCode() / 100 == 2
? httpConn.getInputStream()
: httpConn.getErrorStream();
Scanner s = new Scanner(responseStream).useDelimiter("\\A");
String response = s.hasNext() ? s.next() : "";
XmlDoc.Element r = executor().execute("unimelb.rcp.allocation.users.list", dm.root());
Collection<XmlDoc.Element> allocations = r.elements("allocation");
return response;
return allocations;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment