use of org.openlmis.stockmanagement.dto.referencedata.OrderableDto in project openlmis-stockmanagement by OpenLMIS.
the class StockCardSummariesServiceTest method shouldFindExistingStockCards.
@Test
public void shouldFindExistingStockCards() throws Exception {
// given
UUID orderable1Id = randomUUID();
UUID orderable2Id = randomUUID();
UUID orderable3Id = randomUUID();
UUID orderable4Id = randomUUID();
OrderableDto orderable1 = createOrderableDto(orderable1Id, "");
OrderableDto orderable2 = createOrderableDto(orderable2Id, "");
OrderableDto orderable3 = createOrderableDto(orderable3Id, "");
OrderableDto orderable4 = createOrderableDto(orderable4Id, "");
UUID programId = randomUUID();
UUID facilityId = randomUUID();
when(orderableReferenceDataService.findAll()).thenReturn(asList(orderable1, orderable2, orderable3, orderable4));
when(cardRepository.findByProgramIdAndFacilityId(programId, facilityId)).thenReturn(asList(createStockCard(orderable1Id, randomUUID()), createStockCard(orderable3Id, randomUUID())));
when(lotReferenceDataService.getAllLotsOf(any(UUID.class))).thenReturn(emptyList());
// when
List<StockCardDto> cardDtos = stockCardSummariesService.findStockCards(programId, facilityId);
// then
assertThat(cardDtos.size(), is(2));
String orderablePropertyName = "orderable";
String idPropertyName = "id";
String lineItemsPropertyName = "lineItems";
String stockOnHandPropertyName = "stockOnHand";
String lastUpdatePropertyName = "lastUpdate";
assertThat(cardDtos, hasItem(allOf(hasProperty(orderablePropertyName, is(orderable1)), hasProperty(idPropertyName, notNullValue()), hasProperty(stockOnHandPropertyName, notNullValue()), hasProperty(lastUpdatePropertyName, is(LocalDate.of(2017, 3, 18))), hasProperty(lineItemsPropertyName, nullValue()))));
assertThat(cardDtos, hasItem(allOf(hasProperty(orderablePropertyName, is(orderable3)), hasProperty(idPropertyName, notNullValue()), hasProperty(stockOnHandPropertyName, notNullValue()), hasProperty(lastUpdatePropertyName, is(LocalDate.of(2017, 3, 18))), hasProperty(lineItemsPropertyName, nullValue()))));
}
use of org.openlmis.stockmanagement.dto.referencedata.OrderableDto in project openlmis-stockmanagement by OpenLMIS.
the class StockCardSummariesServiceTest method shouldCreateDummyCards.
@Test
public void shouldCreateDummyCards() throws Exception {
// given
UUID orderable1Id = randomUUID();
UUID orderable2Id = randomUUID();
UUID orderable3Id = randomUUID();
UUID orderable4Id = randomUUID();
OrderableDto orderable1 = createOrderableDto(orderable1Id, "1");
OrderableDto orderable2 = createOrderableDto(orderable2Id, "2");
orderable2.getIdentifiers().put("tradeItem", randomUUID().toString());
OrderableDto orderable3 = createOrderableDto(orderable3Id, "3");
OrderableDto orderable4 = createOrderableDto(orderable4Id, "4");
UUID programId = randomUUID();
UUID facilityId = randomUUID();
// 1,2,3,4 all approved
when(orderableReferenceDataService.findAll()).thenReturn(asList(orderable1, orderable2, orderable3, orderable4));
// but only 1, 3 have cards. 2, 4 don't have cards.
when(cardRepository.getIdentitiesBy(programId, facilityId)).thenReturn(asList(new OrderableLotIdentity(orderable1Id, null), new OrderableLotIdentity(orderable3Id, null)));
LotDto lotDto = new LotDto();
lotDto.setId(randomUUID());
// 2 has a lot
when(lotReferenceDataService.getAllLotsOf(fromString(orderable2.getIdentifiers().get("tradeItem")))).thenReturn(singletonList(lotDto));
// when
List<StockCardDto> cardDtos = stockCardSummariesService.createDummyStockCards(programId, facilityId);
// then
assertThat(cardDtos.size(), is(3));
String orderablePropertyName = "orderable";
String lotPropertyName = "lot";
String idPropertyName = "id";
String lineItemsPropertyName = "lineItems";
String stockOnHandPropertyName = "stockOnHand";
String lastUpdatePropertyName = "lastUpdate";
// 2 and lot
assertThat(cardDtos, hasItem(allOf(hasProperty(orderablePropertyName, is(orderable2)), hasProperty(lotPropertyName, is(lotDto)), hasProperty(idPropertyName, nullValue()), hasProperty(stockOnHandPropertyName, nullValue()), hasProperty(lineItemsPropertyName, nullValue()))));
// 2 and no lot
assertThat(cardDtos, hasItem(allOf(hasProperty(orderablePropertyName, is(orderable2)), hasProperty(lotPropertyName, is(nullValue())), hasProperty(idPropertyName, nullValue()), hasProperty(stockOnHandPropertyName, nullValue()), hasProperty(lastUpdatePropertyName, nullValue()), hasProperty(lineItemsPropertyName, nullValue()))));
// 4 and no lot
assertThat(cardDtos, hasItem(allOf(hasProperty(orderablePropertyName, is(orderable4)), hasProperty(lotPropertyName, is(nullValue())), hasProperty(idPropertyName, nullValue()), hasProperty(stockOnHandPropertyName, nullValue()), hasProperty(lastUpdatePropertyName, nullValue()), hasProperty(lineItemsPropertyName, nullValue()))));
}
use of org.openlmis.stockmanagement.dto.referencedata.OrderableDto in project openlmis-stockmanagement by OpenLMIS.
the class VvmValidator method validate.
/**
* Validates whether the vvm applicables have proper vvm status (if applicable).
* Throws ValidationMessageException if any of items is in invalid state.
* @param vvmApplicables list of items to test
* @param messageKey error message key for exception
* @param ignoreMissingOrderable whether should
*/
public void validate(List<? extends VvmApplicable> vvmApplicables, String messageKey, boolean ignoreMissingOrderable) {
Set<UUID> orderableIds = vvmApplicables.stream().map(VvmApplicable::getOrderableId).collect(Collectors.toSet());
List<OrderableDto> orderables = orderableReferenceDataService.findByIds(orderableIds);
Map<UUID, OrderableDto> groupById = orderables.stream().collect(Collectors.toMap(OrderableDto::getId, orderable -> orderable));
for (VvmApplicable item : vvmApplicables) {
OrderableDto orderable = groupById.get(item.getOrderableId());
if (null == orderable) {
if (ignoreMissingOrderable) {
continue;
} else {
throw new ValidationMessageException(ERROR_EVENT_ORDERABLE_INVALID);
}
}
boolean useVvm = false;
boolean hasVvmStatus = false;
if (orderable.getExtraData() != null) {
useVvm = Boolean.parseBoolean(orderable.getExtraData().get(USE_VVM));
}
if (item.getExtraData() != null) {
hasVvmStatus = item.getExtraData().get(VVM_STATUS) != null;
}
if (!useVvm && hasVvmStatus) {
throw new ValidationMessageException(messageKey);
}
}
}
use of org.openlmis.stockmanagement.dto.referencedata.OrderableDto in project openlmis-stockmanagement by OpenLMIS.
the class StockCardServiceIntegrationTest method shouldGetRefdataAndConvertOrganizationsWhenFindStockCard.
@Test
public void shouldGetRefdataAndConvertOrganizationsWhenFindStockCard() throws Exception {
// given
UUID userId = randomUUID();
StockEventDto stockEventDto = createStockEventDto();
stockEventDto.getLineItems().get(0).setLotId(randomUUID());
// 1. mock ref data service
FacilityDto cardFacility = new FacilityDto();
FacilityDto sourceFacility = new FacilityDto();
ProgramDto programDto = new ProgramDto();
OrderableDto orderableDto = new OrderableDto();
LotDto lotDto = new LotDto();
when(facilityReferenceDataService.findOne(stockEventDto.getFacilityId())).thenReturn(cardFacility);
when(facilityReferenceDataService.findOne(fromString("e6799d64-d10d-4011-b8c2-0e4d4a3f65ce"))).thenReturn(sourceFacility);
when(programReferenceDataService.findOne(stockEventDto.getProgramId())).thenReturn(programDto);
when(orderableReferenceDataService.findOne(stockEventDto.getLineItems().get(0).getOrderableId())).thenReturn(orderableDto);
when(lotReferenceDataService.findOne(stockEventDto.getLineItems().get(0).getLotId())).thenReturn(lotDto);
// 2. there is an existing stock card with line items
StockEvent savedEvent = save(stockEventDto, userId);
// when
StockCard savedCard = stockCardRepository.findByOriginEvent(savedEvent);
StockCardDto foundCardDto = stockCardService.findStockCardById(savedCard.getId());
// then
assertThat(foundCardDto.getFacility(), is(cardFacility));
assertThat(foundCardDto.getProgram(), is(programDto));
assertThat(foundCardDto.getOrderable(), is(orderableDto));
assertThat(foundCardDto.getLot(), is(lotDto));
StockCardLineItemDto lineItemDto = foundCardDto.getLineItems().get(0);
assertThat(lineItemDto.getSource(), is(sourceFacility));
assertThat(lineItemDto.getDestination().getName(), is("NGO"));
}
use of org.openlmis.stockmanagement.dto.referencedata.OrderableDto in project openlmis-stockmanagement by OpenLMIS.
the class StockCardSummariesService method createOrderableLots.
private Map<OrderableLotIdentity, OrderableLot> createOrderableLots(List<OrderableDto> orderableDtos) {
Stream<OrderableLot> orderableLots = orderableDtos.stream().flatMap(this::lotsOfOrderable);
Stream<OrderableLot> orderablesOnly = orderableDtos.stream().map(orderableDto -> new OrderableLot(orderableDto, null));
return concat(orderableLots, orderablesOnly).collect(toMap(OrderableLotIdentity::identityOf, orderableLot -> orderableLot));
}
Aggregations