private static Optional<ThrowingConsumer<Context>> validateUseMessage(final RequestMessage message) throws OpProcessorException {
final Optional<List> l = message.optionalArgs(Tokens.ARGS_COORDINATES);
if (!l.isPresent()) {
final String msg = String.format("A message with an [%s] op code requires a [%s] argument.",
Tokens.OPS_USE, Tokens.ARGS_COORDINATES);
throw new OpProcessorException(msg, ResponseMessage.build(message).code(ResponseStatusCode.REQUEST_ERROR_INVALID_REQUEST_ARGUMENTS).result(msg).create());
}
final List coordinates = l.orElse(new ArrayList());
if (coordinates.size() == 0) {
final String msg = String.format(
"A message with an [%s] op code requires that the [%s] argument has at least one set of valid maven coordinates specified.",
Tokens.OPS_USE, Tokens.ARGS_COORDINATES);
throw new OpProcessorException(msg, ResponseMessage.build(message).code(ResponseStatusCode.REQUEST_ERROR_INVALID_REQUEST_ARGUMENTS).result(msg).create());
}
if (!coordinates.stream().allMatch(ControlOpProcessor::validateCoordinates)) {
final String msg = String.format(
"A message with an [%s] op code requires that all [%s] specified are valid maven coordinates with a group, artifact, and version.",
Tokens.OPS_USE, Tokens.ARGS_COORDINATES);
throw new OpProcessorException(msg, ResponseMessage.build(message).code(ResponseStatusCode.REQUEST_ERROR_INVALID_REQUEST_ARGUMENTS).result(msg).create());
}
return Optional.empty();
}