/** * Creates a new Chargify connector * * @return a new instance of the Chargify connector */ public static ChargifyConnector createConnector() { return new ChargifyConnector(); }
/** * Loads Chargify data command processor * * @param c command * @param p command line arguments * @param ctx current processing context * @throws java.io.IOException in case of IO issues */ private void loadChargify(Command c, CliParams p, ProcessingContext ctx) throws IOException { String configFile = c.getParamMandatory("configFile"); String apiKey = c.getParamMandatory("apiKey"); String e = c.getParamMandatory("entity"); String f = c.getParamMandatory("fields"); String domain = c.getParamMandatory("domain"); c.paramsProcessed(); File conf = FileUtil.getFile(configFile); initSchema(conf.getAbsolutePath()); setEntity(e); setFields(f); setApiToken(apiKey); setDomain(domain); ctx.setConnector(this); setProjectId(ctx); l.info("Chargify Connector successfully loaded (entity: " + e + " fields: " + StringUtil.previewString(f, 256) + ")."); }
/** * {@inheritDoc} */ public void extract(String file, boolean transform) throws IOException { l.debug("Extracting Chargify data."); try { ChargifyWrapper m = new ChargifyWrapper(getDomain(), getApiToken()); l.debug("Executing Chargify query entity: " + getEntity() + " fields: " + getFields()); if (fields != null && fields.length() > 0) { String[] fs = fields.split(","); for (int i = 0; i < fs.length; i++) fs[i] = fs[i].trim(); File dt = FileUtil.getTempFile(); m.getAllData(getEntity(), fs, dt.getAbsolutePath()); int rowCnt = copyAndTransform(FileUtil.createUtf8CsvReader(dt), FileUtil.createUtf8CsvWriter(new File(file)), transform, 10); l.info("Finished Chargify query execution. Retrieved " + rowCnt + " rows of data."); } else { throw new InvalidParameterException("The Chargify fields parameter must contain the comma separated list " + "of the entity fields."); } } catch (SAXException e) { throw new IOException(e); } catch (XPathExpressionException e) { throw new IOException(e); } catch (ParserConfigurationException e) { throw new IOException(e); } }
/** * {@inheritDoc} */ public boolean processCommand(Command c, CliParams cli, ProcessingContext ctx) throws ProcessingException { l.debug("Processing command " + c.getCommand()); try { if (c.match("LoadChargify") || c.match("UseChargify")) { loadChargify(c, cli, ctx); } else { l.debug("No match passing the command " + c.getCommand() + " further."); return super.processCommand(c, cli, ctx); } } catch (IOException e) { throw new ProcessingException(e); } l.debug("Processed command " + c.getCommand()); return true; }
/** * Instantiate all known connectors * TODO: this should be automated * * @return array of all active connectors * @throws IOException in case of IO issues */ private Connector[] instantiateConnectors() throws IOException { return new Connector[]{ CsvConnector.createConnector(), GaConnector.createConnector(), SfdcConnector.createConnector(), JdbcConnector.createConnector(), PtConnector.createConnector(), DateDimensionConnector.createConnector(), FacebookConnector.createConnector(), FacebookInsightsConnector.createConnector(), MsDynamicsConnector.createConnector(), SugarCrmConnector.createConnector(), ChargifyConnector.createConnector() }; }