Commit 001db69f authored by Matija Obreza's avatar Matija Obreza

Crop#rules editable

parent 05ab953c
......@@ -570,7 +570,7 @@
<configuration>
<stopPort>8888</stopPort>
<stopKey>stop</stopKey>
<jvmArgs>-Dspring.profiles.active=dev -Xmx2048M -Xms1024M -XX:MaxPermSize=128M -Djava.awt.headless=true -server</jvmArgs>
<jvmArgs>-Dspring.profiles.active=dev -Xmx2048M -Xms1024M -XX:MaxPermSize=128M -Djava.awt.headless=true -server -Dorg.eclipse.jetty.server.Request.maxFormContentSize=5000000</jvmArgs>
</configuration>
</plugin>
<plugin>
......
......@@ -183,7 +183,7 @@ public class CropServiceImpl implements CropService {
public void rebuildTaxonomies(Crop crop) {
LOG.info("Rebuilding crop taxonomy for: " + crop.getName());
// for all rules
final List<CropRule> cropRules = crop.getCropRules();
final List<CropRule> cropRules = getCropRules(crop);
LOG.warn("Using rules: " + cropRules);
rebuildCropTaxonomies(crop, cropRules);
}
......@@ -196,9 +196,9 @@ public class CropServiceImpl implements CropService {
if (!cr.isIncluded())
continue;
if (cr.getSpecies() == null && cr.getSubtaxa() == null) {
if (StringUtils.isBlank(cr.getSpecies()) && StringUtils.isBlank(cr.getSubtaxa())) {
taxa.addAll(taxonomy2Repository.findByGenus(cr.getGenus()));
} else if (cr.getSubtaxa() == null) {
} else if (StringUtils.isBlank(cr.getSubtaxa())) {
taxa.addAll(taxonomy2Repository.findByGenusAndSpecies(cr.getGenus(), cr.getSpecies()));
} else {
taxa.addAll(taxonomy2Repository.findByGenusAndSpeciesAndSubtaxa(cr.getGenus(), cr.getSpecies(), cr.getSubtaxa()));
......
......@@ -16,11 +16,14 @@
package org.genesys2.server.servlet.controller;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.elasticsearch.common.lang3.StringUtils;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.model.impl.CropRule;
import org.genesys2.server.model.impl.CropTaxonomy;
import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.CropService;
......@@ -43,6 +46,12 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
@Controller
@RequestMapping("/c")
public class CropController extends BaseController {
......@@ -100,6 +109,11 @@ public class CropController extends BaseController {
@PreAuthorize("hasRole('ADMINISTRATOR') or hasRole('CONTENTMANAGER') or hasPermission(#crop, 'ADMINISTRATION')")
public String edit(ModelMap model, @PathVariable(value = "shortName") String shortName) {
view(model, shortName);
try {
model.addAttribute("cropRulesJson", new ObjectMapper().writeValueAsString(model.get("cropRules")));
} catch (JsonProcessingException e) {
}
return "/crop/edit";
}
......@@ -117,7 +131,7 @@ public class CropController extends BaseController {
return "/crop/edit";
}
@RequestMapping("/{shortName}/update")
@RequestMapping(value = "/{shortName}/update", method = RequestMethod.POST)
public String update(ModelMap model, @PathVariable(value = "shortName") String shortName, @RequestParam("cropName") String cropName,
@RequestParam("blurp") String aboutBody, @RequestParam(value = "summary", required = false) String summary) {
......@@ -132,7 +146,7 @@ public class CropController extends BaseController {
return "redirect:/c/" + shortName;
}
@RequestMapping(value = "/{shortName}/update", params = { "otherNames" })
@RequestMapping(value = "/{shortName}/update", params = { "otherNames" }, method = RequestMethod.POST)
public String updateOtherNames(ModelMap model, @PathVariable(value = "shortName") String shortName, @RequestParam("otherNames") String otherNames) {
_logger.debug("Updating crop aliases for " + shortName);
......@@ -147,6 +161,37 @@ public class CropController extends BaseController {
return edit(model, shortName);
}
@RequestMapping(value = "/{shortName}/update", params = { "action=update-rules", "cropRules" }, method = RequestMethod.POST)
public String updateCropRules(ModelMap model, @PathVariable(value = "shortName") String shortName, @RequestParam("cropRules") String cropRulesJson)
throws JsonParseException, JsonMappingException, IOException {
_logger.debug("Updating crop rules for " + shortName);
final Crop crop = cropService.getCrop(shortName);
if (crop == null) {
throw new ResourceNotFoundException();
}
List<CropRule> rules = new ObjectMapper().readValue(cropRulesJson, new TypeReference<List<CropRule>>() {
});
cropService.setCropRules(crop, rules);
return edit(model, shortName);
}
@RequestMapping(value = "/{shortName}/update", params = { "action=update-taxonomy" }, method = RequestMethod.POST)
public String updateTaxonomies(ModelMap model, @PathVariable(value = "shortName") String shortName) {
_logger.debug("Updating crop taxonomies for " + shortName);
final Crop crop = cropService.getCrop(shortName);
if (crop == null) {
throw new ResourceNotFoundException();
}
cropService.rebuildTaxonomies(crop);
return edit(model, shortName);
}
@RequestMapping("/{shortName}/ajax/taxonomies")
public String ajaxTaxonomies(ModelMap model, @PathVariable(value = "shortName") String shortName,
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
......
......@@ -35,7 +35,6 @@ import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.StopWatch;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.persistence.domain.AccessionRepository;
import org.genesys2.server.persistence.domain.GenesysLowlevelRepository;
import org.genesys2.server.service.CountryNamesUpdater;
......@@ -56,8 +55,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
......@@ -378,14 +375,14 @@ public class AdminController {
return "redirect:/admin/";
}
@RequestMapping(value = "/rebuild-taxonomies", method = RequestMethod.POST)
@RequestMapping(value = "/taxonomy", method = RequestMethod.POST, params={"action=taxonomy-rebuild"})
public String rebuild() {
LOG.info("Rebuilding taxonomies");
cropService.rebuildTaxonomies();
return "redirect:/admin/";
}
@RequestMapping(value = "/cleanup-taxonomies", method = RequestMethod.POST)
@RequestMapping(value = "/taxonomy", method = RequestMethod.POST, params={"action=taxonomy-cleanup"})
public String cleanupTaxonomies() {
taxonomyService.cleanupTaxonomies();
return "redirect:/admin/";
......
......@@ -122,8 +122,9 @@
</form>
<h3>Taxonomy</h3>
<form method="post" action="<c:url value="/admin/cleanup-taxonomies" />">
<input type="submit" class="btn btn-default" value="Cleanup taxonomies" />
<form method="post" action="<c:url value="/admin/taxonomy" />">
<button class="btn btn-default" name="action" value="taxonomy-cleanup">Removed unused Taxonomy2 records</button>
<button class="btn btn-default" name="action" value="taxonomy-rebuild">Rebuild</button>
<!-- CSRF protection -->
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
</form>
......
......@@ -63,6 +63,21 @@
<input type="submit" value="<spring:message code="save"/>" class="btn btn-primary" />
</form>
<form role="form" class="form-horizontal" action="<c:url value="/c/${crop.shortName}/update" />" method="post">
<div class="form-group">
<label class="col-lg-12 control-label">
<spring:message code="crop.cropname-aliases" />
</label>
<div class="controls col-lg-12">
<textarea name="cropRules" class="form-control"><c:out value="${cropRulesJson}" /></textarea>
</div>
</div>
<!-- CSRF protection -->
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
<button name="action" value="update-rules" class="btn btn-primary"><spring:message code="save"/></button>
<button name="action" value="update-taxonomy" class="btn btn-default">Re-link Taxonomy2 records</button>
</form>
<content tag="javascript">
<script type="text/javascript">
<local:tinyMCE selector=".html-editor" />
......
......@@ -111,13 +111,13 @@
</h3>
<div class="row">
<div class="col-md-offset-2 col-md-10">
<ul class="funny-list">
<ul class="funny-list"><li>
<c:forEach items="${cropRules}" var="rule">
<li class="${rule.included ? '' : 'excluded'}">
<span class="${rule.included ? '' : 'excluded'}">
<b>${rule.included ? '+' : '-'}</b> <c:out value="${rule.genus}"/> <c:out
value="${rule.species eq null ? '*' : rule.species}"/></li>
value="${rule.species eq null ? '*' : rule.species}"/></span>
</c:forEach>
</ul>
</li></ul>
<%-- <h3><spring:message code="taxonomy-list"/></h3> --%>
<ul class="funny-list">
......
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