use of org.openlmis.stockmanagement.dto.StockCardDto in project openlmis-stockmanagement by OpenLMIS.
the class StockCardServiceIntegrationTest method shouldGetStockCardWithCalculatedSohWhenFindStockCard.
@Test
public void shouldGetStockCardWithCalculatedSohWhenFindStockCard() throws Exception {
// given
StockEventDto stockEventDto = StockEventDtoDataBuilder.createStockEventDto();
stockEventDto.getLineItems().get(0).setSourceId(null);
stockEventDto.getLineItems().get(0).setDestinationId(null);
StockEvent savedEvent = save(stockEventDto, randomUUID());
// when
UUID cardId = stockCardRepository.findByOriginEvent(savedEvent).getId();
StockCardDto card = stockCardService.findStockCardById(cardId);
// then
assertThat(card.getStockOnHand(), is(stockEventDto.getLineItems().get(0).getQuantity()));
}
use of org.openlmis.stockmanagement.dto.StockCardDto in project openlmis-stockmanagement by OpenLMIS.
the class StockCardServiceIntegrationTest method shouldGetRefdataAndConvertOrganizationsWhenFindStockCard.
@Test
public void shouldGetRefdataAndConvertOrganizationsWhenFindStockCard() throws Exception {
// given
UUID userId = randomUUID();
StockEventDto stockEventDto = createStockEventDto();
stockEventDto.getLineItems().get(0).setLotId(randomUUID());
// 1. mock ref data service
FacilityDto cardFacility = new FacilityDto();
FacilityDto sourceFacility = new FacilityDto();
ProgramDto programDto = new ProgramDto();
OrderableDto orderableDto = new OrderableDto();
LotDto lotDto = new LotDto();
when(facilityReferenceDataService.findOne(stockEventDto.getFacilityId())).thenReturn(cardFacility);
when(facilityReferenceDataService.findOne(fromString("e6799d64-d10d-4011-b8c2-0e4d4a3f65ce"))).thenReturn(sourceFacility);
when(programReferenceDataService.findOne(stockEventDto.getProgramId())).thenReturn(programDto);
when(orderableReferenceDataService.findOne(stockEventDto.getLineItems().get(0).getOrderableId())).thenReturn(orderableDto);
when(lotReferenceDataService.findOne(stockEventDto.getLineItems().get(0).getLotId())).thenReturn(lotDto);
// 2. there is an existing stock card with line items
StockEvent savedEvent = save(stockEventDto, userId);
// when
StockCard savedCard = stockCardRepository.findByOriginEvent(savedEvent);
StockCardDto foundCardDto = stockCardService.findStockCardById(savedCard.getId());
// then
assertThat(foundCardDto.getFacility(), is(cardFacility));
assertThat(foundCardDto.getProgram(), is(programDto));
assertThat(foundCardDto.getOrderable(), is(orderableDto));
assertThat(foundCardDto.getLot(), is(lotDto));
StockCardLineItemDto lineItemDto = foundCardDto.getLineItems().get(0);
assertThat(lineItemDto.getSource(), is(sourceFacility));
assertThat(lineItemDto.getDestination().getName(), is("NGO"));
}
use of org.openlmis.stockmanagement.dto.StockCardDto in project openlmis-stockmanagement by OpenLMIS.
the class JasperReportService method getStockCardReportView.
/**
* Generate stock card report in PDF format.
*
* @param stockCardId stock card id
* @return generated stock card report.
*/
public ModelAndView getStockCardReportView(UUID stockCardId) {
StockCardDto stockCardDto = stockCardService.findStockCardById(stockCardId);
if (stockCardDto == null) {
throw new ResourceNotFoundException(new Message(ERROR_REPORT_ID_NOT_FOUND));
}
Collections.reverse(stockCardDto.getLineItems());
Map<String, Object> params = new HashMap<>();
params.put("datasource", singletonList(stockCardDto));
params.put("hasLot", stockCardDto.hasLot());
return generateReport(CARD_REPORT_URL, params);
}
use of org.openlmis.stockmanagement.dto.StockCardDto in project openlmis-stockmanagement by OpenLMIS.
the class StockCardBaseService method cardToDto.
private StockCardDto cardToDto(FacilityDto facility, ProgramDto program, StockCard card) {
card.calculateStockOnHand();
StockCardDto cardDto = StockCardDto.createFrom(card);
cardDto.setFacility(facility);
cardDto.setProgram(program);
cardDto.setOrderable(OrderableDto.builder().id(card.getOrderableId()).build());
if (card.getLotId() != null) {
cardDto.setLot(LotDto.builder().id(card.getLotId()).build());
}
List<StockCardLineItemDto> lineItems = cardDto.getLineItems();
if (!isEmpty(lineItems)) {
cardDto.setLastUpdate(lineItems.get(lineItems.size() - 1).getLineItem().getOccurredDate());
cardDto.setExtraData(lineItems.get(lineItems.size() - 1).getLineItem().getExtraData());
}
return cardDto;
}
use of org.openlmis.stockmanagement.dto.StockCardDto in project openlmis-stockmanagement by OpenLMIS.
the class StockCardService method search.
/**
* Find stock card page by parameters. Allowed multiple id parameters.
*
* @param ids collection of ids for batch fetch
* @param pageable pagination and sorting parameters
* @return page of filtered stock cards.
*/
public Page<StockCardDto> search(@NotNull Collection<UUID> ids, Pageable pageable) {
OAuth2Authentication authentication = (OAuth2Authentication) SecurityContextHolder.getContext().getAuthentication();
Page<StockCard> page;
if (!authentication.isClientOnly()) {
UserDto user = authenticationHelper.getCurrentUser();
LOGGER.info("list of ids:" + ids);
PermissionStrings.Handler handler = permissionService.getPermissionStrings(user.getId());
Set<PermissionStringDto> permissionStrings = handler.get();
LOGGER.info("list of permission strings:" + permissionStrings);
Set<UUID> facilityIds = new HashSet<>();
Set<UUID> programIds = new HashSet<>();
permissionStrings.stream().filter(permissionString -> STOCK_CARDS_VIEW.equalsIgnoreCase(permissionString.getRightName())).forEach(permission -> {
facilityIds.add(permission.getFacilityId());
programIds.add(permission.getProgramId());
});
LOGGER.info("list of facility ids:" + facilityIds);
LOGGER.info("list of program ids:" + programIds);
if (isEmpty(ids)) {
page = cardRepository.findByFacilityIdInAndProgramIdIn(facilityIds, programIds, pageable);
} else {
page = cardRepository.findByFacilityIdInAndProgramIdInAndIdIn(facilityIds, programIds, ids, pageable);
}
} else {
if (isEmpty(ids)) {
page = cardRepository.findAll(pageable);
} else {
page = cardRepository.findByIdIn(ids, pageable);
}
}
return Pagination.getPage(createDtos(page.getContent()), pageable, page.getTotalElements());
}
Aggregations