Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (C) 2021 the original author or authors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package com.fizzgate.fizz.component.circle;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.function.BiFunction;
import org.noear.snack.ONode;
import com.fizzgate.fizz.StepContext;
import com.fizzgate.fizz.component.ComponentExecutor;
import com.fizzgate.fizz.component.ComponentResult;
import com.fizzgate.fizz.component.ComponentTypeEnum;
import com.fizzgate.fizz.component.IComponent;
import com.fizzgate.fizz.component.StepContextPosition;
import com.fizzgate.fizz.component.condition.Condition;
import com.fizzgate.fizz.exception.FizzRuntimeException;
import com.fizzgate.fizz.field.ValueTypeEnum;
import com.fizzgate.fizz.input.PathMapping;
import lombok.Data;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
/**
* Circle component
*
* @author Francis Dong
*
*/
public class Circle implements IComponent {
private static final String type = ComponentTypeEnum.CIRCLE.getCode();
private String desc;
private ValueTypeEnum dataSourceType;
private Object dataSource;
private List execConditions;
private List breakConditions;
@Override
public ComponentTypeEnum getType() {
return ComponentTypeEnum.getEnumByCode(type);
}
/**
*
* @param desc [optional] description
* @param dataSourceType [required] type of data source
* @param dataSource [required] data source
* @param execConditions [optional] conditions to execute current circle loop
* item
* @param breakConditions [optional] conditions to break circle
*/
public Circle(String desc, ValueTypeEnum dataSourceType, Object dataSource, List execConditions,
List breakConditions) {
this.desc = desc;
this.dataSourceType = dataSourceType;
this.dataSource = dataSource;
this.execConditions = execConditions;
this.breakConditions = breakConditions;
}
/**
* Current item
*/
private Object currentItem;
/**
* Index of current item
*/
private Integer index;
/**
* Fixed value of dataSource
*/
private Integer fixedValue;
/**
* Reference value of dataSource
*/
private Object refValue;
private boolean refReadFlag;
private Integer getFixedValue(ONode ctxNode) {
if (fixedValue != null) {
return fixedValue;
}
if (dataSource == null) {
return fixedValue;
}
if (dataSource instanceof Integer || dataSource instanceof Long || dataSource instanceof String) {
try {
fixedValue = Integer.valueOf(dataSource.toString());
} catch (Exception e) {
throw new FizzRuntimeException("invalid data source, fixed data source must be a positive integer");
}
if (fixedValue.intValue() < 1) {
throw new FizzRuntimeException("invalid data source, fixed data source must be a positive integer");
}
return fixedValue;
} else {
throw new FizzRuntimeException("invalid data source, fixed data source must be a positive integer");
}
}
@SuppressWarnings("unchecked")
private Object getRefValue(ONode ctxNode) {
if (refReadFlag) {
return refValue;
}
Object value = PathMapping.getValueByPath(ctxNode, (String) dataSource);
if (value == null) {
return null;
}
if (value instanceof Collection) {
refValue = (List