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;
}
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");
}
}
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");
}
}
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;
}
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;
}
Aggregations