Using new function for getRepositoriesOfUser, now retuning repository snippet

This commit is contained in:
Ioannis Diplas 2019-12-13 13:40:55 +00:00
parent 192ba92c1e
commit ebd68aa2c3
4 changed files with 48 additions and 14 deletions

View File

@ -46,10 +46,10 @@ public class RepositoryController {
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("hasRole('ROLE_USER')")
public List<Repository> getRepositoriesOfUser(@PathVariable("userEmail") String userEmail,
public List<RepositorySnippet> getRepositoriesOfUser(@PathVariable("userEmail") String userEmail,
@PathVariable("page") String page,
@PathVariable("size") String size) throws JSONException {
return repositoryService.getRepositoriesOfUser(userEmail, page, size);
@PathVariable("size") String size) throws JSONException, IOException {
return repositoryService.getRepositoriesSnippetOfUser(userEmail, page, size);
}
@RequestMapping(value = "/searchRegisteredRepositories/{page}/{size}",method = RequestMethod.GET,

View File

@ -1,6 +1,7 @@
package eu.dnetlib.repo.manager.domain;
import eu.dnetlib.domain.data.PiwikInfo;
public class RepositorySnippet {
@ -13,6 +14,9 @@ public class RepositorySnippet {
private Organization[] organizations;
private String registrationdate;
private PiwikInfo piwikInfo;
public RepositorySnippet() {}
public String getId() {
@ -78,4 +82,12 @@ public class RepositorySnippet {
public void setRegistrationdate(String registrationdate) {
this.registrationdate = registrationdate;
}
public PiwikInfo getPiwikInfo() {
return piwikInfo;
}
public void setPiwikInfo(PiwikInfo piwikInfo) {
this.piwikInfo = piwikInfo;
}
}

View File

@ -20,7 +20,9 @@ public interface RepositoryService {
List<Repository> getRepositoriesOfUser(String userEmail,
String page,
String size) throws JSONException;
String size) throws JSONException, IOException;
List<RepositorySnippet> getRepositoriesSnippetOfUser(String userEmail, String page, String size) throws IOException, JSONException;
Repository getRepositoryById(String id) throws JSONException, ResourceNotFoundException;

View File

@ -240,21 +240,11 @@ public class RepositoryServiceImpl implements RepositoryService {
requestFilter.setRegisteredby(userEmail);
try{
long start = System.currentTimeMillis();
String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class);
long end = System.currentTimeMillis();
System.out.println("POST request finished in " + (end-start)+"ms");
start=System.currentTimeMillis();
List<Repository> repos = Converter.jsonToRepositoryList(new JSONObject(rs));
end=System.currentTimeMillis();
System.out.println("Converting json to repo list finished in " + (end-start)+"ms");
start=System.currentTimeMillis();
for (Repository r : repos)
r.setPiwikInfo(piWikService.getPiwikSiteForRepo(r.getId()));
end=System.currentTimeMillis();
System.out.println("Updating "+repos.size()+" repository infos in " + (end-start)+"ms");
return repos;
}catch (Exception e){
LOGGER.debug("Exception on getRepositoriesOfUser" , e);
@ -263,6 +253,36 @@ public class RepositoryServiceImpl implements RepositoryService {
}
}
@Override
public List<RepositorySnippet> getRepositoriesSnippetOfUser(String userEmail, String page, String size) throws IOException, JSONException {
List<RepositorySnippet> resultSet = new ArrayList<>();
ObjectMapper mapper = new ObjectMapper();
UriComponents uriComponents = searchSnipperDatasource(page,size);
RequestFilter requestFilter = new RequestFilter();
requestFilter.setRegisteredby(userEmail);
try{
String rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class);
JSONArray jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
while (jsonArray.length() > 0 ) {
resultSet.addAll(mapper.readValue(String.valueOf(jsonArray),
mapper.getTypeFactory().constructCollectionType(List.class, RepositorySnippet.class)));
page += 1;
uriComponents = searchSnipperDatasource(page,size);
rs = restTemplate.postForObject(uriComponents.toUri(),requestFilter, String.class);
jsonArray = (JSONArray) new JSONObject(rs).get("datasourceInfo");
}
resultSet.parallelStream().forEach(repositorySnippet -> {
repositorySnippet.setPiwikInfo(piWikService.getPiwikSiteForRepo(repositorySnippet.getId()));
});
return resultSet;
}catch (Exception e){
LOGGER.debug("Exception on getRepositoriesByCountry" , e);
throw e;
}
}
@Override
public Repository getRepositoryById(String id) throws JSONException,ResourceNotFoundException {