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

gov.nasa.pds.registry.common.connection.aws.MGetRespWrap Maven / Gradle / Ivy

The newest version!
package gov.nasa.pds.registry.common.connection.aws;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.opensearch.client.opensearch.core.MgetResponse;
import org.opensearch.client.opensearch.core.mget.MultiGetResponseItem;
import gov.nasa.pds.registry.common.es.dao.dd.DataTypeNotFoundException;
import gov.nasa.pds.registry.common.util.Tuple;

class MGetRespWrap extends GetRespWrap {
  final private MgetResponse parent;
  MGetRespWrap (MgetResponse parent) {
    super(null);
    this.parent = parent;
  }
  @Override
  public List dataTypes(boolean stringForMissing) throws IOException, DataTypeNotFoundException {
    ArrayList results = new ArrayList();
    for (MultiGetResponseItem doc : this.parent.docs()) {
      Tuple t = null;
      if (doc.isResult()) {
        @SuppressWarnings("unchecked")
        Map src = (Map)doc.result().source();
        if (src != null && src.containsKey("es_data_type")) t = new Tuple(doc.result().id(), src.get("es_data_type"));
      } else if (stringForMissing) {
        if (doc.result().id().startsWith("ref_lid_") || doc.result().id().startsWith("ref_lidvid_")
            || doc.result().id().endsWith("_Area")) {
          t = new Tuple(doc.result().id(), "keyword");
        } else {
          log.error("Could not find datatype for field " + doc.result().id());
          t = new Tuple(doc.result().id(), "string");
        }
      } else {
        throw new DataTypeNotFoundException();
      }
      if (t != null) results.add(t);
    }
    return results;
  }
}