我有一个GenerateFlowFile处理器,我有2个属性userId(等于= 1)和参数(等于= 5),我有服务,应该给我每个userId(1到5)的repsonse所以我需要调用它5次,我想要的是在执行脚本中创建5个流文件以使用相关的id调用服务5次我已经尝试过以下代码,但它对我不起作用你能给我任何建议我该怎么办?
public class MainActivity extends AppCompatActivity {
private String text ;
private TextView textView, textView2,textView3,textView4;
private SearchView searchView;
private ListView listView ;
private String[] il={"Adana", "Adıyaman", "Afyon", "Ağrı", "Amasya", "Ankara", "Antalya", "Artvin",
"Aydın", "Balıkesir", "Bilecik", "Bingöl", "Bitlis", "Bolu", "Burdur", "Bursa", "Çanakkale",
"Çankırı", "Çorum", "Denizli", "Diyarbakır", "Edirne", "Elazığ", "Erzincan", "Erzurum", "Eskişehir",
"Gaziantep", "Giresun", "Gümüşhane", "Hakkari", "Hatay", "Isparta", "Mersin", "İstanbul", "İzmir",
"Kars", "Kastamonu", "Kayseri", "Kırklareli", "Kırşehir", "Kocaeli", "Konya", "Kütahya", "Malatya",
"Manisa", "Kahramanmaraş", "Mardin", "Muğla", "Muş", "Nevşehir", "Niğde", "Ordu", "Rize", "Sakarya",
"Samsun", "Siirt", "Sinop", "Sivas", "Tekirdağ", "Tokat", "Trabzon", "Tunceli", "Şanlıurfa", "Uşak",
"Van", "Yozgat", "Zonguldak", "Aksaray", "Bayburt", "Karaman", "Kırıkkale", "Batman", "Şırnak",
"Bartın", "Ardahan", "Iğdır", "Yalova", "Karabük", "Kilis", "Osmaniye", "Düzce"};
private ArrayAdapter<String> arrayAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
searchView= (SearchView) findViewById(R.id.searchView);
listView= (ListView) findViewById(R.id.listView);
final SendData sendData = (SendData) this;
FragmentA fragmentA = new FragmentA() ;
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.add(R.id.frameLayout,fragmentA,"fragA");
transaction.commit();
arrayAdapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,android.R.id.text1,il);
listView.setAdapter(arrayAdapter);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
arrayAdapter.getFilter().filter(newText);
return false;
}
});
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, final int position, long id) {
text = (String) listView.getItemAtPosition(position);
sendData.gonder(text);
}
});
}
答案 0 :(得分:0)
var OutputStreamCallback = Java.type("org.apache.nifi.processor.io.OutputStreamCallback");
var StandardCharsets = Java.type("java.nio.charset.StandardCharsets");
Date.prototype.isValid = function ()
{
return (Object.prototype.toString.call(this) === "[object Date]") && !isNaN(this.getTime());
};
var flowFile=session.get()
if (flowFile != null) {
var userId = flowFile.getAttribute('userId')
var parameter = flowFile.getAttribute('parameter')
var i = 0;
for(i=0;i<=parameter;i++) {
var flowfile1=session.create();
userId++;
flowfile1 = session.putAttribute(flowfile1, 'filename', userId);
flowfile1 = session.write(flowfile1,
new OutputStreamCallback(function (outputStream) {
outputStream.write(0)
}));
session.transfer(flowfile1, REL_SUCCESS)
parameter--;
}
session.remove(flowFile)
}