1 |
1 |
package eu.dnetlib.repo.manager.server.services;
|
2 |
2 |
|
3 |
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
4 |
3 |
import com.unboundid.util.Base64;
|
5 |
4 |
import eu.dnetlib.domain.data.Repository;
|
6 |
5 |
import eu.dnetlib.domain.data.RepositoryInterface;
|
... | ... | |
10 |
9 |
import eu.dnetlib.repo.manager.client.services.RepositoryService;
|
11 |
10 |
import eu.dnetlib.repo.manager.server.utils.EmailUtils;
|
12 |
11 |
import eu.dnetlib.repo.manager.server.utils.LocalVocabularies;
|
|
12 |
import eu.dnetlib.repo.manager.service.controllers.RepositoryApi;
|
13 |
13 |
import eu.dnetlib.repo.manager.shared.*;
|
14 |
14 |
import eu.dnetlib.repos.RepoApi;
|
15 |
15 |
import gr.uoa.di.driver.enabling.vocabulary.VocabularyLoader;
|
16 |
16 |
import org.apache.commons.lang.StringEscapeUtils;
|
17 |
17 |
import org.apache.commons.lang.WordUtils;
|
18 |
18 |
import org.apache.log4j.Logger;
|
|
19 |
import org.json.JSONException;
|
19 |
20 |
import org.springframework.beans.factory.annotation.Autowired;
|
20 |
21 |
import org.springframework.beans.factory.annotation.Value;
|
21 |
22 |
import org.springframework.dao.EmptyResultDataAccessException;
|
... | ... | |
23 |
24 |
import org.springframework.stereotype.Service;
|
24 |
25 |
|
25 |
26 |
import javax.annotation.PostConstruct;
|
26 |
|
import java.io.IOException;
|
27 |
27 |
import java.text.Normalizer;
|
28 |
28 |
import java.util.*;
|
29 |
29 |
import java.util.concurrent.ConcurrentHashMap;
|
... | ... | |
83 |
83 |
"</noscript>\n" +
|
84 |
84 |
"<!— End Piwik Code —>");
|
85 |
85 |
|
|
86 |
|
|
87 |
/*----------------------------------------------------------------------------*/
|
|
88 |
|
|
89 |
@Autowired
|
|
90 |
private RepositoryApi repositoryApi;
|
|
91 |
|
|
92 |
|
|
93 |
|
86 |
94 |
@PostConstruct
|
87 |
95 |
public void init() {
|
88 |
96 |
this.loadVocabularies();
|
... | ... | |
137 |
145 |
|
138 |
146 |
@Override
|
139 |
147 |
public DatasourcesCollection getRepositoriesOfUser(String userEmail, boolean includeShared, boolean includeByOthers) throws RepositoryServiceException {
|
140 |
|
try {
|
|
148 |
/*try {
|
141 |
149 |
LOGGER.debug("Getting repositories of user: " + userEmail + " . IncludeShared: " + includeShared + " . IncludeByOthers: " + includeByOthers);
|
142 |
150 |
DatasourcesCollection retDatasources = new DatasourcesCollection();
|
143 |
151 |
retDatasources.setDatasourcesOfUser(this.repoAPI.getRepositoriesOfUser(userEmail, false));
|
... | ... | |
160 |
168 |
emailUtils.reportException(e);
|
161 |
169 |
throw new RepositoryServiceException("login.generalError", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
|
162 |
170 |
}
|
|
171 |
}*/
|
|
172 |
DatasourcesCollection retDatasources = new DatasourcesCollection();
|
|
173 |
try {
|
|
174 |
LOGGER.debug("Getting repositories of user: " + userEmail + " . IncludeShared: "
|
|
175 |
+ includeShared + " . IncludeByOthers: " + includeByOthers);
|
|
176 |
int page = 1;
|
|
177 |
String size = "10";
|
|
178 |
List<Repository> resultSet = repositoryApi.getRepositoriesOfUser(userEmail,String.valueOf(page),size);
|
|
179 |
LOGGER.debug("Resultset size -> " + resultSet.size() );
|
|
180 |
while(resultSet.size() > 0 ){
|
|
181 |
LOGGER.debug("Resultset size -> " + resultSet.size() );
|
|
182 |
retDatasources.getDatasourcesOfUser().addAll(resultSet);
|
|
183 |
page++;
|
|
184 |
resultSet = repositoryApi.getRepositoriesOfUser(userEmail,String.valueOf(page),size);
|
|
185 |
}
|
|
186 |
} catch (JSONException e) {
|
|
187 |
LOGGER.error("Error while getting repositories of user: " + userEmail + " . IncludeShared: " + includeShared + " . IncludeByOthers: " + includeByOthers, e);
|
163 |
188 |
}
|
|
189 |
return retDatasources;
|
164 |
190 |
}
|
165 |
191 |
|
166 |
192 |
@Override
|
... | ... | |
169 |
195 |
LOGGER.debug("Getting repositories(urls) of user: " + userEmail + " . IncludeShared: " + includeShared + " . IncludeByOthers: " + includeByOthers);
|
170 |
196 |
List<String> retRepos = new ArrayList<String>();
|
171 |
197 |
|
172 |
|
retRepos.addAll(this.repoAPI.getUrlsOfRepos(userEmail, false));
|
173 |
|
|
|
198 |
int page = 1;
|
|
199 |
String size = "10";
|
|
200 |
List<String> resultSet = repositoryApi.getUrlsOfUserRepos(userEmail,String.valueOf(page),size);
|
|
201 |
while(resultSet.size() > 0 ){
|
|
202 |
retRepos.addAll(resultSet);
|
|
203 |
page++;
|
|
204 |
resultSet = repositoryApi.getUrlsOfUserRepos(userEmail,String.valueOf(page),size);
|
|
205 |
}
|
|
206 |
//retRepos.addAll(this.repoAPI.getUrlsOfRepos(userEmail, false));
|
174 |
207 |
return retRepos;
|
175 |
208 |
|
176 |
209 |
} catch (Exception e) {
|
177 |
210 |
LOGGER.error("Error while getting repositories(urls) of user: " + userEmail + " . IncludeShared: " + includeShared + " . IncludeByOthers: " + includeByOthers, e);
|
178 |
|
if (e instanceof RepositoryServiceException) {
|
179 |
|
throw (RepositoryServiceException) e;
|
180 |
|
} else {
|
181 |
|
emailUtils.reportException(e);
|
182 |
|
throw new RepositoryServiceException("login.generalError", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
|
183 |
|
}
|
|
211 |
emailUtils.reportException(e);
|
|
212 |
throw new RepositoryServiceException("login.generalError", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
|
184 |
213 |
}
|
185 |
214 |
}
|
186 |
215 |
|
... | ... | |
189 |
218 |
try {
|
190 |
219 |
LOGGER.debug("Getting repository with id: " + repoId);
|
191 |
220 |
|
192 |
|
Repository repo = this.repoAPI.getRepository(repoId);
|
|
221 |
// Repository repo = this.repoAPI.getRepository(repoId);
|
|
222 |
|
|
223 |
Repository repo = repositoryApi.getRepositoryById(repoId);
|
|
224 |
|
193 |
225 |
if (repo != null) {
|
194 |
226 |
for (RepositoryInterface iFace : repo.getInterfaces()) {
|
195 |
227 |
if (!iFace.getContentDescription().equals("file::hybrid") && iFace.getAccessProtocol().equalsIgnoreCase("oai")) {
|
... | ... | |
221 |
253 |
|
222 |
254 |
Map<String, String> countriesMap = new TreeMap<String, String>();
|
223 |
255 |
|
224 |
|
if (existingOnly) {
|
|
256 |
/* if (existingOnly) {
|
225 |
257 |
LOGGER.debug("using the repositories map");
|
226 |
258 |
countries.addAll(this.repoAPI.getRepositoriesByCountry(mode).keySet());
|
227 |
259 |
} else {
|
228 |
260 |
LOGGER.debug("using \"dnet:countries\" vocabulary");
|
229 |
261 |
countries.addAll(this.getVocabulary("dnet:countries").getEnglishNames());
|
230 |
|
}
|
231 |
|
|
|
262 |
}*/
|
|
263 |
countries.addAll(repositoryApi.getDnetCountries());
|
232 |
264 |
for (String country : countries) {
|
233 |
265 |
countriesMap.put(country, WordUtils.capitalizeFully(country));
|
234 |
266 |
}
|
... | ... | |
237 |
269 |
|
238 |
270 |
} catch (Exception e) {
|
239 |
271 |
LOGGER.error("Error while getting getting countries", e);
|
240 |
|
if (e instanceof RepositoryServiceException) {
|
|
272 |
/*if (e instanceof RepositoryServiceException) {
|
241 |
273 |
throw (RepositoryServiceException) e;
|
242 |
|
} else {
|
|
274 |
} else {*/
|
243 |
275 |
emailUtils.reportException(e);
|
244 |
276 |
throw new RepositoryServiceException("login.generalError", RepositoryServiceException.ErrorCode.GENERAL_ERROR);
|
245 |
|
}
|
|
277 |
// }
|
246 |
278 |
}
|
247 |
279 |
}
|
248 |
280 |
|
... | ... | |
255 |
287 |
public List<Timezone> getTimezones() throws RepositoryServiceException {
|
256 |
288 |
try {
|
257 |
289 |
LOGGER.debug("Getting timezones from file");
|
258 |
|
return LocalVocabularies.timezones;
|
|
290 |
return repositoryApi.getTimezones();
|
|
291 |
//return LocalVocabularies.timezones;
|
259 |
292 |
} catch (Exception e) {
|
260 |
293 |
LOGGER.error("Error while getting timezones from file", e);
|
261 |
294 |
emailUtils.reportException(e);
|
... | ... | |
268 |
301 |
public List<String> getTypologies() throws RepositoryServiceException {
|
269 |
302 |
try {
|
270 |
303 |
LOGGER.debug("Getting typologies from file");
|
271 |
|
return LocalVocabularies.typologies;
|
|
304 |
return repositoryApi.getTypologies();
|
|
305 |
//return LocalVocabularies.typologies;
|
272 |
306 |
} catch (Exception e) {
|
273 |
307 |
LOGGER.error("Error while getting typologies from file", e);
|
274 |
308 |
emailUtils.reportException(e);
|
1. Update pom.xml with uoa-repository-manager-service dependency.
2. Change log4j properties.
3. Changes on repository implementation.