use of org.openlmis.stockmanagement.dto.PhysicalInventoryDto in project openlmis-stockmanagement by OpenLMIS.
the class PhysicalInventoryControllerIntegrationTest method shouldReturnBadRequestOnSaveDraftWhenEntityInvalid.
@Test
public void shouldReturnBadRequestOnSaveDraftWhenEntityInvalid() {
// given
UUID physicalInventoryId = UUID.randomUUID();
PhysicalInventoryDto expectedDraft = generatePhysicalInventory();
when(physicalInventoryService.saveDraft(expectedDraft, physicalInventoryId)).thenThrow(new ValidationMessageException(ERROR_PHYSICAL_INVENTORY_LINE_ITEMS_MISSING));
// when
restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()).contentType(APPLICATION_JSON).pathParam("id", physicalInventoryId).body(expectedDraft).when().put(ID_URL).then().statusCode(400);
// then
assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations());
}
use of org.openlmis.stockmanagement.dto.PhysicalInventoryDto in project openlmis-stockmanagement by OpenLMIS.
the class PhysicalInventoryControllerIntegrationTest method generatePhysicalInventory.
private PhysicalInventoryDto generatePhysicalInventory() {
PhysicalInventoryDto inventory = new PhysicalInventoryDto();
inventory.setId(UUID.randomUUID());
inventory.setFacilityId(UUID.randomUUID());
inventory.setProgramId(UUID.randomUUID());
inventory.setOccurredDate(LocalDate.now());
inventory.setDocumentNumber("number");
inventory.setIsStarter(false);
inventory.setSignature("signature");
inventory.setLineItems(Collections.singletonList(generatePhysicalInventoryLineItem()));
return inventory;
}
use of org.openlmis.stockmanagement.dto.PhysicalInventoryDto in project openlmis-stockmanagement by OpenLMIS.
the class PhysicalInventoryService method submitPhysicalInventory.
/**
* Persist physical inventory, with an event id.
*
* @param inventoryDto inventoryDto.
* @param eventId eventId.
*/
void submitPhysicalInventory(PhysicalInventoryDto inventoryDto, UUID eventId) {
LOGGER.info("submit physical inventory");
PhysicalInventory inventory = inventoryDto.toPhysicalInventoryForSubmit();
if (null != eventId) {
StockEvent event = new StockEvent();
event.setId(eventId);
inventory.setStockEvent(event);
}
Map<OrderableLotIdentity, StockCard> cards = stockCardRepository.findByProgramIdAndFacilityId(inventory.getProgramId(), inventory.getFacilityId()).stream().collect(toMap(OrderableLotIdentity::identityOf, card -> card));
for (PhysicalInventoryLineItem line : inventory.getLineItems()) {
StockCard foundCard = cards.get(OrderableLotIdentity.identityOf(line));
// modified during recalculation, this will avoid persistence of those modified models
if (foundCard != null) {
StockCard stockCard = foundCard.shallowCopy();
stockCard.calculateStockOnHand();
line.setPreviousStockOnHandWhenSubmitted(stockCard.getStockOnHand());
}
}
physicalInventoriesRepository.save(inventory);
}
use of org.openlmis.stockmanagement.dto.PhysicalInventoryDto in project openlmis-stockmanagement by OpenLMIS.
the class StockEventProcessor method saveEventAndGenerateLineItems.
private UUID saveEventAndGenerateLineItems(StockEventDto eventDto, Profiler profiler) {
profiler.start("CONVERT_TO_EVENT");
StockEvent stockEvent = eventDto.toEvent();
profiler.start("DB_SAVE");
UUID savedEventId = stockEventsRepository.save(stockEvent).getId();
LOGGER.debug("Saved stock event with id " + savedEventId);
if (eventDto.isPhysicalInventory()) {
profiler.start("CREATE_PHYSICAL_INVENTORY_DTO");
PhysicalInventoryDto inventoryDto = fromEventDto(eventDto);
profiler.start("SUBMIT_PHYSICAL_INVENTORY");
physicalInventoryService.submitPhysicalInventory(inventoryDto, savedEventId);
}
profiler.start("SAVE_FROM_EVENT");
stockCardService.saveFromEvent(eventDto, savedEventId);
profiler.start("CALL_NOTIFICATIONS");
stockEventNotificationProcessor.callAllNotifications(eventDto);
return savedEventId;
}
use of org.openlmis.stockmanagement.dto.PhysicalInventoryDto in project openlmis-stockmanagement by OpenLMIS.
the class PhysicalInventoryValidatorTest method testValidateBasedOnIfExistingIsDraft.
private void testValidateBasedOnIfExistingIsDraft(boolean isDraft) {
PhysicalInventoryDto inventory = newInventory();
PhysicalInventory existingInventory = mock(PhysicalInventory.class);
when(existingInventory.getIsDraft()).thenReturn(isDraft);
when(repository.findOne(inventory.getId())).thenReturn(existingInventory);
validator.validateDraft(inventory, inventory.getId());
}
Aggregations