Search in sources :

Example 1 with QuickBaseException

use of com.intuit.quickbase.util.QuickBaseException in project opennms by OpenNMS.

the class QuickBaseAPITest method XXXtestCreateLead.

public void XXXtestCreateLead() {
    PrintWriter out = null;
    try {
        out = new PrintWriter(System.out);
        out.println("Welcome to QuickBase\n");
        QuickBaseClient qdb = createClient();
        qdb.findDbByName("TPMG Support");
        HashMap tables = (HashMap) qdb.grantedDBs(false, false, true);
        if (tables == null) {
            out.println("No tables belong to this user.");
        }
        Set tableNames = tables.keySet();
        String tableName = "";
        String tableDbid = "";
        for (Iterator it = tableNames.iterator(); it.hasNext(); ) {
            tableName = (String) it.next();
            tableDbid = (String) tables.get(tableName);
            out.println("Name: " + tableName + " DBID: " + tableDbid);
            Document schema = qdb.getSchema(tableDbid);
            Transformer transformer = TransformerFactory.newInstance().newTransformer();
            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
            transformer.transform(new DOMSource(schema), new StreamResult(out));
            NodeList fields = schema.getElementsByTagName("field");
            out.println("The QuickBase application " + tableName + " has " + fields.getLength() + " fields.");
            out.println("The fields are listed below.");
            for (int i = 0; i < fields.getLength(); i++) {
                out.println("Field ID: " + fields.item(i).getAttributes().getNamedItem("id").getNodeValue());
                out.println("Field Type: " + fields.item(i).getAttributes().getNamedItem("type").getNodeValue());
                out.println("Field Label: " + fields.item(i).getChildNodes().item(0).getNodeValue());
            }
        }
    } catch (QuickBaseException qdbe) {
        System.err.println("Exception in main " + qdbe.toString() + " error code: " + qdbe.getErrorCode());
        qdbe.printStackTrace();
    } catch (Throwable e) {
        System.err.println("Exception in main " + e.toString());
        e.printStackTrace();
    } finally {
        if (null != out) {
            out.flush();
            out.close();
        }
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) Set(java.util.Set) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) HashMap(java.util.HashMap) NodeList(org.w3c.dom.NodeList) QuickBaseException(com.intuit.quickbase.util.QuickBaseException) QuickBaseClient(com.intuit.quickbase.util.QuickBaseClient) Document(org.w3c.dom.Document) Iterator(java.util.Iterator) PrintWriter(java.io.PrintWriter)

Aggregations

QuickBaseClient (com.intuit.quickbase.util.QuickBaseClient)1 QuickBaseException (com.intuit.quickbase.util.QuickBaseException)1 PrintWriter (java.io.PrintWriter)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Set (java.util.Set)1 Transformer (javax.xml.transform.Transformer)1 DOMSource (javax.xml.transform.dom.DOMSource)1 StreamResult (javax.xml.transform.stream.StreamResult)1 Document (org.w3c.dom.Document)1 NodeList (org.w3c.dom.NodeList)1