Search in sources :

Example 91 with ModelMapper

use of org.modelmapper.ModelMapper in project hibisco-ws by hibisco-enterprise.

the class AddressDataService method updateAddress.

public AddressResponseDTO updateAddress(Long idAddress, AddressData address) {
    Optional<AddressData> findAddress = repository.findById(idAddress);
    AddressResponseDTO response = new AddressResponseDTO(404, null);
    ModelMapper mapper = new ModelMapper();
    AddressData newAddress = new AddressData();
    if (findAddress.isPresent()) {
        mapper.getConfiguration().setSkipNullEnabled(true);
        mapper.map(address, newAddress);
        newAddress.setIdAddress(idAddress);
        repository.save(newAddress);
        response.setStatusCode(200);
        response.setAddressData(Optional.of(newAddress));
        return response;
    }
    return response;
}
Also used : AddressData(enterprise.hibisco.hibiscows.entities.AddressData) AddressResponseDTO(enterprise.hibisco.hibiscows.response.AddressResponseDTO) ModelMapper(org.modelmapper.ModelMapper)

Example 92 with ModelMapper

use of org.modelmapper.ModelMapper in project cwa-quick-test-backend by corona-warn-app.

the class QuickTestStatisticsControllerTest method getQuicktestStatisticsFail.

@Test
void getQuicktestStatisticsFail() {
    ModelMapper modelMapper = mock(ModelMapper.class);
    when(modelMapper.map(any(), any())).thenReturn(null);
    try {
        quickTestStatisticsController.getQuicktestStatistics(ZonedDateTime.now(), ZonedDateTime.now());
        fail("has to throw exception");
    } catch (ResponseStatusException e) {
        assertEquals(e.getStatus(), HttpStatus.INTERNAL_SERVER_ERROR, "wrong status");
    } catch (Exception e) {
        fail("catch exception and convert to ResponseStatusException failed");
    }
}
Also used : ResponseStatusException(org.springframework.web.server.ResponseStatusException) ResponseStatusException(org.springframework.web.server.ResponseStatusException) IOException(java.io.IOException) ModelMapper(org.modelmapper.ModelMapper) Test(org.junit.jupiter.api.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Example 93 with ModelMapper

use of org.modelmapper.ModelMapper in project cwa-quick-test-backend by corona-warn-app.

the class QuickTestStatisticsControllerTest method getQuicktestTenantStatisticsFail.

@Test
void getQuicktestTenantStatisticsFail() {
    ModelMapper modelMapper = mock(ModelMapper.class);
    when(modelMapper.map(any(), any())).thenReturn(null);
    try {
        quickTestStatisticsController.getQuicktestStatisticsForTenantWithAggregation(ZonedDateTime.now(), ZonedDateTime.now(), Aggregation.DAY);
        fail("has to throw exception");
    } catch (ResponseStatusException e) {
        assertEquals(e.getStatus(), HttpStatus.INTERNAL_SERVER_ERROR, "wrong status");
    } catch (Exception e) {
        fail("catch exception and convert to ResponseStatusException failed");
    }
}
Also used : ResponseStatusException(org.springframework.web.server.ResponseStatusException) ResponseStatusException(org.springframework.web.server.ResponseStatusException) IOException(java.io.IOException) ModelMapper(org.modelmapper.ModelMapper) Test(org.junit.jupiter.api.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Example 94 with ModelMapper

use of org.modelmapper.ModelMapper in project cwa-quick-test-backend by corona-warn-app.

the class MapperConfig method modelMapper.

/**
 * mapper to map two objects.
 *
 * @return modelmapper with the setting "STRICT"
 */
@Bean
public ModelMapper modelMapper() {
    ModelMapper modelMapper = new ModelMapper();
    modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
    return modelMapper;
}
Also used : ModelMapper(org.modelmapper.ModelMapper) Bean(org.springframework.context.annotation.Bean)

Example 95 with ModelMapper

use of org.modelmapper.ModelMapper in project DH-Projeto-Integrador by maik-henrique.

the class ModelMapperConfig method getModelMapper.

@Bean
public ModelMapper getModelMapper() {
    ModelMapper modelMapper = new ModelMapper();
    Converter<InboundOrderUpdateRequest, InboundOrder> converter = getInboundOrderUpdateRequestToInboundOrderConverter();
    Converter<InboundOrder, InboundOrderResponse> inboundOrderToInboundOrderResponseConverter = gedtInboundOrderUpdateRequestToInboundOrderConverter();
    Converter<InboundOrderPostRequest, InboundOrder> inboundOrderPostToInboundOrder = getInboundOrderPostRequestToInboundOrderConverter();
    modelMapper.createTypeMap(InboundOrderUpdateRequest.class, InboundOrder.class).setConverter(converter);
    modelMapper.createTypeMap(InboundOrder.class, InboundOrderResponse.class).setConverter(inboundOrderToInboundOrderResponseConverter);
    modelMapper.createTypeMap(InboundOrderPostRequest.class, InboundOrder.class).setConverter(inboundOrderPostToInboundOrder);
    return modelMapper;
}
Also used : InboundOrderResponse(br.com.meli.dhprojetointegrador.dto.response.InboundOrderResponse) InboundOrder(br.com.meli.dhprojetointegrador.entity.InboundOrder) InboundOrderUpdateRequest(br.com.meli.dhprojetointegrador.dto.request.InboundOrderUpdateRequest) InboundOrderPostRequest(br.com.meli.dhprojetointegrador.dto.request.InboundOrderPostRequest) ModelMapper(org.modelmapper.ModelMapper) Bean(org.springframework.context.annotation.Bean)

Aggregations

ModelMapper (org.modelmapper.ModelMapper)194 Bean (org.springframework.context.annotation.Bean)31 ArrayList (java.util.ArrayList)19 Date (java.util.Date)8 Map (java.util.Map)5 Optional (java.util.Optional)5 Test (org.junit.jupiter.api.Test)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 IOException (java.io.IOException)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