How do I write this Java code in Coldfusion

I have the following code that was written in Java.  I need to know how I can do the same in coldfusion.  I've included the sample below.
import com.fiserv.ist.titan.jaqi.Query;
import com.fiserv.ist.titan.jaqi.QueryRequest2;
import com.fiserv.ist.titan.jaqi.QueryResult;

QueryRequest2 qr2 = new QueryRequest2();
qr2.document  = props.getProperty("document");
qr2.databases = new String[]{ props.getProperty"database") };
qr2.from      = props.getProperty("from");
qr2.to        = props.getProperty("to");
qr2.fields    = new String[0];
qr2.where     = props.getProperty("where");
qr2.order     = new OrderBy[0];
query         = jaqiHandle.submitQuerySync(qr2);

Open in new window

CashmgmtAsked:
Who is Participating?
 
_agx_Commented:
Anyway it looks like the QueryResult doesn't inherit from anything else.  So you can just do a straight translation of their toString() method.  It's looks like it's just looping and displaying values.  Since the arrays are being handled in CF, the indexes should be 1-based, instead of 0-based. But you'll have to test and see.

<cfscript>
    // *** IMPORTANT: Make sure the loop variable names don't conflict
    // with those already in the rest of your code
      if ( IsDefined("data")) {
            // display the headers
            for (i = 1; i lte arrayLen(fieldInfo); i = i+1) {
                  fieldName = fieldInfo[i].name;
                  //Display field names
              WriteOutput(fieldName &" "& chr(9));
          }
          //display the data
          for (row = 1; row lte arrayLen(data.itemInfo); row = row+1) {
            for (col = 1; col lte arrayLen(data.itemInfo[row]); col = col +1) {
                value = data.itemInfo[row][col];
                    WriteOutput(value &" "& chr(9));
            }
                  // ....
            // new line
            WriteOutput(chr(10));
        }    
      }
</cfscript>

As for the conversion, I still don't see the path of the "Util" class, but it's just a simple createObject("java", "path.to.Util")....  followed by this

<cfscript>
     start = createObject("java", "java.lang.System").currentTimeMillis();
     // this might work too, undocumented
     // start = now().getTime();
     images = query.getImagesById(data.viewInfo);
     Util.saveImages(images, "image_", "tif", start);
</cfscript>

Then just close the objects at the end

<cfscript>
   if (IsDefined("jaqiClient")) {
       jaqiHandle.removeQuery(queryId);
       jaqiClient.releaseHandle(jaqiHandle);
       jaqiClient.close();
   }
</cfscript>


That's pretty much it for this example.  Now that it is working, the hard part's over.  You can figure out how you want to structure the final CFC code yourself.



0
 
_agx_Commented:
> qr2.document  = [ props.getProperty"database") ];

      1. Is this right, or should it actually be props.getProperty("database")?
      2. Is qr2.document a property or a method? Same with "from", "to", etc...

> jaqiHandle.submitQuerySync(qr2);

      What type of object (ie class) is jaqiHandle ?
0
 
CashmgmtAuthor Commented:
I've attached screenshots from documentation.  does that help?
ScreenHunter-01-Apr.-15-10.40.gif
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
CashmgmtAuthor Commented:
0
 
CashmgmtAuthor Commented:
it should be qr2.document = props.getProperty("document")
0
 
_agx_Commented:
Somewhat. But the "props" and "jaqiHandle" objects have to be created somewhere else in the code.

Assuming you already have a "props" object, try this first part. Does it work?  I'm not sure how CF is going to handle the properties "document".. etc..

<cfscript>
      qr2 = createObject("java", "com.fiserv.ist.titan.jaqi.QueryRequest2").init();
      qr2.document  = props.getProperty("document");
      dbArray = [ props.getProperty("database") ];
      qr2.databases = dbArray;
</cfscript>
0
 
CashmgmtAuthor Commented:
Here's what I have so far.  When I run the page, I get the version of the Jaqi server, the fields in the table.  the code I pasted above creates a query that will run against the DB and retrieve the items.  But that's where I'm stuck because I'm not sure how to do it in CF. I've included the Java sample where I got the code above.  The difference is that the sample loads the document, database, etc... from a file.  My CF code has the settings hard coded.
<cfobject type="java" action="create" class="com.fiserv.ist.titan.jaqi.JaQIClient" name="JaQiClient">
<cfobject type="java" action="create" class="com.fiserv.ist.titan.jaqi.FieldInfo" name="FieldInfo">
<cfobject type="java" action="create" class="com.fiserv.ist.titan.jaqi.JaQIException" name="JaQIException">
<cfobject type="java" action="create" class="com.fiserv.ist.titan.jaqi.OrderBy" name="OrderBy">
<cfobject type="java" action="create" class="com.fiserv.ist.titan.jaqi.Query" name="Query">
<cfobject type="java" action="create" class="com.fiserv.ist.titan.jaqi.QueryRequest2" name="QueryRequest2">
<cfobject type="java" action="create" class="com.fiserv.ist.titan.jaqi.QueryResult" name="QueryResult">
<cfobject type="java" action="create" class="com.fiserv.ist.titan.jaqi.StateEnum" name="StateEnum">
<cfobject type="java" action="create" class="com.fiserv.ist.titan.jaqi.JaQIHandle" name="JaQIHandle">
<cfobject type="java" action="create" class="com.fiserv.ist.titan.jaqi.ImageOperation" name="ImageOperation">
<cfobject type="java" action="create" class="com.fiserv.ist.titan.jaqi.ConvertEnum" name="ConvertEnum">
<cfobject type="java" action="create" class="java.util.Properties" name="props">
<cfset props.init()>

<cfset props.setProperty("host",      "frost_u4")>
<cfset props.setProperty("port",      "13043")>
<cfset props.setProperty("serverId",  "JaQIServer_1")>
<cfset props.setProperty("username",  "fc06743")>
<cfset props.setProperty("password",  "password")>
<cfset props.setProperty("description", "CMS Item Retrieval")>
<cftry>
	<cfset JaQiClient.init(props)>
	<cfset jaqihandle = JaQiClient.getHandle()>
	<cfset Version = JaQiClient.getVersion()>
	<cfset documents = jaqihandle.getDocuments()>
	<cfset documentFields = jaqihandle.getDocumentFields(documents[5])>
	<cfset database = jaqihandle.getDatabases(documents[5])>
	<cfset cycles = jaqihandle.getCycles(documents[5], database[1])>
	<cfset from = cycles[2]>
	<cfset where = "D_PROOFAMT > 10">
	<cfset datasource = "#documents[5]#/#database[1]#/#from#">
	<cfset images = jaqihandle.getImages(datasource, where)>
	<cfset img = #ToBase64(images[1])#>
	<cfdump var= "#Version#">
	<cfdump var= "#documents#">
	<cfdump var= "#documentFields#">
	<cfdump var= "#database#">
	<cfdump var= "#cycles#">
	<cfdump var= "#datasource#">
	<cfdump var= "#where#">
	<cfdump var= "#images[1]#">
	<cfoutput><img src="TitanImage.asp?img=#img#"></cfoutput>
	<cfcatch type="any">
		<cfdump var="#cfcatch#">
		<cfabort>
	</cfcatch>
</cftry>

Open in new window

AdvancedSample1.java
0
 
_agx_Commented:
> My CF code has the settings hard coded.

   Well then just try replacing the "document", "database", etc... with the values you want. Looks like they're all
   simple strings (or string arrays)

   If you add this code right after your cfdumps, what happens?

       <cfscript>
      qr2 = QueryRequest2.init();
      qr2.document  = "the document value you want here";
      dbArray = [ "database value you want here " ];
      qr2.databases = dbArray;
       </cfscript>

0
 
CashmgmtAuthor Commented:
When I put your sample, I get no errors, but when add the query = jaqihandle.submitQuerySync(qr2);
I get an [empty_string] error on that line.
    <cfscript>
      qr2 = QueryRequest2.init();
      qr2.document  = "#documents#";
      dbArray = [ "#database#" ];
      qr2.databases = dbArray;
      qr2.from = "#from#";
      qr2.to = "#from#";
      qr2.where = "#where#";
      query = jaqihandle.submitQuerySync(qr2);
    </cfscript>

Open in new window

0
 
_agx_Commented:
>  qr2.to = "#from#";
 
    That should probably be your #toValue#.

> I get an [empty_string] error on that line.

   Can you post the full error message? Also, 1) are you using the exact same values as in the
   java example and 2) it doesn't look like you supplied all of the values in example. ie "Fields" and "order"
   are missing.  Are these values mandatory or optional?

0
 
CashmgmtAuthor Commented:
I've attached the error.  I will change the qr2.to value.  the Fields and order are optional.
error.JPG
0
 
_agx_Commented:
Looks like it's saying some value or object it expects to receive is NULL.  Unfortunately, it's not clear from the error what that is.  As I mentioned before, are you using the exact same values as in the java example? And are you sure the base java example actually works ...?
0
 
CashmgmtAuthor Commented:
The java example does work, I can run it and it goes in and retrieves the images just like it's supposed to.
0
 
_agx_Commented:
... and are you using the exact same values? I can't tell from your code ...
0
 
_agx_Commented:
> qr2 = QueryRequest2.init();
>  qr2.document  = "#documents#";
>  dbArray = [ "#database#" ];
> qr2.databases = dbArray;

Also, try one more thing.  After you set the values, dump them to make sure the values are truly "sticking"

      <cfdump var="#qr2#">
      <cfdump var="#qr2.document#">
      <cfdump var="#qr2.from#">
      etc....
0
 
CashmgmtAuthor Commented:
I dumped the var's and they have data.
0
 
_agx_Commented:
While I understand you can't post commercial code, unfortunately it's next to impossible to determine the cause of the NullPointer issue without being able to see the entire java sample next to the CF sample. Maybe you're missing something.  ie Doing something in the java code not being done in the CF sample.
0
 
_agx_Commented:
> The difference is that the sample loads the document, database, etc... from a file.

   When dealing with unfamiliar code/api's it's best to duplicate the example _exactly_ first,  
   before you start modifying things.  Straying from the example is where most problems
   tend to occur ie The issue is often the translation of the code, rather than the library itself .
   
0
 
CashmgmtAuthor Commented:
I have included 2 files, one is the CF_Code, the other is the java code.  I don't mind showing you the code, I need to figure this out one way or the other. As always, I really appreciate your help!!
CF-Code.txt
AdvancedSample2.java
0
 
_agx_Commented:
I would try an exact translation first.  See if this part works without error. If it does, we can move on to the rest. Obviously not tested as I don't have the libraries ;-)  But it should be close.  Just change the path to the .cfg file first.


<cfscript>
    pathToConfig = "c:\fullPathTo\sample.cfg";

    fis = createObject("java", "java.io.FileInputStream").init("sample.cfg");
    props = createObject("java", "java.util.Properties").init();
    props.load( fis );
    fis.close();
	
    jaqiClient = createObject("java", "com.fiserv.ist.titan.jaqi.JaQIClient").init(props);
    WriteOutput("Running example3: AdvancedSample2" + jaqiClient.getVersion() &"<br>");
    jaqiHandle = jaqiClient.getHandle();
    qr2 = createObject("java", "com.fiserv.ist.titan.jaqi.QueryRequest2").init();

    qr2.document  = props.getProperty("document");
    dbArray = [ props.getProperty("database") ];
    qr2.databases = dbArray;
    qr2.from      = props.getProperty("from");
    qr2.to        = props.getProperty("to");
    qr2.where     = props.getProperty("where");
    
    fieldArray = [];
    fieldArray[1] = props.getProperty("queryField1");
    fieldArray[2] = props.getProperty("queryField2");
    fieldArray[3] = props.getProperty("queryField3");
    qr2.fields    = fieldArray;

    queryId   = jaqiHandle.submitQueryAsync(qr2);
    query     = jaqiHandle.getQuery(queryId);
    // ... etc...
</cfscript>

Open in new window

0
 
CashmgmtAuthor Commented:
I got this error
error.JPG
0
 
CashmgmtAuthor Commented:
sorry _agx_ I see that the init has the actual file name and not the variable.  I changed it to the variable and now get this error:  The value Running example3: AdvancedSample2 cannot be converted to a number.
0
 
_agx_Commented:
My bad.  That's because it can't find the file.  That line should be this:

      fis = createObject("java", "java.io.FileInputStream").init( pathToConfig );

Just make sure the file path is correct, or you'll get the error again.
0
 
_agx_Commented:
> Running example3: AdvancedSample2 cannot be converted to a number.

   Oh, that's just an output line anyway. Either comment it out OR

   Change this:
   WriteOutput("Running example3: AdvancedSample2" + jaqiClient.getVersion() &"<br>");

   To this:
    WriteOutput("Running example3: AdvancedSample2"&  jaqiClient.getVersion() &"<br>");
0
 
CashmgmtAuthor Commented:
I got this error
error.JPG
0
 
_agx_Commented:
Expand the strack trace. What does it say?
0
 
_agx_Commented:
Also, are you _positive_ "order" is optional?
0
 
CashmgmtAuthor Commented:
I was just looking at that.  I think it might be required. I've attached the OrderBy class doc.
OrderBy.pdf
0
 
CashmgmtAuthor Commented:
_agx_, if you would like to see any of the class docs, I'll attach them if it will help?
0
 
_agx_Commented:
Let me see if I can figure out first.  I think an array is required, which may be a little tricker. Doable, just not as simple. Unfortunately I have a call coming up, so I won't get to it for an hour or two, okay?
0
 
CashmgmtAuthor Commented:
That's fine!! again thank you!!
0
 
_agx_Commented:
Okay, I'm not sure it'll will work. But try this for the "order" part. If it doesn't work, I have another idea

      OrderBy = createObject("java", "com.fiserv.ist.titan.jaqi.OrderBy");
      orderObj = OrderByClass.init( props.getProperty("orderBy"), true);
      orderArray = [];
      arrayAppend(orderArray, orderObj);
      qr2.order = javacast('com.fiserv.ist.titan.jaqi.OrderBy[]', orderArray);
        queryId       = jaqiHandle.submitQueryAsync(qr2);
      // ...
0
 
_agx_Commented:
Correction:

      orderByClass= createObject("java", "com.fiserv.ist.titan.jaqi.OrderBy");
      orderObj = OrderByClass.init( props.getProperty("orderBy"), true);
      orderArray = [];
      arrayAppend(orderArray, orderObj);
      qr2.order = javacast('com.fiserv.ist.titan.jaqi.OrderBy[]', orderArray);
        queryId       = jaqiHandle.submitQueryAsync(qr2);
      // ...
0
 
CashmgmtAuthor Commented:
sounds good, I will give it a shot and let you know tomorrow.  Thanks!!
0
 
_agx_Commented:
Okay, cool.
0
 
CashmgmtAuthor Commented:
Ok, I added the code and ran it and didn't get any errors.  The only thing I see on the screen is the version information.  So it looks like that step worked.
0
 
_agx_Commented:
Good! A step forward.  Try adding this piece next. Just to see if the basic query looping mechanism works first.  Again, totally untested. So watch out for typos.  

(You're on CF8 right? It's needed for some of the operators "!=" vs NEQ, "==" vs EQ, etc...)
<cfscript>
    nextRow       = 1;
    endRow       = 0;
    maxRow      = 1;    
    // TESTING: For safety abort looping after 50 tries
    safetyCounter = 1;
    abortCounter  = 50;

    if ((StateEnum.COMPLETED == query.getStatus.state)
                    && (query.getStatus.currentRowNumber == 0)) {
        WriteOutput("INFO: submit query completed successfully, but there was no results that matched your query");
    } 
    else {
        CurrThread = createObject("java", "java.lang.Thread").currentThread();
    
        do {
            // I'm not sure why they're sleeping here .. 
            // or if it's really needed 
            try {
                CurrThread.sleep(500);
            } 
            // I'm not _positive_ about this exception type ...
            catch (java.lang.InterruptedException x) {
                break;
            }
            
            // show data rows atmost 10 rows at a time
            maxRow = MIN(10, -nextRow + 1);
            endRow = nextRow + maxRow - 1;
            
            if (0 == endRow) {
                continue;
            }

            if (nextRow > endRow) {
                break;
            }

              WriteOutput("**************************************************************************");
            WriteOutput(" rows " & nextRow & " to "& (nextRow + maxRow - 1));
            WriteOutput("**************************************************************************");

            data = query.getData(nextRow, maxRow);
            // Save this till later
            ///System.out.println(toString(fieldInfo, data));

            nextRow += maxRow;
            
            safetyCounter = safetyCounter + 1;
        } 
        while (query.getStatus.state != StateEnum.FAILED && safetyCounter < abortCounter);
    
    } 
</cfscript>

Open in new window

0
 
_agx_Commented:
(Once you get it working... the code definitely needs a re-write because those continue and break statements are tres-unreadable IMHO ;-)
0
 
CashmgmtAuthor Commented:
I'm actually on CF7.  I changed the != to NEQ and == to EQ.  I'm getting this error:

Element COMPLETED is undefined in STATEENUM.  
 
 
The error occurred in C:\Inetpub\wwwroot\NewFrost\Titan2.cfm: line 42
 
40 :     abortCounter  = 50;
41 :  
42 :     if ((StateEnum.COMPLETED EQ query.getStatus.state)
43 :                     && (query.getStatus.currentRowNumber == 0)) {
44 :         WriteOutput("INFO: submit query completed successfully, but there was no results that matched your query");

 

--------------------------------------------------------------------------------
 
Thanks.
0
 
_agx_Commented:
Yes, that's another class.  Before the  do ... loop starts, create a reference so you can access it's constants.

      StateEnum = createObject("java", "com.fiserv.ist.titan.jaqi.StateEnum");

> && (query.getStatus.currentRowNumber == 0)) {

   ... Unfortunately I used a bunch of CF8 operators. You'll probably have to change others.
0
 
CashmgmtAuthor Commented:
Sorry for the delay getting back to you.  I ran it and it looks like it's trying to do something, but the page eventually times out.  The error I get is that IE can't display the webpage.
0
 
_agx_Commented:
Try commenting out the do and while {...} loop part for now. ie Run a single iteration only.  See if anything happen then. Their do ...loop and thread.sleep() looks a little fishy to me.  Also add a debug line in the catch{...} part, so you can see if an interrupt exception occurs. Maybe that's the issue.  (Unfortunately, without being able to test it, it's possible I didn't get that part right and the code's ending up with an infinite loop somehow. Possibly related to the InterruptedException ...

             catch (java.lang.InterruptedException x) {
                WriteOutput("InterruptedException detected ...<br>");
                break;
            }

0
 
CashmgmtAuthor Commented:
I will give it a try today and let you know.  Thanks.
0
 
_agx_Commented:
>  The error I get is that IE can't display the webpage.

    Also disable IE's friendly http error messages, if needed. So it's not hiding the real error message.
0
 
CashmgmtAuthor Commented:
Hi _agx_, I commented out the do while and I no longer get errors, what I see is the writeoutput that displays the version numbers.  
0
 
_agx_Commented:
Can you post the actual code used? Just from the do..loop section.  Because you should be seeing a line of row number debug output too.  So it's probably either an InterruptedException is occurring or the row numbers are wrong.  Can you dump the row number variables too (nextRow, maxRow, etc..)? What are the values?
0
 
CashmgmtAuthor Commented:
I dumped nextRow and it's 1 maxRow and endRow are both 0.
        //do { 
            // I'm not sure why they're sleeping here ..  
            // or if it's really needed  
            try { 
                CurrThread.sleep(500); 
            }  
            // I'm not _positive_ about this exception type ... 
            catch (java.lang.InterruptedException x) { 
                break; 
            } 
             
            // show data rows atmost 10 rows at a time 
            maxRow = MIN(10, -nextRow + 1); 
            endRow = nextRow + maxRow - 1; 
             
            if (0 EQ endRow) { 
                continue; 
            } 
 
            if (nextRow > endRow) { 
                break; 
            } 
 
              WriteOutput("**************************************************************************"); 
            WriteOutput(" rows " & nextRow & " to "& (nextRow + maxRow - 1)); 
            WriteOutput("**************************************************************************"); 
 
            data = query.getData(nextRow, maxRow); 
            // Save this till later 
            ///System.out.println(toString(fieldInfo, data)); 
 
            nextRow += maxRow; 
             
            safetyCounter = safetyCounter + 1; 
        }  
        //while (query.getStatus().state NEQ StateEnum.FAILED and safetyCounter < abortCounter); 
     
    //}  

Open in new window

0
 
_agx_Commented:
That's the actual code used? Weird, I didn't think "+=" worked on MX7.  Anyway, since it's just an example, if you can't get the row numbers to work. Just use hard coded numbers for now.  The important part is to see if it makes it past this line:

 data = query.getData(nextRow, maxRow);


 //do { 
            // I'm not sure why they're sleeping here ..  
            // or if it's really needed  
            try { 
                CurrThread.sleep(500); 
            }  
            // I'm not _positive_ about this exception type ... 
            catch (java.lang.InterruptedException x) { 
                WriteOutput("InterruptedException detected ...<br>");
                break; 
            } 
             
            // show data rows atmost 10 rows at a time 
            maxRow = MIN(10, query.getStatus().currentRowNumber-nextRow + 1); 
            endRow = nextRow + maxRow - 1; 
             
            if (0 EQ endRow) { 
                WriteOutput("0 EQ endRow...<br>");
                continue; 
            } 
 
            if (nextRow > endRow) { 
                WriteOutput("nextRow > endRow");
                break; 
            } 
 
              WriteOutput("**************************************************************************"); 
            WriteOutput(" rows " & nextRow & " to "& (nextRow + maxRow - 1)); 
            WriteOutput("**************************************************************************"); 
 
            data = query.getData(nextRow, maxRow); 
            // Save this till later 
            ///System.out.println(toString(fieldInfo, data)); 
 
            nextRow += maxRow; 
             
            safetyCounter = safetyCounter + 1; 
        //}  
        //while (query.getStatus().state NEQ StateEnum.FAILED and safetyCounter < abortCounter); 

        // clean up stuff...
        jaqiHandle.removeQuery(queryId);
        jaqiClient.releaseHandle(jaqiHandle);
        jaqiClient.close();

Open in new window

0
 
CashmgmtAuthor Commented:
Sorry for taking so long to reply.  I've didn't get a chance to try this again till today.  I noticed that the max =  row was missing the query.getStatus().currentRowNumber that the Java sample had.  I added that and now I'm getting this:

Running example3: AdvancedSample2 JaQIClient version 4.4.0.02 May 18th, 2009 JaQIServer version 4.4.0.02 May 18th, 2009 JaQILibrary version 4.4.0.02 May 18th, 2009 Copyright (c) 2002-2009 Fiserv http://www.fiserv.com 
************************************************************************** rows 1 to 10**************************************************************************************************************************************************** rows 11 to 20**************************************************************************************************************************************************** rows 21 to 24************************************************************************** 25 0 24

I put the loop back in also.
<cfscript> 
    nextRow       = 1; 
    end        = 0; 
    max        = 10;     
    // TESTING: For safety abort looping after 50 tries 
    safetyCounter = 1; 
    abortCounter  = 5; 
    
    StateEnum = createObject("java", "com.fiserv.ist.titan.jaqi.StateEnum");
 	
    if ((StateEnum.COMPLETED EQ query.getStatus().state) 
                    and (query.getStatus.currentRowNumber EQ 0)) { 
        WriteOutput("INFO: submit query completed successfully, but there was no results that matched your query"); 
    }  
    else { 
        CurrThread = createObject("java", "java.lang.Thread").currentThread(); 
     
        do { 
            // I'm not sure why they're sleeping here ..  
            // or if it's really needed  
            try { 
                CurrThread.sleep(500); 
            }  
            // I'm not _positive_ about this exception type ... 
            catch (java.lang.InterruptedException x) { 
                break; 
            } 
             
            // show data rows atmost 10 rows at a time 
            max = MIN(10, query.getStatus().currentRowNumber - nextRow + 1); 
            end = nextRow + max - 1; 
             
            if (0 EQ end) { 
                continue; 
            } 
 
            if (nextRow > end) { 
                break; 
            } 
 
            WriteOutput("**************************************************************************"); 
            WriteOutput(" rows " & nextRow & " to "& (nextRow + max - 1)); 
            WriteOutput("**************************************************************************"); 
 
            data = query.getData(nextRow, max); 
            // Save this till later 
            ///System.out.println(toString(fieldInfo, data)); 
 
            nextRow += max; 
             
            safetyCounter = safetyCounter + 1; 
        }  
        while (query.getStatus().state NEQ StateEnum.FAILED and safetyCounter < abortCounter); 
     
    }  
</cfscript>
<cfdump var="#nextRow#">
<cfdump var="#max#">
<cfdump var="#end#">

Open in new window

0
 
CashmgmtAuthor Commented:
I ran the java sample also and got 24 items, so it matches what I got with your CF code test.
0
 
_agx_Commented:
Awesome. So it's working now.  All we need to do is add back the part that shows the field info, and end part that converts some images to TIF (I think..?) and that's it.
0
 
CashmgmtAuthor Commented:
Because I need to view these images on a web page, the file needs to be converted to jpg. I see there's a convert class in the java sample.
0
 
_agx_Commented:
Oh, yes. I know you need to convert the images. I just meant there were only 2 pieces left before the code translation is done :)  I'll take a look at them in a bit.
0
 
_agx_Commented:
Sorry I just had a chance to get back to this.  There's only two parts left. One piece goes inside the loop and the other after the loop.

Inside the loop it loooks like they're calling a method named toString(FieldInfo[] fieldInfo, QueryResult data) to display the results in the current row of the query on screen.  In your real code, you'll want to convert that to something else (like a cf query object), rather than just displaying the stuff on screen. Do you know what type of class QueryResult is... a java ResultSet maybe?

The code to save the images (after the loop) is just a few lines. BUT .. they're using a "Util" object I can't see defined anywhere in the code. Do you know what class this is?

(NOTE: This won't work without declaring an instance of the "Util" class ...)
<cfscript>
     start = createObject("java", "java.lang.System").currentTimeMillis();
     // this might work too, undocumented
     // start = now().getTime();
     images = query.getImagesById(data.viewInfo);
     Util.saveImages(images, "image_", "tif", start);
</cfscript>



0
 
CashmgmtAuthor Commented:
Not a problem _agx_, I've included the doc for the QueryResult for you to look at.  I also added the code I found that converts the images to jpg.  I see in the code that it uses the class ImageOperations and I included the doc for that also.
            //
            // example 2: showing the getImagesOps(...) API
            ImageOperation imageOp = new ImageOperation();
            imageOp.xScale                    = 0.0F;
            imageOp.yScale                    = 0.0F;
            imageOp.orientation               = new FlipEnum[0];            
            imageOp.preferFasterInterpolation = true;
            imageOp.forceLittleEndian = false;
            imageOp.conversion = ConvertEnum.NO_CONVERSION;


            String forceLittleEndian = props.getProperty("forceLittleEndian");

            if(null != forceLittleEndian){
               
               if (0 == forceLittleEndian.compareToIgnoreCase("true")) {
                   imageOp.forceLittleEndian = true;
               } else if (0 == forceLittleEndian.compareToIgnoreCase("false")) {
                   imageOp.forceLittleEndian = false;
               }
            }            

            String convertTo = props.getProperty("convertTo");
            String ext = "";

            if(null != convertTo){

               if (0 == convertTo.compareToIgnoreCase("png")) {
                   imageOp.conversion = ConvertEnum.PNG;
                   ext = "png";
               } else if (0 == convertTo.compareToIgnoreCase("bmp")) {
                   imageOp.conversion = ConvertEnum.BMP;
                   ext = "bmp";
               } else if (0 == convertTo.compareToIgnoreCase("jpg")) {
                   imageOp.conversion = ConvertEnum.JPEG;
                   ext = "jpg";
               } else if (0 == convertTo.compareToIgnoreCase("tif")) {
                   imageOp.conversion = ConvertEnum.TIFF;
                   ext = "tif";
               } else if (0 == convertTo.compareToIgnoreCase("noconversion")) {
                   imageOp.conversion = ConvertEnum.NO_CONVERSION;
                   ext = "";
               }
            }

            
            
            start                             = System.currentTimeMillis();
            images                            =
                jaqiHandle.getImagesOps(datasource,
                                        props.getProperty("where"), imageOp);

            Util.saveImages(images, "image_", ext, start);

Open in new window

ScreenHunter-01-Apr.-22-15.38.gif
ScreenHunter-03-Apr.-22-15.45.gif
0
 
_agx_Commented:
> I also added the code I found that converts the images to jpg

    Is that in the original example that we're working on? I thought it was just this line:

         Util.saveImages(images, "image_", ext, start);

   If it's more than that, you should think about leaving some of this code in java.  Create your own
   utility wrapper.  Otherwise the CF code is going to be unmanageable, not to mention it will take forever to
   translate the whole thing in bits and pieces with stuff getting added on ;-)



0
 
CashmgmtAuthor Commented:
The sample we're Working on justsaves rhe tif image. The code I copied above is for converting it to another format which is what I'd need to do if I want to display the image on a browser.   Is there any good documentation on doing a utility wrapper?
0
 
_agx_Commented:
Not really. It would just be another java class that wraps whatever code you want.  Stick it in a jar and it to your classpath like the one(s) you're currently using.  The purpose is just to provide a simpler interface you can use from CF.  So you can just say  Util.doSomething(...)  as opposed to 25 lines of createObject plus the java code to call those methods.

0
 
CashmgmtAuthor Commented:
I've been out the last few days, I will give this a try.
0
 
CashmgmtAuthor Commented:
When I add the last part of the code, I get this:

Variable FIELDINFO is undefined.  
 
 
The error occurred in C:\Inetpub\wwwroot\NewFrost\Titan2.cfm: line 100
 
98 :       if ( IsDefined("data")) {
99 :             // display the headers
100 :             for (i = 1; i lte arrayLen(fieldInfo); i = i+1) {
101 :                   fieldName = fieldInfo[i].name;
102 :                   //Display field names

I can't find the fieldInfo field in the script.

<cfscript> 
    pathToConfig = "C:\Inetpub\wwwroot\NewFrost\sample.cfg"; 
 
    fis = createObject("java", "java.io.FileInputStream").init(pathToConfig); 
    props = createObject("java", "java.util.Properties").init(); 
    props.load( fis ); 
    fis.close(); 
         
    jaqiClient = createObject("java", "com.fiserv.ist.titan.jaqi.JaQIClient").init(props); 
    WriteOutput("Running example3: AdvancedSample2" & jaqiClient.getVersion() &"<br>"); 
    jaqiHandle = jaqiClient.getHandle(); 
    qr2 = createObject("java", "com.fiserv.ist.titan.jaqi.QueryRequest2").init(); 
    
    qr2.document  = props.getProperty("document"); 
    dbArray = [ props.getProperty("database") ]; 
    qr2.databases = dbArray; 
    qr2.from      = props.getProperty("from"); 
    qr2.to        = props.getProperty("to"); 
    qr2.where     = props.getProperty("where"); 
    fieldArray    = []; 
    fieldArray[1] = props.getProperty("queryField1"); 
    fieldArray[2] = props.getProperty("queryField2"); 
    fieldArray[3] = props.getProperty("queryField3"); 
    qr2.fields    = fieldArray; 
    orderByClass= createObject("java", "com.fiserv.ist.titan.jaqi.OrderBy");
    orderObj = OrderByClass.init( props.getProperty("orderBy"), true);
    orderArray = [];
    arrayAppend(orderArray, orderObj);
    qr2.order = javacast('com.fiserv.ist.titan.jaqi.OrderBy[]', orderArray);
    queryId       = jaqiHandle.submitQueryAsync(qr2);
    query         = jaqiHandle.getQuery(queryId); 
    // ... etc... 
</cfscript>
<cfscript> 
    nextRow    = 1; 
    end        = 0; 
    max        = 10;     
    // TESTING: For safety abort looping after 50 tries 
    safetyCounter = 1; 
    abortCounter  = 5; 
    
    StateEnum = createObject("java", "com.fiserv.ist.titan.jaqi.StateEnum");
 	
    if ((StateEnum.COMPLETED EQ query.getStatus().state) 
                    and (query.getStatus.currentRowNumber EQ 0)) { 
        WriteOutput("INFO: submit query completed successfully, but there was no results that matched your query"); 
    }  
    else { 
        CurrThread = createObject("java", "java.lang.Thread").currentThread(); 
     
        do { 
            // I'm not sure why they're sleeping here ..  
            // or if it's really needed  
            try { 
                CurrThread.sleep(500); 
            }  
            // I'm not _positive_ about this exception type ... 
            catch (java.lang.InterruptedException x) { 
                break; 
            } 
             
            // show data rows atmost 10 rows at a time 
            max = MIN(10, query.getStatus().currentRowNumber - nextRow + 1); 
            end = nextRow + max - 1; 
             
            if (0 EQ end) { 
                continue; 
            } 
 
            if (nextRow > end) { 
                break; 
            } 
 
            WriteOutput("**************************************************************************"); 
            WriteOutput(" rows " & nextRow & " to "& (nextRow + max - 1)); 
            WriteOutput("**************************************************************************"); 
 
            data = query.getData(nextRow, max); 
            // Save this till later 
            //System.out.println(toString(fieldInfo, data)); 
 
            nextRow += max; 
             
            safetyCounter = safetyCounter + 1; 
        }  
        while (query.getStatus().state NEQ StateEnum.FAILED and safetyCounter < abortCounter); 
     
    }  
</cfscript>

<cfdump var="#nextRow#">
<cfdump var="#max#">
<cfdump var="#end#">

<cfscript>
    // *** IMPORTANT: Make sure the loop variable names don't conflict
    // with those already in the rest of your code 
      if ( IsDefined("data")) {
            // display the headers
            for (i = 1; i lte arrayLen(fieldInfo); i = i+1) {
                  fieldName = fieldInfo[i].name;
                  //Display field names
              WriteOutput(fieldName &" "& chr(9));
          }
          //display the data 
          for (row = 1; row lte arrayLen(data.itemInfo); row = row+1) {
            for (col = 1; col lte arrayLen(data.itemInfo[row]); col = col +1) {
                value = data.itemInfo[row][col];
                    WriteOutput(value &" "& chr(9));
            }
                  // ....
            // new line
            WriteOutput(chr(10));
        }    
      }
</cfscript>

//As for the conversion, I still don't see the path of the "Util" class, but it's just a simple createObject("java", "path.to.Util")....  followed by this

<cfscript>
     start = createObject("java", "java.lang.System").currentTimeMillis();
     // this might work too, undocumented
     // start = now().getTime();
     images = query.getImagesById(data.viewInfo);
     Util.saveImages(images, "image_", "tif", start);
</cfscript>

//Then just close the objects at the end

<cfscript>
   if (IsDefined("jaqiClient")) {
       jaqiHandle.removeQuery(queryId);
       jaqiClient.releaseHandle(jaqiHandle);
       jaqiClient.close();
   }
</cfscript>

Open in new window

0
 
_agx_Commented:
It's near the top of the if / else / do ... loop:

      fieldInfo = query.getFields();
0
 
CashmgmtAuthor Commented:
Sorry _agx_, I've looked and can't find it.
0
 
_agx_Commented:
It's just the line I posted above :) You declare it before the do ... loop starts.    Here's where it is in the java code:


            Query       query     = jaqiHandle.getQuery(queryId);
            int         nextRow   = 1;
            int         end       = 0;
            int         max       = 1;
            FieldInfo[] fieldInfo = query.getFields();     <!---- HERE .....---->
            QueryResult data      = null;


>  // *** IMPORTANT: Make sure the loop variable names don't conflict
> <cfscript>
>    // *** IMPORTANT: Make sure the loop variable names don't conflict
>    // with those already in the rest of your code
>      if ( IsDefined("data")) {

I think you may have misunderstood that section.  In the java example, they have a function called toString(..) that's called on each loop:

        System.out.println(toString(fieldInfo, data));

All it does it prints out the field names and values to the screen.  The CF code is supposed to _replace_ that function. So obviously it must be inside your do...loop.  Really, you should replace it with a better function that does whatever you want. But at this point we're just trying to get things working. You can cleanup things later.



0
 
CashmgmtAuthor Commented:
_agx_, I feel like such an idiot.  How would I declare the FieldInfo variable?  
0
 
_agx_Commented:
Fortunately this one is simple. Just use

<cfscript>
      fieldInfo = query.getFields();
</cfscript>

Obviously add it to the right location in the code ;-)
0
 
CashmgmtAuthor Commented:
_agx_, I was able to finish it and I'm able to get the data and save the images.  I've attached a copy of the final code.  I want to thank you for all your time, couldn't have done it without your help!!
<cfscript> 
    pathToConfig = "C:\Inetpub\wwwroot\NewFrost\sample.cfg"; 
 
    fis = createObject("java", "java.io.FileInputStream").init(pathToConfig); 
    props = createObject("java", "java.util.Properties").init(); 
    props.load( fis ); 
    fis.close(); 
         
    jaqiClient = createObject("java", "com.fiserv.ist.titan.jaqi.JaQIClient").init(props); 
    WriteOutput("Running example3: AdvancedSample2" & jaqiClient.getVersion() &"<br>"); 
    jaqiHandle = jaqiClient.getHandle(); 
    qr2 = createObject("java", "com.fiserv.ist.titan.jaqi.QueryRequest2").init(); 
    
    qr2.document  = props.getProperty("document"); 
    dbArray = [ props.getProperty("database") ]; 
    qr2.databases = dbArray; 
    qr2.from      = props.getProperty("from"); 
    qr2.to        = props.getProperty("to"); 
    qr2.where     = props.getProperty("where"); 
    fieldArray    = []; 
    fieldArray[1] = props.getProperty("queryField1"); 
    fieldArray[2] = props.getProperty("queryField2"); 
    fieldArray[3] = props.getProperty("queryField3"); 
    qr2.fields    = fieldArray; 
    orderByClass= createObject("java", "com.fiserv.ist.titan.jaqi.OrderBy");
    orderObj = OrderByClass.init( props.getProperty("orderBy"), true);
    orderArray = [];
    arrayAppend(orderArray, orderObj);
    qr2.order = javacast('com.fiserv.ist.titan.jaqi.OrderBy[]', orderArray);
    queryId       = jaqiHandle.submitQueryAsync(qr2);
    query         = jaqiHandle.getQuery(queryId); 

    nextRow    = 1; 
    end        = 0; 
    max        = 10;     
    
    StateEnum = createObject("java", "com.fiserv.ist.titan.jaqi.StateEnum");
 	//data = createObject("java", "com.fiserv.ist.titan.jaqi.QueryResult");

 	
    if ((StateEnum.COMPLETED EQ query.getStatus().state) 
                    and (query.getStatus().currentRowNumber EQ 0)) { 
        WriteOutput("INFO: submit query completed successfully, but there was no results that matched your query"); 
    }  
    else { 
        CurrThread = createObject("java", "java.lang.Thread").currentThread(); 
     
        do { 
            // I'm not sure why they're sleeping here ..  
            // or if it's really needed  
            try { 
                CurrThread.sleep(500); 
            }  
            // I'm not _positive_ about this exception type ... 
            catch (java.lang.InterruptedException x) { 
                break; 
            } 
             
            // show data rows atmost 10 rows at a time 
            max = MIN(10, query.getStatus().currentRowNumber - nextRow + 1); 
            end = nextRow + max - 1; 
             
            if (0 EQ end) { 
                continue; 
            } 
 
            if (nextRow > end) { 
                break; 
            } 
 
            WriteOutput("************************************"); 
            WriteOutput(" rows " & nextRow & " to "& (nextRow + max - 1)); 
            WriteOutput("************************************");
            WriteOutput('<br>'); 
 			
            data = query.getData(nextRow, max); 
            // Save this till later 
           // WriteOutput(toString(data)); 
           
           buffer = CreateObject("java","java.lang.StringBuffer").Init();
		
           for (row = 1; row lte arrayLen(data.itemInfo); row = row+1) {
             for (col = 1; col lte arrayLen(data.itemInfo[row]); col = col +1) {             	 
                 buffer.append(' ');
                 buffer.append(data.itemInfo[row][col]);
                 buffer.append(' ');
             }
             
             for (col = 1; col lte arrayLen(data.viewInfo[row]); col = col +1) {
                 buffer.append(' ');
                 buffer.append(data.viewInfo[row][col]);
                 buffer.append(' ');       
             }             
            
                buffer.append('<br>');
                               
	        	start = createObject("java", "java.lang.System").currentTimeMillis();
			    Util = createObject("java", "Util");
			    images = query.getImagesById(data.viewInfo);
			    Util.saveImages(images, "image_", "tif", start);                  
           }
            
            WriteOutput(buffer); 
            
            nextRow = nextRow + max; 
             
        }  
        while (query.getStatus().state NEQ StateEnum.FAILED); 
    }  
   if (IsDefined("jaqiClient")) {
       jaqiHandle.removeQuery(queryId);
       jaqiClient.releaseHandle(jaqiHandle);
       jaqiClient.close();
   }    
</cfscript>

Open in new window

0
 
CashmgmtAuthor Commented:
Great working with _agx_.
0
 
_agx_Commented:
Awesome!  Congratulations on getting everything working :)  You deserve it.  
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.