find by Object Id in Jongo - java

I know this question is incredibly basic... I'm sorry in advance.
I can't do a 'find by ID' for Mongo using Jongo.
I tried
Iterator<MongoTest> all = db.getCollection("mongoTest").find("{'_id': ObjectId('5194d46bdda2de09c656b64b')}").as(MongoTest.class).iterator();
Error:
java.lang.IllegalArgumentException: {'_id': ObjectId('5194d46bdda2de09c656b64b')} cannot be parsed
at org.jongo.query.JsonQuery.marshallQuery(JsonQuery.java:34)
at org.jongo.query.JsonQuery.<init>(JsonQuery.java:27)
at org.jongo.query.JsonQueryFactory.createQuery(JsonQueryFactory.java:52)
at org.jongo.Find.<init>(Find.java:41)
at org.jongo.MongoCollection.find(MongoCollection.java:79)
at org.jongo.MongoCollection.find(MongoCollection.java:75)
I tried
Iterator<MongoTest> all = db.getCollection("mongoTest").find(withOid(new ObjectId("5194d46bdda2de09c656b64b"))).as(MongoTest.class).iterator();
exactly as in the documentation, and I can't even get it to compile ... there are two possible types of ObjectId.
de.undercouch.bson4jackson.types.ObjectId;
Tells me
The constructor ObjectId(String) is undefined
And if I use
org.bson.types.ObjectId;
it seems to work better, sometimes - but it still tells me that withOid( ObjectId ) is undefined. Which isn't entirely surprising, cause exactly what object is that function supposed to be part of?
My question: How do I do a find by _id in Jongo?

Someone helped me to find an answer elsewhere, putting it here for posterity
A valid construction for this is
db.getCollection("mongoTest")
.find("{ _id: # }", new ObjectId("5194d46bdda2de09c656b64b"))
.as(MongoTest.class);
Using org.bson.types.ObjectId
or
db.getCollection("mongoTest")
.findOne(Oid.withOid("5194d46bdda2de09c656b64b"))
.as(MongoTest.class);`

Related

Using enums with LispWorks' Java interface

I'm trying to use the EWS Java library (link) with LispWorks 7.1.2 Win32's Java interface. I am somewhat familiar with basic Java concepts but have no experience with the Java language. This is the code I am trying to mimic:
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
So I figured I would create an ExchangeVersion object (which is an enum), set it to the value "Exchange2010_SP2", and pass it to another create-java-object expression for the ExchangeService object.
This was my first step:
(create-java-object "microsoft.exchange.webservices.data.core.ExchangeService"
"microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion.Exchange2010_SP2")
However, I get the following error message: constructor of microsoft/exchange/webservices/data/core/ExchangeService first arguments is wrong type, wanted microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion got "microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion.Exchange2010_SP2"
OK, so then I tried this:
(create-java-object "microsoft.exchange.webservices.data.core.ExchangeService"
"microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion")
which gave me the error: constructor of microsoft/exchange/webservices/data/core/ExchangeService first arguments is wrong type, wanted microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion got "microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion". Which doesn't make much sense to me. So finally I tried to create a standalone ExchangeVersion object:
(create-java-object "microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion")
which led to this error message: CREATE-JAVA-OBJECT: : Failed to find constructors for class "microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion".
I wonder if anyone have suggestions on what am I doing wrong?
Many Thanks!

How to use String ressource in Java file in Android without a Layout

I have a Java class that mainly contains strings. It does not have a layout as it is neither a Fragment nor an Activity. It is more used as an auxilliary class. I would like to assign the String values in the class by using the Resource strings as I would like to automatically translate the Strings. Howvever, I can't access the string resources from Java. I use the following code:
static String more = getString(R.string.more);
And in the XML file I have the ressource:
<string name="more">More</string>
I get the error message
Cannot resolve method 'getString'
I also tried static String more = getContext().getString(R.string.more);
but I got the error message:
Cannot resolve method 'getContext'
Would anyone mind helping me on that? I'd appreciate every comment.
Update: I tried to use the answer from "MikaelM"
Resources.getSystem().getString(R.string.more)
However, I get an "exception in initializer error" and when I use the initial String again, I do not get this error. So I still can't get the String from the ressource. DO you have an idea what I can do? I'd appreciate every further comment.
So the error is caused by "Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x7f120038"
The strange thing is that the resource in fact exists (I checked this several times).
getString(R.string...
is not the same as
Resources.getSystem().getString(android.R.string...
Only the second variant you can use in the static context. Alas, you can get this way only system resources.
If you need to get your own resources, no one-line solution exists. Use https://stackoverflow.com/a/4391811/715269 solution of #Cristian. And notice: it is a very good solution, even more, it is the solution meant to be used by the creators of Android.
You should be able to get your string with:
Resources.getSystem().getString(R.string.more)
See more here, getString Outside of a Context or Activity

RegisterNatives failed for 'android/webkit/BrowserFrame'

Building a ROM from source, but stuck at a point. I have understood the error but have no idea exactly what should the fix be.
ROM stucks on boot and I see this
E/dalvikvm( 353): ERROR: couldn't find native method
E/dalvikvm( 353): Requested: Landroid/webkit/BrowserFrame;.nativeAddJavascriptInterface:(ILjava/lang/Object;Ljava/lang/String;)V
E/dalvikvm( 353): Candidate: Landroid/webkit/BrowserFrame;.nativeAddJavascriptInterface:(ILjava/lang/Object;Ljava/lang/String;Z)V
E/JNIHelp ( 353): RegisterNatives failed for 'android/webkit/BrowserFrame', aborting
From the error, what is requested in that method is (ILjava/lang/Object;Ljava/lang/String;)V but what being provided is (ILjava/lang/Object;Ljava/lang/String;Z)V
Difference lies in that Z
Can anyone think of a solution for that method in BrowserFrame.java ? or any other workaround?
The additional argument was added late last year, in a pair of changes:
https://android.googlesource.com/platform/frameworks/base/+/94740e6c333a109be7516abbd17dd418f23b4f0c
https://android.googlesource.com/platform/external/webkit/+/f2d8c5bed31609d7d6e3ae77f33e90ea7f888eb3
It sounds like you have the change from frameworks/base, but not the corresponding change from external/webkit.

How to specify the type of a list in Drools 5.5?

Our rules are based on v4.x now we are migrating to v5.5. It seems this version is type safe so the following code won't work properly:
$contractualBalances : ArrayList() from accountService.getContractualBalances($id, $cmounts)
now when we have this forall statement, it doesn't work because the ArrayList above doesn't specified the type:
ContractualBalance() from $contractualBalances
Can anyone please help me how to specify the type. I tried to use ArrayList() but no luck
Thanks
I resolved the problem:
$contractualBalances : ContractualBalance() from accountService.getContractualBalances($id, $cmounts)

Programatically adding a sort condition to a table in BIRT using JS

I am attempting to write some script that simplifies table sorting and have been getting quite close but am now wondering if I have found a bug...or have just misunderstood limitations.
So my relevant code:
var reportRunnable = reportContext.getReportRunnable();
var reportDesign = reportRunnable.getDesignInstance();
var table = reportDesign.getTable(tableName);
var sortCondition = org.eclipse.birt.report.engine.api.script.element.StructureScriptAPIFactory.createSortCondition();
sortCondition.setKey("row[\"" + columnKey + "\"]");
sortCondition.setDirection("desc");
table.removeSortConditions();
table.addSortCondition(sortCondition);
I am getting a NullPointerException on line 164 in the class Listing:
org.eclipse.birt.report.engine.script.internal.element.Listing, in the method removeSortConditions...
((org.eclipse.birt.report.model.api.simpleapi.IListing) designElementImpl).removeSortConditions();
So the above implies 'designElementImpl' is null, having looked further at the source it seemed to imply that to instantiate the 'table' object, the following constructor was used:
public Table( TableHandle table );
And moving up the heirarchy of super classes, it implies that in the constructor of DesignElement, the following is returning null:
designElementImpl = SimpleElementFactory.getInstance( ).getElement(handle);
Any one any thoughts? Am I just not able to what I am trying to do?
Thanks in advance.
EDIT: Should probably add; I'm using BIRT 2.5.1.
I think I have this sorted now...I created a [simpler] new report without library dependencies and sorting is now working correctly.
I posted on another forum as well, so if anyone wants more details see BIRT Exchange Forums.
Cheers.

Categories