// Build a proper configuration from POST data.
Configuration inputConfig = new Configuration(lr.configuration);
// Build input.
MessageInput input;
try {
input = inputRegistry.create(lr.type, inputConfig);
input.setTitle(lr.title);
input.setCreatorUserId(lr.creatorUserId);
input.setCreatedAt(Tools.iso8601());
input.setGlobal(lr.global);
input.setConfiguration(inputConfig);
input.checkConfiguration();
} catch (NoSuchInputTypeException e) {
LOG.error("There is no such input type registered.", e);
throw new BadRequestException(e);
} catch (ConfigurationException e) {
LOG.error("Missing or invalid input configuration.", e);
throw new BadRequestException(e);
}
String inputId = UUID.randomUUID().toString();
input.setPersistId(inputId);
// Don't run if exclusive and another instance is already running.
if (input.isExclusive() && inputRegistry.hasTypeRunning(input.getClass())) {
LOG.error("Type is exclusive and already has input running.");
throw new BadRequestException();
}
input.initialize();
// Launch input. (this will run async and clean up itself in case of an error.)
inputRegistry.launch(input, inputId, true);
final Map<String, String> result = ImmutableMap.of(