Commit 66b6de37 authored by Matija Obreza's avatar Matija Obreza
Browse files

Update MLS Status of accessions

parent 7d2aaeae
......@@ -116,4 +116,6 @@ public interface GenesysService {
long countAvailable(Set<Long> accessionIds);
void saveAccession(Accession... accession);
}
......@@ -389,7 +389,15 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
LOG.debug("Saving " + accessions.size() + " accessions");
}
accessionRepository.save(accessions);
}
@Override
@Transactional(readOnly = false)
public void saveAccession(Accession... accession) {
for (Accession a : accession) {
LOG.info("Updating " + a);
accessionRepository.save(a);
}
}
@Override
......
......@@ -14,7 +14,6 @@
* limitations under the License.
**/
package org.genesys2.server.servlet.controller;
import java.util.HashMap;
......@@ -46,7 +45,7 @@ public class AccessionController extends BaseController {
@Autowired
private SelectionBean selectionBean;
@Autowired
private InstituteService instituteService;
......@@ -76,14 +75,30 @@ public class AccessionController extends BaseController {
model.addAttribute("metadatas", genesysService.listMetadata(accession));
model.addAttribute("methods", genesysService.listMethods(accession));
model.addAttribute("methodValues", genesysService.getAccessionTraitValues(accession));
model.addAttribute("crops", cropService.getCrops(accession.getTaxonomy()));
model.addAttribute("selection", selectionBean);
return "/accession/details";
}
@RequestMapping("/{holdingInstitute}/{genus}/{accessionName:.+}")
public String viewInstituteAccession(ModelMap model, @PathVariable(value = "holdingInstitute") String holdingInstitute,
@PathVariable(value = "genus") String genus, @PathVariable(value = "accessionName") String accessionName) {
_logger.debug("Viewing ACN " + accessionName);
FaoInstitute faoInstitute = instituteService.getInstitute(holdingInstitute);
if (faoInstitute == null) {
throw new ResourceNotFoundException();
}
Accession accession = genesysService.getAccession(holdingInstitute, genus, accessionName);
if (accession == null) {
throw new ResourceNotFoundException();
} else {
return "redirect:/acn/id/" + accession.getId();
}
}
@RequestMapping("/{holdingInstitute}/{accessionName:.+}")
public String viewInstituteAccession(ModelMap model, @PathVariable(value = "holdingInstitute") String holdingInstitute,
@PathVariable(value = "accessionName") String accessionName) {
......@@ -151,7 +166,7 @@ public class AccessionController extends BaseController {
model.addAttribute("pagedData", accessions);
model.addAttribute("selection", selectionBean);
model.addAttribute("jsonFilter", "{\"taxon\":[\"" + taxonomy.getTaxonName() + "\"]}");
return "/accession/data";
}
......
......@@ -16,23 +16,35 @@
package org.genesys2.server.servlet.controller.rest;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map.Entry;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.service.GenesysService;
import org.genesys2.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
@Controller("restAccessionController")
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = { "/api/v0/a", "/json/v0/a" })
@RequestMapping(value = { "/api/v0/acn", "/json/v0/acn" })
public class AccessionController extends RestController {
private ObjectMapper mapper = new ObjectMapper();
@Autowired
GenesysService genesysService;
......@@ -41,13 +53,85 @@ public class AccessionController extends RestController {
*
* @return
*/
@RequestMapping(value = "/exists/{instCode}/{genus}", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE })
@RequestMapping(value = "/exists/{instCode}/{genus:.+}", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody
boolean exists(@PathVariable("instCode") String instCode, @PathVariable("genus") String genus, @RequestParam("acceNumb") String acceNumb) {
LOG.info("Checking if accn exists " + instCode + "." + acceNumb + " genus=" + genus);
if (LOG.isDebugEnabled())
LOG.debug("Checking if accn exists " + instCode + "." + acceNumb + " genus=" + genus);
Accession accession = genesysService.getAccession(instCode, genus, acceNumb);
if (accession == null) {
LOG.warn("No accession " + instCode + "." + acceNumb + " genus=" + genus);
}
return accession != null;
}
/**
* Check if accessions exists in the system
*
* @return
* @throws IOException
* @throws JsonProcessingException
*/
@RequestMapping(value = "/{instCode}/update", method = { RequestMethod.POST, RequestMethod.PUT }, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody
boolean updateInstituteAccession(@PathVariable("instCode") String instCode, @RequestBody String content) throws JsonProcessingException, IOException {
// TODO Check user's permissions to update this WIEWS institute.
JsonNode json = mapper.readTree(content);
String genus = null;
String acceNumb = null;
for (Iterator<Entry<String, JsonNode>> fields = json.fields(); fields.hasNext();) {
Entry<String, JsonNode> field = fields.next();
String key = field.getKey();
JsonNode value = field.getValue();
if ("genus".equals(key)) {
genus = value.textValue();
} else if ("acceNumb".equals(key)) {
acceNumb = value.textValue();
}
}
if (LOG.isDebugEnabled())
LOG.debug("Loading accession " + instCode + "." + acceNumb + " genus=" + genus);
Accession accession = genesysService.getAccession(instCode, genus, acceNumb);
if (accession == null) {
LOG.warn("No accession " + instCode + "." + acceNumb + " genus=" + genus);
throw new ResourceNotFoundException();
}
boolean updated = false;
for (Iterator<Entry<String, JsonNode>> fields = json.fields(); fields.hasNext();) {
Entry<String, JsonNode> field = fields.next();
String key = field.getKey();
JsonNode value = field.getValue();
if ("mlsStat".equals(key)) {
Boolean inMls = value.isNull() ? null : value.asBoolean();
if (inMls != accession.getMlsStatus()) {
if (LOG.isInfoEnabled())
LOG.info("Setting MLSSTAT to " + inMls);
accession.setMlsStatus(inMls);
updated = true;
}
}
}
if (updated) {
genesysService.saveAccession(accession);
}
return updated;
}
}
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