Search in sources :

Example 1 with ApprovedProductDto

use of org.openlmis.stockmanagement.dto.referencedata.ApprovedProductDto in project openlmis-stockmanagement by OpenLMIS.

the class ApprovedProductReferenceDataService method getApprovedProducts.

/**
 * Retrieves all facility approved products from the reference data service, based on the
 * provided facility and full supply flag. It can be optionally filtered by the program ID.
 *
 * @param facilityId id of the facility
 * @param programId  id of the program
 * @return a collection of approved products matching the search criteria
 */
public Page<OrderableDto> getApprovedProducts(UUID facilityId, UUID programId, Collection<UUID> orderableIds) {
    RequestParameters params = RequestParameters.init();
    params.set("programId", programId);
    if (!isEmpty(orderableIds)) {
        params.set("orderableId", orderableIds);
    }
    Page<ApprovedProductDto> approvedProductPage = getPage(facilityId + "/approvedProducts", params);
    List<OrderableDto> content = approvedProductPage.getContent().stream().map(ApprovedProductDto::getOrderable).collect(Collectors.toList());
    return Pagination.getPage(content);
}
Also used : OrderableDto(org.openlmis.stockmanagement.dto.referencedata.OrderableDto) ApprovedProductDto(org.openlmis.stockmanagement.dto.referencedata.ApprovedProductDto) RequestParameters(org.openlmis.stockmanagement.util.RequestParameters)

Example 2 with ApprovedProductDto

use of org.openlmis.stockmanagement.dto.referencedata.ApprovedProductDto in project openlmis-stockmanagement by OpenLMIS.

the class ApprovedProductReferenceDataServiceTest method shouldReturnFullMapOfOrderableFulfills.

@Test
public void shouldReturnFullMapOfOrderableFulfills() {
    UUID programId = randomUUID();
    RequestParameters parameters = RequestParameters.init();
    parameters.set("programId", programId);
    ApprovedProductDto approvedProduct = generateInstance();
    UUID facilityId = randomUUID();
    mockPageResponseEntity(approvedProduct);
    Page<OrderableDto> result = service.getApprovedProducts(facilityId, programId, null);
    assertEquals(1, result.getTotalElements());
    assertEquals(approvedProduct.getOrderable(), result.getContent().get(0));
    verify(restTemplate).exchange(uriCaptor.capture(), eq(HttpMethod.GET), entityCaptor.capture(), refEq(new DynamicPageTypeReference<>(ApprovedProductDto.class)));
    URI uri = uriCaptor.getValue();
    assertThat(uri.toString(), not(containsString("orderableId")));
    assertAuthHeader(entityCaptor.getValue());
    assertNull(entityCaptor.getValue().getBody());
}
Also used : OrderableDto(org.openlmis.stockmanagement.dto.referencedata.OrderableDto) DynamicPageTypeReference(org.openlmis.stockmanagement.util.DynamicPageTypeReference) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) ApprovedProductDto(org.openlmis.stockmanagement.dto.referencedata.ApprovedProductDto) URI(java.net.URI) RequestParameters(org.openlmis.stockmanagement.util.RequestParameters) Test(org.junit.Test)

Example 3 with ApprovedProductDto

use of org.openlmis.stockmanagement.dto.referencedata.ApprovedProductDto in project openlmis-stockmanagement by OpenLMIS.

the class ApprovedProductReferenceDataServiceTest method shouldReturnMapOfOrderableFulfillsForGivenOrderables.

@Test
public void shouldReturnMapOfOrderableFulfillsForGivenOrderables() {
    UUID programId = randomUUID();
    List<UUID> orderableIds = asList(randomUUID(), randomUUID());
    RequestParameters parameters = RequestParameters.init();
    parameters.set("programId", programId);
    parameters.set("orderableId", orderableIds);
    ApprovedProductDto approvedProduct = generateInstance();
    UUID facilityId = randomUUID();
    mockPageResponseEntity(approvedProduct);
    Page<OrderableDto> result = service.getApprovedProducts(facilityId, programId, orderableIds);
    assertEquals(1, result.getTotalElements());
    assertEquals(approvedProduct.getOrderable(), result.getContent().get(0));
    verify(restTemplate).exchange(uriCaptor.capture(), eq(HttpMethod.GET), entityCaptor.capture(), refEq(new DynamicPageTypeReference<>(ApprovedProductDto.class)));
    URI uri = uriCaptor.getValue();
    assertThat(uri.toString(), containsString("orderableId=" + orderableIds.get(0)));
    assertThat(uri.toString(), containsString("orderableId=" + orderableIds.get(1)));
    assertAuthHeader(entityCaptor.getValue());
    assertNull(entityCaptor.getValue().getBody());
}
Also used : OrderableDto(org.openlmis.stockmanagement.dto.referencedata.OrderableDto) DynamicPageTypeReference(org.openlmis.stockmanagement.util.DynamicPageTypeReference) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) ApprovedProductDto(org.openlmis.stockmanagement.dto.referencedata.ApprovedProductDto) URI(java.net.URI) RequestParameters(org.openlmis.stockmanagement.util.RequestParameters) Test(org.junit.Test)

Example 4 with ApprovedProductDto

use of org.openlmis.stockmanagement.dto.referencedata.ApprovedProductDto in project openlmis-stockmanagement by OpenLMIS.

the class ApprovedProductDtoDataBuilder method build.

/**
 * Creates new instance of {@link ApprovedProductDto} with properties.
 * @return created approved product dto
 */
public ApprovedProductDto build() {
    ApprovedProductDto approvedProductDto = new ApprovedProductDto(orderable);
    approvedProductDto.setId(orderable.getId());
    return approvedProductDto;
}
Also used : ApprovedProductDto(org.openlmis.stockmanagement.dto.referencedata.ApprovedProductDto)

Aggregations

ApprovedProductDto (org.openlmis.stockmanagement.dto.referencedata.ApprovedProductDto)4 OrderableDto (org.openlmis.stockmanagement.dto.referencedata.OrderableDto)3 RequestParameters (org.openlmis.stockmanagement.util.RequestParameters)3 URI (java.net.URI)2 UUID (java.util.UUID)2 UUID.randomUUID (java.util.UUID.randomUUID)2 Test (org.junit.Test)2 DynamicPageTypeReference (org.openlmis.stockmanagement.util.DynamicPageTypeReference)2