Project

General

Profile

1
package eu.dnetlib.functionality.modular.ui;
2

    
3
import java.io.StringReader;
4
import javax.servlet.http.HttpServletResponse;
5

    
6
import com.google.gson.Gson;
7
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
8
import eu.dnetlib.rmi.enabling.ISLookUpService;
9
import eu.dnetlib.rmi.enabling.ISRegistryService;
10
import org.apache.commons.io.IOUtils;
11
import org.springframework.beans.factory.annotation.Autowired;
12
import org.springframework.stereotype.Controller;
13
import org.springframework.web.bind.annotation.RequestMapping;
14
import org.springframework.web.bind.annotation.RequestParam;
15

    
16
@Controller
17
public class CommonController {
18

    
19
	@Autowired
20
	private UniqueServiceLocator serviceLocator;
21

    
22
	@RequestMapping(value = "/ui/**/getProfile")
23
	public void getProfile(final HttpServletResponse res,
24
			@RequestParam(value = "id", required = true) final String id) throws Exception {
25
		res.setContentType("text/xml");
26
		final String profile = this.serviceLocator.getService(ISLookUpService.class).getResourceProfile(id);
27
		IOUtils.copy(new StringReader(profile), res.getOutputStream());
28
	}
29

    
30
	@RequestMapping(value = "/ui/**/getSchema")
31
	public void getSchema(final HttpServletResponse res,
32
			@RequestParam(value = "name", required = true) final String name) throws Exception {
33
		res.setContentType("text/xml");
34
		final String schema = this.serviceLocator.getService(ISLookUpService.class).getResourceTypeSchema(name);
35
		IOUtils.copy(new StringReader(schema), res.getOutputStream());
36
	}
37

    
38
	@RequestMapping(value = "/ui/**/validateProfile")
39
	public void validate(final HttpServletResponse res,
40
			@RequestParam(value = "id", required = true) final String id) throws Exception {
41
		final String newId = this.serviceLocator.getService(ISRegistryService.class).validateProfile(id);
42
		IOUtils.copy(new StringReader(new Gson().toJson(newId)), res.getOutputStream());
43
	}
44

    
45
	@RequestMapping(value = "/ui/**/deleteProfile")
46
	public void deleteProfile(final HttpServletResponse res,
47
			@RequestParam(value = "id", required = true) final String id) throws Exception {
48
		final boolean b = this.serviceLocator.getService(ISRegistryService.class).deleteProfile(id);
49
		IOUtils.copy(new StringReader(new Gson().toJson(b)), res.getOutputStream());
50
	}
51

    
52
}
(3-3/17)