Search in sources :

Example 1 with DroolsService

use of gov.ca.cwds.drools.DroolsService in project api-core by ca-cwds.

the class ClientResultReadAuthorizerTest method init.

@Before
public void init() {
    MockitoAnnotations.initMocks(this);
    final DroolsService droolsService = new DroolsService();
    final DroolsAuthorizationService droolsAuthorizationService = new DroolsAuthorizationService(droolsService);
    testSubject = new ClientResultReadAuthorizer(droolsAuthorizationService, new ClientResultAuthorizationDroolsConfiguration());
    testSubject.setCountyDeterminationService(clientCountyDeterminationServiceMock);
}
Also used : DroolsAuthorizationService(gov.ca.cwds.authorizer.drools.DroolsAuthorizationService) ClientResultAuthorizationDroolsConfiguration(gov.ca.cwds.authorizer.drools.configuration.ClientResultAuthorizationDroolsConfiguration) DroolsService(gov.ca.cwds.drools.DroolsService) Before(org.junit.Before)

Example 2 with DroolsService

use of gov.ca.cwds.drools.DroolsService in project api-core by ca-cwds.

the class SubstituteCareProviderCreateAuthorizerTest method init.

@Before
public void init() {
    MockitoAnnotations.initMocks(this);
    final DroolsService droolsService = new DroolsService();
    final DroolsAuthorizationService droolsAuthorizationService = new DroolsAuthorizationService(droolsService);
    testSubject = new SubstituteCareProviderCreateAuthorizer(droolsAuthorizationService, new SubstituteCareProviderAuthorizationDroolsConfiguration());
}
Also used : DroolsAuthorizationService(gov.ca.cwds.authorizer.drools.DroolsAuthorizationService) SubstituteCareProviderAuthorizationDroolsConfiguration(gov.ca.cwds.authorizer.drools.configuration.SubstituteCareProviderAuthorizationDroolsConfiguration) DroolsService(gov.ca.cwds.drools.DroolsService) Before(org.junit.Before)

Example 3 with DroolsService

use of gov.ca.cwds.drools.DroolsService in project api-core by ca-cwds.

the class ClientAbstractReadAuthorizerTest method init.

@Before
public void init() {
    MockitoAnnotations.initMocks(this);
    final DroolsService droolsService = new DroolsService();
    final DroolsAuthorizationService droolsAuthorizationService = new DroolsAuthorizationService(droolsService);
    final ClientAbstractAuthorizationDroolsConfiguration droolsConfiguration = new ClientAbstractAuthorizationDroolsConfiguration();
    testSubject = new ClientAbstractReadAuthorizer(droolsAuthorizationService, droolsConfiguration);
    testSubject.setSensitivityDeterminationService(clientSensitivityDeterminationService);
    testSubject.setCountyDeterminationService(clientCountyDeterminationService);
}
Also used : DroolsAuthorizationService(gov.ca.cwds.authorizer.drools.DroolsAuthorizationService) DroolsService(gov.ca.cwds.drools.DroolsService) ClientAbstractAuthorizationDroolsConfiguration(gov.ca.cwds.authorizer.drools.configuration.ClientAbstractAuthorizationDroolsConfiguration) Before(org.junit.Before)

Example 4 with DroolsService

use of gov.ca.cwds.drools.DroolsService in project api-core by ca-cwds.

the class PlacementHomeCreateAuthorizerTest method init.

@Before
public void init() {
    MockitoAnnotations.initMocks(this);
    final DroolsService droolsService = new DroolsService();
    final DroolsAuthorizationService droolsAuthorizationService = new DroolsAuthorizationService(droolsService);
    testSubject = new PlacementHomeCreateAuthorizer(droolsAuthorizationService, new PlacementHomeAuthorizationDroolsConfiguration());
}
Also used : DroolsAuthorizationService(gov.ca.cwds.authorizer.drools.DroolsAuthorizationService) PlacementHomeAuthorizationDroolsConfiguration(gov.ca.cwds.authorizer.drools.configuration.PlacementHomeAuthorizationDroolsConfiguration) DroolsService(gov.ca.cwds.drools.DroolsService) Before(org.junit.Before)

Example 5 with DroolsService

use of gov.ca.cwds.drools.DroolsService in project api-core by ca-cwds.

the class DroolsValidator method isValid.

@Override
public boolean isValid(T obj, ConstraintValidatorContext context) {
    if (obj == null) {
        return true;
    }
    DroolsConfiguration<T> configuration = getConfiguration();
    Object validatedFact = configuration.getValidatedFact(obj);
    DroolsService droolsService = InjectorHolder.INSTANCE.getInstance(DroolsService.class);
    Set<IssueDetails> detailsList = null;
    try {
        detailsList = droolsService.performBusinessRules(configuration, validatedFact);
    } catch (DroolsException e) {
        LOGGER.warn(e.getMessage(), e);
        throw new RuntimeException(String.format(DroolsErrorMessages.CANT_PERFORM_BUSINESS_VALIDATION, configuration.getAgendaGroup()));
    }
    if (detailsList.isEmpty()) {
        return true;
    } else {
        context.disableDefaultConstraintViolation();
        detailsList.forEach((details -> context.buildConstraintViolationWithTemplate(marshallData(details)).addPropertyNode("").addConstraintViolation()));
        return false;
    }
}
Also used : DroolsErrorMessages(gov.ca.cwds.drools.DroolsErrorMessages) Logger(org.slf4j.Logger) ConstraintValidator(javax.validation.ConstraintValidator) ConstraintValidatorContext(javax.validation.ConstraintValidatorContext) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) InjectorHolder(gov.ca.cwds.inject.InjectorHolder) DroolsConfiguration(gov.ca.cwds.drools.DroolsConfiguration) IssueDetails(gov.ca.cwds.rest.exception.IssueDetails) DroolsException(gov.ca.cwds.drools.DroolsException) JsonUtils(gov.ca.cwds.utils.JsonUtils) Annotation(java.lang.annotation.Annotation) DroolsService(gov.ca.cwds.drools.DroolsService) DroolsException(gov.ca.cwds.drools.DroolsException) IssueDetails(gov.ca.cwds.rest.exception.IssueDetails) DroolsService(gov.ca.cwds.drools.DroolsService)

Aggregations

DroolsService (gov.ca.cwds.drools.DroolsService)6 Before (org.junit.Before)5 DroolsAuthorizationService (gov.ca.cwds.authorizer.drools.DroolsAuthorizationService)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ClientAbstractAuthorizationDroolsConfiguration (gov.ca.cwds.authorizer.drools.configuration.ClientAbstractAuthorizationDroolsConfiguration)1 ClientResultAuthorizationDroolsConfiguration (gov.ca.cwds.authorizer.drools.configuration.ClientResultAuthorizationDroolsConfiguration)1 PlacementHomeAuthorizationDroolsConfiguration (gov.ca.cwds.authorizer.drools.configuration.PlacementHomeAuthorizationDroolsConfiguration)1 SubstituteCareProviderAuthorizationDroolsConfiguration (gov.ca.cwds.authorizer.drools.configuration.SubstituteCareProviderAuthorizationDroolsConfiguration)1 DroolsConfiguration (gov.ca.cwds.drools.DroolsConfiguration)1 DroolsErrorMessages (gov.ca.cwds.drools.DroolsErrorMessages)1 DroolsException (gov.ca.cwds.drools.DroolsException)1 InjectorHolder (gov.ca.cwds.inject.InjectorHolder)1 IssueDetails (gov.ca.cwds.rest.exception.IssueDetails)1 JsonUtils (gov.ca.cwds.utils.JsonUtils)1 Annotation (java.lang.annotation.Annotation)1 Set (java.util.Set)1 ConstraintValidator (javax.validation.ConstraintValidator)1 ConstraintValidatorContext (javax.validation.ConstraintValidatorContext)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1