From 78b7514f49dd42735094ae86375f17ae78565f93 Mon Sep 17 00:00:00 2001 From: Dhiraj Bokde Date: Thu, 29 Aug 2013 02:23:58 -0700 Subject: [PATCH 1/5] CAMEL-6676: Initial version of Camel Facebook coponent --- .../camel/facebook/FacebookComponent.java | 62 ++ .../camel/facebook/FacebookConstants.java | 23 + .../camel/facebook/FacebookConsumer.java | 200 +++++ .../camel/facebook/FacebookEndpoint.java | 149 ++++ .../camel/facebook/FacebookProducer.java | 170 +++++ .../config/FacebookConfiguration.java | 443 +++++++++++ .../config/FacebookEndpointConfiguration.java | 706 ++++++++++++++++++ .../facebook/config/FacebookNameStyle.java | 10 + .../facebook/data/FacebookMethodsType.java | 572 ++++++++++++++ .../data/FacebookMethodsTypeHelper.java | 350 +++++++++ .../data/FacebookPropertiesHelper.java | 116 +++ .../camel/facebook/data/ReadingBuilder.java | 105 +++ .../facebook/CamelFacebookTestSupport.java | 71 ++ .../FacebookComponentConsumerTest.java | 61 ++ .../FacebookComponentProducerTest.java | 126 ++++ .../data/FacebookMethodsTypeHelperTest.java | 83 ++ .../data/FacebookMethodsTypeTest.java | 47 ++ .../facebook/data/ReadingBuilderTest.java | 63 ++ 18 files changed, 3357 insertions(+) create mode 100644 components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookComponent.java create mode 100644 components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookConstants.java create mode 100644 components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookConsumer.java create mode 100644 components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookEndpoint.java create mode 100644 components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookProducer.java create mode 100644 components/camel-facebook/src/main/java/org/apache/camel/facebook/config/FacebookConfiguration.java create mode 100644 components/camel-facebook/src/main/java/org/apache/camel/facebook/config/FacebookEndpointConfiguration.java create mode 100644 components/camel-facebook/src/main/java/org/apache/camel/facebook/config/FacebookNameStyle.java create mode 100644 components/camel-facebook/src/main/java/org/apache/camel/facebook/data/FacebookMethodsType.java create mode 100644 components/camel-facebook/src/main/java/org/apache/camel/facebook/data/FacebookMethodsTypeHelper.java create mode 100644 components/camel-facebook/src/main/java/org/apache/camel/facebook/data/FacebookPropertiesHelper.java create mode 100644 components/camel-facebook/src/main/java/org/apache/camel/facebook/data/ReadingBuilder.java create mode 100644 components/camel-facebook/src/test/java/org/apache/camel/facebook/CamelFacebookTestSupport.java create mode 100644 components/camel-facebook/src/test/java/org/apache/camel/facebook/FacebookComponentConsumerTest.java create mode 100644 components/camel-facebook/src/test/java/org/apache/camel/facebook/FacebookComponentProducerTest.java create mode 100644 components/camel-facebook/src/test/java/org/apache/camel/facebook/data/FacebookMethodsTypeHelperTest.java create mode 100644 components/camel-facebook/src/test/java/org/apache/camel/facebook/data/FacebookMethodsTypeTest.java create mode 100644 components/camel-facebook/src/test/java/org/apache/camel/facebook/data/ReadingBuilderTest.java diff --git a/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookComponent.java b/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookComponent.java new file mode 100644 index 0000000000000..5cc9aa64b5191 --- /dev/null +++ b/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookComponent.java @@ -0,0 +1,62 @@ +package org.apache.camel.facebook; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.camel.CamelContext; +import org.apache.camel.Endpoint; +import org.apache.camel.facebook.config.FacebookConfiguration; +import org.apache.camel.facebook.config.FacebookEndpointConfiguration; +import org.apache.camel.impl.UriEndpointComponent; +import org.apache.camel.spi.UriParam; +import org.apache.camel.util.IntrospectionSupport; + +/** + * Represents the component that manages {@link FacebookEndpoint}. + */ +public class FacebookComponent extends UriEndpointComponent { + + @UriParam + private FacebookConfiguration configuration; + + public FacebookComponent() { + this(new FacebookConfiguration()); + } + + public FacebookComponent(FacebookConfiguration configuration) { + this(null, configuration); + } + + public FacebookComponent(CamelContext context) { + this(context, new FacebookConfiguration()); + } + + public FacebookComponent(CamelContext context, FacebookConfiguration configuration) { + super(context, FacebookEndpoint.class); + this.configuration = configuration; + } + + protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws Exception { + FacebookEndpointConfiguration config = copyComponentProperties(); + return new FacebookEndpoint(uri, this, remaining, config); + } + + private FacebookEndpointConfiguration copyComponentProperties() throws Exception { + Map componentProperties = new HashMap(); + IntrospectionSupport.getProperties(configuration, componentProperties, null, false); + + // create endpoint configuration with component properties + FacebookEndpointConfiguration config = new FacebookEndpointConfiguration(); + IntrospectionSupport.setProperties(config, componentProperties, null); + return config; + } + + public FacebookConfiguration getConfiguration() { + return configuration; + } + + public void setConfiguration(FacebookConfiguration configuration) { + this.configuration = configuration; + } + +} diff --git a/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookConstants.java b/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookConstants.java new file mode 100644 index 0000000000000..c6df2c54bef66 --- /dev/null +++ b/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookConstants.java @@ -0,0 +1,23 @@ +package org.apache.camel.facebook; + +/** + * Common constants. + */ +public interface FacebookConstants { + + // reading options property name and prefix for uri property + String READING_PPROPERTY = "reading"; + String READING_PREFIX = READING_PPROPERTY + "."; + + // property name prefix for exchange 'in' headers + String FACEBOOK_PROPERTY_PREFIX = "CamelFacebook."; + + // property name for exchange 'in' body + String IN_BODY_PROPERTY = "inBody"; + + String FACEBOOK_THREAD_PROFILE_NAME = "CamelFacebook"; + + // date format used by Facebook Reading since and until fields + String FACEBOOK_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ssZ"; + +} diff --git a/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookConsumer.java b/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookConsumer.java new file mode 100644 index 0000000000000..dd4bc9b33ea73 --- /dev/null +++ b/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookConsumer.java @@ -0,0 +1,200 @@ +package org.apache.camel.facebook; + +import java.lang.reflect.Array; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.concurrent.TimeUnit; +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.facebook.data.FacebookMethodsType; +import org.apache.camel.facebook.data.FacebookPropertiesHelper; +import org.apache.camel.facebook.data.ReadingBuilder; +import org.apache.camel.impl.ScheduledPollConsumer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import facebook4j.Reading; + +import static org.apache.camel.facebook.FacebookConstants.FACEBOOK_DATE_FORMAT; +import static org.apache.camel.facebook.FacebookConstants.READING_PPROPERTY; +import static org.apache.camel.facebook.FacebookConstants.READING_PREFIX; +import static org.apache.camel.facebook.data.FacebookMethodsTypeHelper.MatchType; +import static org.apache.camel.facebook.data.FacebookMethodsTypeHelper.filterMethods; +import static org.apache.camel.facebook.data.FacebookMethodsTypeHelper.getHighestPriorityMethod; +import static org.apache.camel.facebook.data.FacebookMethodsTypeHelper.getMissingProperties; +import static org.apache.camel.facebook.data.FacebookMethodsTypeHelper.invokeMethod; + +/** + * The Facebook consumer. + */ +public class FacebookConsumer extends ScheduledPollConsumer { + + private static final Logger LOG = LoggerFactory.getLogger(FacebookConsumer.class); + private static final String SINCE_PREFIX = "since="; + + private final FacebookEndpoint endpoint; + private final FacebookMethodsType method; + private final Map endpointProperties; + + private String sinceTime; + private String untilTime; + + public FacebookConsumer(FacebookEndpoint endpoint, Processor processor) { + super(endpoint, processor); + this.endpoint = endpoint; + + // determine the consumer method to invoke + this.method = findMethod(endpoint.getCandidates()); + + // get endpoint properties in a map + final HashMap properties = new HashMap(); + 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) { + endIndex = queryString.length(); + } + this.sinceTime = queryString.substring(startIndex, endIndex).replaceAll("%3(a|A)", ":"); + LOG.debug("Using supplied property {}since value {}", READING_PREFIX, this.sinceTime); + } + if (queryString.contains("until=")) { + LOG.debug("Overriding configured property {}until", READING_PREFIX); + } + } + this.endpointProperties = Collections.unmodifiableMap(properties); + } + + private FacebookMethodsType findMethod(List candidates) { + // did we get lucky to have a single candidate? + FacebookMethodsType result; + if (candidates.size() == 1) { + // jackpot + result = candidates.get(0); + } else { + // find one that takes the largest subset of endpoint parameters + final Set argNames = new HashSet(); + argNames.addAll(FacebookPropertiesHelper.getEndpointPropertyNames(endpoint.getConfiguration())); + + // add reading property for polling, if it doesn't already exist! + argNames.add(READING_PPROPERTY); + + final String[] argNamesArray = argNames.toArray(new String[argNames.size()]); + List filteredMethods = filterMethods( + endpoint.getCandidates(), MatchType.SUPER_SET, argNamesArray); + + if (filteredMethods.isEmpty()) { + throw new IllegalArgumentException( + String.format("Missing properties for %s, need one or more from %s", + endpoint.getMethodName(), + getMissingProperties(endpoint.getMethodName(), endpoint.getNameStyle(), argNames))); + } else if (filteredMethods.size() == 1) { + // single match + result = filteredMethods.get(0); + } else { + result = getHighestPriorityMethod(filteredMethods); + LOG.warn("Using highest priority method {} from methods {}", method, filteredMethods); + } + } + return result; + } + + @Override + protected int poll() throws Exception { + // Note mark this consumer as not greedy to avoid making too many Facebook calls + setGreedy(false); + + // invoke the consumer method + Object result = invokeMethod(endpoint.getConfiguration().getFacebook(), + method, getMethodArguments()); + + // process result according to type + if (result != null && (result instanceof Collection || result.getClass().isArray())) { + // create an exchange for every element + final Object array = getResultAsArray(result); + final int length = Array.getLength(array); + for (int i = 0; i < length; i++) { + processResult(Array.get(array, i)); + } + return length; + } else { + processResult(result); + return 1; // number of messages polled + } + } + + private void processResult(Object result) throws Exception { + Exchange exchange = endpoint.createExchange(); + exchange.getIn().setBody(result); + try { + // send message to next processor in the route + getProcessor().process(exchange); + } finally { + // log exception if an exception occurred and was not handled + if (exchange.getException() != null) { + getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException()); + } + } + } + + private Object getResultAsArray(Object result) { + if (result.getClass().isArray()) { + // no conversion needed + return result; + } + // must be a Collection + // TODO add support for Paging using ResponseList + Collection collection = (Collection) result; + return collection.toArray(new Object[collection.size()]); + } + + private Map getMethodArguments() { + // start by setting the Reading since and until fields, + // these are used to avoid reading duplicate results across polls + Map arguments = new HashMap(); + 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; + } + +} diff --git a/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookEndpoint.java b/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookEndpoint.java new file mode 100644 index 0000000000000..7baa6ff658e52 --- /dev/null +++ b/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookEndpoint.java @@ -0,0 +1,149 @@ +package org.apache.camel.facebook; + +import java.util.*; +import org.apache.camel.Consumer; +import org.apache.camel.Processor; +import org.apache.camel.Producer; +import org.apache.camel.facebook.config.FacebookEndpointConfiguration; +import org.apache.camel.facebook.config.FacebookNameStyle; +import org.apache.camel.facebook.data.FacebookMethodsType; +import org.apache.camel.facebook.data.FacebookPropertiesHelper; +import org.apache.camel.impl.DefaultEndpoint; +import org.apache.camel.spi.UriEndpoint; +import org.apache.camel.spi.UriParam; +import org.apache.camel.util.EndpointHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.apache.camel.facebook.data.FacebookMethodsTypeHelper.convertToGetMethod; +import static org.apache.camel.facebook.data.FacebookMethodsTypeHelper.convertToSearchMethod; +import static org.apache.camel.facebook.data.FacebookMethodsTypeHelper.getCandidateMethods; +import static org.apache.camel.facebook.data.FacebookMethodsTypeHelper.getMissingProperties; +import static org.apache.camel.facebook.data.FacebookPropertiesHelper.getEndpointPropertyNames; + +/** + * Represents a Facebook endpoint. + */ +@UriEndpoint(scheme = "facebook", consumerClass = FacebookConsumer.class) +public class FacebookEndpoint extends DefaultEndpoint implements FacebookConstants { + + private static final Logger LOG = LoggerFactory.getLogger(FacebookEndpoint.class); + + @UriParam + private FacebookEndpointConfiguration configuration; + + // Facebook4J method name + private final String methodName; + private FacebookNameStyle nameStyle; + + // candidate methods based on method name and endpoint configuration + private List candidates; + + public FacebookEndpoint(String uri, FacebookComponent facebookComponent, + String remaining, FacebookEndpointConfiguration configuration) { + super(uri, facebookComponent); + this.configuration = configuration; + this.methodName = remaining; + } + + public Producer createProducer() throws Exception { + return new FacebookProducer(this); + } + + public Consumer createConsumer(Processor processor) throws Exception { + final FacebookConsumer consumer = new FacebookConsumer(this, processor); + // also set consumer.* properties + configureConsumer(consumer); + return consumer; + } + + public boolean isSingleton() { + return true; + } + + @Override + public void configureProperties(Map options) { + super.configureProperties(options); + + // set configuration properties first + try { + if (configuration == null) { + configuration = new FacebookEndpointConfiguration(); + } + EndpointHelper.setReferenceProperties(getCamelContext(), configuration, options); + EndpointHelper.setProperties(getCamelContext(), configuration, options); + } catch (Exception e) { + throw new IllegalArgumentException(e.getMessage(), e); + } + + // extract reading properties + FacebookPropertiesHelper.configureReadingProperties(configuration, options); + + // validate configuration + configuration.validate(); + // validate and initialize state + initState(); + } + + private void initState() { + // get endpoint property names + final Set arguments = getEndpointPropertyNames(configuration); + final String[] argNames = arguments.toArray(new String[arguments.size()]); + + candidates = new ArrayList(); + candidates.addAll(getCandidateMethods(methodName, argNames)); + if (!candidates.isEmpty()) { + // found an exact name match, allows disambiguation if needed + this.nameStyle = FacebookNameStyle.EXACT; + } else { + + // also search for long forms of method name, both get* and search* + // Note that this set will be further sorted by Producers and Consumers + // producers will prefer get* forms, and consumers should prefer search* forms + candidates.addAll(getCandidateMethods(convertToGetMethod(methodName), argNames)); + if (!candidates.isEmpty()) { + this.nameStyle = FacebookNameStyle.GET; + } + + candidates.addAll(getCandidateMethods(convertToSearchMethod(methodName), argNames)); + // error if there are no candidates + if (candidates.isEmpty()) { + throw new IllegalArgumentException( + String.format("No matching operation for %s, with arguments %s", methodName, arguments)); + } + + if (nameStyle == null) { + // no get* methods found + nameStyle = FacebookNameStyle.SEARCH; + } else { + // get* and search* methods found + nameStyle = FacebookNameStyle.GET_AND_SEARCH; + } + } + + // log missing/extra properties for debugging + if (LOG.isDebugEnabled()) { + final Set missing = getMissingProperties(methodName, nameStyle, arguments); + if (!missing.isEmpty()) { + LOG.debug("Method {} could use one or more properties from {}", methodName, missing); + } + } + } + + public FacebookEndpointConfiguration getConfiguration() { + return configuration; + } + + public String getMethodName() { + return methodName; + } + + public FacebookNameStyle getNameStyle() { + return nameStyle; + } + + public List getCandidates() { + return Collections.unmodifiableList(candidates); + } + +} diff --git a/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookProducer.java b/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookProducer.java new file mode 100644 index 0000000000000..7feb3feb10853 --- /dev/null +++ b/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookProducer.java @@ -0,0 +1,170 @@ +package org.apache.camel.facebook; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ExecutorService; +import org.apache.camel.AsyncCallback; +import org.apache.camel.CamelContext; +import org.apache.camel.Exchange; +import org.apache.camel.RuntimeCamelException; +import org.apache.camel.facebook.config.FacebookEndpointConfiguration; +import org.apache.camel.facebook.data.FacebookMethodsType; +import org.apache.camel.facebook.data.FacebookMethodsTypeHelper; +import org.apache.camel.impl.DefaultAsyncProducer; +import org.apache.camel.spi.ExecutorServiceManager; +import org.apache.camel.spi.ThreadPoolProfile; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.apache.camel.facebook.data.FacebookMethodsTypeHelper.MatchType; +import static org.apache.camel.facebook.data.FacebookMethodsTypeHelper.filterMethods; +import static org.apache.camel.facebook.data.FacebookMethodsTypeHelper.getCandidateMethods; +import static org.apache.camel.facebook.data.FacebookMethodsTypeHelper.getMissingProperties; +import static org.apache.camel.facebook.data.FacebookPropertiesHelper.getEndpointProperties; +import static org.apache.camel.facebook.data.FacebookPropertiesHelper.getExchangeProperties; + +/** + * The Facebook producer. + */ +public class FacebookProducer extends DefaultAsyncProducer { + private static final transient Logger LOG = LoggerFactory.getLogger(FacebookProducer.class); + + // thread pool executor + private static ExecutorService executorService; + + private FacebookEndpoint endpoint; + + public FacebookProducer(FacebookEndpoint endpoint) { + super(endpoint); + this.endpoint = endpoint; + + // get candidate methods using endpoint configuration + getCandidateMethods(endpoint.getEndpointUri()); + } + + @Override + public boolean process(final Exchange exchange, final AsyncCallback callback) { + // properties for method arguments + final Map properties = new HashMap(); + getEndpointProperties(endpoint.getConfiguration(), properties); + getExchangeProperties(exchange, properties); + + // decide which method to invoke + final FacebookMethodsType method = findMethod(exchange, properties); + if (method == null) { + // synchronous failure + callback.done(true); + return true; + } + + // create a runnable invocation task to be submitted on a background thread pool + // this way we avoid blocking the current thread for long running operations + Runnable invocation = new Runnable() { + @Override + public void run() { + try { + if (LOG.isDebugEnabled()) { + LOG.debug("Invoking method {} with {}", method.getName(), properties.keySet()); + } + + Object result = FacebookMethodsTypeHelper.invokeMethod( + endpoint.getConfiguration().getFacebook(), method, properties); + + // producer returns a single response, even for methods with List return types + exchange.getOut().setBody(result); + // copy headers + exchange.getOut().setHeaders(exchange.getIn().getHeaders()); + + } catch (Exception e) { + exchange.setException(new RuntimeCamelException(String.format("Error invoking %s with %s: %s", + method.getName(), properties.keySet(), e.getMessage()), e)); + } finally { + callback.done(false); + } + } + }; + + getExecutorService(getEndpoint().getCamelContext()).submit(invocation); + return false; + } + + private FacebookMethodsType findMethod(Exchange exchange, Map properties) { + // lucky enough to have a single method candidate? + final List candidates = endpoint.getCandidates(); + FacebookMethodsType method = null; + if (candidates.size() == 1) { + // jackpot! + method = candidates.get(0); + } else if (processInBody(exchange, properties)) { + + // filter candidates based on endpoint and exchange properties + final Set argNames = properties.keySet(); + final List filteredMethods = filterMethods(candidates, MatchType.SUPER_SET, + argNames.toArray(new String[argNames.size()])); + + // get the method to call + if (filteredMethods.isEmpty()) { + final Set missing = getMissingProperties(endpoint.getMethodName(), + endpoint.getNameStyle(), argNames); + throw new RuntimeCamelException(String.format("Missing properties for %s, need one or more from %s", + endpoint.getMethodName(), missing)); + } else if (filteredMethods.size() == 1) { + // found an exact match + method = filteredMethods.get(0); + } else { + method = FacebookMethodsTypeHelper.getHighestPriorityMethod(filteredMethods); + LOG.warn("Calling highest priority method {} from methods {}", method, filteredMethods); + } + } + + return method; + } + + private boolean processInBody(Exchange exchange, Map properties) { + final String inBodyProperty = (String) properties.remove(FacebookConstants.IN_BODY_PROPERTY); + if (inBodyProperty != null) { + + Object value = exchange.getIn().getBody(); + try { + value = getEndpoint().getCamelContext().getTypeConverter().mandatoryConvertTo( + FacebookEndpointConfiguration.class.getDeclaredField(inBodyProperty).getClass(), + exchange, value); + } catch (Exception e) { + exchange.setException(new RuntimeCamelException(String.format( + "Error converting value %s to property %s: %s", value, inBodyProperty, e.getMessage()), e)); + + return false; + } + + properties.put(inBodyProperty, value); + } + + return true; + } + + protected static synchronized ExecutorService getExecutorService(CamelContext context) { + // CamelContext will shutdown thread pool when it shutdown so we can + // lazy create it on demand + // but in case of hot-deploy or the likes we need to be able to + // re-create it (its a shared static instance) + if (executorService == null || executorService.isTerminated() || executorService.isShutdown()) { + final ExecutorServiceManager manager = context.getExecutorServiceManager(); + + // try to lookup a pool first based on profile + ThreadPoolProfile poolProfile = manager.getThreadPoolProfile( + FacebookConstants.FACEBOOK_THREAD_PROFILE_NAME); + if (poolProfile == null) { + poolProfile = manager.getDefaultThreadPoolProfile(); + } + + // create a new pool using the custom or default profile + executorService = manager.newScheduledThreadPool(FacebookProducer.class, + FacebookConstants.FACEBOOK_THREAD_PROFILE_NAME, poolProfile); + } + + return executorService; + } + +} diff --git a/components/camel-facebook/src/main/java/org/apache/camel/facebook/config/FacebookConfiguration.java b/components/camel-facebook/src/main/java/org/apache/camel/facebook/config/FacebookConfiguration.java new file mode 100644 index 0000000000000..1e63daad424e8 --- /dev/null +++ b/components/camel-facebook/src/main/java/org/apache/camel/facebook/config/FacebookConfiguration.java @@ -0,0 +1,443 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.facebook.config; + +import org.apache.camel.spi.UriParam; +import org.apache.camel.spi.UriParams; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import facebook4j.Facebook; +import facebook4j.FacebookException; +import facebook4j.FacebookFactory; +import facebook4j.auth.OAuthAuthorization; +import facebook4j.conf.Configuration; +import facebook4j.conf.ConfigurationBuilder; + +/** + * Facebook component configuration. + */ +@UriParams +public class FacebookConfiguration implements Cloneable { + + private static final Logger LOG = LoggerFactory.getLogger(FacebookConfiguration.class); + + @UriParam + private String oAuthAppId; + @UriParam + private String oAuthAppSecret; + @UriParam + private String oAuthAccessToken; + @UriParam + private String oAuthAuthorizationURL; + @UriParam + private String oAuthPermissions; + + @UriParam + private String oAuthAccessTokenURL; + @UriParam + private String clientURL; + @UriParam + private String clientVersion; + @UriParam + private Boolean debugEnabled; + @UriParam + private Boolean gzipEnabled; + @UriParam + private Integer httpConnectionTimeout; + @UriParam + private Integer httpDefaultMaxPerRoute; + @UriParam + private Integer httpMaxTotalConnections; + @UriParam + private String httpProxyHost; + @UriParam + private String httpProxyPassword; + @UriParam + private Integer httpProxyPort; + @UriParam + private String httpProxyUser; + @UriParam + private Integer httpReadTimeout; + @UriParam + private Integer httpRetryCount; + @UriParam + private Integer httpRetryIntervalSeconds; + @UriParam + private Integer httpStreamingReadTimeout; + @UriParam + private Boolean jsonStoreEnabled; + @UriParam + private Boolean mbeanEnabled; + @UriParam + private Boolean prettyDebugEnabled; + @UriParam + private String restBaseURL; + @UriParam + private Boolean useSSL; + @UriParam + private String videoBaseURL; + + // cached FaceBook instance, is created in getFacebook by endpoint producers and consumers + private Facebook facebook; + + public Configuration getConfiguration() { + final ConfigurationBuilder builder = new ConfigurationBuilder(); + // apply builder settings + + if (oAuthAccessToken != null) { + builder.setOAuthAccessToken(oAuthAccessToken); + } + if (oAuthAccessTokenURL != null) { + builder.setOAuthAccessTokenURL(oAuthAccessTokenURL); + } + if (oAuthAppId != null) { + builder.setOAuthAppId(oAuthAppId); + } + if (oAuthAppSecret != null) { + builder.setOAuthAppSecret(oAuthAppSecret); + } + if (oAuthAuthorizationURL != null) { + builder.setOAuthAuthorizationURL(oAuthAuthorizationURL); + } + if (oAuthPermissions != null) { + builder.setOAuthPermissions(oAuthPermissions); + } + + if (clientURL != null) { + builder.setClientURL(clientURL); + } + if (clientVersion != null) { + builder.setClientVersion(clientVersion); + } + if (debugEnabled != null) { + builder.setDebugEnabled(debugEnabled); + } + if (gzipEnabled != null) { + builder.setGZIPEnabled(gzipEnabled); + } + if (httpConnectionTimeout != null) { + builder.setHttpConnectionTimeout(httpConnectionTimeout); + } + if (httpDefaultMaxPerRoute != null) { + builder.setHttpDefaultMaxPerRoute(httpDefaultMaxPerRoute); + } + if (httpMaxTotalConnections != null) { + builder.setHttpMaxTotalConnections(httpMaxTotalConnections); + } + if (httpProxyHost != null) { + builder.setHttpProxyHost(httpProxyHost); + } + if (httpProxyPassword != null) { + builder.setHttpProxyPassword(httpProxyPassword); + } + if (httpProxyPort != null) { + builder.setHttpProxyPort(httpProxyPort); + } + if (httpProxyUser != null) { + builder.setHttpProxyUser(httpProxyUser); + } + if (httpReadTimeout != null) { + builder.setHttpReadTimeout(httpReadTimeout); + } + if (httpRetryCount != null) { + builder.setHttpRetryCount(httpRetryCount); + } + if (httpRetryIntervalSeconds != null) { + builder.setHttpRetryIntervalSeconds(httpRetryIntervalSeconds); + } + if (httpStreamingReadTimeout != null) { + builder.setHttpStreamingReadTimeout(httpStreamingReadTimeout); + } + if (jsonStoreEnabled != null) { + builder.setJSONStoreEnabled(jsonStoreEnabled); + } + if (mbeanEnabled != null) { + builder.setMBeanEnabled(mbeanEnabled); + } + if (prettyDebugEnabled != null) { + builder.setPrettyDebugEnabled(prettyDebugEnabled); + } + if (restBaseURL != null) { + builder.setRestBaseURL(restBaseURL); + } + if (useSSL != null) { + builder.setUseSSL(useSSL); + } + if (videoBaseURL != null) { + builder.setVideoBaseURL(videoBaseURL); + } + + return builder.build(); + } + + /** + * Returns {@link Facebook} instance. If needed, creates one from configuration. + * @return {@link Facebook} instance + */ + public Facebook getFacebook() throws FacebookException { + if (facebook == null) { + final Configuration configuration = getConfiguration(); + FacebookFactory factory = new FacebookFactory(configuration); + if (this.oAuthAccessToken == null) { + // app login + facebook = factory.getInstance(new OAuthAuthorization(configuration)); + // also get the App access token + facebook.getOAuthAppAccessToken(); + LOG.warn("Login with app id and secret, access to some APIs is restricted!"); + } else { + // user login with token + facebook = factory.getInstance(); + // verify the access token + facebook.getOAuthAccessToken(); + LOG.debug("Login with app id, secret and token, all APIs accessible"); + } + } + return facebook; + } + + public FacebookConfiguration copy() throws CloneNotSupportedException { + final FacebookConfiguration copy = (FacebookConfiguration) clone(); + // do not copy facebook instance!!! + copy.facebook = null; + return copy; + } + + public String getOAuthAccessToken() { + return oAuthAccessToken; + } + + public void setOAuthAccessToken(String oAuthAccessToken) { + this.oAuthAccessToken = oAuthAccessToken; + } + + public String getOAuthAccessTokenURL() { + return oAuthAccessTokenURL; + } + + public void setOAuthAccessTokenURL(String oAuthAccessTokenURL) { + this.oAuthAccessTokenURL = oAuthAccessTokenURL; + } + + public String getOAuthAppId() { + return oAuthAppId; + } + + public void setOAuthAppId(String oAuthAppId) { + this.oAuthAppId = oAuthAppId; + } + + public String getOAuthAppSecret() { + return oAuthAppSecret; + } + + public void setOAuthAppSecret(String oAuthAppSecret) { + this.oAuthAppSecret = oAuthAppSecret; + } + + public String getOAuthAuthorizationURL() { + return oAuthAuthorizationURL; + } + + public void setOAuthAuthorizationURL(String oAuthAuthorizationURL) { + this.oAuthAuthorizationURL = oAuthAuthorizationURL; + } + + public String getClientURL() { + return clientURL; + } + + public void setClientURL(String clientURL) { + this.clientURL = clientURL; + } + + public String getClientVersion() { + return clientVersion; + } + + public void setClientVersion(String clientVersion) { + this.clientVersion = clientVersion; + } + + public Boolean getDebugEnabled() { + return debugEnabled; + } + + public void setDebugEnabled(Boolean debugEnabled) { + this.debugEnabled = debugEnabled; + } + + public Boolean getGzipEnabled() { + return gzipEnabled; + } + + public void setGzipEnabled(Boolean gzipEnabled) { + this.gzipEnabled = gzipEnabled; + } + + public Integer getHttpConnectionTimeout() { + return httpConnectionTimeout; + } + + public void setHttpConnectionTimeout(Integer httpConnectionTimeout) { + this.httpConnectionTimeout = httpConnectionTimeout; + } + + public Integer getHttpDefaultMaxPerRoute() { + return httpDefaultMaxPerRoute; + } + + public void setHttpDefaultMaxPerRoute(Integer httpDefaultMaxPerRoute) { + this.httpDefaultMaxPerRoute = httpDefaultMaxPerRoute; + } + + public Integer getHttpMaxTotalConnections() { + return httpMaxTotalConnections; + } + + public void setHttpMaxTotalConnections(Integer httpMaxTotalConnections) { + this.httpMaxTotalConnections = httpMaxTotalConnections; + } + + public String getHttpProxyHost() { + return httpProxyHost; + } + + public void setHttpProxyHost(String httpProxyHost) { + this.httpProxyHost = httpProxyHost; + } + + public String getHttpProxyPassword() { + return httpProxyPassword; + } + + public void setHttpProxyPassword(String httpProxyPassword) { + this.httpProxyPassword = httpProxyPassword; + } + + public Integer getHttpProxyPort() { + return httpProxyPort; + } + + public void setHttpProxyPort(Integer httpProxyPort) { + this.httpProxyPort = httpProxyPort; + } + + public String getHttpProxyUser() { + return httpProxyUser; + } + + public void setHttpProxyUser(String httpProxyUser) { + this.httpProxyUser = httpProxyUser; + } + + public Integer getHttpReadTimeout() { + return httpReadTimeout; + } + + public void setHttpReadTimeout(Integer httpReadTimeout) { + this.httpReadTimeout = httpReadTimeout; + } + + public Integer getHttpRetryCount() { + return httpRetryCount; + } + + public void setHttpRetryCount(Integer httpRetryCount) { + this.httpRetryCount = httpRetryCount; + } + + public Integer getHttpRetryIntervalSeconds() { + return httpRetryIntervalSeconds; + } + + public void setHttpRetryIntervalSeconds(Integer httpRetryIntervalSeconds) { + this.httpRetryIntervalSeconds = httpRetryIntervalSeconds; + } + + public Integer getHttpStreamingReadTimeout() { + return httpStreamingReadTimeout; + } + + public void setHttpStreamingReadTimeout(Integer httpStreamingReadTimeout) { + this.httpStreamingReadTimeout = httpStreamingReadTimeout; + } + + public Boolean getJsonStoreEnabled() { + return jsonStoreEnabled; + } + + public void setJsonStoreEnabled(Boolean jsonStoreEnabled) { + this.jsonStoreEnabled = jsonStoreEnabled; + } + + public Boolean getMbeanEnabled() { + return mbeanEnabled; + } + + public void setMbeanEnabled(Boolean mbeanEnabled) { + this.mbeanEnabled = mbeanEnabled; + } + + public String getOAuthPermissions() { + return oAuthPermissions; + } + + public void setOAuthPermissions(String oAuthPermissions) { + this.oAuthPermissions = oAuthPermissions; + } + + public Boolean getPrettyDebugEnabled() { + return prettyDebugEnabled; + } + + public void setPrettyDebugEnabled(Boolean prettyDebugEnabled) { + this.prettyDebugEnabled = prettyDebugEnabled; + } + + public String getRestBaseURL() { + return restBaseURL; + } + + public void setRestBaseURL(String restBaseURL) { + this.restBaseURL = restBaseURL; + } + + public Boolean getUseSSL() { + return useSSL; + } + + public void setUseSSL(Boolean useSSL) { + this.useSSL = useSSL; + } + + public String getVideoBaseURL() { + return videoBaseURL; + } + + public void setVideoBaseURL(String videoBaseURL) { + this.videoBaseURL = videoBaseURL; + } + + public void validate() { + if ((oAuthAppId == null || oAuthAppId.isEmpty()) + || (oAuthAppSecret == null || oAuthAppSecret.isEmpty())) { + throw new IllegalArgumentException("Missing required properties oAuthAppId, oAuthAppSecret"); + } + } + +} diff --git a/components/camel-facebook/src/main/java/org/apache/camel/facebook/config/FacebookEndpointConfiguration.java b/components/camel-facebook/src/main/java/org/apache/camel/facebook/config/FacebookEndpointConfiguration.java new file mode 100644 index 0000000000000..2c2f7f399d714 --- /dev/null +++ b/components/camel-facebook/src/main/java/org/apache/camel/facebook/config/FacebookEndpointConfiguration.java @@ -0,0 +1,706 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.facebook.config; + +import java.lang.reflect.Field; +import java.net.URL; +import java.util.Arrays; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import org.apache.camel.facebook.FacebookConstants; +import org.apache.camel.spi.UriParam; +import org.apache.camel.spi.UriParams; +import org.apache.camel.util.ObjectHelper; + +import facebook4j.*; + +@UriParams +public class FacebookEndpointConfiguration extends FacebookConfiguration { + + // property name for Exchange 'In' message body + @UriParam + private String inBody; + + @UriParam + private URL achievementURL; + @UriParam + private AlbumCreate albumCreate; + @UriParam + private String albumId; + @UriParam + private Boolean allowNewOptions; + @UriParam + private String appId; + @UriParam + private GeoLocation center; + @UriParam + private CheckinCreate checkinCreate; + @UriParam + private String checkinId; + @UriParam + private String commentId; + @UriParam + private String description; + @UriParam + private Integer distance; + @UriParam + private String domainId; + @UriParam + private String domainName; + @UriParam + private List domainNames; + @UriParam + private String eventId; + @UriParam + private EventUpdate eventUpdate; + @UriParam + private String friendId; + @UriParam + private String friendUserId; + @UriParam + private String friendlistId; + @UriParam + private String friendlistName; + @UriParam + private String groupId; + @UriParam + private List ids; + @UriParam + private Boolean includeRead; + @UriParam + private URL link; + @UriParam + private String linkId; + @UriParam + private Locale locale; + @UriParam + private String message; + @UriParam + private String messageId; + @UriParam + private String metric; + @UriParam + private String name; + @UriParam + private Boolean noStory; + @UriParam + private String noteId; + @UriParam + private String notificationId; + @UriParam + private String objectId; + @UriParam + private String optionDescription; + @UriParam + private List options; + @UriParam + private String permissionName; + @UriParam + private String permissions; + @UriParam + private String photoId; + @UriParam + private String place; + @UriParam + private String placeId; + @UriParam + private String postId; + @UriParam + private PostUpdate postUpdate; + @UriParam + private Map queries; + @UriParam + private String query; + @UriParam + private String question; + @UriParam + private String questionId; + @UriParam + private Reading reading; + @UriParam + private Integer scoreValue; + @UriParam + private PictureSize size; + @UriParam + private Media source; + @UriParam + private String subject; + @UriParam + private TagUpdate tagUpdate; + @UriParam + private TestUser testUser1; + @UriParam + private TestUser testUser2; + @UriParam + private String testUserId; + @UriParam + private String title; + @UriParam + private String toUserId; + @UriParam + private List toUserIds; + @UriParam + private String userId1; + @UriParam + private String userId2; + @UriParam + private String userId; + @UriParam + private List userIds; + @UriParam + private String userLocale; + @UriParam + private String videoId; + + public String getInBody() { + return inBody; + } + + public void setInBody(String inBody) { + ObjectHelper.notNull(inBody, "inBody"); + this.inBody = inBody; + + // validate name + final List fields = Arrays.asList(getClass().getDeclaredFields()); + fields.remove(FacebookConstants.IN_BODY_PROPERTY); + if (!fields.contains(inBody)) { + throw new IllegalArgumentException("Unknown property " + inBody); + } + } + + public URL getAchievementURL() { + return achievementURL; + } + + public void setAchievementURL(URL achievementURL) { + this.achievementURL = achievementURL; + } + + public AlbumCreate getAlbumCreate() { + return albumCreate; + } + + public void setAlbumCreate(AlbumCreate albumCreate) { + this.albumCreate = albumCreate; + } + + public String getAlbumId() { + return albumId; + } + + public void setAlbumId(String albumId) { + this.albumId = albumId; + } + + public Boolean isAllowNewOptions() { + return allowNewOptions; + } + + public void setAllowNewOptions(Boolean allowNewOptions) { + this.allowNewOptions = allowNewOptions; + } + + public String getoAuthAppId() { + return appId; + } + + public void setoAuthAppId(String appId) { + this.appId = appId; + } + + public GeoLocation getCenter() { + return center; + } + + public void setCenter(GeoLocation center) { + this.center = center; + } + + public CheckinCreate getCheckinCreate() { + return checkinCreate; + } + + public void setCheckinCreate(CheckinCreate checkinCreate) { + this.checkinCreate = checkinCreate; + } + + public String getCheckinId() { + return checkinId; + } + + public void setCheckinId(String checkinId) { + this.checkinId = checkinId; + } + + public String getCommentId() { + return commentId; + } + + public void setCommentId(String commentId) { + this.commentId = commentId; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Integer getDistance() { + return distance; + } + + public void setDistance(Integer distance) { + this.distance = distance; + } + + public String getDomainId() { + return domainId; + } + + public void setDomainId(String domainId) { + this.domainId = domainId; + } + + public String getDomainName() { + return domainName; + } + + public void setDomainName(String domainName) { + this.domainName = domainName; + } + + public List getDomainNames() { + return domainNames; + } + + public void setDomainNames(List domainNames) { + this.domainNames = domainNames; + } + + public String getEventId() { + return eventId; + } + + public void setEventId(String eventId) { + this.eventId = eventId; + } + + public EventUpdate getEventUpdate() { + return eventUpdate; + } + + public void setEventUpdate(EventUpdate eventUpdate) { + this.eventUpdate = eventUpdate; + } + + public String getFriendId() { + return friendId; + } + + public void setFriendId(String friendId) { + this.friendId = friendId; + } + + public String getFriendUserId() { + return friendUserId; + } + + public void setFriendUserId(String friendUserId) { + this.friendUserId = friendUserId; + } + + public String getFriendlistId() { + return friendlistId; + } + + public void setFriendlistId(String friendlistId) { + this.friendlistId = friendlistId; + } + + public String getFriendlistName() { + return friendlistName; + } + + public void setFriendlistName(String friendlistName) { + this.friendlistName = friendlistName; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public List getIds() { + return ids; + } + + public void setIds(List ids) { + this.ids = ids; + } + + public Boolean isIncludeRead() { + return includeRead; + } + + public void setIncludeRead(Boolean includeRead) { + this.includeRead = includeRead; + } + + public URL getLink() { + return link; + } + + public void setLink(URL link) { + this.link = link; + } + + public String getLinkId() { + return linkId; + } + + public void setLinkId(String linkId) { + this.linkId = linkId; + } + + public Locale getLocale() { + return locale; + } + + public void setLocale(Locale locale) { + this.locale = locale; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getMessageId() { + return messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getMetric() { + return metric; + } + + public void setMetric(String metric) { + this.metric = metric; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Boolean isNoStory() { + return noStory; + } + + public void setNoStory(Boolean noStory) { + this.noStory = noStory; + } + + public String getNoteId() { + return noteId; + } + + public void setNoteId(String noteId) { + this.noteId = noteId; + } + + public String getNotificationId() { + return notificationId; + } + + public void setNotificationId(String notificationId) { + this.notificationId = notificationId; + } + + public String getObjectId() { + return objectId; + } + + public void setObjectId(String objectId) { + this.objectId = objectId; + } + + public String getOptionDescription() { + return optionDescription; + } + + public void setOptionDescription(String optionDescription) { + this.optionDescription = optionDescription; + } + + public List getOptions() { + return options; + } + + public void setOptions(List options) { + this.options = options; + } + + public String getPermissionName() { + return permissionName; + } + + public void setPermissionName(String permissionName) { + this.permissionName = permissionName; + } + + public String getoAuthPermissions() { + return permissions; + } + + public void setoAuthPermissions(String permissions) { + this.permissions = permissions; + } + + public String getPhotoId() { + return photoId; + } + + public void setPhotoId(String photoId) { + this.photoId = photoId; + } + + public String getPlace() { + return place; + } + + public void setPlace(String place) { + this.place = place; + } + + public String getPlaceId() { + return placeId; + } + + public void setPlaceId(String placeId) { + this.placeId = placeId; + } + + public String getPostId() { + return postId; + } + + public void setPostId(String postId) { + this.postId = postId; + } + + public PostUpdate getPostUpdate() { + return postUpdate; + } + + public void setPostUpdate(PostUpdate postUpdate) { + this.postUpdate = postUpdate; + } + + public Map getQueries() { + return queries; + } + + public void setQueries(Map queries) { + this.queries = queries; + } + + public String getQuery() { + return query; + } + + public void setQuery(String query) { + this.query = query; + } + + public String getQuestion() { + return question; + } + + public void setQuestion(String question) { + this.question = question; + } + + public String getQuestionId() { + return questionId; + } + + public void setQuestionId(String questionId) { + this.questionId = questionId; + } + + public Reading getReading() { + return reading; + } + + public void setReading(Reading reading) { + this.reading = reading; + } + + public Integer getScoreValue() { + return scoreValue; + } + + public void setScoreValue(Integer scoreValue) { + this.scoreValue = scoreValue; + } + + public PictureSize getSize() { + return size; + } + + public void setSize(PictureSize size) { + this.size = size; + } + + public Media getSource() { + return source; + } + + public void setSource(Media source) { + this.source = source; + } + + public String getSubject() { + return subject; + } + + public void setSubject(String subject) { + this.subject = subject; + } + + public TagUpdate getTagUpdate() { + return tagUpdate; + } + + public void setTagUpdate(TagUpdate tagUpdate) { + this.tagUpdate = tagUpdate; + } + + public TestUser getTestUser1() { + return testUser1; + } + + public void setTestUser1(TestUser testUser1) { + this.testUser1 = testUser1; + } + + public TestUser getTestUser2() { + return testUser2; + } + + public void setTestUser2(TestUser testUser2) { + this.testUser2 = testUser2; + } + + public String getTestUserId() { + return testUserId; + } + + public void setTestUserId(String testUserId) { + this.testUserId = testUserId; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getToUserId() { + return toUserId; + } + + public void setToUserId(String toUserId) { + this.toUserId = toUserId; + } + + public List getToUserIds() { + return toUserIds; + } + + public void setToUserIds(List toUserIds) { + this.toUserIds = toUserIds; + } + + public String getUserId1() { + return userId1; + } + + public void setUserId1(String userId1) { + this.userId1 = userId1; + } + + public String getUserId2() { + return userId2; + } + + public void setUserId2(String userId2) { + this.userId2 = userId2; + } + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public List getUserIds() { + return userIds; + } + + public void setUserIds(List userIds) { + this.userIds = userIds; + } + + public String getUserLocale() { + return userLocale; + } + + public void setUserLocale(String userLocale) { + this.userLocale = userLocale; + } + + public String getVideoId() { + return videoId; + } + + public void setVideoId(String videoId) { + this.videoId = videoId; + } + +} diff --git a/components/camel-facebook/src/main/java/org/apache/camel/facebook/config/FacebookNameStyle.java b/components/camel-facebook/src/main/java/org/apache/camel/facebook/config/FacebookNameStyle.java new file mode 100644 index 0000000000000..94cc2f7d66d4e --- /dev/null +++ b/components/camel-facebook/src/main/java/org/apache/camel/facebook/config/FacebookNameStyle.java @@ -0,0 +1,10 @@ +package org.apache.camel.facebook.config; + +/** + * Constants for method name style. + */ +public enum FacebookNameStyle { + + EXACT, GET, SEARCH, GET_AND_SEARCH; + +} diff --git a/components/camel-facebook/src/main/java/org/apache/camel/facebook/data/FacebookMethodsType.java b/components/camel-facebook/src/main/java/org/apache/camel/facebook/data/FacebookMethodsType.java new file mode 100644 index 0000000000000..ebf040d0fa302 --- /dev/null +++ b/components/camel-facebook/src/main/java/org/apache/camel/facebook/data/FacebookMethodsType.java @@ -0,0 +1,572 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.facebook.data; + +import java.lang.reflect.Method; +import java.net.URL; +import java.util.*; +import org.apache.camel.facebook.FacebookConstants; + +import facebook4j.*; +import facebook4j.internal.org.json.JSONArray; + +/** + * Enum for Facebook4J *Method interfaces. + * The methods are ordered by the number and nature of arguments. + */ +public enum FacebookMethodsType { + + // AccountMethods + GET_ACCOUNTS(ResponseList.class, "getAccounts"), + GET_ACCOUNTS_WITH_OPTIONS(ResponseList.class, "getAccounts", Reading.class, FacebookConstants.READING_PPROPERTY), + GET_ACCOUNTS_WITH_ID(ResponseList.class, "getAccounts", String.class, "userId"), + GET_ACCOUNTS_WITH_ID_OPTIONS(ResponseList.class, "getAccounts", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + + // ActivityMethods + GETACTIVITIES(ResponseList.class, "getActivities"), + GETACTIVITIES_WITH_OPTIONS(ResponseList.class, "getActivities", Reading.class, FacebookConstants.READING_PPROPERTY), + GETACTIVITIES_WITH_ID(ResponseList.class, "getActivities", String.class, "userId"), + GETACTIVITIES_WITH_ID_OPTIONS(ResponseList.class, "getActivities", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + + // AlbumMethods + ADDALBUMPHOTO(String.class, "addAlbumPhoto", String.class, "albumId", Media.class, "source"), + ADDALBUMPHOTO_WITH_MEDIA(String.class, "addAlbumPhoto", String.class, "albumId", Media.class, "source", String.class, "message"), + COMMENTALBUM(String.class, "commentAlbum", String.class, "albumId", String.class, "message"), + CREATEALBUM(String.class, "createAlbum", AlbumCreate.class, "albumCreate"), + CREATEALBUM_WITH_ID(String.class, "createAlbum", String.class, "userId", AlbumCreate.class, "albumCreate"), + GETALBUM(Album.class, "getAlbum", String.class, "albumId"), + GETALBUM_WITH_OPTIONS(Album.class, "getAlbum", String.class, "albumId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETALBUMCOMMENTS(ResponseList.class, "getAlbumComments", String.class, "albumId"), + GETALBUMCOMMENTS_WITH_OPTIONS(ResponseList.class, "getAlbumComments", String.class, "albumId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETALBUMCOVERPHOTO(URL.class, "getAlbumCoverPhoto", String.class, "albumId"), + GETALBUMLIKES(ResponseList.class, "getAlbumLikes", String.class, "albumId"), + GETALBUMLIKES_WITH_OPTIONS(ResponseList.class, "getAlbumLikes", String.class, "albumId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETALBUMPHOTOS(ResponseList.class, "getAlbumPhotos", String.class, "albumId"), + GETALBUMPHOTOS_WITH_OPTIONS(ResponseList.class, "getAlbumPhotos", String.class, "albumId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETALBUMS(ResponseList.class, "getAlbums"), + GETALBUMS_WITH_OPTIONS(ResponseList.class, "getAlbums", Reading.class, FacebookConstants.READING_PPROPERTY), + GETALBUMS_WITH_ID(ResponseList.class, "getAlbums", String.class, "userId"), + GETALBUMS_WITH_ID_OPTIONS(ResponseList.class, "getAlbums", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + LIKEALBUM(boolean.class, "likeAlbum", String.class, "albumId"), + UNLIKEALBUM(boolean.class, "unlikeAlbum", String.class, "albumId"), + + // CheckinMethods + CHECKIN(String.class, "checkin", CheckinCreate.class, "checkinCreate"), + CHECKIN_WITH_ID(String.class, "checkin", String.class, "userId", CheckinCreate.class, "checkinCreate"), + COMMENTCHECKIN(String.class, "commentCheckin", String.class, "checkinId", String.class, "message"), + GETCHECKIN(Checkin.class, "getCheckin", String.class, "checkinId"), + GETCHECKIN_WITH_OPTIONS(Checkin.class, "getCheckin", String.class, "checkinId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETCHECKINCOMMENTS(ResponseList.class, "getCheckinComments", String.class, "checkinId"), + GETCHECKINCOMMENTS_WITH_OPTIONS(ResponseList.class, "getCheckinComments", String.class, "checkinId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETCHECKINLIKES(ResponseList.class, "getCheckinLikes", String.class, "checkinId"), + GETCHECKINLIKES_WITH_OPTIONS(ResponseList.class, "getCheckinLikes", String.class, "checkinId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETCHECKINS(ResponseList.class, "getCheckins"), + GETCHECKINS_WITH_OPTIONS(ResponseList.class, "getCheckins", Reading.class, FacebookConstants.READING_PPROPERTY), + GETCHECKINS_WITH_ID(ResponseList.class, "getCheckins", String.class, "userId"), + GETCHECKINS_WITH_ID_OPTIONS(ResponseList.class, "getCheckins", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + LIKECHECKIN(boolean.class, "likeCheckin", String.class, "checkinId"), + UNLIKECHECKIN(boolean.class, "unlikeCheckin", String.class, "checkinId"), + + // CommentMethods + DELETECOMMENT(boolean.class, "deleteComment", String.class, "commentId"), + GETCOMMENT(Comment.class, "getComment", String.class, "commentId"), + GETCOMMENTLIKES(ResponseList.class, "getCommentLikes", String.class, "commentId"), + GETCOMMENTLIKES_WITH_OPTIONS(ResponseList.class, "getCommentLikes", String.class, "commentId", Reading.class, FacebookConstants.READING_PPROPERTY), + LIKECOMMENT(boolean.class, "likeComment", String.class, "commentId"), + UNLIKECOMMENT(Boolean.class, "unlikeComment", String.class, "commentId"), + + // DomainMethods + GETDOMAIN(Domain.class, "getDomain", String.class, "domainId"), + GETDOMAINBYNAME(Domain.class, "getDomainByName", String.class, "domainName"), + GETDOMAINSBYNAME_WITH_DOMAINS(List.class, "getDomainsByName", new String[0].getClass(), "domainNames"), + + // EventMethods + CREATEEVENT(String.class, "createEvent", EventUpdate.class, "eventUpdate"), + CREATEEVENT_WITH_ID(String.class, "createEvent", String.class, "userId", EventUpdate.class, "eventUpdate"), + DELETEEVENT(Boolean.class, "deleteEvent", String.class, "eventId"), + DELETEEVENTPICTURE(Boolean.class, "deleteEventPicture", String.class, "eventId"), + EDITEVENT(Boolean.class, "editEvent", String.class, "eventId", EventUpdate.class, "eventUpdate"), + GETEVENT(Event.class, "getEvent", String.class, "eventId"), + GETEVENT_WITH_OPTIONS(Event.class, "getEvent", String.class, "eventId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETEVENTFEED(ResponseList.class, "getEventFeed", String.class, "eventId"), + GETEVENTFEED_WITH_OPTIONS(ResponseList.class, "getEventFeed", String.class, "eventId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETEVENTPHOTOS(ResponseList.class, "getEventPhotos", String.class, "eventId"), + GETEVENTPHOTOS_WITH_OPTIONS(ResponseList.class, "getEventPhotos", String.class, "eventId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETEVENTPICTUREURL(URL.class, "getEventPictureURL", String.class, "eventId"), + GETEVENTPICTUREURL_WITH_PICTURESIZE(URL.class, "getEventPictureURL", String.class, "eventId", PictureSize.class, "size"), + GETEVENTS(ResponseList.class, "getEvents"), + GETEVENTS_WITH_OPTIONS(ResponseList.class, "getEvents", Reading.class, FacebookConstants.READING_PPROPERTY), + GETEVENTS_WITH_ID(ResponseList.class, "getEvents", String.class, "userId"), + GETEVENTS_WITH_ID_OPTIONS(ResponseList.class, "getEvents", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETEVENTVIDEOS(ResponseList.class, "getEventVideos", String.class, "eventId"), + GETEVENTVIDEOS_WITH_OPTIONS(ResponseList.class, "getEventVideos", String.class, "eventId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETRSVPSTATUSASINVITED(ResponseList.class, "getRSVPStatusAsInvited", String.class, "eventId"), + GETRSVPSTATUSASINVITED_WITH_ID(ResponseList.class, "getRSVPStatusAsInvited", String.class, "eventId", String.class, "userId"), + GETRSVPSTATUSASNOREPLY(ResponseList.class, "getRSVPStatusAsNoreply", String.class, "eventId"), + GETRSVPSTATUSASNOREPLY_WITH_ID(ResponseList.class, "getRSVPStatusAsNoreply", String.class, "eventId", String.class, "userId"), + GETRSVPSTATUSINATTENDING(ResponseList.class, "getRSVPStatusInAttending", String.class, "eventId"), + GETRSVPSTATUSINATTENDING_WITH_ID(ResponseList.class, "getRSVPStatusInAttending", String.class, "eventId", String.class, "userId"), + GETRSVPSTATUSINDECLINED(ResponseList.class, "getRSVPStatusInDeclined", String.class, "eventId"), + GETRSVPSTATUSINDECLINED_WITH_ID(ResponseList.class, "getRSVPStatusInDeclined", String.class, "eventId", String.class, "userId"), + GETRSVPSTATUSINMAYBE(ResponseList.class, "getRSVPStatusInMaybe", String.class, "eventId"), + GETRSVPSTATUSINMAYBE_WITH_ID(ResponseList.class, "getRSVPStatusInMaybe", String.class, "eventId", String.class, "userId"), + INVITETOEVENT(Boolean.class, "inviteToEvent", String.class, "eventId", String.class, "userId"), + INVITETOEVENT_WITH_IDS(Boolean.class, "inviteToEvent", String.class, "eventId", new String[0].getClass(), "userIds"), + POSTEVENTFEED_WITH_POSTUPDATE(String.class, "postEventFeed", String.class, "eventId", PostUpdate.class, "postUpdate"), + POSTEVENTLINK_WITH_LINK(String.class, "postEventLink", String.class, "eventId", URL.class , "link"), + POSTEVENTLINK_WITH_LINK_MSG(String.class, "postEventLink", String.class, "eventId", URL.class , "link", String.class, "message"), + POSTEVENTPHOTO_WITH_MEDIA(String.class, "postEventPhoto", String.class, "eventId", Media.class, "source"), + POSTEVENTPHOTO_WITH_MEDIA_MSG(String.class, "postEventPhoto", String.class, "eventId", Media.class, "source", String.class, "message"), + POSTEVENTSTATUSMESSAGE_WITH_MSG(String.class, "postEventStatusMessage", String.class, "eventId", String.class, "message"), + POSTEVENTVIDEO_WITH_MEDIA(String.class, "postEventVideo", String.class, "eventId", Media.class, "source"), + POSTEVENTVIDEO_WITH_MEDIA_TITLE_DESC(String.class, "postEventVideo", String.class, "eventId", Media.class, "source", String.class, "title", String.class, "description"), + RSVPEVENTASATTENDING(Boolean.class, "rsvpEventAsAttending", String.class, "eventId"), + RSVPEVENTASDECLINED(Boolean.class, "rsvpEventAsDeclined", String.class, "eventId"), + RSVPEVENTASMAYBE(Boolean.class, "rsvpEventAsMaybe", String.class, "eventId"), + UNINVITEFROMEVENT(Boolean.class, "uninviteFromEvent", String.class, "eventId", String.class, "userId"), + UPDATEEVENTPICTURE(Boolean.class, "updateEventPicture", String.class, "eventId", Media.class, "source"), + + // FamilyMethods + GETFAMILY(ResponseList.class, "getFamily"), + GETFAMILY_WITH_OPTIONS(ResponseList.class, "getFamily", Reading.class, FacebookConstants.READING_PPROPERTY), + GETFAMILY_WITH_ID(ResponseList.class, "getFamily", String.class, "userId"), + GETFAMILY_WITH_ID_OPTIONS(ResponseList.class, "getFamily", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + + // FavouriteMethods + GETBOOKS(ResponseList.class, "getBooks"), + GETBOOKS_WITH_OPTIONS(ResponseList.class, "getBooks", Reading.class, FacebookConstants.READING_PPROPERTY), + GETBOOKS_WITH_ID(ResponseList.class, "getBooks", String.class, "userId"), + GETBOOKS_WITH_ID_OPTIONS(ResponseList.class, "getBooks", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETGAMES(ResponseList.class, "getGames"), + GETGAMES_WITH_OPTIONS(ResponseList.class, "getGames", Reading.class, FacebookConstants.READING_PPROPERTY), + GETGAMES_WITH_ID(ResponseList.class, "getGames", String.class, "userId"), + GETGAMES_WITH_ID_OPTIONS(ResponseList.class, "getGames", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETINTERESTS(ResponseList.class, "getInterests"), + GETINTERESTS_WITH_OPTIONS(ResponseList.class, "getInterests", Reading.class, FacebookConstants.READING_PPROPERTY), + GETINTERESTS_WITH_ID(ResponseList.class, "getInterests", String.class, "userId"), + GETINTERESTS_WITH_ID_OPTIONS(ResponseList.class, "getInterests", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETMOVIES(ResponseList.class, "getMovies"), + GETMOVIES_WITH_OPTIONS(ResponseList.class, "getMovies", Reading.class, FacebookConstants.READING_PPROPERTY), + GETMOVIES_WITH_ID(ResponseList.class, "getMovies", String.class, "userId"), + GETMOVIES_WITH_ID_OPTIONS(ResponseList.class, "getMovies", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETMUSIC(ResponseList.class, "getMusic"), + GETMUSIC_WITH_OPTIONS(ResponseList.class, "getMusic", Reading.class, FacebookConstants.READING_PPROPERTY), + GETMUSIC_WITH_ID(ResponseList.class, "getMusic", String.class, "userId"), + GETMUSIC_WITH_ID_OPTIONS(ResponseList.class, "getMusic", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETTELEVISION(ResponseList.class, "getTelevision"), + GETTELEVISION_WITH_OPTIONS(ResponseList.class, "getTelevision", Reading.class, FacebookConstants.READING_PPROPERTY), + GETTELEVISION_WITH_ID(ResponseList.class, "getTelevision", String.class, "userId"), + GETTELEVISION_WITH_ID_OPTIONS(ResponseList.class, "getTelevision", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + + // FQLMethods + EXECUTEFQL(JSONArray.class, "executeFQL", String.class, "query"), + EXECUTEFQL_WITH_LOCALE(JSONArray.class, "executeFQL", String.class, "query", Locale.class, " locale"), + EXECUTEMULTIFQL(Map.class, "executeMultiFQL", Map.class, "queries"), + EXECUTEMULTIFQL_WITH_LOCALE(Map.class, "executeMultiFQL", Map.class, "queries", Locale.class, "locale"), + + // FriendMethods + ADDFRIENDLISTMEMBER(Boolean.class, "addFriendlistMember", String.class, "friendlistId", String.class, "userId"), + CREATEFRIENDLIST(String.class, "createFriendlist", String.class, "friendlistName"), + CREATEFRIENDLIST_WITH_ID(String.class, "createFriendlist", String.class, "userId", String.class, "friendlistName"), + DELETEFRIENDLIST(Boolean.class, "deleteFriendlist", String.class, "friendlistId"), + GETBELONGSFRIEND(ResponseList.class, "getBelongsFriend", String.class, "friendId"), + GETBELONGSFRIEND_WITH_OPTIONS(ResponseList.class, "getBelongsFriend", String.class, "friendId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETBELONGSFRIEND_WITH_ID(ResponseList.class, "getBelongsFriend", String.class, "userId", String.class, "friendId"), + GETBELONGSFRIEND_WITH_ID_OPTIONS(ResponseList.class, "getBelongsFriend", String.class, "userId", String.class, "friendId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETFRIENDLIST(Friendlist.class, "getFriendlist", String.class, "friendlistId"), + GETFRIENDLIST_WITH_OPTIONS(Friendlist.class, "getFriendlist", String.class, "friendlistId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETFRIENDLISTMEMBERS(ResponseList.class, "getFriendlistMembers", String.class, "friendlistId"), + GETFRIENDLISTS(ResponseList.class, "getFriendlists"), + GETFRIENDLISTS_WITH_OPTIONS(ResponseList.class, "getFriendlists", Reading.class, FacebookConstants.READING_PPROPERTY), + GETFRIENDLISTS_WITH_ID(ResponseList.class, "getFriendlists", String.class, "userId"), + GETFRIENDLISTS_WITH_ID_OPTIONS(ResponseList.class, "getFriendlists", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETFRIENDREQUESTS(ResponseList.class, "getFriendRequests"), + GETFRIENDREQUESTS_WITH_OPTIONS(ResponseList.class, "getFriendRequests", Reading.class, FacebookConstants.READING_PPROPERTY), + GETFRIENDREQUESTS_WITH_ID(ResponseList.class, "getFriendRequests", String.class, "userId"), + GETFRIENDREQUESTS_WITH_ID_OPTIONS(ResponseList.class, "getFriendRequests", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETFRIENDS(ResponseList.class, "getFriends"), + GETFRIENDS_WITH_OPTIONS(ResponseList.class, "getFriends", Reading.class, FacebookConstants.READING_PPROPERTY), + GETFRIENDS_WITH_ID(ResponseList.class, "getFriends", String.class, "userId"), + GETFRIENDS_WITH_ID_OPTIONS(ResponseList.class, "getFriends", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETMUTUALFRIENDS(ResponseList.class, "getMutualFriends", String.class, "friendUserId"), + GETMUTUALFRIENDS_WITH_OPTIONS(ResponseList.class, "getMutualFriends", String.class, "friendUserId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETMUTUALFRIENDS_WITH_ID(ResponseList.class, "getMutualFriends", String.class, "userId1", String.class, "userId2"), + GETMUTUALFRIENDS_WITH_ID_OPTIONS(ResponseList.class, "getMutualFriends", String.class, "userId1", String.class, "userId2", Reading.class, FacebookConstants.READING_PPROPERTY), + REMOVEFRIENDLISTMEMBER(Boolean.class, "removeFriendlistMember", String.class, "friendlistId", String.class, "userId"), + + // GameMethods + DELETEACHIEVEMENT(Boolean.class, "deleteAchievement", URL.class, "achievementURL"), + DELETEACHIEVEMENT_WITH_ID(Boolean.class, "deleteAchievement", String.class, "userId", URL.class , "achievementURL"), + DELETESCORE(Boolean.class, "deleteScore"), + DELETESCORE_WITH_ID(Boolean.class, "deleteScore", String.class, "userId"), + GETACHIEVEMENTS(ResponseList.class, "getAchievements"), + GETACHIEVEMENTS_WITH_OPTIONS(ResponseList.class, "getAchievements", Reading.class, FacebookConstants.READING_PPROPERTY), + GETACHIEVEMENTS_WITH_ID(ResponseList.class, "getAchievements", String.class, "userId"), + GETACHIEVEMENTS_WITH_ID_OPTIONS(ResponseList.class, "getAchievements", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETSCORES(ResponseList.class, "getScores"), + GETSCORES_WITH_OPTIONS(ResponseList.class, "getScores", Reading.class, FacebookConstants.READING_PPROPERTY), + GETSCORES_WITH_ID(ResponseList.class, "getScores", String.class, "userId"), + GETSCORES_WITH_ID_OPTIONS(ResponseList.class, "getScores", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + POSTACHIEVEMENT(String.class, "postAchievement", URL.class, "achievementURL"), + POSTACHIEVEMENT_WITH_ID(String.class, "postAchievement", String.class, "userId", URL.class, "achievementURL"), + POSTSCORE(Boolean.class, "postScore", int.class, "scoreValue"), + POSTSCORE_WITH_ID(Boolean.class, "postScore", String.class, "userId", int.class, "scoreValue"), + + // GroupMethods + GETGROUP(Group.class, "getGroup", String.class, "groupId"), + GETGROUP_WITH_OPTIONS(Group.class, "getGroup", String.class, "groupId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETGROUPDOCS(ResponseList.class, "getGroupDocs", String.class, "groupId"), + GETGROUPDOCS_WITH_OPTIONS(ResponseList.class, "getGroupDocs", String.class, "groupId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETGROUPFEED(ResponseList.class, "getGroupFeed", String.class, "groupId"), + GETGROUPFEED_WITH_OPTIONS(ResponseList.class, "getGroupFeed", String.class, "groupId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETGROUPMEMBERS(ResponseList.class, "getGroupMembers", String.class, "groupId"), + GETGROUPMEMBERS_WITH_OPTIONS(ResponseList.class, "getGroupMembers", String.class, "groupId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETGROUPPICTUREURL(URL.class, "getGroupPictureURL", String.class, "groupId"), + GETGROUPS(ResponseList.class, "getGroups"), + GETGROUPS_WITH_OPTIONS(ResponseList.class, "getGroups", Reading.class, FacebookConstants.READING_PPROPERTY), + GETGROUPS_WITH_ID(ResponseList.class, "getGroups", String.class, "userId"), + GETGROUPS_WITH_ID_OPTIONS(ResponseList.class, "getGroups", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + POSTGROUPFEED_WITH_POSTUPDATE(String.class, "postGroupFeed", String.class, "groupId", PostUpdate.class, "postUpdate"), + POSTGROUPLINK_WITH_LINK(String.class, "postGroupLink", String.class, "groupId", URL.class, "link"), + POSTGROUPLINK_WITH_LINK_MSG(String.class, "postGroupLink", String.class, "groupId", URL.class, "link", String.class, "message"), + POSTGROUPSTATUSMESSAGE(String.class, "postGroupStatusMessage", String.class, "groupId", String.class, "message"), + + // InsightMethods + GETINSIGHTS(ResponseList.class, "getInsights", String.class, "objectId", String.class, "metric"), + GETINSIGHTS_WITH_OPTIONS(ResponseList.class, "getInsights", String.class, "objectId", String.class, "metric", Reading.class, FacebookConstants.READING_PPROPERTY), + + // LikeMethods + GETUSERLIKES(ResponseList.class, "getUserLikes"), + GETUSERLIKES_WITH_OPTIONS(ResponseList.class, "getUserLikes", Reading.class, FacebookConstants.READING_PPROPERTY), + GETUSERLIKES_WITH_ID(ResponseList.class, "getUserLikes", String.class, "userId"), + GETUSERLIKES_WITH_ID_OPTIONS(ResponseList.class, "getUserLikes", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + + // LinkMethods + COMMENTLINK(String.class, "commentLink", String.class, "linkId", String.class, "message"), + GETLINK(Link.class, "getLink", String.class, "linkId"), + GETLINK_WITH_OPTIONS(Link.class, "getLink", String.class, "linkId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETLINKCOMMENTS(ResponseList.class, "getLinkComments", String.class, "linkId"), + GETLINKCOMMENTS_WITH_OPTIONS(ResponseList.class, "getLinkComments", String.class, "linkId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETLINKLIKES(ResponseList.class, "getLinkLikes", String.class, "linkId"), + GETLINKLIKES_WITH_OPTIONS(ResponseList.class, "getLinkLikes", String.class, "linkId", Reading.class, FacebookConstants.READING_PPROPERTY), + LIKELINK(Boolean.class, "likeLink", String.class, "linkId"), + UNLIKELINK(Boolean.class, "unlikeLink", String.class, "linkId"), + + // LocationMethods + GETLOCATIONS(ResponseList.class, "getLocations"), + GETLOCATIONS_WITH_OPTIONS(ResponseList.class, "getLocations", Reading.class, FacebookConstants.READING_PPROPERTY), + GETLOCATIONS_WITH_ID(ResponseList.class, "getLocations", String.class, "userId"), + GETLOCATIONS_WITH_ID_OPTIONS(ResponseList.class, "getLocations", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + + // MessageMethods + GETINBOX(InboxResponseList.class, "getInbox"), + GETINBOX_WITH_OPTIONS(InboxResponseList.class, "getInbox", Reading.class, FacebookConstants.READING_PPROPERTY), + GETINBOX_WITH_ID(InboxResponseList.class, "getInbox", String.class, "userId"), + GETINBOX_WITH_ID_OPTIONS(InboxResponseList.class, "getInbox", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETMESSAGE(Message.class, "getMessage", String.class, "messageId"), + GETMESSAGE_WITH_OPTIONS(Message.class, "getMessage", String.class, "messageId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETOUTBOX(ResponseList.class, "getOutbox"), + GETOUTBOX_WITH_OPTIONS(ResponseList.class, "getOutbox", Reading.class, FacebookConstants.READING_PPROPERTY), + GETOUTBOX_WITH_ID(ResponseList.class, "getOutbox", String.class, "userId"), + GETOUTBOX_WITH_ID_OPTIONS(ResponseList.class, "getOutbox", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETUPDATES(ResponseList.class, "getUpdates"), + GETUPDATES_WITH_OPTIONS(ResponseList.class, "getUpdates", Reading.class, FacebookConstants.READING_PPROPERTY), + GETUPDATES_WITH_ID(ResponseList.class, "getUpdates", String.class, "userId"), + GETUPDATES_WITH_ID_OPTIONS(ResponseList.class, "getUpdates", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + + // NoteMethods + COMMENTNOTE(String.class, "commentNote", String.class, "noteId", String.class, "message"), + CREATENOTE(String.class, "createNote", String.class, "subject", String.class, "message"), + CREATENOTE_WITH_ID_MSG(String.class, "createNote", String.class, "userId", String.class, "subject", String.class, "message"), + GETNOTE(Note.class, "getNote", String.class, "noteId"), + GETNOTE_WITH_OPTIONS(Note.class, "getNote", String.class, "noteId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETNOTECOMMENTS(ResponseList.class, "getNoteComments", String.class, "noteId"), + GETNOTECOMMENTS_WITH_OPTIONS(ResponseList.class, "getNoteComments", String.class, "noteId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETNOTELIKES(ResponseList.class, "getNoteLikes", String.class, "noteId"), + GETNOTELIKES_WITH_OPTIONS(ResponseList.class, "getNoteLikes", String.class, "noteId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETNOTES(ResponseList.class, "getNotes"), + GETNOTES_WITH_OPTIONS(ResponseList.class, "getNotes", Reading.class, FacebookConstants.READING_PPROPERTY), + GETNOTES_WITH_ID(ResponseList.class, "getNotes", String.class, "userId"), + GETNOTES_WITH_ID_OPTIONS(ResponseList.class, "getNotes", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + LIKENOTE(Boolean.class, "likeNote", String.class, "noteId"), + UNLIKENOTE(Boolean.class, "unlikeNote", String.class, "noteId"), + + // NotificationMethods + GETNOTIFICATIONS(ResponseList.class, "getNotifications"), + GETNOTIFICATIONS_WITH_INCLUDEREAD(ResponseList.class, "getNotifications", boolean.class, "includeRead"), + GETNOTIFICATIONS_WITH_OPTIONS(ResponseList.class, "getNotifications", Reading.class, FacebookConstants.READING_PPROPERTY), + GETNOTIFICATIONS_WITH_OPTIONS_INCLUDEREAD(ResponseList.class, "getNotifications", Reading.class, FacebookConstants.READING_PPROPERTY, boolean.class, "includeRead"), + GETNOTIFICATIONS_WITH_ID(ResponseList.class, "getNotifications", String.class, "userId"), + GETNOTIFICATIONS_WITH_ID_INCLUDEREAD(ResponseList.class, "getNotifications", String.class, "userId", boolean.class, "includeRead"), + GETNOTIFICATIONS_WITH_ID_OPTIONS(ResponseList.class, "getNotifications", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETNOTIFICATIONS_WITH_ID_OPTIONS_INCLUDEREAD(ResponseList.class, "getNotifications", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY, boolean.class, "includeRead"), + MARKNOTIFICATIONASREAD(Boolean.class, "markNotificationAsRead", String.class, "notificationId"), + + // PermissionMethods + GETPERMISSIONS(List.class, "getPermissions"), + GETPERMISSIONS_WITH_ID(List.class, "getPermissions", String.class, "userId"), + REVOKEPERMISSION(Boolean.class, "revokePermission", String.class, "permissionName"), + REVOKEPERMISSION_WITH_ID(Boolean.class, "revokePermission", String.class, "userId", String.class, "permissionName"), + + // PhotoMethods + ADDTAGTOPHOTO(Boolean.class, "addTagToPhoto", String.class, "photoId", String.class, "toUserId"), + ADDTAGTOPHOTO_WITH_IDS(Boolean.class, "addTagToPhoto", String.class, "photoId", List.class, "toUserIds"), + ADDTAGTOPHOTO_WITH_TAGUPDATE(Boolean.class, "addTagToPhoto", String.class, "photoId", TagUpdate.class, "tagUpdate"), + COMMENTPHOTO(String.class, "commentPhoto", String.class, "photoId", String.class, "message"), + DELETEPHOTO(Boolean.class, "deletePhoto", String.class, "photoId"), + GETPHOTO(Photo.class, "getPhoto", String.class, "photoId"), + GETPHOTO_WITH_OPTIONS(Photo.class, "getPhoto", String.class, "photoId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETPHOTOCOMMENTS(ResponseList.class, "getPhotoComments", String.class, "photoId"), + GETPHOTOCOMMENTS_WITH_OPTIONS(ResponseList.class, "getPhotoComments", String.class, "photoId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETPHOTOLIKES(ResponseList.class, "getPhotoLikes", String.class, "photoId"), + GETPHOTOLIKES_WITH_OPTIONS(ResponseList.class, "getPhotoLikes", String.class, "photoId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETPHOTOS(ResponseList.class, "getPhotos"), + GETPHOTOS_WITH_OPTIONS(ResponseList.class, "getPhotos", Reading.class, FacebookConstants.READING_PPROPERTY), + GETPHOTOS_WITH_ID(ResponseList.class, "getPhotos", String.class, "userId"), + GETPHOTOS_WITH_ID_OPTIONS(ResponseList.class, "getPhotos", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETPHOTOURL(URL.class, "getPhotoURL", String.class, "photoId"), + GETTAGSONPHOTO(ResponseList.class, "getTagsOnPhoto", String.class, "photoId"), + GETTAGSONPHOTO_WITH_OPTIONS(ResponseList.class, "getTagsOnPhoto", String.class, "photoId", Reading.class, FacebookConstants.READING_PPROPERTY), + LIKEPHOTO(Boolean.class, "likePhoto", String.class, "photoId"), + POSTPHOTO(String.class, "postPhoto", Media.class, "source"), + POSTPHOTO_WITH_MSG(String.class, "postPhoto", Media.class, "source", String.class, "message", String.class, "place", boolean.class, "noStory"), + POSTPHOTO_WITH_MEDIA(String.class, "postPhoto", String.class, "userId", Media.class, "source"), + POSTPHOTO_WITH_MEDIA_MSG(String.class, "postPhoto", String.class, "userId", Media.class, "source", String.class, "message", String.class, "place", boolean.class, "noStory"), + UNLIKEPHOTO(Boolean.class, "unlikePhoto", String.class, "photoId"), + UPDATETAGONPHOTO(Boolean.class, "updateTagOnPhoto", String.class, "photoId", String.class, "toUserId"), + UPDATETAGONPHOTO_WITH_TAGUPDATE(Boolean.class, "updateTagOnPhoto", String.class, "photoId", TagUpdate.class, "tagUpdate"), + + // PokeMethods + GETPOKES(ResponseList.class, "getPokes"), + GETPOKES_WITH_OPTIONS(ResponseList.class, "getPokes", Reading.class, FacebookConstants.READING_PPROPERTY), + GETPOKES_WITH_ID(ResponseList.class, "getPokes", String.class, "userId"), + GETPOKES_WITH_ID_OPTIONS(ResponseList.class, "getPokes", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + + // PostMethods + COMMENTPOST(String.class, "commentPost", String.class, "postId", String.class, "message"), + DELETEPOST(Boolean.class, "deletePost", String.class, "postId"), + GETFEED(ResponseList.class, "getFeed"), + GETFEED_WITH_OPTIONS(ResponseList.class, "getFeed", Reading.class, FacebookConstants.READING_PPROPERTY), + GETFEED_WITH_ID(ResponseList.class, "getFeed", String.class, "userId"), + GETFEED_WITH_ID_OPTIONS(ResponseList.class, "getFeed", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETHOME(ResponseList.class, "getHome"), + GETHOME_WITH_OPTIONS(ResponseList.class, "getHome", Reading.class, FacebookConstants.READING_PPROPERTY), + GETLINKS(ResponseList.class, "getLinks"), + GETLINKS_WITH_OPTIONS(ResponseList.class, "getLinks", Reading.class, FacebookConstants.READING_PPROPERTY), + GETLINKS_WITH_ID(ResponseList.class, "getLinks", String.class, "userId"), + GETLINKS_WITH_ID_OPTIONS(ResponseList.class, "getLinks", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETPOST(Post.class, "getPost", String.class, "postId"), + GETPOST_WITH_OPTIONS(Post.class, "getPost", String.class, "postId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETPOSTCOMMENTS(ResponseList.class, "getPostComments", String.class, "postId"), + GETPOSTCOMMENTS_WITH_OPTIONS(ResponseList.class, "getPostComments", String.class, "postId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETPOSTLIKES(ResponseList.class, "getPostLikes", String.class, "postId"), + GETPOSTLIKES_WITH_OPTIONS(ResponseList.class, "getPostLikes", String.class, "postId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETPOSTS(ResponseList.class, "getPosts"), + GETPOSTS_WITH_OPTIONS(ResponseList.class, "getPosts", Reading.class, FacebookConstants.READING_PPROPERTY), + GETPOSTS_WITH_ID(ResponseList.class, "getPosts", String.class, "userId"), + GETPOSTS_WITH_ID_OPTIONS(ResponseList.class, "getPosts", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETSTATUSES(ResponseList.class, "getStatuses"), + GETSTATUSES_WITH_OPTIONS(ResponseList.class, "getStatuses", Reading.class, FacebookConstants.READING_PPROPERTY), + GETSTATUSES_WITH_ID(ResponseList.class, "getStatuses", String.class, "userId"), + GETSTATUSES_WITH_ID_OPTIONS(ResponseList.class, "getStatuses", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETTAGGED(ResponseList.class, "getTagged"), + GETTAGGED_WITH_OPTIONS(ResponseList.class, "getTagged", Reading.class, FacebookConstants.READING_PPROPERTY), + GETTAGGED_WITH_ID(ResponseList.class, "getTagged", String.class, "userId"), + GETTAGGED_WITH_ID_OPTIONS(ResponseList.class, "getTagged", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + LIKEPOST(Boolean.class, "likePost", String.class, "postId"), + POSTFEED(String.class, "postFeed", PostUpdate.class, "postUpdate"), + POSTFEED_WITH_POSTUPDATE(String.class, "postFeed", String.class, "userId", PostUpdate.class, "postUpdate"), + POSTLINK(String.class, "postLink", URL.class, "link"), + POSTLINK_WITH_MSG(String.class, "postLink", URL.class, "link", String.class, "message"), + POSTLINK_WITH_ID(String.class, "postLink", String.class, "userId", URL.class, "link"), + POSTLINK_WITH_ID_MSG(String.class, "postLink", String.class, "userId", URL.class, "link", String.class, "message"), + POSTSTATUSMESSAGE(String.class, "postStatusMessage", String.class, "message"), + POSTSTATUSMESSAGE_WITH_ID(String.class, "postStatusMessage", String.class, "userId", String.class, "message"), + UNLIKEPOST(Boolean.class, "unlikePost", String.class, "postId"), + + // QuestionMethods + ADDQUESTIONOPTION(String.class, "addQuestionOption", String.class, "questionId", String.class, "optionDescription"), + CREATEQUESTION(String.class, "createQuestion", String.class, "question"), + CREATEQUESTION_WITH_OPTIONS(String.class, "createQuestion", String.class, "question", List.class, "options", boolean.class, "allowNewOptions"), + CREATEQUESTION_WITH_ID(String.class, "createQuestion", String.class, "userId", String.class, "question"), + CREATEQUESTION_WITH_ID_OPTIONS(String.class, "createQuestion", String.class, "userId", String.class, "question", List.class, "options", boolean.class, "allowNewOptions"), + DELETEQUESTION(Boolean.class, "deleteQuestion", String.class, "questionId"), + GETQUESTION(Question.class, "getQuestion", String.class, "questionId"), + GETQUESTION_WITH_OPTIONS(Question.class, "getQuestion", String.class, "questionId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETQUESTIONOPTIONS(ResponseList.class, "getQuestionOptions", String.class, "questionId"), + GETQUESTIONOPTIONS_WITH_OPTIONS(ResponseList.class, "getQuestionOptions", String.class, "questionId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETQUESTIONOPTIONVOTES(ResponseList.class, "getQuestionOptionVotes", String.class, "questionId"), + GETQUESTIONS(ResponseList.class, "getQuestions"), + GETQUESTIONS_WITH_OPTIONS(ResponseList.class, "getQuestions", Reading.class, FacebookConstants.READING_PPROPERTY), + GETQUESTIONS_WITH_ID(ResponseList.class, "getQuestions", String.class, "userId"), + GETQUESTIONS_WITH_ID_OPTIONS(ResponseList.class, "getQuestions", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + + // SubscribeMethods + GETSUBSCRIBEDTO(ResponseList.class, "getSubscribedto"), + GETSUBSCRIBEDTO_WITH_OPTIONS(ResponseList.class, "getSubscribedto", Reading.class, FacebookConstants.READING_PPROPERTY), + GETSUBSCRIBEDTO_WITH_ID(ResponseList.class, "getSubscribedto", String.class, "userId"), + GETSUBSCRIBEDTO_WITH_ID_OPTIONS(ResponseList.class, "getSubscribedto", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETSUBSCRIBERS(ResponseList.class, "getSubscribers"), + GETSUBSCRIBERS_WITH_OPTIONS(ResponseList.class, "getSubscribers", Reading.class, FacebookConstants.READING_PPROPERTY), + GETSUBSCRIBERS_WITH_ID(ResponseList.class, "getSubscribers", String.class, "userId"), + GETSUBSCRIBERS_WITH_ID_OPTIONS(ResponseList.class, "getSubscribers", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + + // TestUserMethods + CREATETESTUSER(TestUser.class, "createTestUser", String.class, "appId"), + CREATETESTUSER_WITH_NAME(TestUser.class, "createTestUser", String.class, "appId", String.class, "name", String.class, "userLocale", String.class, "permissions"), + DELETETESTUSER(Boolean.class, "deleteTestUser", String.class, "testUserId"), + GETTESTUSERS(List.class, "getTestUsers", String.class, "appId"), + MAKEFRIENDTESTUSER(Boolean.class, "makeFriendTestUser", TestUser.class, "testUser1", TestUser.class, "testUser2"), + + // UserMethods + GETME(User.class, "getMe"), + GETME_WITH_OPTIONS(User.class, "getMe", Reading.class, FacebookConstants.READING_PPROPERTY), + GETPICTUREURL(URL.class, "getPictureURL"), + GETPICTUREURL_WITH_PICTURESIZE(URL.class, "getPictureURL", PictureSize.class, "size"), + GETPICTUREURL_WITH_ID(URL.class, "getPictureURL", String.class, "userId"), + GETPICTUREURL_WITH_ID_PICTURESIZE(URL.class, "getPictureURL", String.class, "userId", PictureSize.class, "size"), + GETUSER(User.class, "getUser", String.class, "userId"), + GETUSER_WITH_OPTIONS(User.class, "getUser", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETUSERS(List.class, "getUsers", new String[0].getClass(), "ids"), + + // VideoMethods + COMMENTVIDEO(String.class, "commentVideo", String.class, "videoId", String.class, "message"), + GETVIDEO(Video.class, "getVideo", String.class, "videoId"), + GETVIDEO_WITH_OPTIONS(Video.class, "getVideo", String.class, "videoId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETVIDEOCOMMENTS(ResponseList.class, "getVideoComments", String.class, "videoId"), + GETVIDEOCOMMENTS_WITH_OPTIONS(ResponseList.class, "getVideoComments", String.class, "videoId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETVIDEOCOVER(URL.class, "getVideoCover", String.class, "videoId"), + GETVIDEOLIKES(ResponseList.class, "getVideoLikes", String.class, "videoId"), + GETVIDEOLIKES_WITH_OPTIONS(ResponseList.class, "getVideoLikes", String.class, "videoId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETVIDEOS(ResponseList.class, "getVideos"), + GETVIDEOS_WITH_OPTIONS(ResponseList.class, "getVideos", Reading.class, FacebookConstants.READING_PPROPERTY), + GETVIDEOS_WITH_ID(ResponseList.class, "getVideos", String.class, "userId"), + GETVIDEOS_WITH_ID_OPTIONS(ResponseList.class, "getVideos", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + LIKEVIDEO(Boolean.class, "likeVideo", String.class, "videoId"), + POSTVIDEO(String.class, "postVideo", Media.class, "source"), + POSTVIDEO_WITH_TITLE(String.class, "postVideo", Media.class, "source", String.class, "title", String.class, "description"), + POSTVIDEO_WITH_ID(String.class, "postVideo", String.class, "userId", Media.class, "source"), + POSTVIDEO_WITH_ID_MEDIA(String.class, "postVideo", String.class, "userId", Media.class, "source", String.class, "title", String.class, "description"), + UNLIKEVIDEO(Boolean.class, "unlikeVideo", String.class, "videoId"), + + // SearchMethods get the highest priority with higher ordinal values + SEARCH(ResponseList.class, "search", String.class, "query"), + SEARCH_WITH_OPTIONS(ResponseList.class, "search", String.class, "query", Reading.class, FacebookConstants.READING_PPROPERTY), + SEARCHCHECKINS(ResponseList.class, "searchCheckins"), + SEARCHCHECKINS_WITH_OPTIONS(ResponseList.class, "searchCheckins", Reading.class, FacebookConstants.READING_PPROPERTY), + SEARCHEVENTS(ResponseList.class, "searchEvents", String.class, "query"), + SEARCHEVENTS_WITH_OPTIONS(ResponseList.class, "searchEvents", String.class, "query", Reading.class, FacebookConstants.READING_PPROPERTY), + SEARCHGROUPS(ResponseList.class, "searchGroups", String.class, "query"), + SEARCHGROUPS_WITH_OPTIONS(ResponseList.class, "searchGroups", String.class, "query", Reading.class, FacebookConstants.READING_PPROPERTY), + SEARCHLOCATIONS(ResponseList.class, "searchLocations", GeoLocation.class, "center", int.class, "distance"), + SEARCHLOCATIONS_WITH_OPTIONS(ResponseList.class, "searchLocations", GeoLocation.class, "center", int.class, "distance", Reading.class, FacebookConstants.READING_PPROPERTY), + SEARCHLOCATIONS_WITH_ID(ResponseList.class, "searchLocations", String.class, "placeId"), + SEARCHLOCATIONS_WITH_ID_OPTIONS(ResponseList.class, "searchLocations", String.class, "placeId", Reading.class, FacebookConstants.READING_PPROPERTY), + SEARCHPLACES(ResponseList.class, "searchPlaces", String.class, "query"), + SEARCHPLACES_WITH_OPTIONS(ResponseList.class, "searchPlaces", String.class, "query", Reading.class, FacebookConstants.READING_PPROPERTY), + SEARCHPLACES_WITH_CENTER(ResponseList.class, "searchPlaces", String.class, "query", GeoLocation.class, "center", int.class, "distance"), + SEARCHPLACES_WITH_CENTER_OPTIONS(ResponseList.class, "searchPlaces", String.class, "query", GeoLocation.class, "center", int.class, "distance", Reading.class, FacebookConstants.READING_PPROPERTY), + SEARCHPOSTS(ResponseList.class, "searchPosts", String.class, "query"), + SEARCHPOSTS_WITH_OPTIONS(ResponseList.class, "searchPosts", String.class, "query", Reading.class, FacebookConstants.READING_PPROPERTY), + SEARCHUSERS(ResponseList.class, "searchUsers", String.class, "query"), + SEARCHUSERS_WITH_OPTIONS(ResponseList.class, "searchUsers", String.class, "query", Reading.class, FacebookConstants.READING_PPROPERTY); + + // name, result class, ordered argument names and classes, and Method to invoke + private final String name; + private final Class resultType; + private final List argNames; + private final List argTypes; + private final Method method; + + private FacebookMethodsType(Class resultType, String name, Object... args) throws IllegalArgumentException { + this.name = name; + this.resultType = resultType; + + if (args.length % 2 != 0) { + throw new IllegalArgumentException("Invalid parameter list, " + + "must be of the form 'Class arg1, String arg1Name, Class arg2, String arg2Name..."); + } + int nArgs = args.length / 2; + this.argNames = new ArrayList(nArgs); + this.argTypes = new ArrayList(nArgs); + for (int i = 0; i < nArgs; i++) { + this.argTypes.add((Class) args[i * 2]); + this.argNames.add((String) args[i * 2 + 1]); + } + + // find method in Facebook type + try { + this.method = Facebook.class.getMethod(name, argTypes.toArray(new Class[nArgs])); + } catch (NoSuchMethodException e) { + throw new IllegalArgumentException( + String.format("Missing method %s %s", name, argTypes.toString().replace('[', '(').replace(']', ')')), + e); + } + } + + /** + * Find method type by name and argument types. + * @param name method name + * @param args ordered argument types + * @return matching method, null if not found + */ + public static FacebookMethodsType findMethod(String name, Class... args) { + for (FacebookMethodsType method : values()) { + if (method.name.equals(name)) { + if ((method.argTypes.isEmpty() && (args == null || args.length == 0)) + || Arrays.equals(method.argTypes.toArray(), args)) { + return method; + } + } + } + + return null; + } + + public String getName() { + return name; + } + + public Class getResultType() { + return resultType; + } + + public List getArgNames() { + return Collections.unmodifiableList(argNames); + } + + public List getArgTypes() { + return Collections.unmodifiableList(argTypes); + } + + public Method getMethod() { + return method; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("{") + .append("name=").append(name) + .append(", resultType=").append(resultType) + .append(", argNames=").append(argNames) + .append(", argTypes=").append(argTypes) + .append("}"); + return builder.toString(); + } + +} diff --git a/components/camel-facebook/src/main/java/org/apache/camel/facebook/data/FacebookMethodsTypeHelper.java b/components/camel-facebook/src/main/java/org/apache/camel/facebook/data/FacebookMethodsTypeHelper.java new file mode 100644 index 0000000000000..ce7e60c94cd81 --- /dev/null +++ b/components/camel-facebook/src/main/java/org/apache/camel/facebook/data/FacebookMethodsTypeHelper.java @@ -0,0 +1,350 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.facebook.data; + +import java.lang.reflect.Array; +import java.lang.reflect.InvocationTargetException; +import java.util.*; + +import facebook4j.Facebook; +import org.apache.camel.facebook.FacebookConstants; +import org.apache.camel.facebook.config.FacebookNameStyle; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Helper class for working with {@link FacebookMethodsType}. + */ +public final class FacebookMethodsTypeHelper { + + private static final Logger LOG = LoggerFactory.getLogger(FacebookMethodsTypeHelper.class); + + // maps method name to FacebookMethodsType + private static final Map> METHOD_MAP = + new HashMap>(); + + // maps method name to method arguments of the form Class type1, String name1, Class type2, String name2,... + private static final Map> ARGUMENTS_MAP = + new HashMap>(); + + // maps argument name to argument type + private static final Map VALID_ARGUMENTS = + new HashMap(); + + static { + final FacebookMethodsType[] methods = FacebookMethodsType.values(); + // load lookup maps for FacebookMethodsType + for (FacebookMethodsType method : methods) { + + // map method name to Enum + final String name = method.getName(); + List overloads = METHOD_MAP.get(name); + if (overloads == null) { + overloads = new ArrayList(); + METHOD_MAP.put(method.getName(), overloads); + } + overloads.add(method); + + // add arguments for this method + List arguments = ARGUMENTS_MAP.get(name); + if (arguments == null) { + arguments = new ArrayList(); + ARGUMENTS_MAP.put(name, arguments); + } + + // process all arguments for this method + final int nArgs = method.getArgNames().size(); + final String[] argNames = method.getArgNames().toArray(new String[nArgs]); + final Class[] argTypes = method.getArgTypes().toArray(new Class[nArgs]); + for (int i = 0; i < nArgs; i++) { + final String argName = argNames[i]; + final Class argType = argTypes[i]; + if (!arguments.contains(argName)) { + arguments.add(argType); + arguments.add(argName); + } + + // also collect argument names for all methods, also detect clashes here + final Class previousType = VALID_ARGUMENTS.get(argName); + if (previousType != null && previousType != argType) { + throw new ExceptionInInitializerError(String.format( + "Argument %s has ambiguous types (%s, %s) across methods!", + name, previousType, argType)); + } else if (previousType == null) { + VALID_ARGUMENTS.put(argName, argType); + } + } + + } + + // add endpoint parameter inBody for producers + VALID_ARGUMENTS.put(FacebookConstants.IN_BODY_PROPERTY, String.class); + + LOG.debug("Found {} unique method names in {} methods", METHOD_MAP.size(), methods.length); + + } + + private FacebookMethodsTypeHelper() { + } + + /** + * Gets methods that match the given name and arguments.

+ * Note that the args list is a required subset of arguments for returned methods. + * @param name case sensitive full method name to lookup + * @param argNames unordered required argument names + * @return non-null unmodifiable list of methods that take all of the given arguments, empty if there is no match + */ + public static List getCandidateMethods(String name, String... argNames) { + final List methods = METHOD_MAP.get(name); + if (methods == null) { + LOG.debug("No matching method for method {}", name); + return Collections.emptyList(); + } + int nArgs = argNames != null ? argNames.length : 0; + if (nArgs == 0) { + LOG.debug("Found {} methods for method {}", methods.size(), name); + return Collections.unmodifiableList(methods); + } else { + final List filteredSet = filterMethods(methods, MatchType.SUBSET, argNames); + if (LOG.isDebugEnabled()) { + LOG.debug("Found {} filtered methods for {}", + filteredSet.size(), name + Arrays.toString(argNames).replace('[', '(').replace(']', ')')); + } + return filteredSet; + } + } + + /** + * Filters a list of methods to those that take the given set of arguments. + * + * @param methods list of methods to filter + * @param matchType whether the arguments are an exact match, a subset or a super set of method args + * @param argNames argument names to filter the list + * @return methods with arguments that satisfy the match type.

+ * For SUPER_SET match, if methods with exact match are found, methods that take a subset are ignored + */ + public static List filterMethods(List methods, MatchType matchType, + String... argNames) { + List argsList = Arrays.asList(argNames); + // list of methods that have all args in the given names + final List result = new ArrayList(); + final List extraArgs = new ArrayList(); + + for (FacebookMethodsType method : methods) { + final List methodArgs = method.getArgNames(); + switch (matchType) { + case EXACT: + // method must take all args, and no more + if (methodArgs.containsAll(argsList) && argsList.containsAll(methodArgs)) { + result.add(method); + } + break; + case SUBSET: + // all args are required, method may take more + if (methodArgs.containsAll(argsList)) { + result.add(method); + } + break; + case SUPER_SET: + // all method args must be present + if (argsList.containsAll(methodArgs)) { + if (methodArgs.containsAll(argsList)) { + // prefer exact match to avoid unused args + result.add(method); + } else { + // method takes a subset, unused args + extraArgs.add(method); + } + } + break; + } + } + + return Collections.unmodifiableList(result.isEmpty() ? extraArgs : result); + } + + /** + * Gets argument types and names for all overloaded methods with the given name. + * @param name method name, must be a long form (i.e. get*, or search*) + * @return list of arguments of the form Class type1, String name1, Class type2, String name2,... + */ + public static List getArguments(String name) throws IllegalArgumentException { + final List arguments = ARGUMENTS_MAP.get(name); + if (arguments == null) { + throw new IllegalArgumentException(name); + } + return Collections.unmodifiableList(arguments); + } + + /** + * Gets argument types and names for all overloaded methods with the given short form name. + * @param name method name, may be a short form + * @param style name style + * @return list of arguments of the form Class type1, String name1, Class type2, String name2,... + */ + public static List getArgumentsForNameStyle(String name, FacebookNameStyle style) throws IllegalArgumentException { + if (style == null) { + throw new IllegalArgumentException("Parameters style cannot be null"); + } + switch (style) { + case EXACT: + return getArguments(name); + case GET: + return getArguments(convertToGetMethod(name)); + case SEARCH: + return getArguments(convertToSearchMethod(name)); + case GET_AND_SEARCH: + default: + final List arguments = new ArrayList(); + arguments.addAll(getArguments(convertToGetMethod(name))); + arguments.addAll(getArguments(convertToSearchMethod(name))); + return Collections.unmodifiableList(arguments); + } + } + + /** + * Get missing properties. + * @param methodName method name + * @param nameStyle method name style + * @param argNames available arguments + * @return Set of missing argument names + */ + public static Set getMissingProperties(String methodName, FacebookNameStyle nameStyle, Set argNames) { + final List argsWithTypes = getArgumentsForNameStyle(methodName, nameStyle); + final Set missingArgs = new HashSet(); + + for (int i = 1; i < argsWithTypes.size(); i += 2) { + final String name = (String) argsWithTypes.get(i); + if (!argNames.contains(name)) { + missingArgs.add(name); + } + } + + return missingArgs; + } + + /** + * Get argument types and names used by all methods. + * @return map with argument names as keys, and types as values + */ + public static Map allArguments() { + return Collections.unmodifiableMap(VALID_ARGUMENTS); + } + + /** + * Get the type for the given argument name. + * @param argName argument name + * @return argument type + */ + public static Class getType(String argName) throws IllegalArgumentException { + final Class type = VALID_ARGUMENTS.get(argName); + if (type == null) { + throw new IllegalArgumentException(argName); + } + return type; + } + + public static String convertToGetMethod(String name) throws IllegalArgumentException { + if (name == null || name.isEmpty()) { + throw new IllegalArgumentException("Name cannot be null or empty"); + } + return "get" + Character.toUpperCase(name.charAt(0)) + name.substring(1); + } + + public static String convertToSearchMethod(String name) throws IllegalArgumentException { + if (name == null || name.isEmpty()) { + throw new IllegalArgumentException("Name cannot be null or empty"); + } + return "search" + Character.toUpperCase(name.charAt(0)) + name.substring(1); + } + + public static FacebookMethodsType getHighestPriorityMethod(List filteredMethods) { + FacebookMethodsType highest = null; + for (FacebookMethodsType method : filteredMethods) { + if (highest == null || method.ordinal() > highest.ordinal()) { + highest = method; + } + } + return highest; + } + + /** + * Invokes given method with argument values from given properties. + * + * @param facebook Facebook4J target object for invoke + * @param method method to invoke + * @param properties Map of arguments + * @return result of method invocation + * @throws InvocationTargetException, IllegalAccessException on invocation errors + */ + public static Object invokeMethod( + Facebook facebook, FacebookMethodsType method, Map properties) + throws InvocationTargetException, IllegalAccessException { + + LOG.debug("Invoking {} with arguments {}", method.getName(), properties); + + final List argNames = method.getArgNames(); + final Object[] values = new Object[argNames.size()]; + final List argTypes = method.getArgTypes(); + final Class[] types = argTypes.toArray(new Class[argTypes.size()]); + int index = 0; + for (String name : argNames) { + Object value = properties.get(name); + + // is the parameter an array type? + if (value != null && types[index].isArray()) { + Class type = types[index]; + + if (value instanceof Collection) { + // convert collection to array + Collection collection = (Collection) value; + Object array = Array.newInstance(type.getComponentType(), collection.size()); + if (array instanceof Object[]) { + collection.toArray((Object[]) array); + } else { + int i = 0; + for (Object el : collection) { + Array.set(array, i++, el); + } + } + value = array; + } else if (value.getClass().isArray() && + type.getComponentType().isAssignableFrom(value.getClass().getComponentType())) { + // convert derived array to super array + final int size = Array.getLength(value); + Object array = Array.newInstance(type.getComponentType(), size); + for (int i = 0; i < size; i++) { + Array.set(array, i, Array.get(value, i)); + } + value = array; + } else { + throw new IllegalArgumentException( + String.format("Cannot convert %s to %s", value.getClass(), type)); + } + } + + values[index++] = value; + } + + return method.getMethod().invoke(facebook, values); + } + + public static enum MatchType { + EXACT, SUBSET, SUPER_SET; + } + +} diff --git a/components/camel-facebook/src/main/java/org/apache/camel/facebook/data/FacebookPropertiesHelper.java b/components/camel-facebook/src/main/java/org/apache/camel/facebook/data/FacebookPropertiesHelper.java new file mode 100644 index 0000000000000..21ede54470a21 --- /dev/null +++ b/components/camel-facebook/src/main/java/org/apache/camel/facebook/data/FacebookPropertiesHelper.java @@ -0,0 +1,116 @@ +package org.apache.camel.facebook.data; + +import java.lang.reflect.Field; +import java.util.*; +import org.apache.camel.Exchange; +import org.apache.camel.facebook.FacebookConstants; +import org.apache.camel.facebook.config.FacebookConfiguration; +import org.apache.camel.facebook.config.FacebookEndpointConfiguration; +import org.apache.camel.util.IntrospectionSupport; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import facebook4j.Reading; + +/** + * Helper class to work with Facebook component properties. + */ +public final class FacebookPropertiesHelper { + + // set of field names which are specific to Facebook4J api, to be excluded from method argument considerations + private static final Set COMPONENT_CONFIG_FIELDS = new HashSet(); + + private static final Logger LOG = LoggerFactory.getLogger(FacebookPropertiesHelper.class); + + private static final Set ENDPOINT_CONFIG_FIELDS = new HashSet(); + + static { + for (Field field : FacebookConfiguration.class.getDeclaredFields()) { + COMPONENT_CONFIG_FIELDS.add(field.getName()); + } + for (Field field : FacebookEndpointConfiguration.class.getDeclaredFields()) { + ENDPOINT_CONFIG_FIELDS.add(field.getName()); + } + } + + private FacebookPropertiesHelper() { + // utility + } + + /** + * Apply properties for {@link Reading} type to the supplied {@link FacebookEndpointConfiguration}. + * @param configuration endpoint configuration to update + * @param options properties to apply to the reading field in configuration + */ + public static void configureReadingProperties(FacebookEndpointConfiguration configuration, + Map options) { + final Map readingProperties = IntrospectionSupport.extractProperties( + options, FacebookConstants.READING_PREFIX); + 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, + readingProperties); + + // update reading in configuration + configuration.setReading(reading); + + } catch (Exception e) { + throw new IllegalArgumentException(readingProperties.toString(), e); + } + + // add any unknown properties back to options to throw an error later + for (Map.Entry entry : readingProperties.entrySet()) { + options.put(FacebookConstants.READING_PREFIX + entry.getKey(), entry.getValue()); + } + } + } + + /** + * Gets exchange header properties that start with {@link FacebookConstants}.FACEBOOK_PROPERTY_PREFIX. + * + * @param exchange Camel exchange + * @param properties map to collect properties with required prefix + */ + public static Map getExchangeProperties(Exchange exchange, Map properties) { + int nProperties = 0; + for (Map.Entry entry : exchange.getIn().getHeaders().entrySet()) { + if (entry.getKey().startsWith(FacebookConstants.FACEBOOK_PROPERTY_PREFIX)) { + properties.put(entry.getKey().substring(FacebookConstants.FACEBOOK_PROPERTY_PREFIX.length()), + entry.getValue()); + nProperties++; + } + } + LOG.debug("Found {} properties in exchange", nProperties); + return properties; + } + + public static void getEndpointProperties(FacebookEndpointConfiguration configuration, + Map properties) { + if (IntrospectionSupport.getProperties(configuration, properties, null, false)) { + final Set names = properties.keySet(); + // remove component config properties so we only have endpoint properties + names.removeAll(COMPONENT_CONFIG_FIELDS); + } + if (LOG.isDebugEnabled()) { + final Set names = properties.keySet(); + LOG.debug("Found endpoint properties {}", names.retainAll(ENDPOINT_CONFIG_FIELDS)); + } + } + + public static Set getEndpointPropertyNames(FacebookEndpointConfiguration configuration) { + Map properties = new HashMap(); + getEndpointProperties(configuration, properties); + return Collections.unmodifiableSet(properties.keySet()); + } + +} diff --git a/components/camel-facebook/src/main/java/org/apache/camel/facebook/data/ReadingBuilder.java b/components/camel-facebook/src/main/java/org/apache/camel/facebook/data/ReadingBuilder.java new file mode 100644 index 0000000000000..436b95260c820 --- /dev/null +++ b/components/camel-facebook/src/main/java/org/apache/camel/facebook/data/ReadingBuilder.java @@ -0,0 +1,105 @@ +package org.apache.camel.facebook.data; + +import java.lang.reflect.Field; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.LinkedHashMap; +import java.util.Locale; +import java.util.Map; +import org.apache.camel.facebook.FacebookConstants; + +import facebook4j.Reading; + +/** + * Builds {@link facebook4j.Reading} instances. + */ +public class ReadingBuilder { + + + public static Reading copy(Reading reading, boolean skipSinceUtil) throws NoSuchFieldException, IllegalAccessException { + // use private field access to make a copy + Field field = Reading.class.getDeclaredField("parameterMap"); + field.setAccessible(true); + final LinkedHashMap source = (LinkedHashMap) field.get(reading); + // create another reading, and add all fields from source + Reading copy = new Reading(); + final LinkedHashMap copyMap = new LinkedHashMap(); + copyMap.putAll(source); + if (skipSinceUtil) { + copyMap.remove("since"); + copyMap.remove("until"); + } + field.set(copy, copyMap); + field.setAccessible(false); + return copy; + } + + /** + * Sets Reading properties. + * @param reading Reading object to populate + * @param readingProperties Map to extract properties + */ + public static void setProperties(Reading reading, Map readingProperties) { + + final String fields = (String) readingProperties.remove("fields"); + if (fields != null) { + reading.fields(fields.toString().split(",")); + } + final Object limit = readingProperties.remove("limit"); + if (limit != null) { + reading.limit(Integer.parseInt(limit.toString())); + } + final Object offset = readingProperties.remove("offset"); + if (offset != null) { + reading.offset(Integer.parseInt(offset.toString())); + } + final SimpleDateFormat dateFormat = new SimpleDateFormat(FacebookConstants.FACEBOOK_DATE_FORMAT); + final Object until = readingProperties.remove("until"); + if (until != null) { + try { + reading.until(dateFormat.parse(until.toString())); + } catch (ParseException e) { + throw new RuntimeException("Error parsing property 'until' :" + e.getMessage(), e); + } + } + final Object since = readingProperties.remove("since"); + if (since != null) { + try { + reading.since(dateFormat.parse(since.toString())); + } catch (ParseException e) { + throw new RuntimeException("Error parsing property 'since' :" + e.getMessage(), e); + } + } + final Object metadata = readingProperties.remove("metadata"); + if (metadata != null && Boolean.parseBoolean(metadata.toString())) { + reading.metadata(); + } + final Object locale = readingProperties.remove("locale"); + if (locale != null) { + String[] args = locale.toString().split(","); + switch (args.length) { + case 1: + reading.locale(new Locale(args[0])); + break; + case 2: + reading.locale(new Locale(args[0], args[1])); + break; + case 3: + reading.locale(new Locale(args[0], args[1], args[2])); + break; + default: + throw new IllegalArgumentException(String.format("Invalid value for property 'locale' %s, " + + "must be of the form [language][,country][,variant]", locale.toString())); + } + } + final Object with = readingProperties.remove("with"); + if (with != null && Boolean.parseBoolean(with.toString())) { + reading.withLocation(); + } + final Object filter = readingProperties.remove("filter"); + if (filter != null) { + reading.filter(filter.toString()); + } + } + +} diff --git a/components/camel-facebook/src/test/java/org/apache/camel/facebook/CamelFacebookTestSupport.java b/components/camel-facebook/src/test/java/org/apache/camel/facebook/CamelFacebookTestSupport.java new file mode 100644 index 0000000000000..b2d4795405f21 --- /dev/null +++ b/components/camel-facebook/src/test/java/org/apache/camel/facebook/CamelFacebookTestSupport.java @@ -0,0 +1,71 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.facebook; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import org.apache.camel.facebook.config.FacebookConfiguration; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.apache.camel.util.IntrospectionSupport; + +public class CamelFacebookTestSupport extends CamelTestSupport { + + private final Properties properties; + private FacebookConfiguration configuration; + + public CamelFacebookTestSupport() throws Exception { + URL url = getClass().getResource("/test-options.properties"); + + InputStream inStream; + try { + inStream = url.openStream(); + } catch (IOException e) { + e.printStackTrace(); + throw new IllegalAccessError("test-options.properties could not be found"); + } + + properties = new Properties(); + try { + properties.load(inStream); + } catch (IOException e) { + e.printStackTrace(); + throw new IllegalAccessError("test-options.properties could not be found"); + } + + Map options = new HashMap(); + for (Map.Entry entry : properties.entrySet()) { + options.put(entry.getKey().toString(), entry.getValue()); + } + + configuration = new FacebookConfiguration(); + IntrospectionSupport.setProperties(configuration, options); + } + + public FacebookConfiguration getConfiguration() { + return configuration; + } + + public String getOauthParams() { + return "oAuthAppId=" + properties.get("oAuthAppId") + "&oAuthAppSecret=" + properties.get("oAuthAppSecret") + + (properties.get("oAuthAccessToken") != null ? + ("&oAuthAccessToken=" + properties.get("oAuthAccessToken")) : ""); + } +} diff --git a/components/camel-facebook/src/test/java/org/apache/camel/facebook/FacebookComponentConsumerTest.java b/components/camel-facebook/src/test/java/org/apache/camel/facebook/FacebookComponentConsumerTest.java new file mode 100644 index 0000000000000..131d71e6472a4 --- /dev/null +++ b/components/camel-facebook/src/test/java/org/apache/camel/facebook/FacebookComponentConsumerTest.java @@ -0,0 +1,61 @@ +package org.apache.camel.facebook; + +import java.lang.reflect.Method; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.TimeUnit; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.junit.Test; + +import facebook4j.api.SearchMethods; + +public class FacebookComponentConsumerTest extends CamelFacebookTestSupport { + + private final Set searchNames = new HashSet(); + + public FacebookComponentConsumerTest() throws Exception { + // find search methods for consumer tests + for (Method method : SearchMethods.class.getDeclaredMethods()) { + String name = method.getName(); + if (name.startsWith("search") && !"search".equals(name)) { + name = Character.toLowerCase(name.charAt(6)) + name.substring(7); + } + if (!"locations".equals(name) && !"checkins".equals(name)) { + searchNames.add(name); + } + } + } + + @Test + public void testConsumers() throws InterruptedException { + for (String name : searchNames) { + MockEndpoint mock = getMockEndpoint("mock:consumeResult" + name); + mock.expectedMinimumMessageCount(1); + } + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() { + + // start with a 7 day window for the first delayed poll + String since = new SimpleDateFormat(FacebookConstants.FACEBOOK_DATE_FORMAT).format( + new Date(System.currentTimeMillis() - TimeUnit.MILLISECONDS.convert(7, TimeUnit.DAYS))); + + for (String name : searchNames) { + from("facebook://" + name + "?query=cheese&reading.limit=10&reading.locale=en.US&reading.since=" + + since + "&consumer.initialDelay=1000&" + getOauthParams()) + .to("mock:consumeResult" + name); + } + + // TODO add tests for the rest of the supported methods + } + }; + } + +} diff --git a/components/camel-facebook/src/test/java/org/apache/camel/facebook/FacebookComponentProducerTest.java b/components/camel-facebook/src/test/java/org/apache/camel/facebook/FacebookComponentProducerTest.java new file mode 100644 index 0000000000000..65c5d6945e288 --- /dev/null +++ b/components/camel-facebook/src/test/java/org/apache/camel/facebook/FacebookComponentProducerTest.java @@ -0,0 +1,126 @@ +package org.apache.camel.facebook; + +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.junit.Test; + +import facebook4j.Facebook; + +public class FacebookComponentProducerTest extends CamelFacebookTestSupport { + + private final Set noArgNames = new HashSet(); + + private final List idExcludes; + private final List readingExcludes; + + public FacebookComponentProducerTest() throws Exception { + for (Class clazz : Facebook.class.getInterfaces()) { + final String clazzName = clazz.getSimpleName(); + if (clazzName.endsWith("Methods") && !clazzName.equals("GameMethods")) { + for (Method method : clazz.getDeclaredMethods()) { + String name = method.getName(); + if (name.startsWith("get")) { + name = Character.toLowerCase(name.charAt(3)) + name.substring(4); + } + if (name.startsWith("search") && !"search".equals(name)) { + name = Character.toLowerCase(name.charAt(6)) + name.substring(7); + } + // find all the no-arg methods + if (method.getParameterTypes().length == 0) { + noArgNames.add(name); + } + } + } + } + + idExcludes = Arrays.asList(new String[] { "me", "home", "searchCheckins" }); + readingExcludes = Arrays.asList(new String[] { "pictureURL", "permissions" }); + } + + @Test + public void testProducers() throws Exception { + for (String name : noArgNames) { + MockEndpoint mock = getMockEndpoint("mock:result" + name); + mock.expectedMinimumMessageCount(1); + template().sendBody("direct://test" + name, null); + // avoid hitting Facebook API call rate limit + Thread.sleep(1000); + + // with user id + if (!idExcludes.contains(name)) { + mock = getMockEndpoint("mock:resultId" + name); + mock.expectedMinimumMessageCount(1); + template().sendBody("direct://testId" + name, null); + // avoid hitting Facebook API call rate limit + Thread.sleep(1000); + } + + // with reading + if (!readingExcludes.contains(name)) { + mock = getMockEndpoint("mock:resultReading" + name); + mock.expectedMinimumMessageCount(1); + template().sendBody("direct://testReading" + name, null); + // avoid hitting Facebook API call rate limit + Thread.sleep(1000); + } + + // with user id and reading + if (!(idExcludes.contains(name) || readingExcludes.contains(name))) { + mock = getMockEndpoint("mock:resultIdReading" + name); + mock.expectedMinimumMessageCount(1); + template().sendBody("direct://testIdReading" + name, null); + // avoid hitting Facebook API call rate limit + Thread.sleep(1000); + } + } + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() { + + //--------------- + // producer tests + //--------------- + // generate test routes for all methods with no args + for (String name : noArgNames) { + from("direct://test" + name) + .to("facebook://" + name + "?" + getOauthParams()) + .to("mock:result" + name); + + // with user id + if (!idExcludes.contains(name)) { + from("direct://testId" + name) + .to("facebook://" + name + "?userId=me&" + getOauthParams()) + .to("mock:resultId" + name); + } + + // reading options + if (!readingExcludes.contains(name)) { + from("direct://testReading" + name) + .to("facebook://" + name + "?reading.limit=10&reading.locale=en,US&" + getOauthParams()) + .to("mock:resultReading" + name); + } + + // with id and reading options + if (!(idExcludes.contains(name) || readingExcludes.contains(name))) { + from("direct://testIdReading" + name) + .to("facebook://" + name + "?userId=me&reading.limit=10&reading.locale=en,US&" + getOauthParams()) + .to("mock:resultIdReading" + name); + } + } + + // TODO add tests for the rest of the supported methods + } + }; + } + +} diff --git a/components/camel-facebook/src/test/java/org/apache/camel/facebook/data/FacebookMethodsTypeHelperTest.java b/components/camel-facebook/src/test/java/org/apache/camel/facebook/data/FacebookMethodsTypeHelperTest.java new file mode 100644 index 0000000000000..427d0b4d7d3e3 --- /dev/null +++ b/components/camel-facebook/src/test/java/org/apache/camel/facebook/data/FacebookMethodsTypeHelperTest.java @@ -0,0 +1,83 @@ +package org.apache.camel.facebook.data; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.*; + +import facebook4j.Facebook; +import org.apache.camel.facebook.config.FacebookEndpointConfiguration; +import org.junit.Test; + +/** + * Test {@link FacebookMethodsTypeHelper}. + */ +public class FacebookMethodsTypeHelperTest { + @Test + public void testGetCandidateMethods() throws Exception { + // TODO + } + + @Test + public void testFilterMethods() throws Exception { + // TODO + } + + @Test + public void testGetArguments() throws Exception { + final Class[] interfaces = Facebook.class.getInterfaces(); + for (Class clazz : interfaces) { + if (clazz.getName().endsWith("Methods")) { + // check all methods of this *Methods interface + for (Method method : clazz.getDeclaredMethods()) { + // will throw an exception if can't be found + final List arguments = FacebookMethodsTypeHelper.getArguments(method.getName()); + final int nArgs = arguments.size() / 2; + List types = new ArrayList(nArgs); + for (int i = 0; i < nArgs; i++) { + types.add((Class) arguments.get(2 * i)); + } + assertTrue("Missing parameters for " + method, + types.containsAll(Arrays.asList(method.getParameterTypes()))); + } + } + } + } + + @Test + public void testAllArguments() throws Exception { + assertFalse("Missing arguments", FacebookMethodsTypeHelper.allArguments().isEmpty()); + } + + @Test + public void testGetType() throws Exception { + for (Field field : FacebookEndpointConfiguration.class.getDeclaredFields()) { + Class expectedType = field.getType(); + final Class actualType = FacebookMethodsTypeHelper.getType(field.getName()); + // test for auto boxing, un-boxing + if (actualType.isPrimitive()) { + expectedType = (Class) expectedType.getField("TYPE").get(null); + } else if (List.class.isAssignableFrom(expectedType) && actualType.isArray()) { + // skip lists, since they will be converted in invokeMethod() + expectedType = actualType; + } + assertEquals("Missing property " + field.getName(), expectedType, actualType); + } + } + + @Test + public void testConvertToGetMethod() throws Exception { + assertEquals("Invalid get method name", + FacebookMethodsType.GET_ACCOUNTS.getName(), FacebookMethodsTypeHelper.convertToGetMethod("accounts")); + } + + @Test + public void testConvertToSearchMethod() throws Exception { + assertEquals("Invalid get method name", + FacebookMethodsType.SEARCHPOSTS.getName(), FacebookMethodsTypeHelper.convertToSearchMethod("posts")); + } + +} diff --git a/components/camel-facebook/src/test/java/org/apache/camel/facebook/data/FacebookMethodsTypeTest.java b/components/camel-facebook/src/test/java/org/apache/camel/facebook/data/FacebookMethodsTypeTest.java new file mode 100644 index 0000000000000..e5ec989320a74 --- /dev/null +++ b/components/camel-facebook/src/test/java/org/apache/camel/facebook/data/FacebookMethodsTypeTest.java @@ -0,0 +1,47 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.facebook.data; + +import java.lang.reflect.Method; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import facebook4j.Facebook; +import org.junit.Test; + +/** + * Test that all *Methods methods are mapped in {@link FacebookMethodsType}. + */ +public class FacebookMethodsTypeTest { + + @Test + public void areAllMethodsMapped() throws Exception { + final Class[] interfaces = Facebook.class.getInterfaces(); + for (Class clazz : interfaces) { + if (clazz.getName().endsWith("Methods")) { + // check all methods of this *Methods interface + for (Method method : clazz.getDeclaredMethods()) { + final FacebookMethodsType methodsType = FacebookMethodsType.findMethod(method.getName(), method.getParameterTypes()); + assertNotNull(methodsType); + assertEquals("Methods are not equal", method, methodsType.getMethod()); + } + } + } + } + +} diff --git a/components/camel-facebook/src/test/java/org/apache/camel/facebook/data/ReadingBuilderTest.java b/components/camel-facebook/src/test/java/org/apache/camel/facebook/data/ReadingBuilderTest.java new file mode 100644 index 0000000000000..ea665c8558b0b --- /dev/null +++ b/components/camel-facebook/src/test/java/org/apache/camel/facebook/data/ReadingBuilderTest.java @@ -0,0 +1,63 @@ +package org.apache.camel.facebook.data; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; + +import static org.junit.Assert.*; + +import facebook4j.Reading; +import org.apache.camel.facebook.FacebookConstants; +import org.junit.Test; + +/** + * Test {@link ReadingBuilder}. + */ +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=")); + } + + @Test + public void testSetProperties() throws Exception { + final Reading reading = new Reading(); + + Map properties = new HashMap(); + properties.put("fields", "field1,field2"); + properties.put("filter", "testFilter"); + properties.put("limit", "100"); + properties.put("metadata", ""); + properties.put("offset", "1000"); + final String facebookDate = new SimpleDateFormat(FacebookConstants.FACEBOOK_DATE_FORMAT).format(new Date()); + properties.put("since", facebookDate); + properties.put("until", facebookDate); + properties.put("withLocation", ""); + + // set properties on Reading + ReadingBuilder.setProperties(reading, properties); + } + +} From 36cac71bb74f83f864cebe401aae01c744d1962d Mon Sep 17 00:00:00 2001 From: Dhiraj Bokde Date: Thu, 29 Aug 2013 02:41:29 -0700 Subject: [PATCH 2/5] CAMEL-6676: Fixed copyright header --- .../apache/camel/facebook/FacebookComponent.java | 16 ++++++++++++++++ .../apache/camel/facebook/FacebookConstants.java | 16 ++++++++++++++++ .../apache/camel/facebook/FacebookConsumer.java | 16 ++++++++++++++++ .../apache/camel/facebook/FacebookEndpoint.java | 16 ++++++++++++++++ .../apache/camel/facebook/FacebookProducer.java | 16 ++++++++++++++++ .../camel/facebook/config/FacebookNameStyle.java | 16 ++++++++++++++++ .../facebook/data/FacebookPropertiesHelper.java | 16 ++++++++++++++++ .../camel/facebook/data/ReadingBuilder.java | 16 ++++++++++++++++ .../facebook/FacebookComponentConsumerTest.java | 16 ++++++++++++++++ .../facebook/FacebookComponentProducerTest.java | 16 ++++++++++++++++ 10 files changed, 160 insertions(+) diff --git a/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookComponent.java b/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookComponent.java index 5cc9aa64b5191..b57c62dafabac 100644 --- a/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookComponent.java +++ b/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookComponent.java @@ -1,3 +1,19 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.apache.camel.facebook; import java.util.HashMap; diff --git a/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookConstants.java b/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookConstants.java index c6df2c54bef66..ca9576791ca44 100644 --- a/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookConstants.java +++ b/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookConstants.java @@ -1,3 +1,19 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.apache.camel.facebook; /** diff --git a/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookConsumer.java b/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookConsumer.java index dd4bc9b33ea73..45e4d69d03097 100644 --- a/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookConsumer.java +++ b/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookConsumer.java @@ -1,3 +1,19 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.apache.camel.facebook; import java.lang.reflect.Array; diff --git a/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookEndpoint.java b/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookEndpoint.java index 7baa6ff658e52..a0118111457bf 100644 --- a/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookEndpoint.java +++ b/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookEndpoint.java @@ -1,3 +1,19 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.apache.camel.facebook; import java.util.*; diff --git a/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookProducer.java b/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookProducer.java index 7feb3feb10853..fe4120f897834 100644 --- a/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookProducer.java +++ b/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookProducer.java @@ -1,3 +1,19 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.apache.camel.facebook; import java.util.HashMap; diff --git a/components/camel-facebook/src/main/java/org/apache/camel/facebook/config/FacebookNameStyle.java b/components/camel-facebook/src/main/java/org/apache/camel/facebook/config/FacebookNameStyle.java index 94cc2f7d66d4e..a49d913375d45 100644 --- a/components/camel-facebook/src/main/java/org/apache/camel/facebook/config/FacebookNameStyle.java +++ b/components/camel-facebook/src/main/java/org/apache/camel/facebook/config/FacebookNameStyle.java @@ -1,3 +1,19 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.apache.camel.facebook.config; /** diff --git a/components/camel-facebook/src/main/java/org/apache/camel/facebook/data/FacebookPropertiesHelper.java b/components/camel-facebook/src/main/java/org/apache/camel/facebook/data/FacebookPropertiesHelper.java index 21ede54470a21..0050b19b4224a 100644 --- a/components/camel-facebook/src/main/java/org/apache/camel/facebook/data/FacebookPropertiesHelper.java +++ b/components/camel-facebook/src/main/java/org/apache/camel/facebook/data/FacebookPropertiesHelper.java @@ -1,3 +1,19 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.apache.camel.facebook.data; import java.lang.reflect.Field; diff --git a/components/camel-facebook/src/main/java/org/apache/camel/facebook/data/ReadingBuilder.java b/components/camel-facebook/src/main/java/org/apache/camel/facebook/data/ReadingBuilder.java index 436b95260c820..06aa555df4557 100644 --- a/components/camel-facebook/src/main/java/org/apache/camel/facebook/data/ReadingBuilder.java +++ b/components/camel-facebook/src/main/java/org/apache/camel/facebook/data/ReadingBuilder.java @@ -1,3 +1,19 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.apache.camel.facebook.data; import java.lang.reflect.Field; diff --git a/components/camel-facebook/src/test/java/org/apache/camel/facebook/FacebookComponentConsumerTest.java b/components/camel-facebook/src/test/java/org/apache/camel/facebook/FacebookComponentConsumerTest.java index 131d71e6472a4..2754e8eb3b1b6 100644 --- a/components/camel-facebook/src/test/java/org/apache/camel/facebook/FacebookComponentConsumerTest.java +++ b/components/camel-facebook/src/test/java/org/apache/camel/facebook/FacebookComponentConsumerTest.java @@ -1,3 +1,19 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.apache.camel.facebook; import java.lang.reflect.Method; diff --git a/components/camel-facebook/src/test/java/org/apache/camel/facebook/FacebookComponentProducerTest.java b/components/camel-facebook/src/test/java/org/apache/camel/facebook/FacebookComponentProducerTest.java index 65c5d6945e288..298d5990b3db4 100644 --- a/components/camel-facebook/src/test/java/org/apache/camel/facebook/FacebookComponentProducerTest.java +++ b/components/camel-facebook/src/test/java/org/apache/camel/facebook/FacebookComponentProducerTest.java @@ -1,3 +1,19 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.apache.camel.facebook; import java.lang.reflect.Method; From 1fc0553ffdcbf32dbd13aa2a5363b4f834706163 Mon Sep 17 00:00:00 2001 From: Dhiraj Bokde Date: Thu, 29 Aug 2013 03:19:13 -0700 Subject: [PATCH 3/5] CAMEL-6676: Fixed package names, added OSGi properties --- .../camel/facebook/FacebookComponent.java | 78 -- .../camel/facebook/FacebookConstants.java | 39 - .../camel/facebook/FacebookConsumer.java | 216 ------ .../camel/facebook/FacebookEndpoint.java | 165 ---- .../camel/facebook/FacebookProducer.java | 186 ----- .../config/FacebookConfiguration.java | 443 ----------- .../config/FacebookEndpointConfiguration.java | 706 ------------------ .../facebook/config/FacebookNameStyle.java | 26 - .../facebook/data/FacebookMethodsType.java | 572 -------------- .../data/FacebookMethodsTypeHelper.java | 350 --------- .../data/FacebookPropertiesHelper.java | 132 ---- .../camel/facebook/data/ReadingBuilder.java | 121 --- .../facebook/CamelFacebookTestSupport.java | 71 -- .../FacebookComponentConsumerTest.java | 77 -- .../FacebookComponentProducerTest.java | 142 ---- .../data/FacebookMethodsTypeHelperTest.java | 83 -- .../data/FacebookMethodsTypeTest.java | 47 -- .../facebook/data/ReadingBuilderTest.java | 63 -- 18 files changed, 3517 deletions(-) delete mode 100644 components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookComponent.java delete mode 100644 components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookConstants.java delete mode 100644 components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookConsumer.java delete mode 100644 components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookEndpoint.java delete mode 100644 components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookProducer.java delete mode 100644 components/camel-facebook/src/main/java/org/apache/camel/facebook/config/FacebookConfiguration.java delete mode 100644 components/camel-facebook/src/main/java/org/apache/camel/facebook/config/FacebookEndpointConfiguration.java delete mode 100644 components/camel-facebook/src/main/java/org/apache/camel/facebook/config/FacebookNameStyle.java delete mode 100644 components/camel-facebook/src/main/java/org/apache/camel/facebook/data/FacebookMethodsType.java delete mode 100644 components/camel-facebook/src/main/java/org/apache/camel/facebook/data/FacebookMethodsTypeHelper.java delete mode 100644 components/camel-facebook/src/main/java/org/apache/camel/facebook/data/FacebookPropertiesHelper.java delete mode 100644 components/camel-facebook/src/main/java/org/apache/camel/facebook/data/ReadingBuilder.java delete mode 100644 components/camel-facebook/src/test/java/org/apache/camel/facebook/CamelFacebookTestSupport.java delete mode 100644 components/camel-facebook/src/test/java/org/apache/camel/facebook/FacebookComponentConsumerTest.java delete mode 100644 components/camel-facebook/src/test/java/org/apache/camel/facebook/FacebookComponentProducerTest.java delete mode 100644 components/camel-facebook/src/test/java/org/apache/camel/facebook/data/FacebookMethodsTypeHelperTest.java delete mode 100644 components/camel-facebook/src/test/java/org/apache/camel/facebook/data/FacebookMethodsTypeTest.java delete mode 100644 components/camel-facebook/src/test/java/org/apache/camel/facebook/data/ReadingBuilderTest.java diff --git a/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookComponent.java b/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookComponent.java deleted file mode 100644 index b57c62dafabac..0000000000000 --- a/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookComponent.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.facebook; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.camel.CamelContext; -import org.apache.camel.Endpoint; -import org.apache.camel.facebook.config.FacebookConfiguration; -import org.apache.camel.facebook.config.FacebookEndpointConfiguration; -import org.apache.camel.impl.UriEndpointComponent; -import org.apache.camel.spi.UriParam; -import org.apache.camel.util.IntrospectionSupport; - -/** - * Represents the component that manages {@link FacebookEndpoint}. - */ -public class FacebookComponent extends UriEndpointComponent { - - @UriParam - private FacebookConfiguration configuration; - - public FacebookComponent() { - this(new FacebookConfiguration()); - } - - public FacebookComponent(FacebookConfiguration configuration) { - this(null, configuration); - } - - public FacebookComponent(CamelContext context) { - this(context, new FacebookConfiguration()); - } - - public FacebookComponent(CamelContext context, FacebookConfiguration configuration) { - super(context, FacebookEndpoint.class); - this.configuration = configuration; - } - - protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws Exception { - FacebookEndpointConfiguration config = copyComponentProperties(); - return new FacebookEndpoint(uri, this, remaining, config); - } - - private FacebookEndpointConfiguration copyComponentProperties() throws Exception { - Map componentProperties = new HashMap(); - IntrospectionSupport.getProperties(configuration, componentProperties, null, false); - - // create endpoint configuration with component properties - FacebookEndpointConfiguration config = new FacebookEndpointConfiguration(); - IntrospectionSupport.setProperties(config, componentProperties, null); - return config; - } - - public FacebookConfiguration getConfiguration() { - return configuration; - } - - public void setConfiguration(FacebookConfiguration configuration) { - this.configuration = configuration; - } - -} diff --git a/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookConstants.java b/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookConstants.java deleted file mode 100644 index ca9576791ca44..0000000000000 --- a/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookConstants.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.facebook; - -/** - * Common constants. - */ -public interface FacebookConstants { - - // reading options property name and prefix for uri property - String READING_PPROPERTY = "reading"; - String READING_PREFIX = READING_PPROPERTY + "."; - - // property name prefix for exchange 'in' headers - String FACEBOOK_PROPERTY_PREFIX = "CamelFacebook."; - - // property name for exchange 'in' body - String IN_BODY_PROPERTY = "inBody"; - - String FACEBOOK_THREAD_PROFILE_NAME = "CamelFacebook"; - - // date format used by Facebook Reading since and until fields - String FACEBOOK_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ssZ"; - -} diff --git a/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookConsumer.java b/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookConsumer.java deleted file mode 100644 index 45e4d69d03097..0000000000000 --- a/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookConsumer.java +++ /dev/null @@ -1,216 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.facebook; - -import java.lang.reflect.Array; -import java.text.SimpleDateFormat; -import java.util.*; -import java.util.concurrent.TimeUnit; -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.camel.facebook.data.FacebookMethodsType; -import org.apache.camel.facebook.data.FacebookPropertiesHelper; -import org.apache.camel.facebook.data.ReadingBuilder; -import org.apache.camel.impl.ScheduledPollConsumer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import facebook4j.Reading; - -import static org.apache.camel.facebook.FacebookConstants.FACEBOOK_DATE_FORMAT; -import static org.apache.camel.facebook.FacebookConstants.READING_PPROPERTY; -import static org.apache.camel.facebook.FacebookConstants.READING_PREFIX; -import static org.apache.camel.facebook.data.FacebookMethodsTypeHelper.MatchType; -import static org.apache.camel.facebook.data.FacebookMethodsTypeHelper.filterMethods; -import static org.apache.camel.facebook.data.FacebookMethodsTypeHelper.getHighestPriorityMethod; -import static org.apache.camel.facebook.data.FacebookMethodsTypeHelper.getMissingProperties; -import static org.apache.camel.facebook.data.FacebookMethodsTypeHelper.invokeMethod; - -/** - * The Facebook consumer. - */ -public class FacebookConsumer extends ScheduledPollConsumer { - - private static final Logger LOG = LoggerFactory.getLogger(FacebookConsumer.class); - private static final String SINCE_PREFIX = "since="; - - private final FacebookEndpoint endpoint; - private final FacebookMethodsType method; - private final Map endpointProperties; - - private String sinceTime; - private String untilTime; - - public FacebookConsumer(FacebookEndpoint endpoint, Processor processor) { - super(endpoint, processor); - this.endpoint = endpoint; - - // determine the consumer method to invoke - this.method = findMethod(endpoint.getCandidates()); - - // get endpoint properties in a map - final HashMap properties = new HashMap(); - 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) { - endIndex = queryString.length(); - } - this.sinceTime = queryString.substring(startIndex, endIndex).replaceAll("%3(a|A)", ":"); - LOG.debug("Using supplied property {}since value {}", READING_PREFIX, this.sinceTime); - } - if (queryString.contains("until=")) { - LOG.debug("Overriding configured property {}until", READING_PREFIX); - } - } - this.endpointProperties = Collections.unmodifiableMap(properties); - } - - private FacebookMethodsType findMethod(List candidates) { - // did we get lucky to have a single candidate? - FacebookMethodsType result; - if (candidates.size() == 1) { - // jackpot - result = candidates.get(0); - } else { - // find one that takes the largest subset of endpoint parameters - final Set argNames = new HashSet(); - argNames.addAll(FacebookPropertiesHelper.getEndpointPropertyNames(endpoint.getConfiguration())); - - // add reading property for polling, if it doesn't already exist! - argNames.add(READING_PPROPERTY); - - final String[] argNamesArray = argNames.toArray(new String[argNames.size()]); - List filteredMethods = filterMethods( - endpoint.getCandidates(), MatchType.SUPER_SET, argNamesArray); - - if (filteredMethods.isEmpty()) { - throw new IllegalArgumentException( - String.format("Missing properties for %s, need one or more from %s", - endpoint.getMethodName(), - getMissingProperties(endpoint.getMethodName(), endpoint.getNameStyle(), argNames))); - } else if (filteredMethods.size() == 1) { - // single match - result = filteredMethods.get(0); - } else { - result = getHighestPriorityMethod(filteredMethods); - LOG.warn("Using highest priority method {} from methods {}", method, filteredMethods); - } - } - return result; - } - - @Override - protected int poll() throws Exception { - // Note mark this consumer as not greedy to avoid making too many Facebook calls - setGreedy(false); - - // invoke the consumer method - Object result = invokeMethod(endpoint.getConfiguration().getFacebook(), - method, getMethodArguments()); - - // process result according to type - if (result != null && (result instanceof Collection || result.getClass().isArray())) { - // create an exchange for every element - final Object array = getResultAsArray(result); - final int length = Array.getLength(array); - for (int i = 0; i < length; i++) { - processResult(Array.get(array, i)); - } - return length; - } else { - processResult(result); - return 1; // number of messages polled - } - } - - private void processResult(Object result) throws Exception { - Exchange exchange = endpoint.createExchange(); - exchange.getIn().setBody(result); - try { - // send message to next processor in the route - getProcessor().process(exchange); - } finally { - // log exception if an exception occurred and was not handled - if (exchange.getException() != null) { - getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException()); - } - } - } - - private Object getResultAsArray(Object result) { - if (result.getClass().isArray()) { - // no conversion needed - return result; - } - // must be a Collection - // TODO add support for Paging using ResponseList - Collection collection = (Collection) result; - return collection.toArray(new Object[collection.size()]); - } - - private Map getMethodArguments() { - // start by setting the Reading since and until fields, - // these are used to avoid reading duplicate results across polls - Map arguments = new HashMap(); - 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; - } - -} diff --git a/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookEndpoint.java b/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookEndpoint.java deleted file mode 100644 index a0118111457bf..0000000000000 --- a/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookEndpoint.java +++ /dev/null @@ -1,165 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.facebook; - -import java.util.*; -import org.apache.camel.Consumer; -import org.apache.camel.Processor; -import org.apache.camel.Producer; -import org.apache.camel.facebook.config.FacebookEndpointConfiguration; -import org.apache.camel.facebook.config.FacebookNameStyle; -import org.apache.camel.facebook.data.FacebookMethodsType; -import org.apache.camel.facebook.data.FacebookPropertiesHelper; -import org.apache.camel.impl.DefaultEndpoint; -import org.apache.camel.spi.UriEndpoint; -import org.apache.camel.spi.UriParam; -import org.apache.camel.util.EndpointHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static org.apache.camel.facebook.data.FacebookMethodsTypeHelper.convertToGetMethod; -import static org.apache.camel.facebook.data.FacebookMethodsTypeHelper.convertToSearchMethod; -import static org.apache.camel.facebook.data.FacebookMethodsTypeHelper.getCandidateMethods; -import static org.apache.camel.facebook.data.FacebookMethodsTypeHelper.getMissingProperties; -import static org.apache.camel.facebook.data.FacebookPropertiesHelper.getEndpointPropertyNames; - -/** - * Represents a Facebook endpoint. - */ -@UriEndpoint(scheme = "facebook", consumerClass = FacebookConsumer.class) -public class FacebookEndpoint extends DefaultEndpoint implements FacebookConstants { - - private static final Logger LOG = LoggerFactory.getLogger(FacebookEndpoint.class); - - @UriParam - private FacebookEndpointConfiguration configuration; - - // Facebook4J method name - private final String methodName; - private FacebookNameStyle nameStyle; - - // candidate methods based on method name and endpoint configuration - private List candidates; - - public FacebookEndpoint(String uri, FacebookComponent facebookComponent, - String remaining, FacebookEndpointConfiguration configuration) { - super(uri, facebookComponent); - this.configuration = configuration; - this.methodName = remaining; - } - - public Producer createProducer() throws Exception { - return new FacebookProducer(this); - } - - public Consumer createConsumer(Processor processor) throws Exception { - final FacebookConsumer consumer = new FacebookConsumer(this, processor); - // also set consumer.* properties - configureConsumer(consumer); - return consumer; - } - - public boolean isSingleton() { - return true; - } - - @Override - public void configureProperties(Map options) { - super.configureProperties(options); - - // set configuration properties first - try { - if (configuration == null) { - configuration = new FacebookEndpointConfiguration(); - } - EndpointHelper.setReferenceProperties(getCamelContext(), configuration, options); - EndpointHelper.setProperties(getCamelContext(), configuration, options); - } catch (Exception e) { - throw new IllegalArgumentException(e.getMessage(), e); - } - - // extract reading properties - FacebookPropertiesHelper.configureReadingProperties(configuration, options); - - // validate configuration - configuration.validate(); - // validate and initialize state - initState(); - } - - private void initState() { - // get endpoint property names - final Set arguments = getEndpointPropertyNames(configuration); - final String[] argNames = arguments.toArray(new String[arguments.size()]); - - candidates = new ArrayList(); - candidates.addAll(getCandidateMethods(methodName, argNames)); - if (!candidates.isEmpty()) { - // found an exact name match, allows disambiguation if needed - this.nameStyle = FacebookNameStyle.EXACT; - } else { - - // also search for long forms of method name, both get* and search* - // Note that this set will be further sorted by Producers and Consumers - // producers will prefer get* forms, and consumers should prefer search* forms - candidates.addAll(getCandidateMethods(convertToGetMethod(methodName), argNames)); - if (!candidates.isEmpty()) { - this.nameStyle = FacebookNameStyle.GET; - } - - candidates.addAll(getCandidateMethods(convertToSearchMethod(methodName), argNames)); - // error if there are no candidates - if (candidates.isEmpty()) { - throw new IllegalArgumentException( - String.format("No matching operation for %s, with arguments %s", methodName, arguments)); - } - - if (nameStyle == null) { - // no get* methods found - nameStyle = FacebookNameStyle.SEARCH; - } else { - // get* and search* methods found - nameStyle = FacebookNameStyle.GET_AND_SEARCH; - } - } - - // log missing/extra properties for debugging - if (LOG.isDebugEnabled()) { - final Set missing = getMissingProperties(methodName, nameStyle, arguments); - if (!missing.isEmpty()) { - LOG.debug("Method {} could use one or more properties from {}", methodName, missing); - } - } - } - - public FacebookEndpointConfiguration getConfiguration() { - return configuration; - } - - public String getMethodName() { - return methodName; - } - - public FacebookNameStyle getNameStyle() { - return nameStyle; - } - - public List getCandidates() { - return Collections.unmodifiableList(candidates); - } - -} diff --git a/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookProducer.java b/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookProducer.java deleted file mode 100644 index fe4120f897834..0000000000000 --- a/components/camel-facebook/src/main/java/org/apache/camel/facebook/FacebookProducer.java +++ /dev/null @@ -1,186 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.facebook; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ExecutorService; -import org.apache.camel.AsyncCallback; -import org.apache.camel.CamelContext; -import org.apache.camel.Exchange; -import org.apache.camel.RuntimeCamelException; -import org.apache.camel.facebook.config.FacebookEndpointConfiguration; -import org.apache.camel.facebook.data.FacebookMethodsType; -import org.apache.camel.facebook.data.FacebookMethodsTypeHelper; -import org.apache.camel.impl.DefaultAsyncProducer; -import org.apache.camel.spi.ExecutorServiceManager; -import org.apache.camel.spi.ThreadPoolProfile; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static org.apache.camel.facebook.data.FacebookMethodsTypeHelper.MatchType; -import static org.apache.camel.facebook.data.FacebookMethodsTypeHelper.filterMethods; -import static org.apache.camel.facebook.data.FacebookMethodsTypeHelper.getCandidateMethods; -import static org.apache.camel.facebook.data.FacebookMethodsTypeHelper.getMissingProperties; -import static org.apache.camel.facebook.data.FacebookPropertiesHelper.getEndpointProperties; -import static org.apache.camel.facebook.data.FacebookPropertiesHelper.getExchangeProperties; - -/** - * The Facebook producer. - */ -public class FacebookProducer extends DefaultAsyncProducer { - private static final transient Logger LOG = LoggerFactory.getLogger(FacebookProducer.class); - - // thread pool executor - private static ExecutorService executorService; - - private FacebookEndpoint endpoint; - - public FacebookProducer(FacebookEndpoint endpoint) { - super(endpoint); - this.endpoint = endpoint; - - // get candidate methods using endpoint configuration - getCandidateMethods(endpoint.getEndpointUri()); - } - - @Override - public boolean process(final Exchange exchange, final AsyncCallback callback) { - // properties for method arguments - final Map properties = new HashMap(); - getEndpointProperties(endpoint.getConfiguration(), properties); - getExchangeProperties(exchange, properties); - - // decide which method to invoke - final FacebookMethodsType method = findMethod(exchange, properties); - if (method == null) { - // synchronous failure - callback.done(true); - return true; - } - - // create a runnable invocation task to be submitted on a background thread pool - // this way we avoid blocking the current thread for long running operations - Runnable invocation = new Runnable() { - @Override - public void run() { - try { - if (LOG.isDebugEnabled()) { - LOG.debug("Invoking method {} with {}", method.getName(), properties.keySet()); - } - - Object result = FacebookMethodsTypeHelper.invokeMethod( - endpoint.getConfiguration().getFacebook(), method, properties); - - // producer returns a single response, even for methods with List return types - exchange.getOut().setBody(result); - // copy headers - exchange.getOut().setHeaders(exchange.getIn().getHeaders()); - - } catch (Exception e) { - exchange.setException(new RuntimeCamelException(String.format("Error invoking %s with %s: %s", - method.getName(), properties.keySet(), e.getMessage()), e)); - } finally { - callback.done(false); - } - } - }; - - getExecutorService(getEndpoint().getCamelContext()).submit(invocation); - return false; - } - - private FacebookMethodsType findMethod(Exchange exchange, Map properties) { - // lucky enough to have a single method candidate? - final List candidates = endpoint.getCandidates(); - FacebookMethodsType method = null; - if (candidates.size() == 1) { - // jackpot! - method = candidates.get(0); - } else if (processInBody(exchange, properties)) { - - // filter candidates based on endpoint and exchange properties - final Set argNames = properties.keySet(); - final List filteredMethods = filterMethods(candidates, MatchType.SUPER_SET, - argNames.toArray(new String[argNames.size()])); - - // get the method to call - if (filteredMethods.isEmpty()) { - final Set missing = getMissingProperties(endpoint.getMethodName(), - endpoint.getNameStyle(), argNames); - throw new RuntimeCamelException(String.format("Missing properties for %s, need one or more from %s", - endpoint.getMethodName(), missing)); - } else if (filteredMethods.size() == 1) { - // found an exact match - method = filteredMethods.get(0); - } else { - method = FacebookMethodsTypeHelper.getHighestPriorityMethod(filteredMethods); - LOG.warn("Calling highest priority method {} from methods {}", method, filteredMethods); - } - } - - return method; - } - - private boolean processInBody(Exchange exchange, Map properties) { - final String inBodyProperty = (String) properties.remove(FacebookConstants.IN_BODY_PROPERTY); - if (inBodyProperty != null) { - - Object value = exchange.getIn().getBody(); - try { - value = getEndpoint().getCamelContext().getTypeConverter().mandatoryConvertTo( - FacebookEndpointConfiguration.class.getDeclaredField(inBodyProperty).getClass(), - exchange, value); - } catch (Exception e) { - exchange.setException(new RuntimeCamelException(String.format( - "Error converting value %s to property %s: %s", value, inBodyProperty, e.getMessage()), e)); - - return false; - } - - properties.put(inBodyProperty, value); - } - - return true; - } - - protected static synchronized ExecutorService getExecutorService(CamelContext context) { - // CamelContext will shutdown thread pool when it shutdown so we can - // lazy create it on demand - // but in case of hot-deploy or the likes we need to be able to - // re-create it (its a shared static instance) - if (executorService == null || executorService.isTerminated() || executorService.isShutdown()) { - final ExecutorServiceManager manager = context.getExecutorServiceManager(); - - // try to lookup a pool first based on profile - ThreadPoolProfile poolProfile = manager.getThreadPoolProfile( - FacebookConstants.FACEBOOK_THREAD_PROFILE_NAME); - if (poolProfile == null) { - poolProfile = manager.getDefaultThreadPoolProfile(); - } - - // create a new pool using the custom or default profile - executorService = manager.newScheduledThreadPool(FacebookProducer.class, - FacebookConstants.FACEBOOK_THREAD_PROFILE_NAME, poolProfile); - } - - return executorService; - } - -} diff --git a/components/camel-facebook/src/main/java/org/apache/camel/facebook/config/FacebookConfiguration.java b/components/camel-facebook/src/main/java/org/apache/camel/facebook/config/FacebookConfiguration.java deleted file mode 100644 index 1e63daad424e8..0000000000000 --- a/components/camel-facebook/src/main/java/org/apache/camel/facebook/config/FacebookConfiguration.java +++ /dev/null @@ -1,443 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.facebook.config; - -import org.apache.camel.spi.UriParam; -import org.apache.camel.spi.UriParams; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import facebook4j.Facebook; -import facebook4j.FacebookException; -import facebook4j.FacebookFactory; -import facebook4j.auth.OAuthAuthorization; -import facebook4j.conf.Configuration; -import facebook4j.conf.ConfigurationBuilder; - -/** - * Facebook component configuration. - */ -@UriParams -public class FacebookConfiguration implements Cloneable { - - private static final Logger LOG = LoggerFactory.getLogger(FacebookConfiguration.class); - - @UriParam - private String oAuthAppId; - @UriParam - private String oAuthAppSecret; - @UriParam - private String oAuthAccessToken; - @UriParam - private String oAuthAuthorizationURL; - @UriParam - private String oAuthPermissions; - - @UriParam - private String oAuthAccessTokenURL; - @UriParam - private String clientURL; - @UriParam - private String clientVersion; - @UriParam - private Boolean debugEnabled; - @UriParam - private Boolean gzipEnabled; - @UriParam - private Integer httpConnectionTimeout; - @UriParam - private Integer httpDefaultMaxPerRoute; - @UriParam - private Integer httpMaxTotalConnections; - @UriParam - private String httpProxyHost; - @UriParam - private String httpProxyPassword; - @UriParam - private Integer httpProxyPort; - @UriParam - private String httpProxyUser; - @UriParam - private Integer httpReadTimeout; - @UriParam - private Integer httpRetryCount; - @UriParam - private Integer httpRetryIntervalSeconds; - @UriParam - private Integer httpStreamingReadTimeout; - @UriParam - private Boolean jsonStoreEnabled; - @UriParam - private Boolean mbeanEnabled; - @UriParam - private Boolean prettyDebugEnabled; - @UriParam - private String restBaseURL; - @UriParam - private Boolean useSSL; - @UriParam - private String videoBaseURL; - - // cached FaceBook instance, is created in getFacebook by endpoint producers and consumers - private Facebook facebook; - - public Configuration getConfiguration() { - final ConfigurationBuilder builder = new ConfigurationBuilder(); - // apply builder settings - - if (oAuthAccessToken != null) { - builder.setOAuthAccessToken(oAuthAccessToken); - } - if (oAuthAccessTokenURL != null) { - builder.setOAuthAccessTokenURL(oAuthAccessTokenURL); - } - if (oAuthAppId != null) { - builder.setOAuthAppId(oAuthAppId); - } - if (oAuthAppSecret != null) { - builder.setOAuthAppSecret(oAuthAppSecret); - } - if (oAuthAuthorizationURL != null) { - builder.setOAuthAuthorizationURL(oAuthAuthorizationURL); - } - if (oAuthPermissions != null) { - builder.setOAuthPermissions(oAuthPermissions); - } - - if (clientURL != null) { - builder.setClientURL(clientURL); - } - if (clientVersion != null) { - builder.setClientVersion(clientVersion); - } - if (debugEnabled != null) { - builder.setDebugEnabled(debugEnabled); - } - if (gzipEnabled != null) { - builder.setGZIPEnabled(gzipEnabled); - } - if (httpConnectionTimeout != null) { - builder.setHttpConnectionTimeout(httpConnectionTimeout); - } - if (httpDefaultMaxPerRoute != null) { - builder.setHttpDefaultMaxPerRoute(httpDefaultMaxPerRoute); - } - if (httpMaxTotalConnections != null) { - builder.setHttpMaxTotalConnections(httpMaxTotalConnections); - } - if (httpProxyHost != null) { - builder.setHttpProxyHost(httpProxyHost); - } - if (httpProxyPassword != null) { - builder.setHttpProxyPassword(httpProxyPassword); - } - if (httpProxyPort != null) { - builder.setHttpProxyPort(httpProxyPort); - } - if (httpProxyUser != null) { - builder.setHttpProxyUser(httpProxyUser); - } - if (httpReadTimeout != null) { - builder.setHttpReadTimeout(httpReadTimeout); - } - if (httpRetryCount != null) { - builder.setHttpRetryCount(httpRetryCount); - } - if (httpRetryIntervalSeconds != null) { - builder.setHttpRetryIntervalSeconds(httpRetryIntervalSeconds); - } - if (httpStreamingReadTimeout != null) { - builder.setHttpStreamingReadTimeout(httpStreamingReadTimeout); - } - if (jsonStoreEnabled != null) { - builder.setJSONStoreEnabled(jsonStoreEnabled); - } - if (mbeanEnabled != null) { - builder.setMBeanEnabled(mbeanEnabled); - } - if (prettyDebugEnabled != null) { - builder.setPrettyDebugEnabled(prettyDebugEnabled); - } - if (restBaseURL != null) { - builder.setRestBaseURL(restBaseURL); - } - if (useSSL != null) { - builder.setUseSSL(useSSL); - } - if (videoBaseURL != null) { - builder.setVideoBaseURL(videoBaseURL); - } - - return builder.build(); - } - - /** - * Returns {@link Facebook} instance. If needed, creates one from configuration. - * @return {@link Facebook} instance - */ - public Facebook getFacebook() throws FacebookException { - if (facebook == null) { - final Configuration configuration = getConfiguration(); - FacebookFactory factory = new FacebookFactory(configuration); - if (this.oAuthAccessToken == null) { - // app login - facebook = factory.getInstance(new OAuthAuthorization(configuration)); - // also get the App access token - facebook.getOAuthAppAccessToken(); - LOG.warn("Login with app id and secret, access to some APIs is restricted!"); - } else { - // user login with token - facebook = factory.getInstance(); - // verify the access token - facebook.getOAuthAccessToken(); - LOG.debug("Login with app id, secret and token, all APIs accessible"); - } - } - return facebook; - } - - public FacebookConfiguration copy() throws CloneNotSupportedException { - final FacebookConfiguration copy = (FacebookConfiguration) clone(); - // do not copy facebook instance!!! - copy.facebook = null; - return copy; - } - - public String getOAuthAccessToken() { - return oAuthAccessToken; - } - - public void setOAuthAccessToken(String oAuthAccessToken) { - this.oAuthAccessToken = oAuthAccessToken; - } - - public String getOAuthAccessTokenURL() { - return oAuthAccessTokenURL; - } - - public void setOAuthAccessTokenURL(String oAuthAccessTokenURL) { - this.oAuthAccessTokenURL = oAuthAccessTokenURL; - } - - public String getOAuthAppId() { - return oAuthAppId; - } - - public void setOAuthAppId(String oAuthAppId) { - this.oAuthAppId = oAuthAppId; - } - - public String getOAuthAppSecret() { - return oAuthAppSecret; - } - - public void setOAuthAppSecret(String oAuthAppSecret) { - this.oAuthAppSecret = oAuthAppSecret; - } - - public String getOAuthAuthorizationURL() { - return oAuthAuthorizationURL; - } - - public void setOAuthAuthorizationURL(String oAuthAuthorizationURL) { - this.oAuthAuthorizationURL = oAuthAuthorizationURL; - } - - public String getClientURL() { - return clientURL; - } - - public void setClientURL(String clientURL) { - this.clientURL = clientURL; - } - - public String getClientVersion() { - return clientVersion; - } - - public void setClientVersion(String clientVersion) { - this.clientVersion = clientVersion; - } - - public Boolean getDebugEnabled() { - return debugEnabled; - } - - public void setDebugEnabled(Boolean debugEnabled) { - this.debugEnabled = debugEnabled; - } - - public Boolean getGzipEnabled() { - return gzipEnabled; - } - - public void setGzipEnabled(Boolean gzipEnabled) { - this.gzipEnabled = gzipEnabled; - } - - public Integer getHttpConnectionTimeout() { - return httpConnectionTimeout; - } - - public void setHttpConnectionTimeout(Integer httpConnectionTimeout) { - this.httpConnectionTimeout = httpConnectionTimeout; - } - - public Integer getHttpDefaultMaxPerRoute() { - return httpDefaultMaxPerRoute; - } - - public void setHttpDefaultMaxPerRoute(Integer httpDefaultMaxPerRoute) { - this.httpDefaultMaxPerRoute = httpDefaultMaxPerRoute; - } - - public Integer getHttpMaxTotalConnections() { - return httpMaxTotalConnections; - } - - public void setHttpMaxTotalConnections(Integer httpMaxTotalConnections) { - this.httpMaxTotalConnections = httpMaxTotalConnections; - } - - public String getHttpProxyHost() { - return httpProxyHost; - } - - public void setHttpProxyHost(String httpProxyHost) { - this.httpProxyHost = httpProxyHost; - } - - public String getHttpProxyPassword() { - return httpProxyPassword; - } - - public void setHttpProxyPassword(String httpProxyPassword) { - this.httpProxyPassword = httpProxyPassword; - } - - public Integer getHttpProxyPort() { - return httpProxyPort; - } - - public void setHttpProxyPort(Integer httpProxyPort) { - this.httpProxyPort = httpProxyPort; - } - - public String getHttpProxyUser() { - return httpProxyUser; - } - - public void setHttpProxyUser(String httpProxyUser) { - this.httpProxyUser = httpProxyUser; - } - - public Integer getHttpReadTimeout() { - return httpReadTimeout; - } - - public void setHttpReadTimeout(Integer httpReadTimeout) { - this.httpReadTimeout = httpReadTimeout; - } - - public Integer getHttpRetryCount() { - return httpRetryCount; - } - - public void setHttpRetryCount(Integer httpRetryCount) { - this.httpRetryCount = httpRetryCount; - } - - public Integer getHttpRetryIntervalSeconds() { - return httpRetryIntervalSeconds; - } - - public void setHttpRetryIntervalSeconds(Integer httpRetryIntervalSeconds) { - this.httpRetryIntervalSeconds = httpRetryIntervalSeconds; - } - - public Integer getHttpStreamingReadTimeout() { - return httpStreamingReadTimeout; - } - - public void setHttpStreamingReadTimeout(Integer httpStreamingReadTimeout) { - this.httpStreamingReadTimeout = httpStreamingReadTimeout; - } - - public Boolean getJsonStoreEnabled() { - return jsonStoreEnabled; - } - - public void setJsonStoreEnabled(Boolean jsonStoreEnabled) { - this.jsonStoreEnabled = jsonStoreEnabled; - } - - public Boolean getMbeanEnabled() { - return mbeanEnabled; - } - - public void setMbeanEnabled(Boolean mbeanEnabled) { - this.mbeanEnabled = mbeanEnabled; - } - - public String getOAuthPermissions() { - return oAuthPermissions; - } - - public void setOAuthPermissions(String oAuthPermissions) { - this.oAuthPermissions = oAuthPermissions; - } - - public Boolean getPrettyDebugEnabled() { - return prettyDebugEnabled; - } - - public void setPrettyDebugEnabled(Boolean prettyDebugEnabled) { - this.prettyDebugEnabled = prettyDebugEnabled; - } - - public String getRestBaseURL() { - return restBaseURL; - } - - public void setRestBaseURL(String restBaseURL) { - this.restBaseURL = restBaseURL; - } - - public Boolean getUseSSL() { - return useSSL; - } - - public void setUseSSL(Boolean useSSL) { - this.useSSL = useSSL; - } - - public String getVideoBaseURL() { - return videoBaseURL; - } - - public void setVideoBaseURL(String videoBaseURL) { - this.videoBaseURL = videoBaseURL; - } - - public void validate() { - if ((oAuthAppId == null || oAuthAppId.isEmpty()) - || (oAuthAppSecret == null || oAuthAppSecret.isEmpty())) { - throw new IllegalArgumentException("Missing required properties oAuthAppId, oAuthAppSecret"); - } - } - -} diff --git a/components/camel-facebook/src/main/java/org/apache/camel/facebook/config/FacebookEndpointConfiguration.java b/components/camel-facebook/src/main/java/org/apache/camel/facebook/config/FacebookEndpointConfiguration.java deleted file mode 100644 index 2c2f7f399d714..0000000000000 --- a/components/camel-facebook/src/main/java/org/apache/camel/facebook/config/FacebookEndpointConfiguration.java +++ /dev/null @@ -1,706 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.facebook.config; - -import java.lang.reflect.Field; -import java.net.URL; -import java.util.Arrays; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import org.apache.camel.facebook.FacebookConstants; -import org.apache.camel.spi.UriParam; -import org.apache.camel.spi.UriParams; -import org.apache.camel.util.ObjectHelper; - -import facebook4j.*; - -@UriParams -public class FacebookEndpointConfiguration extends FacebookConfiguration { - - // property name for Exchange 'In' message body - @UriParam - private String inBody; - - @UriParam - private URL achievementURL; - @UriParam - private AlbumCreate albumCreate; - @UriParam - private String albumId; - @UriParam - private Boolean allowNewOptions; - @UriParam - private String appId; - @UriParam - private GeoLocation center; - @UriParam - private CheckinCreate checkinCreate; - @UriParam - private String checkinId; - @UriParam - private String commentId; - @UriParam - private String description; - @UriParam - private Integer distance; - @UriParam - private String domainId; - @UriParam - private String domainName; - @UriParam - private List domainNames; - @UriParam - private String eventId; - @UriParam - private EventUpdate eventUpdate; - @UriParam - private String friendId; - @UriParam - private String friendUserId; - @UriParam - private String friendlistId; - @UriParam - private String friendlistName; - @UriParam - private String groupId; - @UriParam - private List ids; - @UriParam - private Boolean includeRead; - @UriParam - private URL link; - @UriParam - private String linkId; - @UriParam - private Locale locale; - @UriParam - private String message; - @UriParam - private String messageId; - @UriParam - private String metric; - @UriParam - private String name; - @UriParam - private Boolean noStory; - @UriParam - private String noteId; - @UriParam - private String notificationId; - @UriParam - private String objectId; - @UriParam - private String optionDescription; - @UriParam - private List options; - @UriParam - private String permissionName; - @UriParam - private String permissions; - @UriParam - private String photoId; - @UriParam - private String place; - @UriParam - private String placeId; - @UriParam - private String postId; - @UriParam - private PostUpdate postUpdate; - @UriParam - private Map queries; - @UriParam - private String query; - @UriParam - private String question; - @UriParam - private String questionId; - @UriParam - private Reading reading; - @UriParam - private Integer scoreValue; - @UriParam - private PictureSize size; - @UriParam - private Media source; - @UriParam - private String subject; - @UriParam - private TagUpdate tagUpdate; - @UriParam - private TestUser testUser1; - @UriParam - private TestUser testUser2; - @UriParam - private String testUserId; - @UriParam - private String title; - @UriParam - private String toUserId; - @UriParam - private List toUserIds; - @UriParam - private String userId1; - @UriParam - private String userId2; - @UriParam - private String userId; - @UriParam - private List userIds; - @UriParam - private String userLocale; - @UriParam - private String videoId; - - public String getInBody() { - return inBody; - } - - public void setInBody(String inBody) { - ObjectHelper.notNull(inBody, "inBody"); - this.inBody = inBody; - - // validate name - final List fields = Arrays.asList(getClass().getDeclaredFields()); - fields.remove(FacebookConstants.IN_BODY_PROPERTY); - if (!fields.contains(inBody)) { - throw new IllegalArgumentException("Unknown property " + inBody); - } - } - - public URL getAchievementURL() { - return achievementURL; - } - - public void setAchievementURL(URL achievementURL) { - this.achievementURL = achievementURL; - } - - public AlbumCreate getAlbumCreate() { - return albumCreate; - } - - public void setAlbumCreate(AlbumCreate albumCreate) { - this.albumCreate = albumCreate; - } - - public String getAlbumId() { - return albumId; - } - - public void setAlbumId(String albumId) { - this.albumId = albumId; - } - - public Boolean isAllowNewOptions() { - return allowNewOptions; - } - - public void setAllowNewOptions(Boolean allowNewOptions) { - this.allowNewOptions = allowNewOptions; - } - - public String getoAuthAppId() { - return appId; - } - - public void setoAuthAppId(String appId) { - this.appId = appId; - } - - public GeoLocation getCenter() { - return center; - } - - public void setCenter(GeoLocation center) { - this.center = center; - } - - public CheckinCreate getCheckinCreate() { - return checkinCreate; - } - - public void setCheckinCreate(CheckinCreate checkinCreate) { - this.checkinCreate = checkinCreate; - } - - public String getCheckinId() { - return checkinId; - } - - public void setCheckinId(String checkinId) { - this.checkinId = checkinId; - } - - public String getCommentId() { - return commentId; - } - - public void setCommentId(String commentId) { - this.commentId = commentId; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public Integer getDistance() { - return distance; - } - - public void setDistance(Integer distance) { - this.distance = distance; - } - - public String getDomainId() { - return domainId; - } - - public void setDomainId(String domainId) { - this.domainId = domainId; - } - - public String getDomainName() { - return domainName; - } - - public void setDomainName(String domainName) { - this.domainName = domainName; - } - - public List getDomainNames() { - return domainNames; - } - - public void setDomainNames(List domainNames) { - this.domainNames = domainNames; - } - - public String getEventId() { - return eventId; - } - - public void setEventId(String eventId) { - this.eventId = eventId; - } - - public EventUpdate getEventUpdate() { - return eventUpdate; - } - - public void setEventUpdate(EventUpdate eventUpdate) { - this.eventUpdate = eventUpdate; - } - - public String getFriendId() { - return friendId; - } - - public void setFriendId(String friendId) { - this.friendId = friendId; - } - - public String getFriendUserId() { - return friendUserId; - } - - public void setFriendUserId(String friendUserId) { - this.friendUserId = friendUserId; - } - - public String getFriendlistId() { - return friendlistId; - } - - public void setFriendlistId(String friendlistId) { - this.friendlistId = friendlistId; - } - - public String getFriendlistName() { - return friendlistName; - } - - public void setFriendlistName(String friendlistName) { - this.friendlistName = friendlistName; - } - - public String getGroupId() { - return groupId; - } - - public void setGroupId(String groupId) { - this.groupId = groupId; - } - - public List getIds() { - return ids; - } - - public void setIds(List ids) { - this.ids = ids; - } - - public Boolean isIncludeRead() { - return includeRead; - } - - public void setIncludeRead(Boolean includeRead) { - this.includeRead = includeRead; - } - - public URL getLink() { - return link; - } - - public void setLink(URL link) { - this.link = link; - } - - public String getLinkId() { - return linkId; - } - - public void setLinkId(String linkId) { - this.linkId = linkId; - } - - public Locale getLocale() { - return locale; - } - - public void setLocale(Locale locale) { - this.locale = locale; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public String getMessageId() { - return messageId; - } - - public void setMessageId(String messageId) { - this.messageId = messageId; - } - - public String getMetric() { - return metric; - } - - public void setMetric(String metric) { - this.metric = metric; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Boolean isNoStory() { - return noStory; - } - - public void setNoStory(Boolean noStory) { - this.noStory = noStory; - } - - public String getNoteId() { - return noteId; - } - - public void setNoteId(String noteId) { - this.noteId = noteId; - } - - public String getNotificationId() { - return notificationId; - } - - public void setNotificationId(String notificationId) { - this.notificationId = notificationId; - } - - public String getObjectId() { - return objectId; - } - - public void setObjectId(String objectId) { - this.objectId = objectId; - } - - public String getOptionDescription() { - return optionDescription; - } - - public void setOptionDescription(String optionDescription) { - this.optionDescription = optionDescription; - } - - public List getOptions() { - return options; - } - - public void setOptions(List options) { - this.options = options; - } - - public String getPermissionName() { - return permissionName; - } - - public void setPermissionName(String permissionName) { - this.permissionName = permissionName; - } - - public String getoAuthPermissions() { - return permissions; - } - - public void setoAuthPermissions(String permissions) { - this.permissions = permissions; - } - - public String getPhotoId() { - return photoId; - } - - public void setPhotoId(String photoId) { - this.photoId = photoId; - } - - public String getPlace() { - return place; - } - - public void setPlace(String place) { - this.place = place; - } - - public String getPlaceId() { - return placeId; - } - - public void setPlaceId(String placeId) { - this.placeId = placeId; - } - - public String getPostId() { - return postId; - } - - public void setPostId(String postId) { - this.postId = postId; - } - - public PostUpdate getPostUpdate() { - return postUpdate; - } - - public void setPostUpdate(PostUpdate postUpdate) { - this.postUpdate = postUpdate; - } - - public Map getQueries() { - return queries; - } - - public void setQueries(Map queries) { - this.queries = queries; - } - - public String getQuery() { - return query; - } - - public void setQuery(String query) { - this.query = query; - } - - public String getQuestion() { - return question; - } - - public void setQuestion(String question) { - this.question = question; - } - - public String getQuestionId() { - return questionId; - } - - public void setQuestionId(String questionId) { - this.questionId = questionId; - } - - public Reading getReading() { - return reading; - } - - public void setReading(Reading reading) { - this.reading = reading; - } - - public Integer getScoreValue() { - return scoreValue; - } - - public void setScoreValue(Integer scoreValue) { - this.scoreValue = scoreValue; - } - - public PictureSize getSize() { - return size; - } - - public void setSize(PictureSize size) { - this.size = size; - } - - public Media getSource() { - return source; - } - - public void setSource(Media source) { - this.source = source; - } - - public String getSubject() { - return subject; - } - - public void setSubject(String subject) { - this.subject = subject; - } - - public TagUpdate getTagUpdate() { - return tagUpdate; - } - - public void setTagUpdate(TagUpdate tagUpdate) { - this.tagUpdate = tagUpdate; - } - - public TestUser getTestUser1() { - return testUser1; - } - - public void setTestUser1(TestUser testUser1) { - this.testUser1 = testUser1; - } - - public TestUser getTestUser2() { - return testUser2; - } - - public void setTestUser2(TestUser testUser2) { - this.testUser2 = testUser2; - } - - public String getTestUserId() { - return testUserId; - } - - public void setTestUserId(String testUserId) { - this.testUserId = testUserId; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getToUserId() { - return toUserId; - } - - public void setToUserId(String toUserId) { - this.toUserId = toUserId; - } - - public List getToUserIds() { - return toUserIds; - } - - public void setToUserIds(List toUserIds) { - this.toUserIds = toUserIds; - } - - public String getUserId1() { - return userId1; - } - - public void setUserId1(String userId1) { - this.userId1 = userId1; - } - - public String getUserId2() { - return userId2; - } - - public void setUserId2(String userId2) { - this.userId2 = userId2; - } - - public String getUserId() { - return userId; - } - - public void setUserId(String userId) { - this.userId = userId; - } - - public List getUserIds() { - return userIds; - } - - public void setUserIds(List userIds) { - this.userIds = userIds; - } - - public String getUserLocale() { - return userLocale; - } - - public void setUserLocale(String userLocale) { - this.userLocale = userLocale; - } - - public String getVideoId() { - return videoId; - } - - public void setVideoId(String videoId) { - this.videoId = videoId; - } - -} diff --git a/components/camel-facebook/src/main/java/org/apache/camel/facebook/config/FacebookNameStyle.java b/components/camel-facebook/src/main/java/org/apache/camel/facebook/config/FacebookNameStyle.java deleted file mode 100644 index a49d913375d45..0000000000000 --- a/components/camel-facebook/src/main/java/org/apache/camel/facebook/config/FacebookNameStyle.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.facebook.config; - -/** - * Constants for method name style. - */ -public enum FacebookNameStyle { - - EXACT, GET, SEARCH, GET_AND_SEARCH; - -} diff --git a/components/camel-facebook/src/main/java/org/apache/camel/facebook/data/FacebookMethodsType.java b/components/camel-facebook/src/main/java/org/apache/camel/facebook/data/FacebookMethodsType.java deleted file mode 100644 index ebf040d0fa302..0000000000000 --- a/components/camel-facebook/src/main/java/org/apache/camel/facebook/data/FacebookMethodsType.java +++ /dev/null @@ -1,572 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.facebook.data; - -import java.lang.reflect.Method; -import java.net.URL; -import java.util.*; -import org.apache.camel.facebook.FacebookConstants; - -import facebook4j.*; -import facebook4j.internal.org.json.JSONArray; - -/** - * Enum for Facebook4J *Method interfaces. - * The methods are ordered by the number and nature of arguments. - */ -public enum FacebookMethodsType { - - // AccountMethods - GET_ACCOUNTS(ResponseList.class, "getAccounts"), - GET_ACCOUNTS_WITH_OPTIONS(ResponseList.class, "getAccounts", Reading.class, FacebookConstants.READING_PPROPERTY), - GET_ACCOUNTS_WITH_ID(ResponseList.class, "getAccounts", String.class, "userId"), - GET_ACCOUNTS_WITH_ID_OPTIONS(ResponseList.class, "getAccounts", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - - // ActivityMethods - GETACTIVITIES(ResponseList.class, "getActivities"), - GETACTIVITIES_WITH_OPTIONS(ResponseList.class, "getActivities", Reading.class, FacebookConstants.READING_PPROPERTY), - GETACTIVITIES_WITH_ID(ResponseList.class, "getActivities", String.class, "userId"), - GETACTIVITIES_WITH_ID_OPTIONS(ResponseList.class, "getActivities", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - - // AlbumMethods - ADDALBUMPHOTO(String.class, "addAlbumPhoto", String.class, "albumId", Media.class, "source"), - ADDALBUMPHOTO_WITH_MEDIA(String.class, "addAlbumPhoto", String.class, "albumId", Media.class, "source", String.class, "message"), - COMMENTALBUM(String.class, "commentAlbum", String.class, "albumId", String.class, "message"), - CREATEALBUM(String.class, "createAlbum", AlbumCreate.class, "albumCreate"), - CREATEALBUM_WITH_ID(String.class, "createAlbum", String.class, "userId", AlbumCreate.class, "albumCreate"), - GETALBUM(Album.class, "getAlbum", String.class, "albumId"), - GETALBUM_WITH_OPTIONS(Album.class, "getAlbum", String.class, "albumId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETALBUMCOMMENTS(ResponseList.class, "getAlbumComments", String.class, "albumId"), - GETALBUMCOMMENTS_WITH_OPTIONS(ResponseList.class, "getAlbumComments", String.class, "albumId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETALBUMCOVERPHOTO(URL.class, "getAlbumCoverPhoto", String.class, "albumId"), - GETALBUMLIKES(ResponseList.class, "getAlbumLikes", String.class, "albumId"), - GETALBUMLIKES_WITH_OPTIONS(ResponseList.class, "getAlbumLikes", String.class, "albumId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETALBUMPHOTOS(ResponseList.class, "getAlbumPhotos", String.class, "albumId"), - GETALBUMPHOTOS_WITH_OPTIONS(ResponseList.class, "getAlbumPhotos", String.class, "albumId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETALBUMS(ResponseList.class, "getAlbums"), - GETALBUMS_WITH_OPTIONS(ResponseList.class, "getAlbums", Reading.class, FacebookConstants.READING_PPROPERTY), - GETALBUMS_WITH_ID(ResponseList.class, "getAlbums", String.class, "userId"), - GETALBUMS_WITH_ID_OPTIONS(ResponseList.class, "getAlbums", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - LIKEALBUM(boolean.class, "likeAlbum", String.class, "albumId"), - UNLIKEALBUM(boolean.class, "unlikeAlbum", String.class, "albumId"), - - // CheckinMethods - CHECKIN(String.class, "checkin", CheckinCreate.class, "checkinCreate"), - CHECKIN_WITH_ID(String.class, "checkin", String.class, "userId", CheckinCreate.class, "checkinCreate"), - COMMENTCHECKIN(String.class, "commentCheckin", String.class, "checkinId", String.class, "message"), - GETCHECKIN(Checkin.class, "getCheckin", String.class, "checkinId"), - GETCHECKIN_WITH_OPTIONS(Checkin.class, "getCheckin", String.class, "checkinId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETCHECKINCOMMENTS(ResponseList.class, "getCheckinComments", String.class, "checkinId"), - GETCHECKINCOMMENTS_WITH_OPTIONS(ResponseList.class, "getCheckinComments", String.class, "checkinId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETCHECKINLIKES(ResponseList.class, "getCheckinLikes", String.class, "checkinId"), - GETCHECKINLIKES_WITH_OPTIONS(ResponseList.class, "getCheckinLikes", String.class, "checkinId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETCHECKINS(ResponseList.class, "getCheckins"), - GETCHECKINS_WITH_OPTIONS(ResponseList.class, "getCheckins", Reading.class, FacebookConstants.READING_PPROPERTY), - GETCHECKINS_WITH_ID(ResponseList.class, "getCheckins", String.class, "userId"), - GETCHECKINS_WITH_ID_OPTIONS(ResponseList.class, "getCheckins", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - LIKECHECKIN(boolean.class, "likeCheckin", String.class, "checkinId"), - UNLIKECHECKIN(boolean.class, "unlikeCheckin", String.class, "checkinId"), - - // CommentMethods - DELETECOMMENT(boolean.class, "deleteComment", String.class, "commentId"), - GETCOMMENT(Comment.class, "getComment", String.class, "commentId"), - GETCOMMENTLIKES(ResponseList.class, "getCommentLikes", String.class, "commentId"), - GETCOMMENTLIKES_WITH_OPTIONS(ResponseList.class, "getCommentLikes", String.class, "commentId", Reading.class, FacebookConstants.READING_PPROPERTY), - LIKECOMMENT(boolean.class, "likeComment", String.class, "commentId"), - UNLIKECOMMENT(Boolean.class, "unlikeComment", String.class, "commentId"), - - // DomainMethods - GETDOMAIN(Domain.class, "getDomain", String.class, "domainId"), - GETDOMAINBYNAME(Domain.class, "getDomainByName", String.class, "domainName"), - GETDOMAINSBYNAME_WITH_DOMAINS(List.class, "getDomainsByName", new String[0].getClass(), "domainNames"), - - // EventMethods - CREATEEVENT(String.class, "createEvent", EventUpdate.class, "eventUpdate"), - CREATEEVENT_WITH_ID(String.class, "createEvent", String.class, "userId", EventUpdate.class, "eventUpdate"), - DELETEEVENT(Boolean.class, "deleteEvent", String.class, "eventId"), - DELETEEVENTPICTURE(Boolean.class, "deleteEventPicture", String.class, "eventId"), - EDITEVENT(Boolean.class, "editEvent", String.class, "eventId", EventUpdate.class, "eventUpdate"), - GETEVENT(Event.class, "getEvent", String.class, "eventId"), - GETEVENT_WITH_OPTIONS(Event.class, "getEvent", String.class, "eventId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETEVENTFEED(ResponseList.class, "getEventFeed", String.class, "eventId"), - GETEVENTFEED_WITH_OPTIONS(ResponseList.class, "getEventFeed", String.class, "eventId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETEVENTPHOTOS(ResponseList.class, "getEventPhotos", String.class, "eventId"), - GETEVENTPHOTOS_WITH_OPTIONS(ResponseList.class, "getEventPhotos", String.class, "eventId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETEVENTPICTUREURL(URL.class, "getEventPictureURL", String.class, "eventId"), - GETEVENTPICTUREURL_WITH_PICTURESIZE(URL.class, "getEventPictureURL", String.class, "eventId", PictureSize.class, "size"), - GETEVENTS(ResponseList.class, "getEvents"), - GETEVENTS_WITH_OPTIONS(ResponseList.class, "getEvents", Reading.class, FacebookConstants.READING_PPROPERTY), - GETEVENTS_WITH_ID(ResponseList.class, "getEvents", String.class, "userId"), - GETEVENTS_WITH_ID_OPTIONS(ResponseList.class, "getEvents", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETEVENTVIDEOS(ResponseList.class, "getEventVideos", String.class, "eventId"), - GETEVENTVIDEOS_WITH_OPTIONS(ResponseList.class, "getEventVideos", String.class, "eventId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETRSVPSTATUSASINVITED(ResponseList.class, "getRSVPStatusAsInvited", String.class, "eventId"), - GETRSVPSTATUSASINVITED_WITH_ID(ResponseList.class, "getRSVPStatusAsInvited", String.class, "eventId", String.class, "userId"), - GETRSVPSTATUSASNOREPLY(ResponseList.class, "getRSVPStatusAsNoreply", String.class, "eventId"), - GETRSVPSTATUSASNOREPLY_WITH_ID(ResponseList.class, "getRSVPStatusAsNoreply", String.class, "eventId", String.class, "userId"), - GETRSVPSTATUSINATTENDING(ResponseList.class, "getRSVPStatusInAttending", String.class, "eventId"), - GETRSVPSTATUSINATTENDING_WITH_ID(ResponseList.class, "getRSVPStatusInAttending", String.class, "eventId", String.class, "userId"), - GETRSVPSTATUSINDECLINED(ResponseList.class, "getRSVPStatusInDeclined", String.class, "eventId"), - GETRSVPSTATUSINDECLINED_WITH_ID(ResponseList.class, "getRSVPStatusInDeclined", String.class, "eventId", String.class, "userId"), - GETRSVPSTATUSINMAYBE(ResponseList.class, "getRSVPStatusInMaybe", String.class, "eventId"), - GETRSVPSTATUSINMAYBE_WITH_ID(ResponseList.class, "getRSVPStatusInMaybe", String.class, "eventId", String.class, "userId"), - INVITETOEVENT(Boolean.class, "inviteToEvent", String.class, "eventId", String.class, "userId"), - INVITETOEVENT_WITH_IDS(Boolean.class, "inviteToEvent", String.class, "eventId", new String[0].getClass(), "userIds"), - POSTEVENTFEED_WITH_POSTUPDATE(String.class, "postEventFeed", String.class, "eventId", PostUpdate.class, "postUpdate"), - POSTEVENTLINK_WITH_LINK(String.class, "postEventLink", String.class, "eventId", URL.class , "link"), - POSTEVENTLINK_WITH_LINK_MSG(String.class, "postEventLink", String.class, "eventId", URL.class , "link", String.class, "message"), - POSTEVENTPHOTO_WITH_MEDIA(String.class, "postEventPhoto", String.class, "eventId", Media.class, "source"), - POSTEVENTPHOTO_WITH_MEDIA_MSG(String.class, "postEventPhoto", String.class, "eventId", Media.class, "source", String.class, "message"), - POSTEVENTSTATUSMESSAGE_WITH_MSG(String.class, "postEventStatusMessage", String.class, "eventId", String.class, "message"), - POSTEVENTVIDEO_WITH_MEDIA(String.class, "postEventVideo", String.class, "eventId", Media.class, "source"), - POSTEVENTVIDEO_WITH_MEDIA_TITLE_DESC(String.class, "postEventVideo", String.class, "eventId", Media.class, "source", String.class, "title", String.class, "description"), - RSVPEVENTASATTENDING(Boolean.class, "rsvpEventAsAttending", String.class, "eventId"), - RSVPEVENTASDECLINED(Boolean.class, "rsvpEventAsDeclined", String.class, "eventId"), - RSVPEVENTASMAYBE(Boolean.class, "rsvpEventAsMaybe", String.class, "eventId"), - UNINVITEFROMEVENT(Boolean.class, "uninviteFromEvent", String.class, "eventId", String.class, "userId"), - UPDATEEVENTPICTURE(Boolean.class, "updateEventPicture", String.class, "eventId", Media.class, "source"), - - // FamilyMethods - GETFAMILY(ResponseList.class, "getFamily"), - GETFAMILY_WITH_OPTIONS(ResponseList.class, "getFamily", Reading.class, FacebookConstants.READING_PPROPERTY), - GETFAMILY_WITH_ID(ResponseList.class, "getFamily", String.class, "userId"), - GETFAMILY_WITH_ID_OPTIONS(ResponseList.class, "getFamily", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - - // FavouriteMethods - GETBOOKS(ResponseList.class, "getBooks"), - GETBOOKS_WITH_OPTIONS(ResponseList.class, "getBooks", Reading.class, FacebookConstants.READING_PPROPERTY), - GETBOOKS_WITH_ID(ResponseList.class, "getBooks", String.class, "userId"), - GETBOOKS_WITH_ID_OPTIONS(ResponseList.class, "getBooks", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETGAMES(ResponseList.class, "getGames"), - GETGAMES_WITH_OPTIONS(ResponseList.class, "getGames", Reading.class, FacebookConstants.READING_PPROPERTY), - GETGAMES_WITH_ID(ResponseList.class, "getGames", String.class, "userId"), - GETGAMES_WITH_ID_OPTIONS(ResponseList.class, "getGames", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETINTERESTS(ResponseList.class, "getInterests"), - GETINTERESTS_WITH_OPTIONS(ResponseList.class, "getInterests", Reading.class, FacebookConstants.READING_PPROPERTY), - GETINTERESTS_WITH_ID(ResponseList.class, "getInterests", String.class, "userId"), - GETINTERESTS_WITH_ID_OPTIONS(ResponseList.class, "getInterests", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETMOVIES(ResponseList.class, "getMovies"), - GETMOVIES_WITH_OPTIONS(ResponseList.class, "getMovies", Reading.class, FacebookConstants.READING_PPROPERTY), - GETMOVIES_WITH_ID(ResponseList.class, "getMovies", String.class, "userId"), - GETMOVIES_WITH_ID_OPTIONS(ResponseList.class, "getMovies", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETMUSIC(ResponseList.class, "getMusic"), - GETMUSIC_WITH_OPTIONS(ResponseList.class, "getMusic", Reading.class, FacebookConstants.READING_PPROPERTY), - GETMUSIC_WITH_ID(ResponseList.class, "getMusic", String.class, "userId"), - GETMUSIC_WITH_ID_OPTIONS(ResponseList.class, "getMusic", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETTELEVISION(ResponseList.class, "getTelevision"), - GETTELEVISION_WITH_OPTIONS(ResponseList.class, "getTelevision", Reading.class, FacebookConstants.READING_PPROPERTY), - GETTELEVISION_WITH_ID(ResponseList.class, "getTelevision", String.class, "userId"), - GETTELEVISION_WITH_ID_OPTIONS(ResponseList.class, "getTelevision", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - - // FQLMethods - EXECUTEFQL(JSONArray.class, "executeFQL", String.class, "query"), - EXECUTEFQL_WITH_LOCALE(JSONArray.class, "executeFQL", String.class, "query", Locale.class, " locale"), - EXECUTEMULTIFQL(Map.class, "executeMultiFQL", Map.class, "queries"), - EXECUTEMULTIFQL_WITH_LOCALE(Map.class, "executeMultiFQL", Map.class, "queries", Locale.class, "locale"), - - // FriendMethods - ADDFRIENDLISTMEMBER(Boolean.class, "addFriendlistMember", String.class, "friendlistId", String.class, "userId"), - CREATEFRIENDLIST(String.class, "createFriendlist", String.class, "friendlistName"), - CREATEFRIENDLIST_WITH_ID(String.class, "createFriendlist", String.class, "userId", String.class, "friendlistName"), - DELETEFRIENDLIST(Boolean.class, "deleteFriendlist", String.class, "friendlistId"), - GETBELONGSFRIEND(ResponseList.class, "getBelongsFriend", String.class, "friendId"), - GETBELONGSFRIEND_WITH_OPTIONS(ResponseList.class, "getBelongsFriend", String.class, "friendId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETBELONGSFRIEND_WITH_ID(ResponseList.class, "getBelongsFriend", String.class, "userId", String.class, "friendId"), - GETBELONGSFRIEND_WITH_ID_OPTIONS(ResponseList.class, "getBelongsFriend", String.class, "userId", String.class, "friendId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETFRIENDLIST(Friendlist.class, "getFriendlist", String.class, "friendlistId"), - GETFRIENDLIST_WITH_OPTIONS(Friendlist.class, "getFriendlist", String.class, "friendlistId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETFRIENDLISTMEMBERS(ResponseList.class, "getFriendlistMembers", String.class, "friendlistId"), - GETFRIENDLISTS(ResponseList.class, "getFriendlists"), - GETFRIENDLISTS_WITH_OPTIONS(ResponseList.class, "getFriendlists", Reading.class, FacebookConstants.READING_PPROPERTY), - GETFRIENDLISTS_WITH_ID(ResponseList.class, "getFriendlists", String.class, "userId"), - GETFRIENDLISTS_WITH_ID_OPTIONS(ResponseList.class, "getFriendlists", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETFRIENDREQUESTS(ResponseList.class, "getFriendRequests"), - GETFRIENDREQUESTS_WITH_OPTIONS(ResponseList.class, "getFriendRequests", Reading.class, FacebookConstants.READING_PPROPERTY), - GETFRIENDREQUESTS_WITH_ID(ResponseList.class, "getFriendRequests", String.class, "userId"), - GETFRIENDREQUESTS_WITH_ID_OPTIONS(ResponseList.class, "getFriendRequests", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETFRIENDS(ResponseList.class, "getFriends"), - GETFRIENDS_WITH_OPTIONS(ResponseList.class, "getFriends", Reading.class, FacebookConstants.READING_PPROPERTY), - GETFRIENDS_WITH_ID(ResponseList.class, "getFriends", String.class, "userId"), - GETFRIENDS_WITH_ID_OPTIONS(ResponseList.class, "getFriends", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETMUTUALFRIENDS(ResponseList.class, "getMutualFriends", String.class, "friendUserId"), - GETMUTUALFRIENDS_WITH_OPTIONS(ResponseList.class, "getMutualFriends", String.class, "friendUserId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETMUTUALFRIENDS_WITH_ID(ResponseList.class, "getMutualFriends", String.class, "userId1", String.class, "userId2"), - GETMUTUALFRIENDS_WITH_ID_OPTIONS(ResponseList.class, "getMutualFriends", String.class, "userId1", String.class, "userId2", Reading.class, FacebookConstants.READING_PPROPERTY), - REMOVEFRIENDLISTMEMBER(Boolean.class, "removeFriendlistMember", String.class, "friendlistId", String.class, "userId"), - - // GameMethods - DELETEACHIEVEMENT(Boolean.class, "deleteAchievement", URL.class, "achievementURL"), - DELETEACHIEVEMENT_WITH_ID(Boolean.class, "deleteAchievement", String.class, "userId", URL.class , "achievementURL"), - DELETESCORE(Boolean.class, "deleteScore"), - DELETESCORE_WITH_ID(Boolean.class, "deleteScore", String.class, "userId"), - GETACHIEVEMENTS(ResponseList.class, "getAchievements"), - GETACHIEVEMENTS_WITH_OPTIONS(ResponseList.class, "getAchievements", Reading.class, FacebookConstants.READING_PPROPERTY), - GETACHIEVEMENTS_WITH_ID(ResponseList.class, "getAchievements", String.class, "userId"), - GETACHIEVEMENTS_WITH_ID_OPTIONS(ResponseList.class, "getAchievements", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETSCORES(ResponseList.class, "getScores"), - GETSCORES_WITH_OPTIONS(ResponseList.class, "getScores", Reading.class, FacebookConstants.READING_PPROPERTY), - GETSCORES_WITH_ID(ResponseList.class, "getScores", String.class, "userId"), - GETSCORES_WITH_ID_OPTIONS(ResponseList.class, "getScores", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - POSTACHIEVEMENT(String.class, "postAchievement", URL.class, "achievementURL"), - POSTACHIEVEMENT_WITH_ID(String.class, "postAchievement", String.class, "userId", URL.class, "achievementURL"), - POSTSCORE(Boolean.class, "postScore", int.class, "scoreValue"), - POSTSCORE_WITH_ID(Boolean.class, "postScore", String.class, "userId", int.class, "scoreValue"), - - // GroupMethods - GETGROUP(Group.class, "getGroup", String.class, "groupId"), - GETGROUP_WITH_OPTIONS(Group.class, "getGroup", String.class, "groupId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETGROUPDOCS(ResponseList.class, "getGroupDocs", String.class, "groupId"), - GETGROUPDOCS_WITH_OPTIONS(ResponseList.class, "getGroupDocs", String.class, "groupId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETGROUPFEED(ResponseList.class, "getGroupFeed", String.class, "groupId"), - GETGROUPFEED_WITH_OPTIONS(ResponseList.class, "getGroupFeed", String.class, "groupId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETGROUPMEMBERS(ResponseList.class, "getGroupMembers", String.class, "groupId"), - GETGROUPMEMBERS_WITH_OPTIONS(ResponseList.class, "getGroupMembers", String.class, "groupId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETGROUPPICTUREURL(URL.class, "getGroupPictureURL", String.class, "groupId"), - GETGROUPS(ResponseList.class, "getGroups"), - GETGROUPS_WITH_OPTIONS(ResponseList.class, "getGroups", Reading.class, FacebookConstants.READING_PPROPERTY), - GETGROUPS_WITH_ID(ResponseList.class, "getGroups", String.class, "userId"), - GETGROUPS_WITH_ID_OPTIONS(ResponseList.class, "getGroups", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - POSTGROUPFEED_WITH_POSTUPDATE(String.class, "postGroupFeed", String.class, "groupId", PostUpdate.class, "postUpdate"), - POSTGROUPLINK_WITH_LINK(String.class, "postGroupLink", String.class, "groupId", URL.class, "link"), - POSTGROUPLINK_WITH_LINK_MSG(String.class, "postGroupLink", String.class, "groupId", URL.class, "link", String.class, "message"), - POSTGROUPSTATUSMESSAGE(String.class, "postGroupStatusMessage", String.class, "groupId", String.class, "message"), - - // InsightMethods - GETINSIGHTS(ResponseList.class, "getInsights", String.class, "objectId", String.class, "metric"), - GETINSIGHTS_WITH_OPTIONS(ResponseList.class, "getInsights", String.class, "objectId", String.class, "metric", Reading.class, FacebookConstants.READING_PPROPERTY), - - // LikeMethods - GETUSERLIKES(ResponseList.class, "getUserLikes"), - GETUSERLIKES_WITH_OPTIONS(ResponseList.class, "getUserLikes", Reading.class, FacebookConstants.READING_PPROPERTY), - GETUSERLIKES_WITH_ID(ResponseList.class, "getUserLikes", String.class, "userId"), - GETUSERLIKES_WITH_ID_OPTIONS(ResponseList.class, "getUserLikes", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - - // LinkMethods - COMMENTLINK(String.class, "commentLink", String.class, "linkId", String.class, "message"), - GETLINK(Link.class, "getLink", String.class, "linkId"), - GETLINK_WITH_OPTIONS(Link.class, "getLink", String.class, "linkId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETLINKCOMMENTS(ResponseList.class, "getLinkComments", String.class, "linkId"), - GETLINKCOMMENTS_WITH_OPTIONS(ResponseList.class, "getLinkComments", String.class, "linkId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETLINKLIKES(ResponseList.class, "getLinkLikes", String.class, "linkId"), - GETLINKLIKES_WITH_OPTIONS(ResponseList.class, "getLinkLikes", String.class, "linkId", Reading.class, FacebookConstants.READING_PPROPERTY), - LIKELINK(Boolean.class, "likeLink", String.class, "linkId"), - UNLIKELINK(Boolean.class, "unlikeLink", String.class, "linkId"), - - // LocationMethods - GETLOCATIONS(ResponseList.class, "getLocations"), - GETLOCATIONS_WITH_OPTIONS(ResponseList.class, "getLocations", Reading.class, FacebookConstants.READING_PPROPERTY), - GETLOCATIONS_WITH_ID(ResponseList.class, "getLocations", String.class, "userId"), - GETLOCATIONS_WITH_ID_OPTIONS(ResponseList.class, "getLocations", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - - // MessageMethods - GETINBOX(InboxResponseList.class, "getInbox"), - GETINBOX_WITH_OPTIONS(InboxResponseList.class, "getInbox", Reading.class, FacebookConstants.READING_PPROPERTY), - GETINBOX_WITH_ID(InboxResponseList.class, "getInbox", String.class, "userId"), - GETINBOX_WITH_ID_OPTIONS(InboxResponseList.class, "getInbox", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETMESSAGE(Message.class, "getMessage", String.class, "messageId"), - GETMESSAGE_WITH_OPTIONS(Message.class, "getMessage", String.class, "messageId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETOUTBOX(ResponseList.class, "getOutbox"), - GETOUTBOX_WITH_OPTIONS(ResponseList.class, "getOutbox", Reading.class, FacebookConstants.READING_PPROPERTY), - GETOUTBOX_WITH_ID(ResponseList.class, "getOutbox", String.class, "userId"), - GETOUTBOX_WITH_ID_OPTIONS(ResponseList.class, "getOutbox", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETUPDATES(ResponseList.class, "getUpdates"), - GETUPDATES_WITH_OPTIONS(ResponseList.class, "getUpdates", Reading.class, FacebookConstants.READING_PPROPERTY), - GETUPDATES_WITH_ID(ResponseList.class, "getUpdates", String.class, "userId"), - GETUPDATES_WITH_ID_OPTIONS(ResponseList.class, "getUpdates", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - - // NoteMethods - COMMENTNOTE(String.class, "commentNote", String.class, "noteId", String.class, "message"), - CREATENOTE(String.class, "createNote", String.class, "subject", String.class, "message"), - CREATENOTE_WITH_ID_MSG(String.class, "createNote", String.class, "userId", String.class, "subject", String.class, "message"), - GETNOTE(Note.class, "getNote", String.class, "noteId"), - GETNOTE_WITH_OPTIONS(Note.class, "getNote", String.class, "noteId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETNOTECOMMENTS(ResponseList.class, "getNoteComments", String.class, "noteId"), - GETNOTECOMMENTS_WITH_OPTIONS(ResponseList.class, "getNoteComments", String.class, "noteId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETNOTELIKES(ResponseList.class, "getNoteLikes", String.class, "noteId"), - GETNOTELIKES_WITH_OPTIONS(ResponseList.class, "getNoteLikes", String.class, "noteId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETNOTES(ResponseList.class, "getNotes"), - GETNOTES_WITH_OPTIONS(ResponseList.class, "getNotes", Reading.class, FacebookConstants.READING_PPROPERTY), - GETNOTES_WITH_ID(ResponseList.class, "getNotes", String.class, "userId"), - GETNOTES_WITH_ID_OPTIONS(ResponseList.class, "getNotes", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - LIKENOTE(Boolean.class, "likeNote", String.class, "noteId"), - UNLIKENOTE(Boolean.class, "unlikeNote", String.class, "noteId"), - - // NotificationMethods - GETNOTIFICATIONS(ResponseList.class, "getNotifications"), - GETNOTIFICATIONS_WITH_INCLUDEREAD(ResponseList.class, "getNotifications", boolean.class, "includeRead"), - GETNOTIFICATIONS_WITH_OPTIONS(ResponseList.class, "getNotifications", Reading.class, FacebookConstants.READING_PPROPERTY), - GETNOTIFICATIONS_WITH_OPTIONS_INCLUDEREAD(ResponseList.class, "getNotifications", Reading.class, FacebookConstants.READING_PPROPERTY, boolean.class, "includeRead"), - GETNOTIFICATIONS_WITH_ID(ResponseList.class, "getNotifications", String.class, "userId"), - GETNOTIFICATIONS_WITH_ID_INCLUDEREAD(ResponseList.class, "getNotifications", String.class, "userId", boolean.class, "includeRead"), - GETNOTIFICATIONS_WITH_ID_OPTIONS(ResponseList.class, "getNotifications", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETNOTIFICATIONS_WITH_ID_OPTIONS_INCLUDEREAD(ResponseList.class, "getNotifications", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY, boolean.class, "includeRead"), - MARKNOTIFICATIONASREAD(Boolean.class, "markNotificationAsRead", String.class, "notificationId"), - - // PermissionMethods - GETPERMISSIONS(List.class, "getPermissions"), - GETPERMISSIONS_WITH_ID(List.class, "getPermissions", String.class, "userId"), - REVOKEPERMISSION(Boolean.class, "revokePermission", String.class, "permissionName"), - REVOKEPERMISSION_WITH_ID(Boolean.class, "revokePermission", String.class, "userId", String.class, "permissionName"), - - // PhotoMethods - ADDTAGTOPHOTO(Boolean.class, "addTagToPhoto", String.class, "photoId", String.class, "toUserId"), - ADDTAGTOPHOTO_WITH_IDS(Boolean.class, "addTagToPhoto", String.class, "photoId", List.class, "toUserIds"), - ADDTAGTOPHOTO_WITH_TAGUPDATE(Boolean.class, "addTagToPhoto", String.class, "photoId", TagUpdate.class, "tagUpdate"), - COMMENTPHOTO(String.class, "commentPhoto", String.class, "photoId", String.class, "message"), - DELETEPHOTO(Boolean.class, "deletePhoto", String.class, "photoId"), - GETPHOTO(Photo.class, "getPhoto", String.class, "photoId"), - GETPHOTO_WITH_OPTIONS(Photo.class, "getPhoto", String.class, "photoId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETPHOTOCOMMENTS(ResponseList.class, "getPhotoComments", String.class, "photoId"), - GETPHOTOCOMMENTS_WITH_OPTIONS(ResponseList.class, "getPhotoComments", String.class, "photoId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETPHOTOLIKES(ResponseList.class, "getPhotoLikes", String.class, "photoId"), - GETPHOTOLIKES_WITH_OPTIONS(ResponseList.class, "getPhotoLikes", String.class, "photoId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETPHOTOS(ResponseList.class, "getPhotos"), - GETPHOTOS_WITH_OPTIONS(ResponseList.class, "getPhotos", Reading.class, FacebookConstants.READING_PPROPERTY), - GETPHOTOS_WITH_ID(ResponseList.class, "getPhotos", String.class, "userId"), - GETPHOTOS_WITH_ID_OPTIONS(ResponseList.class, "getPhotos", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETPHOTOURL(URL.class, "getPhotoURL", String.class, "photoId"), - GETTAGSONPHOTO(ResponseList.class, "getTagsOnPhoto", String.class, "photoId"), - GETTAGSONPHOTO_WITH_OPTIONS(ResponseList.class, "getTagsOnPhoto", String.class, "photoId", Reading.class, FacebookConstants.READING_PPROPERTY), - LIKEPHOTO(Boolean.class, "likePhoto", String.class, "photoId"), - POSTPHOTO(String.class, "postPhoto", Media.class, "source"), - POSTPHOTO_WITH_MSG(String.class, "postPhoto", Media.class, "source", String.class, "message", String.class, "place", boolean.class, "noStory"), - POSTPHOTO_WITH_MEDIA(String.class, "postPhoto", String.class, "userId", Media.class, "source"), - POSTPHOTO_WITH_MEDIA_MSG(String.class, "postPhoto", String.class, "userId", Media.class, "source", String.class, "message", String.class, "place", boolean.class, "noStory"), - UNLIKEPHOTO(Boolean.class, "unlikePhoto", String.class, "photoId"), - UPDATETAGONPHOTO(Boolean.class, "updateTagOnPhoto", String.class, "photoId", String.class, "toUserId"), - UPDATETAGONPHOTO_WITH_TAGUPDATE(Boolean.class, "updateTagOnPhoto", String.class, "photoId", TagUpdate.class, "tagUpdate"), - - // PokeMethods - GETPOKES(ResponseList.class, "getPokes"), - GETPOKES_WITH_OPTIONS(ResponseList.class, "getPokes", Reading.class, FacebookConstants.READING_PPROPERTY), - GETPOKES_WITH_ID(ResponseList.class, "getPokes", String.class, "userId"), - GETPOKES_WITH_ID_OPTIONS(ResponseList.class, "getPokes", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - - // PostMethods - COMMENTPOST(String.class, "commentPost", String.class, "postId", String.class, "message"), - DELETEPOST(Boolean.class, "deletePost", String.class, "postId"), - GETFEED(ResponseList.class, "getFeed"), - GETFEED_WITH_OPTIONS(ResponseList.class, "getFeed", Reading.class, FacebookConstants.READING_PPROPERTY), - GETFEED_WITH_ID(ResponseList.class, "getFeed", String.class, "userId"), - GETFEED_WITH_ID_OPTIONS(ResponseList.class, "getFeed", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETHOME(ResponseList.class, "getHome"), - GETHOME_WITH_OPTIONS(ResponseList.class, "getHome", Reading.class, FacebookConstants.READING_PPROPERTY), - GETLINKS(ResponseList.class, "getLinks"), - GETLINKS_WITH_OPTIONS(ResponseList.class, "getLinks", Reading.class, FacebookConstants.READING_PPROPERTY), - GETLINKS_WITH_ID(ResponseList.class, "getLinks", String.class, "userId"), - GETLINKS_WITH_ID_OPTIONS(ResponseList.class, "getLinks", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETPOST(Post.class, "getPost", String.class, "postId"), - GETPOST_WITH_OPTIONS(Post.class, "getPost", String.class, "postId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETPOSTCOMMENTS(ResponseList.class, "getPostComments", String.class, "postId"), - GETPOSTCOMMENTS_WITH_OPTIONS(ResponseList.class, "getPostComments", String.class, "postId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETPOSTLIKES(ResponseList.class, "getPostLikes", String.class, "postId"), - GETPOSTLIKES_WITH_OPTIONS(ResponseList.class, "getPostLikes", String.class, "postId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETPOSTS(ResponseList.class, "getPosts"), - GETPOSTS_WITH_OPTIONS(ResponseList.class, "getPosts", Reading.class, FacebookConstants.READING_PPROPERTY), - GETPOSTS_WITH_ID(ResponseList.class, "getPosts", String.class, "userId"), - GETPOSTS_WITH_ID_OPTIONS(ResponseList.class, "getPosts", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETSTATUSES(ResponseList.class, "getStatuses"), - GETSTATUSES_WITH_OPTIONS(ResponseList.class, "getStatuses", Reading.class, FacebookConstants.READING_PPROPERTY), - GETSTATUSES_WITH_ID(ResponseList.class, "getStatuses", String.class, "userId"), - GETSTATUSES_WITH_ID_OPTIONS(ResponseList.class, "getStatuses", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETTAGGED(ResponseList.class, "getTagged"), - GETTAGGED_WITH_OPTIONS(ResponseList.class, "getTagged", Reading.class, FacebookConstants.READING_PPROPERTY), - GETTAGGED_WITH_ID(ResponseList.class, "getTagged", String.class, "userId"), - GETTAGGED_WITH_ID_OPTIONS(ResponseList.class, "getTagged", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - LIKEPOST(Boolean.class, "likePost", String.class, "postId"), - POSTFEED(String.class, "postFeed", PostUpdate.class, "postUpdate"), - POSTFEED_WITH_POSTUPDATE(String.class, "postFeed", String.class, "userId", PostUpdate.class, "postUpdate"), - POSTLINK(String.class, "postLink", URL.class, "link"), - POSTLINK_WITH_MSG(String.class, "postLink", URL.class, "link", String.class, "message"), - POSTLINK_WITH_ID(String.class, "postLink", String.class, "userId", URL.class, "link"), - POSTLINK_WITH_ID_MSG(String.class, "postLink", String.class, "userId", URL.class, "link", String.class, "message"), - POSTSTATUSMESSAGE(String.class, "postStatusMessage", String.class, "message"), - POSTSTATUSMESSAGE_WITH_ID(String.class, "postStatusMessage", String.class, "userId", String.class, "message"), - UNLIKEPOST(Boolean.class, "unlikePost", String.class, "postId"), - - // QuestionMethods - ADDQUESTIONOPTION(String.class, "addQuestionOption", String.class, "questionId", String.class, "optionDescription"), - CREATEQUESTION(String.class, "createQuestion", String.class, "question"), - CREATEQUESTION_WITH_OPTIONS(String.class, "createQuestion", String.class, "question", List.class, "options", boolean.class, "allowNewOptions"), - CREATEQUESTION_WITH_ID(String.class, "createQuestion", String.class, "userId", String.class, "question"), - CREATEQUESTION_WITH_ID_OPTIONS(String.class, "createQuestion", String.class, "userId", String.class, "question", List.class, "options", boolean.class, "allowNewOptions"), - DELETEQUESTION(Boolean.class, "deleteQuestion", String.class, "questionId"), - GETQUESTION(Question.class, "getQuestion", String.class, "questionId"), - GETQUESTION_WITH_OPTIONS(Question.class, "getQuestion", String.class, "questionId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETQUESTIONOPTIONS(ResponseList.class, "getQuestionOptions", String.class, "questionId"), - GETQUESTIONOPTIONS_WITH_OPTIONS(ResponseList.class, "getQuestionOptions", String.class, "questionId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETQUESTIONOPTIONVOTES(ResponseList.class, "getQuestionOptionVotes", String.class, "questionId"), - GETQUESTIONS(ResponseList.class, "getQuestions"), - GETQUESTIONS_WITH_OPTIONS(ResponseList.class, "getQuestions", Reading.class, FacebookConstants.READING_PPROPERTY), - GETQUESTIONS_WITH_ID(ResponseList.class, "getQuestions", String.class, "userId"), - GETQUESTIONS_WITH_ID_OPTIONS(ResponseList.class, "getQuestions", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - - // SubscribeMethods - GETSUBSCRIBEDTO(ResponseList.class, "getSubscribedto"), - GETSUBSCRIBEDTO_WITH_OPTIONS(ResponseList.class, "getSubscribedto", Reading.class, FacebookConstants.READING_PPROPERTY), - GETSUBSCRIBEDTO_WITH_ID(ResponseList.class, "getSubscribedto", String.class, "userId"), - GETSUBSCRIBEDTO_WITH_ID_OPTIONS(ResponseList.class, "getSubscribedto", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETSUBSCRIBERS(ResponseList.class, "getSubscribers"), - GETSUBSCRIBERS_WITH_OPTIONS(ResponseList.class, "getSubscribers", Reading.class, FacebookConstants.READING_PPROPERTY), - GETSUBSCRIBERS_WITH_ID(ResponseList.class, "getSubscribers", String.class, "userId"), - GETSUBSCRIBERS_WITH_ID_OPTIONS(ResponseList.class, "getSubscribers", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - - // TestUserMethods - CREATETESTUSER(TestUser.class, "createTestUser", String.class, "appId"), - CREATETESTUSER_WITH_NAME(TestUser.class, "createTestUser", String.class, "appId", String.class, "name", String.class, "userLocale", String.class, "permissions"), - DELETETESTUSER(Boolean.class, "deleteTestUser", String.class, "testUserId"), - GETTESTUSERS(List.class, "getTestUsers", String.class, "appId"), - MAKEFRIENDTESTUSER(Boolean.class, "makeFriendTestUser", TestUser.class, "testUser1", TestUser.class, "testUser2"), - - // UserMethods - GETME(User.class, "getMe"), - GETME_WITH_OPTIONS(User.class, "getMe", Reading.class, FacebookConstants.READING_PPROPERTY), - GETPICTUREURL(URL.class, "getPictureURL"), - GETPICTUREURL_WITH_PICTURESIZE(URL.class, "getPictureURL", PictureSize.class, "size"), - GETPICTUREURL_WITH_ID(URL.class, "getPictureURL", String.class, "userId"), - GETPICTUREURL_WITH_ID_PICTURESIZE(URL.class, "getPictureURL", String.class, "userId", PictureSize.class, "size"), - GETUSER(User.class, "getUser", String.class, "userId"), - GETUSER_WITH_OPTIONS(User.class, "getUser", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETUSERS(List.class, "getUsers", new String[0].getClass(), "ids"), - - // VideoMethods - COMMENTVIDEO(String.class, "commentVideo", String.class, "videoId", String.class, "message"), - GETVIDEO(Video.class, "getVideo", String.class, "videoId"), - GETVIDEO_WITH_OPTIONS(Video.class, "getVideo", String.class, "videoId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETVIDEOCOMMENTS(ResponseList.class, "getVideoComments", String.class, "videoId"), - GETVIDEOCOMMENTS_WITH_OPTIONS(ResponseList.class, "getVideoComments", String.class, "videoId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETVIDEOCOVER(URL.class, "getVideoCover", String.class, "videoId"), - GETVIDEOLIKES(ResponseList.class, "getVideoLikes", String.class, "videoId"), - GETVIDEOLIKES_WITH_OPTIONS(ResponseList.class, "getVideoLikes", String.class, "videoId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETVIDEOS(ResponseList.class, "getVideos"), - GETVIDEOS_WITH_OPTIONS(ResponseList.class, "getVideos", Reading.class, FacebookConstants.READING_PPROPERTY), - GETVIDEOS_WITH_ID(ResponseList.class, "getVideos", String.class, "userId"), - GETVIDEOS_WITH_ID_OPTIONS(ResponseList.class, "getVideos", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - LIKEVIDEO(Boolean.class, "likeVideo", String.class, "videoId"), - POSTVIDEO(String.class, "postVideo", Media.class, "source"), - POSTVIDEO_WITH_TITLE(String.class, "postVideo", Media.class, "source", String.class, "title", String.class, "description"), - POSTVIDEO_WITH_ID(String.class, "postVideo", String.class, "userId", Media.class, "source"), - POSTVIDEO_WITH_ID_MEDIA(String.class, "postVideo", String.class, "userId", Media.class, "source", String.class, "title", String.class, "description"), - UNLIKEVIDEO(Boolean.class, "unlikeVideo", String.class, "videoId"), - - // SearchMethods get the highest priority with higher ordinal values - SEARCH(ResponseList.class, "search", String.class, "query"), - SEARCH_WITH_OPTIONS(ResponseList.class, "search", String.class, "query", Reading.class, FacebookConstants.READING_PPROPERTY), - SEARCHCHECKINS(ResponseList.class, "searchCheckins"), - SEARCHCHECKINS_WITH_OPTIONS(ResponseList.class, "searchCheckins", Reading.class, FacebookConstants.READING_PPROPERTY), - SEARCHEVENTS(ResponseList.class, "searchEvents", String.class, "query"), - SEARCHEVENTS_WITH_OPTIONS(ResponseList.class, "searchEvents", String.class, "query", Reading.class, FacebookConstants.READING_PPROPERTY), - SEARCHGROUPS(ResponseList.class, "searchGroups", String.class, "query"), - SEARCHGROUPS_WITH_OPTIONS(ResponseList.class, "searchGroups", String.class, "query", Reading.class, FacebookConstants.READING_PPROPERTY), - SEARCHLOCATIONS(ResponseList.class, "searchLocations", GeoLocation.class, "center", int.class, "distance"), - SEARCHLOCATIONS_WITH_OPTIONS(ResponseList.class, "searchLocations", GeoLocation.class, "center", int.class, "distance", Reading.class, FacebookConstants.READING_PPROPERTY), - SEARCHLOCATIONS_WITH_ID(ResponseList.class, "searchLocations", String.class, "placeId"), - SEARCHLOCATIONS_WITH_ID_OPTIONS(ResponseList.class, "searchLocations", String.class, "placeId", Reading.class, FacebookConstants.READING_PPROPERTY), - SEARCHPLACES(ResponseList.class, "searchPlaces", String.class, "query"), - SEARCHPLACES_WITH_OPTIONS(ResponseList.class, "searchPlaces", String.class, "query", Reading.class, FacebookConstants.READING_PPROPERTY), - SEARCHPLACES_WITH_CENTER(ResponseList.class, "searchPlaces", String.class, "query", GeoLocation.class, "center", int.class, "distance"), - SEARCHPLACES_WITH_CENTER_OPTIONS(ResponseList.class, "searchPlaces", String.class, "query", GeoLocation.class, "center", int.class, "distance", Reading.class, FacebookConstants.READING_PPROPERTY), - SEARCHPOSTS(ResponseList.class, "searchPosts", String.class, "query"), - SEARCHPOSTS_WITH_OPTIONS(ResponseList.class, "searchPosts", String.class, "query", Reading.class, FacebookConstants.READING_PPROPERTY), - SEARCHUSERS(ResponseList.class, "searchUsers", String.class, "query"), - SEARCHUSERS_WITH_OPTIONS(ResponseList.class, "searchUsers", String.class, "query", Reading.class, FacebookConstants.READING_PPROPERTY); - - // name, result class, ordered argument names and classes, and Method to invoke - private final String name; - private final Class resultType; - private final List argNames; - private final List argTypes; - private final Method method; - - private FacebookMethodsType(Class resultType, String name, Object... args) throws IllegalArgumentException { - this.name = name; - this.resultType = resultType; - - if (args.length % 2 != 0) { - throw new IllegalArgumentException("Invalid parameter list, " - + "must be of the form 'Class arg1, String arg1Name, Class arg2, String arg2Name..."); - } - int nArgs = args.length / 2; - this.argNames = new ArrayList(nArgs); - this.argTypes = new ArrayList(nArgs); - for (int i = 0; i < nArgs; i++) { - this.argTypes.add((Class) args[i * 2]); - this.argNames.add((String) args[i * 2 + 1]); - } - - // find method in Facebook type - try { - this.method = Facebook.class.getMethod(name, argTypes.toArray(new Class[nArgs])); - } catch (NoSuchMethodException e) { - throw new IllegalArgumentException( - String.format("Missing method %s %s", name, argTypes.toString().replace('[', '(').replace(']', ')')), - e); - } - } - - /** - * Find method type by name and argument types. - * @param name method name - * @param args ordered argument types - * @return matching method, null if not found - */ - public static FacebookMethodsType findMethod(String name, Class... args) { - for (FacebookMethodsType method : values()) { - if (method.name.equals(name)) { - if ((method.argTypes.isEmpty() && (args == null || args.length == 0)) - || Arrays.equals(method.argTypes.toArray(), args)) { - return method; - } - } - } - - return null; - } - - public String getName() { - return name; - } - - public Class getResultType() { - return resultType; - } - - public List getArgNames() { - return Collections.unmodifiableList(argNames); - } - - public List getArgTypes() { - return Collections.unmodifiableList(argTypes); - } - - public Method getMethod() { - return method; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("{") - .append("name=").append(name) - .append(", resultType=").append(resultType) - .append(", argNames=").append(argNames) - .append(", argTypes=").append(argTypes) - .append("}"); - return builder.toString(); - } - -} diff --git a/components/camel-facebook/src/main/java/org/apache/camel/facebook/data/FacebookMethodsTypeHelper.java b/components/camel-facebook/src/main/java/org/apache/camel/facebook/data/FacebookMethodsTypeHelper.java deleted file mode 100644 index ce7e60c94cd81..0000000000000 --- a/components/camel-facebook/src/main/java/org/apache/camel/facebook/data/FacebookMethodsTypeHelper.java +++ /dev/null @@ -1,350 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.facebook.data; - -import java.lang.reflect.Array; -import java.lang.reflect.InvocationTargetException; -import java.util.*; - -import facebook4j.Facebook; -import org.apache.camel.facebook.FacebookConstants; -import org.apache.camel.facebook.config.FacebookNameStyle; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Helper class for working with {@link FacebookMethodsType}. - */ -public final class FacebookMethodsTypeHelper { - - private static final Logger LOG = LoggerFactory.getLogger(FacebookMethodsTypeHelper.class); - - // maps method name to FacebookMethodsType - private static final Map> METHOD_MAP = - new HashMap>(); - - // maps method name to method arguments of the form Class type1, String name1, Class type2, String name2,... - private static final Map> ARGUMENTS_MAP = - new HashMap>(); - - // maps argument name to argument type - private static final Map VALID_ARGUMENTS = - new HashMap(); - - static { - final FacebookMethodsType[] methods = FacebookMethodsType.values(); - // load lookup maps for FacebookMethodsType - for (FacebookMethodsType method : methods) { - - // map method name to Enum - final String name = method.getName(); - List overloads = METHOD_MAP.get(name); - if (overloads == null) { - overloads = new ArrayList(); - METHOD_MAP.put(method.getName(), overloads); - } - overloads.add(method); - - // add arguments for this method - List arguments = ARGUMENTS_MAP.get(name); - if (arguments == null) { - arguments = new ArrayList(); - ARGUMENTS_MAP.put(name, arguments); - } - - // process all arguments for this method - final int nArgs = method.getArgNames().size(); - final String[] argNames = method.getArgNames().toArray(new String[nArgs]); - final Class[] argTypes = method.getArgTypes().toArray(new Class[nArgs]); - for (int i = 0; i < nArgs; i++) { - final String argName = argNames[i]; - final Class argType = argTypes[i]; - if (!arguments.contains(argName)) { - arguments.add(argType); - arguments.add(argName); - } - - // also collect argument names for all methods, also detect clashes here - final Class previousType = VALID_ARGUMENTS.get(argName); - if (previousType != null && previousType != argType) { - throw new ExceptionInInitializerError(String.format( - "Argument %s has ambiguous types (%s, %s) across methods!", - name, previousType, argType)); - } else if (previousType == null) { - VALID_ARGUMENTS.put(argName, argType); - } - } - - } - - // add endpoint parameter inBody for producers - VALID_ARGUMENTS.put(FacebookConstants.IN_BODY_PROPERTY, String.class); - - LOG.debug("Found {} unique method names in {} methods", METHOD_MAP.size(), methods.length); - - } - - private FacebookMethodsTypeHelper() { - } - - /** - * Gets methods that match the given name and arguments.

- * Note that the args list is a required subset of arguments for returned methods. - * @param name case sensitive full method name to lookup - * @param argNames unordered required argument names - * @return non-null unmodifiable list of methods that take all of the given arguments, empty if there is no match - */ - public static List getCandidateMethods(String name, String... argNames) { - final List methods = METHOD_MAP.get(name); - if (methods == null) { - LOG.debug("No matching method for method {}", name); - return Collections.emptyList(); - } - int nArgs = argNames != null ? argNames.length : 0; - if (nArgs == 0) { - LOG.debug("Found {} methods for method {}", methods.size(), name); - return Collections.unmodifiableList(methods); - } else { - final List filteredSet = filterMethods(methods, MatchType.SUBSET, argNames); - if (LOG.isDebugEnabled()) { - LOG.debug("Found {} filtered methods for {}", - filteredSet.size(), name + Arrays.toString(argNames).replace('[', '(').replace(']', ')')); - } - return filteredSet; - } - } - - /** - * Filters a list of methods to those that take the given set of arguments. - * - * @param methods list of methods to filter - * @param matchType whether the arguments are an exact match, a subset or a super set of method args - * @param argNames argument names to filter the list - * @return methods with arguments that satisfy the match type.

- * For SUPER_SET match, if methods with exact match are found, methods that take a subset are ignored - */ - public static List filterMethods(List methods, MatchType matchType, - String... argNames) { - List argsList = Arrays.asList(argNames); - // list of methods that have all args in the given names - final List result = new ArrayList(); - final List extraArgs = new ArrayList(); - - for (FacebookMethodsType method : methods) { - final List methodArgs = method.getArgNames(); - switch (matchType) { - case EXACT: - // method must take all args, and no more - if (methodArgs.containsAll(argsList) && argsList.containsAll(methodArgs)) { - result.add(method); - } - break; - case SUBSET: - // all args are required, method may take more - if (methodArgs.containsAll(argsList)) { - result.add(method); - } - break; - case SUPER_SET: - // all method args must be present - if (argsList.containsAll(methodArgs)) { - if (methodArgs.containsAll(argsList)) { - // prefer exact match to avoid unused args - result.add(method); - } else { - // method takes a subset, unused args - extraArgs.add(method); - } - } - break; - } - } - - return Collections.unmodifiableList(result.isEmpty() ? extraArgs : result); - } - - /** - * Gets argument types and names for all overloaded methods with the given name. - * @param name method name, must be a long form (i.e. get*, or search*) - * @return list of arguments of the form Class type1, String name1, Class type2, String name2,... - */ - public static List getArguments(String name) throws IllegalArgumentException { - final List arguments = ARGUMENTS_MAP.get(name); - if (arguments == null) { - throw new IllegalArgumentException(name); - } - return Collections.unmodifiableList(arguments); - } - - /** - * Gets argument types and names for all overloaded methods with the given short form name. - * @param name method name, may be a short form - * @param style name style - * @return list of arguments of the form Class type1, String name1, Class type2, String name2,... - */ - public static List getArgumentsForNameStyle(String name, FacebookNameStyle style) throws IllegalArgumentException { - if (style == null) { - throw new IllegalArgumentException("Parameters style cannot be null"); - } - switch (style) { - case EXACT: - return getArguments(name); - case GET: - return getArguments(convertToGetMethod(name)); - case SEARCH: - return getArguments(convertToSearchMethod(name)); - case GET_AND_SEARCH: - default: - final List arguments = new ArrayList(); - arguments.addAll(getArguments(convertToGetMethod(name))); - arguments.addAll(getArguments(convertToSearchMethod(name))); - return Collections.unmodifiableList(arguments); - } - } - - /** - * Get missing properties. - * @param methodName method name - * @param nameStyle method name style - * @param argNames available arguments - * @return Set of missing argument names - */ - public static Set getMissingProperties(String methodName, FacebookNameStyle nameStyle, Set argNames) { - final List argsWithTypes = getArgumentsForNameStyle(methodName, nameStyle); - final Set missingArgs = new HashSet(); - - for (int i = 1; i < argsWithTypes.size(); i += 2) { - final String name = (String) argsWithTypes.get(i); - if (!argNames.contains(name)) { - missingArgs.add(name); - } - } - - return missingArgs; - } - - /** - * Get argument types and names used by all methods. - * @return map with argument names as keys, and types as values - */ - public static Map allArguments() { - return Collections.unmodifiableMap(VALID_ARGUMENTS); - } - - /** - * Get the type for the given argument name. - * @param argName argument name - * @return argument type - */ - public static Class getType(String argName) throws IllegalArgumentException { - final Class type = VALID_ARGUMENTS.get(argName); - if (type == null) { - throw new IllegalArgumentException(argName); - } - return type; - } - - public static String convertToGetMethod(String name) throws IllegalArgumentException { - if (name == null || name.isEmpty()) { - throw new IllegalArgumentException("Name cannot be null or empty"); - } - return "get" + Character.toUpperCase(name.charAt(0)) + name.substring(1); - } - - public static String convertToSearchMethod(String name) throws IllegalArgumentException { - if (name == null || name.isEmpty()) { - throw new IllegalArgumentException("Name cannot be null or empty"); - } - return "search" + Character.toUpperCase(name.charAt(0)) + name.substring(1); - } - - public static FacebookMethodsType getHighestPriorityMethod(List filteredMethods) { - FacebookMethodsType highest = null; - for (FacebookMethodsType method : filteredMethods) { - if (highest == null || method.ordinal() > highest.ordinal()) { - highest = method; - } - } - return highest; - } - - /** - * Invokes given method with argument values from given properties. - * - * @param facebook Facebook4J target object for invoke - * @param method method to invoke - * @param properties Map of arguments - * @return result of method invocation - * @throws InvocationTargetException, IllegalAccessException on invocation errors - */ - public static Object invokeMethod( - Facebook facebook, FacebookMethodsType method, Map properties) - throws InvocationTargetException, IllegalAccessException { - - LOG.debug("Invoking {} with arguments {}", method.getName(), properties); - - final List argNames = method.getArgNames(); - final Object[] values = new Object[argNames.size()]; - final List argTypes = method.getArgTypes(); - final Class[] types = argTypes.toArray(new Class[argTypes.size()]); - int index = 0; - for (String name : argNames) { - Object value = properties.get(name); - - // is the parameter an array type? - if (value != null && types[index].isArray()) { - Class type = types[index]; - - if (value instanceof Collection) { - // convert collection to array - Collection collection = (Collection) value; - Object array = Array.newInstance(type.getComponentType(), collection.size()); - if (array instanceof Object[]) { - collection.toArray((Object[]) array); - } else { - int i = 0; - for (Object el : collection) { - Array.set(array, i++, el); - } - } - value = array; - } else if (value.getClass().isArray() && - type.getComponentType().isAssignableFrom(value.getClass().getComponentType())) { - // convert derived array to super array - final int size = Array.getLength(value); - Object array = Array.newInstance(type.getComponentType(), size); - for (int i = 0; i < size; i++) { - Array.set(array, i, Array.get(value, i)); - } - value = array; - } else { - throw new IllegalArgumentException( - String.format("Cannot convert %s to %s", value.getClass(), type)); - } - } - - values[index++] = value; - } - - return method.getMethod().invoke(facebook, values); - } - - public static enum MatchType { - EXACT, SUBSET, SUPER_SET; - } - -} diff --git a/components/camel-facebook/src/main/java/org/apache/camel/facebook/data/FacebookPropertiesHelper.java b/components/camel-facebook/src/main/java/org/apache/camel/facebook/data/FacebookPropertiesHelper.java deleted file mode 100644 index 0050b19b4224a..0000000000000 --- a/components/camel-facebook/src/main/java/org/apache/camel/facebook/data/FacebookPropertiesHelper.java +++ /dev/null @@ -1,132 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.facebook.data; - -import java.lang.reflect.Field; -import java.util.*; -import org.apache.camel.Exchange; -import org.apache.camel.facebook.FacebookConstants; -import org.apache.camel.facebook.config.FacebookConfiguration; -import org.apache.camel.facebook.config.FacebookEndpointConfiguration; -import org.apache.camel.util.IntrospectionSupport; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import facebook4j.Reading; - -/** - * Helper class to work with Facebook component properties. - */ -public final class FacebookPropertiesHelper { - - // set of field names which are specific to Facebook4J api, to be excluded from method argument considerations - private static final Set COMPONENT_CONFIG_FIELDS = new HashSet(); - - private static final Logger LOG = LoggerFactory.getLogger(FacebookPropertiesHelper.class); - - private static final Set ENDPOINT_CONFIG_FIELDS = new HashSet(); - - static { - for (Field field : FacebookConfiguration.class.getDeclaredFields()) { - COMPONENT_CONFIG_FIELDS.add(field.getName()); - } - for (Field field : FacebookEndpointConfiguration.class.getDeclaredFields()) { - ENDPOINT_CONFIG_FIELDS.add(field.getName()); - } - } - - private FacebookPropertiesHelper() { - // utility - } - - /** - * Apply properties for {@link Reading} type to the supplied {@link FacebookEndpointConfiguration}. - * @param configuration endpoint configuration to update - * @param options properties to apply to the reading field in configuration - */ - public static void configureReadingProperties(FacebookEndpointConfiguration configuration, - Map options) { - final Map readingProperties = IntrospectionSupport.extractProperties( - options, FacebookConstants.READING_PREFIX); - 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, - readingProperties); - - // update reading in configuration - configuration.setReading(reading); - - } catch (Exception e) { - throw new IllegalArgumentException(readingProperties.toString(), e); - } - - // add any unknown properties back to options to throw an error later - for (Map.Entry entry : readingProperties.entrySet()) { - options.put(FacebookConstants.READING_PREFIX + entry.getKey(), entry.getValue()); - } - } - } - - /** - * Gets exchange header properties that start with {@link FacebookConstants}.FACEBOOK_PROPERTY_PREFIX. - * - * @param exchange Camel exchange - * @param properties map to collect properties with required prefix - */ - public static Map getExchangeProperties(Exchange exchange, Map properties) { - int nProperties = 0; - for (Map.Entry entry : exchange.getIn().getHeaders().entrySet()) { - if (entry.getKey().startsWith(FacebookConstants.FACEBOOK_PROPERTY_PREFIX)) { - properties.put(entry.getKey().substring(FacebookConstants.FACEBOOK_PROPERTY_PREFIX.length()), - entry.getValue()); - nProperties++; - } - } - LOG.debug("Found {} properties in exchange", nProperties); - return properties; - } - - public static void getEndpointProperties(FacebookEndpointConfiguration configuration, - Map properties) { - if (IntrospectionSupport.getProperties(configuration, properties, null, false)) { - final Set names = properties.keySet(); - // remove component config properties so we only have endpoint properties - names.removeAll(COMPONENT_CONFIG_FIELDS); - } - if (LOG.isDebugEnabled()) { - final Set names = properties.keySet(); - LOG.debug("Found endpoint properties {}", names.retainAll(ENDPOINT_CONFIG_FIELDS)); - } - } - - public static Set getEndpointPropertyNames(FacebookEndpointConfiguration configuration) { - Map properties = new HashMap(); - getEndpointProperties(configuration, properties); - return Collections.unmodifiableSet(properties.keySet()); - } - -} diff --git a/components/camel-facebook/src/main/java/org/apache/camel/facebook/data/ReadingBuilder.java b/components/camel-facebook/src/main/java/org/apache/camel/facebook/data/ReadingBuilder.java deleted file mode 100644 index 06aa555df4557..0000000000000 --- a/components/camel-facebook/src/main/java/org/apache/camel/facebook/data/ReadingBuilder.java +++ /dev/null @@ -1,121 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.facebook.data; - -import java.lang.reflect.Field; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.LinkedHashMap; -import java.util.Locale; -import java.util.Map; -import org.apache.camel.facebook.FacebookConstants; - -import facebook4j.Reading; - -/** - * Builds {@link facebook4j.Reading} instances. - */ -public class ReadingBuilder { - - - public static Reading copy(Reading reading, boolean skipSinceUtil) throws NoSuchFieldException, IllegalAccessException { - // use private field access to make a copy - Field field = Reading.class.getDeclaredField("parameterMap"); - field.setAccessible(true); - final LinkedHashMap source = (LinkedHashMap) field.get(reading); - // create another reading, and add all fields from source - Reading copy = new Reading(); - final LinkedHashMap copyMap = new LinkedHashMap(); - copyMap.putAll(source); - if (skipSinceUtil) { - copyMap.remove("since"); - copyMap.remove("until"); - } - field.set(copy, copyMap); - field.setAccessible(false); - return copy; - } - - /** - * Sets Reading properties. - * @param reading Reading object to populate - * @param readingProperties Map to extract properties - */ - public static void setProperties(Reading reading, Map readingProperties) { - - final String fields = (String) readingProperties.remove("fields"); - if (fields != null) { - reading.fields(fields.toString().split(",")); - } - final Object limit = readingProperties.remove("limit"); - if (limit != null) { - reading.limit(Integer.parseInt(limit.toString())); - } - final Object offset = readingProperties.remove("offset"); - if (offset != null) { - reading.offset(Integer.parseInt(offset.toString())); - } - final SimpleDateFormat dateFormat = new SimpleDateFormat(FacebookConstants.FACEBOOK_DATE_FORMAT); - final Object until = readingProperties.remove("until"); - if (until != null) { - try { - reading.until(dateFormat.parse(until.toString())); - } catch (ParseException e) { - throw new RuntimeException("Error parsing property 'until' :" + e.getMessage(), e); - } - } - final Object since = readingProperties.remove("since"); - if (since != null) { - try { - reading.since(dateFormat.parse(since.toString())); - } catch (ParseException e) { - throw new RuntimeException("Error parsing property 'since' :" + e.getMessage(), e); - } - } - final Object metadata = readingProperties.remove("metadata"); - if (metadata != null && Boolean.parseBoolean(metadata.toString())) { - reading.metadata(); - } - final Object locale = readingProperties.remove("locale"); - if (locale != null) { - String[] args = locale.toString().split(","); - switch (args.length) { - case 1: - reading.locale(new Locale(args[0])); - break; - case 2: - reading.locale(new Locale(args[0], args[1])); - break; - case 3: - reading.locale(new Locale(args[0], args[1], args[2])); - break; - default: - throw new IllegalArgumentException(String.format("Invalid value for property 'locale' %s, " - + "must be of the form [language][,country][,variant]", locale.toString())); - } - } - final Object with = readingProperties.remove("with"); - if (with != null && Boolean.parseBoolean(with.toString())) { - reading.withLocation(); - } - final Object filter = readingProperties.remove("filter"); - if (filter != null) { - reading.filter(filter.toString()); - } - } - -} diff --git a/components/camel-facebook/src/test/java/org/apache/camel/facebook/CamelFacebookTestSupport.java b/components/camel-facebook/src/test/java/org/apache/camel/facebook/CamelFacebookTestSupport.java deleted file mode 100644 index b2d4795405f21..0000000000000 --- a/components/camel-facebook/src/test/java/org/apache/camel/facebook/CamelFacebookTestSupport.java +++ /dev/null @@ -1,71 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.facebook; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; -import org.apache.camel.facebook.config.FacebookConfiguration; -import org.apache.camel.test.junit4.CamelTestSupport; -import org.apache.camel.util.IntrospectionSupport; - -public class CamelFacebookTestSupport extends CamelTestSupport { - - private final Properties properties; - private FacebookConfiguration configuration; - - public CamelFacebookTestSupport() throws Exception { - URL url = getClass().getResource("/test-options.properties"); - - InputStream inStream; - try { - inStream = url.openStream(); - } catch (IOException e) { - e.printStackTrace(); - throw new IllegalAccessError("test-options.properties could not be found"); - } - - properties = new Properties(); - try { - properties.load(inStream); - } catch (IOException e) { - e.printStackTrace(); - throw new IllegalAccessError("test-options.properties could not be found"); - } - - Map options = new HashMap(); - for (Map.Entry entry : properties.entrySet()) { - options.put(entry.getKey().toString(), entry.getValue()); - } - - configuration = new FacebookConfiguration(); - IntrospectionSupport.setProperties(configuration, options); - } - - public FacebookConfiguration getConfiguration() { - return configuration; - } - - public String getOauthParams() { - return "oAuthAppId=" + properties.get("oAuthAppId") + "&oAuthAppSecret=" + properties.get("oAuthAppSecret") + - (properties.get("oAuthAccessToken") != null ? - ("&oAuthAccessToken=" + properties.get("oAuthAccessToken")) : ""); - } -} diff --git a/components/camel-facebook/src/test/java/org/apache/camel/facebook/FacebookComponentConsumerTest.java b/components/camel-facebook/src/test/java/org/apache/camel/facebook/FacebookComponentConsumerTest.java deleted file mode 100644 index 2754e8eb3b1b6..0000000000000 --- a/components/camel-facebook/src/test/java/org/apache/camel/facebook/FacebookComponentConsumerTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.facebook; - -import java.lang.reflect.Method; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.TimeUnit; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.junit.Test; - -import facebook4j.api.SearchMethods; - -public class FacebookComponentConsumerTest extends CamelFacebookTestSupport { - - private final Set searchNames = new HashSet(); - - public FacebookComponentConsumerTest() throws Exception { - // find search methods for consumer tests - for (Method method : SearchMethods.class.getDeclaredMethods()) { - String name = method.getName(); - if (name.startsWith("search") && !"search".equals(name)) { - name = Character.toLowerCase(name.charAt(6)) + name.substring(7); - } - if (!"locations".equals(name) && !"checkins".equals(name)) { - searchNames.add(name); - } - } - } - - @Test - public void testConsumers() throws InterruptedException { - for (String name : searchNames) { - MockEndpoint mock = getMockEndpoint("mock:consumeResult" + name); - mock.expectedMinimumMessageCount(1); - } - assertMockEndpointsSatisfied(); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() { - - // start with a 7 day window for the first delayed poll - String since = new SimpleDateFormat(FacebookConstants.FACEBOOK_DATE_FORMAT).format( - new Date(System.currentTimeMillis() - TimeUnit.MILLISECONDS.convert(7, TimeUnit.DAYS))); - - for (String name : searchNames) { - from("facebook://" + name + "?query=cheese&reading.limit=10&reading.locale=en.US&reading.since=" - + since + "&consumer.initialDelay=1000&" + getOauthParams()) - .to("mock:consumeResult" + name); - } - - // TODO add tests for the rest of the supported methods - } - }; - } - -} diff --git a/components/camel-facebook/src/test/java/org/apache/camel/facebook/FacebookComponentProducerTest.java b/components/camel-facebook/src/test/java/org/apache/camel/facebook/FacebookComponentProducerTest.java deleted file mode 100644 index 298d5990b3db4..0000000000000 --- a/components/camel-facebook/src/test/java/org/apache/camel/facebook/FacebookComponentProducerTest.java +++ /dev/null @@ -1,142 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.facebook; - -import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.junit.Test; - -import facebook4j.Facebook; - -public class FacebookComponentProducerTest extends CamelFacebookTestSupport { - - private final Set noArgNames = new HashSet(); - - private final List idExcludes; - private final List readingExcludes; - - public FacebookComponentProducerTest() throws Exception { - for (Class clazz : Facebook.class.getInterfaces()) { - final String clazzName = clazz.getSimpleName(); - if (clazzName.endsWith("Methods") && !clazzName.equals("GameMethods")) { - for (Method method : clazz.getDeclaredMethods()) { - String name = method.getName(); - if (name.startsWith("get")) { - name = Character.toLowerCase(name.charAt(3)) + name.substring(4); - } - if (name.startsWith("search") && !"search".equals(name)) { - name = Character.toLowerCase(name.charAt(6)) + name.substring(7); - } - // find all the no-arg methods - if (method.getParameterTypes().length == 0) { - noArgNames.add(name); - } - } - } - } - - idExcludes = Arrays.asList(new String[] { "me", "home", "searchCheckins" }); - readingExcludes = Arrays.asList(new String[] { "pictureURL", "permissions" }); - } - - @Test - public void testProducers() throws Exception { - for (String name : noArgNames) { - MockEndpoint mock = getMockEndpoint("mock:result" + name); - mock.expectedMinimumMessageCount(1); - template().sendBody("direct://test" + name, null); - // avoid hitting Facebook API call rate limit - Thread.sleep(1000); - - // with user id - if (!idExcludes.contains(name)) { - mock = getMockEndpoint("mock:resultId" + name); - mock.expectedMinimumMessageCount(1); - template().sendBody("direct://testId" + name, null); - // avoid hitting Facebook API call rate limit - Thread.sleep(1000); - } - - // with reading - if (!readingExcludes.contains(name)) { - mock = getMockEndpoint("mock:resultReading" + name); - mock.expectedMinimumMessageCount(1); - template().sendBody("direct://testReading" + name, null); - // avoid hitting Facebook API call rate limit - Thread.sleep(1000); - } - - // with user id and reading - if (!(idExcludes.contains(name) || readingExcludes.contains(name))) { - mock = getMockEndpoint("mock:resultIdReading" + name); - mock.expectedMinimumMessageCount(1); - template().sendBody("direct://testIdReading" + name, null); - // avoid hitting Facebook API call rate limit - Thread.sleep(1000); - } - } - - assertMockEndpointsSatisfied(); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() { - - //--------------- - // producer tests - //--------------- - // generate test routes for all methods with no args - for (String name : noArgNames) { - from("direct://test" + name) - .to("facebook://" + name + "?" + getOauthParams()) - .to("mock:result" + name); - - // with user id - if (!idExcludes.contains(name)) { - from("direct://testId" + name) - .to("facebook://" + name + "?userId=me&" + getOauthParams()) - .to("mock:resultId" + name); - } - - // reading options - if (!readingExcludes.contains(name)) { - from("direct://testReading" + name) - .to("facebook://" + name + "?reading.limit=10&reading.locale=en,US&" + getOauthParams()) - .to("mock:resultReading" + name); - } - - // with id and reading options - if (!(idExcludes.contains(name) || readingExcludes.contains(name))) { - from("direct://testIdReading" + name) - .to("facebook://" + name + "?userId=me&reading.limit=10&reading.locale=en,US&" + getOauthParams()) - .to("mock:resultIdReading" + name); - } - } - - // TODO add tests for the rest of the supported methods - } - }; - } - -} diff --git a/components/camel-facebook/src/test/java/org/apache/camel/facebook/data/FacebookMethodsTypeHelperTest.java b/components/camel-facebook/src/test/java/org/apache/camel/facebook/data/FacebookMethodsTypeHelperTest.java deleted file mode 100644 index 427d0b4d7d3e3..0000000000000 --- a/components/camel-facebook/src/test/java/org/apache/camel/facebook/data/FacebookMethodsTypeHelperTest.java +++ /dev/null @@ -1,83 +0,0 @@ -package org.apache.camel.facebook.data; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import static org.junit.Assert.*; - -import facebook4j.Facebook; -import org.apache.camel.facebook.config.FacebookEndpointConfiguration; -import org.junit.Test; - -/** - * Test {@link FacebookMethodsTypeHelper}. - */ -public class FacebookMethodsTypeHelperTest { - @Test - public void testGetCandidateMethods() throws Exception { - // TODO - } - - @Test - public void testFilterMethods() throws Exception { - // TODO - } - - @Test - public void testGetArguments() throws Exception { - final Class[] interfaces = Facebook.class.getInterfaces(); - for (Class clazz : interfaces) { - if (clazz.getName().endsWith("Methods")) { - // check all methods of this *Methods interface - for (Method method : clazz.getDeclaredMethods()) { - // will throw an exception if can't be found - final List arguments = FacebookMethodsTypeHelper.getArguments(method.getName()); - final int nArgs = arguments.size() / 2; - List types = new ArrayList(nArgs); - for (int i = 0; i < nArgs; i++) { - types.add((Class) arguments.get(2 * i)); - } - assertTrue("Missing parameters for " + method, - types.containsAll(Arrays.asList(method.getParameterTypes()))); - } - } - } - } - - @Test - public void testAllArguments() throws Exception { - assertFalse("Missing arguments", FacebookMethodsTypeHelper.allArguments().isEmpty()); - } - - @Test - public void testGetType() throws Exception { - for (Field field : FacebookEndpointConfiguration.class.getDeclaredFields()) { - Class expectedType = field.getType(); - final Class actualType = FacebookMethodsTypeHelper.getType(field.getName()); - // test for auto boxing, un-boxing - if (actualType.isPrimitive()) { - expectedType = (Class) expectedType.getField("TYPE").get(null); - } else if (List.class.isAssignableFrom(expectedType) && actualType.isArray()) { - // skip lists, since they will be converted in invokeMethod() - expectedType = actualType; - } - assertEquals("Missing property " + field.getName(), expectedType, actualType); - } - } - - @Test - public void testConvertToGetMethod() throws Exception { - assertEquals("Invalid get method name", - FacebookMethodsType.GET_ACCOUNTS.getName(), FacebookMethodsTypeHelper.convertToGetMethod("accounts")); - } - - @Test - public void testConvertToSearchMethod() throws Exception { - assertEquals("Invalid get method name", - FacebookMethodsType.SEARCHPOSTS.getName(), FacebookMethodsTypeHelper.convertToSearchMethod("posts")); - } - -} diff --git a/components/camel-facebook/src/test/java/org/apache/camel/facebook/data/FacebookMethodsTypeTest.java b/components/camel-facebook/src/test/java/org/apache/camel/facebook/data/FacebookMethodsTypeTest.java deleted file mode 100644 index e5ec989320a74..0000000000000 --- a/components/camel-facebook/src/test/java/org/apache/camel/facebook/data/FacebookMethodsTypeTest.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.facebook.data; - -import java.lang.reflect.Method; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import facebook4j.Facebook; -import org.junit.Test; - -/** - * Test that all *Methods methods are mapped in {@link FacebookMethodsType}. - */ -public class FacebookMethodsTypeTest { - - @Test - public void areAllMethodsMapped() throws Exception { - final Class[] interfaces = Facebook.class.getInterfaces(); - for (Class clazz : interfaces) { - if (clazz.getName().endsWith("Methods")) { - // check all methods of this *Methods interface - for (Method method : clazz.getDeclaredMethods()) { - final FacebookMethodsType methodsType = FacebookMethodsType.findMethod(method.getName(), method.getParameterTypes()); - assertNotNull(methodsType); - assertEquals("Methods are not equal", method, methodsType.getMethod()); - } - } - } - } - -} diff --git a/components/camel-facebook/src/test/java/org/apache/camel/facebook/data/ReadingBuilderTest.java b/components/camel-facebook/src/test/java/org/apache/camel/facebook/data/ReadingBuilderTest.java deleted file mode 100644 index ea665c8558b0b..0000000000000 --- a/components/camel-facebook/src/test/java/org/apache/camel/facebook/data/ReadingBuilderTest.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.apache.camel.facebook.data; - -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; - -import static org.junit.Assert.*; - -import facebook4j.Reading; -import org.apache.camel.facebook.FacebookConstants; -import org.junit.Test; - -/** - * Test {@link ReadingBuilder}. - */ -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=")); - } - - @Test - public void testSetProperties() throws Exception { - final Reading reading = new Reading(); - - Map properties = new HashMap(); - properties.put("fields", "field1,field2"); - properties.put("filter", "testFilter"); - properties.put("limit", "100"); - properties.put("metadata", ""); - properties.put("offset", "1000"); - final String facebookDate = new SimpleDateFormat(FacebookConstants.FACEBOOK_DATE_FORMAT).format(new Date()); - properties.put("since", facebookDate); - properties.put("until", facebookDate); - properties.put("withLocation", ""); - - // set properties on Reading - ReadingBuilder.setProperties(reading, properties); - } - -} From 6717532878d713860e175c9798d11b13c023daca Mon Sep 17 00:00:00 2001 From: Dhiraj Bokde Date: Tue, 3 Sep 2013 12:37:51 -0700 Subject: [PATCH 4/5] CAMEL-6676: removed space in argument name ' locale', formatting --- .../facebook/data/FacebookMethodsType.java | 140 +++++++++--------- 1 file changed, 70 insertions(+), 70 deletions(-) diff --git a/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/data/FacebookMethodsType.java b/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/data/FacebookMethodsType.java index f5273d860c890..e78ffc8e47bdf 100644 --- a/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/data/FacebookMethodsType.java +++ b/components/camel-facebook/src/main/java/org/apache/camel/component/facebook/data/FacebookMethodsType.java @@ -81,8 +81,8 @@ public enum FacebookMethodsType { COMMENTALBUM(String.class, "commentAlbum", String.class, "albumId", String.class, "message"), CREATEALBUM(String.class, "createAlbum", AlbumCreate.class, "albumCreate"), CREATEALBUM_WITH_ID(String.class, "createAlbum", String.class, "userId", AlbumCreate.class, "albumCreate"), - GETALBUM(Album.class, "getAlbum", String.class, "albumId"), - GETALBUM_WITH_OPTIONS(Album.class, "getAlbum", String.class, "albumId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETALBUM(Album.class, "getAlbum", String.class, "albumId"), + GETALBUM_WITH_OPTIONS(Album.class, "getAlbum", String.class, "albumId", Reading.class, FacebookConstants.READING_PPROPERTY), GETALBUMCOMMENTS(ResponseList.class, "getAlbumComments", String.class, "albumId"), GETALBUMCOMMENTS_WITH_OPTIONS(ResponseList.class, "getAlbumComments", String.class, "albumId", Reading.class, FacebookConstants.READING_PPROPERTY), GETALBUMCOVERPHOTO(URL.class, "getAlbumCoverPhoto", String.class, "albumId"), @@ -130,17 +130,17 @@ public enum FacebookMethodsType { // EventMethods CREATEEVENT(String.class, "createEvent", EventUpdate.class, "eventUpdate"), CREATEEVENT_WITH_ID(String.class, "createEvent", String.class, "userId", EventUpdate.class, "eventUpdate"), - DELETEEVENT(Boolean.class, "deleteEvent", String.class, "eventId"), - DELETEEVENTPICTURE(Boolean.class, "deleteEventPicture", String.class, "eventId"), - EDITEVENT(Boolean.class, "editEvent", String.class, "eventId", EventUpdate.class, "eventUpdate"), - GETEVENT(Event.class, "getEvent", String.class, "eventId"), - GETEVENT_WITH_OPTIONS(Event.class, "getEvent", String.class, "eventId", Reading.class, FacebookConstants.READING_PPROPERTY), + DELETEEVENT(Boolean.class, "deleteEvent", String.class, "eventId"), + DELETEEVENTPICTURE(Boolean.class, "deleteEventPicture", String.class, "eventId"), + EDITEVENT(Boolean.class, "editEvent", String.class, "eventId", EventUpdate.class, "eventUpdate"), + GETEVENT(Event.class, "getEvent", String.class, "eventId"), + GETEVENT_WITH_OPTIONS(Event.class, "getEvent", String.class, "eventId", Reading.class, FacebookConstants.READING_PPROPERTY), GETEVENTFEED(ResponseList.class, "getEventFeed", String.class, "eventId"), GETEVENTFEED_WITH_OPTIONS(ResponseList.class, "getEventFeed", String.class, "eventId", Reading.class, FacebookConstants.READING_PPROPERTY), GETEVENTPHOTOS(ResponseList.class, "getEventPhotos", String.class, "eventId"), GETEVENTPHOTOS_WITH_OPTIONS(ResponseList.class, "getEventPhotos", String.class, "eventId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETEVENTPICTUREURL(URL.class, "getEventPictureURL", String.class, "eventId"), - GETEVENTPICTUREURL_WITH_PICTURESIZE(URL.class, "getEventPictureURL", String.class, "eventId", PictureSize.class, "size"), + GETEVENTPICTUREURL(URL.class, "getEventPictureURL", String.class, "eventId"), + GETEVENTPICTUREURL_WITH_PICTURESIZE(URL.class, "getEventPictureURL", String.class, "eventId", PictureSize.class, "size"), GETEVENTS(ResponseList.class, "getEvents"), GETEVENTS_WITH_OPTIONS(ResponseList.class, "getEvents", Reading.class, FacebookConstants.READING_PPROPERTY), GETEVENTS_WITH_ID(ResponseList.class, "getEvents", String.class, "userId"), @@ -157,8 +157,8 @@ public enum FacebookMethodsType { GETRSVPSTATUSINDECLINED_WITH_ID(ResponseList.class, "getRSVPStatusInDeclined", String.class, "eventId", String.class, "userId"), GETRSVPSTATUSINMAYBE(ResponseList.class, "getRSVPStatusInMaybe", String.class, "eventId"), GETRSVPSTATUSINMAYBE_WITH_ID(ResponseList.class, "getRSVPStatusInMaybe", String.class, "eventId", String.class, "userId"), - INVITETOEVENT(Boolean.class, "inviteToEvent", String.class, "eventId", String.class, "userId"), - INVITETOEVENT_WITH_IDS(Boolean.class, "inviteToEvent", String.class, "eventId", new String[0].getClass(), "userIds"), + INVITETOEVENT(Boolean.class, "inviteToEvent", String.class, "eventId", String.class, "userId"), + INVITETOEVENT_WITH_IDS(Boolean.class, "inviteToEvent", String.class, "eventId", new String[0].getClass(), "userIds"), POSTEVENTFEED_WITH_POSTUPDATE(String.class, "postEventFeed", String.class, "eventId", PostUpdate.class, "postUpdate"), POSTEVENTLINK_WITH_LINK(String.class, "postEventLink", String.class, "eventId", URL.class , "link"), POSTEVENTLINK_WITH_LINK_MSG(String.class, "postEventLink", String.class, "eventId", URL.class , "link", String.class, "message"), @@ -167,11 +167,11 @@ public enum FacebookMethodsType { POSTEVENTSTATUSMESSAGE_WITH_MSG(String.class, "postEventStatusMessage", String.class, "eventId", String.class, "message"), POSTEVENTVIDEO_WITH_MEDIA(String.class, "postEventVideo", String.class, "eventId", Media.class, "source"), POSTEVENTVIDEO_WITH_MEDIA_TITLE_DESC(String.class, "postEventVideo", String.class, "eventId", Media.class, "source", String.class, "title", String.class, "description"), - RSVPEVENTASATTENDING(Boolean.class, "rsvpEventAsAttending", String.class, "eventId"), - RSVPEVENTASDECLINED(Boolean.class, "rsvpEventAsDeclined", String.class, "eventId"), - RSVPEVENTASMAYBE(Boolean.class, "rsvpEventAsMaybe", String.class, "eventId"), - UNINVITEFROMEVENT(Boolean.class, "uninviteFromEvent", String.class, "eventId", String.class, "userId"), - UPDATEEVENTPICTURE(Boolean.class, "updateEventPicture", String.class, "eventId", Media.class, "source"), + RSVPEVENTASATTENDING(Boolean.class, "rsvpEventAsAttending", String.class, "eventId"), + RSVPEVENTASDECLINED(Boolean.class, "rsvpEventAsDeclined", String.class, "eventId"), + RSVPEVENTASMAYBE(Boolean.class, "rsvpEventAsMaybe", String.class, "eventId"), + UNINVITEFROMEVENT(Boolean.class, "uninviteFromEvent", String.class, "eventId", String.class, "userId"), + UPDATEEVENTPICTURE(Boolean.class, "updateEventPicture", String.class, "eventId", Media.class, "source"), // FamilyMethods GETFAMILY(ResponseList.class, "getFamily"), @@ -207,7 +207,7 @@ public enum FacebookMethodsType { // FQLMethods EXECUTEFQL(JSONArray.class, "executeFQL", String.class, "query"), - EXECUTEFQL_WITH_LOCALE(JSONArray.class, "executeFQL", String.class, "query", Locale.class, " locale"), + EXECUTEFQL_WITH_LOCALE(JSONArray.class, "executeFQL", String.class, "query", Locale.class, "locale"), EXECUTEMULTIFQL(Map.class, "executeMultiFQL", Map.class, "queries"), EXECUTEMULTIFQL_WITH_LOCALE(Map.class, "executeMultiFQL", Map.class, "queries", Locale.class, "locale"), @@ -257,18 +257,18 @@ public enum FacebookMethodsType { POSTACHIEVEMENT(String.class, "postAchievement", URL.class, "achievementURL"), POSTACHIEVEMENT_WITH_ID(String.class, "postAchievement", String.class, "userId", URL.class, "achievementURL"), POSTSCORE(Boolean.class, "postScore", int.class, "scoreValue"), - POSTSCORE_WITH_ID(Boolean.class, "postScore", String.class, "userId", int.class, "scoreValue"), + POSTSCORE_WITH_ID(Boolean.class, "postScore", String.class, "userId", int.class, "scoreValue"), // GroupMethods - GETGROUP(Group.class, "getGroup", String.class, "groupId"), - GETGROUP_WITH_OPTIONS(Group.class, "getGroup", String.class, "groupId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETGROUP(Group.class, "getGroup", String.class, "groupId"), + GETGROUP_WITH_OPTIONS(Group.class, "getGroup", String.class, "groupId", Reading.class, FacebookConstants.READING_PPROPERTY), GETGROUPDOCS(ResponseList.class, "getGroupDocs", String.class, "groupId"), GETGROUPDOCS_WITH_OPTIONS(ResponseList.class, "getGroupDocs", String.class, "groupId", Reading.class, FacebookConstants.READING_PPROPERTY), GETGROUPFEED(ResponseList.class, "getGroupFeed", String.class, "groupId"), GETGROUPFEED_WITH_OPTIONS(ResponseList.class, "getGroupFeed", String.class, "groupId", Reading.class, FacebookConstants.READING_PPROPERTY), GETGROUPMEMBERS(ResponseList.class, "getGroupMembers", String.class, "groupId"), GETGROUPMEMBERS_WITH_OPTIONS(ResponseList.class, "getGroupMembers", String.class, "groupId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETGROUPPICTUREURL(URL.class, "getGroupPictureURL", String.class, "groupId"), + GETGROUPPICTUREURL(URL.class, "getGroupPictureURL", String.class, "groupId"), GETGROUPS(ResponseList.class, "getGroups"), GETGROUPS_WITH_OPTIONS(ResponseList.class, "getGroups", Reading.class, FacebookConstants.READING_PPROPERTY), GETGROUPS_WITH_ID(ResponseList.class, "getGroups", String.class, "userId"), @@ -290,14 +290,14 @@ public enum FacebookMethodsType { // LinkMethods COMMENTLINK(String.class, "commentLink", String.class, "linkId", String.class, "message"), - GETLINK(Link.class, "getLink", String.class, "linkId"), - GETLINK_WITH_OPTIONS(Link.class, "getLink", String.class, "linkId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETLINK(Link.class, "getLink", String.class, "linkId"), + GETLINK_WITH_OPTIONS(Link.class, "getLink", String.class, "linkId", Reading.class, FacebookConstants.READING_PPROPERTY), GETLINKCOMMENTS(ResponseList.class, "getLinkComments", String.class, "linkId"), GETLINKCOMMENTS_WITH_OPTIONS(ResponseList.class, "getLinkComments", String.class, "linkId", Reading.class, FacebookConstants.READING_PPROPERTY), GETLINKLIKES(ResponseList.class, "getLinkLikes", String.class, "linkId"), GETLINKLIKES_WITH_OPTIONS(ResponseList.class, "getLinkLikes", String.class, "linkId", Reading.class, FacebookConstants.READING_PPROPERTY), - LIKELINK(Boolean.class, "likeLink", String.class, "linkId"), - UNLIKELINK(Boolean.class, "unlikeLink", String.class, "linkId"), + LIKELINK(Boolean.class, "likeLink", String.class, "linkId"), + UNLIKELINK(Boolean.class, "unlikeLink", String.class, "linkId"), // LocationMethods GETLOCATIONS(ResponseList.class, "getLocations"), @@ -310,8 +310,8 @@ public enum FacebookMethodsType { GETINBOX_WITH_OPTIONS(InboxResponseList.class, "getInbox", Reading.class, FacebookConstants.READING_PPROPERTY), GETINBOX_WITH_ID(InboxResponseList.class, "getInbox", String.class, "userId"), GETINBOX_WITH_ID_OPTIONS(InboxResponseList.class, "getInbox", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETMESSAGE(Message.class, "getMessage", String.class, "messageId"), - GETMESSAGE_WITH_OPTIONS(Message.class, "getMessage", String.class, "messageId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETMESSAGE(Message.class, "getMessage", String.class, "messageId"), + GETMESSAGE_WITH_OPTIONS(Message.class, "getMessage", String.class, "messageId", Reading.class, FacebookConstants.READING_PPROPERTY), GETOUTBOX(ResponseList.class, "getOutbox"), GETOUTBOX_WITH_OPTIONS(ResponseList.class, "getOutbox", Reading.class, FacebookConstants.READING_PPROPERTY), GETOUTBOX_WITH_ID(ResponseList.class, "getOutbox", String.class, "userId"), @@ -325,8 +325,8 @@ public enum FacebookMethodsType { COMMENTNOTE(String.class, "commentNote", String.class, "noteId", String.class, "message"), CREATENOTE(String.class, "createNote", String.class, "subject", String.class, "message"), CREATENOTE_WITH_ID_MSG(String.class, "createNote", String.class, "userId", String.class, "subject", String.class, "message"), - GETNOTE(Note.class, "getNote", String.class, "noteId"), - GETNOTE_WITH_OPTIONS(Note.class, "getNote", String.class, "noteId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETNOTE(Note.class, "getNote", String.class, "noteId"), + GETNOTE_WITH_OPTIONS(Note.class, "getNote", String.class, "noteId", Reading.class, FacebookConstants.READING_PPROPERTY), GETNOTECOMMENTS(ResponseList.class, "getNoteComments", String.class, "noteId"), GETNOTECOMMENTS_WITH_OPTIONS(ResponseList.class, "getNoteComments", String.class, "noteId", Reading.class, FacebookConstants.READING_PPROPERTY), GETNOTELIKES(ResponseList.class, "getNoteLikes", String.class, "noteId"), @@ -335,8 +335,8 @@ public enum FacebookMethodsType { GETNOTES_WITH_OPTIONS(ResponseList.class, "getNotes", Reading.class, FacebookConstants.READING_PPROPERTY), GETNOTES_WITH_ID(ResponseList.class, "getNotes", String.class, "userId"), GETNOTES_WITH_ID_OPTIONS(ResponseList.class, "getNotes", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - LIKENOTE(Boolean.class, "likeNote", String.class, "noteId"), - UNLIKENOTE(Boolean.class, "unlikeNote", String.class, "noteId"), + LIKENOTE(Boolean.class, "likeNote", String.class, "noteId"), + UNLIKENOTE(Boolean.class, "unlikeNote", String.class, "noteId"), // NotificationMethods GETNOTIFICATIONS(ResponseList.class, "getNotifications"), @@ -347,22 +347,22 @@ public enum FacebookMethodsType { GETNOTIFICATIONS_WITH_ID_INCLUDEREAD(ResponseList.class, "getNotifications", String.class, "userId", boolean.class, "includeRead"), GETNOTIFICATIONS_WITH_ID_OPTIONS(ResponseList.class, "getNotifications", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), GETNOTIFICATIONS_WITH_ID_OPTIONS_INCLUDEREAD(ResponseList.class, "getNotifications", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY, boolean.class, "includeRead"), - MARKNOTIFICATIONASREAD(Boolean.class, "markNotificationAsRead", String.class, "notificationId"), + MARKNOTIFICATIONASREAD(Boolean.class, "markNotificationAsRead", String.class, "notificationId"), // PermissionMethods GETPERMISSIONS(List.class, "getPermissions"), GETPERMISSIONS_WITH_ID(List.class, "getPermissions", String.class, "userId"), - REVOKEPERMISSION(Boolean.class, "revokePermission", String.class, "permissionName"), - REVOKEPERMISSION_WITH_ID(Boolean.class, "revokePermission", String.class, "userId", String.class, "permissionName"), + REVOKEPERMISSION(Boolean.class, "revokePermission", String.class, "permissionName"), + REVOKEPERMISSION_WITH_ID(Boolean.class, "revokePermission", String.class, "userId", String.class, "permissionName"), // PhotoMethods - ADDTAGTOPHOTO(Boolean.class, "addTagToPhoto", String.class, "photoId", String.class, "toUserId"), - ADDTAGTOPHOTO_WITH_IDS(Boolean.class, "addTagToPhoto", String.class, "photoId", List.class, "toUserIds"), - ADDTAGTOPHOTO_WITH_TAGUPDATE(Boolean.class, "addTagToPhoto", String.class, "photoId", TagUpdate.class, "tagUpdate"), + ADDTAGTOPHOTO(Boolean.class, "addTagToPhoto", String.class, "photoId", String.class, "toUserId"), + ADDTAGTOPHOTO_WITH_IDS(Boolean.class, "addTagToPhoto", String.class, "photoId", List.class, "toUserIds"), + ADDTAGTOPHOTO_WITH_TAGUPDATE(Boolean.class, "addTagToPhoto", String.class, "photoId", TagUpdate.class, "tagUpdate"), COMMENTPHOTO(String.class, "commentPhoto", String.class, "photoId", String.class, "message"), - DELETEPHOTO(Boolean.class, "deletePhoto", String.class, "photoId"), - GETPHOTO(Photo.class, "getPhoto", String.class, "photoId"), - GETPHOTO_WITH_OPTIONS(Photo.class, "getPhoto", String.class, "photoId", Reading.class, FacebookConstants.READING_PPROPERTY), + DELETEPHOTO(Boolean.class, "deletePhoto", String.class, "photoId"), + GETPHOTO(Photo.class, "getPhoto", String.class, "photoId"), + GETPHOTO_WITH_OPTIONS(Photo.class, "getPhoto", String.class, "photoId", Reading.class, FacebookConstants.READING_PPROPERTY), GETPHOTOCOMMENTS(ResponseList.class, "getPhotoComments", String.class, "photoId"), GETPHOTOCOMMENTS_WITH_OPTIONS(ResponseList.class, "getPhotoComments", String.class, "photoId", Reading.class, FacebookConstants.READING_PPROPERTY), GETPHOTOLIKES(ResponseList.class, "getPhotoLikes", String.class, "photoId"), @@ -371,17 +371,17 @@ public enum FacebookMethodsType { GETPHOTOS_WITH_OPTIONS(ResponseList.class, "getPhotos", Reading.class, FacebookConstants.READING_PPROPERTY), GETPHOTOS_WITH_ID(ResponseList.class, "getPhotos", String.class, "userId"), GETPHOTOS_WITH_ID_OPTIONS(ResponseList.class, "getPhotos", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETPHOTOURL(URL.class, "getPhotoURL", String.class, "photoId"), + GETPHOTOURL(URL.class, "getPhotoURL", String.class, "photoId"), GETTAGSONPHOTO(ResponseList.class, "getTagsOnPhoto", String.class, "photoId"), GETTAGSONPHOTO_WITH_OPTIONS(ResponseList.class, "getTagsOnPhoto", String.class, "photoId", Reading.class, FacebookConstants.READING_PPROPERTY), - LIKEPHOTO(Boolean.class, "likePhoto", String.class, "photoId"), + LIKEPHOTO(Boolean.class, "likePhoto", String.class, "photoId"), POSTPHOTO(String.class, "postPhoto", Media.class, "source"), POSTPHOTO_WITH_MSG(String.class, "postPhoto", Media.class, "source", String.class, "message", String.class, "place", boolean.class, "noStory"), POSTPHOTO_WITH_MEDIA(String.class, "postPhoto", String.class, "userId", Media.class, "source"), POSTPHOTO_WITH_MEDIA_MSG(String.class, "postPhoto", String.class, "userId", Media.class, "source", String.class, "message", String.class, "place", boolean.class, "noStory"), - UNLIKEPHOTO(Boolean.class, "unlikePhoto", String.class, "photoId"), - UPDATETAGONPHOTO(Boolean.class, "updateTagOnPhoto", String.class, "photoId", String.class, "toUserId"), - UPDATETAGONPHOTO_WITH_TAGUPDATE(Boolean.class, "updateTagOnPhoto", String.class, "photoId", TagUpdate.class, "tagUpdate"), + UNLIKEPHOTO(Boolean.class, "unlikePhoto", String.class, "photoId"), + UPDATETAGONPHOTO(Boolean.class, "updateTagOnPhoto", String.class, "photoId", String.class, "toUserId"), + UPDATETAGONPHOTO_WITH_TAGUPDATE(Boolean.class, "updateTagOnPhoto", String.class, "photoId", TagUpdate.class, "tagUpdate"), // PokeMethods GETPOKES(ResponseList.class, "getPokes"), @@ -391,7 +391,7 @@ public enum FacebookMethodsType { // PostMethods COMMENTPOST(String.class, "commentPost", String.class, "postId", String.class, "message"), - DELETEPOST(Boolean.class, "deletePost", String.class, "postId"), + DELETEPOST(Boolean.class, "deletePost", String.class, "postId"), GETFEED(ResponseList.class, "getFeed"), GETFEED_WITH_OPTIONS(ResponseList.class, "getFeed", Reading.class, FacebookConstants.READING_PPROPERTY), GETFEED_WITH_ID(ResponseList.class, "getFeed", String.class, "userId"), @@ -402,8 +402,8 @@ public enum FacebookMethodsType { GETLINKS_WITH_OPTIONS(ResponseList.class, "getLinks", Reading.class, FacebookConstants.READING_PPROPERTY), GETLINKS_WITH_ID(ResponseList.class, "getLinks", String.class, "userId"), GETLINKS_WITH_ID_OPTIONS(ResponseList.class, "getLinks", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETPOST(Post.class, "getPost", String.class, "postId"), - GETPOST_WITH_OPTIONS(Post.class, "getPost", String.class, "postId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETPOST(Post.class, "getPost", String.class, "postId"), + GETPOST_WITH_OPTIONS(Post.class, "getPost", String.class, "postId", Reading.class, FacebookConstants.READING_PPROPERTY), GETPOSTCOMMENTS(ResponseList.class, "getPostComments", String.class, "postId"), GETPOSTCOMMENTS_WITH_OPTIONS(ResponseList.class, "getPostComments", String.class, "postId", Reading.class, FacebookConstants.READING_PPROPERTY), GETPOSTLIKES(ResponseList.class, "getPostLikes", String.class, "postId"), @@ -420,7 +420,7 @@ public enum FacebookMethodsType { GETTAGGED_WITH_OPTIONS(ResponseList.class, "getTagged", Reading.class, FacebookConstants.READING_PPROPERTY), GETTAGGED_WITH_ID(ResponseList.class, "getTagged", String.class, "userId"), GETTAGGED_WITH_ID_OPTIONS(ResponseList.class, "getTagged", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - LIKEPOST(Boolean.class, "likePost", String.class, "postId"), + LIKEPOST(Boolean.class, "likePost", String.class, "postId"), POSTFEED(String.class, "postFeed", PostUpdate.class, "postUpdate"), POSTFEED_WITH_POSTUPDATE(String.class, "postFeed", String.class, "userId", PostUpdate.class, "postUpdate"), POSTLINK(String.class, "postLink", URL.class, "link"), @@ -429,7 +429,7 @@ public enum FacebookMethodsType { POSTLINK_WITH_ID_MSG(String.class, "postLink", String.class, "userId", URL.class, "link", String.class, "message"), POSTSTATUSMESSAGE(String.class, "postStatusMessage", String.class, "message"), POSTSTATUSMESSAGE_WITH_ID(String.class, "postStatusMessage", String.class, "userId", String.class, "message"), - UNLIKEPOST(Boolean.class, "unlikePost", String.class, "postId"), + UNLIKEPOST(Boolean.class, "unlikePost", String.class, "postId"), // QuestionMethods ADDQUESTIONOPTION(String.class, "addQuestionOption", String.class, "questionId", String.class, "optionDescription"), @@ -437,9 +437,9 @@ public enum FacebookMethodsType { CREATEQUESTION_WITH_OPTIONS(String.class, "createQuestion", String.class, "question", List.class, "options", boolean.class, "allowNewOptions"), CREATEQUESTION_WITH_ID(String.class, "createQuestion", String.class, "userId", String.class, "question"), CREATEQUESTION_WITH_ID_OPTIONS(String.class, "createQuestion", String.class, "userId", String.class, "question", List.class, "options", boolean.class, "allowNewOptions"), - DELETEQUESTION(Boolean.class, "deleteQuestion", String.class, "questionId"), - GETQUESTION(Question.class, "getQuestion", String.class, "questionId"), - GETQUESTION_WITH_OPTIONS(Question.class, "getQuestion", String.class, "questionId", Reading.class, FacebookConstants.READING_PPROPERTY), + DELETEQUESTION(Boolean.class, "deleteQuestion", String.class, "questionId"), + GETQUESTION(Question.class, "getQuestion", String.class, "questionId"), + GETQUESTION_WITH_OPTIONS(Question.class, "getQuestion", String.class, "questionId", Reading.class, FacebookConstants.READING_PPROPERTY), GETQUESTIONOPTIONS(ResponseList.class, "getQuestionOptions", String.class, "questionId"), GETQUESTIONOPTIONS_WITH_OPTIONS(ResponseList.class, "getQuestionOptions", String.class, "questionId", Reading.class, FacebookConstants.READING_PPROPERTY), GETQUESTIONOPTIONVOTES(ResponseList.class, "getQuestionOptionVotes", String.class, "questionId"), @@ -459,42 +459,42 @@ public enum FacebookMethodsType { GETSUBSCRIBERS_WITH_ID_OPTIONS(ResponseList.class, "getSubscribers", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), // TestUserMethods - CREATETESTUSER(TestUser.class, "createTestUser", String.class, "appId"), - CREATETESTUSER_WITH_NAME(TestUser.class, "createTestUser", String.class, "appId", String.class, "name", String.class, "userLocale", String.class, "permissions"), - DELETETESTUSER(Boolean.class, "deleteTestUser", String.class, "testUserId"), + CREATETESTUSER(TestUser.class, "createTestUser", String.class, "appId"), + CREATETESTUSER_WITH_NAME(TestUser.class, "createTestUser", String.class, "appId", String.class, "name", String.class, "userLocale", String.class, "permissions"), + DELETETESTUSER(Boolean.class, "deleteTestUser", String.class, "testUserId"), GETTESTUSERS(List.class, "getTestUsers", String.class, "appId"), - MAKEFRIENDTESTUSER(Boolean.class, "makeFriendTestUser", TestUser.class, "testUser1", TestUser.class, "testUser2"), + MAKEFRIENDTESTUSER(Boolean.class, "makeFriendTestUser", TestUser.class, "testUser1", TestUser.class, "testUser2"), // UserMethods - GETME(User.class, "getMe"), - GETME_WITH_OPTIONS(User.class, "getMe", Reading.class, FacebookConstants.READING_PPROPERTY), - GETPICTUREURL(URL.class, "getPictureURL"), - GETPICTUREURL_WITH_PICTURESIZE(URL.class, "getPictureURL", PictureSize.class, "size"), - GETPICTUREURL_WITH_ID(URL.class, "getPictureURL", String.class, "userId"), - GETPICTUREURL_WITH_ID_PICTURESIZE(URL.class, "getPictureURL", String.class, "userId", PictureSize.class, "size"), - GETUSER(User.class, "getUser", String.class, "userId"), - GETUSER_WITH_OPTIONS(User.class, "getUser", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETME(User.class, "getMe"), + GETME_WITH_OPTIONS(User.class, "getMe", Reading.class, FacebookConstants.READING_PPROPERTY), + GETPICTUREURL(URL.class, "getPictureURL"), + GETPICTUREURL_WITH_PICTURESIZE(URL.class, "getPictureURL", PictureSize.class, "size"), + GETPICTUREURL_WITH_ID(URL.class, "getPictureURL", String.class, "userId"), + GETPICTUREURL_WITH_ID_PICTURESIZE(URL.class, "getPictureURL", String.class, "userId", PictureSize.class, "size"), + GETUSER(User.class, "getUser", String.class, "userId"), + GETUSER_WITH_OPTIONS(User.class, "getUser", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), GETUSERS(List.class, "getUsers", new String[0].getClass(), "ids"), // VideoMethods COMMENTVIDEO(String.class, "commentVideo", String.class, "videoId", String.class, "message"), - GETVIDEO(Video.class, "getVideo", String.class, "videoId"), - GETVIDEO_WITH_OPTIONS(Video.class, "getVideo", String.class, "videoId", Reading.class, FacebookConstants.READING_PPROPERTY), + GETVIDEO(Video.class, "getVideo", String.class, "videoId"), + GETVIDEO_WITH_OPTIONS(Video.class, "getVideo", String.class, "videoId", Reading.class, FacebookConstants.READING_PPROPERTY), GETVIDEOCOMMENTS(ResponseList.class, "getVideoComments", String.class, "videoId"), GETVIDEOCOMMENTS_WITH_OPTIONS(ResponseList.class, "getVideoComments", String.class, "videoId", Reading.class, FacebookConstants.READING_PPROPERTY), - GETVIDEOCOVER(URL.class, "getVideoCover", String.class, "videoId"), + GETVIDEOCOVER(URL.class, "getVideoCover", String.class, "videoId"), GETVIDEOLIKES(ResponseList.class, "getVideoLikes", String.class, "videoId"), GETVIDEOLIKES_WITH_OPTIONS(ResponseList.class, "getVideoLikes", String.class, "videoId", Reading.class, FacebookConstants.READING_PPROPERTY), GETVIDEOS(ResponseList.class, "getVideos"), GETVIDEOS_WITH_OPTIONS(ResponseList.class, "getVideos", Reading.class, FacebookConstants.READING_PPROPERTY), GETVIDEOS_WITH_ID(ResponseList.class, "getVideos", String.class, "userId"), GETVIDEOS_WITH_ID_OPTIONS(ResponseList.class, "getVideos", String.class, "userId", Reading.class, FacebookConstants.READING_PPROPERTY), - LIKEVIDEO(Boolean.class, "likeVideo", String.class, "videoId"), + LIKEVIDEO(Boolean.class, "likeVideo", String.class, "videoId"), POSTVIDEO(String.class, "postVideo", Media.class, "source"), POSTVIDEO_WITH_TITLE(String.class, "postVideo", Media.class, "source", String.class, "title", String.class, "description"), POSTVIDEO_WITH_ID(String.class, "postVideo", String.class, "userId", Media.class, "source"), POSTVIDEO_WITH_ID_MEDIA(String.class, "postVideo", String.class, "userId", Media.class, "source", String.class, "title", String.class, "description"), - UNLIKEVIDEO(Boolean.class, "unlikeVideo", String.class, "videoId"), + UNLIKEVIDEO(Boolean.class, "unlikeVideo", String.class, "videoId"), // SearchMethods get the highest priority with higher ordinal values SEARCH(ResponseList.class, "search", String.class, "query"), From 1f33f7b1c2a05b7557bd2d6ad5f671af811f8fec Mon Sep 17 00:00:00 2001 From: Dhiraj Bokde Date: Tue, 3 Sep 2013 12:53:21 -0700 Subject: [PATCH 5/5] CAMEL-6676: added tests to generate info for component documentation --- .../data/FacebookMethodsTypeTest.java | 79 ++++++++++++++++++- 1 file changed, 76 insertions(+), 3 deletions(-) diff --git a/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/data/FacebookMethodsTypeTest.java b/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/data/FacebookMethodsTypeTest.java index 8c3c523b74b55..2ff8c1220eea1 100644 --- a/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/data/FacebookMethodsTypeTest.java +++ b/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/data/FacebookMethodsTypeTest.java @@ -17,20 +17,25 @@ package org.apache.camel.component.facebook.data; import java.lang.reflect.Method; +import java.util.LinkedHashMap; +import java.util.Map; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import facebook4j.Facebook; -import org.junit.Test; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; - /** * Test that all *Methods methods are mapped in {@link FacebookMethodsType}. */ public class FacebookMethodsTypeTest { + private static final Logger LOG = LoggerFactory.getLogger(FacebookMethodsTypeTest.class); + private static final String LINE_SEPARATOR = System.getProperty("line.separator"); + @Test public void areAllMethodsMapped() throws Exception { final Class[] interfaces = Facebook.class.getInterfaces(); @@ -46,4 +51,72 @@ public void areAllMethodsMapped() throws Exception { } } + @Test + public void printMethodInfo() { + // map method names to number of overloads + Map methodCountMap = new LinkedHashMap(); + + // map method names to options, along with a count of overloads that use that option + Map> optionsMap = new LinkedHashMap>(); + + for (FacebookMethodsType method : FacebookMethodsType.values()) { + + final String name = method.getName(); + Integer methodCount = methodCountMap.get(name); + if (methodCount == null) { + methodCount = 1; + } else { + methodCount = ++methodCount; + } + methodCountMap.put(name, methodCount); + + Map options = optionsMap.get(name); + if (options == null) { + options = new LinkedHashMap(); + optionsMap.put(name, options); + } + for (String option : method.getArgNames()) { + Integer optionCount = options.get(option); + if (optionCount == null) { + optionCount = 1; + } else { + optionCount = ++optionCount; + } + options.put(option, optionCount); + } + } + + // print method names and options + final StringBuilder builder = new StringBuilder(); + for (Map.Entry methodCount : methodCountMap.entrySet()) { + final String name = methodCount.getKey(); + final int mCount = methodCount.getValue(); + + builder.setLength(0); + builder.append(name) + .append(',') + .append(getShortName(name)); + for (Map.Entry option : optionsMap.get(name).entrySet()) { + builder.append(','); + if (option.getValue() < mCount) { + builder.append('[') + .append(option.getKey()) + .append(']'); + } else { + builder.append(option.getKey()); + } + } + LOG.info(builder.toString()); + } + } + + private String getShortName(String name) { + if (name.startsWith("get")) { + name = Character.toLowerCase(name.charAt(3)) + name.substring(4); + } else if (name.startsWith("search") && !"search".equals(name)) { + name = Character.toLowerCase(name.charAt(6)) + name.substring(7); + } + return name; + } + }