Revision 50278
Added by Michele Artini about 6 years ago
RepoInternalController.java | ||
---|---|---|
9 | 9 |
import javax.servlet.http.HttpServletRequest; |
10 | 10 |
import javax.servlet.http.HttpServletResponse; |
11 | 11 |
|
12 |
import com.google.common.cache.Cache; |
|
13 | 12 |
import org.apache.commons.io.IOUtils; |
14 | 13 |
import org.apache.commons.lang.StringUtils; |
15 | 14 |
import org.apache.commons.lang.exception.ExceptionUtils; |
16 | 15 |
import org.apache.commons.logging.Log; |
17 | 16 |
import org.apache.commons.logging.LogFactory; |
17 |
import org.springframework.beans.factory.annotation.Autowired; |
|
18 | 18 |
import org.springframework.cache.annotation.CacheEvict; |
19 | 19 |
import org.springframework.cache.annotation.Cacheable; |
20 | 20 |
import org.springframework.http.HttpStatus; |
... | ... | |
28 | 28 |
|
29 | 29 |
import com.google.common.collect.Maps; |
30 | 30 |
import com.google.gson.Gson; |
31 |
import com.google.gson.reflect.TypeToken; |
|
31 | 32 |
|
32 | 33 |
import eu.dnetlib.data.collector.rmi.CollectorService; |
33 | 34 |
import eu.dnetlib.data.collector.rmi.CollectorServiceException; |
34 | 35 |
import eu.dnetlib.data.collector.rmi.ProtocolParameterValue; |
35 |
import eu.dnetlib.enabling.datasources.rmi.BrowseTerm; |
|
36 |
import eu.dnetlib.enabling.datasources.rmi.DatasourceDesc; |
|
37 |
import eu.dnetlib.enabling.datasources.rmi.DatasourceManagerService; |
|
38 |
import eu.dnetlib.enabling.datasources.rmi.DatasourceManagerServiceException; |
|
39 |
import eu.dnetlib.enabling.datasources.rmi.IfaceDesc; |
|
40 |
import eu.dnetlib.enabling.datasources.rmi.RepositoryMapEntry; |
|
41 |
import eu.dnetlib.enabling.datasources.rmi.SearchInterfacesEntry; |
|
42 |
import eu.dnetlib.enabling.datasources.rmi.SimpleDatasourceDesc; |
|
36 |
import eu.dnetlib.enabling.datasources.common.Api; |
|
37 |
import eu.dnetlib.enabling.datasources.common.BrowseTerm; |
|
38 |
import eu.dnetlib.enabling.datasources.common.Datasource; |
|
39 |
import eu.dnetlib.enabling.datasources.common.DsmException; |
|
40 |
import eu.dnetlib.enabling.datasources.common.LocalDatasourceManager; |
|
41 |
import eu.dnetlib.enabling.datasources.common.SearchApisEntry; |
|
42 |
import eu.dnetlib.enabling.datasources.common.SimpleDatasource; |
|
43 | 43 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpDocumentNotFoundException; |
44 | 44 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; |
45 | 45 |
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService; |
... | ... | |
54 | 54 |
@Controller |
55 | 55 |
public class RepoInternalController { |
56 | 56 |
|
57 |
@Autowired |
|
58 |
private LocalDatasourceManager<Datasource<?, ?>, Api<?>> dsManager; |
|
59 |
|
|
57 | 60 |
@Resource |
58 | 61 |
private UniqueServiceLocator serviceLocator; |
59 | 62 |
|
... | ... | |
69 | 72 |
private static final Log log = LogFactory.getLog(RepoInternalController.class); |
70 | 73 |
|
71 | 74 |
@RequestMapping(value = "/ui/browseRepoField.do") |
72 |
public @ResponseBody List<BrowseTerm> browseRepoField(@RequestParam(value = "field", required = true) final String field) throws Exception { |
|
73 |
return serviceLocator.getService(DatasourceManagerService.class).browseField(field);
|
|
75 |
public @ResponseBody List<? extends BrowseTerm> browseRepoField(@RequestParam(value = "field", required = true) final String field) throws Exception {
|
|
76 |
return dsManager.browseField(field);
|
|
74 | 77 |
} |
75 | 78 |
|
76 | 79 |
@Cacheable(cacheNames = "repoUIJsonCache", key = "#param, #value", condition = "#refresh == false") |
77 | 80 |
@RequestMapping(value = "/ui/listApis.do") |
78 |
public @ResponseBody List<SearchInterfacesEntry> listApis(
|
|
81 |
public @ResponseBody List<? extends SearchApisEntry> listApis(
|
|
79 | 82 |
@RequestParam(value = "param", required = true) final String param, |
80 | 83 |
@RequestParam(value = "value", required = true) final String value, |
81 | 84 |
@RequestParam(value = "refresh", required = false) final String refresh) throws Exception { |
82 | 85 |
|
83 |
return serviceLocator.getService(DatasourceManagerService.class).searchInterface(param, value);
|
|
86 |
return dsManager.searchApis(param, value);
|
|
84 | 87 |
} |
85 | 88 |
|
86 |
@RequestMapping(value = "/ui/listRepositories.map") |
|
87 |
public @ResponseBody List<RepositoryMapEntry> listRepositories_asMap() throws Exception { |
|
88 |
return serviceLocator.getService(DatasourceManagerService.class).getRepositoryMap(); |
|
89 |
} |
|
90 |
|
|
91 | 89 |
@RequestMapping(value = "/ui/listRepositories.json") |
92 |
public @ResponseBody List<SimpleDatasourceDesc> listRepositories(@RequestParam(value = "type", required = true) final String type) throws Exception {
|
|
93 |
return serviceLocator.getService(DatasourceManagerService.class).simpleListDatasourcesByType(type);
|
|
90 |
public @ResponseBody List<SimpleDatasource> listRepositories(@RequestParam(value = "type", required = true) final String type) throws Exception { |
|
91 |
return dsManager.searchDatasourcesByType(type);
|
|
94 | 92 |
} |
95 | 93 |
|
96 | 94 |
@CacheEvict("repoUIJsonCache") |
... | ... | |
99 | 97 |
@RequestParam(value = "b", required = true) final boolean b) throws Exception { |
100 | 98 |
|
101 | 99 |
final String query = "count(/*[.//RESOURCE_TYPE/@value='MetaWorkflowDSResourceType' and .//DATAPROVIDER/@id='" + id + "'])"; |
102 |
if (!b && (Integer.parseInt(serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(query)) > 0)) { throw new Exception("Repo " + id
|
|
100 |
if (!b && Integer.parseInt(serviceLocator.getService(ISLookUpService.class).getResourceProfileByQuery(query)) > 0) { throw new Exception("Repo " + id
|
|
103 | 101 |
+ " can be invalidated: it is related to some metawfs"); } |
104 | 102 |
|
105 | 103 |
final String newId = b ? serviceLocator.getService(ISRegistryService.class).validateProfile(id) |
... | ... | |
150 | 148 |
return repoUIUtils.getApi(repoId, ifaceId); |
151 | 149 |
} |
152 | 150 |
|
153 |
@SuppressWarnings("unchecked") |
|
154 | 151 |
@RequestMapping("/ui/repoApi.update") |
155 | 152 |
public @ResponseBody boolean updateRepoApi( |
156 | 153 |
@RequestParam(value = "id", required = true) final String repoId, |
... | ... | |
158 | 155 |
@RequestParam(value = "accessParams", required = false) final String accessParamsJson, |
159 | 156 |
@RequestParam(value = "mdIdPath", required = false) final String mdIdPath) throws Exception { |
160 | 157 |
|
161 |
final DatasourceManagerService dsManager = serviceLocator.getService(DatasourceManagerService.class); |
|
162 |
|
|
163 | 158 |
if (!StringUtils.isEmpty(accessParamsJson)) { |
164 |
dsManager.bulkUpdateApiAccessParams(repoId, ifaceId, new Gson().fromJson(accessParamsJson, Map.class)); |
|
159 |
final Map<String, String> params = new Gson().fromJson(accessParamsJson, new TypeToken<Map<String, String>>() {}.getType()); |
|
160 |
final String baseUrl = params.remove("baseUrl"); |
|
161 |
dsManager.updateApiDetails(repoId, ifaceId, mdIdPath, baseUrl, params); |
|
165 | 162 |
} |
166 |
if (mdIdPath != null) { |
|
167 |
dsManager.updateExtraField(repoId, ifaceId, "metadata_identifier_path", mdIdPath, true); |
|
168 |
} |
|
169 | 163 |
|
170 | 164 |
return true; |
171 | 165 |
} |
... | ... | |
174 | 168 |
public @ResponseBody boolean updateRepoApi( |
175 | 169 |
@RequestParam(value = "repo", required = true) final String repoId, |
176 | 170 |
@RequestParam(value = "iface", required = true) final String ifaceId) throws Exception { |
177 |
return serviceLocator.getService(DatasourceManagerService.class).deleteInterface(repoId, ifaceId); |
|
171 |
dsManager.deleteApi(repoId, ifaceId); |
|
172 |
return true; |
|
178 | 173 |
} |
179 | 174 |
|
180 | 175 |
@CacheEvict("repoUIJsonCache") |
... | ... | |
185 | 180 |
|
186 | 181 |
log.debug("SET COMPLIANCE TO " + compliance); |
187 | 182 |
|
188 |
serviceLocator.getService(DatasourceManagerService.class).overrideCompliance(repoId, ifaceId, compliance);
|
|
183 |
dsManager.updateCompliance(repoId, ifaceId, compliance, true);
|
|
189 | 184 |
|
190 | 185 |
return true; |
191 | 186 |
} |
... | ... | |
197 | 192 |
|
198 | 193 |
log.debug("RESET COMPLIANCE"); |
199 | 194 |
|
200 |
serviceLocator.getService(DatasourceManagerService.class).overrideCompliance(repoId, ifaceId, null);
|
|
195 |
dsManager.updateCompliance(repoId, ifaceId, null, true);
|
|
201 | 196 |
|
202 | 197 |
return true; |
203 | 198 |
} |
... | ... | |
207 | 202 |
|
208 | 203 |
@RequestMapping("/ui/repoApi.new") |
209 | 204 |
public @ResponseBody boolean addRepoApi(@RequestParam(value = "repoId", required = true) final String repoId, |
210 |
@RequestParam(value = "iface", required = true) final String ifaceJson) throws DatasourceManagerServiceException {
|
|
211 |
final IfaceDesc iface = new Gson().fromJson(ifaceJson, IfaceDesc.class);
|
|
205 |
@RequestParam(value = "iface", required = true) final String ifaceJson) throws DsmException {
|
|
206 |
final Api<?> iface = new Gson().fromJson(ifaceJson, Api.class);
|
|
212 | 207 |
|
213 |
log.info("Adding interface " + iface.getId() + " to repository " + repoId);
|
|
208 |
iface.setDatasource(repoId);
|
|
214 | 209 |
|
215 |
final DatasourceManagerService dsManager = serviceLocator.getService(DatasourceManagerService.class); |
|
216 |
return dsManager.addInterface(repoId, iface); |
|
210 |
log.info("Adding api " + iface.getId() + " to repository " + repoId); |
|
211 |
|
|
212 |
dsManager.addApi(iface); |
|
213 |
|
|
214 |
return true; |
|
217 | 215 |
} |
218 | 216 |
|
219 | 217 |
@RequestMapping("/ui/repo.new") |
220 |
public @ResponseBody boolean addRepoApi(@RequestParam(value = "repo", required = true) final String repoJson) throws DatasourceManagerServiceException { |
|
221 |
final DatasourceDesc ds = new Gson().fromJson(repoJson, DatasourceDesc.class); |
|
222 |
ds.setDateOfCollection(new Date()); |
|
218 |
public @ResponseBody boolean addRepoApi(@RequestParam(value = "repo", required = true) final String repoJson) throws DsmException { |
|
219 |
final Datasource<?, ?> ds = new Gson().fromJson(repoJson, Datasource.class); |
|
220 |
final Date now = new Date(); |
|
221 |
ds.setDateofcollection(new java.sql.Date(now.getTime())); |
|
223 | 222 |
|
224 |
if (StringUtils.isBlank(ds.getEnglishName())) {
|
|
225 |
ds.setEnglishName(ds.getOfficialName());
|
|
223 |
if (StringUtils.isBlank(ds.getEnglishname())) {
|
|
224 |
ds.setEnglishname(ds.getOfficialname());
|
|
226 | 225 |
} |
227 | 226 |
|
228 |
log.info("Adding datasource " + ds.getId() + " - name " + ds.getOfficialName());
|
|
227 |
log.info("Adding datasource " + ds.getId() + " - name " + ds.getOfficialname());
|
|
229 | 228 |
|
230 |
final DatasourceManagerService dsManager = serviceLocator.getService(DatasourceManagerService.class);
|
|
229 |
dsManager.saveDs(ds);
|
|
231 | 230 |
|
232 |
return dsManager.addDatasource(ds);
|
|
231 |
return true;
|
|
233 | 232 |
} |
234 | 233 |
|
235 | 234 |
@RequestMapping("/ui/listValidValuesForParam.do") |
Also available in: Unified diff
added some methods for repo UI