Search in sources :

Example 1 with PermissionStringDto

use of org.openlmis.stockmanagement.service.referencedata.PermissionStringDto 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());
}
Also used : FacilityReferenceDataService(org.openlmis.stockmanagement.service.referencedata.FacilityReferenceDataService) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) OrderableReferenceDataService(org.openlmis.stockmanagement.service.referencedata.OrderableReferenceDataService) OrganizationRepository(org.openlmis.stockmanagement.repository.OrganizationRepository) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) CollectionUtils.isEmpty(org.apache.commons.collections4.CollectionUtils.isEmpty) OrderableLotIdentity.identityOf(org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity.identityOf) Collections.singletonList(java.util.Collections.singletonList) StockCardLineItem(org.openlmis.stockmanagement.domain.card.StockCardLineItem) HashSet(java.util.HashSet) OrderableLotIdentity(org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity) Lists(com.google.common.collect.Lists) StockCardDto(org.openlmis.stockmanagement.dto.StockCardDto) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) LotReferenceDataService(org.openlmis.stockmanagement.service.referencedata.LotReferenceDataService) Service(org.springframework.stereotype.Service) PHYSICAL_INVENTORY(org.openlmis.stockmanagement.domain.reason.ReasonCategory.PHYSICAL_INVENTORY) Pageable(org.springframework.data.domain.Pageable) StockCardRepository(org.openlmis.stockmanagement.repository.StockCardRepository) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) STOCK_CARDS_VIEW(org.openlmis.stockmanagement.service.PermissionService.STOCK_CARDS_VIEW) Node(org.openlmis.stockmanagement.domain.sourcedestination.Node) StockEventLineItemDto(org.openlmis.stockmanagement.dto.StockEventLineItemDto) Logger(org.slf4j.Logger) PermissionStrings(org.openlmis.stockmanagement.service.referencedata.PermissionStrings) UserDto(org.openlmis.stockmanagement.dto.referencedata.UserDto) Collection(java.util.Collection) Set(java.util.Set) Pagination(org.openlmis.stockmanagement.web.Pagination) UUID(java.util.UUID) NotNull(javax.validation.constraints.NotNull) Page(org.springframework.data.domain.Page) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) PermissionStringDto(org.openlmis.stockmanagement.service.referencedata.PermissionStringDto) List(java.util.List) MessageService(org.openlmis.stockmanagement.i18n.MessageService) AuthenticationHelper(org.openlmis.stockmanagement.util.AuthenticationHelper) Message(org.openlmis.stockmanagement.util.Message) FacilityDto(org.openlmis.stockmanagement.dto.referencedata.FacilityDto) StockCardLineItem.createLineItemFrom(org.openlmis.stockmanagement.domain.card.StockCardLineItem.createLineItemFrom) StockCard.createStockCardFrom(org.openlmis.stockmanagement.domain.card.StockCard.createStockCardFrom) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) UserDto(org.openlmis.stockmanagement.dto.referencedata.UserDto) PermissionStringDto(org.openlmis.stockmanagement.service.referencedata.PermissionStringDto) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) PermissionStrings(org.openlmis.stockmanagement.service.referencedata.PermissionStrings) UUID(java.util.UUID) HashSet(java.util.HashSet)

Aggregations

Lists (com.google.common.collect.Lists)1 Collection (java.util.Collection)1 Collections.singletonList (java.util.Collections.singletonList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 UUID (java.util.UUID)1 NotNull (javax.validation.constraints.NotNull)1 CollectionUtils.isEmpty (org.apache.commons.collections4.CollectionUtils.isEmpty)1 StockCard (org.openlmis.stockmanagement.domain.card.StockCard)1 StockCard.createStockCardFrom (org.openlmis.stockmanagement.domain.card.StockCard.createStockCardFrom)1 StockCardLineItem (org.openlmis.stockmanagement.domain.card.StockCardLineItem)1 StockCardLineItem.createLineItemFrom (org.openlmis.stockmanagement.domain.card.StockCardLineItem.createLineItemFrom)1 OrderableLotIdentity (org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity)1 OrderableLotIdentity.identityOf (org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity.identityOf)1 PHYSICAL_INVENTORY (org.openlmis.stockmanagement.domain.reason.ReasonCategory.PHYSICAL_INVENTORY)1 Node (org.openlmis.stockmanagement.domain.sourcedestination.Node)1 StockCardDto (org.openlmis.stockmanagement.dto.StockCardDto)1 StockEventDto (org.openlmis.stockmanagement.dto.StockEventDto)1 StockEventLineItemDto (org.openlmis.stockmanagement.dto.StockEventLineItemDto)1