Package SDK를 사용하여 반복자 생성

Automation 360에서 SDK 패키지로 반복자를 생성할 수 있습니다. 반복자는 비슷한 유형의 여러 객체를 반복 루프하는 데 사용되며 루프 패키지와 함께 사용됩니다. 두 가지 메소드, 즉 nexthasNext로 구성되어 실제 객체와 부울 값을 반환합니다.

필요한 주석 기호

반복자를 사용하면 next 메소드가 사용 가능한 다음 값을 반환합니다. 더 이상 사용할 수 있는 값이 없으면 예외가 표시됩니다. hasNext 메소드는 다른 값을 확인하고 더 이상 값을 사용할 수 없는 경우 false를 반환합니다. Automation 360에서 루프가 실행될 때 hasNext()가 먼저 호출되고, hasNext()true 값을 반환한 경우에만 next()가 호출됩니다.

반복자를 생성하려면 다음 주석 기호가 필요합니다.

주석 기호 사용량
BotCommand BotCommand 주석 기호를 iterator에서 commandType으로 사용합니다. 이렇게 하면 일반 구형 Java 객체(POJO)가 Automation 360 반복자를 생성할 수 있습니다.
CommandPkg 패키지를 만들 때 주석 기호에 이름, 라벨 및 설명을 제공합니다.
Idx 필요한 모든 매개변수와 구성원 변수에 주석 기호를 지정하고 유효성 검사를 도와주거나, 입력을 위해 인터페이스에 표시할 수 있습니다. Idx 및 유형을 제공합니다.
Pkg 인터페이스에 표시될 모든 매개변수와 구성원 변수에 주석 기호를 지정합니다. 이 주석 기호는 Idx와 함께 제공되지 않으면 무시됩니다.
HasNext 반복자에 더 많은 요소가 있는 경우 테스트를 위해 호출되어야 하는 메소드(next()가 예외를 throw하는 대신 요소를 반환하는 경우 true 반환). 부울 값을 반환해야 합니다.

메소드가 매개변수를 허용하는 경우, Idx로 주석 기호를 지정해야 합니다. hasNext 메소드는 값을 더 이상 사용할 수 없는 경우 이를 확인하고 false를 반환합니다. Automation 360에서 루프가 실행되면 hasNext()가 먼저 호출됩니다. hasNext()true 값을 반환하는 경우에만 next()가 호출됩니다.

Next 메소드는 반복에서 다음으로 사용 가능한 값을 반환합니다. 반환 유형은 값입니다. 값을 더 이상 가용하지 않은 경우, 예외가 표시됩니다.
사용 사례 예시

예시 사용 사례는 예를 들어 (int i=0; I<n; i++) Java 구성의 경우 횟수를 통해 반복됩니다. 이 옵션은 Bot가 생성될 때 Bot Creatorn 값을 허용합니다.

  1. 모든 기능이 샘플에 설명된 대로 작동하도록 다음 패키지를 가져왔는지 확인합니다.
    import com.automationanywhere.botcommand.data.Value;
    import com.automationanywhere.botcommand.data.impl.NumberValue;
    import com.automationanywhere.commandsdk.annotations.BotCommand;
    import com.automationanywhere.commandsdk.annotations.CommandPkg;
    import com.automationanywhere.commandsdk.annotations.HasNext;
    import com.automationanywhere.commandsdk.annotations.Idx;
    import com.automationanywhere.commandsdk.annotations.Inject;
    import com.automationanywhere.commandsdk.annotations.Next;
    import com.automationanywhere.commandsdk.annotations.Pkg;
    import com.automationanywhere.commandsdk.annotations.BotCommand.CommandType;
    import com.automationanywhere.commandsdk.annotations.rules.GreaterThanEqualTo;
    import com.automationanywhere.commandsdk.annotations.rules.NotEmpty;
    import com.automationanywhere.commandsdk.annotations.rules.NumberInteger;
    import com.automationanywhere.commandsdk.model.AttributeType;
    import com.automationanywhere.commandsdk.model.DataType;
  2. 비즈니스 로직으로 POJO 클래스를 만듭니다.

    POJO에 메소드가 있고 부울 값이 반환되는지 확인합니다. 이는 비교 방법으로 사용됩니다.

    @BotCommand(commandType=CommandType.Iterator)
    @CommandPkg(return_label = "Return the value in variable", node_label = ": {{times}} times", 
    label = "Iterator demo", description = "Iterate number of times", name = "iteratorTypeDemo", return_type = DataType.NUMBER)
    public class IteratorTypeDemo {
        @Idx(index = "1", type = AttributeType.NUMBER)
        @Pkg(label = "times", default_value = "10", default_value_type = DataType.NUMBER)
        @GreaterThanEqualTo("0")
        @NumberInteger
        @NotEmpty
        @Inject
    	private Double times = 10d;
    
    	private Double counter = 0d;
    
        @HasNext
        public boolean hasNext() {
    		return counter < times;
        }
    
        @Next
        public Value<Double> next() throws Exception{
    		if (counter >= times)
    			throw new Exception("Counter '"+ counter +"' is exceed the times limit '"+times+"'");
    
    		counter++;
            NumberValue result = new NumberValue();
            result.set(counter);
            return result;
        }
    
        public void setTimes(Double times) {
            this.times = times;
        }
    }
  3. POJO 클래스에 주석을 달아 Automation 360 반복자에 대해 이를 활성화하고 패키지를 만듭니다.
    @BotCommand(commandType = CommandType.Iterator)
    @CommandPkg(return_label = "Return the value in variable", node_label = ": {{times}} times",
    	label = "Iterator demo", description = "Iterate number of times", name = "iteratorTypeDemo", return_type = DataType.NUMBER)
    public class IteratorTypeDemo {
    
    	private Double times = 10 d;
    	private Double counter = 0 d;
    
    	public boolean hasNext() {
    		return counter < times;
    	}
  4. hasNext()next() 메소드에 적절하게 주석 기호를 추가합니다.
    @HasNext
    public boolean hasNext() {
    	return counter < times;
    }
    
    @Next
    public Value < Double > next() throws Exception {
    	if (counter >= times)
    		throw new Exception("Counter '" + counter + "' is exceed the times limit '" + times + "'");
    
    	counter++;
    	NumberValue result = new NumberValue();
    	result.set(counter);
    	return result;
    }

    이 메소드는 사용하기 쉬운 방식으로 명명되며 Java 반복자 인터페이스와 병렬로 표시됩니다. 메소드의 이름을 지정할 때 SDK 측에 제한이 없습니다.

    반복자에서는 매개변수 방법을 사용하지 말고, setter injection을 사용합니다.

  5. 변수에 IdxPkg 주석 기호를 추가합니다.

    @NotEmpty를 추가하여 값이 null이 아닌지 확인하고, @GreaterThanEqualTo를 추가하여 값이 항상 0보다 큰지 확인합니다.

    @Idx(index = "1", type = AttributeType.NUMBER)
    @Pkg(label = "times", default_value = "10", default_value_type = DataType.NUMBER)
    @GreaterThanEqualTo("0")
    @NotEmpty
    @Inject
    private Double times = 10 d;

    속성 유형 숫자는 Double로 반환합니다.