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.is.lookup.rmi.ISLookUpService;
|
16
|
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService;
|
17
|
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
|
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
|
String profile = 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
|
String schema = 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
|
String newId = serviceLocator.getService(ISRegistryService.class).validateProfile(id);
|
45
|
IOUtils.copy(new StringReader(new Gson().toJson(newId)), res.getOutputStream());
|
46
|
}
|
47
|
|
48
|
@RequestMapping(value = "/ui/**/invalidateProfile")
|
49
|
public void invalidateProfile(final HttpServletResponse res,
|
50
|
@RequestParam(value = "id", required = true) final String id) throws Exception {
|
51
|
String newId = serviceLocator.getService(ISRegistryService.class).invalidateProfile(id);
|
52
|
IOUtils.copy(new StringReader(new Gson().toJson(newId)), res.getOutputStream());
|
53
|
}
|
54
|
|
55
|
@RequestMapping(value = "/ui/**/deleteProfile")
|
56
|
public void deleteProfile(final HttpServletResponse res,
|
57
|
@RequestParam(value = "id", required = true) final String id) throws Exception {
|
58
|
boolean b = serviceLocator.getService(ISRegistryService.class).deleteProfile(id);
|
59
|
IOUtils.copy(new StringReader(new Gson().toJson(b)), res.getOutputStream());
|
60
|
}
|
61
|
|
62
|
}
|