1
|
package eu.dnetlib.enabling.inspector;
|
2
|
|
3
|
import java.io.IOException;
|
4
|
|
5
|
import javax.annotation.Resource;
|
6
|
import javax.xml.parsers.ParserConfigurationException;
|
7
|
import javax.xml.xpath.XPathExpressionException;
|
8
|
|
9
|
import org.springframework.stereotype.Controller;
|
10
|
import org.springframework.web.bind.annotation.RequestMapping;
|
11
|
import org.springframework.web.bind.annotation.RequestMethod;
|
12
|
import org.springframework.web.bind.annotation.RequestParam;
|
13
|
import org.xml.sax.SAXException;
|
14
|
|
15
|
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
|
16
|
import eu.dnetlib.enabling.tools.CompatResourceIdentifierResolverImpl;
|
17
|
import eu.dnetlib.enabling.tools.OpaqueResource;
|
18
|
import eu.dnetlib.enabling.tools.ResourceIdentifierResolver;
|
19
|
import eu.dnetlib.enabling.tools.StringOpaqueResource;
|
20
|
import eu.dnetlib.rmi.enabling.ISRegistryException;
|
21
|
import eu.dnetlib.rmi.enabling.ISRegistryService;
|
22
|
|
23
|
/**
|
24
|
* This inspector allows the admin to quickly register a profile, like a repository profile.
|
25
|
*
|
26
|
* @author marko
|
27
|
*
|
28
|
*/
|
29
|
@Controller
|
30
|
public class RegistryController extends AbstractInspectorController {
|
31
|
|
32
|
@Resource
|
33
|
private UniqueServiceLocator serviceLocator;
|
34
|
|
35
|
/**
|
36
|
* manages resource identifier mappings with the abstract xmldb namespace (files/collections).
|
37
|
*/
|
38
|
@Resource
|
39
|
private ResourceIdentifierResolver resIdResolver = new CompatResourceIdentifierResolverImpl();
|
40
|
|
41
|
@RequestMapping(value = "/inspector/registerProfile.do", method = RequestMethod.GET)
|
42
|
public void registerProfile() {}
|
43
|
|
44
|
@RequestMapping(value = "/inspector/registerProfile2.do", method = RequestMethod.POST)
|
45
|
public String doRegisterProfile(
|
46
|
@RequestParam(value = "source") final String source,
|
47
|
@RequestParam(value = "valid", required = false) final String valid,
|
48
|
@RequestParam(value = "pending", required = false) final String pending) throws ISRegistryException, XPathExpressionException, SAXException,
|
49
|
IOException, ParserConfigurationException {
|
50
|
|
51
|
String id = null;
|
52
|
|
53
|
if (valid != null && !"".equals(valid)) {
|
54
|
id = serviceLocator.getService(ISRegistryService.class, true).registerProfile(source);
|
55
|
} else {
|
56
|
id = serviceLocator.getService(ISRegistryService.class, true).insertProfileForValidation(resourceTypeFor(source), source);
|
57
|
}
|
58
|
|
59
|
String collection = resIdResolver.getCollectionName(id);
|
60
|
String file = resIdResolver.getFileName(id);
|
61
|
|
62
|
return "redirect:index.do/db/DRIVER/" + collection + "/" + file + "/show";
|
63
|
}
|
64
|
|
65
|
private String resourceTypeFor(final String source) throws XPathExpressionException, SAXException, IOException, ParserConfigurationException {
|
66
|
OpaqueResource resource = new StringOpaqueResource(source);
|
67
|
return resource.getResourceType();
|
68
|
}
|
69
|
|
70
|
}
|