1
|
package eu.dnetlib.functionality.modular.ui.repositories.controllers;
|
2
|
|
3
|
import java.util.Date;
|
4
|
import java.util.List;
|
5
|
import java.util.Map;
|
6
|
import javax.annotation.Resource;
|
7
|
|
8
|
import com.google.gson.Gson;
|
9
|
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
|
10
|
import eu.dnetlib.functionality.modular.ui.AbstractAjaxController;
|
11
|
import eu.dnetlib.functionality.modular.ui.repositories.util.RepoUIUtils;
|
12
|
import eu.dnetlib.functionality.modular.ui.workflows.objects.sections.WorkflowSectionGrouper;
|
13
|
import eu.dnetlib.msro.workflows.procs.WorkflowExecutor;
|
14
|
import eu.dnetlib.rmi.data.CollectorService;
|
15
|
import eu.dnetlib.rmi.data.CollectorServiceException;
|
16
|
import eu.dnetlib.rmi.data.ProtocolParameterValue;
|
17
|
import eu.dnetlib.rmi.datasource.*;
|
18
|
import net.sf.ehcache.Cache;
|
19
|
import net.sf.ehcache.Element;
|
20
|
import org.apache.commons.lang3.StringUtils;
|
21
|
import org.apache.commons.logging.Log;
|
22
|
import org.apache.commons.logging.LogFactory;
|
23
|
import org.springframework.beans.factory.annotation.Autowired;
|
24
|
import org.springframework.stereotype.Controller;
|
25
|
import org.springframework.web.bind.annotation.RequestMapping;
|
26
|
import org.springframework.web.bind.annotation.RequestParam;
|
27
|
import org.springframework.web.bind.annotation.ResponseBody;
|
28
|
|
29
|
@Controller
|
30
|
public class RepoInternalController extends AbstractAjaxController {
|
31
|
|
32
|
private static final Log log = LogFactory.getLog(RepoInternalController.class);
|
33
|
@Autowired
|
34
|
private UniqueServiceLocator serviceLocator;
|
35
|
@Autowired
|
36
|
private WorkflowSectionGrouper workflowSectionGrouper;
|
37
|
@Autowired
|
38
|
private WorkflowExecutor workflowExecutor;
|
39
|
@Autowired
|
40
|
private RepoUIUtils repoUIUtils;
|
41
|
@Resource(name = "repoUIJsonCache")
|
42
|
private Cache repoUIJsonCache;
|
43
|
|
44
|
@RequestMapping(value = "/ui/browseRepoField.do")
|
45
|
public @ResponseBody List<BrowseTerm> browseRepoField(@RequestParam(value = "field", required = true) final String field) throws Exception {
|
46
|
return this.serviceLocator.getService(DatasourceManagerService.class).browseField(field);
|
47
|
}
|
48
|
|
49
|
@SuppressWarnings("unchecked")
|
50
|
@RequestMapping(value = "/ui/listApis.do")
|
51
|
public @ResponseBody List<SearchInterfacesEntry> listApis(
|
52
|
@RequestParam(value = "param", required = true) final String param,
|
53
|
@RequestParam(value = "value", required = true) final String value,
|
54
|
@RequestParam(value = "refresh", required = false) final String refresh) throws Exception {
|
55
|
|
56
|
final String cacheKey = "list@@@" + param + "@@@" + value;
|
57
|
|
58
|
final Element elem = this.repoUIJsonCache.get(cacheKey);
|
59
|
|
60
|
if (elem != null && refresh == null) {
|
61
|
return (List<SearchInterfacesEntry>) elem.getObjectValue();
|
62
|
} else {
|
63
|
log.info("Refreshing " + cacheKey + " cache...");
|
64
|
final List<SearchInterfacesEntry> list = this.serviceLocator.getService(DatasourceManagerService.class).searchInterface(param, value);
|
65
|
this.repoUIJsonCache.put(new Element(cacheKey, list));
|
66
|
return list;
|
67
|
}
|
68
|
}
|
69
|
|
70
|
@RequestMapping(value = "/ui/listRepositories.map")
|
71
|
public @ResponseBody List<RepositoryMapEntry> listRepositories_asMap() throws Exception {
|
72
|
return this.serviceLocator.getService(DatasourceManagerService.class).getRepositoryMap();
|
73
|
}
|
74
|
|
75
|
@RequestMapping(value = "/ui/listRepositories.json")
|
76
|
public @ResponseBody List<SimpleDatasourceDesc> listRepositories(@RequestParam(value = "type", required = true) final String type) throws Exception {
|
77
|
return this.serviceLocator.getService(DatasourceManagerService.class).simpleListDatasourcesByType(type);
|
78
|
}
|
79
|
|
80
|
@SuppressWarnings("unchecked")
|
81
|
@RequestMapping("/ui/repo/repoApi.update")
|
82
|
public @ResponseBody boolean updateRepoApi(
|
83
|
@RequestParam(value = "id", required = true) final String repoId,
|
84
|
@RequestParam(value = "iface", required = true) final String ifaceId,
|
85
|
@RequestParam(value = "accessParams", required = true) final String accessParamsJson) throws Exception {
|
86
|
if (!StringUtils.isEmpty(accessParamsJson)) {
|
87
|
this.serviceLocator.getService(DatasourceManagerService.class).bulkUpdateApiAccessParams(repoId, ifaceId,
|
88
|
new Gson().fromJson(accessParamsJson, Map.class));
|
89
|
}
|
90
|
return true;
|
91
|
}
|
92
|
|
93
|
@RequestMapping("/ui/repo/repoApiCompliance.update")
|
94
|
public @ResponseBody boolean updateRepoApiCompliance(@RequestParam(value = "id", required = true) final String repoId,
|
95
|
@RequestParam(value = "iface", required = true) final String ifaceId,
|
96
|
@RequestParam(value = "compliance", required = true) final String compliance) throws Exception {
|
97
|
|
98
|
log.debug("SET COMPLIANCE TO " + compliance);
|
99
|
|
100
|
this.serviceLocator.getService(DatasourceManagerService.class).overrideCompliance(repoId, ifaceId, compliance);
|
101
|
|
102
|
this.repoUIJsonCache.removeAll();
|
103
|
|
104
|
return true;
|
105
|
}
|
106
|
|
107
|
@RequestMapping("/ui/repo/repoApiCompliance.reset")
|
108
|
public @ResponseBody boolean resetRepoApiCompliance(@RequestParam(value = "id", required = true) final String repoId,
|
109
|
@RequestParam(value = "iface", required = true) final String ifaceId) throws Exception {
|
110
|
|
111
|
log.debug("RESET COMPLIANCE");
|
112
|
|
113
|
this.serviceLocator.getService(DatasourceManagerService.class).overrideCompliance(repoId, ifaceId, null);
|
114
|
|
115
|
this.repoUIJsonCache.removeAll();
|
116
|
|
117
|
return true;
|
118
|
}
|
119
|
|
120
|
@RequestMapping("/ui/repoApi.new")
|
121
|
public @ResponseBody boolean addRepoApi(@RequestParam(value = "repoId", required = true) final String repoId,
|
122
|
@RequestParam(value = "iface", required = true) final String ifaceJson) throws DatasourceManagerServiceException {
|
123
|
final IfaceDesc iface = new Gson().fromJson(ifaceJson, IfaceDesc.class);
|
124
|
|
125
|
log.info("Adding interface " + iface.getId() + " to repository " + repoId);
|
126
|
|
127
|
final DatasourceManagerService dsManager = this.serviceLocator.getService(DatasourceManagerService.class);
|
128
|
return dsManager.addInterface(repoId, iface);
|
129
|
}
|
130
|
|
131
|
@RequestMapping("/ui/repo.new")
|
132
|
public @ResponseBody boolean addRepoApi(@RequestParam(value = "repo", required = true) final String repoJson) throws DatasourceManagerServiceException {
|
133
|
final DatasourceDesc ds = new Gson().fromJson(repoJson, DatasourceDesc.class);
|
134
|
ds.setDateOfCollection(new Date());
|
135
|
|
136
|
if (StringUtils.isBlank(ds.getEnglishName())) {
|
137
|
ds.setEnglishName(ds.getOfficialName());
|
138
|
}
|
139
|
|
140
|
log.info("Adding datasource " + ds.getId() + " - name " + ds.getOfficialName());
|
141
|
|
142
|
final DatasourceManagerService dsManager = this.serviceLocator.getService(DatasourceManagerService.class);
|
143
|
|
144
|
return dsManager.addDatasource(ds);
|
145
|
}
|
146
|
|
147
|
@RequestMapping("/ui/listValidValuesForParam.do")
|
148
|
public @ResponseBody List<ProtocolParameterValue> listValidValuesForParam(
|
149
|
@RequestParam(value = "protocol", required = true) final String protocol,
|
150
|
@RequestParam(value = "param", required = true) final String param,
|
151
|
@RequestParam(value = "baseUrl", required = true) final String baseUrl) throws CollectorServiceException {
|
152
|
|
153
|
return this.serviceLocator.getService(CollectorService.class).listValidValuesForParam(protocol, baseUrl, param, null);
|
154
|
}
|
155
|
}
|