minor refactoring
This commit is contained in:
parent
b8c1e18d27
commit
d2c45c2db7
|
@ -5,7 +5,7 @@ import eu.dnetlib.domain.data.RepositoryInterface;
|
||||||
import eu.dnetlib.repo.manager.domain.*;
|
import eu.dnetlib.repo.manager.domain.*;
|
||||||
import eu.dnetlib.repo.manager.domain.dto.User;
|
import eu.dnetlib.repo.manager.domain.dto.User;
|
||||||
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
|
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
|
||||||
import eu.dnetlib.repo.manager.service.RepositoryServiceImpl;
|
import eu.dnetlib.repo.manager.service.RepositoryService;
|
||||||
import eu.dnetlib.repo.manager.service.security.AuthorizationService;
|
import eu.dnetlib.repo.manager.service.security.AuthorizationService;
|
||||||
import eu.dnetlib.repo.manager.utils.JsonUtils;
|
import eu.dnetlib.repo.manager.utils.JsonUtils;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
|
@ -28,24 +28,24 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(value = "/repository")
|
@RequestMapping(value = "/repositories")
|
||||||
@Api(description = "Repository API", tags = {"repository"})
|
@Api(description = "Repository API", tags = {"repositories"})
|
||||||
public class RepositoryController {
|
public class RepositoryController {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(RepositoryController.class);
|
private static final Logger logger = Logger.getLogger(RepositoryController.class);
|
||||||
|
|
||||||
private final RepositoryServiceImpl repositoryService; //TODO: why not RepositoryService??
|
private final RepositoryService repositoryService;
|
||||||
private final AuthorizationService authorizationService;
|
private final AuthorizationService authorizationService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
RepositoryController(RepositoryServiceImpl repositoryService,
|
RepositoryController(RepositoryService repositoryService,
|
||||||
AuthorizationService authorizationService) {
|
AuthorizationService authorizationService) {
|
||||||
this.repositoryService = repositoryService;
|
this.repositoryService = repositoryService;
|
||||||
this.authorizationService = authorizationService;
|
this.authorizationService = authorizationService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping(value = "/getCountries", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
@RequestMapping(value = "/countries", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Country[] getCountries() {
|
public Country[] getCountries() {
|
||||||
return repositoryService.getCountries();
|
return repositoryService.getCountries();
|
||||||
|
@ -60,24 +60,12 @@ public class RepositoryController {
|
||||||
return repositoryService.getRepositoriesByCountry(country, mode, managed);
|
return repositoryService.getRepositoriesByCountry(country, mode, managed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/getRepositoriesOfUser/{page}/{size}", method = RequestMethod.GET,
|
@RequestMapping(value = "/snippets/user", method = RequestMethod.GET,
|
||||||
produces = MediaType.APPLICATION_JSON_VALUE)
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@PreAuthorize("hasAuthority('REGISTERED_USER')")
|
@PreAuthorize("hasAuthority('REGISTERED_USER')")
|
||||||
public List<RepositorySnippet> getRepositoriesSnippetOfUser(
|
public List<RepositorySnippet> getRepositoriesSnippetsOfUser() throws Exception {
|
||||||
@PathVariable("page") String page,
|
return repositoryService.getRepositoriesSnippetOfUser("0", "100");
|
||||||
@PathVariable("size") String size) throws Exception {
|
|
||||||
return repositoryService.getRepositoriesSnippetOfUser(page, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequestMapping(value = "/user/repositories/{page}/{size}", method = RequestMethod.GET,
|
|
||||||
produces = MediaType.APPLICATION_JSON_VALUE)
|
|
||||||
@ResponseBody
|
|
||||||
@PreAuthorize("hasAuthority('REGISTERED_USER')")
|
|
||||||
public List<Repository> getRepositoriesOfUser(
|
|
||||||
@PathVariable("page") String page,
|
|
||||||
@PathVariable("size") String size) throws JSONException, IOException {
|
|
||||||
return repositoryService.getRepositoriesOfUser(page, size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/searchRegisteredRepositories/{page}/{size}", method = RequestMethod.GET,
|
@RequestMapping(value = "/searchRegisteredRepositories/{page}/{size}", method = RequestMethod.GET,
|
||||||
|
|
|
@ -8,13 +8,13 @@ import java.util.Date;
|
||||||
public class RepositorySnippet {
|
public class RepositorySnippet {
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
private String officialname;
|
private String officialName;
|
||||||
private String englishname;
|
private String englishName;
|
||||||
private String websiteurl;
|
private String websiteUrl;
|
||||||
private String typology;
|
private String typology;
|
||||||
private String registeredby;
|
private String registeredBy;
|
||||||
private Organization[] organizations;
|
private Organization[] organizations;
|
||||||
private String registrationdate;
|
private String registrationDate;
|
||||||
private String logoUrl;
|
private String logoUrl;
|
||||||
private String description;
|
private String description;
|
||||||
private String fullTextDownload;
|
private String fullTextDownload;
|
||||||
|
@ -24,7 +24,8 @@ public class RepositorySnippet {
|
||||||
|
|
||||||
private PiwikInfo piwikInfo;
|
private PiwikInfo piwikInfo;
|
||||||
|
|
||||||
public RepositorySnippet() {}
|
public RepositorySnippet() {
|
||||||
|
}
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return id;
|
return id;
|
||||||
|
@ -34,36 +35,36 @@ public class RepositorySnippet {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getOfficialname() {
|
public String getOfficialName() {
|
||||||
return officialname;
|
return officialName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOfficialname(String officialname) {
|
public void setOfficialName(String officialName) {
|
||||||
this.officialname = officialname;
|
this.officialName = officialName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEnglishname() {
|
public String getEnglishName() {
|
||||||
return englishname;
|
return englishName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEnglishname(String englishname) {
|
public void setEnglishName(String englishName) {
|
||||||
this.englishname = englishname;
|
this.englishName = englishName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getWebsiteurl() {
|
public String getWebsiteUrl() {
|
||||||
return websiteurl;
|
return websiteUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWebsiteurl(String websiteurl) {
|
public void setWebsiteUrl(String websiteUrl) {
|
||||||
this.websiteurl = websiteurl;
|
this.websiteUrl = websiteUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRegisteredby() {
|
public String getRegisteredBy() {
|
||||||
return registeredby;
|
return registeredBy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRegisteredby(String registeredby) {
|
public void setRegisteredBy(String registeredBy) {
|
||||||
this.registeredby = registeredby;
|
this.registeredBy = registeredBy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTypology() {
|
public String getTypology() {
|
||||||
|
@ -82,12 +83,12 @@ public class RepositorySnippet {
|
||||||
this.organizations = organizations;
|
this.organizations = organizations;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRegistrationdate() {
|
public String getRegistrationDate() {
|
||||||
return registrationdate;
|
return registrationDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRegistrationdate(String registrationdate) {
|
public void setRegistrationDate(String registrationDate) {
|
||||||
this.registrationdate = registrationdate;
|
this.registrationDate = registrationDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PiwikInfo getPiwikInfo() {
|
public PiwikInfo getPiwikInfo() {
|
||||||
|
|
|
@ -2,7 +2,6 @@ package eu.dnetlib.repo.manager.service;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
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.repo.manager.domain.BrokerException;
|
import eu.dnetlib.repo.manager.domain.BrokerException;
|
||||||
import eu.dnetlib.repo.manager.domain.RepositorySnippet;
|
import eu.dnetlib.repo.manager.domain.RepositorySnippet;
|
||||||
import eu.dnetlib.repo.manager.domain.Term;
|
import eu.dnetlib.repo.manager.domain.Term;
|
||||||
|
@ -166,9 +165,9 @@ public class BrokerServiceImpl implements BrokerService {
|
||||||
List<Tuple<BrowseEntry, String>> entries = new ArrayList<>();
|
List<Tuple<BrowseEntry, String>> entries = new ArrayList<>();
|
||||||
for (RepositorySnippet 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());
|
||||||
|
@ -188,26 +187,6 @@ public class BrokerServiceImpl implements BrokerService {
|
||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Repository> getRepositoriesOfUser(String userEmail) throws JSONException {
|
|
||||||
|
|
||||||
int page = 0;
|
|
||||||
int size = 50;
|
|
||||||
List<Repository> rs ;
|
|
||||||
List<Repository> resultSet = new ArrayList<>();
|
|
||||||
|
|
||||||
while (true){
|
|
||||||
rs = repoAPI.getRepositoriesOfUser(userEmail, String.valueOf(page), String.valueOf(size));
|
|
||||||
resultSet.addAll(rs);
|
|
||||||
page+=1;
|
|
||||||
if(rs.size() == 0) break;
|
|
||||||
}
|
|
||||||
return resultSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Repository> getRepositoriesByIds(List<String> sharedDatasourceIds) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EventsPage showEvents(String datasourceName,
|
public EventsPage showEvents(String datasourceName,
|
||||||
String topic,
|
String topic,
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package eu.dnetlib.repo.manager.service;
|
package eu.dnetlib.repo.manager.service;
|
||||||
|
|
||||||
import eu.dnetlib.domain.data.Repository;
|
|
||||||
import eu.dnetlib.repo.manager.domain.*;
|
import eu.dnetlib.repo.manager.domain.*;
|
||||||
import eu.dnetlib.repo.manager.domain.broker.BrowseEntry;
|
import eu.dnetlib.repo.manager.domain.broker.BrowseEntry;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
@ -33,8 +32,8 @@ public class DashboardServiceImpl implements DashboardService {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
List<Repository> repositoriesOfUser = repositoryService.getRepositoriesOfUser(userEmail, page, size);
|
List<RepositorySnippet> repositoriesOfUser = repositoryService.getRepositoriesSnippetOfUser(userEmail, page, size);
|
||||||
for(Repository repository: repositoriesOfUser) {
|
for (RepositorySnippet repository : repositoriesOfUser) {
|
||||||
RepositorySummaryInfo repositorySummaryInfo = new RepositorySummaryInfo();
|
RepositorySummaryInfo repositorySummaryInfo = new RepositorySummaryInfo();
|
||||||
repositorySummaryInfo.setId(repository.getId());
|
repositorySummaryInfo.setId(repository.getId());
|
||||||
repositorySummaryInfo.setRepositoryName(repository.getOfficialName());
|
repositorySummaryInfo.setRepositoryName(repository.getOfficialName());
|
||||||
|
|
|
@ -14,6 +14,7 @@ import java.util.Map;
|
||||||
public interface RepositoryService {
|
public interface RepositoryService {
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: move this elsewhere
|
||||||
Country[] getCountries();
|
Country[] getCountries();
|
||||||
|
|
||||||
List<Repository> getRepositories(List<String> ids) throws JSONException;
|
List<Repository> getRepositories(List<String> ids) throws JSONException;
|
||||||
|
@ -26,8 +27,10 @@ public interface RepositoryService {
|
||||||
|
|
||||||
List<RepositorySnippet> getRepositoriesByCountry(String country, String mode, Boolean managed) throws JSONException, IOException;
|
List<RepositorySnippet> getRepositoriesByCountry(String country, String mode, Boolean managed) throws JSONException, IOException;
|
||||||
|
|
||||||
|
// TODO: remove?
|
||||||
List<Repository> getRepositoriesOfUser(String page, String size) throws JSONException, IOException;
|
List<Repository> getRepositoriesOfUser(String page, String size) throws JSONException, IOException;
|
||||||
|
|
||||||
|
// TODO: remove?
|
||||||
List<Repository> getRepositoriesOfUser(String userEmail,
|
List<Repository> getRepositoriesOfUser(String userEmail,
|
||||||
String page,
|
String page,
|
||||||
String size) throws JSONException, IOException;
|
String size) throws JSONException, IOException;
|
||||||
|
@ -37,6 +40,7 @@ public interface RepositoryService {
|
||||||
List<RepositorySnippet> getRepositoriesSnippetOfUser(String userEmail, String page, String size) throws Exception;
|
List<RepositorySnippet> getRepositoriesSnippetOfUser(String userEmail, String page, String size) throws Exception;
|
||||||
|
|
||||||
RepositorySnippet getRepositorySnippetById(String id) throws JSONException, ResourceNotFoundException;
|
RepositorySnippet getRepositorySnippetById(String id) throws JSONException, ResourceNotFoundException;
|
||||||
|
|
||||||
Repository getRepositoryById(String id) throws JSONException, ResourceNotFoundException;
|
Repository getRepositoryById(String id) throws JSONException, ResourceNotFoundException;
|
||||||
|
|
||||||
List<AggregationDetails> getRepositoryAggregations(String id, int from, int size) throws JSONException;
|
List<AggregationDetails> getRepositoryAggregations(String id, int from, int size) throws JSONException;
|
||||||
|
@ -72,7 +76,7 @@ public interface RepositoryService {
|
||||||
|
|
||||||
List<String> getUrlsOfUserRepos(String user_email,
|
List<String> getUrlsOfUserRepos(String user_email,
|
||||||
String page,
|
String page,
|
||||||
String size) throws JSONException;
|
String size);
|
||||||
|
|
||||||
List<String> getDatasourceVocabularies(String mode);
|
List<String> getDatasourceVocabularies(String mode);
|
||||||
|
|
||||||
|
@ -84,7 +88,7 @@ public interface RepositoryService {
|
||||||
|
|
||||||
MetricsInfo getMetricsInfoForRepository(String repoId) throws RepositoryServiceException;
|
MetricsInfo getMetricsInfoForRepository(String repoId) throws RepositoryServiceException;
|
||||||
|
|
||||||
Map<String, String> getListLatestUpdate(String mode) throws RepositoryServiceException, JSONException;
|
Map<String, String> getListLatestUpdate(String mode) throws JSONException;
|
||||||
|
|
||||||
RepositoryInterface updateRepositoryInterface(String repoId, String registeredBy, String comment, RepositoryInterface repositoryInterface) throws Exception;
|
RepositoryInterface updateRepositoryInterface(String repoId, String registeredBy, String comment, RepositoryInterface repositoryInterface) throws Exception;
|
||||||
|
|
||||||
|
|
|
@ -156,19 +156,19 @@ public class Converter {
|
||||||
|
|
||||||
|
|
||||||
repositorySnippet.setId(repositorySnippetObject.get("id").toString());
|
repositorySnippet.setId(repositorySnippetObject.get("id").toString());
|
||||||
repositorySnippet.setOfficialname(repositorySnippetObject.get("officialname").toString());
|
repositorySnippet.setOfficialName(repositorySnippetObject.get("officialname").toString());
|
||||||
|
|
||||||
repositorySnippet.setEnglishname(repositorySnippetObject.get("englishname").toString());
|
repositorySnippet.setEnglishName(repositorySnippetObject.get("englishname").toString());
|
||||||
if (repositorySnippet.getEnglishname().equals("null"))
|
if (repositorySnippet.getEnglishName().equals("null"))
|
||||||
repositorySnippet.setEnglishname("");
|
repositorySnippet.setEnglishName("");
|
||||||
|
|
||||||
repositorySnippet.setWebsiteurl(repositorySnippetObject.get("websiteurl").toString());
|
repositorySnippet.setWebsiteUrl(repositorySnippetObject.get("websiteurl").toString());
|
||||||
if (repositorySnippet.getWebsiteurl().equals("null"))
|
if (repositorySnippet.getWebsiteUrl().equals("null"))
|
||||||
repositorySnippet.setWebsiteurl("");
|
repositorySnippet.setWebsiteUrl("");
|
||||||
|
|
||||||
repositorySnippet.setRegisteredby(repositorySnippetObject.get("registeredby").toString());
|
repositorySnippet.setRegisteredBy(repositorySnippetObject.get("registeredby").toString());
|
||||||
if (repositorySnippet.getRegisteredby().equals("null"))
|
if (repositorySnippet.getRegisteredBy().equals("null"))
|
||||||
repositorySnippet.setRegisteredby("");
|
repositorySnippet.setRegisteredBy("");
|
||||||
return repositorySnippet;
|
return repositorySnippet;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue