Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    DataImport.setPopulateDisplayFields(true) doesn't work if "columnRemap" has been applied

    Hi Isomorphic,

    field "ReportsTo" is null in my test case what is INHO a bug.
    SmartClient Version: v12.0p_2019-12-14/PowerEdition Deployment (built 2019-12-14).

    employeesUpload.ds.xml
    Code:
    <DataSource xmlns="lmscompany/ds" xmlns:fmt="lmscompany/fmt" ID="employeesUpload" serverType="sql" tableName="employeeTable" recordName="employee" useAnsiJoins="true">
    <fmt:bundle basename="com.smartgwt.sample.server.listener.DSXMLResources-utf8" encoding="utf-8" />
        <fields>
            <field name="EmployeeId" title="Employee ID" type="integer" primaryKey="true" required="true"/>
    
            <field name="Name" uploadFieldName="Name" title="Name" type="text" length="128">
                <validators>
                    <validator type="isUnique" caseSensitive="true" />
                </validators>
            </field>
    
            <field name="ReportsTo" displayField="ReportsToName" uploadFieldName="CustomReportsTo" required="true" importStrategy="display"
                foreignKey="employees.EmployeeId" relatedTableAlias="relatedReportsTo">
                <title><fmt:message key="ReportsTo" /></title>
                <validators>
                    <validator type="hasRelatedRecord" errorMessage="Unknown ReportsTo" />
                </validators>
            </field>
            <field name="ReportsToName" includeFrom="employees.Name" includeVia="ReportsTo" />
    
            <field name="Job" uploadFieldName="Job" title="Title" type="text" length="128">
                <validators>
                    <validator type="isOneOf" />
                </validators>
                <valueMap>
                    <value>Developer</value>
                    <value>IT-Infrastructure</value>
                    <value>Other</value>
                </valueMap>
            </field>
    
            <field name="Gender" uploadFieldName="Gender" title="Gender" type="text" length="7">
                <validators>
                    <validator type="isOneOf" />
                </validators>
                <valueMap>
                    <value>male</value>
                    <value>female</value>
                </valueMap>
            </field>
    
            <field name="Salary" uploadFieldName="Salary" title="Salary" type="integer">
            </field>
        </fields>
        <serverObject lookupStyle="new" className="com.smartgwt.sample.server.listener.EmployeesUpload" />
        <operationBindings>
            <operationBinding operationType="custom" operationId="upload" serverMethod="upload" />
        </operationBindings>
    </DataSource>
    EmployeesUpload.java
    Code:
    package com.smartgwt.sample.server.listener;
    
    import java.util.HashMap;
    import java.util.Map;
    
    import javax.servlet.http.HttpServletRequest;
    
    import com.isomorphic.datasource.DSRequest;
    import com.isomorphic.datasource.DSResponse;
    import com.isomorphic.tools.DataImport;
    
    public class EmployeesUpload {
        public DSResponse upload(DSRequest dsRequest, HttpServletRequest servletRequest) throws Exception {
            @SuppressWarnings("unchecked")
            Map<String, Object> requestValues = dsRequest.getValues();
    
            Map<String, String> columnRemap = new HashMap<>();
            columnRemap.put("EmployeeId", "EmployeeId");
            columnRemap.put("Name", "Name");
            columnRemap.put("CustomReportsTo", "ReportsTo");
            columnRemap.put("ReportsToName", "ReportsToName");
            columnRemap.put("Job", "Job");
            columnRemap.put("Gender", "Gender");
            columnRemap.put("Salary", "Salary");
    
            DataImport dataImporter = new DataImport();
            dataImporter.setPopulateDisplayFields(true);
    
            Map<String, Object> importedFields = dataImporter.importDataSourceRecord(requestValues, columnRemap, "employeesUpload");
            if (importedFields.get("ReportsTo") != null)
                return new DSResponse(dsRequest.getDataSource()).setSuccess();
            else
                return new DSResponse(dsRequest.getDataSource()).setFailure("ReportsTo is null!");
        }
    }
    DSXMLResources-utf8.properties
    Code:
    ReportsTo = MyManager
    Code:
    POST to http://127.0.0.1:8888/builtinds/sc/RESTHandler
    
    Body:
    <request>
        <dataSource>employeesUpload</dataSource>
        <operationType>custom</operationType>
        <operationId>upload</operationId>
        <data>
            <EmployeeId>100001</EmployeeId>
              <Name>New colleague</Name>
            <CustomReportsTo>Charles Madigen</CustomReportsTo>
            <Job>Developer</Job>
            <Gender>male</Gender>
            <Salary>12345</Salary>
          </data>
      </request>
    Best regards
    Pavo

    #2
    Here you added method "importDataSourceRecord".
    If I use "importDataSourceRecords" instead
    Code:
    DataImport dataImporter = new DataImport(ImportFormat.CSV, ";");
    Reader emailContentReader = new StringReader(mailCSVFormat);
    List<Map<String, Object>> dataImporterResult = dataImporter.importDataSourceRecords(emailContentReader, columnRemap,
                                        importDS);
    then it works. Hope this information can help you.

    Comment


      #3
      This is fixed and available for download in nightly builds since Feb 29 (today).

      Comment


        #4
        Hi Isomorphic,

        I just tested this one, it works, thank you!

        Best,
        Pavo

        Comment

        Working...
        X