/* ********************************************************************** **
** Copyright notice **
** **
** (c) 2005-2006 RSSOwl Development Team **
** http://www.rssowl.org/ **
** **
** All rights reserved **
** **
** This program and the accompanying materials are made available under **
** the terms of the Eclipse Public License v1.0 which accompanies this **
** distribution, and is available at: **
** http://www.rssowl.org/legal/epl-v10.html **
** **
** A copy is found in the file epl-v10.html and important notices to the **
** license from the team is found in the textfile LICENSE.txt distributed **
** in this package. **
** **
** This copyright notice MUST APPEAR in all copies of the file! **
** **
** Contributors: **
** RSSOwl Development Team - initial API and implementation **
** **
** ********************************************************************** */
package org.rssowl.core.tests.performance;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.junit.Before;
import org.junit.Test;
import org.rssowl.core.connection.ConnectionManager;
import org.rssowl.core.interpreter.Interpreter;
import org.rssowl.core.model.NewsModel;
import org.rssowl.core.model.dao.IApplicationLayer;
import org.rssowl.core.model.dao.IModelDAO;
import org.rssowl.core.model.dao.PersistenceException;
import org.rssowl.core.model.internal.types.Feed;
import org.rssowl.core.model.reference.FeedReference;
import org.rssowl.core.model.types.IAttachment;
import org.rssowl.core.model.types.ICategory;
import org.rssowl.core.model.types.ICloud;
import org.rssowl.core.model.types.IEntity;
import org.rssowl.core.model.types.IExtendableType;
import org.rssowl.core.model.types.IFeed;
import org.rssowl.core.model.types.IGuid;
import org.rssowl.core.model.types.IImage;
import org.rssowl.core.model.types.ILabel;
import org.rssowl.core.model.types.INews;
import org.rssowl.core.model.types.IPerson;
import org.rssowl.core.model.types.ISource;
import org.rssowl.core.model.types.ITextInput;
import org.rssowl.core.model.util.ITask;
import org.rssowl.core.model.util.TaskAdapter;
import org.rssowl.core.tests.Activator;
import org.rssowl.core.tests.TestUtils;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @author bpasero
*/
public class PerformanceTest {
/* Define the number of Feeds here (1 - 216) */
private static final int FEEDS = 200;
/* Number of Jobs per JobQueue */
private static final int JOBS = 10;
private IModelDAO fDao;
private URL fPluginLocation;
private ConnectionManager fConManager;
private IApplicationLayer fAppLayer;
/**
* @throws Exception
*/
@SuppressWarnings("nls")
@Before
public void setUp() throws Exception {
NewsModel.getDefault().getPersistenceLayer().getModelSearch().stopIndexer();
NewsModel.getDefault().getPersistenceLayer().recreateSchema();
fDao = NewsModel.getDefault().getPersistenceLayer().getModelDAO();
fAppLayer = NewsModel.getDefault().getPersistenceLayer().getApplicationLayer();
fPluginLocation = FileLocator.toFileURL(Platform.getBundle("org.rssowl.core.tests").getEntry("/"));
fConManager = ConnectionManager.getDefault();
}
/**
* @throws Exception
*/
@SuppressWarnings("nls")
@Test
public void setNewsState() throws Exception {
/* Save some Feeds first */
List<IFeed> feeds = interpretFeedsHelper();
final List<IFeed> savedFeeds = new ArrayList<IFeed>(feeds.size());
for (IFeed feed : feeds)
savedFeeds.add(fDao.saveFeed(feed));
List<ITask> tasks = new ArrayList<ITask>();
final List<Exception> ex = new ArrayList<Exception>();
for (final IFeed feed : savedFeeds) {
tasks.add(new TaskAdapter() {
public IStatus run(IProgressMonitor monitor) {
try {
List<INews> news = fDao.loadFeed(feed.getId()).getNews();
fAppLayer.setNewsState(news, INews.State.HIDDEN, true, false);
} catch (PersistenceException e) {
ex.add(e);
}
return Status.OK_STATUS;
}
});
}
/* Cold-Start: Interpret 216 Feeds */
System.out.println("Setting news state: " + FEEDS + " Feeds [Cold - " + JOBS + " Jobs] took: " + TestUtils.executeAndWait(tasks, JOBS) + "ms");
/* Warm-Start: Interpret 216 Feeds */
resetStates(savedFeeds, ex);
long l1 = TestUtils.executeAndWait(tasks, JOBS);
resetStates(savedFeeds, ex);
long l2 = TestUtils.executeAndWait(tasks, JOBS);
resetStates(savedFeeds, ex);
long l3 = TestUtils.executeAndWait(tasks, JOBS);
resetStates(savedFeeds, ex);
long l4 = TestUtils.executeAndWait(tasks, JOBS);
System.out.println("Setting news state: " + FEEDS + " Feeds [Warm - " + JOBS + " Jobs] took: " + (l1 + l2 + l3 + l4) / 4 + "ms\n");
if (ex.size() > 0)
throw ex.get(0);
}
private void resetStates(final List<IFeed> savedFeeds, final List<Exception> ex) {
for (IFeed feed : savedFeeds) {
try {
List<INews> news = fDao.loadFeed(feed.getId()).getNews();
fAppLayer.setNewsState(news, INews.State.NEW, true, false);
} catch (PersistenceException e) {
ex.add(e);
}
}
}
/**
* @throws Exception
*/
@SuppressWarnings("nls")
@Test
public void interpretFeeds() throws Exception {
List<ITask> tasks = new ArrayList<ITask>();
final List<Exception> ex = new ArrayList<Exception>();
/* Prepare Tasks */
for (int i = 1; i < FEEDS + 1; i++) {
final int c = i;
tasks.add(new TaskAdapter() {
public IStatus run(IProgressMonitor monitor) {
try {
URL feedUrl = fPluginLocation.toURI().resolve("data/performance/" + c + ".xml").toURL();
IFeed feed = new Feed(feedUrl);
InputStream inS = fConManager.load(feed.getLink());
Interpreter.getDefault().interpret(inS, feed);
} catch (Exception e) {
ex.add(e);
}
return Status.OK_STATUS;
}
});
}
/* Cold-Start: Interpret 216 Feeds */
System.out.println("Interpreting " + FEEDS + " Feeds [Cold - " + JOBS + " Jobs] took: " + TestUtils.executeAndWait(tasks, JOBS) + "ms");
/* Warm-Start: Interpret 216 Feeds */
long l1 = TestUtils.executeAndWait(tasks, JOBS);
long l2 = TestUtils.executeAndWait(tasks, JOBS);
long l3 = TestUtils.executeAndWait(tasks, JOBS);
long l4 = TestUtils.executeAndWait(tasks, JOBS);
System.out.println("Interpreting " + FEEDS + " Feeds [Warm - " + JOBS + " Jobs] took: " + (l1 + l2 + l3 + l4) / 4 + "ms\n");
if (ex.size() > 0)
throw ex.get(0);
}
/**
* @throws Exception
*/
@SuppressWarnings("nls")
@Test
public void saveFeeds() throws Exception {
final List<Exception> ex = new ArrayList<Exception>();
/* Cold-Start: Save 216 Feeds */
List<ITask> tasks = getSaveFeedsTasks(ex);
System.out.println("Saving " + FEEDS + " Feeds [Cold - " + JOBS + " Jobs] took: " + TestUtils.executeAndWait(tasks, JOBS) + "ms");
/* Warm-Start: Save 216 Feeds */
NewsModel.getDefault().getPersistenceLayer().recreateSchema();
tasks = getSaveFeedsTasks(ex);
long l1 = TestUtils.executeAndWait(tasks, JOBS);
NewsModel.getDefault().getPersistenceLayer().recreateSchema();
tasks = getSaveFeedsTasks(ex);
long l2 = TestUtils.executeAndWait(tasks, JOBS);
NewsModel.getDefault().getPersistenceLayer().recreateSchema();
tasks = getSaveFeedsTasks(ex);
long l3 = TestUtils.executeAndWait(tasks, JOBS);
NewsModel.getDefault().getPersistenceLayer().recreateSchema();
tasks = getSaveFeedsTasks(ex);
long l4 = TestUtils.executeAndWait(tasks, JOBS);
System.out.println("Saving " + FEEDS + " Feeds [Warm - " + JOBS + " Jobs] took: " + (l1 + l2 + l3 + l4) / 4 + "ms\n");
if (ex.size() > 0)
throw ex.get(0);
}
private List<ITask> getSaveFeedsTasks(final List<Exception> ex) {
List<ITask> tasks = new ArrayList<ITask>();
List<IFeed> feeds = interpretFeedsHelper();
for (final IFeed feed : feeds) {
tasks.add(new TaskAdapter() {
public IStatus run(IProgressMonitor monitor) {
try {
fDao.saveFeed(feed);
} catch (Exception e) {
ex.add(e);
}
return Status.OK_STATUS;
}
});
}
return tasks;
}
/**
* @throws Exception
*/
@SuppressWarnings("nls")
@Test
public void resolveFeeds() throws Exception {
List<ITask> tasks = new ArrayList<ITask>();
final List<Exception> ex = new ArrayList<Exception>();
/* Prepare Tasks */
List<FeedReference> feedRefs = saveFeedsHelper();
for (final FeedReference feedRef : feedRefs) {
tasks.add(new TaskAdapter() {
public IStatus run(IProgressMonitor monitor) {
try {
accessAllFields(feedRef.resolve());
} catch (Exception e) {
ex.add(e);
}
return Status.OK_STATUS;
}
});
}
/* Cold-Start: Resolve 216 Feeds */
System.out.println("Resolving " + FEEDS + " Feeds [Cold - " + JOBS + " Jobs] took: " + TestUtils.executeAndWait(tasks, JOBS) + "ms");
/* Warm-Start: Resolve 216 Feeds */
long l1 = TestUtils.executeAndWait(tasks, JOBS);
long l2 = TestUtils.executeAndWait(tasks, JOBS);
long l3 = TestUtils.executeAndWait(tasks, JOBS);
long l4 = TestUtils.executeAndWait(tasks, JOBS);
System.out.println("Resolving " + FEEDS + " Feeds [Warm - " + JOBS + " Jobs] took: " + (l1 + l2 + l3 + l4) / 4 + "ms\n");
if (ex.size() > 0)
throw ex.get(0);
}
/**
* @throws Exception
*/
@SuppressWarnings("nls")
@Test
public void resolveFeedsAndNews() throws Exception {
List<ITask> tasks = new ArrayList<ITask>();
final List<Exception> ex = new ArrayList<Exception>();
/* Prepare Tasks */
List<FeedReference> feedRefs = saveFeedsHelper();
for (final FeedReference feedRef : feedRefs) {
tasks.add(new TaskAdapter() {
public IStatus run(IProgressMonitor monitor) {
try {
IFeed feed = feedRef.resolve();
accessAllFields(feed);
Collection<INews> news = feed.getNews();
for (INews newsItem : news)
accessAllFields(newsItem);
} catch (Exception e) {
ex.add(e);
}
return Status.OK_STATUS;
}
});
}
/* Cold-Start: Resolve 216 Feeds and all News */
System.out.println("Resolving " + FEEDS + " Feeds with all News [Cold - " + JOBS + " Jobs] took: " + TestUtils.executeAndWait(tasks, JOBS) + "ms");
/* Warm-Start: Resolve 216 Feeds and all News */
long l1 = TestUtils.executeAndWait(tasks, JOBS);
long l2 = TestUtils.executeAndWait(tasks, JOBS);
long l3 = TestUtils.executeAndWait(tasks, JOBS);
long l4 = TestUtils.executeAndWait(tasks, JOBS);
System.out.println("Resolving " + FEEDS + " Feeds with all News [Warm - " + JOBS + " Jobs] took: " + (l1 + l2 + l3 + l4) / 4 + "ms\n");
if (ex.size() > 0)
throw ex.get(0);
}
/**
* @throws Exception
*/
@SuppressWarnings("nls")
@Test
public void resolveNewsStatesByResolving() throws Exception {
List<ITask> tasks = new ArrayList<ITask>();
final List<Exception> ex = new ArrayList<Exception>();
/* Prepare Tasks */
List<FeedReference> feedRefs = saveFeedsHelper();
for (final FeedReference feedRef : feedRefs) {
tasks.add(new TaskAdapter() {
public IStatus run(IProgressMonitor monitor) {
try {
IFeed feed = feedRef.resolve();
Collection<INews> news = feed.getNews();
for (INews newsItem : news)
newsItem.getState();
} catch (Exception e) {
ex.add(e);
}
return Status.OK_STATUS;
}
});
}
/* Cold-Start: Resolve 216 Feeds and all News */
System.out.println("Resolving News-States of " + FEEDS + " Feeds [Cold - " + JOBS + " Jobs] took: " + TestUtils.executeAndWait(tasks, JOBS) + "ms");
/* Warm-Start: Resolve 216 Feeds and all News */
long l1 = TestUtils.executeAndWait(tasks, JOBS);
long l2 = TestUtils.executeAndWait(tasks, JOBS);
long l3 = TestUtils.executeAndWait(tasks, JOBS);
long l4 = TestUtils.executeAndWait(tasks, JOBS);
System.out.println("Resolving News-States of " + FEEDS + " Feeds [Warm - " + JOBS + " Jobs] took: " + (l1 + l2 + l3 + l4) / 4 + "ms\n");
if (ex.size() > 0)
throw ex.get(0);
}
/**
* @throws Exception
*/
@SuppressWarnings("nls")
@Test
public void resolveFeedCompletly() throws Exception {
List<ITask> tasks = new ArrayList<ITask>();
final List<Exception> ex = new ArrayList<Exception>();
/* Prepare Tasks */
List<FeedReference> feedRefs = saveFeedsHelper();
for (final FeedReference feedRef : feedRefs) {
tasks.add(new TaskAdapter() {
public IStatus run(IProgressMonitor monitor) {
try {
IFeed feed = feedRef.resolve();
if (feed.getAuthor() != null)
accessAllFields(feed.getAuthor());
List<ICategory> feedCats = feed.getCategories();
for (ICategory category : feedCats)
accessAllFields(category);
if (feed.getImage() != null)
accessAllFields(feed.getImage());
accessAllFields(feed);
Collection<INews> newsList = feed.getNews();
for (INews news : newsList) {
accessAllFields(news);
List<IAttachment> attachments = news.getAttachments();
for (IAttachment attachment : attachments)
accessAllFields(attachment);
if (news.getAuthor() != null)
accessAllFields(news.getAuthor());
List<ICategory> categories = news.getCategories();
for (ICategory category : categories)
accessAllFields(category);
if (news.getGuid() != null)
accessAllFields(news.getGuid());
if (news.getSource() != null)
accessAllFields(news.getSource());
if (news.getLabel() != null)
accessAllFields(news.getLabel());
}
} catch (Exception e) {
ex.add(e);
}
return Status.OK_STATUS;
}
});
}
/* Cold-Start: Resolve 216 Feeds and all News */
System.out.println("Resolving " + FEEDS + " Feeds with all News completly [Cold - " + JOBS + " Jobs] took: " + TestUtils.executeAndWait(tasks, JOBS) + "ms");
/* Warm-Start: Resolve 216 Feeds and all News */
long l1 = TestUtils.executeAndWait(tasks, JOBS);
long l2 = TestUtils.executeAndWait(tasks, JOBS);
long l3 = TestUtils.executeAndWait(tasks, JOBS);
long l4 = TestUtils.executeAndWait(tasks, JOBS);
System.out.println("Resolving " + FEEDS + " Feeds with all News completly [Warm - " + JOBS + " Jobs] took: " + (l1 + l2 + l3 + l4) / 4 + "ms\n");
if (ex.size() > 0)
throw ex.get(0);
}
/**
* @throws Exception
*/
@SuppressWarnings("nls")
@Test
public void deleteFeeds() throws Exception {
final List<Exception> ex = new ArrayList<Exception>();
/* Cold-Start: Delete 216 Feeds */
List<ITask> tasks = getDeleteFeedsTasks(ex);
System.out.println("Deleting " + FEEDS + " Feeds [Cold - " + JOBS + " Jobs] took: " + TestUtils.executeAndWait(tasks, JOBS) + "ms");
/* Warm-Start: Delete 216 Feeds */
NewsModel.getDefault().getPersistenceLayer().recreateSchema();
tasks = getDeleteFeedsTasks(ex);
long l1 = TestUtils.executeAndWait(tasks, JOBS);
NewsModel.getDefault().getPersistenceLayer().recreateSchema();
tasks = getDeleteFeedsTasks(ex);
long l2 = TestUtils.executeAndWait(tasks, JOBS);
NewsModel.getDefault().getPersistenceLayer().recreateSchema();
tasks = getDeleteFeedsTasks(ex);
long l3 = TestUtils.executeAndWait(tasks, JOBS);
NewsModel.getDefault().getPersistenceLayer().recreateSchema();
tasks = getDeleteFeedsTasks(ex);
long l4 = TestUtils.executeAndWait(tasks, JOBS);
System.out.println("Deleting " + FEEDS + " Feeds [Warm - " + JOBS + " Jobs] took: " + (l1 + l2 + l3 + l4) / 4 + "ms\n");
if (ex.size() > 0)
throw ex.get(0);
}
private List<ITask> getDeleteFeedsTasks(final List<Exception> ex) throws PersistenceException {
List<ITask> tasks = new ArrayList<ITask>();
List<FeedReference> feedRefs = saveFeedsHelper();
for (final FeedReference feedRef : feedRefs) {
tasks.add(new TaskAdapter() {
public IStatus run(IProgressMonitor monitor) {
try {
fDao.deleteFeed(feedRef);
} catch (Exception e) {
ex.add(e);
}
return Status.OK_STATUS;
}
});
}
return tasks;
}
/**
* @throws Exception
*/
@SuppressWarnings("nls")
@Test
public void updateFeeds() throws Exception {
final List<Exception> ex = new ArrayList<Exception>();
/* Cold-Start: Update 216 Feeds */
List<ITask> tasks = getUpdateFeedsTasks(ex);
System.out.println("Updating " + FEEDS + " Feeds [Cold - " + JOBS + " Jobs] took: " + TestUtils.executeAndWait(tasks, JOBS) + "ms");
/* Warm-Start: Update 216 Feeds */
NewsModel.getDefault().getPersistenceLayer().recreateSchema();
tasks = getUpdateFeedsTasks(ex);
long l1 = TestUtils.executeAndWait(tasks, JOBS);
NewsModel.getDefault().getPersistenceLayer().recreateSchema();
tasks = getUpdateFeedsTasks(ex);
long l2 = TestUtils.executeAndWait(tasks, JOBS);
NewsModel.getDefault().getPersistenceLayer().recreateSchema();
tasks = getUpdateFeedsTasks(ex);
long l3 = TestUtils.executeAndWait(tasks, JOBS);
NewsModel.getDefault().getPersistenceLayer().recreateSchema();
tasks = getUpdateFeedsTasks(ex);
long l4 = TestUtils.executeAndWait(tasks, JOBS);
System.out.println("Updating " + FEEDS + " Feeds [Warm - " + JOBS + " Jobs] took: " + (l1 + l2 + l3 + l4) / 4 + "ms\n");
if (ex.size() > 0)
throw ex.get(0);
}
@SuppressWarnings("nls")
private List<ITask> getUpdateFeedsTasks(final List<Exception> ex) throws PersistenceException {
List<ITask> tasks = new ArrayList<ITask>();
/* Save some Feeds first */
List<IFeed> feeds = interpretFeedsHelper();
List<IFeed> savedFeeds = new ArrayList<IFeed>(feeds.size());
for (IFeed feed : feeds)
savedFeeds.add(fDao.saveFeed(feed));
/* Interpret them again for updates */
List<IFeed> newFeeds = interpretFeedsHelper();
// To test pure updates on pure detached entities, replace newFeeds
// with savedFeeds and comment out the existingFeed[0].merge(feed) inside
// the task
for (final IFeed feed : newFeeds) {
final IFeed[] existingFeed = new IFeed[1];
for (IFeed savedFeed : savedFeeds) {
if (savedFeed.getLink().toString().equals(feed.getLink().toString())) {
existingFeed[0] = savedFeed;
// Enable this if you want to eliminate the Feed#merge time from
// the test, must also comment this same line inside the task
// existingFeed[0].merge(feed);
// break;
}
}
tasks.add(new TaskAdapter() {
public IStatus run(IProgressMonitor monitor) {
try {
// Uncomment this line and comment the following one to use load the
// full feed before the merge
// existingFeed[0] =
// feedManager.loadFullEntity(existingFeed[0].getId());
existingFeed[0] = fDao.loadFeed(existingFeed[0].getId());
feed.setCopyright("The new Copyright");
feed.setDescription("The Description has changed as well");
feed.setPublishDate(new Date());
if (feed.getNews().size() > 0) {
feed.getNews().get(0).setDescription("Some new news description");
}
NewsModel.getDefault().getTypesFactory().createNews(null, feed, new Date()).setTitle("The New News");
// Uncomment this line and comment out the next two to test the
// performance of setting the id on a new entity to force
// an update
// fDao.saveFeed(feed);
existingFeed[0].merge(feed);
fDao.saveFeed(existingFeed[0]);
} catch (Exception e) {
ex.add(e);
}
return Status.OK_STATUS;
}
});
}
return tasks;
}
/**
* @throws Exception
*/
@SuppressWarnings("nls")
@Test
public void resolveSaveFeeds() throws Exception {
final List<Exception> ex = new ArrayList<Exception>();
/* Cold-Start: Save and Resolve 216 Feeds */
List<ITask> tasks = getResolveSaveFeedsTasks(ex);
System.out.println("Saving/Resolving " + FEEDS / 2 + " Feeds [Cold - " + JOBS + " Jobs] took: " + TestUtils.executeAndWait(tasks, JOBS) + "ms");
/* Warm-Start: Save and Resolve 216 Feeds */
NewsModel.getDefault().getPersistenceLayer().recreateSchema();
tasks = getResolveSaveFeedsTasks(ex);
long l1 = TestUtils.executeAndWait(tasks, JOBS);
NewsModel.getDefault().getPersistenceLayer().recreateSchema();
tasks = getResolveSaveFeedsTasks(ex);
long l2 = TestUtils.executeAndWait(tasks, JOBS);
NewsModel.getDefault().getPersistenceLayer().recreateSchema();
tasks = getResolveSaveFeedsTasks(ex);
long l3 = TestUtils.executeAndWait(tasks, JOBS);
NewsModel.getDefault().getPersistenceLayer().recreateSchema();
tasks = getResolveSaveFeedsTasks(ex);
long l4 = TestUtils.executeAndWait(tasks, JOBS);
System.out.println("Saving/Resolving " + FEEDS / 2 + " Feeds [Warm - " + JOBS + " Jobs] took: " + (l1 + l2 + l3 + l4) / 4 + "ms\n");
if (ex.size() > 0)
throw ex.get(0);
}
private List<ITask> getResolveSaveFeedsTasks(final List<Exception> ex) throws PersistenceException {
List<ITask> tasks = new ArrayList<ITask>();
/* Save some Feeds first */
final List<FeedReference> feedRefs = new ArrayList<FeedReference>();
final List<IFeed> feeds = interpretFeedsHelper();
final int limit = feeds.size() / 2;
for (int i = 0; i < limit; i++)
feedRefs.add(new FeedReference(fDao.saveFeed(feeds.get(i)).getId()));
/* Tasks to resolve Feeds */
for (int i = 0; i < limit; i++) {
final int a = i;
/* Add Task to save a Feed (88%) */
if (a % 8 != 0) {
tasks.add(new TaskAdapter() {
public IStatus run(IProgressMonitor monitor) {
try {
fDao.saveFeed(feeds.get(a + limit));
} catch (Exception e) {
ex.add(e);
}
return Status.OK_STATUS;
}
});
}
/* Add Task to resolve a Feed (12%) */
if (a % 8 == 0) {
tasks.add(new TaskAdapter() {
public IStatus run(IProgressMonitor monitor) {
try {
IFeed feed = feedRefs.get(a).resolve();
if (feed.getAuthor() != null)
accessAllFields(feed.getAuthor());
List<ICategory> feedCats = feed.getCategories();
for (ICategory category : feedCats)
accessAllFields(category);
if (feed.getImage() != null)
accessAllFields(feed.getImage());
accessAllFields(feed);
Collection<INews> newsList = feed.getNews();
for (INews news : newsList) {
accessAllFields(news);
List<IAttachment> attachments = news.getAttachments();
for (IAttachment attachment : attachments)
accessAllFields(attachment);
if (news.getAuthor() != null)
accessAllFields(news.getAuthor());
List<ICategory> categories = news.getCategories();
for (ICategory category : categories)
accessAllFields(category);
if (news.getGuid() != null)
accessAllFields(news.getGuid());
if (news.getSource() != null)
accessAllFields(news.getSource());
if (news.getLabel() != null)
accessAllFields(news.getLabel());
}
} catch (Exception e) {
ex.add(e);
}
return Status.OK_STATUS;
}
});
}
}
return tasks;
}
private List<FeedReference> saveFeedsHelper() throws PersistenceException {
List<IFeed> feeds = interpretFeedsHelper();
List<FeedReference> feedRefs = new ArrayList<FeedReference>();
for (IFeed feed : feeds)
feedRefs.add(new FeedReference(fDao.saveFeed(feed).getId()));
return feedRefs;
}
@SuppressWarnings("nls")
private List<IFeed> interpretFeedsHelper() {
List<IFeed> feeds = new ArrayList<IFeed>();
for (int i = 1; i < FEEDS + 1; i++) {
try {
URL feedUrl = fPluginLocation.toURI().resolve("data/performance/" + i + ".xml").toURL();
IFeed feed = new Feed(feedUrl);
InputStream inS = fConManager.load(feed.getLink());
Interpreter.getDefault().interpret(inS, feed);
feeds.add(feed);
} catch (Exception e) {
Activator.getDefault().logError(e.getMessage(), e);
}
}
return feeds;
}
private void accessAllFields(IExtendableType type) {
if (type instanceof IEntity) {
((IEntity) type).getId();
}
Map<String, ? > properties = type.getProperties();
if (properties != null) {
Set<String> keys = properties.keySet();
for (String string : keys)
properties.get(string);
}
if (type instanceof IFeed) {
IFeed feed = (IFeed) type;
feed.getBase();
feed.getCopyright();
feed.getDaysToSkip();
feed.getDescription();
feed.getDocs();
feed.getFormat();
feed.getGenerator();
feed.getHomepage();
feed.getHoursToSkip();
feed.getLanguage();
feed.getLastBuildDate();
feed.getLastModifiedDate();
feed.getLink();
feed.getProperties();
feed.getPublishDate();
feed.getRating();
feed.getTitle();
feed.getTTL();
feed.getUpdateBase();
feed.getUpdateFrequency();
feed.getUpdatePeriod();
feed.getWebmaster();
}
else if (type instanceof INews) {
INews news = (INews) type;
news.getBase();
news.getComments();
news.getDescription();
news.getLink();
news.getModifiedDate();
news.getPublishDate();
news.getRating();
news.getReceiveDate();
news.getState();
news.getTitle();
}
else if (type instanceof IAttachment) {
IAttachment attachment = (IAttachment) type;
attachment.getLength();
attachment.getType();
attachment.getUrl();
}
else if (type instanceof ICategory) {
ICategory category = (ICategory) type;
category.getDomain();
category.getName();
}
else if (type instanceof ISource) {
ISource source = (ISource) type;
source.getName();
source.getUrl();
}
else if (type instanceof IPerson) {
IPerson person = (IPerson) type;
person.getEmail();
person.getName();
person.getUri();
}
else if (type instanceof IImage) {
IImage image = (IImage) type;
image.getDescription();
image.getHeight();
image.getWidth();
image.getLink();
image.getTitle();
image.getUrl();
}
else if (type instanceof ILabel) {
ILabel label = (ILabel) type;
label.getColor();
label.getName();
}
else if (type instanceof IGuid) {
IGuid guid = (IGuid) type;
guid.getValue();
}
else if (type instanceof ICloud) {
ICloud cloud = (ICloud) type;
cloud.getDomain();
cloud.getPath();
cloud.getPort();
cloud.getRegisterProcedure();
cloud.getProtocol();
cloud.getFeed();
}
else if (type instanceof ITextInput) {
ITextInput input = (ITextInput) type;
input.getDescription();
input.getLink();
input.getName();
input.getTitle();
input.getFeed();
}
}
}