Search in sources :

Example 11 with Node

use of org.openlmis.stockmanagement.domain.sourcedestination.Node in project openlmis-stockmanagement by OpenLMIS.

the class SourceDestinationBaseService method findOrCreateNode.

private Node findOrCreateNode(UUID referenceId, boolean isRefDataFacility) {
    Node node = nodeRepository.findByReferenceId(referenceId);
    if (node == null) {
        node = new Node();
        node.setReferenceId(referenceId);
        node.setRefDataFacility(isRefDataFacility);
        return nodeRepository.save(node);
    }
    return node;
}
Also used : Node(org.openlmis.stockmanagement.domain.sourcedestination.Node)

Example 12 with Node

use of org.openlmis.stockmanagement.domain.sourcedestination.Node in project openlmis-stockmanagement by OpenLMIS.

the class StockCardLineItemTest method shouldDecreaseSohOfLineItemWhenIssueTo.

@Test
public void shouldDecreaseSohOfLineItemWhenIssueTo() throws Exception {
    // given
    StockCardLineItem lineItem = StockCardLineItem.builder().destination(new Node()).quantity(15).build();
    // when
    lineItem.calculateStockOnHand(15);
    // then
    assertThat(lineItem.getStockOnHand(), is(0));
}
Also used : Node(org.openlmis.stockmanagement.domain.sourcedestination.Node) Test(org.junit.Test)

Example 13 with Node

use of org.openlmis.stockmanagement.domain.sourcedestination.Node in project openlmis-stockmanagement by OpenLMIS.

the class SourceDestinationBaseServiceTest method shouldReturnSourceDtoWhenFoundExistingOne.

@Test
public void shouldReturnSourceDtoWhenFoundExistingOne() throws Exception {
    UUID programId = randomUUID();
    UUID facilityTypeId = randomUUID();
    UUID sourceId = randomUUID();
    ValidSourceAssignment assignment = createSource(programId, facilityTypeId, sourceId);
    Node node = createNode(sourceId, true);
    when(nodeRepository.findByReferenceId(sourceId)).thenReturn(node);
    when(facilityReferenceDataService.findOne(sourceId)).thenReturn(new FacilityDto());
    when(sourceRepository.findByProgramIdAndFacilityTypeIdAndNodeId(programId, facilityTypeId, node.getId())).thenReturn(createSourceAssignment(programId, facilityTypeId, node));
    // when
    ValidSourceDestinationDto foundDto = validSourceService.findByProgramFacilitySource(assignment);
    assertThat(foundDto.getProgramId(), is(programId));
    assertThat(foundDto.getFacilityTypeId(), is(facilityTypeId));
    assertThat(foundDto.getNode().getReferenceId(), is(sourceId));
    verify(programFacilityTypeExistenceService, times(1)).checkProgramAndFacilityTypeExist(programId, facilityTypeId);
}
Also used : ValidSourceAssignment(org.openlmis.stockmanagement.domain.sourcedestination.ValidSourceAssignment) ValidSourceDestinationDto(org.openlmis.stockmanagement.dto.ValidSourceDestinationDto) Node(org.openlmis.stockmanagement.domain.sourcedestination.Node) FacilityDto(org.openlmis.stockmanagement.dto.referencedata.FacilityDto) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 14 with Node

use of org.openlmis.stockmanagement.domain.sourcedestination.Node in project openlmis-stockmanagement by OpenLMIS.

the class SourceDestinationBaseServiceTest method mockedOrganizationNode.

private Node mockedOrganizationNode(String name) {
    Organization organization = new Organization();
    organization.setName(name);
    organization.setId(randomUUID());
    when(organizationRepository.findOne(organization.getId())).thenReturn(organization);
    Node node = new Node();
    node.setRefDataFacility(false);
    node.setId(randomUUID());
    node.setReferenceId(organization.getId());
    return node;
}
Also used : Organization(org.openlmis.stockmanagement.domain.sourcedestination.Organization) Node(org.openlmis.stockmanagement.domain.sourcedestination.Node)

Example 15 with Node

use of org.openlmis.stockmanagement.domain.sourcedestination.Node in project openlmis-stockmanagement by OpenLMIS.

the class ValidDestinationAssignmentDataBuilder method createDestination.

/**
 * Create a valid destination assignment.
 *
 * @param programId      program ID
 * @param facilityTypeId facility type ID
 * @param destinationId  destination ID
 * @return valid destination assignment
 */
public static ValidDestinationAssignment createDestination(UUID programId, UUID facilityTypeId, UUID destinationId) {
    Node node = new Node();
    node.setReferenceId(destinationId);
    ValidDestinationAssignment assignment = new ValidDestinationAssignment();
    assignment.setProgramId(programId);
    assignment.setFacilityTypeId(facilityTypeId);
    assignment.setNode(node);
    return assignment;
}
Also used : ValidDestinationAssignment(org.openlmis.stockmanagement.domain.sourcedestination.ValidDestinationAssignment) Node(org.openlmis.stockmanagement.domain.sourcedestination.Node)

Aggregations

Node (org.openlmis.stockmanagement.domain.sourcedestination.Node)15 UUID (java.util.UUID)4 Test (org.junit.Test)4 FacilityDto (org.openlmis.stockmanagement.dto.referencedata.FacilityDto)4 ValidDestinationAssignment (org.openlmis.stockmanagement.domain.sourcedestination.ValidDestinationAssignment)3 ValidSourceAssignment (org.openlmis.stockmanagement.domain.sourcedestination.ValidSourceAssignment)3 UUID.randomUUID (java.util.UUID.randomUUID)2 StockCardLineItemReason (org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason)2 ValidSourceDestinationDto (org.openlmis.stockmanagement.dto.ValidSourceDestinationDto)2 List (java.util.List)1 StockCard (org.openlmis.stockmanagement.domain.card.StockCard)1 StockEvent (org.openlmis.stockmanagement.domain.event.StockEvent)1 OrderableLotIdentity (org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity)1 Organization (org.openlmis.stockmanagement.domain.sourcedestination.Organization)1 LotDto (org.openlmis.stockmanagement.dto.referencedata.LotDto)1 OrderableDto (org.openlmis.stockmanagement.dto.referencedata.OrderableDto)1 ProgramDto (org.openlmis.stockmanagement.dto.referencedata.ProgramDto)1 ValidationMessageException (org.openlmis.stockmanagement.exception.ValidationMessageException)1 LazyGrouping (org.openlmis.stockmanagement.util.LazyGrouping)1 LazyList (org.openlmis.stockmanagement.util.LazyList)1