루프 작업용 맞춤형 패키지에서 반복자 추가
루프 action용 패키지에서 반복자를 추가합니다
루프 작업에 반복자를 추가합니다.
- 반복자를 생성하려면 BotCommand 주석 기호의 commandType 특성을 값과 함께 반복자로 설정합니다.
- 반복자는 두 가지 방법을 필요로 하며, 이는 HasNext와 Next 주석기호로 정의됩니다.
@BotCommand(commandType = BotCommand.CommandType.Iterator)
@CommandPkg(name = "loop.iterators.files",
label = "For each file in folder",
node_label = "for each file and assign file name and extension to {{returnTo}}",
description = "Iterator for each file in folder.",
return_type = DataType.DICTIONARY,
return_sub_type = DataType.STRING,
return_required = true,
return_description = "Note: Access the 'name' key to access file name and 'extension'
key to access the file extension.",
return_label = "Assign file name and extension to this variable")
public class FileLoop extends AbstractCommandFileIterator {
@Idx(index = "1", type = AttributeType.TEXT)
@Pkg(label = "Folder path")
@Inject
@NotEmpty
private String folderPath;
@HasNext
public boolean hasNext() {
return getFileIterator(folderPath).hasNext();
}
@Next
public Value<?> next() {
Map<String, Value> returnValueMap = new HashMap<>();
FileIterator fileIterator = getFileIterator(folderPath);
String fileName = fileIterator.getNext();
returnValueMap.put(FILE_NAME, new StringValue(fileIterator.getFileName(fileName)));
returnValueMap.put(EXTENSION, new StringValue(fileIterator.getExtension(fileName)));
return new DictionaryValue(returnValueMap);
}
public void setFolderPath(String folderPath) {
this.folderPath = folderPath;
}
}