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);
}
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());
}
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());
}
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;
}
Aggregations