package org.gbif.occurrence.cli.registry.sync;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.hadoop.hbase.util.Bytes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SyncCommon {

  private static final Logger LOG = LoggerFactory.getLogger(SyncCommon.class);
  private static final String PROPS_FILE = "registry-sync.properties";

  public static final String OCC_TABLE_PROPS_KEY = "occurrence.db.table_name";
  public static final String REG_WS_PROPS_KEY = "registry.ws.url";
  public static final byte[] OCC_CF = Bytes.toBytes("o");
  public static final byte[] DK_COL = Bytes.toBytes("dk");
  public static final byte[] OOK_COL = Bytes.toBytes("ook");
  public static final byte[] HC_COL = Bytes.toBytes("hc");
  public static final byte[] CI_COL = Bytes.toBytes("ci");

  public static Properties loadProperties() {
    Properties props = new Properties();
    InputStream in = null;
    try {
      in = SyncCommon.class.getClassLoader().getResourceAsStream(PROPS_FILE);
      props.load(in);
    } catch (Exception e) {
      LOG.error("Unable to open registry-sync.properties file - RegistrySync is not initialized", e);
    } finally {
      if (in != null) {
        try {
          in.close();
        } catch (IOException e) {
          LOG.info("Failed to close input stream for registry-sync.properties file - continuing anyway.", e);
        }
      }
    }

    return props;
  }
}

@@ -41,16 +41,151 @@
 .sync;%0A%0A
+import org.gbif.dwc.terms.GbifInternalTerm;%0Aimport org.gbif.dwc.terms.GbifTerm;%0Aimport org.gbif.occurrence.persistence.hbase.Columns;%0A%0A
 import j
@@ -729,26 +729,18 @@
 F = 
-Bytes.toBytes(%22o%22)
+Columns.CF
 ;%0A  
@@ -793,12 +793,43 @@
 tes(
-%22dk%22
+Columns.column(GbifTerm.datasetKey)
 );%0A 
@@ -884,13 +884,57 @@
 tes(
-%22ook%22
+Columns.column(GbifInternalTerm.publishingOrgKey)
 );%0A 
@@ -988,12 +988,50 @@
 tes(
-%22hc%22
+Columns.column(GbifTerm.publishingCountry)
 );%0A 
@@ -1085,12 +1085,48 @@
 tes(
-%22ci%22
+Columns.column(GbifInternalTerm.crawlId)
 );%0A%0A

update registry sync to use Columns for fetching column names