Revision 49790
Added by Panagiotis Kanakakis over 6 years ago
RepositoryApiImpl.java | ||
---|---|---|
108 | 108 |
|
109 | 109 |
|
110 | 110 |
@Override |
111 |
public Set<String> getRepositoriesByCountry(@PathVariable("country") String country) throws JSONException { |
|
111 |
public List<Repository> getRepositoriesByCountry(@PathVariable("country") String country, |
|
112 |
@PathVariable("country") String mode) throws JSONException { |
|
112 | 113 |
|
113 |
|
|
114 |
LOGGER.debug("Getting repositories by country!"); |
|
114 | 115 |
int page = 1; |
115 | 116 |
int size = 10; |
116 |
String mode = "openaire____::opendoar";
|
|
117 |
String countryCode = getCountryCode(country);
|
|
117 | 118 |
|
119 |
|
|
120 |
LOGGER.debug("Country code equals : " + countryCode); |
|
118 | 121 |
UriComponents uriComponents = UriComponentsBuilder |
119 | 122 |
.fromHttpUrl(baseAddress + "/ds/search/country/") |
120 | 123 |
.path("/{page}/{size}/") |
... | ... | |
122 | 125 |
.build().expand(page,size).encode(); |
123 | 126 |
|
124 | 127 |
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class); |
125 |
Set<String> resultSet = new HashSet<>();
|
|
128 |
List<Repository> resultSet = new ArrayList<>();
|
|
126 | 129 |
while(!rs.equals("[]")){ |
127 | 130 |
List<Repository> rep = Converter.jsonToRepositoryList(new JSONArray(rs)); |
128 | 131 |
|
129 |
Collection<String> repos = this.getRepositoriesByMode(mode,rep); |
|
130 |
this.addRepos(resultSet,repos); |
|
131 |
|
|
132 |
Collection<Repository> repos = this.getRepositoriesByMode(mode,rep); |
|
133 |
//this.addRepos(repIDs,repos); |
|
134 |
resultSet.addAll(repos); |
|
135 |
|
|
132 | 136 |
page+=1; |
133 | 137 |
uriComponents = UriComponentsBuilder |
134 | 138 |
.fromHttpUrl(baseAddress + "/ds/search/country/") |
135 | 139 |
.path("/{page}/{size}/") |
136 |
.queryParam("country",country) |
|
140 |
.queryParam("country",countryCode)
|
|
137 | 141 |
.build().expand(page,size).encode(); |
138 | 142 |
rs = restTemplate.getForObject(uriComponents.toUri(), String.class); |
139 | 143 |
} |
140 |
|
|
141 | 144 |
return resultSet; |
142 | 145 |
} |
143 | 146 |
|
147 |
private String getCountryCode(String country) { |
|
148 |
|
|
149 |
Country[] countries = getCountries(); |
|
150 |
for(Country c : countries) |
|
151 |
if(c.getName().equals(country)) |
|
152 |
return c.getCode(); |
|
153 |
return country; |
|
154 |
} |
|
155 |
|
|
144 | 156 |
private void addRepos(Set<String> resultSet, Collection<String> repos) { |
145 | 157 |
for(String s : repos) |
146 | 158 |
if(!resultSet.contains(s)) |
147 | 159 |
resultSet.add(s); |
148 | 160 |
} |
149 | 161 |
|
150 |
private Collection<String> getRepositoriesByMode(String mode, List<Repository> rs) {
|
|
162 |
private Collection<Repository> getRepositoriesByMode(String mode, List<Repository> rs) {
|
|
151 | 163 |
|
152 |
List<String> reps = new ArrayList<>();
|
|
164 |
List<Repository> reps = new ArrayList<>();
|
|
153 | 165 |
|
154 | 166 |
for(Repository r : rs) |
155 | 167 |
if(r.getCollectedFrom().equals(mode)) |
156 |
reps.add(r.getOfficialName());
|
|
168 |
reps.add(r); |
|
157 | 169 |
|
158 | 170 |
return reps; |
159 | 171 |
} |
... | ... | |
170 | 182 |
.queryParam("contactemail",userEmail) |
171 | 183 |
.build().expand(page,size).encode(); |
172 | 184 |
|
173 |
LOGGER.debug("URI -> " + uriComponents.toUri()); |
|
174 | 185 |
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class); |
175 |
LOGGER.debug("Repositories are : " + rs); |
|
176 | 186 |
return Converter.jsonToRepositoryList(new JSONArray(rs)); |
177 | 187 |
} |
178 | 188 |
|
... | ... | |
375 | 385 |
return vocabularyMap.get(vocName); |
376 | 386 |
} |
377 | 387 |
|
388 |
|
|
389 |
@Override |
|
390 |
public Map<String, String> getCompatibilityClasses(@PathVariable("mode") String mode) { |
|
391 |
|
|
392 |
LOGGER.debug("Getting compatibility classes for mode: " + mode); |
|
393 |
Map<String, String> retMap = new HashMap<String, String>(); |
|
394 |
|
|
395 |
Map<String, String> compatibilityClasses = this.getVocabulary("dnet:compatibilityLevel").getAsMap(); |
|
396 |
boolean foundData = false; |
|
397 |
for (Map.Entry<String, String> entry : compatibilityClasses.entrySet()) { |
|
398 |
if (mode.equalsIgnoreCase(Constants.REPOSITORY_MODE_ALL)) |
|
399 |
return compatibilityClasses; |
|
400 |
else if (mode.equalsIgnoreCase(Constants.REPOSITORY_MODE_RE3DATA)) { |
|
401 |
if (entry.getKey().matches("^openaire[1-9].0_data$")) { |
|
402 |
retMap.put(entry.getKey(), entry.getValue()); |
|
403 |
foundData = true; |
|
404 |
} |
|
405 |
} else { |
|
406 |
if (entry.getKey().matches("^openaire[1-9].0$") || entry.getKey().equals("driver")) |
|
407 |
retMap.put(entry.getKey(), entry.getValue()); |
|
408 |
} |
|
409 |
} |
|
410 |
|
|
411 |
//TODO TO BE REMOVED WHEN VOCABULARIES ARE UPDATED |
|
412 |
if (mode.equalsIgnoreCase(Constants.REPOSITORY_MODE_RE3DATA) && !foundData) |
|
413 |
retMap.put("openaire2.0_data", "OpenAIRE Data (funded, referenced datasets)"); |
|
414 |
|
|
415 |
return retMap; |
|
416 |
} |
|
417 |
|
|
418 |
@Override |
|
419 |
public Map<String, String> getDatasourceClasses(@PathVariable("mode") String mode) { |
|
420 |
|
|
421 |
LOGGER.debug("Getting datasource classes for mode: " + mode); |
|
422 |
|
|
423 |
Map<String, String> retMap = new HashMap<String, String>(); |
|
424 |
|
|
425 |
for (Map.Entry<String, String> entry : this.getVocabulary("dnet:datasource_typologies").getAsMap().entrySet()) { |
|
426 |
if (mode.equalsIgnoreCase("aggregator")) { |
|
427 |
if (entry.getKey().contains("aggregator")) |
|
428 |
retMap.put(entry.getKey(), entry.getValue()); |
|
429 |
} else if (mode.equalsIgnoreCase("journal")) { |
|
430 |
if (entry.getKey().contains("journal")) |
|
431 |
retMap.put(entry.getKey(), entry.getValue()); |
|
432 |
} else if (mode.equalsIgnoreCase("opendoar")) { |
|
433 |
if (entry.getKey().contains("pubsrepository")) |
|
434 |
retMap.put(entry.getKey(), entry.getValue()); |
|
435 |
} else if (mode.equalsIgnoreCase("re3data")) { |
|
436 |
if (entry.getKey().contains("datarepository")) |
|
437 |
retMap.put(entry.getKey(), entry.getValue()); |
|
438 |
} |
|
439 |
} |
|
440 |
return retMap; |
|
441 |
|
|
442 |
} |
|
443 |
|
|
378 | 444 |
} |
Also available in: Unified diff
1. Create method to convert country names -> country codes
2. Create methods for : getDatasourceClasses , getCompatibilityClasses