1
|
package eu.dnetlib.enabling.datasources;
|
2
|
|
3
|
import java.io.StringReader;
|
4
|
import java.util.*;
|
5
|
import java.util.Map.Entry;
|
6
|
import java.util.stream.Collectors;
|
7
|
|
8
|
import com.google.common.base.Function;
|
9
|
import com.google.common.collect.Iterables;
|
10
|
import com.google.common.collect.Lists;
|
11
|
import eu.dnetlib.rmi.datasource.*;
|
12
|
import org.apache.commons.lang3.StringEscapeUtils;
|
13
|
import org.apache.commons.lang3.StringUtils;
|
14
|
import org.apache.commons.lang3.math.NumberUtils;
|
15
|
import org.apache.commons.logging.Log;
|
16
|
import org.apache.commons.logging.LogFactory;
|
17
|
import org.dom4j.Document;
|
18
|
import org.dom4j.Node;
|
19
|
import org.dom4j.io.SAXReader;
|
20
|
import org.springframework.beans.factory.annotation.Required;
|
21
|
|
22
|
/**
|
23
|
* Created by sandro on 7/11/16.
|
24
|
*/
|
25
|
public class DnetPostgresDasourceManagerCoreImpl implements DnetDatasourceManagerCore {
|
26
|
|
27
|
private static final Log log = LogFactory.getLog(DnetPostgresDasourceManagerCoreImpl.class);
|
28
|
private DatasourceManagerClients datasourceManagerClients;
|
29
|
private List<DbBrowsableField> browsableFields;
|
30
|
|
31
|
@Override
|
32
|
public boolean addDatasource(final DatasourceDesc ds) throws DatasourceManagerServiceException {
|
33
|
if (StringUtils.isBlank(ds.getAggregator())) {
|
34
|
ds.setAggregator("OPENAIRE");
|
35
|
}
|
36
|
|
37
|
final Map<String, Object> params = DatasourceFunctions.asMapOfSqlValues(ds);
|
38
|
|
39
|
if (ds.getOrganization() != null && !ds.getOrganization().trim().isEmpty()) {
|
40
|
params.put("hasOrganization", 1);
|
41
|
}
|
42
|
return datasourceManagerClients.updateSQL(ds.getId(), "addDatasource.sql.st", params, false, true);
|
43
|
}
|
44
|
|
45
|
@Override
|
46
|
public boolean deleteDatasource(final String dsId) throws DatasourceManagerServiceException {
|
47
|
final Map<String, Object> params = new HashMap<>();
|
48
|
|
49
|
params.put("dsId", DatasourceFunctions.asSqlValue(dsId));
|
50
|
|
51
|
return datasourceManagerClients.updateSQL(dsId, "deleteDatasource.sql.st", params, true, true);
|
52
|
}
|
53
|
|
54
|
@Override
|
55
|
public DatasourceDesc getDatasource(final String dsId) throws DatasourceManagerServiceException {
|
56
|
final List<DatasourceDesc> list = datasourceManagerClients.getDatasourcesByCondition("ds.id = " + DatasourceFunctions.asSqlValue(dsId));
|
57
|
if (list.size() != 1) { throw new DatasourceManagerServiceException("Datasource not found, id=" + dsId); }
|
58
|
|
59
|
return list.get(0);
|
60
|
}
|
61
|
|
62
|
@Override
|
63
|
public List<DatasourceDesc> listAllDatasources() throws DatasourceManagerServiceException {
|
64
|
return datasourceManagerClients.getDatasourcesByCondition(null);
|
65
|
}
|
66
|
|
67
|
@Override
|
68
|
public List<DatasourceDesc> listDatasourcesUsingFilter(final String compliance,
|
69
|
final String contentDescription,
|
70
|
final String iisProcessingWorkflow,
|
71
|
final String collectedFrom) throws DatasourceManagerServiceException {
|
72
|
|
73
|
String cond = "";
|
74
|
|
75
|
if (compliance != null && !compliance.isEmpty()) {
|
76
|
if (!cond.isEmpty()) {
|
77
|
cond += " and ";
|
78
|
}
|
79
|
cond += "ag.compatibilityclass=" + DatasourceFunctions.asSqlValue(compliance);
|
80
|
}
|
81
|
|
82
|
if (contentDescription != null && !contentDescription.isEmpty()) {
|
83
|
if (!cond.isEmpty()) {
|
84
|
cond += " and ";
|
85
|
}
|
86
|
cond += "ag.contentdescriptionclass=" + DatasourceFunctions.asSqlValue(contentDescription);
|
87
|
}
|
88
|
|
89
|
if (iisProcessingWorkflow != null && !iisProcessingWorkflow.isEmpty()) {
|
90
|
if (!cond.isEmpty()) {
|
91
|
cond += " and ";
|
92
|
}
|
93
|
cond += "ag.accessinfopackage LIKE '%###" + DatasourceParams.iis_processing_workflow + "###" + iisProcessingWorkflow + "###%'";
|
94
|
}
|
95
|
|
96
|
if (collectedFrom != null && !collectedFrom.isEmpty()) {
|
97
|
if (!cond.isEmpty()) {
|
98
|
cond += " and ";
|
99
|
}
|
100
|
cond += "ds.collectedfrom=" + DatasourceFunctions.asSqlValue(collectedFrom);
|
101
|
}
|
102
|
|
103
|
return datasourceManagerClients.getDatasourcesByCondition(cond);
|
104
|
}
|
105
|
|
106
|
@Override
|
107
|
public boolean updateActivationStatus(final String dsId, final String ifaceId, final boolean active) throws DatasourceManagerServiceException {
|
108
|
final Map<String, Object> params = new HashMap<>();
|
109
|
|
110
|
params.put("active", DatasourceFunctions.asSqlValue(active));
|
111
|
params.put("ifaceId", DatasourceFunctions.asSqlValue(ifaceId));
|
112
|
String correctDSId = dsId;
|
113
|
|
114
|
if (StringUtils.endsWith(dsId, "_UmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZXMvUmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZVR5cGU=")) {
|
115
|
correctDSId = datasourceManagerClients.findDatasourceId(dsId);
|
116
|
}
|
117
|
params.put("dsId", DatasourceFunctions.asSqlValue(correctDSId));
|
118
|
|
119
|
return datasourceManagerClients.updateSQL(correctDSId, "updateActivationStatus.sql.st", params, false, true);
|
120
|
}
|
121
|
|
122
|
@Override
|
123
|
public boolean updateLevelOfCompliance(final String dsId, final String ifaceId, final String level) throws DatasourceManagerServiceException {
|
124
|
final Map<String, Object> params = new HashMap<>();
|
125
|
|
126
|
params.put("level", DatasourceFunctions.asSqlValue(level));
|
127
|
params.put("ifaceId", DatasourceFunctions.asSqlValue(ifaceId));
|
128
|
params.put("dsId", DatasourceFunctions.asSqlValue(dsId));
|
129
|
|
130
|
return datasourceManagerClients.updateSQL(dsId, "updateLevelOfCompliance.sql.st", params, false, true);
|
131
|
}
|
132
|
|
133
|
@Override
|
134
|
public boolean updateBaseUrl(final String dsId, final String ifaceId, final String baseUrl) throws DatasourceManagerServiceException {
|
135
|
return updateAccessParam(dsId, ifaceId, DatasourceParams.baseUrl.toString(), baseUrl, true);
|
136
|
}
|
137
|
|
138
|
@Override
|
139
|
public boolean updateContentDescription(final String dsId, final String ifaceId, final String desc) throws DatasourceManagerServiceException {
|
140
|
final Map<String, Object> params = new HashMap<>();
|
141
|
params.put("desc", DatasourceFunctions.asSqlValue(desc));
|
142
|
params.put("ifaceId", DatasourceFunctions.asSqlValue(ifaceId));
|
143
|
params.put("dsId", DatasourceFunctions.asSqlValue(dsId));
|
144
|
|
145
|
return datasourceManagerClients.updateSQL(dsId, "updateContentDescription.sql.st", params, false, true);
|
146
|
}
|
147
|
|
148
|
@Override
|
149
|
public boolean setIisProcessingWorkflow(final String dsId, final String ifaceId, final String wf) throws DatasourceManagerServiceException {
|
150
|
return updateExtraField(dsId, ifaceId, DatasourceParams.iis_processing_workflow.toString(), wf, false);
|
151
|
}
|
152
|
|
153
|
@Override
|
154
|
public boolean addInterface(final String dsId, final IfaceDesc iface) throws DatasourceManagerServiceException {
|
155
|
final Map<String, Object> params = new HashMap<>();
|
156
|
|
157
|
params.put("datasource", DatasourceFunctions.asSqlValue(dsId));
|
158
|
params.put("id", DatasourceFunctions.asSqlValue(iface.getId()));
|
159
|
params.put("typology", DatasourceFunctions.asSqlValue(iface.getTypology()));
|
160
|
params.put("protocol", DatasourceFunctions.asSqlValue(iface.getAccessProtocol()));
|
161
|
params.put("baseUrl", DatasourceFunctions.asSqlValue(iface.getBaseUrl()));
|
162
|
params.put("description", DatasourceFunctions.asSqlValue(iface.getContentDescription()));
|
163
|
params.put("compliance", DatasourceFunctions.asSqlValue(iface.getCompliance()));
|
164
|
|
165
|
final Map<String, String> accessParams = new HashMap<>();
|
166
|
if (iface.getAccessParams() != null) {
|
167
|
for (Entry<String, String> e : iface.getAccessParams().entrySet()) {
|
168
|
accessParams.put(DatasourceFunctions.asSqlValue(e.getKey()), DatasourceFunctions.asSqlValue(e.getValue()));
|
169
|
}
|
170
|
}
|
171
|
params.put("accessParams", accessParams);
|
172
|
|
173
|
final Map<String, String> extraFields = new HashMap<String, String>();
|
174
|
if (iface.getExtraFields() != null) {
|
175
|
for (Entry<String, String> e : iface.getExtraFields().entrySet()) {
|
176
|
extraFields.put(DatasourceFunctions.asSqlValue(e.getKey()), DatasourceFunctions.asSqlValue(e.getValue()));
|
177
|
}
|
178
|
}
|
179
|
params.put("extraFields", extraFields);
|
180
|
|
181
|
return datasourceManagerClients.updateSQL(dsId, "insertInterface.sql.st", params, false, true);
|
182
|
}
|
183
|
|
184
|
@Override
|
185
|
public boolean deleteInterface(final String dsId, final String ifcId) throws DatasourceManagerServiceException {
|
186
|
final Map<String, Object> params = new HashMap<>();
|
187
|
|
188
|
params.put("datasource", DatasourceFunctions.asSqlValue(dsId));
|
189
|
params.put("id", DatasourceFunctions.asSqlValue(ifcId));
|
190
|
|
191
|
return datasourceManagerClients.updateSQL(dsId, "deleteInterface.sql.st", params, false, true);
|
192
|
}
|
193
|
|
194
|
@Override
|
195
|
public boolean updateExtraField(final String dsId, final String ifaceId, final String field, final String value, final boolean preserveOriginal)
|
196
|
throws DatasourceManagerServiceException {
|
197
|
return updateApiCollectionsRow(dsId, ifaceId, field, value, preserveOriginal, false);
|
198
|
}
|
199
|
|
200
|
@Override
|
201
|
public boolean updateAccessParam(final String dsId, final String ifaceId, final String field, final String value, final boolean preserveOriginal)
|
202
|
throws DatasourceManagerServiceException {
|
203
|
return updateApiCollectionsRow(dsId, ifaceId, field, value, preserveOriginal, true);
|
204
|
}
|
205
|
|
206
|
private boolean updateApiCollectionsRow(final String dsId,
|
207
|
final String ifaceId,
|
208
|
final String field,
|
209
|
final String value,
|
210
|
final boolean preserveOriginal,
|
211
|
final boolean accessParam) throws DatasourceManagerServiceException {
|
212
|
|
213
|
final Map<String, Object> params = new HashMap<>();
|
214
|
|
215
|
params.put("dsId", DatasourceFunctions.asSqlValue(dsId));
|
216
|
params.put("ifaceId", DatasourceFunctions.asSqlValue(ifaceId));
|
217
|
params.put("field", DatasourceFunctions.asSqlValue(field));
|
218
|
params.put("accessParam", accessParam);
|
219
|
|
220
|
if (value != null) {
|
221
|
params.put("value", DatasourceFunctions.asSqlValue(value));
|
222
|
}
|
223
|
|
224
|
if (datasourceManagerClients.isDefinedParam(ifaceId, field)) {
|
225
|
params.put("update", 1);
|
226
|
}
|
227
|
if (preserveOriginal) {
|
228
|
params.put("preserveOriginal", 1);
|
229
|
}
|
230
|
|
231
|
return datasourceManagerClients.updateSQL(dsId, "updateApiCollectionsRow.sql.st", params, false, true);
|
232
|
}
|
233
|
|
234
|
@Override
|
235
|
public boolean deleteAccessParamOrExtraField(final String dsId, final String ifaceId, final String field) throws DatasourceManagerServiceException {
|
236
|
final Map<String, Object> params = new HashMap<>();
|
237
|
|
238
|
params.put("dsId", DatasourceFunctions.asSqlValue(dsId));
|
239
|
params.put("ifaceId", DatasourceFunctions.asSqlValue(ifaceId));
|
240
|
params.put("field", DatasourceFunctions.asSqlValue(field));
|
241
|
|
242
|
return datasourceManagerClients.updateSQL(dsId, "deleteApiCollectionsRow.sql.st", params, false, true);
|
243
|
}
|
244
|
|
245
|
@Override
|
246
|
public boolean updateSQL(final String dsId, final String sql, final boolean delete) throws DatasourceManagerServiceException {
|
247
|
return datasourceManagerClients.updateSQL(dsId, sql, delete, true);
|
248
|
}
|
249
|
|
250
|
@Override
|
251
|
public Date findNextScheduledExecution(final String dsId, final String ifaceId)
|
252
|
throws DatasourceManagerServiceException {
|
253
|
return datasourceManagerClients.findNextScheduledExecution(dsId, ifaceId);
|
254
|
}
|
255
|
|
256
|
@Override
|
257
|
public boolean bulkUpdateApiExtraFields(final String repoId, final String ifaceId, final Map<String, String> fields)
|
258
|
throws DatasourceManagerServiceException {
|
259
|
return performUpdate(repoId, ifaceId, fields, false);
|
260
|
}
|
261
|
|
262
|
@Override
|
263
|
public boolean bulkUpdateApiAccessParams(final String repoId, final String ifaceId, final Map<String, String> params)
|
264
|
throws DatasourceManagerServiceException {
|
265
|
return performUpdate(repoId, ifaceId, params, true);
|
266
|
}
|
267
|
|
268
|
private boolean performUpdate(final String repoId, final String ifaceId, final Map<String, String> params, final boolean accessParam)
|
269
|
throws DatasourceManagerServiceException {
|
270
|
final String dsId = datasourceManagerClients.findDatasourceId(repoId);
|
271
|
|
272
|
if (!accessParam) {
|
273
|
deleteOldExtraFields(dsId, ifaceId);
|
274
|
}
|
275
|
|
276
|
for (Map.Entry<String, String> e : params.entrySet()) {
|
277
|
performSingleUpdate(dsId, ifaceId, e.getKey(), e.getValue(), accessParam);
|
278
|
}
|
279
|
datasourceManagerClients.regenerateProfile(dsId);
|
280
|
return true;
|
281
|
}
|
282
|
|
283
|
private boolean deleteOldExtraFields(final String dsId, final String ifaceId) throws DatasourceManagerServiceException {
|
284
|
final Map<String, Object> params = new HashMap<>();
|
285
|
|
286
|
params.put("dsId", DatasourceFunctions.asSqlValue(dsId));
|
287
|
params.put("ifaceId", DatasourceFunctions.asSqlValue(ifaceId));
|
288
|
|
289
|
return datasourceManagerClients.updateSQL(dsId, "deleteOldExtraFields.sql.st", params, false, false);
|
290
|
}
|
291
|
|
292
|
private boolean performSingleUpdate(final String dsId, final String ifaceId, final String field, final String value, final boolean accessParam)
|
293
|
throws DatasourceManagerServiceException {
|
294
|
final Map<String, Object> params = new HashMap<>();
|
295
|
|
296
|
params.put("dsId", DatasourceFunctions.asSqlValue(dsId));
|
297
|
params.put("ifaceId", DatasourceFunctions.asSqlValue(ifaceId));
|
298
|
params.put("field", DatasourceFunctions.asSqlValue(field));
|
299
|
params.put("accessParam", accessParam);
|
300
|
|
301
|
if (value != null) {
|
302
|
params.put("value", DatasourceFunctions.asSqlValue(value));
|
303
|
}
|
304
|
|
305
|
if (accessParam && datasourceManagerClients.isDefinedParam(ifaceId, field)) {
|
306
|
params.put("update", 1);
|
307
|
params.put("preserveOriginal", 1);
|
308
|
}
|
309
|
|
310
|
return datasourceManagerClients.updateSQL(dsId, "updateApiCollectionsRow.sql.st", params, false, false);
|
311
|
}
|
312
|
|
313
|
public DatasourceManagerClients getDatasourceManagerClients() {
|
314
|
return datasourceManagerClients;
|
315
|
}
|
316
|
|
317
|
@Required
|
318
|
public void setDatasourceManagerClients(final DatasourceManagerClients datasourceManagerClients) {
|
319
|
this.datasourceManagerClients = datasourceManagerClients;
|
320
|
}
|
321
|
|
322
|
@Override
|
323
|
public boolean overrideCompliance(final String repoId, final String ifaceId, final String compliance) throws DatasourceManagerServiceException {
|
324
|
|
325
|
final String dsId = datasourceManagerClients.findDatasourceId(repoId);
|
326
|
|
327
|
final Map<String, Object> params = new HashMap<>();
|
328
|
params.put("dsId", DatasourceFunctions.asSqlValue(dsId));
|
329
|
params.put("ifaceId", DatasourceFunctions.asSqlValue(ifaceId));
|
330
|
params.put("field", DatasourceFunctions.asSqlValue(DatasourceConstants.OVERRIDING_COMPLIANCE_FIELD));
|
331
|
|
332
|
if (StringUtils.isEmpty(compliance)) {
|
333
|
params.put("delete", true);
|
334
|
log.debug("Removing compliance");
|
335
|
} else {
|
336
|
params.put("value", DatasourceFunctions.asSqlValue(compliance));
|
337
|
if (datasourceManagerClients.isDefinedParam(ifaceId, DatasourceConstants.OVERRIDING_COMPLIANCE_FIELD)) {
|
338
|
params.put("update", true);
|
339
|
log.debug("Updating compliance: " + compliance);
|
340
|
} else {
|
341
|
params.put("insert", true);
|
342
|
log.debug("Adding compliance: " + compliance);
|
343
|
}
|
344
|
}
|
345
|
return datasourceManagerClients.updateSQL(dsId, "overrideCompliance.sql.st", params, false, true);
|
346
|
}
|
347
|
|
348
|
@Override
|
349
|
public List<BrowsableField> listBrowsableFields() throws DatasourceManagerServiceException {
|
350
|
|
351
|
return getBrowsableFields().stream().map(it -> new BrowsableField(it.getId(), it.getLabel())).collect(Collectors.toList());
|
352
|
}
|
353
|
|
354
|
@Override
|
355
|
public List<BrowseTerm> browseField(final String f) throws DatasourceManagerServiceException {
|
356
|
final List<BrowseTerm> list = Lists.newArrayList();
|
357
|
|
358
|
try {
|
359
|
final DbBrowsableField field = findBrowseField(f, getBrowsableFields());
|
360
|
if (field != null) {
|
361
|
final SAXReader reader = new SAXReader();
|
362
|
for (String s : datasourceManagerClients.searchSQL(field.getSql())) {
|
363
|
final Document doc = reader.read(new StringReader(s));
|
364
|
final String id = doc.valueOf("/ROW/FIELD[@name='id']");
|
365
|
final String name = doc.valueOf("/ROW/FIELD[@name='name']");
|
366
|
final int value = NumberUtils.toInt(doc.valueOf("/ROW/FIELD[@name='count']"), 0);
|
367
|
if (StringUtils.isNotEmpty(id)) {
|
368
|
list.add(new BrowseTerm(id, name, value));
|
369
|
}
|
370
|
}
|
371
|
}
|
372
|
} catch (Exception e) {
|
373
|
log.error("Error browsing field " + f, e);
|
374
|
}
|
375
|
|
376
|
return list;
|
377
|
}
|
378
|
|
379
|
@Override
|
380
|
public List<SearchInterfacesEntry> searchInterface(final String field, final String value) throws DatasourceManagerServiceException {
|
381
|
try {
|
382
|
final Map<String, Object> params = new HashMap<>();
|
383
|
params.put("value", value);
|
384
|
|
385
|
if (!field.equalsIgnoreCase("__search__")) {
|
386
|
params.put("field", field);
|
387
|
}
|
388
|
|
389
|
final DbBrowsableField f = findBrowseField(field, getBrowsableFields());
|
390
|
if (f == null || f.isText()) {
|
391
|
params.put("delimeter", "'");
|
392
|
}
|
393
|
|
394
|
final SAXReader reader = new SAXReader();
|
395
|
final Iterable<String> iter = datasourceManagerClients.searchSQL("searchRepoInterfaces.sql.st", params);
|
396
|
return Lists.newArrayList(Iterables.transform(iter, s -> {
|
397
|
final SearchInterfacesEntry iface = new SearchInterfacesEntry();
|
398
|
try {
|
399
|
final Document doc = reader.read(new StringReader(s));
|
400
|
final String country = doc.valueOf("/ROW/FIELD[@name='country']");
|
401
|
|
402
|
iface.setRepoId(doc.valueOf("/ROW/FIELD[@name='repoid']"));
|
403
|
iface.setRepoCountry(StringUtils.isEmpty(country) ? "-" : country.toUpperCase());
|
404
|
iface.setRepoName(StringEscapeUtils.unescapeXml(doc.valueOf("/ROW/FIELD[@name='reponame']")));
|
405
|
iface.setRepoPrefix(doc.valueOf("/ROW/FIELD[@name='repoprefix']"));
|
406
|
|
407
|
iface.setId(doc.valueOf("/ROW/FIELD[@name='id']"));
|
408
|
iface.setActive(Boolean.valueOf(doc.valueOf("/ROW/FIELD[@name='active']")));
|
409
|
iface.setProtocol(doc.valueOf("/ROW/FIELD[@name='protocol']"));
|
410
|
iface.setCompliance(doc.valueOf("/ROW/FIELD[@name='compliance']"));
|
411
|
iface.setAggrDate(doc.valueOf("/ROW/FIELD[@name='aggrdate']"));
|
412
|
iface.setAggrTotal(NumberUtils.toInt(doc.valueOf("/ROW/FIELD[@name='aggrtotal']"), 0));
|
413
|
} catch (Exception e) {
|
414
|
log.error(e);
|
415
|
}
|
416
|
return iface;
|
417
|
}));
|
418
|
} catch (Exception e) {
|
419
|
log.error("Error searching field " + field + " - value: " + value, e);
|
420
|
}
|
421
|
return Lists.newArrayList();
|
422
|
}
|
423
|
|
424
|
private DbBrowsableField findBrowseField(final String id, final List<DbBrowsableField> browsableFields) {
|
425
|
for (DbBrowsableField f : browsableFields) {
|
426
|
if (f.getId().equals(id)) { return f; }
|
427
|
}
|
428
|
return null;
|
429
|
}
|
430
|
|
431
|
@Override
|
432
|
public List<RepositoryMapEntry> getRepositoryMap() throws DatasourceManagerServiceException {
|
433
|
final SAXReader reader = new SAXReader();
|
434
|
|
435
|
try {
|
436
|
final Iterable<String> iter = datasourceManagerClients.searchSQL("findReposMap.sql.st", null);
|
437
|
return Lists.newArrayList(Iterables.transform(iter, new Function<String, RepositoryMapEntry>() {
|
438
|
|
439
|
@Override
|
440
|
public RepositoryMapEntry apply(final String s) {
|
441
|
final RepositoryMapEntry r = new RepositoryMapEntry();
|
442
|
try {
|
443
|
final Document doc = reader.read(new StringReader(s));
|
444
|
r.setId(doc.valueOf("/ROW/FIELD[@name='id']"));
|
445
|
r.setName(StringEscapeUtils.unescapeXml(doc.valueOf("/ROW/FIELD[@name='name']")));
|
446
|
r.setLat(NumberUtils.toFloat(doc.valueOf("/ROW/FIELD[@name='lat']"), 0));
|
447
|
r.setLng(NumberUtils.toFloat(doc.valueOf("/ROW/FIELD[@name='lng']"), 0));
|
448
|
} catch (Exception e) {
|
449
|
log.error(e);
|
450
|
}
|
451
|
return r;
|
452
|
}
|
453
|
}));
|
454
|
} catch (Exception e) {
|
455
|
log.error("Error obtaing repo map entries", e);
|
456
|
}
|
457
|
return Lists.newArrayList();
|
458
|
}
|
459
|
|
460
|
@Override
|
461
|
public List<SimpleDatasourceDesc> simpleListDatasourcesByType(final String type) throws DatasourceManagerServiceException {
|
462
|
final Map<String, Object> params = new HashMap<>();
|
463
|
params.put("type", type);
|
464
|
final List<SimpleDatasourceDesc> list = Lists.newArrayList();
|
465
|
try {
|
466
|
final SAXReader reader = new SAXReader();
|
467
|
for (String s : datasourceManagerClients.searchSQL("simpleFindRepos.sql.st", params)) {
|
468
|
final Document doc = reader.read(new StringReader(s));
|
469
|
final SimpleDatasourceDesc r = new SimpleDatasourceDesc();
|
470
|
r.setId(doc.valueOf("/ROW/FIELD[@name='id']"));
|
471
|
r.setOrigId(doc.valueOf("/ROW/FIELD[@name='id']"));
|
472
|
r.setName(StringEscapeUtils.unescapeXml(doc.valueOf("/ROW/FIELD[@name='name']")));
|
473
|
for (Object o : doc.selectNodes("/ROW/FIELD[@name='apis']/ITEM")) {
|
474
|
r.getApis().add(((Node) o).getText());
|
475
|
}
|
476
|
r.setValid(true); // TODO
|
477
|
r.setTypology(type);
|
478
|
list.add(r);
|
479
|
}
|
480
|
Collections.sort(list);
|
481
|
} catch (Exception e) {
|
482
|
log.error("Error listing repos", e);
|
483
|
}
|
484
|
return list;
|
485
|
}
|
486
|
|
487
|
public List<DbBrowsableField> getBrowsableFields() {
|
488
|
return browsableFields;
|
489
|
}
|
490
|
|
491
|
@Required
|
492
|
public void setBrowsableFields(final List<DbBrowsableField> browsableFields) {
|
493
|
this.browsableFields = browsableFields;
|
494
|
}
|
495
|
}
|