Revision 50509
Added by Sandro La Bruzzo about 6 years ago
LocalOpenaireDatasourceManager.java | ||
---|---|---|
36 | 36 |
import eu.dnetlib.enabling.datasources.common.Organization; |
37 | 37 |
import eu.dnetlib.enabling.datasources.common.SearchApisEntry; |
38 | 38 |
import eu.dnetlib.enabling.datasources.common.SimpleDatasource; |
39 |
import org.springframework.transaction.annotation.Transactional; |
|
39 | 40 |
|
40 | 41 |
public class LocalOpenaireDatasourceManager implements LocalDatasourceManager<Datasource<Organization<?>, Identity>, Api<ApiParam>> { |
41 | 42 |
|
... | ... | |
68 | 69 |
private static final String REPO_PROFILEID_SUFFIX = "_UmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZXMvUmVwb3NpdG9yeVNlcnZpY2VSZXNvdXJjZVR5cGU="; |
69 | 70 |
|
70 | 71 |
@Override |
72 |
@Transactional(readOnly = true) |
|
71 | 73 |
public Set<String> listManagedDatasourceIds() throws DsmRuntimeException { |
72 | 74 |
try { |
73 | 75 |
return datasourceManagerClients.searchSQL("SELECT id FROM dsm_datasources WHERE managed = true", new HashMap<>()) |
... | ... | |
80 | 82 |
} |
81 | 83 |
|
82 | 84 |
@Override |
85 |
@Transactional(readOnly = true) |
|
83 | 86 |
public List<SimpleDatasource> searchDatasourcesByType(final String type) throws DsmException { |
87 |
|
|
84 | 88 |
return datasourceManagerClients.searchSQL(searchDsByType, ImmutableMap.of("type", type)) |
85 | 89 |
.stream() |
86 | 90 |
.map(DatasourceFunctions::mapToSimpleDs) |
... | ... | |
88 | 92 |
} |
89 | 93 |
|
90 | 94 |
@Override |
95 |
@Transactional(readOnly = true) |
|
91 | 96 |
public List<? extends SearchApisEntry> searchApis(final String field, final Object value) throws DsmException { |
92 | 97 |
try { |
93 | 98 |
final StringWriter sql = new StringWriter(); |
... | ... | |
114 | 119 |
} |
115 | 120 |
|
116 | 121 |
@Override |
122 |
@Transactional |
|
117 | 123 |
public void saveDs(final Datasource<Organization<?>, Identity> ds) throws DsmException { |
118 | 124 |
|
119 | 125 |
if (StringUtils.isBlank(ds.getAggregator())) { |
... | ... | |
135 | 141 |
} |
136 | 142 |
|
137 | 143 |
@Override |
144 |
@Transactional |
|
138 | 145 |
public void deleteDs(final String dsId) throws DsmException { |
139 | 146 |
datasourceManagerClients.updateSQL(fixDsId(dsId), deleteDs, AfterSqlUpdate.DELETE_DS_PROFILE, ImmutableMap.of("dsId", dsId)); |
140 | 147 |
} |
... | ... | |
173 | 180 |
} |
174 | 181 |
|
175 | 182 |
@Override |
183 |
@Transactional |
|
176 | 184 |
public void setActive(final String dsId, final String apiId, final boolean active) throws DsmException { |
177 | 185 |
final String id = fixDsId(dsId); |
178 | 186 |
|
... | ... | |
190 | 198 |
} |
191 | 199 |
|
192 | 200 |
@Override |
201 |
@Transactional(readOnly = true) |
|
193 | 202 |
public boolean isActive(final String dsId, final String apiId) throws DsmException { |
194 | 203 |
final String q = "SELECT * from dsm_api WHERE id = :apiId AND datasource = :dsId AND active = true"; |
195 | 204 |
return !datasourceManagerClients.searchSQL(q, ImmutableMap.of("dsId", fixDsId(dsId), "apiId", apiId)).isEmpty(); |
196 | 205 |
} |
197 | 206 |
|
198 | 207 |
@Override |
208 |
@Transactional(readOnly = true) |
|
199 | 209 |
public boolean isRemovable(final String dsId, final String apiId) throws DsmException { |
200 | 210 |
final String q = "SELECT * from dsm_api WHERE id = :apiId AND datasource = :dsId AND active != true AND removable = true"; |
201 | 211 |
return !datasourceManagerClients.searchSQL(q, ImmutableMap.of("dsId", fixDsId(dsId), "apiId", apiId)).isEmpty(); |
202 | 212 |
} |
203 | 213 |
|
204 | 214 |
@Override |
215 |
@Transactional |
|
205 | 216 |
public void updateCompliance(final String dsId, final String apiId, final String level, final boolean override) throws DsmException { |
206 | 217 |
final String id = fixDsId(dsId); |
207 | 218 |
|
... | ... | |
217 | 228 |
} |
218 | 229 |
|
219 | 230 |
@Override |
231 |
|
|
220 | 232 |
public void setLastCollectionInfo(final String dsId, final String apiId, final String mdId, final Integer size, final Date date) |
221 | 233 |
throws DsmException { |
222 | 234 |
setLastOperationInfo(setLastCollectionInfo, fixDsId(dsId), apiId, mdId, size, date); |
... | ... | |
234 | 246 |
setLastOperationInfo(setLastDownloadInfo, fixDsId(dsId), apiId, objId, size, date); |
235 | 247 |
} |
236 | 248 |
|
237 |
private void setLastOperationInfo(final Resource sqlResource, final String dsId, final String apiId, final String mdId, final Integer size, final Date date) |
|
249 |
@Transactional |
|
250 |
protected void setLastOperationInfo(final Resource sqlResource, final String dsId, final String apiId, final String mdId, final Integer size, final Date date) |
|
238 | 251 |
throws DsmException { |
239 | 252 |
final Map<String, Object> params = new HashMap<>(); |
240 | 253 |
params.put("dsId", dsId); |
... | ... | |
251 | 264 |
} |
252 | 265 |
|
253 | 266 |
@Override |
267 |
@Transactional |
|
254 | 268 |
public void updateApiDetails(final String dsId, |
255 | 269 |
final String apiId, |
256 | 270 |
final String metadataIdentifierPath, |
... | ... | |
311 | 325 |
} |
312 | 326 |
|
313 | 327 |
@Override |
328 |
@Transactional |
|
314 | 329 |
public void addApi(final Api<ApiParam> api) throws DsmException { |
315 | 330 |
|
316 | 331 |
datasourceManagerClients.updateSQL(api.getDatasource(), insertApi, AfterSqlUpdate.NONE, DatasourceFunctions.apiToMap(api)); |
... | ... | |
328 | 343 |
} |
329 | 344 |
|
330 | 345 |
@Override |
346 |
@Transactional |
|
331 | 347 |
public void deleteApi(final String dsId, final String apiId) throws DsmException { |
332 | 348 |
if (!isRemovable(dsId, apiId)) { throw new DsmException("The api " + apiId + " can't be deleted"); } |
333 | 349 |
|
Also available in: Unified diff
upgraded version of jdbc driver for postgres, this includes a lot of changes, Because we have to add @transactional
annotation in some properties to avoid connection closed exception