diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 8911fef2d..39e942965 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -674,52 +674,71 @@ public class BeanMappingMethod extends NormalTypeMappingMethod { // fetch settings from element to implement ReportingPolicyPrism unmappedTargetPolicy = getUnmappedTargetPolicy(); - //we handle automapping forged methods differently than the usual source ones. in - if ( method instanceof ForgedMethod && ( (ForgedMethod) method ).isForgedNamedBased() ) { - - ForgedMethod forgedMethod = (ForgedMethod) this.method; - if ( targetProperties.isEmpty() || !unprocessedTargetProperties.isEmpty() ) { - - if ( forgedMethod.getHistory() == null ) { - Type sourceType = this.method.getParameters().get( 0 ).getType(); - Type targetType = this.method.getReturnType(); - ctx.getMessager().printMessage( - this.method.getExecutable(), - Message.PROPERTYMAPPING_FORGED_MAPPING_NOT_FOUND, - sourceType, - targetType, - targetType, - sourceType - ); - } - else { - ForgedMethodHistory history = forgedMethod.getHistory(); - ctx.getMessager().printMessage( - this.method.getExecutable(), - Message.PROPERTYMAPPING_MAPPING_NOT_FOUND, - history.createSourcePropertyErrorMessage(), - history.getTargetType(), - history.createTargetPropertyName(), - history.getTargetType(), - history.getSourceType() - ); - } - + if ( method instanceof ForgedMethod && targetProperties.isEmpty() ) { + //TODO until we solve 1140 we report this error when the target properties are empty + ForgedMethod forgedMethod = (ForgedMethod) method; + if ( forgedMethod.getHistory() == null ) { + Type sourceType = this.method.getParameters().get( 0 ).getType(); + Type targetType = this.method.getReturnType(); + ctx.getMessager().printMessage( + this.method.getExecutable(), + Message.PROPERTYMAPPING_FORGED_MAPPING_NOT_FOUND, + sourceType, + targetType, + targetType, + sourceType + ); + } + else { + ForgedMethodHistory history = forgedMethod.getHistory(); + ctx.getMessager().printMessage( + this.method.getExecutable(), + Message.PROPERTYMAPPING_MAPPING_NOT_FOUND, + history.createSourcePropertyErrorMessage(), + history.getTargetType(), + history.createTargetPropertyName(), + history.getTargetType(), + history.getSourceType() + ); } } else if ( !unprocessedTargetProperties.isEmpty() && unmappedTargetPolicy.requiresReport() ) { Message msg = unmappedTargetPolicy.getDiagnosticKind() == Diagnostic.Kind.ERROR ? Message.BEANMAPPING_UNMAPPED_TARGETS_ERROR : Message.BEANMAPPING_UNMAPPED_TARGETS_WARNING; - - ctx.getMessager().printMessage( - method.getExecutable(), - msg, + Object[] args = new Object[] { MessageFormat.format( "{0,choice,1#property|1 secretaryDtoEmployeeDtoMapToSecretaryEntityEmployeeEntityMap(Map map) { + if ( map == null ) { + return null; + } + + Map map1 = new HashMap(); + + for ( java.util.Map.Entry entry : map.entrySet() ) { + SecretaryEntity key = secretaryDtoToSecretaryEntity( entry.getKey() ); + EmployeeEntity value = employeeDtoToEmployeeEntity( entry.getValue() ); + map1.put( key, value ); + } + + return map1; + } + + protected void unmappableDepartmentDtoToDepartmentEntity(UnmappableDepartmentDto unmappableDepartmentDto, DepartmentEntity mappingTarget) { + if ( unmappableDepartmentDto == null ) { + return; + } + + mappingTarget.setName( unmappableDepartmentDto.getName() ); + if ( mappingTarget.getSecretaryToEmployee() != null ) { + Map map = secretaryDtoEmployeeDtoMapToSecretaryEntityEmployeeEntityMap( unmappableDepartmentDto.getSecretaryToEmployee() ); + if ( map != null ) { + mappingTarget.getSecretaryToEmployee().clear(); + mappingTarget.getSecretaryToEmployee().putAll( map ); + } + else { + mappingTarget.setSecretaryToEmployee( null ); + } + } + else { + Map map = secretaryDtoEmployeeDtoMapToSecretaryEntityEmployeeEntityMap( unmappableDepartmentDto.getSecretaryToEmployee() ); + if ( map != null ) { + mappingTarget.setSecretaryToEmployee( map ); + } + } + } +}