Programmer : Mashup Programmer : Customizing the Mashup UI : Creating Feeds
 
Creating Feeds
 
Using the Eclipse plugin
Abstract class Feed
Sample Feed
Creating feeds can be useful when the standard feeds library is not sufficient. For example, if you want to connect and retrieve data from an unsupported database.
Using the Eclipse plugin
The Eclipse plugin allows you to create the feed with all required files at once.
1. In Eclipse, select File > New > Other.
2. Select CloudView Mashup Components > Mashup-API feed and click Next.
3. Define your feed general configuration:
a. Specify a source folder.
b. Specify a package.
c. Give it a name.
4. Click Finish.
The new feed is added to the specified source folder in the Project Explorer panel. Edit the feed files as needed.
Abstract class Feed
public abstract class Feed {
/*
* API to implement
*/
/**
* Return a human friendly name for this Feed, to be used by the Administration Console
*/
abstract public String getDisplayName();1
/**
* Execute routine. Called when receiving a request without any specific ID.
* @param context
* @return Return the ResultFeed for the given QueryContext
* @throws AccessException
*/
abstract public ResultFeed execute(QueryContext context)4 throws AccessException;
/**
* Get routine. Called when receiving a request with a specific ID. Must return one and only one hit.
* @param context
* @param id
* @throws AccessException
*/
abstract public ResultFeed get(QueryContext context, String id) throws AccessException;
/**
* Get the list of available metas for the given feed configuration.
* @param feedConf
* @throws AccessException
*/
@Override
public AvailableMetas getAvailableMetas(Map<String, String[]> feedConf) throws AccessException {
AvailableMetas m = new AvailableMetas();
String[] mv = { "metaName", "feedOption1" };
m.addType(new AvailableMetas.Type("all", mv, null));
return m;
}
/**
* Get the list of supported parameters by this Feed.
* @return An array of supported Parameters
*/
abstract protected Parameter[] getSupportedParameters();3
Sample Feed
import java.util.HashMap;
import java.util.Map;

import com.exalead.access.feedapi.AccessException;
import com.exalead.access.feedapi.Entry;
import com.exalead.access.feedapi.Feed;
import com.exalead.access.feedapi.Meta;
import com.exalead.access.feedapi.QueryContext;
import com.exalead.access.feedapi.ResultFeed;
import com.exalead.access.feedapi.utils.FeedHelper;
import com.exalead.access.feedapi.v10.AvailableMetas;
import com.exalead.access.feedapi.v10.Parameter;
import com.exalead.cv360.customcomponents.CustomComponent;

@CustomComponent(displayName = "Sample Feed")
public class SampleFeed extends Feed {

@Override
public String getDisplayName() {
return "Sample Feed";
}

@Override
public ResultFeed execute(QueryContext context) throws AccessException {
String feedOption1 = this.getEvaluatedParameter(context, "feedOption1");
ResultFeed r = new ResultFeed(this);
Entry e = new Entry("42");
e.addMeta(new Meta("metaName", "metaValue"));
e.addMeta(new Meta("feedOption1", feedOption1));
r.addEntry(e);
return r;
}

@Override
public ResultFeed get(QueryContext context, String id) throws AccessException {
return null;
}

@Override
public AvailableMetas getAvailableMetas(Map<String, String[]> feedConf) throws AccessException {
AvailableMetas m = new AvailableMetas();
String[] mv = { "metaName", "feedOption1" };
m.addType(new AvailableMetas.Type("all", mv, null));
return m;
}

@Override
protected Parameter[] getSupportedParameters() {
return new Parameter[] { new Parameter("feedOption1") };
}
public static void main(String[] args) throws Exception {
com.exalead.access.configuration.v10.Feed config = new com.exalead.access.configuration.v10.Feed();
config.addParameter(new com.exalead.access.configuration.v10.Feed.Parameter("feedOption1", "value1"));

Feed pageSearch = FeedHelper.getTestPageFeed("search");

pageSearch.getSubFeeds().add(FeedHelper.getTestFeed(SampleFeed.class, "test", config));

// FeedTrigger trigger = new testFeedTrigger();
// testFeed.getTriggers().add(trigger);

Map<String, String> params = new HashMap<String, String>();
params.put("test.feedOption1", "feedOption1Value");


ResultFeed result = FeedHelper.runFirstFeed(pageSearch, params);
for (Entry e : result.getEntries()) {
for (Object s : e.getMetas().keySet().toArray()) {
System.out.println(s + " : " + e.getMeta((String) s).getFirstValue());
}
}
}
}