Revision 53113
Added by Panagiotis Kanakakis over 5 years ago
RepositoryApiImpl.java | ||
---|---|---|
6 | 6 |
import eu.dnetlib.domain.data.Repository; |
7 | 7 |
import eu.dnetlib.domain.data.RepositoryInterface; |
8 | 8 |
import eu.dnetlib.domain.enabling.Vocabulary; |
9 |
import eu.dnetlib.repo.manager.service.domain.RepositorySnippet; |
|
9 | 10 |
import eu.dnetlib.repo.manager.service.domain.RequestFilter; |
10 | 11 |
import eu.dnetlib.repo.manager.service.exception.ResourceNotFoundException; |
11 | 12 |
import eu.dnetlib.repo.manager.service.utils.Converter; |
... | ... | |
35 | 36 |
import org.springframework.web.util.UriComponentsBuilder; |
36 | 37 |
|
37 | 38 |
import javax.annotation.PostConstruct; |
39 |
import java.io.IOException; |
|
38 | 40 |
import java.sql.Timestamp; |
39 | 41 |
import java.util.*; |
40 | 42 |
import java.util.concurrent.ConcurrentHashMap; |
... | ... | |
143 | 145 |
|
144 | 146 |
|
145 | 147 |
@Override |
146 |
public List<Repository> getRepositoriesByCountry(@PathVariable("country") String country, |
|
147 |
@PathVariable("mode") String mode, |
|
148 |
@RequestParam(value = "managed",required=false) Boolean managed) throws JSONException {
|
|
148 |
public List<RepositorySnippet> getRepositoriesByCountry(@PathVariable("country") String country,
|
|
149 |
@PathVariable("mode") String mode,
|
|
150 |
@RequestParam(value = "managed",required=false) Boolean managed) throws JSONException, IOException {
|
|
149 | 151 |
|
150 | 152 |
LOGGER.debug("Getting repositories by country!"); |
151 | 153 |
int page = 0; |
152 | 154 |
int size = 100; |
153 |
List<Repository> resultSet = new ArrayList<>(); |
|
155 |
List<RepositorySnippet> resultSet = new ArrayList<>(); |
|
156 |
ObjectMapper mapper = new ObjectMapper(); |
|
154 | 157 |
|
155 |
String countryCode = countriesMap.get(country); |
|
156 | 158 |
String filterKey = "UNKNOWN"; |
157 | 159 |
if (mode.equalsIgnoreCase("opendoar")) |
158 | 160 |
filterKey = "openaire____::opendoar"; |
... | ... | |
160 | 162 |
filterKey = "openaire____::re3data"; |
161 | 163 |
|
162 | 164 |
|
163 |
LOGGER.debug("Country code equals : " + countryCode);
|
|
165 |
LOGGER.debug("Country code equals : " + country); |
|
164 | 166 |
LOGGER.debug("Filter mode equals : " + filterKey); |
165 | 167 |
|
166 |
UriComponents uriComponents = searchDatasource(String.valueOf(page),String.valueOf(size)); |
|
168 |
UriComponents uriComponents = searchSnipperDatasource(String.valueOf(page),String.valueOf(size));
|
|
167 | 169 |
RequestFilter requestFilter = new RequestFilter(); |
168 |
requestFilter.setCountry(countryCode); |
|
170 |
requestFilter.setCountry(country); |
|
171 |
requestFilter.setCollectedfrom(filterKey); |
|
169 | 172 |
|
170 | 173 |
try{ |
171 | 174 |
String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class); |
172 | 175 |
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo"); |
173 | 176 |
while (jsonArray.length() > 0 ) { |
174 |
resultSet.addAll(this.getRepositoriesByMode(filterKey, Converter.jsonToRepositoryList(new JSONObject(rs)))); |
|
177 |
resultSet.addAll(mapper.readValue(String.valueOf(jsonArray), |
|
178 |
mapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class))); |
|
175 | 179 |
page += 1; |
176 |
uriComponents = searchDatasource(String.valueOf(page),String.valueOf(size)); |
|
180 |
uriComponents = searchSnipperDatasource(String.valueOf(page),String.valueOf(size));
|
|
177 | 181 |
rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class); |
178 | 182 |
jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo"); |
179 | 183 |
} |
180 |
for (Repository r : resultSet) |
|
181 |
this.updateRepositoryInfo(r); |
|
182 |
|
|
183 | 184 |
return resultSet; |
184 | 185 |
}catch (Exception e){ |
185 | 186 |
LOGGER.debug("Exception on getRepositoriesByCountry" , e); |
186 |
emailUtils.reportException(e); |
|
187 |
// emailUtils.reportException(e);
|
|
187 | 188 |
throw e; |
188 | 189 |
} |
189 | 190 |
|
... | ... | |
794 | 795 |
return UriComponentsBuilder |
795 | 796 |
.fromHttpUrl(baseAddress + "/ds/search/") |
796 | 797 |
.path("/{page}/{size}/") |
797 |
.queryParam("requestSortBy","id")
|
|
798 |
.queryParam("requestSortBy","officialname")
|
|
798 | 799 |
.queryParam("order","ASCENDING") |
799 | 800 |
.build().expand(page, size).encode(); |
800 | 801 |
} |
801 | 802 |
|
803 |
private UriComponents searchSnipperDatasource(String page,String size){ |
|
804 |
|
|
805 |
return UriComponentsBuilder |
|
806 |
.fromHttpUrl(baseAddress + "/ds/searchsnippet/") |
|
807 |
.path("/{page}/{size}/") |
|
808 |
.queryParam("requestSortBy","officialname") |
|
809 |
.queryParam("order","ASCENDING") |
|
810 |
.build().expand(page, size).encode(); |
|
811 |
} |
|
812 |
|
|
802 | 813 |
private String getRepositoryType(String typology){ |
803 | 814 |
return invertedDataSourceClass.get(typology); |
804 | 815 |
} |
Also available in: Unified diff
Add repository snippet methods