DataImporter unable to import CSV

I’m looking to import a CSV using an input stream in to my database. I have built the import configuration as follows:

            ImportConfiguration config = ImportConfiguration.builder(SIMCards.class, InputDataFormat.CSV)
                    .addSimplePropertyMapping("LANSubnet","lanSubnet")
                    .addSimplePropertyMapping("LANIP","lanIpMask")
                    .addSimplePropertyMapping("ComputerIP","computerIP")
                    .addSimplePropertyMapping("TTK", "dmvpnSpokeIp")
                    .addSimplePropertyMapping("Operator","operator")
                    .addSimplePropertyMapping("SIMIP","simIpSubnet")
                    .addSimplePropertyMapping("MSISDN","msisdn")
                    .addSimplePropertyMapping("series","simNumber")
                    .addSimplePropertyMapping("serial","routerSerial")
                    .withTransactionStrategy(ImportTransactionStrategy.TRANSACTION_PER_ENTITY)
                    .build();

The README on the dataimporter, says to use

ImportResult importData(ImportConfiguration config, InputStream importedCsv);

However, IntelliJ is telling me it is expecting a ; after importData.

I have tried the following code:

ImportResult inputData = new DataImporterImpl().importData(configuration, importedCsv);

System.out.println(inputData.getErrorMessage());
System.out.println(inputData.isSuccess());
System.out.println(inputData.getFailedEntities());
System.out.println(inputData.getImportedEntityIds());

This gets me a step further, but the import will not complete, and does not give me any indication as to why. Is anyone able to assist?

java.lang.NullPointerException: null
	at io.jmix.dataimport.impl.DataImporterImpl.importData(DataImporterImpl.java:62) ~[jmix-dataimport-1.5.3.jar:na]
	at com.triwonderdigital.systemcenter.screen.simcards.SIMCardsBrowser.onFileFieldFileUploadSucceed(SIMCardsBrowser.java:98) ~[main/:na]
	at io.jmix.core.common.event.EventHub.publish(EventHub.java:170) ~[jmix-core-1.5.3.jar:na]
	at io.jmix.ui.component.impl.AbstractComponent.publish(AbstractComponent.java:85) ~[jmix-ui-1.5.3.jar:na]
	at io.jmix.ui.component.impl.AbstractSingleFileUploadField.fireFileUploadSucceed(AbstractSingleFileUploadField.java:314) ~[jmix-ui-1.5.3.jar:na]
	at io.jmix.ui.component.impl.AbstractSingleFileUploadField.onUploadSucceeded(AbstractSingleFileUploadField.java:147) ~[jmix-ui-1.5.3.jar:na]

Hi,

You need to inject DataImporter instead of using DataImportImpl. It is a spring bean, so you should never instantiate them on your own. Just declare that you need an instance (e.g with @Autowired annotation on the field) and spring will do its magic.

Cheers
Mario

1 Like