mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-12-28 07:58:31 +00:00
added generic method to list entities (#5570)
This commit is contained in:
parent
a913cf46db
commit
88ffca764f
@ -0,0 +1,31 @@
|
||||
package org.openmetadata.client.listUtils;
|
||||
|
||||
import io.swagger.client.model.Paging;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ListUtils {
|
||||
|
||||
public static ArrayList<Object> listResults(Object client, String methodName, Class<?> className) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, ClassNotFoundException, InstantiationException {
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
Object classInstance = className.getDeclaredConstructor().newInstance();
|
||||
ArrayList<Object> arrayList = new ArrayList<>();
|
||||
Paging paging;
|
||||
String after;
|
||||
Method method = client.getClass().getMethod(methodName, Map.class);
|
||||
Method getData = classInstance.getClass().getMethod("getData");
|
||||
Method getPaging = classInstance.getClass().getMethod("getPaging");
|
||||
do {
|
||||
classInstance = method.invoke(client, data);
|
||||
arrayList.addAll((Collection<?>) getData.invoke(classInstance));
|
||||
paging = (Paging) getPaging.invoke(classInstance);
|
||||
after = paging.getAfter();
|
||||
data.put("after", after);
|
||||
} while (after != null);
|
||||
return arrayList;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user