Questions RE: eModeling Users Guide

34 views
Skip to first unread message

Geoffry Roberts

unread,
Oct 31, 2013, 12:52:34 PM10/31/13
to mong...@googlegroups.com
Brian,

I read the eModeling Users Guide and have a couple of questions:

  1. src vs dest -- Let's say I have an EMF compliant object graph that is to be persisted into Mongo.  I would assume dest = the Mongo URI and src = ?.
  2. Are we still doing things this way? (see below)  I am still getting an error that protocol mongodb is unknown.  I do believe the configuration is now correct.  Code is below.
Saving my EMF model run as an osgi command and taken from the old user guide:

public void cda() {

// Load a clinical document from the filesystem.

File file = new    File("/Users/gcr/Documents/ehrWorkspace/ehrWorkArea/samples/SampleCDADocument.xml");

try {

Reader reader = new BufferedReader(new FileReader(file));

InputSource is = new InputSource(reader);

ClinicalDocument cda = CDAUtil.load(is); 

                        // we now have a CDA which is based on EMF.


// begin: Mongo-emf related code

ResourceSetFactory resourceSetFactory = res.getResourceSet();

ResourceSet resourceSet = resourceSetFactory.createResourceSet();

String uri = database.getURI(); // at this point urimongodb://localhost/ehr

Resource resource = resourceSet.createResource(URI

.createURI(uri));

EList<EObject> eo = resource.getContents();

eo.add(cda);

try {

cda.eResource().save(null);

} catch (IOException e) {

log.error("", e); // error = unknown protocol: mongodb

}

} catch (Exception e) {

log.error("", e);  

}

}


MongoClient Configuration:


@Reference

void setConfigurationAdmin(ConfigurationAdmin configurationAdmin)

throws ConfigurationException {


log.info("setConfigurationAdmin configurationAdmin="

+ configurationAdmin);


try {

Configuration config = configurationAdmin.getConfiguration(

ConfigurationProperties.CLIENT_PID, null);


@SuppressWarnings("unchecked")

Dictionary<String, Object> properties = config.getProperties();


if (properties == null)

properties = new Hashtable<String, Object>();


properties.put(MongoClientProvider.PROP_CLIENT_ID, "storet");

properties.put(MongoClientProvider.PROP_URI, "mongodb://localhost");

config.update(properties);

} catch (IOException e) {

throw new ConfigurationException(e);

}

}


Mongo DB Configuration:

@Reference

void setConfigurationAdmin(ConfigurationAdmin configurationAdmin)

throws ConfigurationException {


log.info("setConfigurationAdmin configurationAdmin="

+ configurationAdmin);


try {

Configuration config = configurationAdmin.getConfiguration(

ConfigurationProperties.DATABASE_PID, null);


@SuppressWarnings("unchecked")

Dictionary<String, Object> properties = config.getProperties();


if (properties == null)

properties = new Hashtable<String, Object>();


properties.put(MongoDatabaseProvider.PROP_ALIAS, "storet");

properties.put(MongoDatabaseProvider.PROP_DATABASE, "ehr");

config.update(properties);

} catch (IOException e) {

log.error("", e);

}

}

Bryan Hunt

unread,
Oct 31, 2013, 1:27:19 PM10/31/13
to mong...@googlegroups.com
Hi Geoffry,

You only need the URI mapping when your source URI is something other than mongodb://host/db/collection.  This was originally created to handle the case when the URI originated from a REST service.

You are probably missing some bundles from MongoEMF.  Make sure you have:

mongoemf.builders
mongoemf.converter
mongoemf.core
mongoemf.handlers
mongoemf.query.mongodb or simple
mongoemf.streams

Also, I noticed that in your example below, you are missing the collection segment from the URI.  The URI must be in the form mongodb://host/db/collection

Bryan
--
You received this message because you are subscribed to the Google Groups "MongoEMF" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoemf+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Geoffry Roberts

unread,
Oct 31, 2013, 2:44:33 PM10/31/13
to mong...@googlegroups.com
Brian,

wrt,

That list of mongo-emf dependencies: good to know.  I wondered when the mongo-emf would be needed.  

However, while looking at the repository (located @ http://bryanhunt.github.com/mongo-emf/releases/0.8.0/index.xml.gz), I do not see mongoemf.query.mongodb.  I do see mongoemf.query.simple.  I added it to the run time and got a complaint that the dependency  mongoemf.query cannot be found.  I don't see  mongoemf.query in the repository either.

Reason: Missing Constraint: Import-Package: org.eclipselabs.emodeling.query; version="0.0.0"


We're getting there :-)

Bryan Hunt

unread,
Oct 31, 2013, 3:16:05 PM10/31/13
to mong...@googlegroups.com
Hi Geoffry,

It looks like the missing query.mongodb is an oversight on my part.  If you have a minute to create an issue agains MongoEMF, I'll try to fix that tonight.

query.simple needs emodeling.query not mongemf.query.

FYI, query.mongodb is much more powerful than query.simple, but is MongoDB specific.

Bryan

Geoffry Roberts

unread,
Oct 31, 2013, 4:11:59 PM10/31/13
to mong...@googlegroups.com
Brian,

Thanks for pointing our my misread on the last error message.  I'm looking forward to getting the missing bundle.

However,  even with all the dependencies you recommended both installed and active, I am still getting a malformed url exception.  unknown protocol mongodb.  Perhaps the missing bundle will help.

Thanks again

Bryan Hunt

unread,
Oct 31, 2013, 4:24:47 PM10/31/13
to mong...@googlegroups.com
Hi Geoffry,

The query bundle won't fix the unknown protocol problem.  If you look at the handler bundle, it implements the UriHandlerProvider service which creates an instance of MongoURIHandlerImpl which is what can handle the mongodb scheme.  That service implementation depends on the MongoDatabaseProvider, InputStreamFactory, and OutputStreamFactory services.  This gets into a complex dependency chain and if one of the pieces is missing, the handler does not get registered.  This is where the Equinox "ls" command or the Felix equivalent comes in handy.  Which services are active and which are not?

Bryan

Geoffry Roberts

unread,
Oct 31, 2013, 7:43:38 PM10/31/13
to mong...@googlegroups.com
Brian,

All services are active.

I've read your last post to this thread and have just finished re-reading the users guide. I am trying to connect the dots. Apparently, I need to implement something else, but at this point I can't tell what.

If you will accommodate me with a few clarifications.

From the UG:

1. "Users need to supply a service configuration using ConfigurationAdmin for each URI mapping needed"
Is this accomplished with the following statement?

properties.put(MongoClientProvider.PROP_URI, "mongodb://localhost");


2. "The UriHandlerProvider service is implemented by client code (you)."

If I implement this, say with a near cut and paste from the example, will it make the connection needed to get the protocol working? IOTW is this the missing link?


3. ResourceCache and ResourceSetFactory

I see some code in these two sections. Am I to provide implementations using this code as a guide? The way the two sections are written, they sound informational i.e. fyi only.

Bryan Hunt

unread,
Oct 31, 2013, 9:46:36 PM10/31/13
to mong...@googlegroups.com
Hi Geoffry,

1. URI mappings are optional.  The UriMapProvider is a service that will add a URI map to the resource set upon construction based on the UriMapProvider service configuration properties.  You only need instances of this service if your resource set needs a URI Map (this is a feature of EMF).

2. From an eModeling project point of view, the UriHandlerProvider is implemented by client code.  MongoEMF happens to be a client of eModeling that implements UriHandlerProvider, so you as the programmer do not need to implement UriHandlerProvider.

3. The code provided in the ResourceSetFactory and ResourceCache are examples of how you might write your OSGi component to use one of those services.

If all services are active, then you should not be getting the unknown protocol exception.  It just occurred to me that it is possible that you could have a race condition where your OSGi component is being activated before the other components.  I just verified that the launcher I use for the MongoEMF example sets the bundle start level of org.eclipselabs.mongoemf.examples to 5 which guarantees that bundle is started after all others.  If this is the problem you are running into, you can either set the start level of your bundle, or have your component depend on the UriHandlerProvider service.  If you set a breakpoint in your activate and then look at which services are active and which are not, that will verify this problem.

Bryan
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages