Revision 61441
Added by Antonis Lempesis over 2 years ago
RepositoryServiceImpl.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.repo.manager.service; |
2 | 2 |
|
3 | 3 |
import com.fasterxml.jackson.databind.ObjectMapper; |
4 |
import com.google.gson.JsonArray; |
|
5 |
import com.google.gson.JsonElement; |
|
6 |
import com.google.gson.JsonObject; |
|
4 | 7 |
import eu.dnetlib.api.functionality.ValidatorServiceException; |
5 | 8 |
import eu.dnetlib.domain.data.Repository; |
6 | 9 |
import eu.dnetlib.domain.data.RepositoryInterface; |
7 | 10 |
import eu.dnetlib.domain.enabling.Vocabulary; |
8 | 11 |
import eu.dnetlib.domain.functionality.validator.JobForValidation; |
9 | 12 |
import eu.dnetlib.repo.manager.domain.*; |
13 |
import eu.dnetlib.repo.manager.domain.dto.Role; |
|
10 | 14 |
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException; |
15 |
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; |
|
11 | 19 |
import eu.dnetlib.repo.manager.utils.Converter; |
12 | 20 |
import gr.uoa.di.driver.enabling.vocabulary.VocabularyLoader; |
13 | 21 |
import org.apache.commons.codec.digest.DigestUtils; |
... | ... | |
15 | 23 |
import org.json.JSONArray; |
16 | 24 |
import org.json.JSONException; |
17 | 25 |
import org.json.JSONObject; |
26 |
import org.mitre.openid.connect.model.OIDCAuthenticationToken; |
|
18 | 27 |
import org.springframework.beans.factory.annotation.Autowired; |
19 | 28 |
import org.springframework.beans.factory.annotation.Value; |
29 |
import org.springframework.context.annotation.Lazy; |
|
20 | 30 |
import org.springframework.core.ParameterizedTypeReference; |
21 | 31 |
import org.springframework.http.*; |
22 | 32 |
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; |
23 | 33 |
import org.springframework.security.core.Authentication; |
24 | 34 |
import org.springframework.security.core.context.SecurityContextHolder; |
25 | 35 |
import org.springframework.stereotype.Service; |
36 |
import org.springframework.web.client.HttpClientErrorException; |
|
26 | 37 |
import org.springframework.web.client.RestClientException; |
27 | 38 |
import org.springframework.web.client.RestTemplate; |
28 | 39 |
import org.springframework.web.util.UriComponents; |
... | ... | |
38 | 49 |
@Service("repositoryService") |
39 | 50 |
public class RepositoryServiceImpl implements RepositoryService { |
40 | 51 |
|
52 |
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 |
|
|
41 | 64 |
@Value("${api.baseAddress}") |
42 | 65 |
private String baseAddress; |
43 | 66 |
|
44 | 67 |
@Value("${services.repo-manager.adminEmail}") |
45 | 68 |
private String adminEmail; |
46 | 69 |
|
47 |
@Autowired |
|
48 |
RestTemplate restTemplate; |
|
49 |
|
|
50 |
private HttpHeaders httpHeaders; |
|
51 |
|
|
52 |
private final String[] vocabularyNames = {"dnet:countries", "dnet:datasource_typologies", "dnet:compatibilityLevel"}; |
|
53 |
|
|
54 |
private static final Logger LOGGER = Logger.getLogger(RepositoryServiceImpl.class); |
|
55 |
|
|
56 | 70 |
@Value("${services.repomanager.usageStatisticsDiagramsBaseURL}") |
57 | 71 |
private String usageStatisticsDiagramsBaseURL; |
58 | 72 |
|
59 | 73 |
@Value("${services.repomanager.usageStatisticsNumbersBaseURL}") |
60 | 74 |
private String usageStatisticsNumbersBaseURL; |
61 | 75 |
|
62 |
@Autowired |
|
63 |
private VocabularyLoader vocabularyLoader; |
|
64 | 76 |
|
65 |
@Autowired
|
|
66 |
private PiWikService piWikService;
|
|
77 |
private static final Map<String, List<String>> dataSourceClass = new HashMap<>();
|
|
78 |
private static final Map<String, String> invertedDataSourceClass = new HashMap<>();
|
|
67 | 79 |
|
68 |
@Autowired |
|
69 |
private EmailUtils emailUtils; |
|
70 | 80 |
|
71 |
@Autowired |
|
72 |
ValidatorService validatorService; |
|
81 |
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<>(); |
|
73 | 85 |
|
86 |
private HttpHeaders httpHeaders; |
|
74 | 87 |
|
75 |
private Map<String, Vocabulary> vocabularyMap = new ConcurrentHashMap<>(); |
|
88 |
@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 |
} |
|
76 | 108 |
|
77 |
private Map<String, String> countriesMap = new HashMap<>(); |
|
78 |
private Map<String, String> inverseCountriesMap = new HashMap<>(); |
|
109 |
private String getAuthenticatedUserEmail() { |
|
110 |
OIDCAuthenticationToken authenticationToken = (OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); |
|
111 |
return authenticationToken.getUserInfo().getEmail(); |
|
112 |
} |
|
79 | 113 |
|
80 |
private static Map<String,List<String>> dataSourceClass = new HashMap<>(); |
|
81 | 114 |
|
82 |
private static Map<String,String> invertedDataSourceClass = new HashMap<>(); |
|
83 |
|
|
84 |
|
|
85 |
|
|
86 | 115 |
@PostConstruct |
87 | 116 |
private void init() { |
88 | 117 |
LOGGER.debug("Initialization method of repository api!"); |
89 | 118 |
LOGGER.debug("Updated version!"); |
90 | 119 |
|
91 |
dataSourceClass.put("opendoar",Arrays.asList("pubsrepository::institutional","pubsrepository::thematic","pubsrepository::unknown","pubsrepository::mock"));
|
|
120 |
dataSourceClass.put("opendoar", Arrays.asList("pubsrepository::institutional", "pubsrepository::thematic", "pubsrepository::unknown", "pubsrepository::mock"));
|
|
92 | 121 |
dataSourceClass.put("re3data", Collections.singletonList("datarepository::unknown")); |
93 | 122 |
dataSourceClass.put("journal", Collections.singletonList("pubsrepository::journal")); |
94 |
dataSourceClass.put("aggregator",Arrays.asList("aggregator::pubsrepository::institutional","aggregator::pubsrepository::journals","aggregator::datarepository", "aggregator::pubsrepository::unknown"));
|
|
123 |
dataSourceClass.put("aggregator", Arrays.asList("aggregator::pubsrepository::institutional", "aggregator::pubsrepository::journals", "aggregator::datarepository", "aggregator::pubsrepository::unknown"));
|
|
95 | 124 |
|
96 |
invertedDataSourceClass.put("pubsrepository::institutional","opendoar"); |
|
97 |
invertedDataSourceClass.put("pubsrepository::thematic","opendoar"); |
|
98 |
invertedDataSourceClass.put("pubsrepository::unknown","opendoar"); |
|
99 |
invertedDataSourceClass.put("pubsrepository::mock","opendoar"); |
|
100 |
invertedDataSourceClass.put("datarepository::unknown","re3data"); |
|
101 |
invertedDataSourceClass.put("pubsrepository::journal","journal"); |
|
102 |
invertedDataSourceClass.put("aggregator::pubsrepository::institutional","aggregator"); |
|
103 |
invertedDataSourceClass.put("aggregator::pubsrepository::journals","aggregator"); |
|
104 |
invertedDataSourceClass.put("aggregator::datarepository","aggregator"); |
|
105 |
invertedDataSourceClass.put("aggregator::pubsrepository::unknown","aggregator"); |
|
125 |
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");
|
|
106 | 135 |
|
107 | 136 |
|
108 | 137 |
httpHeaders = new HttpHeaders(); |
... | ... | |
128 | 157 |
.build().encode(); |
129 | 158 |
return restTemplate.getForObject(uriComponents.toUri(), Country[].class); |
130 | 159 |
} |
160 |
|
|
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 |
} |
|
131 | 168 |
|
169 |
// 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(); |
|
132 | 178 |
|
179 |
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. |
|
133 | 200 |
@Override |
201 |
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 |
|
134 | 240 |
public List<RepositorySnippet> getRepositoriesByCountry(String country, |
135 | 241 |
String mode, |
136 | 242 |
Boolean managed) throws JSONException, IOException { |
... | ... | |
151 | 257 |
LOGGER.debug("Country code equals : " + country); |
152 | 258 |
LOGGER.debug("Filter mode equals : " + filterKey); |
153 | 259 |
|
154 |
UriComponents uriComponents = searchSnipperDatasource(String.valueOf(page),String.valueOf(size)); |
|
260 |
UriComponents uriComponents = searchSnipperDatasource(String.valueOf(page), String.valueOf(size));
|
|
155 | 261 |
RequestFilter requestFilter = new RequestFilter(); |
156 | 262 |
requestFilter.setCountry(country); |
157 | 263 |
requestFilter.setCollectedfrom(filterKey); |
158 | 264 |
|
159 |
try{ |
|
160 |
String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class); |
|
265 |
try {
|
|
266 |
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
|
161 | 267 |
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo"); |
162 |
while (jsonArray.length() > 0 ) {
|
|
268 |
while (jsonArray.length() > 0) { |
|
163 | 269 |
resultSet.addAll(mapper.readValue(String.valueOf(jsonArray), |
164 | 270 |
mapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class))); |
165 | 271 |
page += 1; |
166 |
uriComponents = searchSnipperDatasource(String.valueOf(page),String.valueOf(size)); |
|
167 |
rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class); |
|
272 |
uriComponents = searchSnipperDatasource(String.valueOf(page), String.valueOf(size));
|
|
273 |
rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
|
168 | 274 |
jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo"); |
169 | 275 |
} |
170 | 276 |
return resultSet; |
171 |
}catch (Exception e){
|
|
172 |
LOGGER.debug("Exception on getRepositoriesByCountry" , e);
|
|
277 |
} catch (Exception e) {
|
|
278 |
LOGGER.debug("Exception on getRepositoriesByCountry", e); |
|
173 | 279 |
// emailUtils.reportException(e); |
174 | 280 |
throw e; |
175 | 281 |
} |
176 | 282 |
} |
177 | 283 |
|
178 | 284 |
public List<RepositorySnippet> searchRegisteredRepositories(String country, String typology, String englishName, |
179 |
String officialName, String requestSortBy, String order, int page, int pageSize) throws Exception { |
|
285 |
String officialName, String requestSortBy, String order, int page, int pageSize) throws Exception {
|
|
180 | 286 |
|
181 | 287 |
LOGGER.debug("Searching registered repositories"); |
182 | 288 |
|
... | ... | |
192 | 298 |
requestFilter.setEnglishname(englishName); |
193 | 299 |
|
194 | 300 |
try { |
195 |
String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class); |
|
301 |
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
|
196 | 302 |
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo"); |
197 | 303 |
|
198 |
resultSet.addAll(mapper.readValue(String.valueOf(jsonArray), mapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class)));
|
|
304 |
resultSet.addAll(mapper.readValue(String.valueOf(jsonArray), mapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class))); |
|
199 | 305 |
|
200 |
return resultSet;
|
|
201 |
}catch (Exception e){
|
|
202 |
LOGGER.error("Error searching registered datasources" , e);
|
|
306 |
return resultSet; |
|
307 |
} catch (Exception e) {
|
|
308 |
LOGGER.error("Error searching registered datasources", e); |
|
203 | 309 |
throw e; |
204 | 310 |
} |
205 | 311 |
} |
... | ... | |
207 | 313 |
private Repository updateRepositoryInfo(Repository r) throws JSONException { |
208 | 314 |
|
209 | 315 |
/* |
210 |
* from datasource class |
|
211 |
* we get the datasource type form the inverted map |
|
212 |
* */ |
|
316 |
* from datasource class
|
|
317 |
* we get the datasource type form the inverted map
|
|
318 |
* */
|
|
213 | 319 |
r.setDatasourceType(getRepositoryType(r.getDatasourceClass())); |
214 | 320 |
r.setInterfaces(this.getRepositoryInterface(r.getId())); |
215 | 321 |
r.setPiwikInfo(piWikService.getPiwikSiteForRepo(r.getId())); |
... | ... | |
230 | 336 |
} |
231 | 337 |
|
232 | 338 |
@Override |
233 |
public List<Repository> getRepositoriesOfUser(String userEmail, |
|
234 |
String page, |
|
235 |
String size) throws JSONException { |
|
339 |
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 |
} |
|
236 | 345 |
|
237 |
LOGGER.debug("Retreiving repositories of user : " + userEmail ); |
|
238 |
UriComponents uriComponents = searchDatasource(page,size); |
|
239 |
RequestFilter requestFilter = new RequestFilter(); |
|
240 |
requestFilter.setRegisteredby(userEmail); |
|
346 |
@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 |
} |
|
241 | 352 |
|
242 |
try{ |
|
243 |
String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class); |
|
353 |
@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 |
} |
|
244 | 358 |
|
245 |
List<Repository> repos = Converter.jsonToRepositoryList(new JSONObject(rs)); |
|
246 |
for (Repository r : repos) |
|
247 |
r.setPiwikInfo(piWikService.getPiwikSiteForRepo(r.getId())); |
|
248 |
return repos; |
|
249 |
}catch (Exception e){ |
|
250 |
LOGGER.debug("Exception on getRepositoriesOfUser" , e); |
|
251 |
emailUtils.reportException(e); |
|
252 |
throw e; |
|
253 |
} |
|
359 |
@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)); |
|
254 | 363 |
} |
255 | 364 |
|
256 | 365 |
@Override |
257 |
public List<RepositorySnippet> getRepositoriesSnippetOfUser(String userEmail, String page, String size) throws IOException, JSONException { |
|
258 |
List<RepositorySnippet> resultSet = new ArrayList<>(); |
|
259 |
ObjectMapper mapper = new ObjectMapper(); |
|
366 |
public RepositorySnippet getRepositorySnippetById(String id) throws JSONException, ResourceNotFoundException { |
|
260 | 367 |
|
261 |
UriComponents uriComponents = searchSnipperDatasource(page,size); |
|
368 |
LOGGER.debug("Retreiving repositories with id : " + id); |
|
369 |
RepositorySnippet repo = null; |
|
370 |
UriComponents uriComponents = searchSnipperDatasource("0", "100"); |
|
262 | 371 |
RequestFilter requestFilter = new RequestFilter(); |
263 |
requestFilter.setRegisteredby(userEmail);
|
|
372 |
requestFilter.setId(id);
|
|
264 | 373 |
|
265 |
try{ |
|
266 |
String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class); |
|
374 |
try {
|
|
375 |
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
|
267 | 376 |
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo"); |
268 |
while (jsonArray.length() > 0 ) { |
|
269 |
resultSet.addAll(mapper.readValue(String.valueOf(jsonArray), |
|
270 |
mapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class))); |
|
271 |
page += 1; |
|
272 |
uriComponents = searchSnipperDatasource(page,size); |
|
273 |
rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class); |
|
274 |
jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo"); |
|
275 |
} |
|
276 |
resultSet.parallelStream().forEach(repositorySnippet -> { |
|
277 |
repositorySnippet.setPiwikInfo(piWikService.getPiwikSiteForRepo(repositorySnippet.getId())); |
|
278 |
}); |
|
279 |
return resultSet; |
|
280 |
}catch (Exception e){ |
|
281 |
LOGGER.debug("Exception on getRepositoriesByCountry" , e); |
|
377 |
|
|
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); |
|
282 | 386 |
throw e; |
283 | 387 |
} |
388 |
|
|
284 | 389 |
} |
285 | 390 |
|
286 | 391 |
@Override |
287 |
public Repository getRepositoryById(String id) throws JSONException,ResourceNotFoundException { |
|
392 |
public Repository getRepositoryById(String id) throws JSONException, ResourceNotFoundException {
|
|
288 | 393 |
|
289 |
LOGGER.debug("Retreiving repositories with id : " + id );
|
|
394 |
LOGGER.debug("Retreiving repositories with id : " + id); |
|
290 | 395 |
Repository repo = null; |
291 |
UriComponents uriComponents = searchDatasource("0","100"); |
|
396 |
UriComponents uriComponents = searchDatasource("0", "100");
|
|
292 | 397 |
RequestFilter requestFilter = new RequestFilter(); |
293 | 398 |
requestFilter.setId(id); |
294 | 399 |
|
295 |
try{ |
|
296 |
String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class); |
|
400 |
try {
|
|
401 |
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
|
297 | 402 |
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo"); |
298 | 403 |
|
299 |
if(jsonArray.length() == 0) |
|
404 |
if (jsonArray.length() == 0)
|
|
300 | 405 |
throw new ResourceNotFoundException(); |
301 | 406 |
|
302 | 407 |
repo = Converter.jsonToRepositoryObject(jsonArray.getJSONObject(0)); |
303 | 408 |
return updateRepositoryInfo(repo); |
304 |
}catch (JSONException e){
|
|
305 |
LOGGER.debug("Exception on getRepositoryById" , e);
|
|
409 |
} catch (JSONException e) {
|
|
410 |
LOGGER.debug("Exception on getRepositoryById", e); |
|
306 | 411 |
emailUtils.reportException(e); |
307 | 412 |
throw e; |
308 | 413 |
} |
... | ... | |
313 | 418 |
@Override |
314 | 419 |
public List<AggregationDetails> getRepositoryAggregations(String id, int from, int size) throws JSONException { |
315 | 420 |
|
316 |
LOGGER.debug("Retreiving aggregations for repository with id : " + id );
|
|
317 |
UriComponents uriComponents = searchDatasource(from+"",size+"");
|
|
421 |
LOGGER.debug("Retreiving aggregations for repository with id : " + id); |
|
422 |
UriComponents uriComponents = searchDatasource(from + "", size + "");
|
|
318 | 423 |
RequestFilter requestFilter = new RequestFilter(); |
319 | 424 |
requestFilter.setId(id); |
320 | 425 |
|
... | ... | |
322 | 427 |
|
323 | 428 |
try { |
324 | 429 |
long start = System.currentTimeMillis(); |
325 |
String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class); |
|
430 |
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
|
326 | 431 |
long end = System.currentTimeMillis(); |
327 | 432 |
|
328 |
System.out.println("Aggregations request through rest template took " + (end-start)+"ms");
|
|
433 |
System.out.println("Aggregations request through rest template took " + (end - start) + "ms");
|
|
329 | 434 |
JSONObject repository = new JSONObject(rs); |
330 | 435 |
|
331 |
if(repository.getJSONArray("datasourceInfo").length() == 0) |
|
436 |
if (repository.getJSONArray("datasourceInfo").length() == 0)
|
|
332 | 437 |
return aggregationHistory; |
333 | 438 |
|
334 | 439 |
start = System.currentTimeMillis(); |
335 | 440 |
aggregationHistory.addAll(Converter.getAggregationHistoryFromJson(repository.getJSONArray("datasourceInfo").getJSONObject(0))); |
336 | 441 |
end = System.currentTimeMillis(); |
337 | 442 |
|
338 |
System.out.println("Getting aggregations history from json " + (end-start)+"ms");
|
|
339 |
return aggregationHistory.size() == 0? aggregationHistory : aggregationHistory.stream() |
|
340 |
.sorted(Comparator.comparing(AggregationDetails::getDate).reversed())
|
|
341 |
.limit(size)
|
|
342 |
.collect(Collectors.toList());
|
|
443 |
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()); |
|
343 | 448 |
} catch (JSONException e) { |
344 |
LOGGER.debug("Exception on getRepositoryAggregations" , e);
|
|
449 |
LOGGER.debug("Exception on getRepositoryAggregations", e); |
|
345 | 450 |
emailUtils.reportException(e); |
346 | 451 |
throw e; |
347 | 452 |
} |
... | ... | |
350 | 455 |
|
351 | 456 |
@Override |
352 | 457 |
public Map<String, List<AggregationDetails>> getRepositoryAggregationsByYear(String id) throws JSONException { |
353 |
LOGGER.debug("Retreiving aggregations (by year) for repository with id : " + id );
|
|
354 |
UriComponents uriComponents = searchDatasource("0","100"); |
|
458 |
LOGGER.debug("Retreiving aggregations (by year) for repository with id : " + id); |
|
459 |
UriComponents uriComponents = searchDatasource("0", "100");
|
|
355 | 460 |
RequestFilter requestFilter = new RequestFilter(); |
356 | 461 |
requestFilter.setId(id); |
357 | 462 |
|
358 | 463 |
List<AggregationDetails> aggregationHistory = new ArrayList<>(); |
359 | 464 |
Map<String, List<AggregationDetails>> aggregationByYear = new HashMap<>(); |
360 | 465 |
try { |
361 |
String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class); |
|
466 |
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
|
362 | 467 |
JSONObject repository = new JSONObject(rs); |
363 | 468 |
|
364 |
if(repository.getJSONArray("datasourceInfo").length() == 0) |
|
469 |
if (repository.getJSONArray("datasourceInfo").length() == 0)
|
|
365 | 470 |
return aggregationByYear; |
366 | 471 |
|
367 | 472 |
aggregationHistory.addAll(Converter.getAggregationHistoryFromJson(repository.getJSONArray("datasourceInfo").getJSONObject(0))); |
368 |
return aggregationHistory.size() == 0? aggregationByYear:createYearMap(aggregationHistory);
|
|
473 |
return aggregationHistory.size() == 0 ? aggregationByYear : createYearMap(aggregationHistory);
|
|
369 | 474 |
|
370 | 475 |
} catch (JSONException e) { |
371 |
LOGGER.debug("Exception on getRepositoryAggregations" , e);
|
|
476 |
LOGGER.debug("Exception on getRepositoryAggregations", e); |
|
372 | 477 |
emailUtils.reportException(e); |
373 | 478 |
throw e; |
374 | 479 |
} |
375 | 480 |
} |
376 | 481 |
|
377 |
private Map<String,List<AggregationDetails>> createYearMap(List<AggregationDetails> aggregationHistory) { |
|
482 |
private Map<String, List<AggregationDetails>> createYearMap(List<AggregationDetails> aggregationHistory) {
|
|
378 | 483 |
Map<String, List<AggregationDetails>> aggregationByYear; |
379 | 484 |
aggregationHistory = aggregationHistory.stream() |
380 |
.sorted(Comparator.comparing(AggregationDetails::getDate).reversed())
|
|
381 |
.collect(Collectors.toList());
|
|
485 |
.sorted(Comparator.comparing(AggregationDetails::getDate).reversed()) |
|
486 |
.collect(Collectors.toList()); |
|
382 | 487 |
|
383 |
return aggregationHistory.stream() |
|
384 |
.collect(Collectors.groupingBy(AggregationDetails::getYear));
|
|
488 |
return aggregationHistory.stream()
|
|
489 |
.collect(Collectors.groupingBy(AggregationDetails::getYear)); |
|
385 | 490 |
} |
386 | 491 |
|
387 | 492 |
|
... | ... | |
390 | 495 |
String page, |
391 | 496 |
String size) throws JSONException { |
392 | 497 |
|
393 |
LOGGER.debug("Retreiving repositories with official name : " + name );
|
|
394 |
UriComponents uriComponents = searchDatasource("0","100"); |
|
498 |
LOGGER.debug("Retreiving repositories with official name : " + name); |
|
499 |
UriComponents uriComponents = searchDatasource("0", "100");
|
|
395 | 500 |
RequestFilter requestFilter = new RequestFilter(); |
396 | 501 |
requestFilter.setOfficialname(name); |
397 | 502 |
|
398 |
try{ |
|
399 |
String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class); |
|
503 |
try {
|
|
504 |
String rs = restTemplate.postForObject(uriComponents.toUri(), requestFilter, String.class);
|
|
400 | 505 |
List<Repository> repos = Converter.jsonToRepositoryList(new JSONObject(rs)); |
401 | 506 |
for (Repository r : repos) |
402 | 507 |
updateRepositoryInfo(r); |
403 | 508 |
return repos; |
404 |
}catch (Exception e){
|
|
405 |
LOGGER.debug("Exception on getRepositoriesByName" , e);
|
|
509 |
} catch (Exception e) {
|
|
510 |
LOGGER.debug("Exception on getRepositoriesByName", e); |
|
406 | 511 |
emailUtils.reportException(e); |
407 | 512 |
throw e; |
408 | 513 |
} |
... | ... | |
417 | 522 |
.path("/{id}") |
418 | 523 |
.build().expand(id).encode(); |
419 | 524 |
|
420 |
try{ |
|
525 |
try {
|
|
421 | 526 |
String rs = restTemplate.getForObject(uriComponents.toUri(), String.class); |
422 | 527 |
return Converter.jsonToRepositoryInterfaceList(new JSONObject(rs)); |
423 |
}catch (Exception e ){
|
|
424 |
LOGGER.debug("Exception on getRepositoryInterface" , e);
|
|
528 |
} catch (Exception e) {
|
|
529 |
LOGGER.debug("Exception on getRepositoryInterface", e); |
|
425 | 530 |
emailUtils.reportException(e); |
426 | 531 |
throw e; |
427 | 532 |
} |
... | ... | |
442 | 547 |
repository.setId("openaire____::issn" + repository.getIssn()); |
443 | 548 |
repository.setNamespacePrefix("issn" + repository.getIssn()); |
444 | 549 |
this.storeRepository(repository, SecurityContextHolder.getContext().getAuthentication()); |
445 |
}else if (datatype.equals("aggregator")) { |
|
550 |
} else if (datatype.equals("aggregator")) {
|
|
446 | 551 |
repository.setId("openaire____::" + com.unboundid.util.Base64.encode(repository.getOfficialName())); |
447 |
repository.setNamespacePrefix(DigestUtils.md5Hex(repository.getOfficialName()).substring(0,12)); |
|
552 |
repository.setNamespacePrefix(DigestUtils.md5Hex(repository.getOfficialName()).substring(0, 12));
|
|
448 | 553 |
this.storeRepository(repository, SecurityContextHolder.getContext().getAuthentication()); |
449 |
}else { |
|
554 |
} else {
|
|
450 | 555 |
this.latentUpdate(repository, SecurityContextHolder.getContext().getAuthentication()); |
451 | 556 |
} |
452 | 557 |
|
558 |
// 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 |
|
|
453 | 592 |
return repository; |
454 | 593 |
} |
455 | 594 |
|
... | ... | |
465 | 604 |
LOGGER.debug("JSON to add(update) -> " + json_repository); |
466 | 605 |
|
467 | 606 |
HttpEntity<String> httpEntity = new HttpEntity<String>(json_repository, httpHeaders); |
468 |
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(),HttpMethod.POST, httpEntity, ResponseEntity.class); |
|
607 |
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class);
|
|
469 | 608 |
|
470 | 609 |
if (responseEntity.getStatusCode().equals(HttpStatus.OK)) { |
471 |
emailUtils.sendUserRegistrationEmail(repository, authentication); |
|
472 |
emailUtils.sendAdminRegistrationEmail(repository, authentication); |
|
610 |
// emailUtils.sendUserRegistrationEmail(repository, authentication);
|
|
611 |
// emailUtils.sendAdminRegistrationEmail(repository, authentication);
|
|
473 | 612 |
} else |
474 | 613 |
LOGGER.debug(responseEntity.getBody().toString()); |
475 | 614 |
|
476 | 615 |
return repository; |
477 | 616 |
} catch (Exception e) { |
478 |
LOGGER.debug("Exception on updateRepository" , e);
|
|
617 |
LOGGER.debug("Exception on updateRepository", e); |
|
479 | 618 |
emailUtils.reportException(e); |
480 | 619 |
throw e; |
481 | 620 |
} |
... | ... | |
484 | 623 |
} |
485 | 624 |
|
486 | 625 |
@Override |
487 |
public Repository updateRepository(Repository repository,Authentication authentication) throws Exception { |
|
626 |
public Repository updateRepository(Repository repository, Authentication authentication) throws Exception {
|
|
488 | 627 |
UriComponents uriComponents = UriComponentsBuilder |
489 | 628 |
.fromHttpUrl(baseAddress + "/ds/update/") |
490 | 629 |
.build() |
... | ... | |
496 | 635 |
LOGGER.debug("JSON to update -> " + json_repository); |
497 | 636 |
|
498 | 637 |
HttpEntity<String> httpEntity = new HttpEntity<String>(json_repository, httpHeaders); |
499 |
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(),HttpMethod.POST, httpEntity |
|
638 |
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity
|
|
500 | 639 |
, ResponseEntity.class); |
501 | 640 |
|
502 | 641 |
if (responseEntity.getStatusCode().equals(HttpStatus.OK)) { |
... | ... | |
507 | 646 |
|
508 | 647 |
return repository; |
509 | 648 |
} catch (Exception e) { |
510 |
LOGGER.debug("Exception on updateRepository" , e);
|
|
649 |
LOGGER.debug("Exception on updateRepository", e); |
|
511 | 650 |
emailUtils.reportException(e); |
512 | 651 |
throw e; |
513 | 652 |
} |
... | ... | |
526 | 665 |
.build() |
527 | 666 |
.encode(); |
528 | 667 |
String json_repository = Converter.repositoryObjectToJson(repository); |
529 |
HttpEntity<String> httpEntity = new HttpEntity <String> (json_repository,httpHeaders);
|
|
530 |
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(),HttpMethod.POST, httpEntity, ResponseEntity.class); |
|
668 |
HttpEntity<String> httpEntity = new HttpEntity<String>(json_repository, httpHeaders);
|
|
669 |
ResponseEntity responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, httpEntity, ResponseEntity.class);
|
|
531 | 670 |
|
532 |
if(responseEntity.getStatusCode().equals(HttpStatus.OK)) { |
|
671 |
if (responseEntity.getStatusCode().equals(HttpStatus.OK)) {
|
|
533 | 672 |
emailUtils.sendUserRegistrationEmail(repository, authentication); |
534 | 673 |
emailUtils.sendAdminRegistrationEmail(repository, authentication); |
535 | 674 |
} else { |
... | ... | |
538 | 677 |
} |
539 | 678 |
|
540 | 679 |
@Override |
541 |
public void deleteRepositoryInterface(String id ,
|
|
542 |
String registeredBy){ |
|
680 |
public void deleteRepositoryInterface(String id, |
|
681 |
String registeredBy) {
|
|
543 | 682 |
UriComponents uriComponents = UriComponentsBuilder |
544 | 683 |
.fromHttpUrl(baseAddress + "/ds/api/") |
545 | 684 |
.path("/{id}") |
... | ... | |
555 | 694 |
String comment, RepositoryInterface repositoryInterface) throws Exception { |
556 | 695 |
try { |
557 | 696 |
Repository e = this.getRepositoryById(repoId); |
558 |
repositoryInterface = createRepositoryInterface(e,repositoryInterface,datatype);
|
|
559 |
String json_interface = Converter.repositoryInterfaceObjectToJson(e,repositoryInterface); |
|
697 |
repositoryInterface = createRepositoryInterface(e, repositoryInterface, datatype);
|
|
698 |
String json_interface = Converter.repositoryInterfaceObjectToJson(e, repositoryInterface);
|
|
560 | 699 |
|
561 | 700 |
UriComponents uriComponents = UriComponentsBuilder |
562 | 701 |
.fromHttpUrl(baseAddress + "/ds/api/add/") |
563 | 702 |
.build() |
564 | 703 |
.encode(); |
565 | 704 |
|
566 |
HttpEntity<String> httpEntity = new HttpEntity <> (json_interface,httpHeaders);
|
|
705 |
HttpEntity<String> httpEntity = new HttpEntity<>(json_interface, httpHeaders);
|
|
567 | 706 |
|
568 |
restTemplate.postForObject(uriComponents.toUri(),httpEntity, String.class); |
|
707 |
restTemplate.postForObject(uriComponents.toUri(), httpEntity, String.class);
|
|
569 | 708 |
|
570 | 709 |
emailUtils.sendAdminRegisterInterfaceEmail(e, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication()); |
571 | 710 |
emailUtils.sendUserRegisterInterfaceEmail(e, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication()); |
... | ... | |
575 | 714 |
return repositoryInterface; |
576 | 715 |
|
577 | 716 |
} catch (Exception e) { |
578 |
LOGGER.error("Exception on addRepositoryInterface" , e);
|
|
717 |
LOGGER.error("Exception on addRepositoryInterface", e); |
|
579 | 718 |
emailUtils.reportException(e); |
580 | 719 |
throw e; |
581 | 720 |
} |
... | ... | |
586 | 725 |
String registeredBy, |
587 | 726 |
String comment, RepositoryInterface repositoryInterface) throws Exception { |
588 | 727 |
|
589 |
this.updateBaseUrl(repoId,repositoryInterface.getId(),repositoryInterface.getBaseUrl());
|
|
590 |
this.updateCompliance(repoId,repositoryInterface.getId(),repositoryInterface.getCompliance());
|
|
591 |
this.updateValidationSet(repoId,repositoryInterface.getId(),repositoryInterface.getAccessSet());
|
|
728 |
this.updateBaseUrl(repoId, repositoryInterface.getId(), repositoryInterface.getBaseUrl());
|
|
729 |
this.updateCompliance(repoId, repositoryInterface.getId(), repositoryInterface.getCompliance());
|
|
730 |
this.updateValidationSet(repoId, repositoryInterface.getId(), repositoryInterface.getAccessSet());
|
|
592 | 731 |
|
593 |
Repository e = this.getRepositoryById(repoId); |
|
594 |
emailUtils.sendAdminUpdateInterfaceEmail(e, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication()); |
|
595 |
emailUtils.sendUserUpdateInterfaceEmail(e, comment, repositoryInterface, SecurityContextHolder.getContext().getAuthentication()); |
|
596 |
submitInterfaceValidation(getRepositoryById(repoId),registeredBy,repositoryInterface,true); |
|
732 |
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 |
} |
|
597 | 739 |
|
740 |
submitInterfaceValidation(getRepositoryById(repoId), registeredBy, repositoryInterface, true); |
|
741 |
|
|
598 | 742 |
return repositoryInterface; |
599 | 743 |
} |
600 | 744 |
|
... | ... | |
665 | 809 |
|
666 | 810 |
@Override |
667 | 811 |
public List<Timezone> getTimezones() { |
668 |
List<String> timezones = Converter.readFile("timezones.txt");
|
|
812 |
List<String> timezones = Converter.readFile("timezones.txt"); |
|
669 | 813 |
return Converter.toTimezones(timezones); |
670 | 814 |
} |
671 | 815 |
|
672 | 816 |
@Override |
673 | 817 |
public List<String> getUrlsOfUserRepos(String userEmail, |
674 | 818 |
String page, |
675 |
String size){ |
|
819 |
String size) {
|
|
676 | 820 |
UriComponents uriComponents = UriComponentsBuilder |
677 | 821 |
.fromHttpUrl(baseAddress + "/api/baseurl/") |
678 | 822 |
.path("/{page}/{size}") |
679 |
.build().expand(page,size).encode(); |
|
823 |
.build().expand(page, size).encode();
|
|
680 | 824 |
|
681 |
try{ |
|
825 |
try {
|
|
682 | 826 |
RequestFilter requestFilter = new RequestFilter(); |
683 | 827 |
requestFilter.setRegisteredby(userEmail); |
684 |
return Arrays.asList(restTemplate.postForObject(uriComponents.toUri(),requestFilter, String[].class)); |
|
685 |
}catch (Exception e){
|
|
686 |
LOGGER.debug("Exception on addRepositoryInterface" , e);
|
|
828 |
return Arrays.asList(restTemplate.postForObject(uriComponents.toUri(), requestFilter, String[].class));
|
|
829 |
} catch (Exception e) {
|
|
830 |
LOGGER.debug("Exception on addRepositoryInterface", e); |
|
687 | 831 |
emailUtils.reportException(e); |
688 | 832 |
throw e; |
689 | 833 |
} |
... | ... | |
723 | 867 |
|
724 | 868 |
|
725 | 869 |
@Override |
726 |
public Map<String, String> getCompatibilityClasses(String mode) {
|
|
870 |
public Map<String, String> getCompatibilityClasses(String mode) { |
|
727 | 871 |
|
728 | 872 |
LOGGER.debug("Getting compatibility classes for mode: " + mode); |
729 | 873 |
Map<String, String> retMap = new HashMap<String, String>(); |
... | ... | |
752 | 896 |
} |
753 | 897 |
|
754 | 898 |
@Override |
755 |
public Map<String, String> getDatasourceClasses(String mode) {
|
|
899 |
public Map<String, String> getDatasourceClasses(String mode) { |
|
756 | 900 |
|
757 | 901 |
LOGGER.debug("Getting datasource classes for mode: " + mode); |
758 | 902 |
|
... | ... | |
773 | 917 |
retMap.put(entry.getKey(), entry.getValue()); |
774 | 918 |
} |
775 | 919 |
} |
776 |
return filterResults(retMap,mode); |
|
920 |
return filterResults(retMap, mode);
|
|
777 | 921 |
|
778 | 922 |
} |
779 | 923 |
|
780 |
private Map<String,String> filterResults(Map<String, String> map,String mode) {
|
|
924 |
private Map<String, String> filterResults(Map<String, String> map, String mode) {
|
|
781 | 925 |
|
782 |
HashMap<String,String> filteredMap = new HashMap<>(); |
|
783 |
for(String key:map.keySet())
|
|
784 |
if(dataSourceClass.get(mode).contains(key)) |
|
785 |
filteredMap.put(key,map.get(key)); |
|
926 |
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));
|
|
786 | 930 |
|
787 | 931 |
return filteredMap; |
788 | 932 |
} |
... | ... | |
810 | 954 |
|
811 | 955 |
@Override |
812 | 956 |
public Map<String, String> getListLatestUpdate(String mode) throws JSONException { |
813 |
if(mode.equals("opendoar")) |
|
814 |
return Collections.singletonMap("lastCollectionDate", getRepositoryInterface("openaire____::"+mode).get(0).getLastCollectionDate());
|
|
957 |
if (mode.equals("opendoar"))
|
|
958 |
return Collections.singletonMap("lastCollectionDate", getRepositoryInterface("openaire____::" + mode).get(0).getLastCollectionDate());
|
|
815 | 959 |
else |
816 | 960 |
/* |
817 |
* first api of re3data has null value on collection date |
|
818 |
* */ |
|
819 |
return Collections.singletonMap("lastCollectionDate", getRepositoryInterface("openaire____::"+mode).get(1).getLastCollectionDate());
|
|
961 |
* first api of re3data has null value on collection date
|
|
962 |
* */
|
|
963 |
return Collections.singletonMap("lastCollectionDate", getRepositoryInterface("openaire____::" + mode).get(1).getLastCollectionDate());
|
|
820 | 964 |
} |
821 | 965 |
|
822 | 966 |
private void updateValidationSet(String repositoryId, String repositoryInterfaceId, String validationSet) throws Exception { |
823 | 967 |
UriComponents uriComponents = UriComponentsBuilder |
824 | 968 |
.fromHttpUrl(baseAddress + "/ds/api/oaiset") |
825 |
.queryParam("dsId",repositoryId) |
|
826 |
.queryParam("apiId",repositoryInterfaceId) |
|
827 |
.queryParam("oaiSet",validationSet) |
|
969 |
.queryParam("dsId", repositoryId)
|
|
970 |
.queryParam("apiId", repositoryInterfaceId)
|
|
971 |
.queryParam("oaiSet", validationSet)
|
|
828 | 972 |
.build().encode(); |
829 |
restTemplate.exchange(uriComponents.toUri(),HttpMethod.POST, null, ResponseEntity.class);
|
|
973 |
restTemplate.exchange(uriComponents.toUri(), HttpMethod.POST, null, ResponseEntity.class);
|
|
830 | 974 |
|
831 | 975 |
} |
832 | 976 |
|
... | ... | |
834 | 978 |
private void updateBaseUrl(String repositoryId, String repositoryInterfaceId, String baseUrl) { |
835 | 979 |
UriComponents uriComponents = UriComponentsBuilder |
836 | 980 |
.fromHttpUrl(baseAddress + "/ds/api/baseurl") |
837 |
.queryParam("dsId",repositoryId) |
|
838 |
.queryParam("apiId",repositoryInterfaceId) |
|
839 |
.queryParam("baseUrl",baseUrl) |
|
981 |
.queryParam("dsId", repositoryId)
|
|
982 |
.queryParam("apiId", repositoryInterfaceId)
|
|
983 |
.queryParam("baseUrl", baseUrl)
|
|
840 | 984 |
.build().encode(); |
841 |
restTemplate.postForObject(uriComponents.toUri(),null,String.class);
|
|
985 |
restTemplate.postForObject(uriComponents.toUri(), null, String.class);
|
|
842 | 986 |
} |
843 | 987 |
|
844 |
private void updateCompliance(String repositoryId, String repositoryInterfaceId,String compliance) { |
|
988 |
private void updateCompliance(String repositoryId, String repositoryInterfaceId, String compliance) {
|
|
845 | 989 |
UriComponents uriComponents = UriComponentsBuilder |
846 | 990 |
.fromHttpUrl(baseAddress + "/ds/api/compliance") |
847 |
.queryParam("dsId",repositoryId) |
|
848 |
.queryParam("apiId",repositoryInterfaceId) |
|
849 |
.queryParam("compliance",compliance) |
|
991 |
.queryParam("dsId", repositoryId)
|
|
992 |
.queryParam("apiId", repositoryInterfaceId)
|
|
993 |
.queryParam("compliance", compliance)
|
|
850 | 994 |
.build().encode(); |
851 |
restTemplate.postForObject(uriComponents.toUri(),null,String.class);
|
|
995 |
restTemplate.postForObject(uriComponents.toUri(), null, String.class);
|
|
852 | 996 |
} |
853 | 997 |
|
854 | 998 |
private MetricsNumbers getMetricsNumbers(String openAIREID) throws BrokerException { |
... | ... | |
869 | 1013 |
new ParameterizedTypeReference<MetricsNumbers>() { |
870 | 1014 |
}); |
871 | 1015 |
} catch (RestClientException e) { |
872 |
LOGGER.debug("Exception on getMetricsNumbers" , e);
|
|
1016 |
LOGGER.debug("Exception on getMetricsNumbers", e); |
|
873 | 1017 |
emailUtils.reportException(e); |
874 | 1018 |
throw e; |
875 | 1019 |
} |
... | ... | |
886 | 1030 |
return null; |
887 | 1031 |
} |
888 | 1032 |
|
889 |
private UriComponents searchDatasource(String page,String size){
|
|
1033 |
private UriComponents searchDatasource(String page, String size) {
|
|
890 | 1034 |
|
891 | 1035 |
return UriComponentsBuilder |
892 | 1036 |
.fromHttpUrl(baseAddress + "/ds/search/") |
893 | 1037 |
.path("/{page}/{size}/") |
894 |
.queryParam("requestSortBy","officialname") |
|
895 |
.queryParam("order","ASCENDING") |
|
1038 |
.queryParam("requestSortBy", "officialname")
|
|
1039 |
.queryParam("order", "ASCENDING")
|
|
896 | 1040 |
.build().expand(page, size).encode(); |
897 | 1041 |
} |
898 | 1042 |
|
899 |
private UriComponents searchSnipperDatasource(String page,String size){
|
|
1043 |
private UriComponents searchSnipperDatasource(String page, String size) {
|
|
900 | 1044 |
|
901 | 1045 |
return UriComponentsBuilder |
902 | 1046 |
.fromHttpUrl(baseAddress + "/ds/searchsnippet/") |
903 | 1047 |
.path("/{page}/{size}/") |
904 |
.queryParam("requestSortBy","officialname") |
|
905 |
.queryParam("order","ASCENDING") |
|
1048 |
.queryParam("requestSortBy", "officialname")
|
|
1049 |
.queryParam("order", "ASCENDING")
|
|
906 | 1050 |
.build().expand(page, size).encode(); |
907 | 1051 |
} |
908 | 1052 |
|
909 |
private UriComponents searchRegisteredDatasource(String requestSortBy, String order, String page,String size){
|
|
1053 |
private UriComponents searchRegisteredDatasource(String requestSortBy, String order, String page, String size) {
|
|
910 | 1054 |
|
911 | 1055 |
return UriComponentsBuilder |
912 | 1056 |
.fromHttpUrl(baseAddress + "/ds/searchregistered/") |
913 | 1057 |
.path("/{page}/{size}/") |
914 |
.queryParam("requestSortBy",requestSortBy) |
|
915 |
.queryParam("order",order) |
|
1058 |
.queryParam("requestSortBy", requestSortBy)
|
|
1059 |
.queryParam("order", order)
|
|
916 | 1060 |
.build().expand(page, size).encode(); |
917 | 1061 |
} |
918 | 1062 |
|
919 |
private String getRepositoryType(String typology){ |
|
1063 |
private String getRepositoryType(String typology) {
|
|
920 | 1064 |
return invertedDataSourceClass.get(typology); |
921 | 1065 |
} |
922 | 1066 |
|
1067 |
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 |
} |
|
923 | 1081 |
|
1082 |
roleIds.addAll(registryCalls.getCouNames(couIds).values()); |
|
1083 |
|
|
1084 |
} |
|
1085 |
return roleIds; |
|
1086 |
} |
|
924 | 1087 |
} |
Also available in: Unified diff
merged branch aai_roles_new to trunk