use of org.nextprot.api.web.domain.NextProtNews in project nextprot-api by calipho-sib.
the class GitHubServiceUnitTest method shouldGetANextProtNews.
@Test
public void shouldGetANextProtNews() throws Exception {
NextProtNews n = GitHubServiceImpl.parseGitHubNewsFilePath("2014/08/25/Google OAuth Support.md");
assertEquals(n.getUrl(), "google-oauth-support");
assertEquals(n.getTitle(), "Google OAuth Support");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Date date = df.parse("2014-08-25");
assertEquals(n.getPublicationDate(), date);
assertEquals(n.getPublicationDateFormatted(), "Aug 25, 2014");
}
use of org.nextprot.api.web.domain.NextProtNews in project nextprot-api by calipho-sib.
the class GitHubServiceImpl method getNews.
@Override
@Cacheable(value = "github-news")
public List<NextProtNews> getNews() {
List<NextProtNews> news = new ArrayList<>();
try {
GitHub github = getGitHubConnection();
GHRepository repo = github.getRepository("calipho-sib/nextprot-docs");
GHTree tree = repo.getTreeRecursive(githubDocBranch, 1);
newsFileNames.clear();
for (GHTreeEntry te : tree.getTree()) {
if (te.getPath().startsWith("news")) {
// Add only file on news
if (te.getType().equalsIgnoreCase("blob")) {
// file
String fileName = te.getPath().replaceAll("news/", "");
NextProtNews n = parseGitHubNewsFilePath(fileName);
if (n != null) {
news.add(n);
String fileEncoded = URLEncoder.encode(fileName.replace(".md", ""), "UTF-8").replace("+", "%20");
newsFileNames.put(n.getUrl(), fileEncoded);
}
}
}
}
} catch (IOException e) {
e.printStackTrace();
throw new NextProtException("News not available, sorry for the inconvenience");
}
Collections.sort(news);
return news;
}
use of org.nextprot.api.web.domain.NextProtNews in project nextprot-api by calipho-sib.
the class GitHubServiceImpl method parseGitHubNewsFilePath.
static NextProtNews parseGitHubNewsFilePath(String filePath) {
NextProtNews result = new NextProtNews();
if (filePath == null || filePath.equals("")) {
return null;
}
String[] elements = filePath.split("\\/");
if (elements.length != 4) {
LOGGER.warn("Number of elements is different than 4 != " + elements.length + " " + elements);
return null;
}
// Check for elements not null or empty
for (String elem : elements) {
if (elem == null || elem.isEmpty()) {
LOGGER.warn("Found a null or empty element on " + filePath);
return null;
}
}
try {
// Parse the date
DateFormat df = new SimpleDateFormat("yyyy/MM/dd");
Date date = df.parse(elements[0] + "/" + elements[1] + "/" + elements[2]);
result.setPublicationDate(date);
} catch (ParseException e) {
LOGGER.warn("Failed to parse the date for file" + filePath + " " + e.getMessage());
// e.printStackTrace();
return null;
}
// Gets url and title
String title = elements[3].replace(".md", "").trim();
result.setTitle(title);
result.setUrl(normalizeTitleToUrl(title));
return result;
}
use of org.nextprot.api.web.domain.NextProtNews in project nextprot-api by calipho-sib.
the class SeoTagsServiceImpl method getNewsSeoTags.
@Override
@Cacheable(value = "seo-github-news")
public SeoTags getNewsSeoTags(String url) {
String[] urlElements = RelativeUrlUtils.getPathElements(url);
List<NextProtNews> allNews = gitHubService.getNews();
if (urlElements.length > 1) {
String pageUrl = urlElements[1];
for (NextProtNews oneNews : allNews) {
if (pageUrl.equals(oneNews.getUrl())) {
return getOneNewsSeoTags(oneNews);
}
}
} else {
NextProtNews mostRecentNews = allNews.get(allNews.size() - 1);
return getOneNewsSeoTags(mostRecentNews);
}
return null;
}
use of org.nextprot.api.web.domain.NextProtNews in project nextprot-api by calipho-sib.
the class GitHubServiceUnitTest method shouldReturnNullIfThereIsLessThan2Slashes.
@Test
public void shouldReturnNullIfThereIsLessThan2Slashes() throws Exception {
NextProtNews n = GitHubServiceImpl.parseGitHubNewsFilePath("2014/08/Google OAuth Support.md");
assertTrue(n == null);
}
Aggregations