Reputation: 123
I'm trying to use the Java SDK provided by Prediction.io but am running into some trouble. Basically, to make use of the Java SDK, the Java code is as below.
import com.google.common.collect.ImmutableMap;
import io.prediction.EventClient;
import org.joda.time.DateTime;
EventClient eventClient = new EventClient(1);
eventClient.setUser("id_1", ImmutableMap.<String, Object>of(), new DateTime("2004-12-13T21:39:45.618-07:00"));
What I've done is:
1) Compiled the Java SDK and copied the resulting jar file and dependencies to /opt/railo/lib/
2) Managed to get a dump of the EventClient class using the code below:
<cfset MyTest = CreateObject("java", "io.prediction.EventClient")>
<cfdump var="#MyTest#">
I'm pretty much lost after that. Although I'm pretty used to Coldfusion, I'm a total Java newbie. How do I use/replicate the Java code above into Coldfusion?
Upvotes: 2
Views: 266
Reputation: 1973
Completely untested, but something like this should do:
Create the object first:
<cfset MyTest = CreateObject("java", "io.prediction.EventClient").init(1)>
This is equivalent to EventClient eventClient = new io.prediction.EventClient(1);
. You need the init() method in order to create an instance of the class you loaded with CreateObject(), by calling its constructor with the parameter 1
.
Create an empty ImmutableMap
:
<cfset imClass = CreateObject("java", "com.google.common.collect.ImmutableMap")>
<cfset imObj = imClass.of()>
Above, you are calling the static method of()
of the ImmutableMap
class, so you do not need an init
on the class. You could merge these two lines into a single line too if you wish.
Now create the Joda DateTime object:
<cfset jtObj = CreateObject("java", "org.joda.time.DateTime").init("2004-12-13T21:39:45.618-07:00")>
Finally, you can call the method on your EventClient object:
<cfset MyTest.setUser("id_1", imObj, jtObj)>
Upvotes: 2