3 |
3 |
import eu.dnetlib.domain.data.Repository;
|
4 |
4 |
import eu.dnetlib.gwt.server.service.SpringGwtRemoteServiceServlet;
|
5 |
5 |
import eu.dnetlib.repo.manager.client.services.BrokerService;
|
|
6 |
import eu.dnetlib.repo.manager.service.controllers.BrokerApi;
|
|
7 |
import eu.dnetlib.repo.manager.service.controllers.RepositoryApi;
|
6 |
8 |
import eu.dnetlib.repo.manager.shared.BrokerException;
|
7 |
9 |
import eu.dnetlib.repo.manager.shared.RepositoryServiceException;
|
8 |
10 |
import eu.dnetlib.repo.manager.shared.Tuple;
|
9 |
11 |
import eu.dnetlib.repo.manager.shared.broker.*;
|
10 |
12 |
import eu.dnetlib.repos.RepoApi;
|
11 |
13 |
import org.apache.log4j.Logger;
|
|
14 |
import org.json.JSONException;
|
|
15 |
import org.json.JSONObject;
|
12 |
16 |
import org.springframework.beans.factory.annotation.Autowired;
|
13 |
17 |
import org.springframework.beans.factory.annotation.Value;
|
14 |
18 |
import org.springframework.core.ParameterizedTypeReference;
|
... | ... | |
40 |
44 |
@Autowired
|
41 |
45 |
private RepoApi repoAPI;
|
42 |
46 |
|
|
47 |
|
|
48 |
@Autowired
|
|
49 |
private RepositoryApi repositoryApi;
|
|
50 |
@Autowired
|
|
51 |
private BrokerApi brokerApi;
|
|
52 |
|
|
53 |
|
43 |
54 |
@Override
|
44 |
55 |
public void init(ServletConfig config) throws ServletException {
|
45 |
56 |
super.init(config);
|
... | ... | |
59 |
70 |
*/
|
60 |
71 |
@Override
|
61 |
72 |
public List<BrowseEntry> getTopicsForDatasource(String datasourceName) throws BrokerException {
|
62 |
|
final String service = "/topicsForDatasource";
|
63 |
|
|
64 |
|
//build the uri params
|
65 |
|
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service)
|
66 |
|
.queryParam("ds", datasourceName);
|
67 |
|
|
68 |
|
//create new template engine
|
69 |
|
RestTemplate template = new RestTemplate();
|
70 |
|
template.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
|
71 |
|
ResponseEntity<List<BrowseEntry>> resp;
|
72 |
|
try {
|
73 |
|
//communicate with endpoint
|
74 |
|
resp = template.exchange(
|
75 |
|
builder.build().encode().toUri(),
|
76 |
|
HttpMethod.GET,
|
77 |
|
null,
|
78 |
|
new ParameterizedTypeReference<List<BrowseEntry>>() {
|
79 |
|
});
|
80 |
|
} catch (RestClientException e) {
|
81 |
|
throw new BrokerException(e);
|
82 |
|
}
|
83 |
|
|
84 |
|
return resp.getBody();
|
|
73 |
return brokerApi.getTopicsForDatasource(datasourceName);
|
85 |
74 |
}
|
86 |
75 |
|
87 |
76 |
/**
|
... | ... | |
92 |
81 |
* @throws BrokerException containing the error code from the server
|
93 |
82 |
*/
|
94 |
83 |
@Override
|
95 |
|
public EventsPage showEvents(String datasourceName, String topic, long page) throws BrokerException {
|
96 |
|
final String service = "/showEvents";
|
97 |
|
|
98 |
|
//build the uri params
|
99 |
|
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service)
|
100 |
|
.queryParam("ds", datasourceName)
|
101 |
|
.queryParam("topic", topic)
|
102 |
|
.queryParam("page", page);
|
103 |
|
|
104 |
|
//create new template engine
|
105 |
|
RestTemplate template = new RestTemplate();
|
106 |
|
template.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
|
107 |
|
ResponseEntity<EventsPage> resp;
|
|
84 |
public EventsPage showEvents(String datasourceName, String topic, long page) throws BrokerException{
|
|
85 |
JSONObject params = new JSONObject();
|
108 |
86 |
try {
|
109 |
|
//communicate with endpoint
|
110 |
|
resp = template.exchange(
|
111 |
|
builder.build().encode().toUri(),
|
112 |
|
HttpMethod.GET,
|
113 |
|
null,
|
114 |
|
new ParameterizedTypeReference<EventsPage>() {
|
115 |
|
});
|
116 |
|
} catch (RestClientException e) {
|
117 |
|
throw new BrokerException(e);
|
|
87 |
params.append("datasourceName",datasourceName);
|
|
88 |
params.append("topic",topic);
|
|
89 |
params.append("page",String.valueOf(page));
|
|
90 |
return brokerApi.showEvents(params.toString());
|
|
91 |
} catch (JSONException e) {
|
|
92 |
LOGGER.debug("Error on show events",e);
|
118 |
93 |
}
|
119 |
|
return resp.getBody();
|
|
94 |
return null;
|
120 |
95 |
}
|
121 |
96 |
|
122 |
97 |
/**
|
... | ... | |
128 |
103 |
*/
|
129 |
104 |
@Override
|
130 |
105 |
public EventsPage advancedShowEvents(AdvQueryObject advQueryObject, long page, long pageSize) throws BrokerException {
|
131 |
|
final String service = "/events/{page}/{pageSize}";
|
132 |
106 |
|
133 |
|
// URI (URL) parameters
|
134 |
|
Map<String, Long> uriParams = new HashMap<>();
|
135 |
|
uriParams.put("page", page);
|
136 |
|
uriParams.put("pageSize", pageSize);
|
137 |
|
|
138 |
|
//build the uri params
|
139 |
|
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service);
|
140 |
|
|
141 |
|
//Header info
|
142 |
|
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
|
143 |
|
headers.add("Content-Type", "application/json");
|
144 |
|
|
145 |
|
advQueryObject.setPage(page);
|
146 |
|
|
147 |
|
HttpEntity<AdvQueryObject> entity = new HttpEntity<>(advQueryObject, headers);
|
148 |
|
|
149 |
|
//create new template engine
|
150 |
|
RestTemplate template = new RestTemplate();
|
151 |
|
template.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
|
152 |
|
ResponseEntity<EventsPage> resp;
|
|
107 |
JSONObject jsonObject = new JSONObject();
|
153 |
108 |
try {
|
154 |
|
//communicate with endpoint
|
155 |
|
resp = template.exchange(
|
156 |
|
builder.buildAndExpand(uriParams).encode().toUri(),
|
157 |
|
HttpMethod.POST,
|
158 |
|
entity,
|
159 |
|
new ParameterizedTypeReference<EventsPage>() {
|
160 |
|
}
|
161 |
|
);
|
162 |
|
} catch (RestClientException e) {
|
163 |
|
throw new BrokerException(e);
|
|
109 |
jsonObject.append("page",String.valueOf(page));
|
|
110 |
jsonObject.append("pagesize",String.valueOf(pageSize));
|
|
111 |
jsonObject.append("advQueryObject",advQueryObject);
|
|
112 |
return brokerApi.advancedShowEvents(jsonObject.toString());
|
|
113 |
} catch (JSONException e) {
|
|
114 |
LOGGER.debug("Error on advanced show events",e);
|
164 |
115 |
}
|
165 |
|
return resp.getBody();
|
|
116 |
return null;
|
166 |
117 |
}
|
167 |
118 |
|
168 |
119 |
@Override
|
169 |
|
public DatasourcesBroker getDatasourcesOfUser(String userEmail, boolean includeShared, boolean includeByOthers) throws BrokerException {
|
|
120 |
public DatasourcesBroker getDatasourcesOfUser(String userEmail, boolean includeShared, boolean includeByOthers)
|
|
121 |
throws BrokerException {
|
|
122 |
|
|
123 |
/*JSONObject params = new JSONObject();
|
|
124 |
try {
|
|
125 |
params.append("userEmail",userEmail);
|
|
126 |
params.append("includeShared",includeShared);
|
|
127 |
params.append("includeByOthers",includeByOthers);
|
|
128 |
return brokerApi.getDatasourcesOfUser(params.toString());
|
|
129 |
} catch (JSONException e) {
|
|
130 |
LOGGER.debug("Error on get datasources of user",e);
|
|
131 |
}
|
|
132 |
return null;*/
|
170 |
133 |
DatasourcesBroker ret = new DatasourcesBroker();
|
171 |
134 |
try {
|
172 |
135 |
LOGGER.debug("In getDatasourcesOfUser");
|
... | ... | |
197 |
160 |
|
198 |
161 |
@Override
|
199 |
162 |
public Map<String, List<SimpleSubscriptionDesc>> getSubscriptionsOfUser(String userEmail) throws BrokerException {
|
|
163 |
|
|
164 |
|
200 |
165 |
final String service = "/subscriptions";
|
201 |
166 |
|
202 |
167 |
//build the uri params
|