Package facebook4j

Examples of facebook4j.Reading


        // get endpoint properties in a map
        final HashMap<String, Object> properties = new HashMap<String, Object>();
        FacebookPropertiesHelper.getEndpointProperties(endpoint.getConfiguration(), properties);

        // skip since and until fields?
        final Reading reading = (Reading) properties.get(READING_PPROPERTY);
        if (reading != null) {
            final String queryString = reading.toString();
            if (queryString.contains(SINCE_PREFIX)) {
                // use the user supplied value to start with
                final int startIndex = queryString.indexOf(SINCE_PREFIX) + SINCE_PREFIX.length();
                int endIndex = queryString.indexOf('&', startIndex);
                if (endIndex == -1) {
View Full Code Here


        // start by setting the Reading since and until fields,
        // these are used to avoid reading duplicate results across polls
        Map<String, Object> arguments = new HashMap<String, Object>();
        arguments.putAll(endpointProperties);

        Reading reading = (Reading) arguments.remove(READING_PPROPERTY);
        if (reading == null) {
            reading = new Reading();
        } else {
            try {
                reading = ReadingBuilder.copy(reading, true);
            } catch (NoSuchFieldException e) {
                throw new IllegalArgumentException(String.format("Error creating property [%s]: %s",
                    READING_PPROPERTY, e.getMessage()), e);
            } catch (IllegalAccessException e) {
                throw new IllegalArgumentException(String.format("Error creating property [%s]: %s",
                    READING_PPROPERTY, e.getMessage()), e);
            }
        }

        // now set since and until for this poll
        final SimpleDateFormat dateFormat = new SimpleDateFormat(FACEBOOK_DATE_FORMAT);
        final long currentMillis = System.currentTimeMillis();
        if (this.sinceTime == null) {
            // first poll, set this to (current time - initial poll delay)
            final Date startTime = new Date(currentMillis
                - TimeUnit.MILLISECONDS.convert(getInitialDelay(), getTimeUnit()));
            this.sinceTime = dateFormat.format(startTime);
        } else if (this.untilTime != null) {
            // use the last 'until' time
            this.sinceTime = this.untilTime;
        }
        this.untilTime = dateFormat.format(new Date(currentMillis));

        reading.since(this.sinceTime);
        reading.until(this.untilTime);

        arguments.put(READING_PPROPERTY, reading);

        return arguments;
    }
View Full Code Here

        if (!readingProperties.isEmpty()) {
            try {

                // add to an existing reading reference?
                // NOTE Reading class does not support overwriting properties!!!
                Reading reading = configuration.getReading();
                if (reading == null) {
                    reading = new Reading();
                } else {
                    reading = ReadingBuilder.copy(reading, false);
                }
                // set properties
                ReadingBuilder.setProperties(reading,
View Full Code Here

        // use private field access to make a copy
        Field field = Reading.class.getDeclaredField("parameterMap");
        field.setAccessible(true);
        final LinkedHashMap<String, String> source = (LinkedHashMap<String, String>) field.get(reading);
        // create another reading, and add all fields from source
        Reading copy = new Reading();
        final LinkedHashMap<String, String> copyMap = new LinkedHashMap<String, String>();
        copyMap.putAll(source);
        if (skipSinceUtil) {
            copyMap.remove("since");
            copyMap.remove("until");
View Full Code Here

*/
public class ReadingBuilderTest {

    @Test
    public void testCopy() throws Exception {
        final Reading source = new Reading();
        source.fields("field1", "field2");
        source.filter("testFilter");
        source.limit(100);
        source.locale(Locale.US);
        source.metadata();
        source.offset(1000);
        source.since(new Date());
        source.until(new Date());
        source.withLocation();
       
        Reading copy = ReadingBuilder.copy(source, false);
        assertNotNull("Null copy", copy);
        assertEquals("Copy not equal", source.toString(), copy.toString());

        // skip since and until
        copy = ReadingBuilder.copy(source, true);
        assertNotEquals("Copy equal", source.toString(), copy.toString());
        assertFalse("since", copy.toString().contains("since="));
        assertFalse("until", copy.toString().contains("until="));
    }
View Full Code Here

        assertFalse("until", copy.toString().contains("until="));
    }

    @Test
    public void testSetProperties() throws Exception {
        final Reading reading = new Reading();

        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put("fields", "field1,field2");
        properties.put("filter", "testFilter");
        properties.put("limit", "100");
View Full Code Here

        // use private field access to make a copy
        Field field = Reading.class.getDeclaredField("parameterMap");
        field.setAccessible(true);
        final LinkedHashMap<String, String> source = (LinkedHashMap<String, String>) field.get(reading);
        // create another reading, and add all fields from source
        Reading copy = new Reading();
        final LinkedHashMap<String, String> copyMap = new LinkedHashMap<String, String>();
        copyMap.putAll(source);
        if (skipSinceUtil) {
            copyMap.remove("since");
            copyMap.remove("until");
View Full Code Here

*/
public class ReadingBuilderTest {

    @Test
    public void testCopy() throws Exception {
        final Reading source = new Reading();
        source.fields("field1", "field2");
        source.filter("testFilter");
        source.limit(100);
        source.locale(Locale.US);
        source.metadata();
        source.offset(1000);
        source.since(new Date());
        source.until(new Date());
        source.withLocation();
       
        Reading copy = ReadingBuilder.copy(source, false);
        assertNotNull("Null copy", copy);
        assertEquals("Copy not equal", source.toString(), copy.toString());

        // skip since and until
        copy = ReadingBuilder.copy(source, true);
        assertNotEquals("Copy equal", source.toString(), copy.toString());
        assertFalse("since", copy.toString().contains("since="));
        assertFalse("until", copy.toString().contains("until="));
    }
View Full Code Here

        assertFalse("until", copy.toString().contains("until="));
    }

    @Test
    public void testSetProperties() throws Exception {
        final Reading reading = new Reading();

        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put("fields", "field1,field2");
        properties.put("filter", "testFilter");
        properties.put("limit", "100");
View Full Code Here

        // get endpoint properties in a map
        final HashMap<String, Object> properties = new HashMap<String, Object>();
        FacebookPropertiesHelper.getEndpointProperties(endpoint.getConfiguration(), properties);

        // skip since and until fields?
        final Reading reading = (Reading) properties.get(READING_PPROPERTY);
        if (reading != null) {
            final String queryString = reading.toString();
            if (queryString.contains("since=")) {
                // use the user supplied value to start with
                final int startIndex = queryString.indexOf(SINCE_PREFIX) + SINCE_PREFIX.length();
                int endIndex = queryString.indexOf('&', startIndex);
                if (endIndex == -1) {
View Full Code Here

TOP

Related Classes of facebook4j.Reading

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.