Commit c0d96a96 authored by Matija Obreza's avatar Matija Obreza

/archive controller

parent 47f4ef38
......@@ -22,6 +22,7 @@ import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.genesys2.server.model.elastic.AccessionDetails;
import org.genesys2.server.model.genesys.Accession;
......@@ -219,5 +220,6 @@ public interface GenesysService {
int assignMissingUuid(int count);
AccessionHistoric getHistoricAccession(UUID uuid);
}
......@@ -1515,7 +1515,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
public int assignMissingUuid(int count) {
List<AccessionId> accessionIds = accessionIdRepository.findMissingUuid(new PageRequest(0, count));
for (AccessionId accessionId : accessionIds) {
if (accessionId.getUuid()==null) {
if (accessionId.getUuid() == null) {
accessionId.setUuid(UUID.randomUUID());
}
}
......@@ -1524,4 +1524,12 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
return accessionIds.size();
}
@Override
public AccessionHistoric getHistoricAccession(UUID uuid) {
AccessionHistoric ah = accessionHistoricRepository.findOneByUuid(uuid);
if (ah != null) {
ah.getStoRage().size();
}
return ah;
}
}
......@@ -44,7 +44,7 @@ import org.springframework.web.bind.annotation.RequestParam;
@RequestMapping("/acn")
public class AccessionController extends BaseController {
private static final UUID WORLDCLIM_DATASET_UUID = UUID.fromString("BC84433B-A626-4BDF-97D3-DB36D79499C6");
public static final UUID WORLDCLIM_DATASET_UUID = UUID.fromString("BC84433B-A626-4BDF-97D3-DB36D79499C6");
@Autowired
private InstituteService instituteService;
......
/**
* Copyright 2015 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.genesys2.server.servlet.controller;
import java.util.UUID;
import org.genesys2.server.model.dataset.DS;
import org.genesys2.server.model.genesys.AccessionGeo;
import org.genesys2.server.model.genesys.AccessionHistoric;
import org.genesys2.server.service.CropService;
import org.genesys2.server.service.DSService;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.TaxonomyService;
import org.genesys2.server.service.TraitService;
import org.genesys2.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;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping("/archive")
public class ArchiveController extends BaseController {
@Autowired
private GenesysService genesysService;
@Autowired
private TraitService traitService;
@Autowired
private TaxonomyService taxonomyService;
@Autowired
private CropService cropService;
@Autowired
private DSService dsService;
@RequestMapping(value = "/{uuid:.{36}}", method = RequestMethod.GET)
public String view(ModelMap model, @PathVariable(value = "uuid") UUID uuid) {
_logger.debug("Viewing archive ACN " + uuid);
fillModel(model, uuid);
return "/accession/details";
}
@RequestMapping(value = "/{uuid:.{36}}", method = RequestMethod.GET, headers = "accept=text/turtle", produces = "text/turtle")
public String viewTurtle(ModelMap model, @PathVariable(value = "uuid") UUID uuid) {
_logger.debug("Viewing archive ACN " + uuid);
fillModel(model, uuid);
return "/accession/details-turtle";
}
private void fillModel(ModelMap model, UUID uuid) {
final AccessionHistoric accession = genesysService.getHistoricAccession(uuid);
if (accession == null) {
throw new ResourceNotFoundException();
}
model.addAttribute("accession", accession);
model.addAttribute("accessionNames", genesysService.listAccessionNames(accession.getAccessionId()));
model.addAttribute("accessionAliases", genesysService.listAccessionAliases(accession.getAccessionId()));
model.addAttribute("accessionExchange", genesysService.listAccessionExchange(accession.getAccessionId()));
model.addAttribute("accessionCollect", genesysService.listAccessionCollect(accession.getAccessionId()));
model.addAttribute("accessionBreeding", genesysService.listAccessionBreeding(accession.getAccessionId()));
AccessionGeo accessionGeo = genesysService.listAccessionGeo(accession.getAccessionId());
model.addAttribute("accessionGeo", accessionGeo);
model.addAttribute("svalbardData", genesysService.getSvalbardData(accession.getAccessionId()));
model.addAttribute("accessionRemarks", genesysService.listAccessionRemarks(accession.getAccessionId()));
model.addAttribute("metadatas", genesysService.listMetadata(accession.getAccessionId()));
model.addAttribute("methods", traitService.listMethods(accession.getAccessionId()));
model.addAttribute("methodValues", genesysService.getAccessionTraitValues(accession.getAccessionId()));
model.addAttribute("crops", cropService.getCrops(accession.getTaxonomy()));
// Worldclim data
if (accessionGeo != null && accessionGeo.getTileIndex() != null) {
DS worldClimDataset = dsService.loadDatasetByUuid(AccessionController.WORLDCLIM_DATASET_UUID);
if (worldClimDataset != null) {
model.addAttribute("worldclimJson", dsService.jsonForTile(worldClimDataset, accessionGeo.getTileIndex()));
}
}
}
}
......@@ -79,7 +79,7 @@ public class ResolverController {
}
if (resolved instanceof AccessionHistoric) {
return "redirect:/history/acn/id/" + resolved.getUuid();
return "redirect:/archive/" + resolved.getUuid();
}
throw new ResourceNotFoundException("We don't have an object with UUID " + uuid);
......
......@@ -31,7 +31,7 @@
<div class="col-sm-2">
<c:choose>
<c:when test="${accession.getClass().simpleName=='AccessionHistoric'}">
<a href="<c:url value="/archive/acn/${accession.uuid}" />"><c:out value="${accession.accessionName}" /></a>
<a href="<c:url value="/archive/${accession.uuid}" />"><c:out value="${accession.accessionName}" /></a>
</c:when>
<c:otherwise>
<a href="<c:url value="/acn/id/${accession.id}" />"><c:out value="${accession.accessionName}" /></a>
......
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