Using RepositorySnippet for getDatasourcesOfUser

This commit is contained in:
Ioannis Diplas 2019-12-16 12:43:08 +00:00
parent b78350ec83
commit 763285fdac
2 changed files with 35 additions and 14 deletions

View File

@ -13,6 +13,8 @@ public class RepositorySnippet {
private String registeredby; private String registeredby;
private Organization[] organizations; private Organization[] organizations;
private String registrationdate; private String registrationdate;
private String logoUrl;
private String description;
private PiwikInfo piwikInfo; private PiwikInfo piwikInfo;
@ -90,4 +92,20 @@ public class RepositorySnippet {
public void setPiwikInfo(PiwikInfo piwikInfo) { public void setPiwikInfo(PiwikInfo piwikInfo) {
this.piwikInfo = piwikInfo; this.piwikInfo = piwikInfo;
} }
public String getLogoUrl() {
return logoUrl;
}
public void setLogoUrl(String logoUrl) {
this.logoUrl = logoUrl;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
} }

View File

@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.domain.data.Repository; import eu.dnetlib.domain.data.Repository;
import eu.dnetlib.repo.manager.domain.BrokerException; import eu.dnetlib.repo.manager.domain.BrokerException;
import eu.dnetlib.repo.manager.domain.RepositorySnippet;
import eu.dnetlib.repo.manager.domain.Term; import eu.dnetlib.repo.manager.domain.Term;
import eu.dnetlib.repo.manager.domain.Tuple; import eu.dnetlib.repo.manager.domain.Tuple;
import eu.dnetlib.repo.manager.domain.broker.*; import eu.dnetlib.repo.manager.domain.broker.*;
@ -81,17 +82,17 @@ public class BrokerServiceImpl implements BrokerService {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
DatasourcesBroker ret = new DatasourcesBroker(); DatasourcesBroker ret = new DatasourcesBroker();
try { try {
ret.setDatasourcesOfUser(getDatasourcesOfUserType(getRepositoriesOfUser(user))); ret.setDatasourcesOfUser(getDatasourcesOfUserType(repoAPI.getRepositoriesSnippetOfUser(user,"0","100")));
//TODO fix bug when values are true //TODO fix bug when values are true
if (Boolean.parseBoolean(includeShared)) { // if (Boolean.parseBoolean(includeShared)) {
List<String> sharedDatasourceIds = new ArrayList<String>(); // List<String> sharedDatasourceIds = new ArrayList<String>();
ret.setSharedDatasources(getDatasourcesOfUserType(getRepositoriesByIds(sharedDatasourceIds))); // ret.setSharedDatasources(getDatasourcesOfUserType(getRepositoriesByIds(sharedDatasourceIds)));
} // }
if (Boolean.parseBoolean(includeByOthers)) { // if (Boolean.parseBoolean(includeByOthers)) {
ret.setDatasourcesOfOthers(getDatasourcesOfUserType(getRepositoriesOfUser(user))); // ret.setDatasourcesOfOthers(getDatasourcesOfUserType(getRepositoriesOfUser(user)));
} // }
} catch (BrokerException e) { } catch (BrokerException | IOException e) {
LOGGER.debug("Exception on getDatasourcesOfUser" , e); LOGGER.debug("Exception on getDatasourcesOfUser" , e);
emailUtils.reportException(e); emailUtils.reportException(e);
} }
@ -160,14 +161,14 @@ public class BrokerServiceImpl implements BrokerService {
} }
private List<Tuple<BrowseEntry, String>> getDatasourcesOfUserType(List<Repository> repositories) throws BrokerException { private List<Tuple<BrowseEntry, String>> getDatasourcesOfUserType(List<RepositorySnippet> repositories) throws BrokerException {
long start = System.currentTimeMillis();
List<Tuple<BrowseEntry, String>> entries = new ArrayList<>(); List<Tuple<BrowseEntry, String>> entries = new ArrayList<>();
for (Repository repo : repositories) { for (RepositorySnippet repo : repositories) {
BrowseEntry temp = new BrowseEntry(); BrowseEntry temp = new BrowseEntry();
temp.setValue(repo.getOfficialName()); temp.setValue(repo.getOfficialname());
temp.setSize(new Long(0)); temp.setSize(new Long(0));
for (BrowseEntry e : getTopicsForDatasource(repo.getOfficialName())) { for (BrowseEntry e : getTopicsForDatasource(repo.getOfficialname())) {
temp.setSize(temp.getSize() + e.getSize()); temp.setSize(temp.getSize() + e.getSize());
} }
Tuple<BrowseEntry, String> tup = new Tuple<>(temp, repo.getLogoUrl()); Tuple<BrowseEntry, String> tup = new Tuple<>(temp, repo.getLogoUrl());
@ -181,6 +182,8 @@ public class BrokerServiceImpl implements BrokerService {
return (int) (e2.getFirst().getSize().longValue() - e1.getFirst().getSize().longValue()); return (int) (e2.getFirst().getSize().longValue() - e1.getFirst().getSize().longValue());
} }
}); });
long stop = System.currentTimeMillis();
System.out.println("getDatasourcesOfUserType returned in " + (stop-start) + "ms ");
return entries; return entries;
} }