Commit 630d0982 authored by Matija Obreza's avatar Matija Obreza
Browse files

Crops

parent 285b1059
package org.crophub.rest.common.model.impl;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.Table;
import org.crophub.rest.common.model.BusinessModel;
@Entity
@Table(name = "crop")
public class Crop extends BusinessModel {
private static final long serialVersionUID = -2686341831839109257L;
@Column(nullable = false, length = 200)
private String name;
/**
* Crop short name used as short name in URLs
*/
@Column(nullable = false, length = 50, unique = true)
private String shortName;
@Lob
private String description;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getShortName() {
return shortName;
}
public void setShortName(String shortName) {
this.shortName = shortName;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
/**
* 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.Crop;
import org.springframework.data.jpa.repository.JpaRepository;
public interface CropRepository extends JpaRepository<Crop, Long> {
Crop findByShortName(String shortName);
}
package org.crophub.rest.common.service;
import java.util.List;
import org.crophub.rest.common.model.impl.Crop;
public interface CropService {
List<Crop> list();
Crop getCrop(String shortName);
}
package org.crophub.rest.common.service.impl;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.crophub.rest.common.model.impl.Crop;
import org.crophub.rest.common.persistence.domain.CropRepository;
import org.crophub.rest.common.service.CropService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@Transactional(readOnly = true)
public class CropServiceImpl implements CropService {
public static final Log LOG = LogFactory.getLog(CropServiceImpl.class);
@Autowired
CropRepository cropRepository;
@Override
public Crop getCrop(String shortName) {
return cropRepository.findByShortName(shortName);
}
@Override
public List<Crop> list() {
return cropRepository.findAll(new Sort("name"));
}
}
package org.crophub.rest.servlet.controller;
import org.crophub.rest.common.model.impl.Crop;
import org.crophub.rest.common.service.CropService;
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("/c")
public class CropController extends BaseController {
@Autowired
private CropService cropService;
@RequestMapping("/{shortName}")
public String view(ModelMap model, @PathVariable(value = "shortName") String shortName) {
_logger.debug("Viewing crop " + shortName);
Crop crop = cropService.getCrop(shortName);
model.addAttribute("crop", crop);
return "/crop/index";
}
}
......@@ -28,6 +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.CropService;
import org.crophub.rest.common.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
......@@ -50,6 +51,9 @@ public class HtmlController extends BaseController {
@Autowired
private UserService userService;
@Autowired
private CropService cropService;
@Autowired
private Validator validator;
......@@ -69,6 +73,7 @@ public class HtmlController extends BaseController {
public String index(ModelMap model) {
List<Permissions> permissionsList = Arrays.asList(Permissions.values());
model.addAttribute("permissionsList", permissionsList);
model.addAttribute("cropList", cropService.list());
return "/index";
}
......
......@@ -68,6 +68,11 @@ sample.message.organizations = Organizations
sample.message.invite.organizations = Invite Organizations
sample.message.invite.to.network = Invite to Network
data.error.404=The data you requested was not found in the system.
user.pulldown.logout=Logout
user.pulldown.profile=View profile
crop.croplist=Crop list
crop.page.profile.title=Crop profile
<!DOCTYPE html>
<%@include file="/WEB-INF/jsp/init.jsp"%>
<html>
<head>
<title><spring:message code="crop.page.profile.title" /></title>
</head>
<body>
<c:if test="${crop eq null}">
<div class="alert alert-error"><spring:message code="data.error.404"/></div>
</c:if>
<h1><c:out value="${crop.name}" /></h1>
<div class="free-text">
<c:out value="${crop.description}" />
</div>
</body>
</html>
\ No newline at end of file
......@@ -4,9 +4,17 @@
<html>
<head>
<title><spring:message code="sample.message.index.title"/></title>
<title><spring:message code="sample.message.index.title" /></title>
</head>
<body>
<c:if test="${cropList ne null and cropList.size() gt 0}">
<h3><spring:message code="crop.croplist"/></h3>
<ul>
<c:forEach items="${cropList}" var="crop" varStatus="status">
<li><a href="/c/${crop.shortName}"><c:out value="${crop.name}" /></a></li>
</c:forEach>
</ul>
</c:if>
</body>
</html>
\ No newline at end of file
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