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