Norconex / collector-core

Collector-related code shared between different collector implementations
http://www.norconex.com/collectors/collector-core/
Apache License 2.0
7 stars 15 forks source link

Enhancement request - delegate buildMongoClient and buildMongoCredential #13

Closed danizen closed 6 years ago

danizen commented 6 years ago

Current Behavior

com.norconex.collector.core.data.store.impl.mongo.MongoCrawlDataStore builds a client object during its construction, based on the details stored in com.norconex.collector.core.data.store.impl.mongo.MongoConnectionDetails.

Desired Behavior

The static method buildMongoClient is retained, but delegates to a similar instance method in com.norconex.collector.core.data.store.impl.mongo.MongoConnectionDetails.

The static method buildMongoCredential is moved to com.norconex.collector.core.data.store.impl.mongo.MongoConnectionDetails and may be static or become an instance method with a smaller signature.

Rationale

It makes sense because MongoConnectionDetails already contains all information needed to create this client connection aside from the id.

It has utility because any user attempting to implement a MongoJobStatusStore as discussed in https://github.com/Norconex/jef/issues/9 will have to implement similar logic.

Technical Notes

Ideally, the the MongoConnectionDetails would implement IXMLSerializable, and AbstractMongoCrawlDataStoreFactory would delegate to it.

Maybe a new package com.norconex.collector.core.config could be created to hold MongoConnectionDetails.

danizen commented 6 years ago

See pull request

essiembre commented 6 years ago

Shall we close now that your pull-request has been merged? Please confirm.

danizen commented 6 years ago

Up to you - I couldn't justify work on the government dime to do more than the minimum upstream commit. If you want to parse MongoConnectionDetails parameters in a DRY way, they might be delegated to a MongoConnectionConfig object that taxes an XMLConfiguration to parse and an EnhancedXMLWriter to write. This assures the same conventions for parsing in the Mongo data store and anything else that uses Mongo. However, given that the other is closed ... maybe not worth bothering.

I'm happy either way.

essiembre commented 6 years ago

Closing then and if these latest changes prove not to be sufficient, we'll advise then.