Project

General

Profile

1 48828 alessia.ba
package eu.dnetlib.parthenos.publisher;
2
3 49001 alessia.ba
import eu.dnetlib.parthenos.publisher.ParthenosPublisherHelper.ParthenosTargets;
4
import org.apache.commons.lang3.StringUtils;
5
import org.springframework.beans.factory.annotation.Autowired;
6 48844 alessia.ba
import org.springframework.scheduling.annotation.Async;
7 48828 alessia.ba
import org.springframework.web.bind.annotation.RequestMapping;
8
import org.springframework.web.bind.annotation.RequestMethod;
9
import org.springframework.web.bind.annotation.RequestParam;
10
import org.springframework.web.bind.annotation.RestController;
11
12
@RestController
13
public class ParthenosPublisherController {
14
15 49001 alessia.ba
	//TODO: to nicely handle arrors, follow https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-error-handling
16 48828 alessia.ba
17 49001 alessia.ba
	@Autowired
18
	private ParthenosPublisherHelper parthenosPublisherHelper;
19 48828 alessia.ba
20 49001 alessia.ba
	@RequestMapping(value = "/publish", method = RequestMethod.POST)
21 48844 alessia.ba
	@Async
22 49001 alessia.ba
	public void publish(@RequestParam final String record, @RequestParam(required = false) String parthenosTarget) throws ParthenosPublisherException {
23
		this.parthenosPublisherHelper.publish(record, getTarget(parthenosTarget));
24 48844 alessia.ba
	}
25
26 49001 alessia.ba
	@RequestMapping(value = "/unpublish", method = RequestMethod.GET)
27 48844 alessia.ba
	@Async
28 49001 alessia.ba
	public long unpublish(@RequestParam final String datasourceApi, @RequestParam(required = false) String parthenosTarget) throws ParthenosPublisherException {
29
		return this.parthenosPublisherHelper.unpublish(datasourceApi, getTarget(parthenosTarget));
30
	}
31 48828 alessia.ba
32 49001 alessia.ba
	private ParthenosTargets getTarget(String value){
33
		ParthenosTargets target = ParthenosTargets.ALL;
34
		if (StringUtils.isNotBlank(value)) {
35
			target = ParthenosTargets.valueOf(value);
36
		}
37
		return target;
38 48828 alessia.ba
	}
39
40 49233 alessia.ba
	public ParthenosPublisherHelper getParthenosPublisherHelper() {
41
		return parthenosPublisherHelper;
42
	}
43
44
	public void setParthenosPublisherHelper(final ParthenosPublisherHelper parthenosPublisherHelper) {
45
		this.parthenosPublisherHelper = parthenosPublisherHelper;
46
	}
47 48828 alessia.ba
}