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