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