Search in sources :

Example 6 with UserDto

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

the class PermissionService method checkUserToken.

private ResultDto<Boolean> checkUserToken(String rightName, UUID program, UUID facility, UUID warehouse) {
    UserDto user = authenticationHelper.getCurrentUser();
    RightDto right = authenticationHelper.getRight(rightName);
    try {
        return userReferenceDataService.hasRight(user.getId(), right.getId(), program, facility, warehouse);
    } catch (HttpClientErrorException httpException) {
        throw new PermissionMessageException(new Message(ERROR_PERMISSION_CHECK_FAILED, httpException.getMessage()), httpException);
    }
}
Also used : RightDto(org.openlmis.stockmanagement.dto.referencedata.RightDto) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) Message(org.openlmis.stockmanagement.util.Message) UserDto(org.openlmis.stockmanagement.dto.referencedata.UserDto) PermissionMessageException(org.openlmis.stockmanagement.exception.PermissionMessageException)

Example 7 with UserDto

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

the class StockoutNotifier method notifyStockEditors.

/**
 * Notify user with "Edit stock inventories" right for the facility/program that
 * facility has stocked out of a product.
 *
 * @param stockCard StockCard for a product
 */
public void notifyStockEditors(StockCard stockCard) {
    Collection<UserDto> recipients = getEditors(stockCard);
    String subject = getMessage(EMAIL_ACTION_REQUIRED_SUBJECT);
    String content = getMessage(EMAIL_ACTION_REQUIRED_CONTENT);
    Map<String, String> valuesMap = getValuesMap(stockCard);
    StrSubstitutor sub = new StrSubstitutor(valuesMap);
    for (UserDto recipient : recipients) {
        if (recipient.getHomeFacilityId().equals(stockCard.getFacilityId()) && canBeNotified(recipient)) {
            valuesMap.put("username", recipient.getUsername());
            notificationService.notify(recipient, sub.replace(subject), sub.replace(content));
        }
    }
}
Also used : StrSubstitutor(org.apache.commons.lang.text.StrSubstitutor) UserDto(org.openlmis.stockmanagement.dto.referencedata.UserDto)

Example 8 with UserDto

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

the class BaseWebIntegrationTest method mockUserAuthenticated.

protected void mockUserAuthenticated() {
    UserDto user = new UserDto();
    user.setId(UUID.randomUUID());
    user.setFirstName("admin");
    user.setLastName("strator");
    user.setEmail("admin@openlmis.org");
    given(authenticationHelper.getCurrentUser()).willReturn(user);
}
Also used : UserDto(org.openlmis.stockmanagement.dto.referencedata.UserDto)

Aggregations

UserDto (org.openlmis.stockmanagement.dto.referencedata.UserDto)8 Test (org.junit.Test)3 URI (java.net.URI)2 UUID (java.util.UUID)2 Message (org.openlmis.stockmanagement.util.Message)2 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 NotNull (javax.validation.constraints.NotNull)1 CollectionUtils.isEmpty (org.apache.commons.collections4.CollectionUtils.isEmpty)1 StrSubstitutor (org.apache.commons.lang.text.StrSubstitutor)1 Matchers.containsString (org.hamcrest.Matchers.containsString)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