2024-02-14 11:39:37 +01:00
|
|
|
|
2024-02-05 15:19:41 +01:00
|
|
|
package eu.dnetlib.dhp.collection.plugin.base;
|
|
|
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.Optional;
|
|
|
|
import java.util.Spliterator;
|
|
|
|
import java.util.Spliterators;
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
import java.util.stream.StreamSupport;
|
|
|
|
|
|
|
|
import org.apache.hadoop.fs.FileSystem;
|
|
|
|
import org.apache.hadoop.fs.Path;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
import eu.dnetlib.dhp.collection.ApiDescriptor;
|
|
|
|
import eu.dnetlib.dhp.collection.plugin.CollectorPlugin;
|
|
|
|
import eu.dnetlib.dhp.collection.plugin.file.AbstractSplittedRecordPlugin;
|
|
|
|
import eu.dnetlib.dhp.common.aggregation.AggregatorReport;
|
|
|
|
import eu.dnetlib.dhp.common.collection.CollectorException;
|
|
|
|
|
|
|
|
public class BaseCollectorPlugin implements CollectorPlugin {
|
|
|
|
|
|
|
|
private final FileSystem fs;
|
|
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(AbstractSplittedRecordPlugin.class);
|
|
|
|
|
2024-02-14 11:39:37 +01:00
|
|
|
// MAPPING AND FILTERING ARE DEFINED HERE:
|
|
|
|
// https://docs.google.com/document/d/1Aj-ZAV11b44MCrAAUCPiS2TUlXb6PnJEu1utCMAcCOU/edit
|
2024-02-06 15:10:29 +01:00
|
|
|
|
2024-02-05 15:19:41 +01:00
|
|
|
public BaseCollectorPlugin(final FileSystem fs) {
|
|
|
|
this.fs = fs;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Stream<String> collect(final ApiDescriptor api, final AggregatorReport report) throws CollectorException {
|
|
|
|
// get path to file
|
|
|
|
final Path filePath = Optional
|
2024-02-14 11:39:37 +01:00
|
|
|
.ofNullable(api.getBaseUrl())
|
|
|
|
.map(Path::new)
|
|
|
|
.orElseThrow(() -> new CollectorException("missing baseUrl"));
|
2024-02-05 15:19:41 +01:00
|
|
|
|
|
|
|
log.info("baseUrl: {}", filePath);
|
|
|
|
|
|
|
|
try {
|
2024-02-14 11:39:37 +01:00
|
|
|
if (!this.fs.exists(filePath)) {
|
|
|
|
throw new CollectorException("path does not exist: " + filePath);
|
|
|
|
}
|
2024-02-05 15:19:41 +01:00
|
|
|
} catch (final Throwable e) {
|
|
|
|
throw new CollectorException(e);
|
|
|
|
}
|
|
|
|
|
2024-02-15 08:21:52 +01:00
|
|
|
final Iterator<String> iterator = new BaseCollectorIterator(this.fs, filePath, report);
|
|
|
|
final Spliterator<String> spliterator = Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED);
|
2024-02-14 11:39:37 +01:00
|
|
|
return StreamSupport
|
|
|
|
.stream(spliterator, false)
|
2024-02-15 08:21:52 +01:00
|
|
|
.filter(doc -> filterXml(doc, report));
|
2024-02-05 15:19:41 +01:00
|
|
|
}
|
|
|
|
|
2024-02-15 08:21:52 +01:00
|
|
|
private boolean filterXml(final String xml, final AggregatorReport report) {
|
2024-02-06 15:10:29 +01:00
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
// HERE THE FILTERS ACCORDING TO THE DOCUMENTATION
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-02-05 15:19:41 +01:00
|
|
|
}
|