Revision 50001
Added by Antonis Lempesis over 6 years ago
RepositoryServiceImpl.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.repo.manager.server.services; |
2 | 2 |
|
3 |
import com.fasterxml.jackson.databind.DeserializationConfig; |
|
3 | 4 |
import com.fasterxml.jackson.databind.ObjectMapper; |
5 |
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; |
|
4 | 6 |
import com.unboundid.util.Base64; |
5 | 7 |
import eu.dnetlib.domain.data.PiwikInfo; |
6 | 8 |
import eu.dnetlib.domain.data.Repository; |
... | ... | |
11 | 13 |
import eu.dnetlib.repo.manager.client.services.RepositoryService; |
12 | 14 |
import eu.dnetlib.repo.manager.server.utils.EmailUtils; |
13 | 15 |
import eu.dnetlib.repo.manager.server.utils.LocalVocabularies; |
16 |
import eu.dnetlib.domain.data.PiwikInfo; |
|
14 | 17 |
import eu.dnetlib.repo.manager.service.controllers.RepositoryApi; |
15 | 18 |
import eu.dnetlib.repo.manager.shared.*; |
16 | 19 |
import eu.dnetlib.repos.RepoApi; |
... | ... | |
20 | 23 |
import org.apache.commons.lang.WordUtils; |
21 | 24 |
import org.apache.log4j.Logger; |
22 | 25 |
import org.json.JSONException; |
26 |
import org.json.JSONObject; |
|
23 | 27 |
import org.springframework.beans.factory.annotation.Autowired; |
24 | 28 |
import org.springframework.beans.factory.annotation.Value; |
25 | 29 |
import org.springframework.core.ParameterizedTypeReference; |
... | ... | |
170 | 174 |
try { |
171 | 175 |
LOGGER.debug("Getting repositories of user: " + userEmail + " . IncludeShared: " |
172 | 176 |
+ includeShared + " . IncludeByOthers: " + includeByOthers); |
173 |
int page = 1;
|
|
174 |
String size = "10";
|
|
177 |
int page = 0;
|
|
178 |
String size = "50";
|
|
175 | 179 |
List<Repository> resultSet = repositoryApi.getRepositoriesOfUser(userEmail,String.valueOf(page),size); |
176 | 180 |
while(resultSet.size() > 0 ){ |
177 | 181 |
retDatasources.getDatasourcesOfUser().addAll(resultSet); |
... | ... | |
210 | 214 |
LOGGER.debug("Getting repositories(urls) of user: " + userEmail + " . IncludeShared: " + includeShared + " . IncludeByOthers: " + includeByOthers); |
211 | 215 |
List<String> retRepos = new ArrayList<String>(); |
212 | 216 |
|
213 |
int page = 1;
|
|
214 |
String size = "10";
|
|
217 |
int page = 0;
|
|
218 |
String size = "50";
|
|
215 | 219 |
List<String> resultSet = repositoryApi.getUrlsOfUserRepos(userEmail,String.valueOf(page),size); |
216 | 220 |
while(resultSet.size() > 0 ){ |
217 | 221 |
retRepos.addAll(resultSet); |
... | ... | |
340 | 344 |
|
341 | 345 |
try { |
342 | 346 |
LOGGER.debug("Storing repository with name: " + repo.getOfficialName()); |
343 |
List<RepositoryInterface> interfacesToRegister = new ArrayList<RepositoryInterface>(); |
|
347 |
//List<RepositoryInterface> interfacesToRegister = new ArrayList<RepositoryInterface>(); |
|
348 |
JSONObject params = new JSONObject(); |
|
349 |
params.put("datatype", mode); |
|
350 |
ObjectMapper mapper = new ObjectMapper(); |
|
351 |
String json_repo = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(repo); |
|
352 |
params.put("repository", json_repo); |
|
353 |
repositoryApi.addRepository(params.toString()); |
|
354 |
LOGGER.debug("Repository with name: " + repo.getOfficialName() + " stored!"); |
|
344 | 355 |
|
345 |
//TODO update map |
|
346 |
repo.setCountryCode(getCountryCode(repo.getCountryName())); |
|
347 |
|
|
348 |
repo.setActivationId(UUID.randomUUID().toString()); |
|
349 |
// repo.setRegisteredBy((String) session.get(LocalVocabularies.loggedInField)); |
|
350 |
|
|
351 |
if (mode.equals("opendoar") || mode.equals("re3data")) { |
|
352 |
repo.setProvenanceActionClass("sysimport:crosswalk:entityregistry"); |
|
353 |
} else if (mode.equals("journal")) { |
|
354 |
repo.setProvenanceActionClass("user:insert"); |
|
355 |
repo.setCollectedFrom("infrastruct_::openaire"); |
|
356 |
if (repo.getIssn() != null && repo.getIssn().length() == 0) |
|
357 |
repo.setIssn(Base64.encode(repo.getOfficialName()).substring(0, 8)); |
|
358 |
repo.setId("openaire____::issn" + repo.getIssn()); |
|
359 |
repo.setNamespacePrefix("issn" + repo.getIssn()); |
|
360 |
} else if (mode.equals("aggregator")) { |
|
361 |
repo.setProvenanceActionClass("user:insert"); |
|
362 |
repo.setCollectedFrom("infrastruct_::openaire"); |
|
363 |
repo.setId("openaire____::" + Base64.encode(repo.getOfficialName())); |
|
364 |
repo.setNamespacePrefix(Normalizer.normalize(repo.getOfficialName().toLowerCase().replace(" ", "_"), Normalizer.Form.NFD).replaceAll("[^a-zA-Z0-9]", "")); |
|
365 |
if (repo.getNamespacePrefix().length() > 12) { |
|
366 |
repo.setNamespacePrefix(repo.getNamespacePrefix().substring(0, 12)); |
|
367 |
} else { |
|
368 |
while (repo.getNamespacePrefix().length() < 12) |
|
369 |
repo.setNamespacePrefix(repo.getNamespacePrefix().concat("_")); |
|
370 |
} |
|
371 |
} |
|
372 |
repositoryApi.addRepository(repo); |
|
373 |
} catch (JSONException e) { |
|
374 |
LOGGER.error("Error while Storing repository with name: " + repo.getOfficialName(), e); |
|
375 |
emailUtils.reportException(e); |
|
376 |
throw new RepositoryServiceException("login.generalError", RepositoryServiceException.ErrorCode.GENERAL_ERROR); |
|
356 |
}catch (Exception e) { |
|
357 |
emailUtils.reportException(e); |
|
358 |
LOGGER.error("Error while storing repository with name: " + repo.getOfficialName(), e); |
|
359 |
throw new RepositoryServiceException("Error while storing repository", RepositoryServiceException.ErrorCode.GENERAL_ERROR); |
|
377 | 360 |
} |
378 | 361 |
} |
379 | 362 |
|
... | ... | |
389 | 372 |
repositoryApi.updateLatitude(repo.getId(), String.valueOf(repo.getLatitude())); |
390 | 373 |
repositoryApi.updateLongitude(repo.getId(), String.valueOf(repo.getLongitude())); |
391 | 374 |
repositoryApi.updateOfficialName(repo.getId(),repo.getOfficialName()); |
375 |
repositoryApi.updateLogoUrl(repo.getId(),repo.getLogoUrl()); |
|
376 |
repositoryApi.updateTimezone(repo.getId(),String.valueOf(repo.getTimezone())); |
|
377 |
repositoryApi.updatePlatform(repo.getId(),repo.getTypology()); |
|
378 |
|
|
392 | 379 |
} catch (Exception e) { |
393 | 380 |
LOGGER.error("Error while updating information of repo: " + repo.getOfficialName(), e); |
394 | 381 |
if (e instanceof RepositoryServiceException) { |
... | ... | |
427 | 414 |
RepositoryInterface retIface = null; |
428 | 415 |
//retIface = this.repoAPI.insertRepositoryInterfaceWithoutChecks(repoId, iFace, datatype); |
429 | 416 |
|
430 |
Repository e = this.getRepository(repoId); |
|
431 |
iFace.setContentDescription("metadata"); |
|
432 |
iFace.setCompliance("UNKNOWN"); |
|
433 |
if(e.getDatasourceClass() == null) { |
|
434 |
if(datatype.equalsIgnoreCase("journal")) { |
|
435 |
iFace.setTypology("pubsrepository::journal"); |
|
436 |
} else if(datatype.equalsIgnoreCase("aggregator")) { |
|
437 |
iFace.setTypology("aggregator::pubsrepository::unknown"); |
|
438 |
} else { |
|
439 |
iFace.setTypology("pubsrepository::unknown"); |
|
440 |
} |
|
441 |
} else { |
|
442 |
iFace.setTypology(e.getDatasourceClass()); |
|
443 |
} |
|
444 |
|
|
445 |
if(datatype.equals("re3data")) { |
|
446 |
iFace.setAccessFormat("oai_datacite"); |
|
447 |
} else { |
|
448 |
iFace.setAccessFormat("oai_dc"); |
|
449 |
} |
|
450 |
|
|
451 |
iFace.setAccessProtocol("oai"); |
|
452 |
iFace.setRemovable(true); |
|
453 |
iFace.setMetadataIdentifierPath("//*[local-name()=\'header\']/*[local-name()=\'identifier\']"); |
|
454 |
iFace.setId("api_________::" + repoId + "::" + UUID.randomUUID().toString().substring(0, 8)); |
|
455 |
if(iFace.getAccessSet().isEmpty()) { |
|
456 |
LOGGER.debug("set is empty: " + iFace.getAccessSet()); |
|
457 |
iFace.removeAccessSet(); |
|
458 |
} |
|
459 |
|
|
460 |
retIface = repositoryApi.addRepositoryInterface(iFace); |
|
417 |
JSONObject params = new JSONObject(); |
|
418 |
params.put("datatype",datatype); |
|
419 |
params.put("repoId",repoId); |
|
420 |
params.put("iFace",iFace); |
|
421 |
retIface = repositoryApi.addRepositoryInterface(params.toString()); |
|
461 | 422 |
retIface.setComplianceName(this.getComplianceName(retIface.getCompliance())); |
462 |
|
|
463 | 423 |
return retIface; |
464 | 424 |
|
465 | 425 |
} catch (Exception e) { |
... | ... | |
756 | 716 |
|
757 | 717 |
return null; |
758 | 718 |
} |
759 |
} |
|
719 |
} |
Also available in: Unified diff
merged (again...) newAPI branch to trunk.