use of com.redhat.service.bridge.actions.ActionProvider in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ActionParamValidatorContainer method isValid.
@Override
public boolean isValid(ProcessorRequest value, ConstraintValidatorContext context) {
/*
* Centralised handling of Action parameters. The idea here being that for each Action we support, we
* provide the ability to check:
*
* - The action 'type' is recognised
* - The parameters supplied to configure the Action are valid.
*/
BaseAction baseAction = value.getAction();
if (baseAction == null) {
return false;
}
if (baseAction.getParameters() == null) {
return false;
}
ActionProvider actionProvider;
try {
actionProvider = actionProviderFactory.getActionProvider(baseAction.getType());
} catch (ActionProviderException e) {
context.disableDefaultConstraintViolation();
HibernateConstraintValidatorContext hibernateContext = context.unwrap(HibernateConstraintValidatorContext.class);
hibernateContext.addMessageParameter(TYPE_PARAM, baseAction.getType());
hibernateContext.buildConstraintViolationWithTemplate(ACTION_TYPE_NOT_RECOGNISED_ERROR).addConstraintViolation();
return false;
}
ValidationResult v = actionProvider.getParameterValidator().isValid(baseAction);
if (!v.isValid()) {
String message = v.getMessage();
context.disableDefaultConstraintViolation();
if (message == null) {
message = ACTION_PARAMETERS_NOT_VALID_ERROR;
HibernateConstraintValidatorContext hibernateContext = context.unwrap(HibernateConstraintValidatorContext.class);
hibernateContext.addMessageParameter(TYPE_PARAM, baseAction.getType());
} else {
message = InterpolationHelper.escapeMessageParameter(message);
}
context.buildConstraintViolationWithTemplate(message).addConstraintViolation();
}
return v.isValid();
}
use of com.redhat.service.bridge.actions.ActionProvider in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ActionParamValidatorContainerTest method beforeEach.
@BeforeEach
public void beforeEach() {
actionValidatorMock = mock(ActionParameterValidator.class);
when(actionValidatorMock.isValid(any())).thenReturn(ValidationResult.valid());
ActionProvider actionProviderMock = mock(ActionProvider.class);
when(actionProviderMock.getParameterValidator()).thenReturn(actionValidatorMock);
reset(actionProviderFactoryMock);
when(actionProviderFactoryMock.getActionProvider(TEST_ACTION_TYPE)).thenReturn(actionProviderMock);
when(actionProviderFactoryMock.getActionProvider(not(eq(TEST_ACTION_TYPE)))).thenThrow(new ActionProviderException("No action provider found"));
validatorContext = mock(HibernateConstraintValidatorContext.class);
builderMock = mock(HibernateConstraintViolationBuilder.class);
when(validatorContext.buildConstraintViolationWithTemplate(any(String.class))).thenReturn(builderMock);
when(validatorContext.unwrap(HibernateConstraintValidatorContext.class)).thenReturn(validatorContext);
}
use of com.redhat.service.bridge.actions.ActionProvider in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorServiceImpl method createProcessor.
@Override
public Processor createProcessor(String bridgeId, String customerId, ProcessorRequest processorRequest) {
/* We cannot deploy Processors to a Bridge that is not Available */
Bridge bridge = bridgesService.getReadyBridge(bridgeId, customerId);
if (processorDAO.findByBridgeIdAndName(bridgeId, processorRequest.getName()) != null) {
throw new AlreadyExistingItemException("Processor with name '" + processorRequest.getName() + "' already exists for bridge with id '" + bridgeId + "' for customer '" + customerId + "'");
}
Processor newProcessor = new Processor();
Set<BaseFilter> requestedFilters = processorRequest.getFilters();
String requestedTransformationTemplate = processorRequest.getTransformationTemplate();
BaseAction requestedAction = processorRequest.getAction();
ActionProvider actionProvider = actionProviderFactory.getActionProvider(requestedAction.getType());
BaseAction resolvedAction = actionProviderFactory.resolve(requestedAction, bridge.getId(), customerId, newProcessor.getId());
newProcessor.setName(processorRequest.getName());
newProcessor.setSubmittedAt(ZonedDateTime.now());
newProcessor.setStatus(ManagedResourceStatus.ACCEPTED);
newProcessor.setBridge(bridge);
newProcessor.setShardId(shardService.getAssignedShardId(newProcessor.getId()));
ProcessorDefinition definition = new ProcessorDefinition(requestedFilters, requestedTransformationTemplate, requestedAction, resolvedAction);
newProcessor.setDefinition(definitionToJsonNode(definition));
LOGGER.info("Processor with id '{}' for customer '{}' on bridge '{}' has been marked for creation", newProcessor.getId(), newProcessor.getBridge().getCustomerId(), newProcessor.getBridge().getId());
createProcessorConnectorEntity(newProcessor, actionProvider, resolvedAction);
workManager.schedule(newProcessor);
return newProcessor;
}
Aggregations