Revision 58380
Added by Michele Artini almost 4 years ago
RepoInternalController.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.functionality.modular.ui.repositories; |
2 | 2 |
|
3 |
import java.io.IOException; |
|
3 | 4 |
import java.io.StringReader; |
4 | 5 |
import java.util.Date; |
5 |
import java.util.HashMap; |
|
6 | 6 |
import java.util.List; |
7 | 7 |
import java.util.Map; |
8 | 8 |
|
... | ... | |
29 | 29 |
import org.springframework.web.bind.annotation.RequestParam; |
30 | 30 |
import org.springframework.web.bind.annotation.ResponseBody; |
31 | 31 |
import org.springframework.web.bind.annotation.ResponseStatus; |
32 |
import org.springframework.web.client.RestTemplate; |
|
32 | 33 |
|
33 | 34 |
import com.google.common.collect.Maps; |
34 | 35 |
import com.google.gson.Gson; |
... | ... | |
77 | 78 |
@Resource |
78 | 79 |
private RepoUIUtils repoUIUtils; |
79 | 80 |
|
81 |
@Value("${repo.ui.mdstore.sync.button}") |
|
82 |
private String syncButton; |
|
83 |
|
|
80 | 84 |
@Value("${repo.ui.mdstore.sync.desc}") |
81 |
private String syncDescription;
|
|
85 |
private String syncDesc; |
|
82 | 86 |
|
83 |
@Value("${repo.ui.mdstore.sync.baseUrl}") |
|
84 |
private String syncApi; |
|
87 |
@Value("${repo.ui.mdstore.sync.api.baseUrl}")
|
|
88 |
private String syncApiBaseUrl;
|
|
85 | 89 |
|
90 |
@Value("${repo.ui.mdstore.sync.is.baseUrl}") |
|
91 |
private String syncISBaseUrl; |
|
92 |
|
|
86 | 93 |
@Value("${services.mdstore.mongodb.db}") |
87 | 94 |
private String mongoDb; |
88 | 95 |
|
... | ... | |
234 | 241 |
|
235 | 242 |
@RequestMapping("/ui/repos/repoApi.html") |
236 | 243 |
public void repoApiHtml(final ModelMap map) throws Exception { |
237 |
if (StringUtils.isNoneBlank(syncDescription, syncApi)) { |
|
238 |
map.addAttribute("syncDesc", syncDescription); |
|
244 |
if (StringUtils.isNoneBlank(syncButton, syncDesc, syncApiBaseUrl, syncISBaseUrl)) { |
|
245 |
map.addAttribute("syncButton", syncButton); |
|
246 |
map.addAttribute("syncDesc", syncDesc); |
|
247 |
map.addAttribute("syncISBaseUrl", syncISBaseUrl); |
|
239 | 248 |
map.addAttribute("mongoDB", mongoDb); |
240 | 249 |
map.addAttribute("mongoUrl", String.format("mongodb://%s:%s", mongoHost, mongoPort)); |
241 | 250 |
} |
... | ... | |
282 | 291 |
} |
283 | 292 |
|
284 | 293 |
@RequestMapping(value = "/ui/remoteDatasource/apis", method = RequestMethod.GET) |
285 |
public @ResponseBody Map<String, String> listRemoteApis(@RequestParam(value = "repo", required = true) final String repoId) { |
|
286 |
// TODO |
|
287 |
return new HashMap<>(); |
|
294 |
public void listRemoteApis(@RequestParam(value = "repo", required = true) final String repoId, |
|
295 |
final HttpServletResponse response) throws IOException { |
|
296 |
|
|
297 |
final RestTemplate restTemplate = new RestTemplate(); |
|
298 |
|
|
299 |
final String res = restTemplate.getForObject(syncApiBaseUrl + "/ds/api/" + repoId, String.class); |
|
300 |
|
|
301 |
response.setContentType("application/json;charset=UTF-8"); |
|
302 |
|
|
303 |
IOUtils.write(res, response.getOutputStream()); |
|
288 | 304 |
} |
289 | 305 |
|
290 | 306 |
@RequestMapping(value = "/ui/remoteDatasource/api", method = RequestMethod.POST) |
291 |
public @ResponseBody Map<String, String> listRemoteApis(@RequestParam(value = "repo", required = true) final String repoId, |
|
292 |
@RequestBody final Api<ApiParam> api) { |
|
293 |
// TODO |
|
294 |
return new HashMap<>(); |
|
307 |
public void saveRemoteApi(@RequestBody final Api<ApiParamImpl> api, final HttpServletResponse response) throws IOException { |
|
308 |
|
|
309 |
final String url = syncApiBaseUrl + "/ds/api/add"; |
|
310 |
|
|
311 |
log.info("Adding new remote API:"); |
|
312 |
log.info(" - repo id: " + api.getDatasource()); |
|
313 |
log.info(" - api id: " + api.getId()); |
|
314 |
log.info(" - rest call: " + url); |
|
315 |
|
|
316 |
final RestTemplate restTemplate = new RestTemplate(); |
|
317 |
|
|
318 |
final String res = restTemplate.postForObject(url, api, String.class); |
|
319 |
|
|
320 |
response.setContentType("application/json;charset=UTF-8"); |
|
321 |
|
|
322 |
IOUtils.write(res, response.getOutputStream()); |
|
295 | 323 |
} |
296 | 324 |
|
297 | 325 |
@ExceptionHandler(Exception.class) |
Also available in: Unified diff
remoteMdstore API creation in other infrastructure (partial implementation)