Hi Isomorphic,
while the issue in this thread is still valid, the real issue I had there was a different one, related to DataImport (v11.1p_2017-12-05). In absence of the feature mentioned here
I need to convert my values to CSV, and then run DataImport. DataImport does only convert "true" to true, "false" is converted to null.
Please see this example:
supplyItem.ds.xml change:
SupplyItem.java:
ARC request (good):
Data in Eclipse when setting a breakpoint:
ARC request (bad):
Data in Eclipse when setting a breakpoint:
As you can see, the value is null, and not false, as expected.
This one is a important one for me, as basically all RESTHandler issues (other boolean issue, queue status and enhancement for this usecase (more easy FK-resolution via RESTHandler) and DataImport function and docs improvement, RESTHandler with relatedUpdate (not as important as the others for me right now)).
I also made these enhancement suggestion: more powerful Expanded Raw REST mode URI Syntax (minor for me right now).
Best regards
Blama
while the issue in this thread is still valid, the real issue I had there was a different one, related to DataImport (v11.1p_2017-12-05). In absence of the feature mentioned here
Generally speaking this is working, but IMHO the workaround with CSV should not be necessary. DataImport-methods should have an overload that take Map<String, Object> and do the conversion displayName->ID
Please see this example:
supplyItem.ds.xml change:
Code:
<field name="inStock" type="boolean" length="1" title="In Stock" escapeHTML="true" sqlStorageStrategy="singleCharYN" /> <field name="nextShipment" type="date" title="Next Shipment"/> </fields> <serverObject lookupStyle="new" className="com.smartgwt.sample.server.listener.SupplyItem" /> <operationBindings> <operationBinding operationType="custom" operationId="addApi" serverMethod="addApi" /> </operationBindings>
Code:
package com.smartgwt.sample.server.listener; import java.io.Reader; import java.io.StringReader; import java.io.StringWriter; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import com.isomorphic.datasource.DSRequest; import com.isomorphic.datasource.DSResponse; import com.isomorphic.datasource.DataSource; import com.isomorphic.tools.DataImport; import com.isomorphic.tools.DataImport.ImportFormat; public class SupplyItem { public DSResponse addApi(DSRequest dsRequest, HttpServletRequest servletRequest) throws Exception { @SuppressWarnings("unchecked") Map<String, Object> map = dsRequest.getValues(); StringWriter csvHeader = new StringWriter(); StringWriter csvData = new StringWriter(); for (Map.Entry<String, Object> entry : map.entrySet()) { csvHeader.append(entry.getKey() + ";"); if (entry.getValue() != null) csvData.append("\"" + entry.getValue().toString().replace("\"", "\"\"") + "\"" + ";"); else csvData.append(";"); } Reader jsonReader = new StringReader(csvHeader.toString() + "\r\n" + csvData.toString()); DataImport dataImporter = new DataImport(ImportFormat.CSV, ";"); dataImporter.setPopulateDisplayFields(true); @SuppressWarnings("unchecked") List<Map<String, Object>> dataImporterResult = dataImporter.importDataSourceRecords(jsonReader, dsRequest.getDataSourceName()); DSRequest addRequest = new DSRequest(dsRequest.getDataSourceName(), DataSource.OP_ADD, dsRequest.getRPCManager()); addRequest.setValues(dataImporterResult); DSResponse addResponse = addRequest.execute(); return addResponse; } }
Code:
<request> <dataSource>supplyItem</dataSource> <operationType>custom</operationType> <operationId>addApi</operationId> <data> <itemName>Agent pen</itemName> <SKU>007</SKU> <category>Office Paper Products</category> <unitCost>0.07</unitCost> <units>Ea</units> [B]<inStock>true</inStock>[/B] </data> </request>
Code:
csvData: "Agent pen";"007";"Office Paper Products";"0.07";"Ea";[B]"true"[/B]; dataImporterResult: [{itemName=Agent pen, unitCost=0.07, [B]inStock=true[/B], units=Ea, category=Office Paper Products, SKU=007}]
Code:
<request> <dataSource>supplyItem</dataSource> <operationType>custom</operationType> <operationId>addApi</operationId> <data> <itemName>Agent pen</itemName> <SKU>007</SKU> <category>Office Paper Products</category> <unitCost>0.07</unitCost> <units>Ea</units> [B]<inStock>false</inStock>[/B] </data> </request>
Code:
csvData: "Agent pen";"007";"Office Paper Products";"0.07";"Ea";[B]"false"[/B]; dataImporterResult: {itemName=Agent pen, unitCost=0.07, [B]inStock=null[/B], units=Ea, category=Office Paper Products, SKU=007}
This one is a important one for me, as basically all RESTHandler issues (other boolean issue, queue status and enhancement for this usecase (more easy FK-resolution via RESTHandler) and DataImport function and docs improvement, RESTHandler with relatedUpdate (not as important as the others for me right now)).
I also made these enhancement suggestion: more powerful Expanded Raw REST mode URI Syntax (minor for me right now).
Best regards
Blama
Comment