Project

General

Profile

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

    
3
import java.io.StringReader;
4

    
5
import javax.annotation.Resource;
6
import javax.servlet.http.HttpServletResponse;
7

    
8
import org.apache.commons.io.IOUtils;
9
import org.springframework.stereotype.Controller;
10
import org.springframework.web.bind.annotation.RequestMapping;
11
import org.springframework.web.bind.annotation.RequestParam;
12

    
13
import com.google.gson.Gson;
14

    
15
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
16
import eu.dnetlib.rmi.enabling.ISLookUpService;
17
import eu.dnetlib.rmi.enabling.ISRegistryService;
18

    
19
@Controller
20
public class CommonController {
21

    
22
	@Resource
23
	private UniqueServiceLocator serviceLocator;
24

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

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

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

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

    
55
}
(3-3/17)