All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openmetadata.client.listUtils.ListUtils Maven / Gradle / Ivy

There is a newer version: 1.5.11
Show newest version
package org.openmetadata.client.listUtils;

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;
import org.openmetadata.client.model.Paging;

public class ListUtils {

  private ListUtils() {}

  public static ArrayList listResults(Object client, String methodName, Class className)
      throws NoSuchMethodException,
          InvocationTargetException,
          IllegalAccessException,
          InstantiationException {
    Map data = new HashMap<>();
    Object classInstance = className.getDeclaredConstructor().newInstance();
    ArrayList 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;
  }
}