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;
|
||||||
|
@ -44,11 +43,11 @@ public class BrokerServiceImpl implements BrokerService {
|
||||||
.getLogger(BrokerServiceImpl.class);
|
.getLogger(BrokerServiceImpl.class);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
RestTemplate restTemplate ;
|
RestTemplate restTemplate;
|
||||||
|
|
||||||
private HttpHeaders httpHeaders;
|
private HttpHeaders httpHeaders;
|
||||||
|
|
||||||
private HashMap<String,Term> topics = new HashMap<String, Term>();
|
private HashMap<String, Term> topics = new HashMap<String, Term>();
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private EmailUtils emailUtils;
|
private EmailUtils emailUtils;
|
||||||
|
@ -60,29 +59,29 @@ public class BrokerServiceImpl implements BrokerService {
|
||||||
httpHeaders.set("Content-Type", "application/json");
|
httpHeaders.set("Content-Type", "application/json");
|
||||||
|
|
||||||
LOGGER.debug("Init dnet topics!");
|
LOGGER.debug("Init dnet topics!");
|
||||||
try (InputStream is = new URL(topicsURL).openStream() ){
|
try (InputStream is = new URL(topicsURL).openStream()) {
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
JsonNode root = mapper.readTree(is);
|
JsonNode root = mapper.readTree(is);
|
||||||
for (JsonNode term : root.path("terms") )
|
for (JsonNode term : root.path("terms"))
|
||||||
topics.put(term.path("code").textValue(), parseTerm(term));
|
topics.put(term.path("code").textValue(), parseTerm(term));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOGGER.debug("Exception on initDnetTopicsMap" , e);
|
LOGGER.debug("Exception on initDnetTopicsMap", e);
|
||||||
emailUtils.reportException(e);
|
emailUtils.reportException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Term parseTerm(JsonNode term) {
|
private Term parseTerm(JsonNode term) {
|
||||||
return new Term(term.path("englishName").textValue(),term.path("nativeName").textValue(),
|
return new Term(term.path("englishName").textValue(), term.path("nativeName").textValue(),
|
||||||
term.path("encoding").textValue(),term.path("code").textValue());
|
term.path("encoding").textValue(), term.path("code").textValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DatasourcesBroker getDatasourcesOfUser(String user,String includeShared,String includeByOthers) throws JSONException {
|
public DatasourcesBroker getDatasourcesOfUser(String user, String includeShared, String includeByOthers) throws JSONException {
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
DatasourcesBroker ret = new DatasourcesBroker();
|
DatasourcesBroker ret = new DatasourcesBroker();
|
||||||
try {
|
try {
|
||||||
ret.setDatasourcesOfUser(getDatasourcesOfUserType(repoAPI.getRepositoriesSnippetOfUser(user,"0","100")));
|
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>();
|
||||||
|
@ -93,11 +92,11 @@ public class BrokerServiceImpl implements BrokerService {
|
||||||
// ret.setDatasourcesOfOthers(getDatasourcesOfUserType(getRepositoriesOfUser(user)));
|
// ret.setDatasourcesOfOthers(getDatasourcesOfUserType(getRepositoriesOfUser(user)));
|
||||||
// }
|
// }
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.debug("Exception on getDatasourcesOfUser" , e);
|
LOGGER.debug("Exception on getDatasourcesOfUser", e);
|
||||||
emailUtils.reportException(e);
|
emailUtils.reportException(e);
|
||||||
}
|
}
|
||||||
long end = System.currentTimeMillis();
|
long end = System.currentTimeMillis();
|
||||||
System.out.println("Getting datasources of user in " + (end-start)+"ms");
|
System.out.println("Getting datasources of user in " + (end - start) + "ms");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +116,7 @@ public class BrokerServiceImpl implements BrokerService {
|
||||||
new ParameterizedTypeReference<List<BrowseEntry>>() {
|
new ParameterizedTypeReference<List<BrowseEntry>>() {
|
||||||
});
|
});
|
||||||
} catch (RestClientException e) {
|
} catch (RestClientException e) {
|
||||||
LOGGER.debug("Exception on getTopicsForDatasource" , e);
|
LOGGER.debug("Exception on getTopicsForDatasource", e);
|
||||||
emailUtils.reportException(e);
|
emailUtils.reportException(e);
|
||||||
throw new BrokerException(e);
|
throw new BrokerException(e);
|
||||||
}
|
}
|
||||||
|
@ -128,7 +127,7 @@ public class BrokerServiceImpl implements BrokerService {
|
||||||
@Override
|
@Override
|
||||||
public EventsPage advancedShowEvents(String page,
|
public EventsPage advancedShowEvents(String page,
|
||||||
String size,
|
String size,
|
||||||
AdvQueryObject advQueryObject) throws BrokerException, JSONException ,IOException {
|
AdvQueryObject advQueryObject) throws BrokerException, JSONException, IOException {
|
||||||
|
|
||||||
final String service = "/events/{page}/{pageSize}";
|
final String service = "/events/{page}/{pageSize}";
|
||||||
|
|
||||||
|
@ -151,7 +150,7 @@ public class BrokerServiceImpl implements BrokerService {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
} catch (RestClientException e) {
|
} catch (RestClientException e) {
|
||||||
LOGGER.debug("Exception on advancedShowEvents" , e);
|
LOGGER.debug("Exception on advancedShowEvents", e);
|
||||||
emailUtils.reportException(e);
|
emailUtils.reportException(e);
|
||||||
throw new BrokerException(e);
|
throw new BrokerException(e);
|
||||||
}
|
}
|
||||||
|
@ -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());
|
||||||
|
@ -183,31 +182,11 @@ public class BrokerServiceImpl implements BrokerService {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
long stop = System.currentTimeMillis();
|
long stop = System.currentTimeMillis();
|
||||||
System.out.println("getDatasourcesOfUserType returned in " + (stop-start) + "ms ");
|
System.out.println("getDatasourcesOfUserType returned in " + (stop - start) + "ms ");
|
||||||
|
|
||||||
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,
|
||||||
|
@ -230,7 +209,7 @@ public class BrokerServiceImpl implements BrokerService {
|
||||||
new ParameterizedTypeReference<EventsPage>() {
|
new ParameterizedTypeReference<EventsPage>() {
|
||||||
});
|
});
|
||||||
} catch (RestClientException e) {
|
} catch (RestClientException e) {
|
||||||
LOGGER.debug("Exception on showEvents" , e);
|
LOGGER.debug("Exception on showEvents", e);
|
||||||
emailUtils.reportException(e);
|
emailUtils.reportException(e);
|
||||||
throw new BrokerException(e);
|
throw new BrokerException(e);
|
||||||
}
|
}
|
||||||
|
@ -256,7 +235,7 @@ public class BrokerServiceImpl implements BrokerService {
|
||||||
new ParameterizedTypeReference<Map<String, List<SimpleSubscriptionDesc>>>() {
|
new ParameterizedTypeReference<Map<String, List<SimpleSubscriptionDesc>>>() {
|
||||||
});
|
});
|
||||||
} catch (RestClientException e) {
|
} catch (RestClientException e) {
|
||||||
LOGGER.debug("Exception on getSimpleSubscriptionsOfUser" , e);
|
LOGGER.debug("Exception on getSimpleSubscriptionsOfUser", e);
|
||||||
emailUtils.reportException(e);
|
emailUtils.reportException(e);
|
||||||
throw new BrokerException(e);
|
throw new BrokerException(e);
|
||||||
}
|
}
|
||||||
|
@ -292,7 +271,7 @@ public class BrokerServiceImpl implements BrokerService {
|
||||||
new ParameterizedTypeReference<Subscription>() {
|
new ParameterizedTypeReference<Subscription>() {
|
||||||
});
|
});
|
||||||
} catch (RestClientException e) {
|
} catch (RestClientException e) {
|
||||||
LOGGER.debug("Exception on OpenaireSubscription" , e);
|
LOGGER.debug("Exception on OpenaireSubscription", e);
|
||||||
emailUtils.reportException(e);
|
emailUtils.reportException(e);
|
||||||
throw new BrokerException(e);
|
throw new BrokerException(e);
|
||||||
}
|
}
|
||||||
|
@ -316,15 +295,15 @@ public class BrokerServiceImpl implements BrokerService {
|
||||||
new ParameterizedTypeReference<Void>() {
|
new ParameterizedTypeReference<Void>() {
|
||||||
});
|
});
|
||||||
} catch (RestClientException e) {
|
} catch (RestClientException e) {
|
||||||
LOGGER.debug("Exception on unsubscribe" , e);
|
LOGGER.debug("Exception on unsubscribe", e);
|
||||||
emailUtils.reportException(e);
|
emailUtils.reportException(e);
|
||||||
throw new BrokerException(e);
|
throw new BrokerException(e);
|
||||||
}
|
}
|
||||||
return new ResponseEntity<>("OK",HttpStatus.OK);
|
return new ResponseEntity<>("OK", HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Subscription getSubscription( String subscriptionId) throws BrokerException {
|
public Subscription getSubscription(String subscriptionId) throws BrokerException {
|
||||||
final String service = "/subscriptions/" + subscriptionId;
|
final String service = "/subscriptions/" + subscriptionId;
|
||||||
|
|
||||||
//build the uri params
|
//build the uri params
|
||||||
|
@ -340,7 +319,7 @@ public class BrokerServiceImpl implements BrokerService {
|
||||||
new ParameterizedTypeReference<Subscription>() {
|
new ParameterizedTypeReference<Subscription>() {
|
||||||
});
|
});
|
||||||
} catch (RestClientException e) {
|
} catch (RestClientException e) {
|
||||||
LOGGER.debug("Exception on getSubscription" , e);
|
LOGGER.debug("Exception on getSubscription", e);
|
||||||
emailUtils.reportException(e);
|
emailUtils.reportException(e);
|
||||||
throw new BrokerException(e);
|
throw new BrokerException(e);
|
||||||
}
|
}
|
||||||
|
@ -360,7 +339,7 @@ public class BrokerServiceImpl implements BrokerService {
|
||||||
UriComponents uriComponents = UriComponentsBuilder
|
UriComponents uriComponents = UriComponentsBuilder
|
||||||
.fromHttpUrl(openairePath + "/notifications/")
|
.fromHttpUrl(openairePath + "/notifications/")
|
||||||
.path("/{id}/{page}/{size}/")
|
.path("/{id}/{page}/{size}/")
|
||||||
.build().expand(subscriptionId,page, size).encode();
|
.build().expand(subscriptionId, page, size).encode();
|
||||||
|
|
||||||
ResponseEntity<EventsPage> resp;
|
ResponseEntity<EventsPage> resp;
|
||||||
try {
|
try {
|
||||||
|
@ -371,7 +350,7 @@ public class BrokerServiceImpl implements BrokerService {
|
||||||
new ParameterizedTypeReference<EventsPage>() {
|
new ParameterizedTypeReference<EventsPage>() {
|
||||||
});
|
});
|
||||||
} catch (RestClientException e) {
|
} catch (RestClientException e) {
|
||||||
LOGGER.debug("Exception on getNotificationsBySubscriptionId" , e);
|
LOGGER.debug("Exception on getNotificationsBySubscriptionId", e);
|
||||||
emailUtils.reportException(e);
|
emailUtils.reportException(e);
|
||||||
throw new BrokerException(e);
|
throw new BrokerException(e);
|
||||||
}
|
}
|
||||||
|
@ -383,16 +362,16 @@ public class BrokerServiceImpl implements BrokerService {
|
||||||
throws BrokerException {
|
throws BrokerException {
|
||||||
|
|
||||||
Map<String, List<SimpleSubscriptionDesc>> simpleSubs = getSimpleSubscriptionsOfUser(userEmail);
|
Map<String, List<SimpleSubscriptionDesc>> simpleSubs = getSimpleSubscriptionsOfUser(userEmail);
|
||||||
Map<String,List<Subscription>> subs = new HashMap<>();
|
Map<String, List<Subscription>> subs = new HashMap<>();
|
||||||
List<Subscription> subscriptions = null;
|
List<Subscription> subscriptions = null;
|
||||||
|
|
||||||
for(String s:simpleSubs.keySet()){
|
for (String s : simpleSubs.keySet()) {
|
||||||
List<SimpleSubscriptionDesc> simpleSubscriptionDescs = simpleSubs.get(s);
|
List<SimpleSubscriptionDesc> simpleSubscriptionDescs = simpleSubs.get(s);
|
||||||
for(SimpleSubscriptionDesc simpleSubscriptionDesc : simpleSubscriptionDescs) {
|
for (SimpleSubscriptionDesc simpleSubscriptionDesc : simpleSubscriptionDescs) {
|
||||||
subscriptions = new ArrayList<>();
|
subscriptions = new ArrayList<>();
|
||||||
subscriptions.add(getSubscription(simpleSubscriptionDesc.getId()));
|
subscriptions.add(getSubscription(simpleSubscriptionDesc.getId()));
|
||||||
}
|
}
|
||||||
subs.put(s,subscriptions);
|
subs.put(s, subscriptions);
|
||||||
}
|
}
|
||||||
return subs;
|
return subs;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -27,58 +26,58 @@ public class DashboardServiceImpl implements DashboardService {
|
||||||
@Override
|
@Override
|
||||||
public List<RepositorySummaryInfo> getRepositoriesSummaryInfo(String userEmail,
|
public List<RepositorySummaryInfo> getRepositoriesSummaryInfo(String userEmail,
|
||||||
String page,
|
String page,
|
||||||
String size){
|
String size) {
|
||||||
|
|
||||||
List<RepositorySummaryInfo> repositorySummaryInfoList = new ArrayList<>();
|
List<RepositorySummaryInfo> repositorySummaryInfoList = new ArrayList<>();
|
||||||
|
|
||||||
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());
|
||||||
repositorySummaryInfo.setLogoURL(repository.getLogoUrl());
|
repositorySummaryInfo.setLogoURL(repository.getLogoUrl());
|
||||||
|
|
||||||
//TODO getRepositoryAggregations returns only the 20 more recent items. Is it positive that we will find an indexed version there?
|
//TODO getRepositoryAggregations returns only the 20 more recent items. Is it positive that we will find an indexed version there?
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
List<AggregationDetails> aggregationDetailsList = repositoryService.getRepositoryAggregations(repository.getId(),0,20);
|
List<AggregationDetails> aggregationDetailsList = repositoryService.getRepositoryAggregations(repository.getId(), 0, 20);
|
||||||
for(AggregationDetails aggregationDetails: aggregationDetailsList) {
|
for (AggregationDetails aggregationDetails : aggregationDetailsList) {
|
||||||
if(aggregationDetails.getIndexedVersion()) {
|
if (aggregationDetails.getIndexedVersion()) {
|
||||||
repositorySummaryInfo.setRecordsCollected(aggregationDetails.getNumberOfRecords());
|
repositorySummaryInfo.setRecordsCollected(aggregationDetails.getNumberOfRecords());
|
||||||
repositorySummaryInfo.setLastIndexedVersion(aggregationDetails.getDate());
|
repositorySummaryInfo.setLastIndexedVersion(aggregationDetails.getDate());
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
long end = System.currentTimeMillis();
|
|
||||||
|
|
||||||
System.out.println("Got repo aggregations in "+ (end-start)+"ms");
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
MetricsInfo metricsInfo = repositoryService.getMetricsInfoForRepository(repository.getId());
|
|
||||||
repositorySummaryInfo.setTotalDownloads(metricsInfo.getMetricsNumbers().getTotalDownloads());
|
|
||||||
repositorySummaryInfo.setTotalViews(metricsInfo.getMetricsNumbers().getTotalViews());
|
|
||||||
|
|
||||||
} catch (RepositoryServiceException e) {
|
|
||||||
logger.error("Exception getting metrics info for repository: " + repository.getId(), e);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
List<BrowseEntry> events = brokerService.getTopicsForDatasource(repository.getOfficialName());
|
|
||||||
Long totalEvents = 0L;
|
|
||||||
for(BrowseEntry browseEntry: events)
|
|
||||||
totalEvents += browseEntry.getSize();
|
|
||||||
repositorySummaryInfo.setEnrichmentEvents(totalEvents);
|
|
||||||
|
|
||||||
|
|
||||||
} catch (BrokerException e) {
|
|
||||||
logger.error("Exception getting broker events for repository: " + repository.getId(), e);
|
|
||||||
}
|
|
||||||
|
|
||||||
repositorySummaryInfoList.add(repositorySummaryInfo);
|
|
||||||
}
|
}
|
||||||
|
long end = System.currentTimeMillis();
|
||||||
|
|
||||||
|
System.out.println("Got repo aggregations in " + (end - start) + "ms");
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
MetricsInfo metricsInfo = repositoryService.getMetricsInfoForRepository(repository.getId());
|
||||||
|
repositorySummaryInfo.setTotalDownloads(metricsInfo.getMetricsNumbers().getTotalDownloads());
|
||||||
|
repositorySummaryInfo.setTotalViews(metricsInfo.getMetricsNumbers().getTotalViews());
|
||||||
|
|
||||||
|
} catch (RepositoryServiceException e) {
|
||||||
|
logger.error("Exception getting metrics info for repository: " + repository.getId(), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
List<BrowseEntry> events = brokerService.getTopicsForDatasource(repository.getOfficialName());
|
||||||
|
Long totalEvents = 0L;
|
||||||
|
for (BrowseEntry browseEntry : events)
|
||||||
|
totalEvents += browseEntry.getSize();
|
||||||
|
repositorySummaryInfo.setEnrichmentEvents(totalEvents);
|
||||||
|
|
||||||
|
|
||||||
|
} catch (BrokerException e) {
|
||||||
|
logger.error("Exception getting broker events for repository: " + repository.getId(), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
repositorySummaryInfoList.add(repositorySummaryInfo);
|
||||||
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Something baad happened!", e);
|
logger.error("Something baad happened!", e);
|
||||||
|
|
|
@ -14,7 +14,8 @@ import java.util.Map;
|
||||||
public interface RepositoryService {
|
public interface RepositoryService {
|
||||||
|
|
||||||
|
|
||||||
Country[] getCountries() ;
|
// TODO: move this elsewhere
|
||||||
|
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,19 +40,20 @@ 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;
|
||||||
|
|
||||||
Map<String,List<AggregationDetails>> getRepositoryAggregationsByYear(String id) throws JSONException;
|
Map<String, List<AggregationDetails>> getRepositoryAggregationsByYear(String id) throws JSONException;
|
||||||
|
|
||||||
List<Repository> getRepositoriesByName(String name,
|
List<Repository> getRepositoriesByName(String name,
|
||||||
String page,
|
String page,
|
||||||
String size) throws JSONException;
|
String size) throws JSONException;
|
||||||
|
|
||||||
List<RepositorySnippet> searchRegisteredRepositories(String country, String typology, String englishName,
|
List<RepositorySnippet> searchRegisteredRepositories(String country, String typology, String englishName,
|
||||||
String officialName, String requestSortBy, String order,
|
String officialName, String requestSortBy, String order,
|
||||||
int page, int pageSize) throws Exception;
|
int page, int pageSize) throws Exception;
|
||||||
|
|
||||||
List<RepositoryInterface> getRepositoryInterface(String id) throws JSONException;
|
List<RepositoryInterface> getRepositoryInterface(String id) 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