added a method to search registered repositories

This commit is contained in:
Antonis Lempesis 2019-07-09 10:12:56 +00:00
parent a514949c7f
commit 9ca226a0b8
6 changed files with 148 additions and 11 deletions

35
pom.xml
View File

@ -246,6 +246,41 @@
<version>1.1.5.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.xml.ws/jaxws-api -->
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.3.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.jws/javax.jws-api -->
<dependency>
<groupId>javax.jws</groupId>
<artifactId>javax.jws-api</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-core -->
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1-rev-1</version>
</dependency>
</dependencies>
<build>

View File

@ -14,6 +14,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;
import javax.ws.rs.Path;
import java.io.IOException;
import java.util.List;
import java.util.Map;
@ -51,6 +52,22 @@ public class RepositoryController {
return repositoryService.getRepositoriesOfUser(userEmail, page, size);
}
@RequestMapping(value = "/searchRegisteredRepositories/{page}/{size}",method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_ADMIN')")
public List<RepositorySnippet> searchRegisteredRepositories(@RequestParam("country") String country,
@RequestParam("typology") String typology,
@RequestParam("englishName") String englishName,
@RequestParam("officialName") String officialName,
@RequestParam("requestSortBy") String requestSortBy,
@RequestParam("order") String order,
@PathVariable("page)") int page,
@PathVariable("size") int pageSize) throws Exception {
return repositoryService.searchRegisteredRepositories(country, typology, englishName, officialName, requestSortBy, order, page, pageSize);
}
@RequestMapping(value = "/getRepositoryById/{id}", method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody

View File

@ -10,9 +10,12 @@ public class RequestFilter{
private String country = null;
private String id = null;
private String officialname = null;
private String englishname = null;
private String collectedfrom = null;
public RequestFilter() {
}
@ -64,4 +67,12 @@ public class RequestFilter{
public void setCollectedfrom(String collectedfrom) {
this.collectedfrom = collectedfrom;
}
public String getEnglishname() {
return englishname;
}
public void setEnglishname(String englishname) {
this.englishname = englishname;
}
}

View File

@ -10,11 +10,14 @@ import eu.dnetlib.repo.manager.shared.broker.BrowseEntry;
import org.apache.log4j.Logger;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;
import javax.xml.ws.ServiceMode;
import java.util.ArrayList;
import java.util.List;
@Service("dashboardService")
public class DashboardServiceImpl implements DashboardService {
private static final Logger logger = Logger.getLogger(DashboardServiceImpl.class);

View File

@ -32,6 +32,10 @@ public interface RepositoryService {
String page,
String size) throws JSONException;
List<RepositorySnippet> searchRegisteredRepositories(String country, String typology, String englishName,
String officialName, String requestSortBy, String order,
int page, int pageSize) throws Exception;
List<RepositoryInterface> getRepositoryInterface(String id) throws JSONException;
Repository addRepository(String datatype, Repository repository) throws Exception;

View File

@ -3,15 +3,18 @@ package eu.dnetlib.repo.manager.service;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import eu.dnetlib.api.functionality.ValidatorServiceException;
import eu.dnetlib.domain.data.Repository;
import eu.dnetlib.domain.data.RepositoryInterface;
import eu.dnetlib.domain.enabling.Vocabulary;
import eu.dnetlib.domain.functionality.validator.JobForValidation;
import eu.dnetlib.repo.manager.domain.RepositorySnippet;
import eu.dnetlib.repo.manager.domain.RequestFilter;
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
import eu.dnetlib.repo.manager.shared.*;
import eu.dnetlib.repo.manager.utils.Converter;
import gr.uoa.di.driver.enabling.vocabulary.VocabularyLoader;
import gr.uoa.di.driver.xml.repository.INTERFACE;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.log4j.Logger;
import org.json.JSONArray;
@ -46,6 +49,9 @@ public class RepositoryServiceImpl implements RepositoryService {
@Value("${api.baseAddress}")
private String baseAddress;
@Value("${services.repo-manager.adminEmail}")
private String adminEmail;
@Autowired
RestTemplate restTemplate;
@ -70,6 +76,9 @@ public class RepositoryServiceImpl implements RepositoryService {
@Autowired
private EmailUtils emailUtils;
@Autowired
ValidatorService validatorService;
private Map<String, Vocabulary> vocabularyMap = new ConcurrentHashMap<String, Vocabulary>();
@ -186,8 +195,35 @@ public class RepositoryServiceImpl implements RepositoryService {
// emailUtils.reportException(e);
throw e;
}
}
public List<RepositorySnippet> searchRegisteredRepositories(String country, String typology, String englishName,
String officialName, String requestSortBy, String order, int page, int pageSize) throws Exception {
LOGGER.debug("Searching registered repositories");
List<RepositorySnippet> resultSet = new ArrayList<>();
ObjectMapper mapper = new ObjectMapper();
UriComponents uriComponents = searchRegisteredDatasource(requestSortBy, order, Integer.toString(page), Integer.toString(pageSize));
RequestFilter requestFilter = new RequestFilter();
requestFilter.setCountry(country);
requestFilter.setTypology(typology);
requestFilter.setOfficialname(officialName);
requestFilter.setEnglishname(englishName);
try {
String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class);
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
resultSet.addAll(mapper.readValue(String.valueOf(jsonArray), mapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class)));
return resultSet;
}catch (Exception e){
LOGGER.error("Error searching registered datasources" , e);
throw e;
}
}
private Repository updateRepositoryInfo(Repository r) throws JSONException {
@ -552,6 +588,38 @@ public class RepositoryServiceImpl implements RepositoryService {
}
}
@Override
public RepositoryInterface updateRepositoryInterface(@RequestParam("repoId") String repoId,
@RequestParam("registeredBy") String registeredBy,
@RequestBody RepositoryInterface repositoryInterface) throws Exception {
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 submitInterfaceValidation(Repository repo, String repoType, String userEmail, RepositoryInterface iFace) throws ValidatorServiceException {
JobForValidation job = new JobForValidation();
job.setActivationId(UUID.randomUUID().toString());
job.setAdminEmails(Collections.singletonList(this.adminEmail));
job.setBaseUrl(iFace.getBaseUrl());
job.setDatasourceId(repo.getId());
job.setDesiredCompatibilityLevel(iFace.getDesiredCompatibilityLevel());
job.setInterfaceId(iFace.getId());
// job.setInterfaceIdOld(null);
job.setOfficialName(repo.getOfficialName());
job.setRepoType(repoType);
job.setUserEmail(userEmail);
job.setValidationSet(iFace.getAccessSet());
job.setRecords(-1);
job.setRegistration(true);
job.setUpdateExisting(false);
this.validatorService.submitJobForValidation(job);
}
private RepositoryInterface createRepositoryInterface(Repository repo, RepositoryInterface iFace, String datatype) {
iFace.setContentDescription("metadata");
@ -752,17 +820,6 @@ public class RepositoryServiceImpl implements RepositoryService {
return Collections.singletonMap("lastCollectionDate", getRepositoryInterface("openaire____::"+mode).get(1).getLastCollectionDate());
}
@Override
public RepositoryInterface updateRepositoryInterface(@RequestParam("repoId") String repoId,
@RequestParam("registeredBy") String registeredBy,
@RequestBody RepositoryInterface repositoryInterface) throws Exception {
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) throws Exception {
UriComponents uriComponents = UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/api/oaiset")
@ -850,6 +907,16 @@ public class RepositoryServiceImpl implements RepositoryService {
.build().expand(page, size).encode();
}
private UriComponents searchRegisteredDatasource(String requestSortBy, String order, String page,String size){
return UriComponentsBuilder
.fromHttpUrl(baseAddress + "/ds/searchregistered/")
.path("/{page}/{size}/")
.queryParam("requestSortBy",requestSortBy)
.queryParam("order",order)
.build().expand(page, size).encode();
}
private String getRepositoryType(String typology){
return invertedDataSourceClass.get(typology);
}