Search in sources :

Example 6 with CsvImportException

use of org.motechproject.mds.exception.csv.CsvImportException in project motech by motech.

the class CsvImporterExporter method buildRelationshipCollection.

private Collection<Object> buildRelationshipCollection(RelationshipHolder relationshipHolder) {
    String collectionClassName = relationshipHolder.getCollectionClassName();
    Class collectionClass = TypeHelper.suggestCollectionImplementation(collectionClassName);
    if (collectionClass == null) {
        return new ArrayList<>();
    } else {
        try {
            return (Collection<Object>) collectionClass.newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            throw new CsvImportException("Unable to parse collection type " + relationshipHolder.getCollectionClassName(), e);
        }
    }
}
Also used : CsvImportException(org.motechproject.mds.exception.csv.CsvImportException) ArrayList(java.util.ArrayList) Collection(java.util.Collection)

Aggregations

CsvImportException (org.motechproject.mds.exception.csv.CsvImportException)6 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 FieldDto (org.motechproject.mds.dto.FieldDto)2 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 CsvImportResults (org.motechproject.mds.dto.CsvImportResults)1 DefaultCsvImportCustomizer (org.motechproject.mds.service.DefaultCsvImportCustomizer)1 MotechDataService (org.motechproject.mds.service.MotechDataService)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1 CsvMapReader (org.supercsv.io.CsvMapReader)1