Skip to content

Commit

Permalink
Alias binding: bugfixes (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-haulmont authored Jun 10, 2020
1 parent bd31578 commit a6db457
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Table of Contents

| Platform Version | Add-on Version |
| ---------------- | -------------- |
| 7.2.x | 0.12.x - 0.13.x|
| 7.2.x | 0.12.x - 0.14.x|
| 7.1.x | 0.10.x - 0.11.x|
| 7.0.x | 0.8.x - 0.9.x |
| 6.10.x | 0.7.x |
Expand Down
10 changes: 3 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ apply(plugin: 'cuba')
cuba {
artifact {
group = 'de.diedavids.cuba.dataimport'
version = project.properties['version'].replaceAll('-SNAPSHOT', '')
version = project.properties['version'].replaceAll('-SNAPSHOT', '')
isSnapshot = project.properties['version'].contains('-SNAPSHOT')
}
tomcat {
Expand Down Expand Up @@ -133,7 +133,6 @@ test.finalizedBy(project.tasks.cobertura)
test.finalizedBy(project.tasks.coberturaCheck)



configure([globalModule, coreModule, guiModule, webModule]) {
apply(plugin: 'java')
apply(plugin: 'maven')
Expand Down Expand Up @@ -304,15 +303,15 @@ configure(coreModule) {
host = 'localhost'
dbUser = 'sa'
dbPassword = ''
}
}

task updateDb(dependsOn: assembleDbScripts, description: 'Updates local database', type: CubaDbUpdate) {
dbName = 'ddcdi4'
dbms = 'hsql'
host = 'localhost'
dbUser = 'sa'
dbPassword = ''
}
}


task createTestDb(dependsOn: assembleDbScripts, description: 'Creates local HSQL database', type: CubaDbCreation) {
Expand Down Expand Up @@ -383,9 +382,6 @@ configure(webModule) {
}





task undeploy(type: Delete, dependsOn: ":${modulePrefix}-web:cleanConf") {
delete("$cuba.tomcat.dir/shared")
delete("$cuba.tomcat.dir/webapps/${modulePrefix}-core")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ class AttributeBindRequest {

String getRawValue() {
def alias = importAttributeMapper.fileColumnAlias
if (importAttributeMapper.isRequiredColumn && !dataRow.hasProperty(alias))
if (importAttributeMapper.isRequiredColumn && !dataRow.hasProperty(alias)) {
throw new MissingPropertyException(alias)
}

((String) dataRow[alias]).trim()
def columnValue = dataRow[alias] ?: ''
((String) columnValue).trim()
}

String getImportEntityClassName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class ImportExecutionIntegrationTest extends AbstractImportIntegrationTest {
importConfiguration = new ImportConfiguration(
entityClass: 'ddcdi$MlbTeam',
importAttributeMappers: [
new ImportAttributeMapper(attributeType: AttributeType.DIRECT_ATTRIBUTE, entityAttribute: 'name', fileColumnAlias: 'name', fileColumnNumber: 0),
new ImportAttributeMapper(attributeType: AttributeType.DIRECT_ATTRIBUTE, entityAttribute: 'code', fileColumnAlias: 'code', fileColumnNumber: 1),
new ImportAttributeMapper(attributeType: AttributeType.DIRECT_ATTRIBUTE, entityAttribute: 'name', fileColumnAlias: 'name', fileColumnNumber: 0, 'isRequiredColumn': true),
new ImportAttributeMapper(attributeType: AttributeType.DIRECT_ATTRIBUTE, entityAttribute: 'code', fileColumnAlias: 'code', fileColumnNumber: 1, 'isRequiredColumn': true),
],
transactionStrategy: ImportTransactionStrategy.SINGLE_TRANSACTION
)
Expand Down Expand Up @@ -77,8 +77,8 @@ class ImportExecutionIntegrationTest extends AbstractImportIntegrationTest {
importConfiguration = new ImportConfiguration(
entityClass: 'ddcdi$MlbTeam',
importAttributeMappers: [
new ImportAttributeMapper(attributeType: AttributeType.DIRECT_ATTRIBUTE, entityAttribute: 'name', fileColumnAlias: 'name', fileColumnNumber: 0),
new ImportAttributeMapper(attributeType: AttributeType.DIRECT_ATTRIBUTE, entityAttribute: 'code', fileColumnAlias: 'code', fileColumnNumber: 1),
new ImportAttributeMapper(attributeType: AttributeType.DIRECT_ATTRIBUTE, entityAttribute: 'name', fileColumnAlias: 'name', fileColumnNumber: 0, 'isRequiredColumn': true),
new ImportAttributeMapper(attributeType: AttributeType.DIRECT_ATTRIBUTE, entityAttribute: 'code', fileColumnAlias: 'code', fileColumnNumber: 1, 'isRequiredColumn': true),
],
transactionStrategy: ImportTransactionStrategy.SINGLE_TRANSACTION
)
Expand All @@ -100,15 +100,16 @@ class ImportExecutionIntegrationTest extends AbstractImportIntegrationTest {
ImportExecutionDetail importExecutionDetail = persistedImportExecution.details[0]
assertThat(importExecutionDetail.category).isEqualTo(ImportExecutionDetailCategory.DATA_BINDING)
}

@Test
void "doDataImport stores an exception in the execution due to a type mismatch between import mappers and import data"() {

// given:
importConfiguration = new ImportConfiguration(
entityClass: 'ddcdi$MlbTeam',
importAttributeMappers: [
new ImportAttributeMapper(attributeType: AttributeType.DIRECT_ATTRIBUTE, entityAttribute: 'name', fileColumnAlias: 'name', fileColumnNumber: 0),
new ImportAttributeMapper(attributeType: AttributeType.DIRECT_ATTRIBUTE, entityAttribute: 'code', fileColumnAlias: 'code', fileColumnNumber: 1),
new ImportAttributeMapper(attributeType: AttributeType.DIRECT_ATTRIBUTE, entityAttribute: 'name', fileColumnAlias: 'name', fileColumnNumber: 0, 'isRequiredColumn': true),
new ImportAttributeMapper(attributeType: AttributeType.DIRECT_ATTRIBUTE, entityAttribute: 'code', fileColumnAlias: 'code', fileColumnNumber: 1, 'isRequiredColumn': true),
],
transactionStrategy: ImportTransactionStrategy.SINGLE_TRANSACTION
)
Expand All @@ -131,4 +132,32 @@ class ImportExecutionIntegrationTest extends AbstractImportIntegrationTest {
assertThat(importExecutionDetail.category).isEqualTo(ImportExecutionDetailCategory.DATA_BINDING)
}


@Test
void "doDataImport passes the execution when import mappers contains optional columns and import data is missing columns"() {

// given:
importConfiguration = new ImportConfiguration(
entityClass: 'ddcdi$MlbTeam',
importAttributeMappers: [
new ImportAttributeMapper(attributeType: AttributeType.DIRECT_ATTRIBUTE, entityAttribute: 'name', fileColumnAlias: 'name', fileColumnNumber: 0, 'isRequiredColumn': true),
new ImportAttributeMapper(attributeType: AttributeType.DIRECT_ATTRIBUTE, entityAttribute: 'code', fileColumnAlias: 'code', fileColumnNumber: 1, 'isRequiredColumn': false),
],
transactionStrategy: ImportTransactionStrategy.SINGLE_TRANSACTION
)

// and:
ImportData importData = createData([
[name: 1],
[name: 2]
])

// when:
ImportExecution importExecution = sut.doDataImport(importConfiguration, importData)

// then:
ImportExecution persistedImportExecution = simpleDataLoader.load(ImportExecution, importExecution.getId(), "importExecution-with-details-view")
assertThat(persistedImportExecution.entitiesImportSuccess).isEqualTo(2)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class ImportDataImpl implements ImportData {
@Override
ColumnValidationResult isCompatibleWith(List<ImportAttributeMapper> attributeMappers) {
List<String> invalidColumns = attributeMappers
.findAll { attributeMapper -> isInvalidColumn(attributeMapper)}
.collect { it.fileColumnAlias }
.findAll { attributeMapper -> isInvalidColumn(attributeMapper) }
*.fileColumnAlias

new ColumnValidationResult(invalidColumns.isEmpty(), invalidColumns)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import de.diedavids.cuba.dataimport.dto.ColumnValidationResult

class ImportDataImportConfigurationMatchException extends RuntimeException {

private ColumnValidationResult result
public static final String DELIMITER = ', '
final private ColumnValidationResult result

ImportDataImportConfigurationMatchException(ColumnValidationResult result) {
super('Import File does not match import configuration. Please check required columns: '
+ result.getColumns().join(", "))
+ result.columns.join(DELIMITER))
this.result = result
}

String getResult() {
return result.getColumns().join(", ")
result.columns.join(DELIMITER)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class ImportWithImportConfigurationWizard extends AbstractEditor<ImportConfigura
log.error(e.message, e)

startImport.enabled = false
showNotification(formatMessage('uploadFileDoesNotMatchExpectedStructure', e.getResult()),
showNotification(formatMessage('uploadFileDoesNotMatchExpectedStructure', e.result),
Frame.NotificationType.ERROR)

toStep1()
Expand Down

0 comments on commit a6db457

Please sign in to comment.