package yanagishima.util;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.http.client.fluent.Request;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static java.nio.charset.StandardCharsets.UTF_8;

public class MetadataUtil {

    private static Logger LOGGER = LoggerFactory.getLogger(MetadataUtil.class);

    public static void setMetadata(String metadataServiceUrl, HashMap<String, Object> retVal, String schema, String table, List<List<String>> records) {
        try {
            String json = Request.Get(String.format("%s/%s/%s", metadataServiceUrl, schema, table)).execute().returnContent().asString(UTF_8);
            ObjectMapper mapper = new ObjectMapper();
            Map map = mapper.readValue(json, Map.class);
            List<Map> columns = (List) map.get("columns");
            List<List<String>> newRecordList = new ArrayList<List<String>>();
            for (int i = 0; i < records.size(); i++) {
                List<String> newColumnList = new ArrayList<>();
                for (String column : records.get(i)) {
                    newColumnList.add(column);
                }
                if(i < columns.size()) {
                    Object n = columns.get(i).get("note");
                    if (n == null) {
                        newColumnList.add(null);
                    } else {
                        newColumnList.add((String) ((Map) n).get("note"));
                    }
                }
                newRecordList.add(newColumnList);
            }
            retVal.put("results", newRecordList);
            if (map.get("note") != null) {
                retVal.put("note", ((Map) map.get("note")).get("note"));
            }
        } catch (IOException e) {
            LOGGER.error(e.getMessage(), e);
        }
    }
}

@@ -68,24 +68,77 @@
 jectMapper;%0A
+import org.apache.http.client.HttpResponseException;%0A
 import org.a
@@ -1886,32 +1886,189 @@
 ;%0A            %7D%0A
+        %7D catch (HttpResponseException e) %7B%0A            LOGGER.warn(String.format(%22schema=%25s, table=%25s, status code=%25d%22, schema, table, e.getStatusCode()));%0A
         %7D catch 

Improve error handling