parent
cbb0848d5c
commit
0b62a37073
|
@ -121,32 +121,9 @@ public class PiWikApiImpl implements PiWikApi{
|
|||
public void enableMetricsForRepository(@RequestBody PiwikInfo piwikInfo) throws RepositoryServiceException {
|
||||
|
||||
try {
|
||||
String URL = analyticsURL + "siteName=" + URLEncoder.encode(piwikInfo.getRepositoryName(), "UTF-8")
|
||||
+ "&url=" + piwikInfo.getSiteId();
|
||||
Map<String, Object> map = new ObjectMapper().readValue(new URL(URL), Map.class);
|
||||
|
||||
/* String siteId = null;
|
||||
if(map.get("value")!=null) {
|
||||
siteId = map.get("value").toString();
|
||||
}
|
||||
|
||||
String authenticationToken = "32846584f571be9b57488bf4088f30ea";
|
||||
|
||||
PiwikInfo piwikInfo = new PiwikInfo();
|
||||
piwikInfo.setRepositoryId(repository.getId());
|
||||
piwikInfo.setRepositoryName(repository.getOfficialName());
|
||||
piwikInfo.setCountry(repository.getCountryName());
|
||||
piwikInfo.setSiteId(siteId);
|
||||
piwikInfo.setAuthenticationToken(authenticationToken);
|
||||
piwikInfo.setRequestorEmail(userProfile.getEmail());
|
||||
piwikInfo.setRequestorName(userProfile.getFirstname() + " " + userProfile.getLastname());
|
||||
piwikInfo.setValidated(false);
|
||||
*/
|
||||
savePiwikInfo(piwikInfo);
|
||||
|
||||
emailUtils.sendAdministratorRequestToEnableMetrics(piwikInfo);
|
||||
emailUtils.sendUserRequestToEnableMetrics(piwikInfo);
|
||||
|
||||
} catch (UnsupportedEncodingException uee) {
|
||||
LOGGER.error("Error while creating piwikScript URL", uee);
|
||||
emailUtils.reportException(uee);
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package eu.dnetlib.repo.manager.service.controllers;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import eu.dnetlib.domain.data.Repository;
|
||||
import eu.dnetlib.domain.data.RepositoryInterface;
|
||||
import eu.dnetlib.domain.enabling.Vocabulary;
|
||||
|
@ -63,6 +66,41 @@ public class RepositoryApiImpl implements RepositoryApi {
|
|||
private Map<String, String> countriesMap = new HashMap<>();
|
||||
private Map<String, String> inverseCountriesMap = new HashMap<>();
|
||||
|
||||
private static Map<String,List<String>> dataSourceClass = new HashMap<String,List<String>>(){{
|
||||
put("opendoar",new ArrayList<String>(){{ add("pubsrepository::institutional");
|
||||
add("pubsrepository::thematic");
|
||||
add("pubsrepository::unknown");
|
||||
add("pubsrepository::mock");
|
||||
}});
|
||||
put("re3data",new ArrayList<String>(){{ add("datarepository::unknown");
|
||||
}});
|
||||
put("journal",new ArrayList<String>(){{ add("pubsrepository::journal");
|
||||
}});
|
||||
put("aggregator",new ArrayList<String>(){{ add("aggregator::pubsrepository::institutional");
|
||||
add("aggregator::pubsrepository::journals");
|
||||
add("aggregator::datarepository");
|
||||
add("aggregator::pubsrepository::unknown");
|
||||
}});
|
||||
}};
|
||||
|
||||
private static Map<String,String> invertedDataSourceClass = new HashMap<String,String>(){{
|
||||
put("pubsrepository::institutional","opendoar");
|
||||
put("pubsrepository::thematic","opendoar");
|
||||
put("pubsrepository::unknown","opendoar");
|
||||
put("pubsrepository::mock","opendoar");
|
||||
|
||||
put("datarepository::unknown","re3data");
|
||||
|
||||
put("pubsrepository::journal","journal");
|
||||
|
||||
put("aggregator::pubsrepository::institutional","aggregator");
|
||||
put("aggregator::pubsrepository::journals","aggregator");
|
||||
put("aggregator::datarepository","aggregator");
|
||||
put("aggregator::pubsrepository::unknown","aggregator");
|
||||
|
||||
}};
|
||||
|
||||
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
|
@ -180,6 +218,12 @@ public class RepositoryApiImpl implements RepositoryApi {
|
|||
}
|
||||
|
||||
private void getRepositoryInfo(Repository r) throws JSONException {
|
||||
|
||||
/*
|
||||
* from datasource class
|
||||
* we get the datasource type form the inverted map
|
||||
* */
|
||||
r.setDatasourceType(getRepositoryType(r.getDatasourceClass()));
|
||||
r.setInterfaces(this.getRepositoryInterface(r.getId()));
|
||||
r.setPiwikInfo(piWikApi.getPiwikSiteForRepo(r.getId()));
|
||||
r.setCountryName(getCountryName(r.getCountryCode()));
|
||||
|
@ -313,31 +357,17 @@ public class RepositoryApiImpl implements RepositoryApi {
|
|||
|
||||
//TODO update map
|
||||
repository.setCountryCode(countriesMap.get(repository.getCountryName()));
|
||||
|
||||
repository.setActivationId(UUID.randomUUID().toString());
|
||||
// repo.setRegisteredBy((String) session.get(LocalVocabularies.loggedInField));
|
||||
repository.setCollectedFrom("infrastruct_::openaire");
|
||||
|
||||
if (datatype.equals("opendoar") || datatype.equals("re3data")) {
|
||||
repository.setProvenanceActionClass("sysimport:crosswalk:entityregistry");
|
||||
} else if (datatype.equals("journal")) {
|
||||
repository.setProvenanceActionClass("user:insert");
|
||||
repository.setCollectedFrom("infrastruct_::openaire");
|
||||
if (repository.getIssn() != null && repository.getIssn().length() == 0)
|
||||
repository.setIssn(com.unboundid.util.Base64.encode(repository.getOfficialName()).substring(0, 8));
|
||||
if (datatype.equals("journal")) {
|
||||
repository.setId("openaire____::issn" + repository.getIssn());
|
||||
repository.setNamespacePrefix("issn" + repository.getIssn());
|
||||
} else if (datatype.equals("aggregator")) {
|
||||
repository.setProvenanceActionClass("user:insert");
|
||||
repository.setCollectedFrom("infrastruct_::openaire");
|
||||
}else if (datatype.equals("aggregator")) {
|
||||
repository.setId("openaire____::" + com.unboundid.util.Base64.encode(repository.getOfficialName()));
|
||||
repository.setNamespacePrefix(Normalizer.normalize(repository.getOfficialName().toLowerCase().replace(" ", "_"), Normalizer.Form.NFD).replaceAll("[^a-zA-Z0-9]", ""));
|
||||
if (repository.getNamespacePrefix().length() > 12) {
|
||||
repository.setNamespacePrefix(repository.getNamespacePrefix().substring(0, 12));
|
||||
} else {
|
||||
while (repository.getNamespacePrefix().length() < 12)
|
||||
repository.setNamespacePrefix(repository.getNamespacePrefix().concat("_"));
|
||||
}
|
||||
repository.setNamespacePrefix(DigestUtils.md5Hex(repository.getOfficialName()).substring(0,12));
|
||||
}
|
||||
|
||||
return repository;
|
||||
}
|
||||
|
||||
|
@ -379,6 +409,15 @@ public class RepositoryApiImpl implements RepositoryApi {
|
|||
.build()
|
||||
.encode();
|
||||
String json_repository = Converter.repositoryObjectToJson(repository);
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.enable(SerializationFeature.INDENT_OUTPUT);
|
||||
try {
|
||||
LOGGER.debug(mapper.writeValueAsString(json_repository));
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
HttpEntity<String> httpEntity = new HttpEntity <String> (json_repository,httpHeaders);
|
||||
restTemplate.postForObject(uriComponents.toUri(),httpEntity,String.class);
|
||||
}
|
||||
|
@ -566,10 +605,20 @@ public class RepositoryApiImpl implements RepositoryApi {
|
|||
retMap.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
return retMap;
|
||||
return filterResults(retMap,mode);
|
||||
|
||||
}
|
||||
|
||||
private Map<String,String> filterResults(Map<String, String> map,String mode) {
|
||||
|
||||
HashMap<String,String> filteredMap = new HashMap<>();
|
||||
for(String key:map.keySet())
|
||||
if(dataSourceClass.get(mode).contains(key))
|
||||
filteredMap.put(key,map.get(key));
|
||||
|
||||
return filteredMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCountryName(String countryCode) {
|
||||
return inverseCountriesMap.get(countryCode);
|
||||
|
@ -608,9 +657,20 @@ public class RepositoryApiImpl implements RepositoryApi {
|
|||
|
||||
this.updateBaseUrl(repoId,repositoryInterface.getId(),repositoryInterface.getBaseUrl());
|
||||
this.updateCompliance(repoId,repositoryInterface.getId(),repositoryInterface.getCompliance());
|
||||
this.updateValidationSet(repoId,repositoryInterface.getId(),repositoryInterface.getAccessSet());
|
||||
return repositoryInterface;
|
||||
}
|
||||
|
||||
private void updateValidationSet(String repositoryId, String repositoryInterfaceId, String validationSet) {
|
||||
UriComponents uriComponents = UriComponentsBuilder
|
||||
.fromHttpUrl(baseAddress + "/ds/api/oaiset")
|
||||
.queryParam("dsId",repositoryId)
|
||||
.queryParam("apiId",repositoryInterfaceId)
|
||||
.queryParam("oaiSet",validationSet)
|
||||
.build().encode();
|
||||
restTemplate.postForObject(uriComponents.toUri(),null,String.class);
|
||||
}
|
||||
|
||||
|
||||
private void updateBaseUrl(String repositoryId, String repositoryInterfaceId, String baseUrl) {
|
||||
UriComponents uriComponents = UriComponentsBuilder
|
||||
|
@ -675,5 +735,9 @@ public class RepositoryApiImpl implements RepositoryApi {
|
|||
.build().expand(page, size).encode();
|
||||
}
|
||||
|
||||
private String getRepositoryType(String typology){
|
||||
return invertedDataSourceClass.get(typology);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -40,11 +40,18 @@ public class Converter {
|
|||
repository.setEnglishName("");
|
||||
|
||||
repository.setWebsiteUrl(datasource.get("websiteurl").toString());
|
||||
if(repository.getWebsiteUrl().equals("null"))
|
||||
repository.setWebsiteUrl("");
|
||||
|
||||
repository.setLogoUrl(datasource.get("logourl").toString());
|
||||
if(repository.getLogoUrl().equals("null"))
|
||||
repository.setLogoUrl("");
|
||||
|
||||
repository.setContactEmail(datasource.get("contactemail").toString());
|
||||
if(repository.getContactEmail().equals("null"))
|
||||
repository.setContactEmail("");
|
||||
|
||||
|
||||
repository.setLatitude( toDouble(datasource.get("latitude").toString()));
|
||||
repository.setLongitude(toDouble(datasource.get("longitude").toString()));
|
||||
Double timezone = toDouble(datasource.get("timezone").toString());
|
||||
|
@ -69,28 +76,20 @@ public class Converter {
|
|||
|
||||
repository.setIssn(datasource.get("issn").toString());
|
||||
repository.setLissn(datasource.get("lissn").toString());
|
||||
if(repository.getLissn().equals("null"))
|
||||
repository.setLissn("");
|
||||
repository.setEissn(datasource.get("eissn").toString());
|
||||
if(repository.getEissn().equals("null"))
|
||||
repository.setEissn("");
|
||||
repository.setRegisteredBy(datasource.get("registeredby").toString());
|
||||
|
||||
/* managed field */
|
||||
repository.setRegistered(Boolean.parseBoolean(datasource.get("managed").toString()));
|
||||
|
||||
//subjects
|
||||
repository.setAggregator(datasource.get("aggregator").toString());
|
||||
|
||||
String collectedFrom = datasource.get("collectedfrom").toString();
|
||||
//TODO check data consistency
|
||||
String type = "UNKNOWN";
|
||||
if (collectedFrom.equalsIgnoreCase("openaire____::opendoar")) {
|
||||
type = "opendoar";
|
||||
} else if (collectedFrom.equalsIgnoreCase("openaire____::re3data")) {
|
||||
type = "re3data";
|
||||
} else if (collectedFrom.equalsIgnoreCase("infrastruct_::openaire")) {
|
||||
type = "journal";
|
||||
}
|
||||
/* collected from field */
|
||||
repository.setDatasourceType(type);
|
||||
repository.setCollectedFrom(collectedFrom);
|
||||
repository.setAggregator(datasource.get("aggregator").toString());
|
||||
repository.setCollectedFrom(datasource.get("collectedfrom").toString());
|
||||
|
||||
//TODO change organization to list
|
||||
JSONArray organizations = ((JSONArray)datasource.get("organizations"));
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
</bean>
|
||||
|
||||
<util:map id="userRoles">
|
||||
<entry key="urn:geant:openaire.eu:group:Super+Administrator" value="ROLE_ADMIN"/>
|
||||
<entry key="urn:geant:openaire.eu:group:Super+Administrator#aai.openaire.eu" value="ROLE_ADMIN"/>
|
||||
</util:map>
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue