Skip to content

Commit

Permalink
Added News section
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Jun 13, 2014
1 parent c81bdca commit 7cdd994
Show file tree
Hide file tree
Showing 10 changed files with 501 additions and 45 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/jboss/forge/website/SiteConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public interface SiteConstants
String ADDON_REPO_URL_CORE = REPO_BASE_URL + "/addons-core.yaml";
String ADDON_REPO_URL_COMMUNITY = REPO_BASE_URL + "/addons-community.yaml";

String DOCS_REPO_URL_NEWS = REPO_BASE_URL + "/docs-news.yaml";
String DOCS_REPO_URL_GETSTARTED = REPO_BASE_URL + "/docs-getstarted.yaml";
String DOCS_REPO_URL_TUTORIALS = REPO_BASE_URL + "/docs-tutorials.yaml";
String DOCS_REPO_URL_ADVANCED = REPO_BASE_URL + "/docs-advanced.yaml";
Expand Down
151 changes: 151 additions & 0 deletions src/main/java/org/jboss/forge/website/model/News.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
package org.jboss.forge.website.model;

import java.io.Serializable;
import java.util.Date;

import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class News implements Serializable
{
private static final long serialVersionUID = 1L;
private String title;
private String summary;
private String repo;
private String ref;
private String path;
private String author;
private String email;
private Date date;

public String getTitle()
{
return title;
}

public void setTitle(String title)
{
this.title = title;
}

public String getSummary()
{
return summary;
}

public void setSummary(String summary)
{
this.summary = summary;
}

public String getRepo()
{
return repo;
}

public void setRepo(String repository)
{
this.repo = repository;
}

public String getRef()
{
return ref;
}

public void setRef(String ref)
{
this.ref = ref;
}

public String getPath()
{
return path;
}

public void setPath(String path)
{
this.path = path;
}

public String getAuthor()
{
return author;
}

public void setAuthor(String author)
{
this.author = author;
}

public String getEmail()
{
return email;
}

public void setEmail(String email)
{
this.email = email;
}

public Date getDate()
{
return date;
}

public void setDate(Date date)
{
this.date = date;
}

@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + ((path == null) ? 0 : path.hashCode());
result = prime * result + ((ref == null) ? 0 : ref.hashCode());
result = prime * result + ((repo == null) ? 0 : repo.hashCode());
return result;
}

@Override
public boolean equals(Object obj)
{
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
News other = (News) obj;
if (path == null)
{
if (other.path != null)
return false;
}
else if (!path.equals(other.path))
return false;
if (ref == null)
{
if (other.ref != null)
return false;
}
else if (!ref.equals(other.ref))
return false;
if (repo == null)
{
if (other.repo != null)
return false;
}
else if (!repo.equals(other.repo))
return false;
return true;
}

@Override
public String toString()
{
return repo + " " + ref + " " + path;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ public Configuration getConfiguration(ServletContext context)

.addRule(Join.path("/document/{title}").to("/document").withChaining())
.where("title").transposedBy(new SpacesToDashes())


.addRule(Join.path("/news/{title}").to("/news-entry").withChaining())
.where("title").transposedBy(new SpacesToDashes())

.addRule(Join.path("/addon/{id}").to("/addon").withChaining())

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.jboss.forge.website.model.Addon.Category;
import org.jboss.forge.website.model.Contributor;
import org.jboss.forge.website.model.Document;
import org.jboss.forge.website.model.News;
import org.yaml.snakeyaml.Yaml;

import com.google.gson.Gson;
Expand All @@ -37,14 +38,14 @@ public List<Addon> getAllAddons()
{
List<Addon> result = new ArrayList<>();

List<Addon> community = fetchList(SiteConstants.ADDON_REPO_URL_COMMUNITY, Addon.class);
List<Addon> community = fetchYamlList(SiteConstants.ADDON_REPO_URL_COMMUNITY, Addon.class);
for (Addon addon : community)
{
addon.setCategory(Category.COMMUNITY);
}
result.addAll(community);

List<Addon> core = fetchList(SiteConstants.ADDON_REPO_URL_CORE, Addon.class);
List<Addon> core = fetchYamlList(SiteConstants.ADDON_REPO_URL_CORE, Addon.class);
for (Addon addon : core)
{
addon.setCategory(Category.CORE);
Expand All @@ -57,7 +58,7 @@ public List<Addon> getAllAddons()
public List<Addon> getRandomCommunityAddons(int count)
{
List<Addon> result = new ArrayList<>();
List<Addon> addons = new ArrayList<>(fetchList(SiteConstants.ADDON_REPO_URL_COMMUNITY, Addon.class));
List<Addon> addons = new ArrayList<>(fetchYamlList(SiteConstants.ADDON_REPO_URL_COMMUNITY, Addon.class));

Random random = new Random(System.currentTimeMillis());
while (result.size() < count && !addons.isEmpty())
Expand All @@ -72,21 +73,21 @@ public List<Document> getAllDocuments()
{
List<Document> result = new ArrayList<>();

List<Document> getStarted = fetchList(SiteConstants.DOCS_REPO_URL_GETSTARTED, Document.class);
List<Document> getStarted = fetchYamlList(SiteConstants.DOCS_REPO_URL_GETSTARTED, Document.class);
for (Document document : getStarted)
{
document.setCategory(org.jboss.forge.website.model.Document.Category.QUICKSTART);
}
result.addAll(getStarted);

List<Document> tutorials = fetchList(SiteConstants.DOCS_REPO_URL_TUTORIALS, Document.class);
List<Document> tutorials = fetchYamlList(SiteConstants.DOCS_REPO_URL_TUTORIALS, Document.class);
for (Document document : tutorials)
{
document.setCategory(org.jboss.forge.website.model.Document.Category.TUTORIAL);
}
result.addAll(tutorials);

List<Document> advanced = fetchList(SiteConstants.DOCS_REPO_URL_ADVANCED, Document.class);
List<Document> advanced = fetchYamlList(SiteConstants.DOCS_REPO_URL_ADVANCED, Document.class);
for (Document document : advanced)
{
document.setCategory(org.jboss.forge.website.model.Document.Category.ADVANCED);
Expand Down Expand Up @@ -137,73 +138,78 @@ public List<Contributor> getAllContributors()
return Arrays.asList(contributors);
}

/*
* Helpers
*/

private <T> List<T> parse(String content, Class<T> type)
public List<Document> getRelatedDocuments(Addon addon, int count)
{
List<T> result = new ArrayList<>();
List<Document> result = new ArrayList<>();

if (content != null)
String tagString = addon.getTags();
if (tagString != null && !tagString.isEmpty())
{
List<String> addonEntries = Arrays.asList(content.trim().split("---"));

for (String addonEntry : addonEntries)
for (String tag : tagString.split(","))
{
if (!addonEntry.trim().isEmpty())
tag = tag.trim();
for (Document doc : getAllDocuments())
{
T addon = new Yaml().loadAs(addonEntry, type);
result.add(addon);
if ((doc.getSummary() != null && doc.getSummary().contains(tag))
|| (doc.getSummary() != null && doc.getTitle().contains(tag)))
{
result.add(doc);
}
}
}
}
return result;
return new ArrayList<Document>();
}

public List<News> getAllNews()
{
List<News> news = fetchYamlList(SiteConstants.DOCS_REPO_URL_NEWS, News.class);
return news;
}

public List<News> getNews(int count)
{
List<News> news = getAllNews();
return news.subList(0, Math.min(count, news.size()));
}

/*
* Helpers
*/
private <T> T parseJson(String content, Class<T> type)
{
return new Gson().fromJson(content, type);
}

private <T> List<T> fetchList(String url, Class<T> type)
private <T> List<T> fetchYamlList(String url, Class<T> type)
{
String content = downloader.download(url);

List<T> result = null;
if (content != null)
result = parse(content, type);
result = parseYaml(content, type);
else
result = new ArrayList<>();

return result;
}

public List<Document> getRelatedDocuments(Addon addon, int count)
private <T> List<T> parseYaml(String content, Class<T> type)
{
List<Document> result = new ArrayList<Document>();

String tagString = addon.getTags();
List<String> tags = null;
if (tagString != null && !tagString.isEmpty())
tags = Arrays.asList(tagString.split(","));
List<T> result = new ArrayList<>();

if (tags != null)
if (content != null)
{
for (String tag : tags)
for (String entry : content.trim().split("---"))
{
tag = tag.trim();
for (Document doc : getAllDocuments())
if (!entry.trim().isEmpty())
{
if ((doc.getSummary() != null && doc.getSummary().contains(tag))
|| (doc.getSummary() != null && doc.getTitle().contains(tag)))
{
result.add(doc);
}
T obj = new Yaml().loadAs(entry, type);
result.add(obj);
}
}
}
return new ArrayList<Document>();
return result;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public void retrieve() throws IOException
if (documentTitle.equalsIgnoreCase(document.getTitle().replaceAll("-+", " ").replaceAll("\\s+", " ")))
{
this.document = document;
this.documentTitle = document.getTitle();
break;
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/jboss/forge/website/view/IndexBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import org.jboss.forge.website.model.Addon;
import org.jboss.forge.website.model.Contributor;
import org.jboss.forge.website.model.News;
import org.jboss.forge.website.service.RepositoryService;

/**
Expand All @@ -36,4 +37,9 @@ public List<Contributor> getContributors()
{
return service.getRandomContributors(5);
}

public List<News> getNewsFeed()
{
return service.getNews(5);
}
}

0 comments on commit 7cdd994

Please sign in to comment.