Skip to content

Commit

Permalink
returnAs提升为步骤的通用属性
Browse files Browse the repository at this point in the history
  • Loading branch information
entropy-cloud committed Dec 2, 2024
1 parent ae8ce72 commit c3bb279
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,24 @@
const subCaseMap = {}
function normalizeCase(subCase){
subCase.subCases = subCase.subCases?.map(caseItem=>{
subCase.subCases?.map(caseItem=>{
caseItem.subCases?.map(caseName=>{
return $.notNull(subCaseMap[caseName],"invalid caseName:"+caseName);
});
caseItem.removeProp('subCases');
});
}
rootRecord.subCases.$('sss')?.forEach(subCase=>{
rootRecord.subCaseMap?.forEach(subCase=>{
subCaseMap[subCase.name] = subCase;
});
rootRecord.subCaseMap?.forEach(normalizeCase);
rootRecord.removeProp('subCaseMap');
normalizeCase(rootRecord);
]]></normalizeFieldsExpr>

<sheets>
Expand Down
5 changes: 5 additions & 0 deletions nop-cli-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@
<artifactId>nop-batch-dsl</artifactId>
</dependency>

<dependency>
<groupId>io.github.entropy-cloud</groupId>
<artifactId>nop-batch-dao</artifactId>
</dependency>

<!-- <dependency>-->
<!-- <groupId>io.quarkus</groupId>-->
<!-- <artifactId>quarkus-resteasy-reactive</artifactId>-->
Expand Down
3 changes: 3 additions & 0 deletions nop-cli-core/src/test/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ quarkus:
level: INFO

nop:
orm:
init-database-schema: true

datasource:
driver-class-name: org.h2.Driver
jdbc-url: jdbc:h2:mem:test
Expand Down
Binary file modified nop-cli/demo/_vfs/batch/create-card.batch-gen.xlsx
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,38 @@
<input name="request" type="Map"/>
<input name="consume"/>

<x:config>
<c:import from="/nop/orm/xlib/dao.xlib"/>
</x:config>

<steps>
<xpl name="createCustomer" useParentScope="true">
<xpl name="createCustomer" useParentScope="true" returnAs="customer">
<source>
<c:var name="customerNumber" value="'C' + $Strings.randomDigits(20)"/>
<c:var name="customerNumber" value="${'C' + $String.randomDigits(20)}"/>
<dao:SaveEntity entityName="DemoCustomer" data="${{
firstName: request.customer.firstName,
lastName: request.customer.lastName,
gender: request.customer.gender,
customerNumber,
idCard: request.customer.idCard
idCard: request.customer.idCard,
partitionIndex: customerNumber.$shortHash()
}}"/>
</source>
<output name="customer">RESULT</output>
</xpl>

<xpl name="createAccount" useParentScope="true">
<xpl name="createAccount" useParentScope="true" returnAs="account">
<source>
<dao:SaveEntity entityName="DemoAccount" data="${{
customerId: customer.id,
partitionIndex: customer.partitionIndex
accountNumber: 'A'+$Strings.randomDigits(20),
partitionIndex: customer.partitionIndex,
accountNumber: 'A'+$String.randomDigits(20),
balance: request.account.balance
}}"/>
</source>
<output name="account">RESULT</output>
</xpl>

<custom name="createCard" customType="dao:SaveEntity"
dao:entityName="DemoCard" xmlns:dao="/nop/dao/xlib/dao.xlib"
dao:entityName="DemoCard" xmlns:dao="/nop/orm/xlib/dao.xlib"
dao:data="${{
customerId: customer.id,
accountId: account.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ public Object buildBean(@Nonnull Object src, @Nonnull IGenericType targetType, B

private Object _buildBean(Object src, IGenericType targetType, FieldSelectionBean selection,
BeanCopyOptions options) {
if(src == null)
return null;

Object target = options.getMappedObj(src);
if (target != null)
return target;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,5 +393,6 @@ private void initAbstractStep(TaskStepModel stepModel, AbstractTaskStep step) {
step.setInputs(stepModel.getInputs());
step.setOutputs(stepModel.getOutputs());
step.setConcurrent(stepModel.isConcurrent());
step.setReturnAs(stepModel.getReturnAs());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ public abstract class _InvokeTaskStepModel extends io.nop.task.model.TaskStepMod
*/
private java.lang.String _method ;

/**
*
* xml name: returnAs
* 指定bean方法的返回值所对应的返回变量名,缺省为RESULT
*/
private java.lang.String _returnAs ;

/**
*
* xml name:
Expand Down Expand Up @@ -82,25 +75,6 @@ public void setMethod(java.lang.String value){
}


/**
*
* xml name: returnAs
* 指定bean方法的返回值所对应的返回变量名,缺省为RESULT
*/

public java.lang.String getReturnAs(){
return _returnAs;
}


public void setReturnAs(java.lang.String value){
checkAllowChange();

this._returnAs = value;

}


/**
*
* xml name:
Expand Down Expand Up @@ -137,7 +111,6 @@ protected void outputJson(IJsonHandler out){

out.putNotNull("bean",this.getBean());
out.putNotNull("method",this.getMethod());
out.putNotNull("returnAs",this.getReturnAs());
out.putNotNull("type",this.getType());
}

Expand All @@ -152,7 +125,6 @@ protected void copyTo(InvokeTaskStepModel instance){

instance.setBean(this.getBean());
instance.setMethod(this.getMethod());
instance.setReturnAs(this.getReturnAs());
instance.setType(this.getType());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ public abstract class _TaskStepModel extends io.nop.task.model.TaskExecutableMod
*/
private boolean _recordMetrics = false;

/**
*
* xml name: returnAs
*
*/
private java.lang.String _returnAs ;

/**
*
* xml name: runOnContext
Expand Down Expand Up @@ -325,6 +332,25 @@ public void setRecordMetrics(boolean value){
}


/**
*
* xml name: returnAs
*
*/

public java.lang.String getReturnAs(){
return _returnAs;
}


public void setReturnAs(java.lang.String value){
checkAllowChange();

this._returnAs = value;

}


/**
*
* xml name: runOnContext
Expand Down Expand Up @@ -483,6 +509,7 @@ protected void outputJson(IJsonHandler out){
out.putNotNull("next",this.getNext());
out.putNotNull("nextOnError",this.getNextOnError());
out.putNotNull("recordMetrics",this.isRecordMetrics());
out.putNotNull("returnAs",this.getReturnAs());
out.putNotNull("runOnContext",this.isRunOnContext());
out.putNotNull("saveState",this.getSaveState());
out.putNotNull("sync",this.isSync());
Expand Down Expand Up @@ -511,6 +538,7 @@ protected void copyTo(TaskStepModel instance){
instance.setNext(this.getNext());
instance.setNextOnError(this.getNextOnError());
instance.setRecordMetrics(this.isRecordMetrics());
instance.setReturnAs(this.getReturnAs());
instance.setRunOnContext(this.isRunOnContext());
instance.setSaveState(this.getSaveState());
instance.setSync(this.isSync());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,37 @@
package io.nop.task.step;

import io.nop.api.core.util.SourceLocation;
import io.nop.commons.util.StringHelper;
import io.nop.task.ITaskStep;
import io.nop.task.TaskStepReturn;
import io.nop.task.model.ITaskInputModel;
import io.nop.task.model.ITaskOutputModel;

import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletionStage;

public abstract class AbstractTaskStep implements ITaskStep {
private SourceLocation location;
private String stepType;

private Set<String> persistVars;
private String returnAs;

private boolean concurrent;

private List<? extends ITaskInputModel> inputs = Collections.emptyList();

private List<? extends ITaskOutputModel> outputs = Collections.emptyList();

public String getReturnAs() {
return returnAs;
}

public void setReturnAs(String returnAs) {
this.returnAs = returnAs;
}

@Override
public SourceLocation getLocation() {
Expand Down Expand Up @@ -82,4 +93,21 @@ public List<? extends ITaskOutputModel> getOutputs() {
public void setOutputs(List<? extends ITaskOutputModel> outputs) {
this.outputs = outputs;
}

protected TaskStepReturn makeReturn(String nextStepName, Object returnValue) {
if (StringHelper.isEmpty(returnAs)) {
return TaskStepReturn.of(nextStepName, returnValue);
} else {
if (returnValue instanceof CompletionStage) {
return TaskStepReturn.of(nextStepName, ((CompletionStage) returnValue).thenApply(
v -> Collections.singletonMap(returnAs, v)));
} else {
return TaskStepReturn.RETURN(nextStepName, Collections.singletonMap(returnAs, returnValue));
}
}
}

protected TaskStepReturn makeReturn(Object returnValue) {
return makeReturn(null, returnValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import io.nop.task.TaskStepReturn;
import jakarta.annotation.Nonnull;

import java.util.concurrent.CompletionStage;

public class EndTaskStep extends AbstractTaskStep {
private IEvalAction result;

Expand All @@ -30,9 +28,6 @@ public void setResult(IEvalAction result) {
@Nonnull
public TaskStepReturn execute(ITaskStepRuntime stepRt) {
Object ret = result == null ? null : result.invoke(stepRt);
if (ret instanceof CompletionStage)
return TaskStepReturn.ASYNC(TaskConstants.STEP_NAME_END, (CompletionStage<?>) ret);

return TaskStepReturn.of(TaskConstants.STEP_NAME_END, ret);
return makeReturn(TaskConstants.STEP_NAME_END, ret);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ public void setSource(IEvalAction source) {
@Override
public TaskStepReturn execute(ITaskStepRuntime stepRt) {
Object result = source.invoke(stepRt);
return TaskStepReturn.of(null, result);
return makeReturn(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import io.nop.task.TaskStepReturn;
import jakarta.annotation.Nonnull;

import java.util.concurrent.CompletionStage;

public class ExitTaskStep extends AbstractTaskStep {
private IEvalAction result;

Expand All @@ -30,9 +28,6 @@ public void setResult(IEvalAction result) {
@Override
public TaskStepReturn execute(ITaskStepRuntime stepRt) {
Object ret = result == null ? null : result.invoke(stepRt);
if (ret instanceof CompletionStage)
return TaskStepReturn.ASYNC(TaskConstants.STEP_NAME_EXIT, (CompletionStage<?>) ret);

return TaskStepReturn.of(TaskConstants.STEP_NAME_EXIT, ret);
return makeReturn(TaskConstants.STEP_NAME_EXIT, ret);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
package io.nop.task.step;

import io.nop.api.core.exceptions.NopException;
import io.nop.commons.util.StringHelper;
import io.nop.core.CoreErrors;
import io.nop.core.lang.eval.IEvalScope;
import io.nop.core.reflect.IClassModel;
Expand All @@ -18,9 +17,7 @@
import io.nop.task.TaskStepReturn;
import jakarta.annotation.Nonnull;

import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletionStage;

import static io.nop.core.CoreErrors.ARG_CLASS_NAME;
import static io.nop.core.CoreErrors.ARG_COUNT;
Expand All @@ -32,8 +29,6 @@ public class InvokeTaskStep extends AbstractTaskStep {

private List<String> argNames;

private String returnAs;

public void setBeanName(String beanName) {
this.beanName = beanName;
}
Expand All @@ -46,14 +41,6 @@ public void setArgNames(List<String> argNames) {
this.argNames = argNames;
}

public String getReturnAs() {
return returnAs;
}

public void setReturnAs(String returnAs) {
this.returnAs = returnAs;
}

@Nonnull
@Override
public TaskStepReturn execute(ITaskStepRuntime stepRt) {
Expand All @@ -73,15 +60,6 @@ public TaskStepReturn execute(ITaskStepRuntime stepRt) {
.param(ARG_COUNT, args.length);

Object returnValue = method.invoke(bean, args, scope);
if (StringHelper.isEmpty(returnAs)) {
return TaskStepReturn.of(null, returnValue);
} else {
if (returnValue instanceof CompletionStage) {
return TaskStepReturn.of(null, ((CompletionStage) returnValue).thenApply(
v -> Collections.singletonMap(returnAs, v)));
} else {
return TaskStepReturn.RETURN(Collections.singletonMap(returnAs, returnValue));
}
}
return makeReturn(returnValue);
}
}
Loading

0 comments on commit c3bb279

Please sign in to comment.