Project

General

Profile

1
package eu.dnetlib.parthenos.publisher;
2

    
3
import java.io.IOException;
4
import java.net.URISyntaxException;
5

    
6
import eu.dnetlib.parthenos.jrr.JRRPublisherHelper;
7
import eu.dnetlib.parthenos.publisher.ParthenosPublisherHelper.ParthenosTargets;
8
import freemarker.template.TemplateException;
9
import org.apache.commons.logging.Log;
10
import org.apache.commons.logging.LogFactory;
11
import org.springframework.beans.factory.annotation.Autowired;
12
import org.springframework.web.bind.annotation.RequestMapping;
13
import org.springframework.web.bind.annotation.RequestMethod;
14
import org.springframework.web.bind.annotation.RequestParam;
15
import org.springframework.web.bind.annotation.RestController;
16

    
17
@RestController
18
public class ParthenosPublisherController {
19

    
20
	private static final Log log = LogFactory.getLog(ParthenosPublisherController.class);
21
	//TODO: to nicely handle arrors, follow https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-error-handling
22

    
23
	@Autowired
24
	private ParthenosPublisherHelper parthenosPublisherHelper;
25

    
26
	@Autowired
27
	private JRRPublisherHelper jrrPublisherHelper;
28

    
29
	@RequestMapping(value="publishJRR", method = RequestMethod.POST)
30
	public int publishJRR(@RequestParam final String typeNamespace, @RequestParam final String typeName, @RequestParam final String datasourceApi, @RequestParam final String datasourceName)
31
			throws URISyntaxException, TemplateException, IOException, InterruptedException, ParthenosPublisherException {
32
		return jrrPublisherHelper.publish(typeNamespace, typeName, datasourceApi, datasourceName);
33
	}
34

    
35
	@RequestMapping(value = "/publish", method = RequestMethod.POST)
36
	public void publish(@RequestParam final String record, @RequestParam(required = false) String parthenosTarget) throws ParthenosPublisherException {
37
		getParthenosPublisherHelper().publish(record, getTarget(parthenosTarget));
38
	}
39

    
40

    
41
	@RequestMapping(value = "/unpublish", method = RequestMethod.GET)
42
	public void unpublish(@RequestParam final String datasourceApi, @RequestParam(required = false) String parthenosTarget) throws ParthenosPublisherException {
43
		getParthenosPublisherHelper().unpublish(datasourceApi, getTarget(parthenosTarget));
44
	}
45

    
46
	@RequestMapping(value = "/dropRegistry", method = RequestMethod.GET)
47
	public void unpublish() throws ParthenosPublisherException {
48
		getParthenosPublisherHelper().dropRegistry();
49
	}
50

    
51
	private ParthenosTargets getTarget(String value) {
52
		return ParthenosTargets.valueOf(value);
53
	}
54

    
55
	public ParthenosPublisherHelper getParthenosPublisherHelper() {
56
		return parthenosPublisherHelper;
57
	}
58

    
59
	public void setParthenosPublisherHelper(final ParthenosPublisherHelper parthenosPublisherHelper) {
60
		this.parthenosPublisherHelper = parthenosPublisherHelper;
61
	}
62
}
(1-1/4)