Search in sources :

Example 1 with ERROR_PROGRAM_NOT_SUPPORTED

use of org.openlmis.stockmanagement.i18n.MessageKeys.ERROR_PROGRAM_NOT_SUPPORTED in project openlmis-stockmanagement by OpenLMIS.

the class HomeFacilityPermissionService method checkProgramSupported.

/**
 * Check if program is supported by user's home facility.
 *
 * @param programId  the program's id.
 */
public void checkProgramSupported(UUID programId) {
    UUID homeFacilityId = authenticationHelper.getCurrentUser().getHomeFacilityId();
    FacilityDto homeFacility = null;
    if (homeFacilityId != null) {
        homeFacility = facilityService.findOne(homeFacilityId);
    }
    boolean isSupported = homeFacility != null && homeFacility.getSupportedPrograms().stream().anyMatch(supportedProgram -> programId.equals(supportedProgram.getId()));
    if (!isSupported) {
        throwException(ERROR_PROGRAM_NOT_SUPPORTED, programId.toString());
    }
}
Also used : ERROR_PROGRAM_NOT_SUPPORTED(org.openlmis.stockmanagement.i18n.MessageKeys.ERROR_PROGRAM_NOT_SUPPORTED) FacilityReferenceDataService(org.openlmis.stockmanagement.service.referencedata.FacilityReferenceDataService) AuthenticationHelper(org.openlmis.stockmanagement.util.AuthenticationHelper) Message(org.openlmis.stockmanagement.util.Message) Service(org.springframework.stereotype.Service) Autowired(org.springframework.beans.factory.annotation.Autowired) UUID(java.util.UUID) FacilityDto(org.openlmis.stockmanagement.dto.referencedata.FacilityDto) PermissionMessageException(org.openlmis.stockmanagement.exception.PermissionMessageException) FacilityDto(org.openlmis.stockmanagement.dto.referencedata.FacilityDto) UUID(java.util.UUID)

Aggregations

UUID (java.util.UUID)1 FacilityDto (org.openlmis.stockmanagement.dto.referencedata.FacilityDto)1 PermissionMessageException (org.openlmis.stockmanagement.exception.PermissionMessageException)1 ERROR_PROGRAM_NOT_SUPPORTED (org.openlmis.stockmanagement.i18n.MessageKeys.ERROR_PROGRAM_NOT_SUPPORTED)1 FacilityReferenceDataService (org.openlmis.stockmanagement.service.referencedata.FacilityReferenceDataService)1 AuthenticationHelper (org.openlmis.stockmanagement.util.AuthenticationHelper)1 Message (org.openlmis.stockmanagement.util.Message)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Service (org.springframework.stereotype.Service)1