1
|
package eu.dnetlib.functionality.modular.ui.workflows.controllers;
|
2
|
|
3
|
import java.io.IOException;
|
4
|
import java.util.*;
|
5
|
import javax.servlet.http.HttpServletRequest;
|
6
|
import javax.servlet.http.HttpServletResponse;
|
7
|
|
8
|
import com.google.common.collect.Maps;
|
9
|
import eu.dnetlib.functionality.modular.ui.AbstractAjaxController;
|
10
|
import eu.dnetlib.msro.workflows.util.ValidNodeValuesFetcher;
|
11
|
import eu.dnetlib.msro.workflows.util.ValidNodeValuesFetcher.DnetParamValue;
|
12
|
import org.apache.commons.logging.Log;
|
13
|
import org.apache.commons.logging.LogFactory;
|
14
|
import org.springframework.beans.factory.annotation.Autowired;
|
15
|
import org.springframework.stereotype.Controller;
|
16
|
import org.springframework.web.bind.annotation.RequestMapping;
|
17
|
import org.springframework.web.bind.annotation.RequestParam;
|
18
|
import org.springframework.web.bind.annotation.ResponseBody;
|
19
|
|
20
|
@Controller
|
21
|
public class DnetParamValuesController extends AbstractAjaxController {
|
22
|
|
23
|
private static final Log log = LogFactory.getLog(DnetParamValuesController.class);
|
24
|
@Autowired
|
25
|
private List<ValidNodeValuesFetcher> validNodesFetchers;
|
26
|
|
27
|
@RequestMapping("/ui/wf/obtainValidValues.do")
|
28
|
public @ResponseBody List<DnetParamValue> obtainValidValues(final HttpServletRequest request,
|
29
|
final HttpServletResponse response,
|
30
|
@RequestParam(value = "bean", required = true) final String bean) throws IOException {
|
31
|
|
32
|
final ValidNodeValuesFetcher fetcher = findValidNodeValuesFetcher(bean);
|
33
|
|
34
|
if (fetcher == null) {
|
35
|
log.error("ValidNodeValuesFetcher not found: " + bean);
|
36
|
return new ArrayList<ValidNodeValuesFetcher.DnetParamValue>();
|
37
|
} else {
|
38
|
final Map<String, String> params = findParams(request);
|
39
|
final List<DnetParamValue> list = fetcher.apply(params);
|
40
|
Collections.sort(list);
|
41
|
return list;
|
42
|
}
|
43
|
}
|
44
|
|
45
|
private ValidNodeValuesFetcher findValidNodeValuesFetcher(final String bean) {
|
46
|
for (final ValidNodeValuesFetcher fetcher : this.validNodesFetchers) {
|
47
|
if (fetcher.getName().equals(bean)) { return fetcher; }
|
48
|
}
|
49
|
return null;
|
50
|
}
|
51
|
|
52
|
private Map<String, String> findParams(final HttpServletRequest request) {
|
53
|
final Map<String, String> params = Maps.newHashMap();
|
54
|
|
55
|
final Enumeration<?> e = request.getParameterNames();
|
56
|
while (e.hasMoreElements()) {
|
57
|
final String name = (String) e.nextElement();
|
58
|
params.put(name, request.getParameter(name));
|
59
|
}
|
60
|
return params;
|
61
|
}
|
62
|
|
63
|
}
|