1
|
package eu.dnetlib.enabling.inspector;
|
2
|
|
3
|
import java.io.File;
|
4
|
import java.io.IOException;
|
5
|
import javax.annotation.Resource;
|
6
|
import javax.servlet.http.HttpServletRequest;
|
7
|
import javax.xml.parsers.ParserConfigurationException;
|
8
|
import javax.xml.xpath.XPathExpressionException;
|
9
|
|
10
|
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
|
11
|
import eu.dnetlib.enabling.tools.OpaqueResource;
|
12
|
import eu.dnetlib.enabling.tools.ResourceIdentifierResolver;
|
13
|
import eu.dnetlib.enabling.tools.StringOpaqueResource;
|
14
|
import eu.dnetlib.rmi.enabling.ISLookUpException;
|
15
|
import eu.dnetlib.rmi.enabling.ISLookUpService;
|
16
|
import eu.dnetlib.rmi.enabling.ISRegistryException;
|
17
|
import eu.dnetlib.rmi.enabling.ISRegistryService;
|
18
|
import eu.dnetlib.xml.database.XMLDatabase;
|
19
|
import org.apache.commons.logging.Log;
|
20
|
import org.apache.commons.logging.LogFactory;
|
21
|
import org.springframework.beans.factory.annotation.Autowired;
|
22
|
import org.springframework.stereotype.Controller;
|
23
|
import org.springframework.ui.Model;
|
24
|
import org.springframework.web.bind.annotation.RequestMapping;
|
25
|
import org.xml.sax.SAXException;
|
26
|
import org.xmldb.api.base.XMLDBException;
|
27
|
|
28
|
/**
|
29
|
* Implement mid-level functionality for validation and invalidation of profiles browsed with the ResourceTreeController.
|
30
|
*
|
31
|
* @see ResourceTreeController
|
32
|
* @author marko
|
33
|
*
|
34
|
*/
|
35
|
@Controller
|
36
|
public class ValidationController extends AbstractInspectorController {
|
37
|
|
38
|
/**
|
39
|
* logger.
|
40
|
*/
|
41
|
private static final Log log = LogFactory.getLog(ValidationController.class); // NOPMD by marko on 11/24/08 5:02 PM
|
42
|
|
43
|
/**
|
44
|
* base index.do path.
|
45
|
*/
|
46
|
private static final String INDEX_DO = "/inspector/index.do";
|
47
|
|
48
|
/**
|
49
|
* xml database.
|
50
|
*/
|
51
|
@Resource(name = "existDatabase")
|
52
|
private transient XMLDatabase xmlDatabase;
|
53
|
|
54
|
/**
|
55
|
* service locator.
|
56
|
*/
|
57
|
@Autowired
|
58
|
private UniqueServiceLocator serviceLocator;
|
59
|
|
60
|
/**
|
61
|
* resolve xmldb ids to resource ids.
|
62
|
*/
|
63
|
@Autowired
|
64
|
private transient ResourceIdentifierResolver resIdResolver;
|
65
|
|
66
|
/**
|
67
|
* high level: profile validation via registry.
|
68
|
*
|
69
|
* @param model
|
70
|
* model
|
71
|
* @param request
|
72
|
* request
|
73
|
* @return view name
|
74
|
* @throws XMLDBException
|
75
|
* happens
|
76
|
* @throws ParserConfigurationException
|
77
|
* shouldn't happen
|
78
|
* @throws IOException
|
79
|
* shouldn't happen
|
80
|
* @throws SAXException
|
81
|
* shouldn't happen
|
82
|
* @throws XPathExpressionException
|
83
|
* shouldn't happen
|
84
|
* @throws ISRegistryException
|
85
|
* happens
|
86
|
* @throws ISLookUpException
|
87
|
* happens
|
88
|
*/
|
89
|
@RequestMapping("/inspector/index.do/**/validate")
|
90
|
String validate(final Model model, final HttpServletRequest request) throws XMLDBException, XPathExpressionException, SAXException, IOException,
|
91
|
ParserConfigurationException, ISRegistryException, ISLookUpException {
|
92
|
|
93
|
final String path = request.getPathInfo().replace(INDEX_DO, "").replace("/validate", "");
|
94
|
|
95
|
final File fileHelper = new File(path);
|
96
|
final String collection = fileHelper.getParent();
|
97
|
final String fileName = fileHelper.getName();
|
98
|
|
99
|
log.info("validating: " + path);
|
100
|
final OpaqueResource resource = new StringOpaqueResource(xmlDatabase.read(fileName, collection));
|
101
|
log.info("validating a " + resource.getResourceType());
|
102
|
|
103
|
final String newId = serviceLocator.getService(ISRegistryService.class, true).validateProfile(resource.getResourceId());
|
104
|
final OpaqueResource valid = new StringOpaqueResource(serviceLocator.getService(ISLookUpService.class).getResourceProfile(newId));
|
105
|
|
106
|
final String vFileName = resIdResolver.getFileName(valid.getResourceId());
|
107
|
final String vCollectionName = resIdResolver.getCollectionName(valid.getResourceId());
|
108
|
|
109
|
return "redirect:../../../" + vCollectionName + "/" + vFileName + "/show";
|
110
|
}
|
111
|
|
112
|
/**
|
113
|
* high level: profile invalidation via registry.
|
114
|
*
|
115
|
* @param model
|
116
|
* model
|
117
|
* @param request
|
118
|
* request
|
119
|
* @return view name
|
120
|
* @throws XMLDBException
|
121
|
* happens
|
122
|
* @throws ParserConfigurationException
|
123
|
* shouldn't happen
|
124
|
* @throws IOException
|
125
|
* shouldn't happen
|
126
|
* @throws SAXException
|
127
|
* shouldn't happen
|
128
|
* @throws XPathExpressionException
|
129
|
* shouldn't happen
|
130
|
* @throws ISRegistryException
|
131
|
* happens
|
132
|
* @throws ISLookUpException
|
133
|
* happens
|
134
|
*/
|
135
|
@RequestMapping("/inspector/index.do/**/invalidate")
|
136
|
String invalidate(final Model model, final HttpServletRequest request) throws XMLDBException, XPathExpressionException, SAXException, IOException,
|
137
|
ParserConfigurationException, ISRegistryException, ISLookUpException {
|
138
|
|
139
|
final String path = request.getPathInfo().replace(INDEX_DO, "").replace("/invalidate", "");
|
140
|
|
141
|
final File fileHelper = new File(path);
|
142
|
final String collection = fileHelper.getParent();
|
143
|
final String fileName = fileHelper.getName();
|
144
|
|
145
|
log.info("invalidating: " + path);
|
146
|
final OpaqueResource resource = new StringOpaqueResource(xmlDatabase.read(fileName, collection));
|
147
|
log.info("invalidating a " + resource.getResourceType());
|
148
|
|
149
|
final String newId = serviceLocator.getService(ISRegistryService.class, true).invalidateProfile(resource.getResourceId());
|
150
|
final OpaqueResource invalid = new StringOpaqueResource(serviceLocator.getService(ISLookUpService.class).getResourceProfile(newId));
|
151
|
|
152
|
final String vFileName = resIdResolver.getFileName(invalid.getResourceId());
|
153
|
final String vCollectionName = resIdResolver.getCollectionName(invalid.getResourceId());
|
154
|
|
155
|
return "redirect:../../../" + vCollectionName + "/" + vFileName + "/show";
|
156
|
}
|
157
|
|
158
|
}
|