Created
June 16, 2021 14:06
-
-
Save robsonkades/fa51fd570fb3ebe508c28e79705b2e34 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package br.com.kades.robson.configuration; | |
import static org.apache.commons.collections4.CollectionUtils.emptyIfNull; | |
import static org.apache.commons.lang3.ObjectUtils.defaultIfNull; | |
import java.util.Arrays; | |
import javax.annotation.PostConstruct; | |
import javax.inject.Inject; | |
import org.modelmapper.AbstractConverter; | |
import org.springframework.context.annotation.Configuration; | |
import lombok.AccessLevel; | |
import lombok.RequiredArgsConstructor; | |
import lombok.experimental.FieldDefaults; | |
@Configuration | |
@RequiredArgsConstructor(onConstructor = @__(@Inject)) | |
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true) | |
public class ResourceFilterMappingConfiguration { | |
ModelMapperConfiguration.CustomModelMapper modelMapper; | |
@PostConstruct | |
public void doMapping() { | |
modelMapper.createTypeMap(ResourceFilterEntity.class, ResourceFilter.class).setConverter(new AbstractConverter<ResourceFilterEntity, ResourceFilter>() { | |
@Override | |
protected ResourceFilter convert(ResourceFilterEntity source) { | |
ResourceFilter destination = new ResourceFilter(); | |
destination.sequence = (long) source.getSequence(); | |
destination.domainName = source.getDomain(); | |
destination.serviceName = source.getService(); | |
destination.uri = source.getUri(); | |
destination.name = source.getName(); | |
destination.description = translationHubApi.getMessage(source.getDescription()); | |
destination.adminDefault = source.isAdminDefault(); | |
destination.resources = Arrays.asList(modelMapper.map(emptyIfNull(source.getResources()), ResourceFilterScope[].class)); | |
return destination; | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment