use of com.accenture.trac.common.exception.EInputValidation in project tracdap by finos.
the class RestApiTranslator method translateRequestBody.
public Message translateRequestBody(ByteBuf bodyBuffer) {
if (!hasBody)
throw new EUnexpected();
var bodyType = (blankBody != null) ? blankBody : blankRequest;
try (var jsonStream = new ByteBufInputStream(bodyBuffer);
var jsonReader = new InputStreamReader(jsonStream)) {
var bodyBuilder = bodyType.newBuilderForType();
var jsonParser = JsonFormat.parser();
jsonParser.merge(jsonReader, bodyBuilder);
return bodyBuilder.build();
} catch (InvalidProtocolBufferException e) {
// Validation failures will go back to users (API users, i.e. application developers)
// Strip out GSON class name from the error message for readability
var detailMessage = e.getLocalizedMessage();
var classNamePrefix = MalformedJsonException.class.getName() + ": ";
if (detailMessage.startsWith(classNamePrefix))
detailMessage = detailMessage.substring(classNamePrefix.length());
var message = String.format("Invalid JSON input for type [%s]: %s", bodyType.getDescriptorForType().getName(), detailMessage);
log.warn(message);
throw new EInputValidation(message, e);
} catch (IOException e) {
// Shouldn't happen, reader source is a buffer already held in memory
log.error("Unexpected IO error reading from internal buffer", e);
throw new EUnexpected();
}
}
use of com.accenture.trac.common.exception.EInputValidation in project tracdap by finos.
the class JobLifecycle method convertFlowToModel.
JobState convertFlowToModel(JobState jobState) {
if (jobState.definition.getJobType() != JobType.RUN_FLOW)
return jobState;
var runFlow = jobState.definition.getRunFlow();
if (runFlow.getModelsCount() != 1)
throw new EInputValidation("Run flow must be supplied with a single model for the preview implementation");
var modelSelector = runFlow.getModelsMap().values().stream().findFirst();
if (modelSelector.isEmpty())
throw new EInputValidation("Run flow must be supplied with a single model for the preview implementation");
var runModel = RunModelJob.newBuilder().setModel(modelSelector.get()).putAllParameters(runFlow.getParametersMap()).putAllInputs(runFlow.getInputsMap()).putAllOutputs(runFlow.getOutputsMap()).putAllPriorOutputs(runFlow.getPriorOutputsMap()).addAllOutputAttrs(runFlow.getOutputAttrsList()).build();
var jobDef = jobState.definition.toBuilder().setJobType(JobType.IMPORT_MODEL).setRunModel(runModel).build();
var newState = jobState.clone();
newState.definition = jobDef;
return newState;
}
Aggregations