Skip to content

Commit

Permalink
OAM-260: Added not null constraints for units in stock cards, event i…
Browse files Browse the repository at this point in the history
…tems and inventory items (#66)

* OAM-260: Added not null constraints for units in stock cards, event items and inventory items

* OAM-260: Added proper index cleanup

---------

Co-authored-by: Piotr Wargulak <[email protected]>
  • Loading branch information
sradziszewski and pwargulak authored Aug 1, 2024
1 parent cb85a44 commit 2ced360
Show file tree
Hide file tree
Showing 11 changed files with 409 additions and 378 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ CrudRepository<StockCard, UUID> getRepository() {

@Override
StockCard generateInstance() throws Exception {
return generateInstance(randomUUID(), randomUUID(), randomUUID(), randomUUID());
return generateInstance(randomUUID(), randomUUID(), randomUUID(), randomUUID(), randomUUID());
}

private StockCard generateInstance(UUID facility, UUID program, UUID product, UUID lot) {
Expand Down Expand Up @@ -221,9 +221,9 @@ public void findByIds() throws Exception {
public void findByLotIdInShouldOnlyFindMatchingStockCards() throws Exception {
UUID matchingLotId = UUID.randomUUID();
stockCard1 = stockCardRepository.save(generateInstance(randomUUID(), randomUUID(), randomUUID(),
matchingLotId));
matchingLotId, randomUUID()));
stockCard2 = stockCardRepository.save(generateInstance(randomUUID(), randomUUID(), randomUUID(),
matchingLotId));
matchingLotId, randomUUID()));
stockCard3 = stockCardRepository.save(generateInstance());
stockCard4 = stockCardRepository.save(generateInstance());

Expand All @@ -236,22 +236,28 @@ public void findByLotIdInShouldOnlyFindMatchingStockCards() throws Exception {

private void initializeStockCardsForMultipleFacilitiesAndPrograms() {
stockCard1 = stockCardRepository
.save(generateInstance(facilityId1, programId1, randomUUID(), randomUUID()));
.save(generateInstance(facilityId1, programId1, randomUUID(), randomUUID(), randomUUID()));
stockCard2 = stockCardRepository
.save(generateInstance(facilityId2, programId2, randomUUID(), randomUUID()));
.save(generateInstance(facilityId2, programId2, randomUUID(), randomUUID(), randomUUID()));
stockCard3 = stockCardRepository
.save(generateInstance(facilityId2, programId1, randomUUID(), randomUUID()));
.save(generateInstance(facilityId2, programId1, randomUUID(), randomUUID(), randomUUID()));
stockCard4 = stockCardRepository
.save(generateInstance(facilityId1, programId2, randomUUID(), randomUUID()));
.save(generateInstance(facilityId1, programId2, randomUUID(), randomUUID(), randomUUID()));
stockCard5 = stockCardRepository
.save(generateInstance(randomUUID(), randomUUID(), randomUUID(), randomUUID()));

stockCardRepository.save(generateInstance(facilityId1, programId1, randomUUID(), randomUUID()));
stockCardRepository.save(generateInstance(facilityId2, programId2, randomUUID(), randomUUID()));
stockCardRepository.save(generateInstance(facilityId1, programId2, randomUUID(), randomUUID()));
.save(generateInstance(randomUUID(), randomUUID(), randomUUID(), randomUUID(),
randomUUID()));

stockCardRepository.save(generateInstance(facilityId1, programId1, randomUUID(), randomUUID(),
randomUUID()));
stockCardRepository.save(generateInstance(facilityId2, programId2, randomUUID(), randomUUID(),
randomUUID()));
stockCardRepository.save(generateInstance(facilityId1, programId2, randomUUID(), randomUUID(),
randomUUID()));
stockCardRepository
.save(generateInstance(facilityId2, randomUUID(), randomUUID(), randomUUID()));
.save(generateInstance(facilityId2, randomUUID(), randomUUID(), randomUUID(),
randomUUID()));
stockCardRepository
.save(generateInstance(randomUUID(), programId1, randomUUID(), randomUUID()));
.save(generateInstance(randomUUID(), programId1, randomUUID(), randomUUID(),
randomUUID()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ public void shouldFindExistingStockCards()
when(programReferenceDataService.findOne(any(UUID.class)))
.thenReturn(new ProgramDto());

createStockCard(orderable1Id, randomUUID());
createStockCard(orderable3Id, randomUUID());
createStockCard(orderable1Id, randomUUID(), randomUUID());
createStockCard(orderable3Id, randomUUID(), randomUUID());

//when
List<StockCardDto> cardDtos = stockCardSummariesService
Expand Down Expand Up @@ -159,7 +159,7 @@ public void shouldReturnPageOfStockCards() throws Exception {
UUID orderableId = randomUUID();
OrderableDto orderable = createOrderableDto(orderableId, "");

createStockCard(orderableId, randomUUID());
createStockCard(orderableId, randomUUID(), randomUUID());

doReturn(singletonList(orderable)).when(orderableReferenceDataService).findAll();

Expand All @@ -183,7 +183,7 @@ private OrderableDto createOrderableDto(UUID orderableId, String productName) {
.build();
}

private StockCard createStockCard(UUID orderableId, UUID cardId) {
private StockCard createStockCard(UUID orderableId, UUID cardId, UUID unitId) {
StockEvent stockEvent = stockEventsRepository.save(new StockEventDataBuilder()
.withoutId().build());

Expand All @@ -192,6 +192,7 @@ private StockCard createStockCard(UUID orderableId, UUID cardId) {
stockCard.setFacilityId(facilityId);
stockCard.setProgramId(programId);
stockCard.setOriginEvent(stockEvent);
stockCard.setUnitOfOrderableId(unitId);
stockCard.setId(cardId);
Map<String, String> oldExtraData = new HashMap<>();
oldExtraData.put("vvmStatus", "STAGE_1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public class StockCard extends BaseEntity implements IdentifiableByOrderableLotU
@Column
private UUID lotId;

@Column
@Column(nullable = false)
private UUID unitOfOrderableId;

@LazyCollection(FALSE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public class StockEventLineItem extends BaseEntity
@JoinColumn(name = "stockEventLineItemId")
private List<PhysicalInventoryLineItemAdjustment> stockAdjustments;

@Column(nullable = false)
private UUID unitOfOrderableId;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ public class PhysicalInventoryLineItem
implements VvmApplicable, IdentifiableByOrderableLotUnit {
@Column(nullable = false)
private UUID orderableId;

@Column
private UUID lotId;
@Column

@Column(nullable = false)
private UUID unitOfOrderableId;

//when saving draft quantity is allowed to be null
Expand Down
Loading

0 comments on commit 2ced360

Please sign in to comment.