2 |
2 |
|
3 |
3 |
import eu.dnetlib.domain.data.Repository;
|
4 |
4 |
import eu.dnetlib.repo.manager.client.RepositoryService;
|
|
5 |
import eu.dnetlib.repo.manager.server.utils.EmailUtils;
|
5 |
6 |
import eu.dnetlib.repo.manager.shared.RepositoryServiceException;
|
6 |
7 |
import eu.dnetlib.repos.RepoApi;
|
|
8 |
import gr.uoa.di.driver.enabling.vocabulary.VocabularyLoader;
|
7 |
9 |
import org.apache.log4j.Logger;
|
8 |
10 |
import org.springframework.beans.factory.annotation.Autowired;
|
9 |
11 |
import org.springframework.beans.factory.annotation.Value;
|
10 |
12 |
import org.springframework.stereotype.Service;
|
11 |
13 |
|
|
14 |
import java.util.ArrayList;
|
12 |
15 |
import java.util.List;
|
|
16 |
import java.util.Locale;
|
|
17 |
import java.util.Set;
|
13 |
18 |
|
14 |
19 |
/**
|
15 |
20 |
* Created by nikonas on 12/8/15.
|
... | ... | |
24 |
29 |
@Autowired
|
25 |
30 |
private RepoApi repoAPI;
|
26 |
31 |
|
27 |
|
@Value("${services.repo-manager.baseUrl}")
|
28 |
|
private String repoManagerBaseUrl;
|
|
32 |
@Autowired
|
|
33 |
private EmailUtils emailUtils;
|
29 |
34 |
|
|
35 |
@Autowired
|
|
36 |
private VocabularyLoader vocabularyLoader;
|
|
37 |
|
30 |
38 |
@Override
|
31 |
39 |
public List<Repository> getRepositoriesByCountry(String country, String mode) throws RepositoryServiceException {
|
32 |
40 |
try {
|
... | ... | |
40 |
48 |
|
41 |
49 |
} catch (Exception e) {
|
42 |
50 |
LOGGER.error("Error while getting repositories of country: " + country + " with type: " + mode);
|
|
51 |
emailUtils.reportException(e);
|
43 |
52 |
if (e instanceof RepositoryServiceException) {
|
44 |
53 |
throw (RepositoryServiceException) e;
|
45 |
54 |
} else {
|
46 |
55 |
throw new RepositoryServiceException("login.generalError", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
|
47 |
56 |
}
|
48 |
|
// reportException(e);
|
49 |
57 |
}
|
50 |
58 |
}
|
51 |
59 |
|
... | ... | |
62 |
70 |
|
63 |
71 |
} catch (Exception e) {
|
64 |
72 |
LOGGER.error("Error while getting repository with id: " + repoId + " and name: " + officialName);
|
|
73 |
emailUtils.reportException(e);
|
65 |
74 |
if (e instanceof RepositoryServiceException) {
|
66 |
75 |
throw (RepositoryServiceException) e;
|
67 |
76 |
} else {
|
68 |
77 |
throw new RepositoryServiceException("login.generalError", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
|
69 |
78 |
}
|
70 |
|
// reportException(e);
|
71 |
79 |
}
|
72 |
80 |
}
|
73 |
81 |
|
74 |
82 |
@Override
|
|
83 |
public List<String> getCountries(Boolean existingOnly, String mode) throws RepositoryServiceException {
|
|
84 |
try {
|
|
85 |
LOGGER.debug("Getting countries");
|
|
86 |
List<String> countries = new ArrayList<String>();
|
|
87 |
if (existingOnly) {
|
|
88 |
LOGGER.debug("using the repositories map");
|
|
89 |
countries.addAll(this.repoAPI.getRepositoriesByCountry(mode).keySet());
|
|
90 |
} else {
|
|
91 |
LOGGER.debug("using \"dnet:countries\" vocabulary");
|
|
92 |
countries.addAll(vocabularyLoader.getVocabulary("dnet:countries", Locale.ENGLISH, Locale.ROOT).getEnglishNames());
|
|
93 |
}
|
|
94 |
return countries;
|
|
95 |
|
|
96 |
} catch (Exception e) {
|
|
97 |
LOGGER.error("Error while getting getting countries");
|
|
98 |
emailUtils.reportException(e);
|
|
99 |
if (e instanceof RepositoryServiceException) {
|
|
100 |
throw (RepositoryServiceException) e;
|
|
101 |
} else {
|
|
102 |
throw new RepositoryServiceException("login.generalError", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
|
|
103 |
}
|
|
104 |
}
|
|
105 |
}
|
|
106 |
|
|
107 |
@Override
|
|
108 |
public List<String> getCountries() throws RepositoryServiceException {
|
|
109 |
return this.getCountries(false,null);
|
|
110 |
}
|
|
111 |
|
|
112 |
@Override
|
75 |
113 |
public void storeRepository(Repository repo, String mode) throws RepositoryServiceException {
|
76 |
114 |
|
|
115 |
|
|
116 |
/* try {
|
|
117 |
LOGGER.debug("Getting repository with id: " + repoId + " and name: " + officialName);
|
|
118 |
|
|
119 |
Repository repo = this.repoAPI.getRepository(officialName, repoId);
|
|
120 |
if (repo == null) {
|
|
121 |
throw new RepositoryServiceException("registration.repositoryNotExists", RepositoryServiceException.ErrorCode.REPOSITORY_NOT_EXISTS);
|
|
122 |
}
|
|
123 |
return repo;
|
|
124 |
|
|
125 |
} catch (Exception e) {
|
|
126 |
LOGGER.error("Error while getting repository with id: " + repoId + " and name: " + officialName);
|
|
127 |
emailUtils.reportException(e);
|
|
128 |
if (e instanceof RepositoryServiceException) {
|
|
129 |
throw (RepositoryServiceException) e;
|
|
130 |
} else {
|
|
131 |
throw new RepositoryServiceException("login.generalError", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
|
|
132 |
}
|
|
133 |
}*/
|
77 |
134 |
}
|
78 |
135 |
}
|
added methods to getCountries