Page 1 of 1

Fail to create CVSrowset

Posted: Fri Jul 07, 2017 7:04 am
by anutta78
Hello,

I have GA version 5.4.1
I need to send csv file to REST API
I created a project:
ReadCSV, WriteJson, POST Json to REST
2 issues:
1.My rowset loos like this in the json file
com.linoma.ga.projects.tasks.converters.csv.CSVRowSet@58dce226
2.POST command returns success but no files were sent..
Below project XML.
Thank you for you help
Code: Select all
<project name="send csv to REST" mainModule="Main" version="2.0" logLevel="verbose">

	<module name="Main">

		<readCSV inputFile="\Import\IC230-testanna2.csv" 
outputRowSetVariable="currentfilecontent"   fieldDelimiter="comma"   version="1.0">
			<data>
				<column index="1" />
				<column index="2" />
				<column index="3" />
				<column index="4" />
				<column index="5" />
				<column index="6" />
				<column index="7" />
				<column index="8" />
				<column index="9" />
				<column index="10" />
				<column index="11" />
				<column index="12" />
				<column index="13" />
				<column index="14" />
				<column index="15" />
				<column index="16" />
				<column index="17" />
			</data>
		</readCSV>


		<jsonWrite outputFile="\Import\jsonoutput.json" whenFileExists="overwrite" outputFileVariable="filetoporcess" version="1.0">
			<object name="{">
				<field name="Protocol" value="AnnaTest6" />
				<field name="FileContents" value="${currentfilecontent}" />
			</object>
		</jsonWrite>


		<restPost resourceId="Test_rest" uri="DIC230011/api/UserSiteImportTest/" inputFile="${filetoporcess}" contentType="application/json" responseBodyDestination="none" responseHeadersDestination="none" version="1.0" logLevel="debug" disabled="false">
			<header name="x-apiKey" value="12365478" />
		</restPost>

	</module>

</project>

Re: Fail to create CVSrowset

Posted: Tue Jul 11, 2017 11:30 am
by Support_Rick
You're using the Rowset Value incorrectly. The way you're using it is as a pointer (thus the "com.linoma.ga.projects.tasks.converters.csv.CSVRowSet@58dce226" value)

Try setting the contents of the CSV to a variable named "FileContents" like this:

<setVariable name="FileContents" inputFile="\Import\IC230-testanna2.csv" version="2.0" />

Then print that as the value needed inside your JSON file instead.

Re: Fail to create CVSrowset

Posted: Tue Jul 11, 2017 1:13 pm
by Support_Tim
Hi Annuta78,

Your project appears to be trying to upload a JSON file created from a CSV file. The Write JSON seems to be the issue since you are seeing a successful post. Here is an example based on your project. It shows how you need to add the field elements for each column in the rowset, which is an array.

The HTTP Post is disabled, so you will need to enable it. Then just add the rest of your fields as I have done for columns 1-3, and consult the RESTful HTTP host’s documentation to see what format and labels are expected by the server.

If you are trying to post a CSV file, you would not need to read the data from it and create a JSON. You would simply post it with a post task like you have in your project.

Code: Select all
<project name="REST_POST send csv to REST" mainModule="Main" version="2.0" logLevel="debug">

                <module name="Main">

                                <createWorkspace version="1.0" />


                                <readCSV inputFile="C:\Users\TMcCall\Documents\_Case Docs\50313\Upload_Full_06Jul2017183019.csv" outputRowSetVariable="currentfilecontent" fieldDelimiter="comma" version="1.0">
                                                <data>
                                                                <column index="1" />
                                                                <column index="2" />
                                                                <column index="3" />
                                                                <column index="4" />
                                                                <column index="5" />
                                                                <column index="6" />
                                                                <column index="7" />
                                                                <column index="8" />
                                                                <column index="9" />
                                                                <column index="10" />
                                                                <column index="11" />
                                                                <column index="12" />
                                                                <column index="13" />
                                                                <column index="14" />
                                                                <column index="15" />
                                                                <column index="16" />
                                                                <column index="17" />
                                                </data>
                                </readCSV>


                                <jsonWrite outputFile="${system.job.workspace}\jsonoutput.json" whenFileExists="overwrite" tidy="true" defaultNullSubstitute=" " outputFileVariable="filetoporcess" version="1.0">
                                                <object name="wrapper">
                                                                <array name="Data" inputRowSetVariable="${currentfilecontent}">
                                                                                <object name="{">
                                                                                                <field name="Site Code" value="${currentfilecontent[1]}" />
                                                                                                <field name="Site Name" value="${currentfilecontent[2]}" />
                                                                                                <field name="Primary Investigator" value="${currentfilecontent[3]}" />
                                                                                </object>
                                                                </array>
                                                </object>
                                </jsonWrite>


                                <restPost resourceId="[removed]" uri="DIC230011/api/UserSiteImportTest/" inputFile="${system.job.workspace}/${filetoporcess}" contentType="application/json" responseBodyDestination="none" responseHeadersDestination="none" version="1.0" logLevel="debug" disabled="true">
                                                <header name="x-apiKey" value="12365478" />
                                </restPost>


                                <deleteWorkspace version="1.0" />

                </module>

</project>

Re: Fail to create CVSrowset

Posted: Wed Jul 12, 2017 9:29 am
by anutta78
Support_Rick wrote:
You're using the Rowset Value incorrectly. The way you're using it is as a pointer (thus the "com.linoma.ga.projects.tasks.converters.csv.CSVRowSet@58dce226" value)

Try setting the contents of the CSV to a variable named "FileContents" like this:

<setVariable name="FileContents" inputFile="\Import\IC230-testanna2.csv" version="2.0" />

Then print that as the value needed inside your JSON file instead.

THANK YOU, Rick!