Package com.socrata.api

Examples of com.socrata.api.Soda2Consumer


        //Create a query that should return a single result
        SoqlQuery query = new SoqlQueryBuilder()
                .setWhereClause(new ConditionalExpression("primary_naics=325510"))
                .build();

        final Soda2Consumer   soda2Consumer = new Soda2Consumer(connection);

        //
        //   Issue query as a full query
        final ClientResponse responseFullQuery = soda2Consumer.query(dataset, HttpLowLevel.JSON_TYPE, query.toString());
        final List<ToxinData> resultsFullQuery = responseFullQuery.getEntity(new GenericType<List<ToxinData>>() {});
        TestCase.assertEquals(6, resultsFullQuery.size());
        for (ToxinData toxinData : resultsFullQuery) {
            TestCase.assertEquals(325510L, toxinData.getPrimaryNAICS());
        }


        //
        //   Issue query as a through $where, etc.

        final ClientResponse response = soda2Consumer.query(dataset, HttpLowLevel.JSON_TYPE,query);
        final List<ToxinData> results = response.getEntity(new GenericType<List<ToxinData>>() {});
        TestCase.assertEquals(6, results.size());
        for (ToxinData toxinData : results) {
            TestCase.assertEquals(325510L, toxinData.getPrimaryNAICS());
        }

        //
        //  Issue a query and get back maps
        final List responseList = soda2Consumer.query(dataset,query, new GenericType<List<Object>>() {});
        TestCase.assertEquals(6, responseList.size());
        for (Object crimeObject : responseList) {
            Map<String, String> crimeMap = (Map<String, String>) crimeObject;
            TestCase.assertEquals("325510", crimeMap.get("primary_naics"));
        }
View Full Code Here


                                                                        null);
        return httpLowLevel;
    }

    protected Soda2Consumer createConsumer() throws IOException {
        return new Soda2Consumer(connect());
    }
View Full Code Here

        //Create a query that should return a single result
        SoqlQuery query = new SoqlQueryBuilder()
                .setWhereClause(new ConditionalExpression("primary_naics=325510"))
                .build();

        final Soda2Consumer soda2Consumer = new Soda2Consumer(connection);

        //
        //   Issue query as a full query
        final ClientResponse responseFullQuery = soda2Consumer.query(dataset, HttpLowLevel.JSON_TYPE, query.toString());
        final List<ToxinData> resultsFullQuery = responseFullQuery.getEntity(new GenericType<List<ToxinData>>() {});
        TestCase.assertEquals(6, resultsFullQuery.size());
        for (ToxinData toxinData : resultsFullQuery) {
            TestCase.assertEquals(325510L, toxinData.getPrimaryNAICS());
        }


        //
        //   Issue query as a through $where, etc.

        final ClientResponse response = soda2Consumer.query(dataset, HttpLowLevel.JSON_TYPE,query);
        final List<ToxinData> results = response.getEntity(new GenericType<List<ToxinData>>() {});
        TestCase.assertEquals(6, results.size());
        for (ToxinData toxinData : results) {
            TestCase.assertEquals(325510L, toxinData.getPrimaryNAICS());
        }

        //
        //  Issue a query and get back maps
        final List responseList = soda2Consumer.query(dataset,query, new GenericType<List<Object>>() {});
        TestCase.assertEquals(6, responseList.size());
        for (Object crimeObject : responseList) {
            Map<String, String> crimeMap = (Map<String, String>) crimeObject;
            TestCase.assertEquals("325510", crimeMap.get("primary_naics"));
        }
View Full Code Here

    public void testFloatingDateSoql() throws IOException, InterruptedException, SodaError
    {

        Date d = new Date(112, 5, 20, 7, 0);

        Soda2Consumer   consumer = createConsumer();

        //  Run an equality filter on a floating timestamp
        SoqlQuery query = new SoqlQueryBuilder()
                .setWhereClause(new ConditionalExpression(ColumnUtil.getQueryName("Nomination Date"+ "=to_floating_timestamp('2012-6-20T07:00:00Z')"))
                .build();
        final List<Nomination>  results = consumer.query(NOMINATION_DATA_SET, query, Nomination.LIST_TYPE);


        // Verify results against known values.
        final Set<String>       names = Sets.newHashSet("Masumoto, David", "Trottenberg, Polly Ellen");
        for (Nomination n: results) {
            TestCase.assertTrue(names.remove(n.getName()));
            TestCase.assertEquals(d, n.getNominationDate());
        }

        //  Check greater than floating timestamp
        SoqlQuery queryGreater = new SoqlQueryBuilder()
                .setWhereClause(new ConditionalExpression(ColumnUtil.getQueryName("Nomination Date"+ ">to_floating_timestamp('2012-6-20T07:00:00Z')"))
                .build();
        final List<Nomination>  resultsGreater = consumer.query(NOMINATION_DATA_SET, queryGreater, Nomination.LIST_TYPE);


        //  Verify results all come after the test date
        for (Nomination n: resultsGreater) {
            TestCase.assertTrue(n.getNominationDate().after(d));
        }

        //  Check greater than floating timestamp
        SoqlQuery queryLesser = new SoqlQueryBuilder()
                .setWhereClause(new ConditionalExpression(ColumnUtil.getQueryName("Nomination Date"+ "<to_floating_timestamp('2012-6-20T07:00:00Z')"))
                .build();

        final List<Nomination>  resultsLesser = consumer.query(NOMINATION_DATA_SET, queryLesser, Nomination.LIST_TYPE);

        // Verify results all come before the test date
        for (Nomination n: resultsLesser) {
            TestCase.assertTrue(n.getNominationDate().before(d));
        }
View Full Code Here

    @Test
    public void testFloatingDateSoqlWJoda() throws IOException, InterruptedException, SodaError
    {
        Date d = new Date(112, 5, 20, 7, 0);

        Soda2Consumer   consumer = createConsumer();

        //
        //  Check floating timestamp
        SoqlQuery query = new SoqlQueryBuilder()
                .setWhereClause(new ConditionalExpression(ColumnUtil.getQueryName("Nomination Date"+ "=to_floating_timestamp('2012-6-20T07:00:00Z')"))
                .build();

        final List<NominationWithJoda>  results = consumer.query(NOMINATION_DATA_SET, query, NominationWithJoda.LIST_TYPE);
        final Set<String>       names = Sets.newHashSet("Masumoto, David", "Trottenberg, Polly Ellen");

        for (NominationWithJoda n: results) {
            TestCase.assertTrue(names.remove(n.getName()));
            TestCase.assertTrue(n.getNominationDate().toDateTime(DateTimeZone.getDefault()).toDate().equals(d));
        }

        //
        //  Check greater than floating timestamp
        SoqlQuery queryGreater = new SoqlQueryBuilder()
                .setWhereClause(new ConditionalExpression(ColumnUtil.getQueryName("Nomination Date"+ ">to_floating_timestamp('2012-6-20T07:00:00Z')"))
                .build();

        final List<NominationWithJoda>  resultsGreater = consumer.query(NOMINATION_DATA_SET, queryGreater, NominationWithJoda.LIST_TYPE);

        for (NominationWithJoda n: resultsGreater) {
            TestCase.assertTrue(n.getNominationDate().toDateTime(DateTimeZone.getDefault()).isAfter(d.getTime()));
        }

        //
        //  Check greater than floating timestamp
        SoqlQuery queryLesser = new SoqlQueryBuilder()
                .setWhereClause(new ConditionalExpression(ColumnUtil.getQueryName("Nomination Date"+ "<to_floating_timestamp('2012-6-20T07:00:00Z')"))
                .build();

        final List<NominationWithJoda>  resultsLesser = consumer.query(NOMINATION_DATA_SET, queryLesser, NominationWithJoda.LIST_TYPE);

        for (NominationWithJoda n: resultsLesser) {
            TestCase.assertTrue(n.getNominationDate().toDateTime(DateTimeZone.getDefault()).isBefore(d.getTime()));
        }
View Full Code Here

    @Test
    public void testFixedDateSoql() throws IOException, InterruptedException, SodaError
    {
        Date d = new Date(112, 5, 20, 7, 0);

        Soda2Consumer   consumer = createConsumer();

        //
        //  Check floating timestamp
        SoqlQuery query = new SoqlQueryBuilder()
                .setWhereClause(new ConditionalExpression(ColumnUtil.getQueryName("Confirmation Vote"+ "=to_fixed_timestamp('2012-6-20T07:00:00Z')"))
                .build();

        final List<Nomination>  results = consumer.query(NOMINATION_DATA_SET, query, Nomination.LIST_TYPE);
        final Set<String>       names = Sets.newHashSet("Masumoto, David", "Trottenberg, Polly Ellen");

        for (Nomination n: results) {
            TestCase.assertTrue(names.remove(n.getName()));
            TestCase.assertEquals(d, n.getNominationDate());
        }

        //
        //  Check greater than floating timestamp
        SoqlQuery queryGreater = new SoqlQueryBuilder()
                .setWhereClause(new ConditionalExpression(ColumnUtil.getQueryName("Confirmation Vote"+ ">to_fixed_timestamp('2012-6-20T07:00:00Z')"))
                .build();

        final List<Nomination>  resultsGreater = consumer.query(NOMINATION_DATA_SET, queryGreater, Nomination.LIST_TYPE);

        for (Nomination n: resultsGreater) {
            if (n.getConfirmationVoteDate() != null) {
                TestCase.assertTrue(d.before(n.getConfirmationVoteDate()));
            }
        }

        //
        //  Check greater than floating timestamp
        SoqlQuery queryLesser = new SoqlQueryBuilder()
                .setWhereClause(new ConditionalExpression(ColumnUtil.getQueryName("Confirmation Vote"+ "<to_fixed_timestamp('2012-6-20T07:00:00Z')"))
                .build();

        final List<Nomination>  resultsLesser = consumer.query(NOMINATION_DATA_SET, queryLesser, Nomination.LIST_TYPE);

        for (Nomination n: resultsLesser) {
            if (n.getConfirmationVoteDate() != null) {
                TestCase.assertTrue(d.after(n.getConfirmationVoteDate()));
            }
View Full Code Here

    @Test
    public void testFixedDateSoqlJoda() throws IOException, InterruptedException, SodaError
    {
        Date d = new Date(112, 5, 20, 7, 0);

        Soda2Consumer   consumer = createConsumer();

        //
        //  Check floating timestamp
        SoqlQuery query = new SoqlQueryBuilder()
                .setWhereClause(new ConditionalExpression(ColumnUtil.getQueryName("Confirmation Vote"+ "=to_fixed_timestamp('2012-6-20T07:00:00Z')"))
                .build();

        final List<NominationWithJoda>  results = consumer.query(NOMINATION_DATA_SET, query, NominationWithJoda.LIST_TYPE);
        final Set<String>       names = Sets.newHashSet("Masumoto, David", "Trottenberg, Polly Ellen");

        for (NominationWithJoda n: results) {
            TestCase.assertTrue(names.remove(n.getName()));
            TestCase.assertEquals(d, n.getNominationDate().toDate());
        }

        //
        //  Check greater than floating timestamp
        SoqlQuery queryGreater = new SoqlQueryBuilder()
                .setWhereClause(new ConditionalExpression(ColumnUtil.getQueryName("Confirmation Vote"+ ">to_fixed_timestamp('2012-6-20T07:00:00Z')"))
                .build();

        final List<NominationWithJoda>  resultsGreater = consumer.query(NOMINATION_DATA_SET, queryGreater, NominationWithJoda.LIST_TYPE);

        for (NominationWithJoda n: resultsGreater) {
            if (n.getConfirmationVoteDate() != null) {
                TestCase.assertTrue(d.before(n.getConfirmationVoteDate().toDate()));
            }
        }

        //
        //  Check greater than floating timestamp
        SoqlQuery queryLesser = new SoqlQueryBuilder()
                .setWhereClause(new ConditionalExpression(ColumnUtil.getQueryName("Confirmation Vote"+ "<to_fixed_timestamp('2012-6-20T07:00:00Z')"))
                .build();

        final List<NominationWithJoda>  resultsLesser = consumer.query(NOMINATION_DATA_SET, queryLesser, NominationWithJoda.LIST_TYPE);

        for (NominationWithJoda n: resultsLesser) {
            if (n.getConfirmationVoteDate() != null) {
                TestCase.assertTrue(d.after(n.getConfirmationVoteDate().toDate()));
            }
View Full Code Here

      // creator "creates" a new dataset on the sink site (and publishes if applicable)
            final SodaDdl creator = SodaDdl.newDdl(sinkSiteDomain,
          connectionInfo.getUser(), connectionInfo.getPassword(),
                    portDestinationDomainAppToken);
      // streamExporter "exports" the source dataset rows
      final Soda2Consumer streamExporter = Soda2Consumer.newConsumer(
          sourceSiteDomain, connectionInfo.getUser(),
          connectionInfo.getPassword(), connectionInfo.getToken());
      // streamUpserter "upserts" the rows exported to the created dataset
      final Soda2Producer streamUpserter = Soda2Producer.newProducer(
          sinkSiteDomain, connectionInfo.getUser(),
View Full Code Here

    protected SodaDdl createSodaDdl() throws IOException {
        return SodaDdl.newDdl(DOMAIN, USERNAME, PASSWORD, API_KEY);
    }

    protected int getTotalRows(String UnitTestDataset) throws LongRunningQueryException, SodaError {
        final Soda2Consumer consumer = Soda2Consumer.newConsumer(DOMAIN, USERNAME, PASSWORD, API_KEY);

        ClientResponse response = consumer.query(UnitTestDataset, HttpLowLevel.JSON_TYPE, "select count(*)");

        ArrayList results = response.getEntity(ArrayList.class);
        Map count = (HashMap<String,String>) results.get(0);
        return Integer.parseInt((String) count.get("count"));
    }
View Full Code Here

TOP

Related Classes of com.socrata.api.Soda2Consumer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.