1
|
package eu.dnetlib.data.transformation.inspector;
|
2
|
|
3
|
import java.util.List;
|
4
|
|
5
|
import javax.annotation.Resource;
|
6
|
|
7
|
import org.springframework.stereotype.Controller;
|
8
|
import org.springframework.ui.Model;
|
9
|
import org.springframework.web.bind.annotation.RequestMapping;
|
10
|
import org.springframework.web.bind.annotation.RequestParam;
|
11
|
|
12
|
import com.google.common.base.Function;
|
13
|
import com.google.common.collect.Lists;
|
14
|
|
15
|
import eu.dnetlib.data.transformation.service.DataTransformerFactory;
|
16
|
import eu.dnetlib.data.transformation.service.SimpleDataTransformer;
|
17
|
import eu.dnetlib.enabling.inspector.AbstractInspectorController;
|
18
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException;
|
19
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
|
20
|
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
|
21
|
|
22
|
@Controller
|
23
|
public class DataTransformationController extends AbstractInspectorController {
|
24
|
|
25
|
@Resource
|
26
|
private DataTransformerFactory dataTransformerFactory;
|
27
|
|
28
|
@Resource
|
29
|
private UniqueServiceLocator serviceLocator;
|
30
|
|
31
|
public static class SelectOption {
|
32
|
|
33
|
private String id;
|
34
|
private String name;
|
35
|
private boolean selected;
|
36
|
|
37
|
public SelectOption(final String id, final String name, final boolean selected) {
|
38
|
this.id = id;
|
39
|
this.name = name;
|
40
|
this.selected = selected;
|
41
|
}
|
42
|
|
43
|
public String getId() {
|
44
|
return id;
|
45
|
}
|
46
|
|
47
|
public String getName() {
|
48
|
return name;
|
49
|
}
|
50
|
|
51
|
public boolean isSelected() {
|
52
|
return selected;
|
53
|
}
|
54
|
}
|
55
|
|
56
|
@RequestMapping(value = "/inspector/transform.do")
|
57
|
public void transform(final Model model,
|
58
|
@RequestParam(value = "rule", required = false) final String ruleId,
|
59
|
@RequestParam(value = "record", required = false) final String record) throws Exception {
|
60
|
|
61
|
model.addAttribute("rules", obtainRuleProfiles(ruleId));
|
62
|
|
63
|
if (ruleId != null && record != null) {
|
64
|
final SimpleDataTransformer transformer = dataTransformerFactory.createTransformer(ruleId);
|
65
|
model.addAttribute("input", record);
|
66
|
model.addAttribute("output", transformer.evaluate(record));
|
67
|
}
|
68
|
}
|
69
|
|
70
|
private List<SelectOption> obtainRuleProfiles(final String currentId) throws ISLookUpException {
|
71
|
String xquery = "for $x " +
|
72
|
"in collection('/db/DRIVER/TransformationRuleDSResources/TransformationRuleDSResourceType') " +
|
73
|
"return concat($x//RESOURCE_IDENTIFIER/@value, ' @@@ ', $x//TITLE)";
|
74
|
|
75
|
return Lists.transform(serviceLocator.getService(ISLookUpService.class).quickSearchProfile(xquery), new Function<String, SelectOption>() {
|
76
|
|
77
|
@Override
|
78
|
public SelectOption apply(final String value) {
|
79
|
final String[] arr = value.split("@@@");
|
80
|
final String id = arr[0].trim();
|
81
|
final String name = arr[1].trim();
|
82
|
return new SelectOption(id, name, id.equals(currentId));
|
83
|
}
|
84
|
});
|
85
|
}
|
86
|
}
|