Commit bb51bc98 authored by Matija Obreza's avatar Matija Obreza
Browse files

Articles

parent a15c5e5f
package org.crophub.rest.common.model.impl;
import java.util.Calendar;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.crophub.rest.common.model.BusinessModel;
@Entity
@Table(name = "article")
public class Article extends BusinessModel {
private static final long serialVersionUID = 8690395020204070378L;
@Column(nullable = false, length = 150)
private String slug;
@Lob
private String title;
@Lob
private String body;
@Temporal(TemporalType.TIMESTAMP)
private Calendar postDate;
public String getSlug() {
return slug;
}
public void setSlug(String slug) {
this.slug = slug;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
public Calendar getPostDate() {
return postDate;
}
public void setPostDate(Calendar postDate) {
this.postDate = postDate;
}
}
/**
* Copyright 2013 Global Crop Diversity Trust
*
* Licensed 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.crophub.rest.common.persistence.domain;
import org.crophub.rest.common.model.impl.Article;
import org.springframework.data.jpa.repository.JpaRepository;
public interface ArticleRepository extends JpaRepository<Article, Long> {
Article findBySlug(String slug);
}
......@@ -3,9 +3,12 @@ package org.crophub.rest.common.service;
import java.util.List;
import org.crophub.rest.common.model.impl.ActivityPost;
import org.crophub.rest.common.model.impl.Article;
public interface ActivityPostService {
public interface ContentService {
List<ActivityPost> lastNews();
Article getArticle(String slug);
}
......@@ -3,8 +3,10 @@ package org.crophub.rest.common.service.impl;
import java.util.List;
import org.crophub.rest.common.model.impl.ActivityPost;
import org.crophub.rest.common.model.impl.Article;
import org.crophub.rest.common.persistence.domain.ActivityPostRepository;
import org.crophub.rest.common.service.ActivityPostService;
import org.crophub.rest.common.persistence.domain.ArticleRepository;
import org.crophub.rest.common.service.ContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort.Direction;
......@@ -13,10 +15,13 @@ import org.springframework.transaction.annotation.Transactional;
@Service
@Transactional(readOnly = true)
public class ActivityPostServiceImpl implements ActivityPostService {
public class ContentServiceImpl implements ContentService {
@Autowired
private ActivityPostRepository postRepository;
@Autowired
private ArticleRepository articleRepository;
@Override
public List<ActivityPost> lastNews() {
......@@ -24,4 +29,8 @@ public class ActivityPostServiceImpl implements ActivityPostService {
return postRepository.findAll(page).getContent();
}
@Override
public Article getArticle(String slug) {
return articleRepository.findBySlug(slug);
}
}
package org.crophub.rest.servlet.controller;
import org.crophub.rest.common.model.impl.Article;
import org.crophub.rest.common.service.ContentService;
import org.crophub.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/content")
public class ArticleController extends BaseController {
@Autowired
private ContentService contentService;
@RequestMapping("{url}")
public String view(ModelMap model, @PathVariable(value = "url") String slug) {
_logger.debug("Viewing article " + slug);
Article article = contentService.getArticle(slug);
if (article == null) {
throw new ResourceNotFoundException();
}
model.addAttribute("title", article.getTitle());
model.addAttribute("article", article);
return "/content/article";
}
}
......@@ -28,7 +28,7 @@ import org.crophub.rest.common.aspect.AsAdmin;
import org.crophub.rest.common.model.Permissions;
import org.crophub.rest.common.model.UserRole;
import org.crophub.rest.common.model.impl.User;
import org.crophub.rest.common.service.ActivityPostService;
import org.crophub.rest.common.service.ContentService;
import org.crophub.rest.common.service.CropService;
import org.crophub.rest.common.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -57,7 +57,7 @@ public class HtmlController extends BaseController {
private CropService cropService;
@Autowired
private ActivityPostService activityPostService;
private ContentService activityPostService;
@Autowired
private Validator validator;
......
......@@ -71,10 +71,20 @@ sample.message.invite.to.network = Invite to Network
data.error.404=The data you requested was not found in the system.
page.rendertime=Processing this page took {0}ms.
footer.copyright-statement=&copy;2013 Global Crop Diversity Trust
footer.copyright-statement=&copy; 2013 Global Crop Diversity Trust
menu.about=About
menu.contact=Contact
menu.disclaimer=Disclaimer
menu.feedback=Feedback
menu.help=Help
menu.terms=Terms and Conditions of Use
menu.copying=Copyright policy
menu.privacy=Privacy policy
user.pulldown.logout=Logout
user.pulldown.profile=View profile
user.create-new-account=Create an account
crop.croplist=Crop list
crop.page.profile.title={0} profile
......
......@@ -61,8 +61,13 @@
</div>
</div>
<sec:authorize access="isAuthenticated()">
<div class="navbar pull-right">
<sec:authorize access="isAnonymous()">
<div style="line-height: 20px; padding: 10px 15px;">
<a href="<c:url value="/login" />">Login</a> or <a href="<c:url value="/registration" />"><spring:message code="user.create-new-account" /></a>
</div>
</sec:authorize>
<sec:authorize access="isAuthenticated()">
<ul class="nav">
<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" title="<spring:message code="sample.message.change.locale"/>"> You are <b>${user.username}</b> <b class="caret"></b>
</a>
......@@ -71,8 +76,8 @@
<li><a href="<c:url value="/logout" />"><spring:message code="user.pulldown.logout" /></a></li>
</ul></li>
</ul>
</div>
</sec:authorize>
</div>
</div>
</div>
......@@ -102,18 +107,18 @@
<div id="nav-foot" class="clearfix">
<div class="pull-left">
<ul>
<li><a href="<c:url value="/" />">About</a></li>
<li><a href="<c:url value="/" />">Contact</a></li>
<li><a href="<c:url value="/" />">Disclaimer</a></li>
<li><a href="<c:url value="/" />">Feedback</a></li>
<li><a href="<c:url value="/" />">Help</a></li>
<li><a href="<c:url value="/content/about" />"><spring:message code="menu.about" /></a></li>
<li><a href="<c:url value="/content/contact" />"><spring:message code="menu.contact" /></a></li>
<li><a href="<c:url value="/content/disclaimer" />"><spring:message code="menu.disclaimer" /></a></li>
<li><a href="<c:url value="/content/feedback" />"><spring:message code="menu.feedback" /></a></li>
<li><a href="<c:url value="/content/help" />"><spring:message code="menu.help" /></a></li>
</ul>
</div>
<div class="pull-right">
<ul>
<li><a href="<c:url value="/" />">Terms and Conditions of Use</a></li>
<li><a href="<c:url value="/" />">Copyright Policy</a></li>
<li><a href="<c:url value="/" />">Privacy Policy</a></li>
<li><a href="<c:url value="/content/terms" />"><spring:message code="menu.terms" /></a></li>
<li><a href="<c:url value="/content/copying" />"><spring:message code="menu.copying" /></a></li>
<li><a href="<c:url value="/content/privacy" />"><spring:message code="menu.privacy" /></a></li>
</ul>
</div>
</div>
......
<!DOCTYPE html>
<%@include file="/WEB-INF/jsp/init.jsp"%>
<html>
<head>
<title>${title}</title>
</head>
<body>
<c:if test="${title ne ''}">
<h1>
<c:out value="${title}" />
</h1>
</c:if>
<div class="">
<c:out value="${article.body}" escapeXml="false" />
</div>
<div class="clearfix pull-right">
<fmt:formatDate value="${article.postDate.time}" />
</div>
</body>
</html>
\ No newline at end of file
......@@ -138,6 +138,7 @@ body {
#header {
padding: 1em 1em 0.5em 1em;
background-color: #4d4c47;
color: White;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment