1 |
54525
|
panagiotis
|
package eu.dnetlib.repo.manager.service;
|
2 |
49236
|
panagiotis
|
|
3 |
51549
|
panagiotis
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
4 |
61441
|
antonis.le
|
import com.google.gson.JsonArray;
|
5 |
|
|
import com.google.gson.JsonElement;
|
6 |
|
|
import com.google.gson.JsonObject;
|
7 |
56636
|
antonis.le
|
import eu.dnetlib.api.functionality.ValidatorServiceException;
|
8 |
50051
|
panagiotis
|
import eu.dnetlib.domain.data.Repository;
|
9 |
|
|
import eu.dnetlib.domain.data.RepositoryInterface;
|
10 |
49450
|
panagiotis
|
import eu.dnetlib.domain.enabling.Vocabulary;
|
11 |
56636
|
antonis.le
|
import eu.dnetlib.domain.functionality.validator.JobForValidation;
|
12 |
57741
|
ioannis.di
|
import eu.dnetlib.repo.manager.domain.*;
|
13 |
61441
|
antonis.le
|
import eu.dnetlib.repo.manager.domain.dto.Role;
|
14 |
54525
|
panagiotis
|
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
|
15 |
61441
|
antonis.le
|
import eu.dnetlib.repo.manager.service.aai.registry.AaiRegistryService;
|
16 |
|
|
import eu.dnetlib.repo.manager.service.security.AuthoritiesUpdater;
|
17 |
|
|
import eu.dnetlib.repo.manager.service.security.AuthorizationService;
|
18 |
|
|
import eu.dnetlib.repo.manager.service.security.RoleMappingService;
|
19 |
54525
|
panagiotis
|
import eu.dnetlib.repo.manager.utils.Converter;
|
20 |
49450
|
panagiotis
|
import gr.uoa.di.driver.enabling.vocabulary.VocabularyLoader;
|
21 |
50570
|
panagiotis
|
import org.apache.commons.codec.digest.DigestUtils;
|
22 |
49763
|
panagiotis
|
import org.apache.log4j.Logger;
|
23 |
49236
|
panagiotis
|
import org.json.JSONArray;
|
24 |
49362
|
panagiotis
|
import org.json.JSONException;
|
25 |
49236
|
panagiotis
|
import org.json.JSONObject;
|
26 |
61441
|
antonis.le
|
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
|
27 |
49450
|
panagiotis
|
import org.springframework.beans.factory.annotation.Autowired;
|
28 |
49236
|
panagiotis
|
import org.springframework.beans.factory.annotation.Value;
|
29 |
61441
|
antonis.le
|
import org.springframework.context.annotation.Lazy;
|
30 |
50570
|
panagiotis
|
import org.springframework.core.ParameterizedTypeReference;
|
31 |
53933
|
panagiotis
|
import org.springframework.http.*;
|
32 |
49245
|
panagiotis
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
33 |
53933
|
panagiotis
|
import org.springframework.security.core.Authentication;
|
34 |
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
35 |
54525
|
panagiotis
|
import org.springframework.stereotype.Service;
|
36 |
61441
|
antonis.le
|
import org.springframework.web.client.HttpClientErrorException;
|
37 |
50570
|
panagiotis
|
import org.springframework.web.client.RestClientException;
|
38 |
49245
|
panagiotis
|
import org.springframework.web.client.RestTemplate;
|
39 |
49304
|
panagiotis
|
import org.springframework.web.util.UriComponents;
|
40 |
49245
|
panagiotis
|
import org.springframework.web.util.UriComponentsBuilder;
|
41 |
50051
|
panagiotis
|
|
42 |
49304
|
panagiotis
|
import javax.annotation.PostConstruct;
|
43 |
53113
|
panagiotis
|
import java.io.IOException;
|
44 |
49960
|
panagiotis
|
import java.sql.Timestamp;
|
45 |
49450
|
panagiotis
|
import java.util.*;
|
46 |
|
|
import java.util.concurrent.ConcurrentHashMap;
|
47 |
52781
|
panagiotis
|
import java.util.stream.Collectors;
|
48 |
49236
|
panagiotis
|
|
49 |
54525
|
panagiotis
|
@Service("repositoryService")
|
50 |
54690
|
panagiotis
|
public class RepositoryServiceImpl implements RepositoryService {
|
51 |
49236
|
panagiotis
|
|
52 |
61441
|
antonis.le
|
private static final Logger LOGGER = Logger.getLogger(RepositoryServiceImpl.class);
|
53 |
|
|
|
54 |
|
|
private final AuthorizationService authorizationService;
|
55 |
|
|
private final RoleMappingService roleMappingService;
|
56 |
|
|
private final AaiRegistryService registryCalls;
|
57 |
|
|
private final AuthoritiesUpdater authoritiesUpdater;
|
58 |
|
|
private final RestTemplate restTemplate;
|
59 |
|
|
private final VocabularyLoader vocabularyLoader;
|
60 |
|
|
private final PiWikService piWikService;
|
61 |
|
|
private final EmailUtils emailUtils;
|
62 |
|
|
private final ValidatorService validatorService;
|
63 |
|
|
|
64 |
49304
|
panagiotis
|
@Value("${api.baseAddress}")
|
65 |
49236
|
panagiotis
|
private String baseAddress;
|
66 |
|
|
|
67 |
56636
|
antonis.le
|
@Value("${services.repo-manager.adminEmail}")
|
68 |
|
|
private String adminEmail;
|
69 |
|
|
|
70 |
50570
|
panagiotis
|
@Value("${services.repomanager.usageStatisticsDiagramsBaseURL}")
|
71 |
|
|
private String usageStatisticsDiagramsBaseURL;
|
72 |
|
|
|
73 |
|
|
@Value("${services.repomanager.usageStatisticsNumbersBaseURL}")
|
74 |
|
|
private String usageStatisticsNumbersBaseURL;
|
75 |
|
|
|
76 |
49450
|
panagiotis
|
|
77 |
61441
|
antonis.le
|
private static final Map<String, List<String>> dataSourceClass = new HashMap<>();
|
78 |
|
|
private static final Map<String, String> invertedDataSourceClass = new HashMap<>();
|
79 |
50219
|
panagiotis
|
|
80 |
51831
|
panagiotis
|
|
81 |
61441
|
antonis.le
|
private final String[] vocabularyNames = {"dnet:countries", "dnet:datasource_typologies", "dnet:compatibilityLevel"};
|
82 |
|
|
private final Map<String, Vocabulary> vocabularyMap = new ConcurrentHashMap<>();
|
83 |
|
|
private final Map<String, String> countriesMap = new HashMap<>();
|
84 |
|
|
private final Map<String, String> inverseCountriesMap = new HashMap<>();
|
85 |
54702
|
panagiotis
|
|
86 |
61441
|
antonis.le
|
private HttpHeaders httpHeaders;
|
87 |
56636
|
antonis.le
|
|
88 |
61441
|
antonis.le
|
@Autowired
|
89 |
|
|
public RepositoryServiceImpl(AuthorizationService authorizationService,
|
90 |
|
|
RoleMappingService roleMappingService,
|
91 |
|
|
AaiRegistryService registryCalls,
|
92 |
|
|
AuthoritiesUpdater authoritiesUpdater,
|
93 |
|
|
VocabularyLoader vocabularyLoader,
|
94 |
|
|
RestTemplate restTemplate,
|
95 |
|
|
@Lazy EmailUtils emailUtils,
|
96 |
|
|
@Lazy ValidatorService validatorService,
|
97 |
|
|
@Lazy PiWikService piWikService) {
|
98 |
|
|
this.authorizationService = authorizationService;
|
99 |
|
|
this.roleMappingService = roleMappingService;
|
100 |
|
|
this.registryCalls = registryCalls;
|
101 |
|
|
this.authoritiesUpdater = authoritiesUpdater;
|
102 |
|
|
this.vocabularyLoader = vocabularyLoader;
|
103 |
|
|
this.piWikService = piWikService;
|
104 |
|
|
this.emailUtils = emailUtils;
|
105 |
|
|
this.validatorService = validatorService;
|
106 |
|
|
this.restTemplate = restTemplate;
|
107 |
|
|
}
|
108 |
49450
|
panagiotis
|
|
109 |
61441
|
antonis.le
|
private String getAuthenticatedUserEmail() {
|
110 |
|
|
OIDCAuthenticationToken authenticationToken = (OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
|
111 |
|
|
return authenticationToken.getUserInfo().getEmail();
|
112 |
|
|
}
|
113 |
49450
|
panagiotis
|
|
114 |
49898
|
panagiotis
|
|
115 |
49304
|
panagiotis
|
@PostConstruct
|
116 |
49960
|
panagiotis
|
private void init() {
|
117 |
49770
|
panagiotis
|
LOGGER.debug("Initialization method of repository api!");
|
118 |
53933
|
panagiotis
|
LOGGER.debug("Updated version!");
|
119 |
49770
|
panagiotis
|
|
120 |
61441
|
antonis.le
|
dataSourceClass.put("opendoar", Arrays.asList("pubsrepository::institutional", "pubsrepository::thematic", "pubsrepository::unknown", "pubsrepository::mock"));
|
121 |
56766
|
ioannis.di
|
dataSourceClass.put("re3data", Collections.singletonList("datarepository::unknown"));
|
122 |
|
|
dataSourceClass.put("journal", Collections.singletonList("pubsrepository::journal"));
|
123 |
61441
|
antonis.le
|
dataSourceClass.put("aggregator", Arrays.asList("aggregator::pubsrepository::institutional", "aggregator::pubsrepository::journals", "aggregator::datarepository", "aggregator::pubsrepository::unknown"));
|
124 |
56766
|
ioannis.di
|
|
125 |
61441
|
antonis.le
|
invertedDataSourceClass.put("pubsrepository::institutional", "opendoar");
|
126 |
|
|
invertedDataSourceClass.put("pubsrepository::thematic", "opendoar");
|
127 |
|
|
invertedDataSourceClass.put("pubsrepository::unknown", "opendoar");
|
128 |
|
|
invertedDataSourceClass.put("pubsrepository::mock", "opendoar");
|
129 |
|
|
invertedDataSourceClass.put("datarepository::unknown", "re3data");
|
130 |
|
|
invertedDataSourceClass.put("pubsrepository::journal", "journal");
|
131 |
|
|
invertedDataSourceClass.put("aggregator::pubsrepository::institutional", "aggregator");
|
132 |
|
|
invertedDataSourceClass.put("aggregator::pubsrepository::journals", "aggregator");
|
133 |
|
|
invertedDataSourceClass.put("aggregator::datarepository", "aggregator");
|
134 |
|
|
invertedDataSourceClass.put("aggregator::pubsrepository::unknown", "aggregator");
|
135 |
56766
|
ioannis.di
|
|
136 |
|
|
|
137 |
55039
|
panagiotis
|
httpHeaders = new HttpHeaders();
|
138 |
55066
|
panagiotis
|
httpHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8);
|
139 |
49450
|
panagiotis
|
|
140 |
|
|
for (String vocName : vocabularyNames) {
|
141 |
|
|
vocabularyMap.put(vocName, vocabularyLoader.getVocabulary(vocName, Locale.ENGLISH, Locale.ROOT));
|
142 |
|
|
}
|
143 |
|
|
|
144 |
49898
|
panagiotis
|
Country[] countries = getCountries();
|
145 |
49960
|
panagiotis
|
for (Country c : countries) {
|
146 |
|
|
countriesMap.put(c.getName(), c.getCode());
|
147 |
|
|
inverseCountriesMap.put(c.getCode(), c.getName());
|
148 |
49898
|
panagiotis
|
}
|
149 |
|
|
|
150 |
|
|
|
151 |
49304
|
panagiotis
|
}
|
152 |
|
|
|
153 |
49236
|
panagiotis
|
@Override
|
154 |
49960
|
panagiotis
|
public Country[] getCountries() {
|
155 |
49304
|
panagiotis
|
UriComponents uriComponents = UriComponentsBuilder
|
156 |
|
|
.fromHttpUrl(baseAddress + "/ds/countries")
|
157 |
|
|
.build().encode();
|
158 |
49960
|
panagiotis
|
return restTemplate.getForObject(uriComponents.toUri(), Country[].class);
|
159 |
49236
|
panagiotis
|
}
|
160 |
61441
|
antonis.le
|
|
161 |
|
|
// FIXME: with the new roles of the users the "requestFilter.setRegisteredby(userEmail)" can no longer be used
|
162 |
|
|
// and the "requestFilter.setId(repoId)" should return only one result at a time, thus,
|
163 |
|
|
// another way for paging must be implemented.
|
164 |
|
|
@Override
|
165 |
|
|
public List<Repository> getRepositories(List<String> ids) throws JSONException {
|
166 |
|
|
return getRepositories(ids, 0, 10);
|
167 |
|
|
}
|
168 |
49236
|
panagiotis
|
|
169 |
61441
|
antonis.le
|
// FIXME: with the new roles of the users the "requestFilter.setRegisteredby(userEmail)" can no longer be used
|
170 |
|
|
// and the "requestFilter.setId(repoId)" should return only one result at a time, thus,
|
171 |
|
|
// another way for paging must be implemented.
|
172 |
|
|
@Override
|
173 |
|
|
public List<Repository> getRepositories(List<String> ids, int page, int size) throws JSONException {
|
174 |
|
|
List<Repository> repos = new ArrayList<>();
|
175 |
|
|
LOGGER.debug("Retreiving repositories with ids : " + String.join(", ", ids));
|
176 |
|
|
UriComponents uriComponents = searchDatasource(Integer.toString(Math.abs(page)), Integer.toString(Math.abs(size)));
|
177 |
|
|
RequestFilter requestFilter = new RequestFilter();
|
178 |
49236
|
panagiotis
|
|
179 |
61441
|
antonis.le
|
try {
|
180 |
|
|
for (String repoId : ids) {
|
181 |
|
|
requestFilter.setId(repoId);
|
182 |
|
|
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
183 |
|
|
|
184 |
|
|
repos.addAll(Converter.jsonToRepositoryList(new JSONObject(rs)));
|
185 |
|
|
}
|
186 |
|
|
} catch (JSONException e) {
|
187 |
|
|
LOGGER.debug("Exception on getRepositoriesOfUser", e);
|
188 |
|
|
emailUtils.reportException(e);
|
189 |
|
|
throw e;
|
190 |
|
|
}
|
191 |
|
|
|
192 |
|
|
for (Repository r : repos)
|
193 |
|
|
r.setPiwikInfo(piWikService.getPiwikSiteForRepo(r.getId()));
|
194 |
|
|
return repos;
|
195 |
|
|
}
|
196 |
|
|
|
197 |
|
|
// FIXME: with the new roles of the users the "requestFilter.setRegisteredby(userEmail)" can no longer be used
|
198 |
|
|
// and the "requestFilter.setId(repoId)" should return only one result at a time, thus,
|
199 |
|
|
// another way for paging must be implemented.
|
200 |
49236
|
panagiotis
|
@Override
|
201 |
61441
|
antonis.le
|
public List<RepositorySnippet> getRepositoriesSnippets(List<String> ids) throws Exception {
|
202 |
|
|
return getRepositoriesSnippets(ids, 0, 10);
|
203 |
|
|
}
|
204 |
|
|
|
205 |
|
|
// FIXME: with the new roles of the users the "requestFilter.setRegisteredby(userEmail)" can no longer be used
|
206 |
|
|
// and the "requestFilter.setId(repoId)" should return only one result at a time, thus,
|
207 |
|
|
// another way for paging must be implemented.
|
208 |
|
|
@Override
|
209 |
|
|
public List<RepositorySnippet> getRepositoriesSnippets(List<String> ids, int page, int size) throws Exception {
|
210 |
|
|
List<RepositorySnippet> resultSet = new ArrayList<>();
|
211 |
|
|
ObjectMapper mapper = new ObjectMapper();
|
212 |
|
|
|
213 |
|
|
// here page should be 0
|
214 |
|
|
UriComponents uriComponents = searchSnipperDatasource(Integer.toString(Math.abs(page)), Integer.toString(Math.abs(size)));
|
215 |
|
|
RequestFilter requestFilter = new RequestFilter();
|
216 |
|
|
|
217 |
|
|
try {
|
218 |
|
|
for (String repoId : ids) {
|
219 |
|
|
requestFilter.setId(repoId);
|
220 |
|
|
|
221 |
|
|
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
222 |
|
|
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
|
223 |
|
|
resultSet.addAll(mapper.readValue(String.valueOf(jsonArray),
|
224 |
|
|
mapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class)));
|
225 |
|
|
}
|
226 |
|
|
} catch (Exception e) {
|
227 |
|
|
LOGGER.debug("Exception on getRepositoriesSnippetOfUser", e);
|
228 |
|
|
throw e;
|
229 |
|
|
}
|
230 |
|
|
|
231 |
|
|
LOGGER.debug("resultSet:" + resultSet);
|
232 |
|
|
resultSet.parallelStream().forEach(repositorySnippet -> {
|
233 |
|
|
repositorySnippet.setPiwikInfo(piWikService.getPiwikSiteForRepo(repositorySnippet.getId()));
|
234 |
|
|
});
|
235 |
|
|
return resultSet;
|
236 |
|
|
}
|
237 |
|
|
|
238 |
|
|
|
239 |
|
|
@Override
|
240 |
56761
|
ioannis.di
|
public List<RepositorySnippet> getRepositoriesByCountry(String country,
|
241 |
|
|
String mode,
|
242 |
|
|
Boolean managed) throws JSONException, IOException {
|
243 |
49245
|
panagiotis
|
|
244 |
49790
|
panagiotis
|
LOGGER.debug("Getting repositories by country!");
|
245 |
49898
|
panagiotis
|
int page = 0;
|
246 |
|
|
int size = 100;
|
247 |
53113
|
panagiotis
|
List<RepositorySnippet> resultSet = new ArrayList<>();
|
248 |
|
|
ObjectMapper mapper = new ObjectMapper();
|
249 |
49898
|
panagiotis
|
|
250 |
49813
|
panagiotis
|
String filterKey = "UNKNOWN";
|
251 |
51525
|
panagiotis
|
if (mode.equalsIgnoreCase("opendoar"))
|
252 |
49813
|
panagiotis
|
filterKey = "openaire____::opendoar";
|
253 |
51525
|
panagiotis
|
else if (mode.equalsIgnoreCase("re3data"))
|
254 |
49813
|
panagiotis
|
filterKey = "openaire____::re3data";
|
255 |
49431
|
panagiotis
|
|
256 |
51525
|
panagiotis
|
|
257 |
53113
|
panagiotis
|
LOGGER.debug("Country code equals : " + country);
|
258 |
49813
|
panagiotis
|
LOGGER.debug("Filter mode equals : " + filterKey);
|
259 |
51525
|
panagiotis
|
|
260 |
61441
|
antonis.le
|
UriComponents uriComponents = searchSnipperDatasource(String.valueOf(page), String.valueOf(size));
|
261 |
50631
|
panagiotis
|
RequestFilter requestFilter = new RequestFilter();
|
262 |
53113
|
panagiotis
|
requestFilter.setCountry(country);
|
263 |
|
|
requestFilter.setCollectedfrom(filterKey);
|
264 |
49245
|
panagiotis
|
|
265 |
61441
|
antonis.le
|
try {
|
266 |
|
|
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
267 |
51831
|
panagiotis
|
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
|
268 |
61441
|
antonis.le
|
while (jsonArray.length() > 0) {
|
269 |
53113
|
panagiotis
|
resultSet.addAll(mapper.readValue(String.valueOf(jsonArray),
|
270 |
|
|
mapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class)));
|
271 |
51831
|
panagiotis
|
page += 1;
|
272 |
61441
|
antonis.le
|
uriComponents = searchSnipperDatasource(String.valueOf(page), String.valueOf(size));
|
273 |
|
|
rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
274 |
51831
|
panagiotis
|
jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
|
275 |
|
|
}
|
276 |
|
|
return resultSet;
|
277 |
61441
|
antonis.le
|
} catch (Exception e) {
|
278 |
|
|
LOGGER.debug("Exception on getRepositoriesByCountry", e);
|
279 |
53113
|
panagiotis
|
// emailUtils.reportException(e);
|
280 |
51831
|
panagiotis
|
throw e;
|
281 |
49431
|
panagiotis
|
}
|
282 |
56636
|
antonis.le
|
}
|
283 |
50075
|
panagiotis
|
|
284 |
56636
|
antonis.le
|
public List<RepositorySnippet> searchRegisteredRepositories(String country, String typology, String englishName,
|
285 |
61441
|
antonis.le
|
String officialName, String requestSortBy, String order, int page, int pageSize) throws Exception {
|
286 |
51831
|
panagiotis
|
|
287 |
56636
|
antonis.le
|
LOGGER.debug("Searching registered repositories");
|
288 |
|
|
|
289 |
|
|
List<RepositorySnippet> resultSet = new ArrayList<>();
|
290 |
|
|
ObjectMapper mapper = new ObjectMapper();
|
291 |
|
|
|
292 |
|
|
UriComponents uriComponents = searchRegisteredDatasource(requestSortBy, order, Integer.toString(page), Integer.toString(pageSize));
|
293 |
|
|
|
294 |
|
|
RequestFilter requestFilter = new RequestFilter();
|
295 |
|
|
requestFilter.setCountry(country);
|
296 |
|
|
requestFilter.setTypology(typology);
|
297 |
|
|
requestFilter.setOfficialname(officialName);
|
298 |
|
|
requestFilter.setEnglishname(englishName);
|
299 |
|
|
|
300 |
|
|
try {
|
301 |
61441
|
antonis.le
|
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
302 |
56636
|
antonis.le
|
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
|
303 |
|
|
|
304 |
61441
|
antonis.le
|
resultSet.addAll(mapper.readValue(String.valueOf(jsonArray), mapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class)));
|
305 |
56636
|
antonis.le
|
|
306 |
61441
|
antonis.le
|
return resultSet;
|
307 |
|
|
} catch (Exception e) {
|
308 |
|
|
LOGGER.error("Error searching registered datasources", e);
|
309 |
56636
|
antonis.le
|
throw e;
|
310 |
|
|
}
|
311 |
49236
|
panagiotis
|
}
|
312 |
|
|
|
313 |
52781
|
panagiotis
|
private Repository updateRepositoryInfo(Repository r) throws JSONException {
|
314 |
51549
|
panagiotis
|
|
315 |
|
|
/*
|
316 |
61441
|
antonis.le
|
* from datasource class
|
317 |
|
|
* we get the datasource type form the inverted map
|
318 |
|
|
* */
|
319 |
51549
|
panagiotis
|
r.setDatasourceType(getRepositoryType(r.getDatasourceClass()));
|
320 |
50219
|
panagiotis
|
r.setInterfaces(this.getRepositoryInterface(r.getId()));
|
321 |
54690
|
panagiotis
|
r.setPiwikInfo(piWikService.getPiwikSiteForRepo(r.getId()));
|
322 |
50219
|
panagiotis
|
r.setCountryName(getCountryName(r.getCountryCode()));
|
323 |
52781
|
panagiotis
|
return r;
|
324 |
50219
|
panagiotis
|
}
|
325 |
49790
|
panagiotis
|
|
326 |
50219
|
panagiotis
|
|
327 |
49790
|
panagiotis
|
private Collection<Repository> getRepositoriesByMode(String mode, List<Repository> rs) {
|
328 |
49431
|
panagiotis
|
|
329 |
49790
|
panagiotis
|
List<Repository> reps = new ArrayList<>();
|
330 |
49960
|
panagiotis
|
for (Repository r : rs) {
|
331 |
50631
|
panagiotis
|
if (r.getCollectedFrom() != null && r.getCollectedFrom().equals(mode))
|
332 |
49790
|
panagiotis
|
reps.add(r);
|
333 |
51525
|
panagiotis
|
|
334 |
49813
|
panagiotis
|
}
|
335 |
49431
|
panagiotis
|
return reps;
|
336 |
|
|
}
|
337 |
|
|
|
338 |
49236
|
panagiotis
|
@Override
|
339 |
61441
|
antonis.le
|
public List<Repository> getRepositoriesOfUser(String page, String size) throws JSONException {
|
340 |
|
|
String userEmail = ((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail();
|
341 |
|
|
LOGGER.debug("Retreiving repositories of authenticated user : " + userEmail);
|
342 |
|
|
Collection<String> repoIds = roleMappingService.getRepoIdsByRoleIds(authorizationService.getUserRoles());
|
343 |
|
|
return getRepositories(new ArrayList<>(repoIds));
|
344 |
|
|
}
|
345 |
49397
|
panagiotis
|
|
346 |
61441
|
antonis.le
|
@Override
|
347 |
|
|
public List<Repository> getRepositoriesOfUser(String userEmail, String page, String size) throws JSONException {
|
348 |
|
|
LOGGER.debug("Retreiving repositories of authenticated user : " + userEmail);
|
349 |
|
|
Collection<String> repoIds = roleMappingService.getRepoIdsByRoleIds(authorizationService.getUserRoles(userEmail));
|
350 |
|
|
return getRepositories(new ArrayList<>(repoIds));
|
351 |
|
|
}
|
352 |
50845
|
panagiotis
|
|
353 |
61441
|
antonis.le
|
@Override
|
354 |
|
|
public List<RepositorySnippet> getRepositoriesSnippetsOfUser(String page, String size) throws Exception {
|
355 |
|
|
Collection<String> repoIds = roleMappingService.getRepoIdsByRoleIds(authorizationService.getUserRoles());
|
356 |
|
|
return getRepositoriesSnippets(new ArrayList<>(repoIds));
|
357 |
|
|
}
|
358 |
49988
|
panagiotis
|
|
359 |
61441
|
antonis.le
|
@Override
|
360 |
|
|
public List<RepositorySnippet> getRepositoriesSnippetsOfUser(String userEmail, String page, String size) throws Exception {
|
361 |
|
|
Collection<String> repoIds = roleMappingService.getRepoIdsByRoleIds(authorizationService.getUserRoles(userEmail));
|
362 |
|
|
return getRepositoriesSnippets(new ArrayList<>(repoIds));
|
363 |
49236
|
panagiotis
|
}
|
364 |
|
|
|
365 |
|
|
@Override
|
366 |
61441
|
antonis.le
|
public RepositorySnippet getRepositorySnippetById(String id) throws JSONException, ResourceNotFoundException {
|
367 |
57874
|
ioannis.di
|
|
368 |
61441
|
antonis.le
|
LOGGER.debug("Retreiving repositories with id : " + id);
|
369 |
|
|
RepositorySnippet repo = null;
|
370 |
|
|
UriComponents uriComponents = searchSnipperDatasource("0", "100");
|
371 |
57874
|
ioannis.di
|
RequestFilter requestFilter = new RequestFilter();
|
372 |
61441
|
antonis.le
|
requestFilter.setId(id);
|
373 |
57874
|
ioannis.di
|
|
374 |
61441
|
antonis.le
|
try {
|
375 |
|
|
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
376 |
57874
|
ioannis.di
|
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
|
377 |
61441
|
antonis.le
|
|
378 |
|
|
if (jsonArray.length() == 0)
|
379 |
|
|
throw new ResourceNotFoundException();
|
380 |
|
|
|
381 |
|
|
repo = Converter.jsonToRepositorySnippetObject(jsonArray.getJSONObject(0));
|
382 |
|
|
return repo;
|
383 |
|
|
} catch (JSONException e) {
|
384 |
|
|
LOGGER.debug("Exception on getRepositoryById", e);
|
385 |
|
|
emailUtils.reportException(e);
|
386 |
57874
|
ioannis.di
|
throw e;
|
387 |
|
|
}
|
388 |
61441
|
antonis.le
|
|
389 |
57874
|
ioannis.di
|
}
|
390 |
|
|
|
391 |
|
|
@Override
|
392 |
61441
|
antonis.le
|
public Repository getRepositoryById(String id) throws JSONException, ResourceNotFoundException {
|
393 |
49397
|
panagiotis
|
|
394 |
61441
|
antonis.le
|
LOGGER.debug("Retreiving repositories with id : " + id);
|
395 |
50945
|
panagiotis
|
Repository repo = null;
|
396 |
61441
|
antonis.le
|
UriComponents uriComponents = searchDatasource("0", "100");
|
397 |
50845
|
panagiotis
|
RequestFilter requestFilter = new RequestFilter();
|
398 |
|
|
requestFilter.setId(id);
|
399 |
51831
|
panagiotis
|
|
400 |
61441
|
antonis.le
|
try {
|
401 |
|
|
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
402 |
51831
|
panagiotis
|
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
|
403 |
52781
|
panagiotis
|
|
404 |
61441
|
antonis.le
|
if (jsonArray.length() == 0)
|
405 |
52781
|
panagiotis
|
throw new ResourceNotFoundException();
|
406 |
|
|
|
407 |
|
|
repo = Converter.jsonToRepositoryObject(jsonArray.getJSONObject(0));
|
408 |
|
|
return updateRepositoryInfo(repo);
|
409 |
61441
|
antonis.le
|
} catch (JSONException e) {
|
410 |
|
|
LOGGER.debug("Exception on getRepositoryById", e);
|
411 |
51831
|
panagiotis
|
emailUtils.reportException(e);
|
412 |
|
|
throw e;
|
413 |
|
|
}
|
414 |
|
|
|
415 |
49236
|
panagiotis
|
}
|
416 |
|
|
|
417 |
49988
|
panagiotis
|
|
418 |
49236
|
panagiotis
|
@Override
|
419 |
57176
|
ioannis.di
|
public List<AggregationDetails> getRepositoryAggregations(String id, int from, int size) throws JSONException {
|
420 |
49763
|
panagiotis
|
|
421 |
61441
|
antonis.le
|
LOGGER.debug("Retreiving aggregations for repository with id : " + id);
|
422 |
|
|
UriComponents uriComponents = searchDatasource(from + "", size + "");
|
423 |
50845
|
panagiotis
|
RequestFilter requestFilter = new RequestFilter();
|
424 |
|
|
requestFilter.setId(id);
|
425 |
49935
|
panagiotis
|
|
426 |
52781
|
panagiotis
|
List<AggregationDetails> aggregationHistory = new ArrayList<>();
|
427 |
|
|
|
428 |
49960
|
panagiotis
|
try {
|
429 |
57549
|
ioannis.di
|
long start = System.currentTimeMillis();
|
430 |
61441
|
antonis.le
|
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
431 |
57549
|
ioannis.di
|
long end = System.currentTimeMillis();
|
432 |
|
|
|
433 |
61441
|
antonis.le
|
System.out.println("Aggregations request through rest template took " + (end - start) + "ms");
|
434 |
51831
|
panagiotis
|
JSONObject repository = new JSONObject(rs);
|
435 |
54745
|
panagiotis
|
|
436 |
61441
|
antonis.le
|
if (repository.getJSONArray("datasourceInfo").length() == 0)
|
437 |
54745
|
panagiotis
|
return aggregationHistory;
|
438 |
57549
|
ioannis.di
|
|
439 |
|
|
start = System.currentTimeMillis();
|
440 |
52781
|
panagiotis
|
aggregationHistory.addAll(Converter.getAggregationHistoryFromJson(repository.getJSONArray("datasourceInfo").getJSONObject(0)));
|
441 |
57549
|
ioannis.di
|
end = System.currentTimeMillis();
|
442 |
|
|
|
443 |
61441
|
antonis.le
|
System.out.println("Getting aggregations history from json " + (end - start) + "ms");
|
444 |
|
|
return aggregationHistory.size() == 0 ? aggregationHistory : aggregationHistory.stream()
|
445 |
|
|
.sorted(Comparator.comparing(AggregationDetails::getDate).reversed())
|
446 |
|
|
.limit(size)
|
447 |
|
|
.collect(Collectors.toList());
|
448 |
52781
|
panagiotis
|
} catch (JSONException e) {
|
449 |
61441
|
antonis.le
|
LOGGER.debug("Exception on getRepositoryAggregations", e);
|
450 |
52781
|
panagiotis
|
emailUtils.reportException(e);
|
451 |
|
|
throw e;
|
452 |
|
|
}
|
453 |
51831
|
panagiotis
|
|
454 |
52781
|
panagiotis
|
}
|
455 |
|
|
|
456 |
|
|
@Override
|
457 |
56761
|
ioannis.di
|
public Map<String, List<AggregationDetails>> getRepositoryAggregationsByYear(String id) throws JSONException {
|
458 |
61441
|
antonis.le
|
LOGGER.debug("Retreiving aggregations (by year) for repository with id : " + id);
|
459 |
|
|
UriComponents uriComponents = searchDatasource("0", "100");
|
460 |
52781
|
panagiotis
|
RequestFilter requestFilter = new RequestFilter();
|
461 |
|
|
requestFilter.setId(id);
|
462 |
|
|
|
463 |
|
|
List<AggregationDetails> aggregationHistory = new ArrayList<>();
|
464 |
|
|
Map<String, List<AggregationDetails>> aggregationByYear = new HashMap<>();
|
465 |
|
|
try {
|
466 |
61441
|
antonis.le
|
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
467 |
52781
|
panagiotis
|
JSONObject repository = new JSONObject(rs);
|
468 |
54745
|
panagiotis
|
|
469 |
61441
|
antonis.le
|
if (repository.getJSONArray("datasourceInfo").length() == 0)
|
470 |
54745
|
panagiotis
|
return aggregationByYear;
|
471 |
|
|
|
472 |
52781
|
panagiotis
|
aggregationHistory.addAll(Converter.getAggregationHistoryFromJson(repository.getJSONArray("datasourceInfo").getJSONObject(0)));
|
473 |
61441
|
antonis.le
|
return aggregationHistory.size() == 0 ? aggregationByYear : createYearMap(aggregationHistory);
|
474 |
52781
|
panagiotis
|
|
475 |
49960
|
panagiotis
|
} catch (JSONException e) {
|
476 |
61441
|
antonis.le
|
LOGGER.debug("Exception on getRepositoryAggregations", e);
|
477 |
51831
|
panagiotis
|
emailUtils.reportException(e);
|
478 |
49935
|
panagiotis
|
throw e;
|
479 |
|
|
}
|
480 |
52781
|
panagiotis
|
}
|
481 |
49935
|
panagiotis
|
|
482 |
61441
|
antonis.le
|
private Map<String, List<AggregationDetails>> createYearMap(List<AggregationDetails> aggregationHistory) {
|
483 |
52781
|
panagiotis
|
Map<String, List<AggregationDetails>> aggregationByYear;
|
484 |
|
|
aggregationHistory = aggregationHistory.stream()
|
485 |
61441
|
antonis.le
|
.sorted(Comparator.comparing(AggregationDetails::getDate).reversed())
|
486 |
|
|
.collect(Collectors.toList());
|
487 |
52781
|
panagiotis
|
|
488 |
61441
|
antonis.le
|
return aggregationHistory.stream()
|
489 |
|
|
.collect(Collectors.groupingBy(AggregationDetails::getYear));
|
490 |
49763
|
panagiotis
|
}
|
491 |
|
|
|
492 |
52781
|
panagiotis
|
|
493 |
49763
|
panagiotis
|
@Override
|
494 |
56761
|
ioannis.di
|
public List<Repository> getRepositoriesByName(String name,
|
495 |
|
|
String page,
|
496 |
|
|
String size) throws JSONException {
|
497 |
49397
|
panagiotis
|
|
498 |
61441
|
antonis.le
|
LOGGER.debug("Retreiving repositories with official name : " + name);
|
499 |
|
|
UriComponents uriComponents = searchDatasource("0", "100");
|
500 |
50845
|
panagiotis
|
RequestFilter requestFilter = new RequestFilter();
|
501 |
|
|
requestFilter.setOfficialname(name);
|
502 |
|
|
|
503 |
61441
|
antonis.le
|
try {
|
504 |
|
|
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
505 |
51831
|
panagiotis
|
List<Repository> repos = Converter.jsonToRepositoryList(new JSONObject(rs));
|
506 |
|
|
for (Repository r : repos)
|
507 |
52781
|
panagiotis
|
updateRepositoryInfo(r);
|
508 |
51831
|
panagiotis
|
return repos;
|
509 |
61441
|
antonis.le
|
} catch (Exception e) {
|
510 |
|
|
LOGGER.debug("Exception on getRepositoriesByName", e);
|
511 |
51831
|
panagiotis
|
emailUtils.reportException(e);
|
512 |
|
|
throw e;
|
513 |
|
|
}
|
514 |
|
|
|
515 |
49236
|
panagiotis
|
}
|
516 |
|
|
|
517 |
|
|
@Override
|
518 |
56761
|
ioannis.di
|
public List<RepositoryInterface> getRepositoryInterface(String id) throws JSONException {
|
519 |
49397
|
panagiotis
|
|
520 |
|
|
UriComponents uriComponents = UriComponentsBuilder
|
521 |
49813
|
panagiotis
|
.fromHttpUrl(baseAddress + "/ds/api/")
|
522 |
51330
|
panagiotis
|
.path("/{id}")
|
523 |
49397
|
panagiotis
|
.build().expand(id).encode();
|
524 |
|
|
|
525 |
61441
|
antonis.le
|
try {
|
526 |
51831
|
panagiotis
|
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class);
|
527 |
|
|
return Converter.jsonToRepositoryInterfaceList(new JSONObject(rs));
|
528 |
61441
|
antonis.le
|
} catch (Exception e) {
|
529 |
|
|
LOGGER.debug("Exception on getRepositoryInterface", e);
|
530 |
51831
|
panagiotis
|
emailUtils.reportException(e);
|
531 |
|
|
throw e;
|
532 |
|
|
}
|
533 |
|
|
|
534 |
49236
|
panagiotis
|
}
|
535 |
|
|
|
536 |
|
|
@Override
|
537 |
56761
|
ioannis.di
|
public Repository addRepository(String datatype,
|
538 |
|
|
Repository repository) throws Exception {
|
539 |
49898
|
panagiotis
|
|
540 |
49960
|
panagiotis
|
LOGGER.debug("storing " + datatype + " repository with id: " + repository.getId());
|
541 |
54690
|
panagiotis
|
|
542 |
|
|
repository.setCountryCode(countriesMap.get(repository.getCountryName()));
|
543 |
|
|
repository.setActivationId(UUID.randomUUID().toString());
|
544 |
|
|
repository.setCollectedFrom("infrastruct_::openaire");
|
545 |
|
|
|
546 |
|
|
if (datatype.equals("journal")) {
|
547 |
|
|
repository.setId("openaire____::issn" + repository.getIssn());
|
548 |
|
|
repository.setNamespacePrefix("issn" + repository.getIssn());
|
549 |
|
|
this.storeRepository(repository, SecurityContextHolder.getContext().getAuthentication());
|
550 |
61441
|
antonis.le
|
} else if (datatype.equals("aggregator")) {
|
551 |
54690
|
panagiotis
|
repository.setId("openaire____::" + com.unboundid.util.Base64.encode(repository.getOfficialName()));
|
552 |
61441
|
antonis.le
|
repository.setNamespacePrefix(DigestUtils.md5Hex(repository.getOfficialName()).substring(0, 12));
|
553 |
54690
|
panagiotis
|
this.storeRepository(repository, SecurityContextHolder.getContext().getAuthentication());
|
554 |
61441
|
antonis.le
|
} else {
|
555 |
54690
|
panagiotis
|
this.latentUpdate(repository, SecurityContextHolder.getContext().getAuthentication());
|
556 |
|
|
}
|
557 |
|
|
|
558 |
61441
|
antonis.le
|
// TODO: move the following code elsewhere (creation and assignment of role to user) ??
|
559 |
|
|
// Create new role
|
560 |
|
|
String newRoleName = roleMappingService.getRoleIdByRepoId(repository.getId());
|
561 |
|
|
Role newRole = new Role(newRoleName, repository.getOfficialName());
|
562 |
|
|
Integer couId = null;
|
563 |
|
|
try {
|
564 |
|
|
couId = registryCalls.createRole(newRole);
|
565 |
|
|
} catch (HttpClientErrorException e) {
|
566 |
|
|
couId = registryCalls.getCouId(newRoleName);
|
567 |
|
|
if (couId == null) {
|
568 |
|
|
LOGGER.error(String.format("Could not create role '%s'", newRoleName), e);
|
569 |
|
|
}
|
570 |
|
|
} catch (Exception e) {
|
571 |
|
|
LOGGER.error(String.format("Could not create role '%s'", newRoleName), e);
|
572 |
|
|
throw e;
|
573 |
|
|
}
|
574 |
|
|
|
575 |
|
|
// Assign new role to the user that created it
|
576 |
|
|
Integer coPersonId = registryCalls.getCoPersonIdByIdentifier();
|
577 |
|
|
if (couId != null) {
|
578 |
|
|
Integer role = registryCalls.getRoleId(coPersonId, couId);
|
579 |
|
|
try {
|
580 |
|
|
registryCalls.assignMemberRole(coPersonId, couId, role);
|
581 |
|
|
|
582 |
|
|
// Add role to current user authorities
|
583 |
|
|
authoritiesUpdater.addRole(roleMappingService.convertRepoIdToAuthority(repository.getId()));
|
584 |
|
|
} catch (Exception e) {
|
585 |
|
|
LOGGER.debug("Exception on assign role to user during add repository", e);
|
586 |
|
|
throw e;
|
587 |
|
|
}
|
588 |
|
|
|
589 |
|
|
}
|
590 |
|
|
|
591 |
|
|
|
592 |
50945
|
panagiotis
|
return repository;
|
593 |
49963
|
panagiotis
|
}
|
594 |
49960
|
panagiotis
|
|
595 |
54690
|
panagiotis
|
/* update method acting as add -> send email with registration topic/body*/
|
596 |
|
|
private Repository latentUpdate(Repository repository, Authentication authentication) throws Exception {
|
597 |
|
|
UriComponents uriComponents = UriComponentsBuilder
|
598 |
|
|
.fromHttpUrl(baseAddress + "/ds/update/")
|
599 |
|
|
.build()
|
600 |
|
|
.encode();
|
601 |
|
|
|
602 |
|
|
try {
|
603 |
|
|
String json_repository = Converter.repositoryObjectToJson(repository);
|
604 |
|
|
LOGGER.debug("JSON to add(update) -> " + json_repository);
|
605 |
|
|
|
606 |
|
|
HttpEntity<String> httpEntity = new HttpEntity<String>(json_repository, httpHeaders);
|
607 |
61441
|
antonis.le
|
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class);
|
608 |
54690
|
panagiotis
|
|
609 |
54924
|
panagiotis
|
if (responseEntity.getStatusCode().equals(HttpStatus.OK)) {
|
610 |
61441
|
antonis.le
|
// emailUtils.sendUserRegistrationEmail(repository, authentication);
|
611 |
|
|
// emailUtils.sendAdminRegistrationEmail(repository, authentication);
|
612 |
56636
|
antonis.le
|
} else
|
613 |
54690
|
panagiotis
|
LOGGER.debug(responseEntity.getBody().toString());
|
614 |
|
|
|
615 |
|
|
return repository;
|
616 |
|
|
} catch (Exception e) {
|
617 |
61441
|
antonis.le
|
LOGGER.debug("Exception on updateRepository", e);
|
618 |
54690
|
panagiotis
|
emailUtils.reportException(e);
|
619 |
|
|
throw e;
|
620 |
|
|
}
|
621 |
|
|
|
622 |
|
|
|
623 |
|
|
}
|
624 |
|
|
|
625 |
51239
|
panagiotis
|
@Override
|
626 |
61441
|
antonis.le
|
public Repository updateRepository(Repository repository, Authentication authentication) throws Exception {
|
627 |
51330
|
panagiotis
|
UriComponents uriComponents = UriComponentsBuilder
|
628 |
51239
|
panagiotis
|
.fromHttpUrl(baseAddress + "/ds/update/")
|
629 |
|
|
.build()
|
630 |
51330
|
panagiotis
|
.encode();
|
631 |
51586
|
panagiotis
|
|
632 |
51831
|
panagiotis
|
try {
|
633 |
54078
|
panagiotis
|
String json_repository = Converter.repositoryObjectToJson(repository);
|
634 |
53933
|
panagiotis
|
|
635 |
|
|
LOGGER.debug("JSON to update -> " + json_repository);
|
636 |
|
|
|
637 |
|
|
HttpEntity<String> httpEntity = new HttpEntity<String>(json_repository, httpHeaders);
|
638 |
61441
|
antonis.le
|
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity
|
639 |
56636
|
antonis.le
|
, ResponseEntity.class);
|
640 |
53933
|
panagiotis
|
|
641 |
56636
|
antonis.le
|
if (responseEntity.getStatusCode().equals(HttpStatus.OK)) {
|
642 |
57912
|
stefania.m
|
emailUtils.sendUserUpdateRepositoryInfoEmail(repository, authentication);
|
643 |
|
|
emailUtils.sendAdminUpdateRepositoryInfoEmail(repository, authentication);
|
644 |
56636
|
antonis.le
|
} else
|
645 |
53933
|
panagiotis
|
LOGGER.debug(responseEntity.getBody().toString());
|
646 |
|
|
|
647 |
51831
|
panagiotis
|
return repository;
|
648 |
53933
|
panagiotis
|
} catch (Exception e) {
|
649 |
61441
|
antonis.le
|
LOGGER.debug("Exception on updateRepository", e);
|
650 |
51831
|
panagiotis
|
emailUtils.reportException(e);
|
651 |
|
|
throw e;
|
652 |
|
|
}
|
653 |
50075
|
panagiotis
|
}
|
654 |
|
|
|
655 |
53933
|
panagiotis
|
private void storeRepository(Repository repository, Authentication authentication) throws Exception {
|
656 |
49960
|
panagiotis
|
|
657 |
49963
|
panagiotis
|
Date utilDate = new Date();
|
658 |
|
|
Timestamp date = new Timestamp(utilDate.getTime());
|
659 |
|
|
repository.setDateOfCollection(date);
|
660 |
|
|
repository.setAggregator("OPENAIRE");
|
661 |
51525
|
panagiotis
|
repository.setCountryCode(countriesMap.get(repository.getCountryName()));
|
662 |
49963
|
panagiotis
|
|
663 |
49397
|
panagiotis
|
UriComponents uriComponents = UriComponentsBuilder
|
664 |
|
|
.fromHttpUrl(baseAddress + "/ds/add/")
|
665 |
|
|
.build()
|
666 |
|
|
.encode();
|
667 |
50051
|
panagiotis
|
String json_repository = Converter.repositoryObjectToJson(repository);
|
668 |
61441
|
antonis.le
|
HttpEntity<String> httpEntity = new HttpEntity<String>(json_repository, httpHeaders);
|
669 |
|
|
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class);
|
670 |
53933
|
panagiotis
|
|
671 |
61441
|
antonis.le
|
if (responseEntity.getStatusCode().equals(HttpStatus.OK)) {
|
672 |
56636
|
antonis.le
|
emailUtils.sendUserRegistrationEmail(repository, authentication);
|
673 |
|
|
emailUtils.sendAdminRegistrationEmail(repository, authentication);
|
674 |
|
|
} else {
|
675 |
53933
|
panagiotis
|
LOGGER.debug(responseEntity.getBody().toString());
|
676 |
|
|
}
|
677 |
49236
|
panagiotis
|
}
|
678 |
|
|
|
679 |
|
|
@Override
|
680 |
61441
|
antonis.le
|
public void deleteRepositoryInterface(String id,
|
681 |
|
|
String registeredBy) {
|
682 |
49397
|
panagiotis
|
UriComponents uriComponents = UriComponentsBuilder
|
683 |
49813
|
panagiotis
|
.fromHttpUrl(baseAddress + "/ds/api/")
|
684 |
51525
|
panagiotis
|
.path("/{id}")
|
685 |
49813
|
panagiotis
|
.build().expand(id).encode();
|
686 |
51525
|
panagiotis
|
LOGGER.debug(uriComponents.toUri());
|
687 |
49813
|
panagiotis
|
restTemplate.delete(uriComponents.toUri());
|
688 |
|
|
}
|
689 |
|
|
|
690 |
|
|
@Override
|
691 |
56761
|
ioannis.di
|
public RepositoryInterface addRepositoryInterface(String datatype,
|
692 |
|
|
String repoId,
|
693 |
|
|
String registeredBy,
|
694 |
59190
|
antonis.le
|
String comment, RepositoryInterface repositoryInterface) throws Exception {
|
695 |
49963
|
panagiotis
|
try {
|
696 |
51525
|
panagiotis
|
Repository e = this.getRepositoryById(repoId);
|
697 |
61441
|
antonis.le
|
repositoryInterface = createRepositoryInterface(e, repositoryInterface, datatype);
|
698 |
|
|
String json_interface = Converter.repositoryInterfaceObjectToJson(e, repositoryInterface);
|
699 |
49963
|
panagiotis
|
|
700 |
|
|
UriComponents uriComponents = UriComponentsBuilder
|
701 |
|
|
.fromHttpUrl(baseAddress + "/ds/api/add/")
|
702 |
|
|
.build()
|
703 |
|
|
.encode();
|
704 |
|
|
|
705 |
61441
|
antonis.le
|
HttpEntity<String> httpEntity = new HttpEntity<>(json_interface, httpHeaders);
|
706 |
56761
|
ioannis.di
|
|
707 |
61441
|
antonis.le
|
restTemplate.postForObject(uriComponents.toUri(), httpEntity, String.class);
|
708 |
50051
|
panagiotis
|
|
709 |
59584
|
antonis.le
|
emailUtils.sendAdminRegisterInterfaceEmail(e, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication());
|
710 |
|
|
emailUtils.sendUserRegisterInterfaceEmail(e, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication());
|
711 |
57912
|
stefania.m
|
|
712 |
59584
|
antonis.le
|
submitInterfaceValidation(e, registeredBy, repositoryInterface, false);
|
713 |
57912
|
stefania.m
|
|
714 |
59584
|
antonis.le
|
return repositoryInterface;
|
715 |
57912
|
stefania.m
|
|
716 |
59584
|
antonis.le
|
} catch (Exception e) {
|
717 |
61441
|
antonis.le
|
LOGGER.error("Exception on addRepositoryInterface", e);
|
718 |
51831
|
panagiotis
|
emailUtils.reportException(e);
|
719 |
|
|
throw e;
|
720 |
49963
|
panagiotis
|
}
|
721 |
|
|
}
|
722 |
|
|
|
723 |
56636
|
antonis.le
|
@Override
|
724 |
56761
|
ioannis.di
|
public RepositoryInterface updateRepositoryInterface(String repoId,
|
725 |
|
|
String registeredBy,
|
726 |
59190
|
antonis.le
|
String comment, RepositoryInterface repositoryInterface) throws Exception {
|
727 |
56636
|
antonis.le
|
|
728 |
61441
|
antonis.le
|
this.updateBaseUrl(repoId, repositoryInterface.getId(), repositoryInterface.getBaseUrl());
|
729 |
|
|
this.updateCompliance(repoId, repositoryInterface.getId(), repositoryInterface.getCompliance());
|
730 |
|
|
this.updateValidationSet(repoId, repositoryInterface.getId(), repositoryInterface.getAccessSet());
|
731 |
57912
|
stefania.m
|
|
732 |
61441
|
antonis.le
|
Repository repository = this.getRepositoryById(repoId);
|
733 |
|
|
try {
|
734 |
|
|
emailUtils.sendAdminUpdateInterfaceEmail(repository, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication());
|
735 |
|
|
emailUtils.sendUserUpdateInterfaceEmail(repository, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication());
|
736 |
|
|
} catch (Exception e) {
|
737 |
|
|
LOGGER.warn("Could not send emails", e);
|
738 |
|
|
}
|
739 |
57912
|
stefania.m
|
|
740 |
61441
|
antonis.le
|
submitInterfaceValidation(getRepositoryById(repoId), registeredBy, repositoryInterface, true);
|
741 |
|
|
|
742 |
56636
|
antonis.le
|
return repositoryInterface;
|
743 |
|
|
}
|
744 |
|
|
|
745 |
56961
|
ioannis.di
|
private void submitInterfaceValidation(Repository repo, String userEmail, RepositoryInterface iFace, boolean updateExisting) throws ValidatorServiceException {
|
746 |
56636
|
antonis.le
|
JobForValidation job = new JobForValidation();
|
747 |
|
|
|
748 |
|
|
job.setActivationId(UUID.randomUUID().toString());
|
749 |
|
|
job.setAdminEmails(Collections.singletonList(this.adminEmail));
|
750 |
|
|
job.setBaseUrl(iFace.getBaseUrl());
|
751 |
|
|
job.setDatasourceId(repo.getId());
|
752 |
|
|
job.setDesiredCompatibilityLevel(iFace.getDesiredCompatibilityLevel());
|
753 |
|
|
job.setInterfaceId(iFace.getId());
|
754 |
|
|
job.setOfficialName(repo.getOfficialName());
|
755 |
56761
|
ioannis.di
|
job.setRepoType(repo.getDatasourceType());
|
756 |
56636
|
antonis.le
|
job.setUserEmail(userEmail);
|
757 |
56761
|
ioannis.di
|
job.setValidationSet((iFace.getAccessSet().isEmpty() ? "none" : iFace.getAccessSet()));
|
758 |
56636
|
antonis.le
|
job.setRecords(-1);
|
759 |
56961
|
ioannis.di
|
job.setRegistration(!updateExisting);
|
760 |
|
|
job.setUpdateExisting(updateExisting);
|
761 |
56636
|
antonis.le
|
|
762 |
|
|
this.validatorService.submitJobForValidation(job);
|
763 |
|
|
}
|
764 |
|
|
|
765 |
51525
|
panagiotis
|
private RepositoryInterface createRepositoryInterface(Repository repo, RepositoryInterface iFace, String datatype) {
|
766 |
|
|
|
767 |
|
|
iFace.setContentDescription("metadata");
|
768 |
|
|
iFace.setCompliance("UNKNOWN");
|
769 |
|
|
|
770 |
|
|
if (datatype.equals("re3data"))
|
771 |
|
|
iFace.setAccessFormat("oai_datacite");
|
772 |
|
|
else
|
773 |
|
|
iFace.setAccessFormat("oai_dc");
|
774 |
|
|
|
775 |
|
|
|
776 |
|
|
if (repo.getDatasourceClass() != null && !repo.getDatasourceClass().isEmpty())
|
777 |
|
|
iFace.setTypology(repo.getDatasourceClass());
|
778 |
|
|
else if (datatype.equalsIgnoreCase("journal"))
|
779 |
|
|
iFace.setTypology("pubsrepository::journal");
|
780 |
|
|
else if (datatype.equalsIgnoreCase("aggregator"))
|
781 |
|
|
iFace.setTypology("aggregator::pubsrepository::unknown");
|
782 |
|
|
else if (datatype.equalsIgnoreCase("opendoar"))
|
783 |
|
|
iFace.setTypology("pubsrepository::unknown");
|
784 |
|
|
else if (datatype.equalsIgnoreCase("re3data"))
|
785 |
|
|
iFace.setTypology("datarepository::unknown");
|
786 |
|
|
|
787 |
|
|
iFace.setRemovable(true);
|
788 |
|
|
iFace.setAccessProtocol("oai");
|
789 |
|
|
iFace.setMetadataIdentifierPath("//*[local-name()='header']/*[local-name()='identifier']");
|
790 |
|
|
iFace.setId("api_________::" + repo.getId() + "::" + UUID.randomUUID().toString().substring(0, 8));
|
791 |
56761
|
ioannis.di
|
if (iFace.getAccessSet() == null || iFace.getAccessSet().isEmpty()) {
|
792 |
51525
|
panagiotis
|
LOGGER.debug("set is empty: " + iFace.getAccessSet());
|
793 |
|
|
iFace.removeAccessSet();
|
794 |
56761
|
ioannis.di
|
iFace.setAccessSet("none");
|
795 |
51525
|
panagiotis
|
}
|
796 |
|
|
return iFace;
|
797 |
|
|
}
|
798 |
|
|
|
799 |
49236
|
panagiotis
|
@Override
|
800 |
|
|
public List<String> getDnetCountries() {
|
801 |
49770
|
panagiotis
|
LOGGER.debug("Getting dnet-countries!");
|
802 |
49236
|
panagiotis
|
return Converter.readFile("countries.txt");
|
803 |
|
|
}
|
804 |
|
|
|
805 |
|
|
@Override
|
806 |
|
|
public List<String> getTypologies() {
|
807 |
|
|
return Converter.readFile("typologies.txt");
|
808 |
|
|
}
|
809 |
|
|
|
810 |
|
|
@Override
|
811 |
49763
|
panagiotis
|
public List<Timezone> getTimezones() {
|
812 |
61441
|
antonis.le
|
List<String> timezones = Converter.readFile("timezones.txt");
|
813 |
49763
|
panagiotis
|
return Converter.toTimezones(timezones);
|
814 |
49236
|
panagiotis
|
}
|
815 |
|
|
|
816 |
|
|
@Override
|
817 |
56761
|
ioannis.di
|
public List<String> getUrlsOfUserRepos(String userEmail,
|
818 |
|
|
String page,
|
819 |
61441
|
antonis.le
|
String size) {
|
820 |
49763
|
panagiotis
|
UriComponents uriComponents = UriComponentsBuilder
|
821 |
|
|
.fromHttpUrl(baseAddress + "/api/baseurl/")
|
822 |
|
|
.path("/{page}/{size}")
|
823 |
61441
|
antonis.le
|
.build().expand(page, size).encode();
|
824 |
50614
|
panagiotis
|
|
825 |
61441
|
antonis.le
|
try {
|
826 |
51831
|
panagiotis
|
RequestFilter requestFilter = new RequestFilter();
|
827 |
|
|
requestFilter.setRegisteredby(userEmail);
|
828 |
61441
|
antonis.le
|
return Arrays.asList(restTemplate.postForObject(uriComponents.toUri(), requestFilter, String[].class));
|
829 |
|
|
} catch (Exception e) {
|
830 |
|
|
LOGGER.debug("Exception on addRepositoryInterface", e);
|
831 |
51831
|
panagiotis
|
emailUtils.reportException(e);
|
832 |
|
|
throw e;
|
833 |
|
|
}
|
834 |
49236
|
panagiotis
|
}
|
835 |
|
|
|
836 |
49450
|
panagiotis
|
@Override
|
837 |
56761
|
ioannis.di
|
public List<String> getDatasourceVocabularies(String mode) {
|
838 |
49450
|
panagiotis
|
|
839 |
|
|
List<String> resultSet = new ArrayList<>();
|
840 |
|
|
for (Map.Entry<String, String> entry : this.getVocabulary("dnet:datasource_typologies").getAsMap().entrySet()) {
|
841 |
|
|
if (mode.equalsIgnoreCase("aggregator")) {
|
842 |
|
|
if (entry.getKey().contains("aggregator"))
|
843 |
|
|
resultSet.add(entry.getValue());
|
844 |
|
|
} else if (mode.equalsIgnoreCase("journal")) {
|
845 |
|
|
if (entry.getKey().contains("journal"))
|
846 |
|
|
resultSet.add(entry.getValue());
|
847 |
|
|
} else if (mode.equalsIgnoreCase("opendoar")) {
|
848 |
|
|
if (entry.getKey().contains("pubsrepository"))
|
849 |
|
|
resultSet.add(entry.getValue());
|
850 |
|
|
} else if (mode.equalsIgnoreCase("re3data")) {
|
851 |
|
|
if (entry.getKey().contains("datarepository"))
|
852 |
|
|
resultSet.add(entry.getValue());
|
853 |
|
|
}
|
854 |
|
|
}
|
855 |
|
|
|
856 |
|
|
|
857 |
|
|
return resultSet;
|
858 |
|
|
}
|
859 |
|
|
|
860 |
|
|
private Vocabulary getVocabulary(String vocName) {
|
861 |
|
|
|
862 |
|
|
if (!vocabularyMap.containsKey(vocName)) {
|
863 |
|
|
vocabularyMap.put(vocName, vocabularyLoader.getVocabulary(vocName, Locale.ENGLISH, Locale.ROOT));
|
864 |
|
|
}
|
865 |
|
|
return vocabularyMap.get(vocName);
|
866 |
|
|
}
|
867 |
|
|
|
868 |
49790
|
panagiotis
|
|
869 |
|
|
@Override
|
870 |
61441
|
antonis.le
|
public Map<String, String> getCompatibilityClasses(String mode) {
|
871 |
49790
|
panagiotis
|
|
872 |
|
|
LOGGER.debug("Getting compatibility classes for mode: " + mode);
|
873 |
|
|
Map<String, String> retMap = new HashMap<String, String>();
|
874 |
|
|
|
875 |
|
|
Map<String, String> compatibilityClasses = this.getVocabulary("dnet:compatibilityLevel").getAsMap();
|
876 |
|
|
boolean foundData = false;
|
877 |
|
|
for (Map.Entry<String, String> entry : compatibilityClasses.entrySet()) {
|
878 |
|
|
if (mode.equalsIgnoreCase(Constants.REPOSITORY_MODE_ALL))
|
879 |
|
|
return compatibilityClasses;
|
880 |
|
|
else if (mode.equalsIgnoreCase(Constants.REPOSITORY_MODE_RE3DATA)) {
|
881 |
|
|
if (entry.getKey().matches("^openaire[1-9].0_data$")) {
|
882 |
|
|
retMap.put(entry.getKey(), entry.getValue());
|
883 |
|
|
foundData = true;
|
884 |
|
|
}
|
885 |
|
|
} else {
|
886 |
|
|
if (entry.getKey().matches("^openaire[1-9].0$") || entry.getKey().equals("driver"))
|
887 |
|
|
retMap.put(entry.getKey(), entry.getValue());
|
888 |
|
|
}
|
889 |
|
|
}
|
890 |
|
|
|
891 |
|
|
//TODO TO BE REMOVED WHEN VOCABULARIES ARE UPDATED
|
892 |
|
|
if (mode.equalsIgnoreCase(Constants.REPOSITORY_MODE_RE3DATA) && !foundData)
|
893 |
|
|
retMap.put("openaire2.0_data", "OpenAIRE Data (funded, referenced datasets)");
|
894 |
|
|
|
895 |
|
|
return retMap;
|
896 |
|
|
}
|
897 |
|
|
|
898 |
|
|
@Override
|
899 |
61441
|
antonis.le
|
public Map<String, String> getDatasourceClasses(String mode) {
|
900 |
49790
|
panagiotis
|
|
901 |
|
|
LOGGER.debug("Getting datasource classes for mode: " + mode);
|
902 |
|
|
|
903 |
|
|
Map<String, String> retMap = new HashMap<String, String>();
|
904 |
|
|
|
905 |
|
|
for (Map.Entry<String, String> entry : this.getVocabulary("dnet:datasource_typologies").getAsMap().entrySet()) {
|
906 |
|
|
if (mode.equalsIgnoreCase("aggregator")) {
|
907 |
|
|
if (entry.getKey().contains("aggregator"))
|
908 |
|
|
retMap.put(entry.getKey(), entry.getValue());
|
909 |
|
|
} else if (mode.equalsIgnoreCase("journal")) {
|
910 |
|
|
if (entry.getKey().contains("journal"))
|
911 |
|
|
retMap.put(entry.getKey(), entry.getValue());
|
912 |
|
|
} else if (mode.equalsIgnoreCase("opendoar")) {
|
913 |
|
|
if (entry.getKey().contains("pubsrepository"))
|
914 |
|
|
retMap.put(entry.getKey(), entry.getValue());
|
915 |
|
|
} else if (mode.equalsIgnoreCase("re3data")) {
|
916 |
|
|
if (entry.getKey().contains("datarepository"))
|
917 |
|
|
retMap.put(entry.getKey(), entry.getValue());
|
918 |
|
|
}
|
919 |
|
|
}
|
920 |
61441
|
antonis.le
|
return filterResults(retMap, mode);
|
921 |
49790
|
panagiotis
|
|
922 |
|
|
}
|
923 |
|
|
|
924 |
61441
|
antonis.le
|
private Map<String, String> filterResults(Map<String, String> map, String mode) {
|
925 |
51549
|
panagiotis
|
|
926 |
61441
|
antonis.le
|
HashMap<String, String> filteredMap = new HashMap<>();
|
927 |
|
|
for (String key : map.keySet())
|
928 |
|
|
if (dataSourceClass.get(mode).contains(key))
|
929 |
|
|
filteredMap.put(key, map.get(key));
|
930 |
51549
|
panagiotis
|
|
931 |
|
|
return filteredMap;
|
932 |
|
|
}
|
933 |
|
|
|
934 |
49898
|
panagiotis
|
@Override
|
935 |
|
|
public String getCountryName(String countryCode) {
|
936 |
|
|
return inverseCountriesMap.get(countryCode);
|
937 |
|
|
}
|
938 |
|
|
|
939 |
50570
|
panagiotis
|
@Override
|
940 |
56761
|
ioannis.di
|
public MetricsInfo getMetricsInfoForRepository(String repoId) throws RepositoryServiceException {
|
941 |
50570
|
panagiotis
|
try {
|
942 |
|
|
|
943 |
|
|
MetricsInfo metricsInfo = new MetricsInfo();
|
944 |
|
|
metricsInfo.setDiagramsBaseURL(this.usageStatisticsDiagramsBaseURL);
|
945 |
|
|
metricsInfo.setMetricsNumbers(getMetricsNumbers(getOpenAIREId(repoId)));
|
946 |
|
|
return metricsInfo;
|
947 |
|
|
|
948 |
|
|
} catch (Exception e) {
|
949 |
|
|
LOGGER.error("Error while getting metrics info for repository: ", e);
|
950 |
51831
|
panagiotis
|
emailUtils.reportException(e);
|
951 |
50570
|
panagiotis
|
throw new RepositoryServiceException("General error", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
|
952 |
|
|
}
|
953 |
|
|
}
|
954 |
|
|
|
955 |
51330
|
panagiotis
|
@Override
|
956 |
56761
|
ioannis.di
|
public Map<String, String> getListLatestUpdate(String mode) throws JSONException {
|
957 |
61441
|
antonis.le
|
if (mode.equals("opendoar"))
|
958 |
|
|
return Collections.singletonMap("lastCollectionDate", getRepositoryInterface("openaire____::" + mode).get(0).getLastCollectionDate());
|
959 |
51330
|
panagiotis
|
else
|
960 |
|
|
/*
|
961 |
61441
|
antonis.le
|
* first api of re3data has null value on collection date
|
962 |
|
|
* */
|
963 |
|
|
return Collections.singletonMap("lastCollectionDate", getRepositoryInterface("openaire____::" + mode).get(1).getLastCollectionDate());
|
964 |
51330
|
panagiotis
|
}
|
965 |
|
|
|
966 |
54702
|
panagiotis
|
private void updateValidationSet(String repositoryId, String repositoryInterfaceId, String validationSet) throws Exception {
|
967 |
51549
|
panagiotis
|
UriComponents uriComponents = UriComponentsBuilder
|
968 |
|
|
.fromHttpUrl(baseAddress + "/ds/api/oaiset")
|
969 |
61441
|
antonis.le
|
.queryParam("dsId", repositoryId)
|
970 |
|
|
.queryParam("apiId", repositoryInterfaceId)
|
971 |
|
|
.queryParam("oaiSet", validationSet)
|
972 |
51549
|
panagiotis
|
.build().encode();
|
973 |
61441
|
antonis.le
|
restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, null, ResponseEntity.class);
|
974 |
54702
|
panagiotis
|
|
975 |
51549
|
panagiotis
|
}
|
976 |
51525
|
panagiotis
|
|
977 |
51549
|
panagiotis
|
|
978 |
51525
|
panagiotis
|
private void updateBaseUrl(String repositoryId, String repositoryInterfaceId, String baseUrl) {
|
979 |
|
|
UriComponents uriComponents = UriComponentsBuilder
|
980 |
|
|
.fromHttpUrl(baseAddress + "/ds/api/baseurl")
|
981 |
61441
|
antonis.le
|
.queryParam("dsId", repositoryId)
|
982 |
|
|
.queryParam("apiId", repositoryInterfaceId)
|
983 |
|
|
.queryParam("baseUrl", baseUrl)
|
984 |
51525
|
panagiotis
|
.build().encode();
|
985 |
61441
|
antonis.le
|
restTemplate.postForObject(uriComponents.toUri(), null, String.class);
|
986 |
51525
|
panagiotis
|
}
|
987 |
|
|
|
988 |
61441
|
antonis.le
|
private void updateCompliance(String repositoryId, String repositoryInterfaceId, String compliance) {
|
989 |
51525
|
panagiotis
|
UriComponents uriComponents = UriComponentsBuilder
|
990 |
|
|
.fromHttpUrl(baseAddress + "/ds/api/compliance")
|
991 |
61441
|
antonis.le
|
.queryParam("dsId", repositoryId)
|
992 |
|
|
.queryParam("apiId", repositoryInterfaceId)
|
993 |
|
|
.queryParam("compliance", compliance)
|
994 |
51525
|
panagiotis
|
.build().encode();
|
995 |
61441
|
antonis.le
|
restTemplate.postForObject(uriComponents.toUri(), null, String.class);
|
996 |
51525
|
panagiotis
|
}
|
997 |
|
|
|
998 |
50570
|
panagiotis
|
private MetricsNumbers getMetricsNumbers(String openAIREID) throws BrokerException {
|
999 |
|
|
|
1000 |
|
|
//build the uri params
|
1001 |
|
|
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(this.usageStatisticsNumbersBaseURL + openAIREID + "/clicks");
|
1002 |
|
|
|
1003 |
|
|
//create new template engine
|
1004 |
|
|
RestTemplate template = new RestTemplate();
|
1005 |
|
|
template.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
|
1006 |
|
|
ResponseEntity<MetricsNumbers> resp;
|
1007 |
|
|
try {
|
1008 |
|
|
//communicate with endpoint
|
1009 |
|
|
resp = template.exchange(
|
1010 |
|
|
builder.build().encode().toUri(),
|
1011 |
|
|
HttpMethod.GET,
|
1012 |
|
|
null,
|
1013 |
|
|
new ParameterizedTypeReference<MetricsNumbers>() {
|
1014 |
|
|
});
|
1015 |
|
|
} catch (RestClientException e) {
|
1016 |
61441
|
antonis.le
|
LOGGER.debug("Exception on getMetricsNumbers", e);
|
1017 |
51831
|
panagiotis
|
emailUtils.reportException(e);
|
1018 |
50570
|
panagiotis
|
throw e;
|
1019 |
|
|
}
|
1020 |
|
|
|
1021 |
|
|
return resp.getBody();
|
1022 |
|
|
}
|
1023 |
|
|
|
1024 |
|
|
private String getOpenAIREId(String repoId) {
|
1025 |
|
|
|
1026 |
|
|
if (repoId != null && repoId.contains("::")) {
|
1027 |
|
|
return repoId.split("::")[0] + "::" + DigestUtils.md5Hex(repoId.split("::")[1]);
|
1028 |
|
|
}
|
1029 |
|
|
|
1030 |
|
|
return null;
|
1031 |
|
|
}
|
1032 |
|
|
|
1033 |
61441
|
antonis.le
|
private UriComponents searchDatasource(String page, String size) {
|
1034 |
50570
|
panagiotis
|
|
1035 |
50631
|
panagiotis
|
return UriComponentsBuilder
|
1036 |
|
|
.fromHttpUrl(baseAddress + "/ds/search/")
|
1037 |
|
|
.path("/{page}/{size}/")
|
1038 |
61441
|
antonis.le
|
.queryParam("requestSortBy", "officialname")
|
1039 |
|
|
.queryParam("order", "ASCENDING")
|
1040 |
50631
|
panagiotis
|
.build().expand(page, size).encode();
|
1041 |
|
|
}
|
1042 |
|
|
|
1043 |
61441
|
antonis.le
|
private UriComponents searchSnipperDatasource(String page, String size) {
|
1044 |
53113
|
panagiotis
|
|
1045 |
|
|
return UriComponentsBuilder
|
1046 |
|
|
.fromHttpUrl(baseAddress + "/ds/searchsnippet/")
|
1047 |
|
|
.path("/{page}/{size}/")
|
1048 |
61441
|
antonis.le
|
.queryParam("requestSortBy", "officialname")
|
1049 |
|
|
.queryParam("order", "ASCENDING")
|
1050 |
53113
|
panagiotis
|
.build().expand(page, size).encode();
|
1051 |
|
|
}
|
1052 |
|
|
|
1053 |
61441
|
antonis.le
|
private UriComponents searchRegisteredDatasource(String requestSortBy, String order, String page, String size) {
|
1054 |
56636
|
antonis.le
|
|
1055 |
|
|
return UriComponentsBuilder
|
1056 |
|
|
.fromHttpUrl(baseAddress + "/ds/searchregistered/")
|
1057 |
|
|
.path("/{page}/{size}/")
|
1058 |
61441
|
antonis.le
|
.queryParam("requestSortBy", requestSortBy)
|
1059 |
|
|
.queryParam("order", order)
|
1060 |
56636
|
antonis.le
|
.build().expand(page, size).encode();
|
1061 |
|
|
}
|
1062 |
|
|
|
1063 |
61441
|
antonis.le
|
private String getRepositoryType(String typology) {
|
1064 |
51549
|
panagiotis
|
return invertedDataSourceClass.get(typology);
|
1065 |
|
|
}
|
1066 |
50631
|
panagiotis
|
|
1067 |
61441
|
antonis.le
|
private List<String> getRoleIdsFromUserRoles(String userEmail) {
|
1068 |
|
|
Integer coPersonId = registryCalls.getCoPersonIdByEmail(userEmail);
|
1069 |
|
|
JsonArray roles;
|
1070 |
|
|
ArrayList<String> roleIds = new ArrayList<>();
|
1071 |
|
|
ArrayList<Integer> couIds = new ArrayList<>();
|
1072 |
|
|
if (coPersonId != null) {
|
1073 |
|
|
roles = registryCalls.getRolesWithStatus(coPersonId, AaiRegistryService.RoleStatus.ACTIVE);
|
1074 |
|
|
for (JsonElement role : roles) {
|
1075 |
|
|
JsonObject object = role.getAsJsonObject();
|
1076 |
|
|
if (object.get("CouId") == null) {
|
1077 |
|
|
continue;
|
1078 |
|
|
}
|
1079 |
|
|
couIds.add(object.get("CouId").getAsInt());
|
1080 |
|
|
}
|
1081 |
51549
|
panagiotis
|
|
1082 |
61441
|
antonis.le
|
roleIds.addAll(registryCalls.getCouNames(couIds).values());
|
1083 |
|
|
|
1084 |
|
|
}
|
1085 |
|
|
return roleIds;
|
1086 |
|
|
}
|
1087 |
49236
|
panagiotis
|
}
|