Revision 50435
Added by Michele Artini about 6 years ago
LocalOpenaireDatasourceManager.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.enabling.datasources; |
2 | 2 |
|
3 | 3 |
import java.io.StringWriter; |
4 |
import java.util.*; |
|
4 |
import java.util.ArrayList; |
|
5 |
import java.util.Date; |
|
6 |
import java.util.HashMap; |
|
7 |
import java.util.List; |
|
8 |
import java.util.Map; |
|
9 |
import java.util.Optional; |
|
5 | 10 |
import java.util.stream.Collectors; |
6 | 11 |
|
7 |
import com.google.common.collect.ImmutableMap; |
|
8 |
import eu.dnetlib.enabling.datasources.DatasourceManagerClients.AfterSqlUpdate; |
|
9 |
import eu.dnetlib.enabling.datasources.common.*; |
|
10 | 12 |
import org.apache.commons.io.IOUtils; |
11 | 13 |
import org.apache.commons.lang.StringUtils; |
12 | 14 |
import org.apache.commons.lang.math.NumberUtils; |
... | ... | |
16 | 18 |
import org.springframework.core.io.ClassPathResource; |
17 | 19 |
import org.springframework.core.io.Resource; |
18 | 20 |
|
21 |
import com.google.common.collect.ImmutableMap; |
|
22 |
|
|
23 |
import eu.dnetlib.enabling.datasources.DatasourceManagerClients.AfterSqlUpdate; |
|
24 |
import eu.dnetlib.enabling.datasources.common.Api; |
|
25 |
import eu.dnetlib.enabling.datasources.common.ApiParam; |
|
26 |
import eu.dnetlib.enabling.datasources.common.BrowsableField; |
|
27 |
import eu.dnetlib.enabling.datasources.common.BrowseTerm; |
|
28 |
import eu.dnetlib.enabling.datasources.common.BrowseTermImpl; |
|
29 |
import eu.dnetlib.enabling.datasources.common.Datasource; |
|
30 |
import eu.dnetlib.enabling.datasources.common.DsmException; |
|
31 |
import eu.dnetlib.enabling.datasources.common.Identity; |
|
32 |
import eu.dnetlib.enabling.datasources.common.LocalDatasourceManager; |
|
33 |
import eu.dnetlib.enabling.datasources.common.Organization; |
|
34 |
import eu.dnetlib.enabling.datasources.common.SearchApisEntry; |
|
35 |
import eu.dnetlib.enabling.datasources.common.SimpleDatasource; |
|
36 |
|
|
19 | 37 |
public class LocalOpenaireDatasourceManager implements LocalDatasourceManager<Datasource<Organization<?>, Identity>, Api<ApiParam>> { |
20 | 38 |
|
21 | 39 |
private DatasourceManagerClients datasourceManagerClients; |
... | ... | |
81 | 99 |
|
82 | 100 |
@Override |
83 | 101 |
public void saveDs(final Datasource<Organization<?>, Identity> ds) throws DsmException { |
102 |
|
|
84 | 103 |
if (StringUtils.isBlank(ds.getAggregator())) { |
85 | 104 |
ds.setAggregator("OPENAIRE"); |
86 | 105 |
} |
87 | 106 |
|
107 |
ds.setManaged(true); |
|
108 |
|
|
88 | 109 |
datasourceManagerClients.updateSQL(ds.getId(), addDs, AfterSqlUpdate.NONE, DatasourceFunctions.dsToMap(ds)); |
89 | 110 |
|
90 | 111 |
if (ds.getOrganizations() != null) { |
... | ... | |
144 | 165 |
params.put("apiId", apiId); |
145 | 166 |
params.put("dsId", id); |
146 | 167 |
|
147 |
datasourceManagerClients.updateSQL(id, setActive, AfterSqlUpdate.UPDATE_DS_PROFILE, params);
|
|
168 |
datasourceManagerClients.updateSQL(id, setActive, AfterSqlUpdate.NONE, params);
|
|
148 | 169 |
if (!active) { |
149 | 170 |
setLastCollectionInfo(id, apiId, null, null, null); |
150 | 171 |
setLastAggregationInfo(id, apiId, null, null, null); |
151 | 172 |
setLastDownloadInfo(id, apiId, null, null, null); |
152 | 173 |
} |
174 |
|
|
175 |
setManaged(id, true); // It also update the IS profile |
|
153 | 176 |
} |
154 | 177 |
|
155 | 178 |
@Override |
... | ... | |
169 | 192 |
final String id = fixDsId(dsId); |
170 | 193 |
|
171 | 194 |
if (!override) { |
172 |
datasourceManagerClients.updateSQL(id, setCompliance, AfterSqlUpdate.UPDATE_DS_PROFILE, |
|
173 |
ImmutableMap.of("level", level, "apiId", apiId, "dsId", id)); |
|
195 |
datasourceManagerClients.updateSQL(id, setCompliance, AfterSqlUpdate.NONE, ImmutableMap.of("level", level, "apiId", apiId, "dsId", id)); |
|
174 | 196 |
} else if (level != null) { |
175 |
datasourceManagerClients.updateSQL(id, overrideCompliance, AfterSqlUpdate.UPDATE_DS_PROFILE, |
|
176 |
ImmutableMap.of("level", level, "apiId", apiId, "dsId", id)); |
|
197 |
datasourceManagerClients.updateSQL(id, overrideCompliance, AfterSqlUpdate.NONE, ImmutableMap.of("level", level, "apiId", apiId, "dsId", id)); |
|
177 | 198 |
} else { |
178 |
datasourceManagerClients.updateSQL(id, resetCompliance, AfterSqlUpdate.UPDATE_DS_PROFILE, ImmutableMap.of("apiId", apiId, "dsId", id));
|
|
199 |
datasourceManagerClients.updateSQL(id, resetCompliance, AfterSqlUpdate.NONE, ImmutableMap.of("apiId", apiId, "dsId", id));
|
|
179 | 200 |
} |
201 |
|
|
202 |
setManaged(id, true); // It also update the IS profile |
|
180 | 203 |
} |
181 | 204 |
|
182 | 205 |
@Override |
... | ... | |
205 | 228 |
params.put("mdId", mdId); |
206 | 229 |
params.put("total", size); |
207 | 230 |
params.put("date", new java.sql.Timestamp(date.getTime())); |
208 |
datasourceManagerClients.updateSQL(dsId, sqlResource, AfterSqlUpdate.UPDATE_DS_PROFILE, params); |
|
231 |
|
|
232 |
datasourceManagerClients.updateSQL(dsId, sqlResource, AfterSqlUpdate.NONE, params); |
|
233 |
|
|
234 |
setManaged(dsId, true); // It also update the IS profile |
|
209 | 235 |
} |
210 | 236 |
|
211 | 237 |
@Override |
... | ... | |
239 | 265 |
AfterSqlUpdate.NONE, |
240 | 266 |
ImmutableMap.of("path", metadataIdentifierPath, "api", apiId)); |
241 | 267 |
|
242 |
// Update the IS profile |
|
243 |
datasourceManagerClients.regenerateProfile(id); |
|
268 |
setManaged(id, true); // It also update the IS profile |
|
244 | 269 |
} |
245 | 270 |
|
246 | 271 |
@Override |
... | ... | |
283 | 308 |
} |
284 | 309 |
}); |
285 | 310 |
|
286 |
datasourceManagerClients.regenerateProfile(api.getDatasource());
|
|
311 |
setManaged(api.getDatasource(), true); // It also update the IS profile
|
|
287 | 312 |
} |
288 | 313 |
|
289 | 314 |
@Override |
... | ... | |
291 | 316 |
if (!isRemovable(dsId, apiId)) { throw new DsmException("The api " + apiId + " can't be deleted"); } |
292 | 317 |
|
293 | 318 |
datasourceManagerClients.updateSQL(dsId, "DELETE FROM dsm_apiparams WHERE api = :api", AfterSqlUpdate.NONE, ImmutableMap.of("api", apiId)); |
294 |
datasourceManagerClients.updateSQL(dsId, "DELETE FROM dsm_api WHERE id = :api", AfterSqlUpdate.UPDATE_DS_PROFILE, ImmutableMap.of("api", apiId)); |
|
319 |
datasourceManagerClients.updateSQL(dsId, "DELETE FROM dsm_api WHERE id = :api", AfterSqlUpdate.NONE, ImmutableMap.of("api", apiId)); |
|
320 |
|
|
321 |
setManaged(dsId, true); // It also update the IS profile |
|
295 | 322 |
} |
296 | 323 |
|
297 | 324 |
public DatasourceManagerClients getDatasourceManagerClients() { |
Also available in: Unified diff
setManaged(true) after method invocations