|
|
|
@ -7,48 +7,38 @@ import java.util.Spliterators;
|
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
import java.util.stream.StreamSupport;
|
|
|
|
|
|
|
|
|
|
import org.bson.Document;
|
|
|
|
|
|
|
|
|
|
import com.mongodb.MongoClient;
|
|
|
|
|
import com.mongodb.client.MongoCollection;
|
|
|
|
|
import com.mongodb.client.MongoDatabase;
|
|
|
|
|
import eu.dnetlib.dhp.common.MdstoreClient;
|
|
|
|
|
|
|
|
|
|
import eu.dnetlib.dhp.aggregation.common.AggregatorReport;
|
|
|
|
|
import eu.dnetlib.dhp.collection.ApiDescriptor;
|
|
|
|
|
import eu.dnetlib.dhp.collection.CollectorException;
|
|
|
|
|
import eu.dnetlib.dhp.collection.plugin.CollectorPlugin;
|
|
|
|
|
import org.bson.Document;
|
|
|
|
|
|
|
|
|
|
public class MongoDbCollectorPlugin implements CollectorPlugin {
|
|
|
|
|
public class MDStoreCollectorPlugin implements CollectorPlugin {
|
|
|
|
|
|
|
|
|
|
public static final String MONGODB_HOST = "mongodb_host";
|
|
|
|
|
public static final String MONGODB_PORT = "mongodb_port";
|
|
|
|
|
public static final String MONGODB_COLLECTION = "mongodb_collection";
|
|
|
|
|
public static final String MONGODB_BASEURL = "mongodb_baseurl";
|
|
|
|
|
public static final String MONGODB_DBNAME = "mongodb_dbname";
|
|
|
|
|
public static final String MDSTORE_ID = "mongodb_collection";
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Stream<String> collect(ApiDescriptor api, AggregatorReport report) throws CollectorException {
|
|
|
|
|
|
|
|
|
|
final String host = Optional
|
|
|
|
|
.ofNullable(api.getParams().get(MONGODB_HOST))
|
|
|
|
|
.orElseThrow(() -> new CollectorException(String.format("missing parameter '%s'", MONGODB_HOST)));
|
|
|
|
|
|
|
|
|
|
final Integer port = Optional
|
|
|
|
|
.ofNullable(api.getParams().get(MONGODB_PORT))
|
|
|
|
|
.map(Integer::parseInt)
|
|
|
|
|
.orElseThrow(() -> new CollectorException(String.format("missing parameter '%s'", MONGODB_PORT)));
|
|
|
|
|
final String mongoBaseUrl = Optional
|
|
|
|
|
.ofNullable(api.getParams().get(MONGODB_BASEURL))
|
|
|
|
|
.orElseThrow(() -> new CollectorException(String.format("missing parameter '%s'", MONGODB_BASEURL)));
|
|
|
|
|
|
|
|
|
|
final String dbName = Optional
|
|
|
|
|
.ofNullable(api.getParams().get(MONGODB_DBNAME))
|
|
|
|
|
.orElseThrow(() -> new CollectorException(String.format("missing parameter '%s'", MONGODB_DBNAME)));
|
|
|
|
|
|
|
|
|
|
final String collection = Optional
|
|
|
|
|
.ofNullable(api.getParams().get(MONGODB_COLLECTION))
|
|
|
|
|
.orElseThrow(() -> new CollectorException(String.format("missing parameter '%s'", MONGODB_COLLECTION)));
|
|
|
|
|
|
|
|
|
|
final MongoClient mongoClient = new MongoClient(host, port);
|
|
|
|
|
final MongoDatabase database = mongoClient.getDatabase(dbName);
|
|
|
|
|
final MongoCollection<Document> mdstore = database.getCollection(collection);
|
|
|
|
|
final String mdId = Optional
|
|
|
|
|
.ofNullable(api.getParams().get(MDSTORE_ID))
|
|
|
|
|
.orElseThrow(() -> new CollectorException(String.format("missing parameter '%s'", MDSTORE_ID)));
|
|
|
|
|
|
|
|
|
|
final MdstoreClient client = new MdstoreClient(mongoBaseUrl, dbName);
|
|
|
|
|
final MongoCollection<Document> mdstore = client.mdStore(mdId);
|
|
|
|
|
long size = mdstore.count();
|
|
|
|
|
|
|
|
|
|
return StreamSupport
|