Revision 61063
Added by Konstantinos Triantafyllou almost 3 years ago
RegistryCalls.java | ||
---|---|---|
115 | 115 |
} |
116 | 116 |
|
117 | 117 |
/** |
118 |
* 3. Get all OpenAIRE cous
|
|
118 |
* 3.1 Get OpenAIRE cous with a specific name(or substring)
|
|
119 | 119 |
*/ |
120 |
public JsonArray getCous() { |
|
120 |
public JsonArray getCous(String name) {
|
|
121 | 121 |
Map<String, String> params = new HashMap<>(); |
122 | 122 |
params.put("coid", coid); |
123 |
if(name != null) { |
|
124 |
params.put("name", name.toLowerCase()); |
|
125 |
} |
|
123 | 126 |
JsonElement response = httpUtils.get("cous.json", params); |
124 | 127 |
return (response != null) ? response.getAsJsonObject().get("Cous").getAsJsonArray() : new JsonArray(); |
125 | 128 |
} |
126 | 129 |
|
127 | 130 |
/** |
128 |
* 4. Get a couId by name |
|
131 |
* 3.2 Get all OpenAIRE cous |
|
132 |
*/ |
|
133 |
public JsonArray getCous() { |
|
134 |
return getCous(null); |
|
135 |
} |
|
136 |
|
|
137 |
/** |
|
138 |
* 4.1 Get a couId by name |
|
129 | 139 |
* |
130 | 140 |
* @param name |
131 | 141 |
* @return |
132 | 142 |
*/ |
133 | 143 |
public Integer getCouId(String name) { |
134 |
JsonArray cous = getCous(); |
|
144 |
JsonArray cous = getCous(name);
|
|
135 | 145 |
Integer couId = null; |
136 | 146 |
for (JsonElement cou : cous) { |
137 |
if (cou.getAsJsonObject().get("Name").getAsString().equals(name)) {
|
|
147 |
if (cou.getAsJsonObject().get("Name").getAsString().toLowerCase().equals(name.toLowerCase())) {
|
|
138 | 148 |
couId = cou.getAsJsonObject().get("Id").getAsInt(); |
139 | 149 |
} |
140 | 150 |
} |
... | ... | |
142 | 152 |
} |
143 | 153 |
|
144 | 154 |
/** |
145 |
* 4. Get a couId by type.id
|
|
155 |
* 4.2 Get a couId by type.id with/without mapping type
|
|
146 | 156 |
* |
147 | 157 |
* @param type |
148 | 158 |
* @param id |
149 | 159 |
* @return |
150 | 160 |
*/ |
151 |
public Integer getCouId(String type, String id) { |
|
152 |
return getCouId(type, id, true);
|
|
161 |
public Integer getCouId(String type, String id, boolean communityMap) {
|
|
162 |
return getCouId(mapType(type, communityMap) + "." + id);
|
|
153 | 163 |
} |
154 | 164 |
|
155 |
|
|
156 | 165 |
/** |
157 |
* 4. Get a couId by type.id without mapping type
|
|
166 |
* 4.3 Get a couId by type.id with mapping type
|
|
158 | 167 |
* |
159 | 168 |
* @param type |
160 | 169 |
* @param id |
161 | 170 |
* @return |
162 | 171 |
*/ |
163 |
public Integer getCouId(String type, String id, boolean communityMap) { |
|
164 |
JsonArray cous = getCous(); |
|
165 |
Integer couId = null; |
|
166 |
for (JsonElement cou : cous) { |
|
167 |
if (cou.getAsJsonObject().get("Name").getAsString().equals(mapType(type, communityMap) + "." + id)) { |
|
168 |
couId = cou.getAsJsonObject().get("Id").getAsInt(); |
|
169 |
} |
|
170 |
} |
|
171 |
return couId; |
|
172 |
public Integer getCouId(String type, String id) { |
|
173 |
return getCouId(type, id, true); |
|
172 | 174 |
} |
173 | 175 |
|
174 | 176 |
/** |
... | ... | |
354 | 356 |
/** |
355 | 357 |
* 17. Create a new role |
356 | 358 |
*/ |
357 |
public void createRole(Role role) { |
|
358 |
httpUtils.post("cous.json", jsonUtils.createNewCou(role)); |
|
359 |
public Integer createRole(Role role) { |
|
360 |
JsonElement element = httpUtils.post("cous.json", jsonUtils.createNewCou(role)); |
|
361 |
return element.getAsJsonObject().get("Id").getAsInt(); |
|
359 | 362 |
} |
360 | 363 |
|
361 | 364 |
/** |
Also available in: Unified diff
[Users | Trunk]: 1. Http utils: Encode params. 2. Registry calls: Add name parameter for getting cous base on a name. 3. Return coudId on role creation