Commit 95952753 authored by Alexander Prendetskiy's avatar Alexander Prendetskiy Committed by Matija Obreza

New methods to AccessionController v1 to return details

parent 548b5799
......@@ -26,29 +26,28 @@ import javax.servlet.http.HttpServletRequest;
import org.genesys.blocks.model.JsonViews;
import org.genesys.catalog.api.FilteredPage;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.service.DatasetService;
import org.genesys.catalog.service.ShortFilterService;
import org.genesys2.server.api.ApiBaseController;
import org.genesys2.server.api.model.AccessionHeaderJson;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.PDCI;
import org.genesys2.server.model.impl.AccessionIdentifier3;
import org.genesys2.server.model.impl.Subset;
import org.genesys2.server.service.AccessionService;
import org.genesys2.server.service.ElasticsearchService;
import org.genesys2.server.service.ElasticsearchService.TermResult;
import org.genesys2.server.service.SubsetService;
import org.genesys2.server.service.filter.AccessionFilter;
import org.genesys2.server.service.impl.SearchException;
import org.genesys2.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
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.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.HandlerMapping;
import com.fasterxml.jackson.annotation.JsonView;
......@@ -83,6 +82,12 @@ public class AccessionController {
@Autowired
private ElasticsearchService elasticsearchService;
@Autowired
private DatasetService datasetService;
@Autowired
private SubsetService subsetService;
private final Set<String> terms = Sets.newHashSet("institute.code", "institute.country.code3", "cropName", "crop.shortName", "taxonomy.genus", "taxonomy.species",
"taxonomy.genusSpecies", "countryOfOrigin.code3", "sampStat", "available", "mlsStatus", "donorCode", "sgsv", "storage", "duplSite", "breederCode");
......@@ -175,6 +180,40 @@ public class AccessionController {
return accessionService.toUUID(identifiers);
}
@RequestMapping(value = "/details/10.{dummy:[0-9]+}/**}", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE })
@JsonView(JsonViews.Minimal.class)
public AccessionDetailsJson getAccessionDetailsByDoi(HttpServletRequest request) {
final String fullPath = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
final String doi = fullPath.substring(API_BASE.length() + 1);
Accession accession = accessionService.getByDoi(doi);
return getAccessionDetails(accession);
}
@GetMapping(value="/details/{UUID}", consumes = MediaType.APPLICATION_JSON_VALUE)
@JsonView(JsonViews.Minimal.class)
public AccessionDetailsJson getAccessionDetailsByUUID(@PathVariable("UUID") final UUID uuid) {
Accession accession = accessionService.getByUuid(uuid);
return getAccessionDetails(accession);
}
private AccessionDetailsJson getAccessionDetails(Accession accession) {
if (accession == null) {
throw new ResourceNotFoundException();
}
List<Dataset> datasets = datasetService.listByAccession(accession.getAccessionId());
List<Subset> subsets = subsetService.listByAccession(accession.getAccessionId());
AccessionDetailsJson accessionDetails = new AccessionDetailsJson();
accessionDetails.details = accession;
accessionDetails.pdci = accession.getAccessionId().getPdci();
accessionDetails.datasets = datasets;
accessionDetails.subsets = subsets;
return accessionDetails;
}
/**
* Get term overview for filters
......@@ -238,4 +277,11 @@ public class AccessionController {
return objectMapper.readValue(objectMapper.writeValueAsString(filter), AccessionFilter.class);
}
public static class AccessionDetailsJson {
public Accession details;
public PDCI pdci;
public List<Dataset> datasets;
public List<Subset> subsets;
}
}
......@@ -16,9 +16,11 @@
package org.genesys2.server.service;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import org.genesys2.server.model.genesys.AccessionId;
import org.genesys2.server.model.impl.Subset;
import org.genesys2.server.service.filter.SubsetFilter;
import org.springframework.data.domain.Page;
......@@ -131,4 +133,6 @@ public interface SubsetService {
*/
Subset approveSubset(Subset subset);
List<Subset> listByAccession(AccessionId accessionId);
}
......@@ -333,4 +333,9 @@ public class SubsetServiceImpl implements SubsetService {
return deepLoad(subsetRepository.save(loaded));
}
@Override
public List<Subset> listByAccession(AccessionId accessionId) {
return (List<Subset>) subsetRepository.findAll(QSubset.subset.accessions.contains(accessionId));
}
}
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