Revision 49662
Added by Michele Artini over 6 years ago
LocalOpenaireDatasourceManager.java | ||
---|---|---|
23 | 23 |
import com.google.common.collect.Lists; |
24 | 24 |
import com.google.common.collect.Maps; |
25 | 25 |
|
26 |
import eu.dnetlib.enabling.datasources.common.BrowsableField;
|
|
26 |
import eu.dnetlib.enabling.datasources.common.Api;
|
|
27 | 27 |
import eu.dnetlib.enabling.datasources.common.BrowseTerm; |
28 |
import eu.dnetlib.enabling.datasources.common.DatasourceConstants; |
|
29 |
import eu.dnetlib.enabling.datasources.common.DatasourceDesc; |
|
28 |
import eu.dnetlib.enabling.datasources.common.Datasource; |
|
30 | 29 |
import eu.dnetlib.enabling.datasources.common.DatasourceManager; |
31 |
import eu.dnetlib.enabling.datasources.common.DatasourceManagerServiceException; |
|
32 |
import eu.dnetlib.enabling.datasources.common.IfaceDesc; |
|
33 |
import eu.dnetlib.enabling.datasources.common.RepositoryMapEntry; |
|
34 |
import eu.dnetlib.enabling.datasources.common.SearchInterfacesEntry; |
|
35 |
import eu.dnetlib.enabling.datasources.common.SimpleDatasourceDesc; |
|
30 |
import eu.dnetlib.enabling.datasources.common.DatasourceManagerException; |
|
36 | 31 |
|
37 |
public class LocalOpenaireDatasourceManager implements DatasourceManager { |
|
32 |
public class LocalOpenaireDatasourceManager implements DatasourceManager<Datasource<?, ?>, Api> {
|
|
38 | 33 |
|
39 | 34 |
private DatasourceManagerClients datasourceManagerClients; |
40 | 35 |
|
... | ... | |
43 | 38 |
private static final Log log = LogFactory.getLog(LocalOpenaireDatasourceManager.class); |
44 | 39 |
|
45 | 40 |
@Override |
46 |
public boolean addDatasource(final DatasourceDesc ds) throws DatasourceManagerServiceException {
|
|
41 |
public void saveDs(final Datasource<?, ?> ds) throws DatasourceManagerException {
|
|
47 | 42 |
if (StringUtils.isBlank(ds.getAggregator())) { |
48 | 43 |
ds.setAggregator("OPENAIRE"); |
49 | 44 |
} |
50 | 45 |
|
51 | 46 |
final Map<String, Object> params = DatasourceFunctions.asMapOfSqlValues(ds); |
52 | 47 |
|
53 |
if ((ds.getOrganization() != null) && !ds.getOrganization().trim().isEmpty()) {
|
|
48 |
if ((ds.getOrganizations() != null) && !ds.getOrganizations().isEmpty()) {
|
|
54 | 49 |
params.put("hasOrganization", 1); |
55 | 50 |
} |
56 |
return datasourceManagerClients.updateSQL(ds.getId(), "addDatasource.sql.st", params, false, true); |
|
51 |
|
|
52 |
datasourceManagerClients.updateSQL(ds.getId(), "addDatasource.sql.st", params, false, true); |
|
57 | 53 |
} |
58 | 54 |
|
59 | 55 |
@Override |
60 |
public boolean deleteDatasource(final String dsId) throws DatasourceManagerServiceException {
|
|
56 |
public void deleteDs(final String dsId) throws DatasourceManagerException {
|
|
61 | 57 |
final Map<String, Object> params = Maps.newHashMap(); |
62 | 58 |
|
63 | 59 |
params.put("dsId", DatasourceFunctions.asSqlValue(dsId)); |
64 | 60 |
|
65 |
return datasourceManagerClients.updateSQL(dsId, "deleteDatasource.sql.st", params, true, true);
|
|
61 |
datasourceManagerClients.updateSQL(dsId, "deleteDatasource.sql.st", params, true, true); |
|
66 | 62 |
} |
67 | 63 |
|
68 | 64 |
@Override |
69 |
public DatasourceDesc getDatasource(final String dsId) throws DatasourceManagerServiceException {
|
|
70 |
final List<DatasourceDesc> list = datasourceManagerClients.getDatasourcesByCondition("ds.id = " + DatasourceFunctions.asSqlValue(dsId));
|
|
71 |
if (list.size() != 1) { throw new DatasourceManagerServiceException("Datasource not found, id=" + dsId); }
|
|
65 |
public Datasource<?, ?> getDs(final String dsId) throws DatasourceManagerException {
|
|
66 |
final List<Datasource<?, ?>> list = datasourceManagerClients.getDatasourcesByCondition("ds.id = " + DatasourceFunctions.asSqlValue(dsId));
|
|
67 |
if (list.size() != 1) { throw new DatasourceManagerException("Datasource not found, id=" + dsId); } |
|
72 | 68 |
|
73 | 69 |
return list.get(0); |
74 | 70 |
} |
75 | 71 |
|
76 | 72 |
@Override |
77 |
public boolean updateActivationStatus(final String dsId, final String ifaceId, final boolean active) throws DatasourceManagerServiceException {
|
|
73 |
public void updateActivationStatus(final String dsId, final String ifaceId, final boolean active) throws DatasourceManagerException {
|
|
78 | 74 |
final Map<String, Object> params = Maps.newHashMap(); |
79 | 75 |
|
80 | 76 |
params.put("active", DatasourceFunctions.asSqlValue(active)); |
81 | 77 |
params.put("ifaceId", DatasourceFunctions.asSqlValue(ifaceId)); |
82 | 78 |
params.put("dsId", DatasourceFunctions.asSqlValue(dsId)); |
83 | 79 |
|
84 |
return datasourceManagerClients.updateSQL(dsId, "updateActivationStatus.sql.st", params, false, true);
|
|
80 |
datasourceManagerClients.updateSQL(dsId, "updateActivationStatus.sql.st", params, false, true); |
|
85 | 81 |
} |
86 | 82 |
|
87 | 83 |
@Override |
88 |
public boolean updateLevelOfCompliance(final String dsId, final String ifaceId, final String level) throws DatasourceManagerServiceException {
|
|
84 |
public void updateCompliance(final String dsId, final String ifaceId, final String level) throws DatasourceManagerException {
|
|
89 | 85 |
final Map<String, Object> params = Maps.newHashMap(); |
90 | 86 |
|
91 | 87 |
params.put("level", DatasourceFunctions.asSqlValue(level)); |
92 | 88 |
params.put("ifaceId", DatasourceFunctions.asSqlValue(ifaceId)); |
93 | 89 |
params.put("dsId", DatasourceFunctions.asSqlValue(dsId)); |
94 | 90 |
|
95 |
return datasourceManagerClients.updateSQL(dsId, "updateLevelOfCompliance.sql.st", params, false, true);
|
|
91 |
datasourceManagerClients.updateSQL(dsId, "updateLevelOfCompliance.sql.st", params, false, true); |
|
96 | 92 |
} |
97 | 93 |
|
98 | 94 |
@Override |
99 |
public boolean updateBaseUrl(final String dsId, final String ifaceId, final String baseUrl) throws DatasourceManagerServiceException {
|
|
100 |
return updateAccessParam(dsId, ifaceId, DatasourceParams.baseUrl.toString(), baseUrl);
|
|
95 |
public void updateBaseUrl(final String dsId, final String ifaceId, final String baseUrl) throws DatasourceManagerException {
|
|
96 |
updateAccessParam(dsId, ifaceId, DatasourceParams.baseUrl.toString(), baseUrl); |
|
101 | 97 |
} |
102 | 98 |
|
103 | 99 |
@Override |
104 |
public boolean updateContentDescription(final String dsId, final String ifaceId, final String desc) throws DatasourceManagerServiceException {
|
|
100 |
public void addApi(final Api iface) throws DatasourceManagerException {
|
|
105 | 101 |
final Map<String, Object> params = Maps.newHashMap(); |
106 |
params.put("desc", DatasourceFunctions.asSqlValue(desc)); |
|
107 |
params.put("ifaceId", DatasourceFunctions.asSqlValue(ifaceId)); |
|
108 |
params.put("dsId", DatasourceFunctions.asSqlValue(dsId)); |
|
109 | 102 |
|
110 |
return datasourceManagerClients.updateSQL(dsId, "updateContentDescription.sql.st", params, false, true); |
|
111 |
} |
|
112 |
|
|
113 |
@Override |
|
114 |
public boolean addInterface(final String dsId, final IfaceDesc iface) throws DatasourceManagerServiceException { |
|
115 |
final Map<String, Object> params = Maps.newHashMap(); |
|
116 |
|
|
117 |
params.put("datasource", DatasourceFunctions.asSqlValue(dsId)); |
|
103 |
params.put("datasource", DatasourceFunctions.asSqlValue(iface.getDatasource())); |
|
118 | 104 |
params.put("id", DatasourceFunctions.asSqlValue(iface.getId())); |
119 | 105 |
params.put("typology", DatasourceFunctions.asSqlValue(iface.getTypology())); |
120 | 106 |
params.put("protocol", DatasourceFunctions.asSqlValue(iface.getAccessProtocol())); |
... | ... | |
138 | 124 |
} |
139 | 125 |
params.put("extraFields", extraFields); |
140 | 126 |
|
141 |
return datasourceManagerClients.updateSQL(dsId, "insertInterface.sql.st", params, false, true);
|
|
127 |
datasourceManagerClients.updateSQL(dsId, "insertInterface.sql.st", params, false, true); |
|
142 | 128 |
} |
143 | 129 |
|
144 | 130 |
@Override |
145 |
public boolean deleteInterface(final String dsId, final String ifcId) throws DatasourceManagerServiceException {
|
|
131 |
public void deleteApi(String dsId, final String ifcId) throws DatasourceManagerException {
|
|
146 | 132 |
final Map<String, Object> params = Maps.newHashMap(); |
147 | 133 |
|
148 | 134 |
params.put("datasource", DatasourceFunctions.asSqlValue(dsId)); |
149 | 135 |
params.put("id", DatasourceFunctions.asSqlValue(ifcId)); |
150 | 136 |
|
151 |
return datasourceManagerClients.updateSQL(dsId, "deleteInterface.sql.st", params, false, true);
|
|
137 |
datasourceManagerClients.updateSQL(dsId, "deleteInterface.sql.st", params, false, true); |
|
152 | 138 |
} |
153 | 139 |
|
154 | 140 |
@Override |
155 |
public boolean updateAccessParam(final String dsId, final String ifaceId, final String field, final String value) throws DatasourceManagerServiceException {
|
|
141 |
public boolean updateAccessParam(final String dsId, final String ifaceId, final String field, final String value) throws DatasourceManagerException { |
|
156 | 142 |
|
157 | 143 |
final String openaireDsId = datasourceManagerClients.findDatasourceId(dsId); |
158 | 144 |
|
... | ... | |
175 | 161 |
} |
176 | 162 |
|
177 | 163 |
@Override |
178 |
public boolean deleteAccessParam(final String dsId, final String ifaceId, final String field) throws DatasourceManagerServiceException {
|
|
164 |
public boolean deleteAccessParam(final String dsId, final String ifaceId, final String field) throws DatasourceManagerException { |
|
179 | 165 |
final Map<String, Object> params = Maps.newHashMap(); |
180 | 166 |
|
181 | 167 |
params.put("dsId", DatasourceFunctions.asSqlValue(dsId)); |
... | ... | |
186 | 172 |
} |
187 | 173 |
|
188 | 174 |
@Override |
189 |
public boolean updateSQL(final String dsId, final String sql, final boolean delete) throws DatasourceManagerServiceException {
|
|
175 |
public boolean updateSQL(final String dsId, final String sql, final boolean delete) throws DatasourceManagerException { |
|
190 | 176 |
return datasourceManagerClients.updateSQL(dsId, sql, delete, true); |
191 | 177 |
} |
192 | 178 |
|
193 | 179 |
@Override |
194 | 180 |
public Date findNextScheduledExecution(final String dsId, final String ifaceId) |
195 |
throws DatasourceManagerServiceException {
|
|
181 |
throws DatasourceManagerException { |
|
196 | 182 |
return datasourceManagerClients.findNextScheduledExecution(dsId, ifaceId); |
197 | 183 |
} |
198 | 184 |
|
199 | 185 |
@Override |
200 | 186 |
public boolean bulkUpdateApiAccessParams(final String repoId, final String ifaceId, final Map<String, String> params) |
201 |
throws DatasourceManagerServiceException {
|
|
187 |
throws DatasourceManagerException { |
|
202 | 188 |
return performUpdate(repoId, ifaceId, params, true); |
203 | 189 |
} |
204 | 190 |
|
205 | 191 |
private boolean performUpdate(final String repoId, final String ifaceId, final Map<String, String> params, final boolean accessParam) |
206 |
throws DatasourceManagerServiceException {
|
|
192 |
throws DatasourceManagerException { |
|
207 | 193 |
final String dsId = datasourceManagerClients.findDatasourceId(repoId); |
208 | 194 |
|
209 | 195 |
if (!accessParam) { |
... | ... | |
217 | 203 |
return true; |
218 | 204 |
} |
219 | 205 |
|
220 |
private boolean deleteOldExtraFields(final String dsId, final String ifaceId) throws DatasourceManagerServiceException {
|
|
206 |
private boolean deleteOldExtraFields(final String dsId, final String ifaceId) throws DatasourceManagerException { |
|
221 | 207 |
final Map<String, Object> params = Maps.newHashMap(); |
222 | 208 |
|
223 | 209 |
params.put("dsId", DatasourceFunctions.asSqlValue(dsId)); |
... | ... | |
227 | 213 |
} |
228 | 214 |
|
229 | 215 |
private boolean performSingleUpdate(final String dsId, final String ifaceId, final String field, final String value, final boolean accessParam) |
230 |
throws DatasourceManagerServiceException {
|
|
216 |
throws DatasourceManagerException { |
|
231 | 217 |
final Map<String, Object> params = Maps.newHashMap(); |
232 | 218 |
|
233 | 219 |
params.put("dsId", DatasourceFunctions.asSqlValue(dsId)); |
... | ... | |
257 | 243 |
} |
258 | 244 |
|
259 | 245 |
@Override |
260 |
public boolean overrideCompliance(final String repoId, final String ifaceId, final String compliance) throws DatasourceManagerServiceException {
|
|
246 |
public boolean overrideCompliance(final String repoId, final String ifaceId, final String compliance) throws DatasourceManagerException { |
|
261 | 247 |
|
262 | 248 |
final String dsId = datasourceManagerClients.findDatasourceId(repoId); |
263 | 249 |
|
... | ... | |
283 | 269 |
} |
284 | 270 |
|
285 | 271 |
@Override |
286 |
public List<BrowsableField> listBrowsableFields() throws DatasourceManagerServiceException {
|
|
272 |
public List<BrowsableField> listBrowsableFields() throws DatasourceManagerException { |
|
287 | 273 |
return Lists.transform(getBrowsableFields(), new Function<DbBrowsableField, BrowsableField>() { |
288 | 274 |
|
289 | 275 |
@Override |
... | ... | |
294 | 280 |
} |
295 | 281 |
|
296 | 282 |
@Override |
297 |
public List<BrowseTerm> browseField(final String f) throws DatasourceManagerServiceException {
|
|
283 |
public List<BrowseTerm> browseField(final String f) throws DatasourceManagerException { |
|
298 | 284 |
final List<BrowseTerm> list = Lists.newArrayList(); |
299 | 285 |
|
300 | 286 |
try { |
... | ... | |
319 | 305 |
} |
320 | 306 |
|
321 | 307 |
@Override |
322 |
public List<SearchInterfacesEntry> searchInterface(final String field, final String value) throws DatasourceManagerServiceException {
|
|
308 |
public List<SearchInterfacesEntry> searchInterface(final String field, final String value) throws DatasourceManagerException { |
|
323 | 309 |
try { |
324 | 310 |
final Map<String, Object> params = Maps.newHashMap(); |
325 | 311 |
params.put("value", value); |
... | ... | |
375 | 361 |
} |
376 | 362 |
|
377 | 363 |
@Override |
378 |
public List<RepositoryMapEntry> getRepositoryMap() throws DatasourceManagerServiceException {
|
|
364 |
public List<RepositoryMapEntry> getRepositoryMap() throws DatasourceManagerException { |
|
379 | 365 |
final SAXReader reader = new SAXReader(); |
380 | 366 |
|
381 | 367 |
try { |
... | ... | |
400 | 386 |
} |
401 | 387 |
|
402 | 388 |
@Override |
403 |
public List<SimpleDatasourceDesc> simpleListDatasourcesByType(final String type) throws DatasourceManagerServiceException {
|
|
389 |
public List<SimpleDatasourceDesc> simpleListDatasourcesByType(final String type) throws DatasourceManagerException { |
|
404 | 390 |
final Map<String, Object> params = Maps.newHashMap(); |
405 | 391 |
params.put("type", type); |
406 | 392 |
final List<SimpleDatasourceDesc> list = Lists.newArrayList(); |
Also available in: Unified diff
Work in progress