Search in sources :

Example 86 with ModelMapper

use of org.modelmapper.ModelMapper in project paascloud-master by paascloud.

the class MdcProductCategoryServiceImpl method getMdcCategoryVoById.

@Override
public MdcCategoryVo getMdcCategoryVoById(final Long categoryId) {
    MdcProductCategory category = mdcProductCategoryMapper.selectByPrimaryKey(categoryId);
    if (category == null) {
        logger.error("找不到数据字典信息id={}", categoryId);
        throw new MdcBizException(ErrorCodeEnum.MDC10023001, categoryId);
    }
    // 获取父级菜单信息
    MdcProductCategory parentCategory = mdcProductCategoryMapper.selectByPrimaryKey(category.getPid());
    ModelMapper modelMapper = new ModelMapper();
    MdcCategoryVo categoryVo = modelMapper.map(category, MdcCategoryVo.class);
    categoryVo.setId(category.getId());
    categoryVo.setPid(category.getPid());
    if (parentCategory != null) {
        categoryVo.setParentCategoryName(parentCategory.getName());
    }
    return categoryVo;
}
Also used : MdcBizException(com.paascloud.provider.exceptions.MdcBizException) MdcProductCategory(com.paascloud.provider.model.domain.MdcProductCategory) MdcCategoryVo(com.paascloud.provider.model.vo.MdcCategoryVo) ModelMapper(org.modelmapper.ModelMapper)

Example 87 with ModelMapper

use of org.modelmapper.ModelMapper in project paascloud-master by paascloud.

the class OmcOrderServiceImpl method queryOrderDtoByUserIdAndOrderNo.

@Override
public OrderDto queryOrderDtoByUserIdAndOrderNo(Long userId, String orderNo) {
    OmcOrder omcOrder = this.queryByUserIdAndOrderNo(userId, orderNo);
    if (omcOrder == null) {
        throw new OmcBizException(ErrorCodeEnum.OMC10031005, orderNo);
    }
    ModelMapper modelMapper = new ModelMapper();
    return modelMapper.map(omcOrder, OrderDto.class);
}
Also used : OmcBizException(com.paascloud.provider.exceptions.OmcBizException) OmcOrder(com.paascloud.provider.model.domain.OmcOrder) ModelMapper(org.modelmapper.ModelMapper)

Example 88 with ModelMapper

use of org.modelmapper.ModelMapper in project CzechIdMng by bcvsolutions.

the class ModelMapperConfig method modelMapper.

@SuppressWarnings("unchecked")
@Bean
public ModelMapper modelMapper() {
    ModelMapper modeler = new ModelMapper();
    modeler.getConfiguration().setMatchingStrategy(// We want use STRICT matching strategy ... others can be ambiguous.
    MatchingStrategies.STRICT).setSkipNullEnabled(// prevent to skip null property values
    false);
    // Convert BaseEntity to UIID (get ID)
    // FIXME: Fix EntityToUuidConditionalConverter field resolving and use conditional converter instead this.
    Converter<? extends BaseEntity, UUID> entityToUuid = new EntityToUuidConverter(modeler, applicationContext);
    // Convert UIID to Entity
    // Conditional converter is using here, because ModelMapper contains bug with
    // skipping converter if source value is null. More here https://redmine.czechidm.com/issues/2271.
    modeler.getConfiguration().getConverters().add(new UuidToEntityConditionalConverter(applicationContext));
    // This converter must be set for only one purpose... workaround fixed
    // error in ModelMapper.
    // When is in DTO field (applicant for example) with type UUID (with
    // conversion to IdmIdentity) and other UUID field (for example
    // modifierId), but with same value as first field, then mapper will be
    // set converted value from first field (applicant) to second field (IdmIdentity to UUID) ->
    // Class cast exception will be throw.
    // + Additionally this converter allows load DTO (by UUID) and put him to embedded map.
    Converter<UUID, UUID> uuidToUuid = new UuidToUuidConverter(applicationContext);
    modeler.createTypeMap(UUID.class, UUID.class).setConverter(uuidToUuid);
    // Converter for resolve problem with 0x00 character in Postgress.
    modeler.createTypeMap(String.class, String.class).setConverter(new StringToStringConverter());
    // Converter OperationResult for resolve problem with 0x00 character in PostgreSQL.
    modeler.createTypeMap(OperationResult.class, OperationResult.class).setConverter(new OperationResultConverter(modeler));
    // Simple ConfigurationMap converter - map without template is not provided by model mapper out of box.
    modeler.createTypeMap(ConfigurationMap.class, ConfigurationMap.class).setConverter(new ConfigurationMapToConfigurationMapConverter());
    // Condition for property ... if is property list and dto is trimmed,
    // then will be not used (set null)
    // or if is property list and have parent dto, then will be to set null
    // (only two levels are allowed).
    Condition<Object, Object> trimListCondition = new Condition<Object, Object>() {

        @Override
        public boolean applies(MappingContext<Object, Object> context) {
            if (List.class.isAssignableFrom(context.getDestinationType())) {
                MappingContext<?, ?> parentContext = context.getParent();
                MappingContext<?, ?> superContext = parentContext != null ? parentContext.getParent() : null;
                if (superContext != null) {
                    if (parentContext != null && parentContext.getDestination() instanceof AbstractDto) {
                        ((AbstractDto) parentContext.getDestination()).setTrimmed(true);
                    }
                    return false;
                }
                if (parentContext != null && parentContext.getDestination() instanceof AbstractDto && ((AbstractDto) parentContext.getDestination()).isTrimmed()) {
                    return false;
                }
            }
            return true;
        }
    };
    modeler.getConfiguration().setPropertyCondition(trimListCondition);
    // entity to uuid converters will be set for all entities
    entityManager.getMetamodel().getEntities().forEach(entityType -> {
        if (entityType.getJavaType() == null) {
            return;
        }
        @SuppressWarnings("rawtypes") TypeMap typeMapEntityToUuid = modeler.createTypeMap(entityType.getJavaType(), UUID.class);
        typeMapEntityToUuid.setConverter(entityToUuid);
    });
    // configure default type map for entities
    // this behavior must be placed in this class, not in toDto methods (getEmbedded use mapper for map entity to dto)
    // identity role and backward compatibility with automatic role
    TypeMap<IdmIdentityRole, IdmIdentityRoleDto> typeMapIdentityRole = modeler.getTypeMap(IdmIdentityRole.class, IdmIdentityRoleDto.class);
    if (typeMapIdentityRole == null) {
        modeler.createTypeMap(IdmIdentityRole.class, IdmIdentityRoleDto.class);
        typeMapIdentityRole = modeler.getTypeMap(IdmIdentityRole.class, IdmIdentityRoleDto.class);
        typeMapIdentityRole.addMappings(new PropertyMap<IdmIdentityRole, IdmIdentityRoleDto>() {

            @Override
            protected void configure() {
                this.skip().setAutomaticRole(null);
            }
        });
    }
    // concept role request and automatic role backward compatibility
    TypeMap<IdmConceptRoleRequest, IdmConceptRoleRequestDto> typeMapRoleConcept = modeler.getTypeMap(IdmConceptRoleRequest.class, IdmConceptRoleRequestDto.class);
    if (typeMapRoleConcept == null) {
        modeler.createTypeMap(IdmConceptRoleRequest.class, IdmConceptRoleRequestDto.class);
        typeMapRoleConcept = modeler.getTypeMap(IdmConceptRoleRequest.class, IdmConceptRoleRequestDto.class);
        typeMapRoleConcept.addMappings(new PropertyMap<IdmConceptRoleRequest, IdmConceptRoleRequestDto>() {

            @Override
            protected void configure() {
                this.skip().setAutomaticRole(null);
            }
        });
    }
    // 
    return modeler;
}
Also used : UuidToEntityConditionalConverter(eu.bcvsolutions.idm.core.config.domain.UuidToEntityConditionalConverter) IdmConceptRoleRequest(eu.bcvsolutions.idm.core.model.entity.IdmConceptRoleRequest) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) OperationResultConverter(eu.bcvsolutions.idm.core.config.domain.OperationResultConverter) EntityToUuidConverter(eu.bcvsolutions.idm.core.config.domain.EntityToUuidConverter) MappingContext(org.modelmapper.spi.MappingContext) IdmIdentityRole(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) UuidToUuidConverter(eu.bcvsolutions.idm.core.config.domain.UuidToUuidConverter) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) UUID(java.util.UUID) Condition(org.modelmapper.Condition) ModelMapper(org.modelmapper.ModelMapper) StringToStringConverter(eu.bcvsolutions.idm.core.config.domain.StringToStringConverter) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) ConfigurationMapToConfigurationMapConverter(eu.bcvsolutions.idm.core.config.domain.ConfigurationMapToConfigurationMapConverter) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) TypeMap(org.modelmapper.TypeMap) Bean(org.springframework.context.annotation.Bean)

Example 89 with ModelMapper

use of org.modelmapper.ModelMapper in project Settler by EmhyrVarEmreis.

the class UserService method getUsersWithValue.

public ResponseEntity<List<UserWithValueDTO>> getUsersWithValue(Long userId) {
    getPermissionManager().authorizeGlobalAdmin();
    if (Objects.isNull(userId) || userId < 0) {
        userId = Security.currentUser().getId();
    }
    QUser user = QUser.user;
    QTransaction transaction = QTransaction.transaction;
    List<Tuple> fetch = new JPAQuery<>(entityManager).from(user, transaction).select(user, transaction.value.sum()).where(transaction.creator.id.eq(userId)).where(user.id.ne(userId)).where(transaction.owners.any().id.user.eq(user).or(transaction.contractors.any().id.user.eq(user))).groupBy(user.id, user.firstName, user.lastName, user.email, user.created, user.avatar, user.login, user.accountExpireDate).orderBy(transaction.value.sum().desc()).fetch();
    ModelMapper preparedModelMapper = getModelMapper();
    List<UserWithValueDTO> userWithValueDTOList = new ArrayList<>(fetch.size());
    for (Tuple tuple : fetch) {
        User u = tuple.get(user);
        Double d = tuple.get(transaction.value.sum());
        if (Objects.nonNull(u)) {
            userWithValueDTOList.add(new UserWithValueDTO(userId, preparedModelMapper.map(u, String.class), d));
        }
    }
    return new ResponseEntity<>(userWithValueDTOList, HttpStatus.OK);
}
Also used : QUser(pl.morecraft.dev.settler.domain.QUser) QTransaction(pl.morecraft.dev.settler.domain.QTransaction) ResponseEntity(org.springframework.http.ResponseEntity) User(pl.morecraft.dev.settler.domain.User) QUser(pl.morecraft.dev.settler.domain.QUser) ArrayList(java.util.ArrayList) JPAQuery(com.querydsl.jpa.impl.JPAQuery) Tuple(com.querydsl.core.Tuple) ModelMapper(org.modelmapper.ModelMapper)

Example 90 with ModelMapper

use of org.modelmapper.ModelMapper in project Settler by EmhyrVarEmreis.

the class ListPageConverter method convert.

public <S, T> List<T> convert(List<S> source, Class<T> tClass) {
    List<T> content = new ArrayList<>();
    ModelMapper modelMapper = entityConvertersPack.getPreparedModelMapper();
    for (S s : source) {
        content.add(modelMapper.map(s, tClass));
    }
    return content;
}
Also used : ArrayList(java.util.ArrayList) ModelMapper(org.modelmapper.ModelMapper)

Aggregations

ModelMapper (org.modelmapper.ModelMapper)164 Bean (org.springframework.context.annotation.Bean)24 ArrayList (java.util.ArrayList)18 Date (java.util.Date)6 Map (java.util.Map)5 Optional (java.util.Optional)5 Actor (com.management.entities.Actor)4 CinemaTheatre (com.management.entities.CinemaTheatre)4 Event (com.management.entities.Event)4 Performance (com.management.entities.Performance)4 Props (com.management.entities.Props)4 User (com.management.entities.User)4 List (java.util.List)4 PutMessageRequestType (no.difi.meldingsutveksling.noarkexchange.schema.PutMessageRequestType)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Actorperformances (com.management.entities.Actorperformances)3 FanZone (com.management.entities.FanZone)3 Friendslist (com.management.entities.Friendslist)3 Hall (com.management.entities.Hall)3