Skip to content

Commit

Permalink
fix(sdk-java): Remove output schema when there is not return type in …
Browse files Browse the repository at this point in the history
…LHTaskMethod
  • Loading branch information
KarlaCarvajal committed Nov 29, 2024
1 parent 1183aec commit bbff05d
Showing 1 changed file with 29 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,17 @@ public LHTaskSignature(String taskDefName, Object executable, String lhTaskMetho
+ " on "
+ executable.getClass());
}
VariableType returnType = LHLibUtil.javaClassToLHVarType(taskMethod.getReturnType());
boolean maskedValue = false;
String outputSchemaVarName = "output";
if (taskMethod.isAnnotationPresent(LHType.class)) {
LHType type = taskMethod.getAnnotation(LHType.class);
maskedValue = type.masked();
if (!type.name().isEmpty() || !type.name().isBlank()) {
outputSchemaVarName = type.name();
}

Class<?> returnType = taskMethod.getReturnType();

buildInputVarsSignature();

if (!void.class.isAssignableFrom(returnType)) {
buildOutputSchemaSignature(returnType);
}
outputSchema = TaskDefOutputSchema.newBuilder()
.setValueDef(VariableDef.newBuilder()
.setType(returnType)
.setName(outputSchemaVarName)
.setMaskedValue(maskedValue)
.build())
.build();
}

private void buildInputVarsSignature() {
for (int i = 0; i < taskMethod.getParameterCount(); i++) {
Parameter param = taskMethod.getParameters()[i];
if (param.getType().equals(WorkerContext.class)) {
Expand Down Expand Up @@ -105,6 +98,26 @@ public LHTaskSignature(String taskDefName, Object executable, String lhTaskMetho
}
}

private void buildOutputSchemaSignature(Class<?> classReturnType) {
VariableType returnType = LHLibUtil.javaClassToLHVarType(classReturnType);
boolean maskedValue = false;
String outputSchemaVarName = "output";
if (taskMethod.isAnnotationPresent(LHType.class)) {
LHType type = taskMethod.getAnnotation(LHType.class);
maskedValue = type.masked();
if (!type.name().isEmpty() || !type.name().isBlank()) {
outputSchemaVarName = type.name();
}
}
outputSchema = TaskDefOutputSchema.newBuilder()
.setValueDef(VariableDef.newBuilder()
.setType(returnType)
.setName(outputSchemaVarName)
.setMaskedValue(maskedValue)
.build())
.build();
}

private String varNameFromParameterName(Parameter param) {
if (!param.isNamePresent()) {
log.warn(
Expand Down

0 comments on commit bbff05d

Please sign in to comment.