Commit 3c6430c1 authored by Matija Obreza's avatar Matija Obreza

One big JSON for accession

parent 4eab729c
......@@ -27,6 +27,7 @@ import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.json.AccessionJson;
import org.genesys2.server.service.BatchRESTService;
import org.genesys2.server.service.CropService;
import org.genesys2.server.service.GenesysFilterService;
import org.genesys2.server.service.GenesysRESTService;
import org.genesys2.server.service.GenesysService;
......@@ -70,7 +71,10 @@ public class AccessionController extends RestController {
@Autowired
private GenesysFilterService filterService;
@Autowired
private CropService cropService;
@Autowired
BatchRESTService batchRESTService;
......@@ -88,7 +92,7 @@ public class AccessionController extends RestController {
/**
* Check if accessions exists in the system
*
*
* @return
*/
@RequestMapping(value = "/exists/{instCode}/{genus:.+}", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE })
......@@ -109,7 +113,7 @@ public class AccessionController extends RestController {
/**
* Check if accessions exists in the system
*
*
* @return
* @throws IOException
* @throws JsonProcessingException
......@@ -170,7 +174,7 @@ public class AccessionController extends RestController {
/**
* Update accessions in the system
*
*
* @return
* @throws IOException
* @throws JsonProcessingException
......@@ -212,7 +216,7 @@ public class AccessionController extends RestController {
/**
* Update accessions in the system
*
*
* @return
* @throws IOException
* @throws JsonProcessingException
......@@ -239,7 +243,7 @@ public class AccessionController extends RestController {
/**
* Update accessions in the system
*
*
* @return
* @throws IOException
* @throws JsonProcessingException
......@@ -265,35 +269,61 @@ public class AccessionController extends RestController {
return restService.getAccessionJSON(instCode, accessionId);
}
@RequestMapping(value = "/{id}", method = { RequestMethod.GET }, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody
AccessionDetails getDetails(@PathVariable("id") long accessionId) {
final Accession accession = genesysService.getAccession(accessionId);
if (accession == null) {
throw new ResourceNotFoundException();
}
AccessionDetails ad = AccessionDetails.from(accession);
// ad.names(genesysService.listAccessionNames(accession));
ad.aliases(genesysService.listAccessionAliases(accession));
ad.exch(genesysService.listAccessionExchange(accession));
ad.collect(genesysService.listAccessionCollect(accession));
ad.breeding(genesysService.listAccessionBreeding(accession));
ad.geo(genesysService.listAccessionGeo(accession));
ad.svalbard(genesysService.getSvalbardData(accession));
ad.remarks(genesysService.listAccessionRemarks(accession));
// model.addAttribute("metadatas",
// genesysService.listMetadata(accession));
ad.traits(genesysService.listMethods(accession), genesysService.getAccessionTraitValues(accession));
ad.crops(cropService.getCrops(accession.getTaxonomy()));
return ad;
}
@RequestMapping(value = "/list", method = { RequestMethod.POST }, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody
List<AccessionJson> get(@RequestBody Set<Long> accessionIds) {
return restService.getAccessionJSON(accessionIds);
}
@RequestMapping(value = "/filter", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Object getAcc(@RequestBody JsonData jsonData) throws IOException {
String filter = "{\"crop\":[\"" + jsonData.crop + "\"]}";
ObjectNode jsonTree = null;
@RequestMapping(value = "/filter", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Object getAcc(@RequestBody JsonData jsonData) throws IOException {
String filter = "{\"crop\":[\"" + jsonData.crop + "\"]}";
ObjectNode jsonTree = null;
jsonTree = (ObjectNode) mapper.readTree(filter);
jsonTree = (ObjectNode) mapper.readTree(filter);
LOG.debug(jsonTree.toString());
LOG.debug(jsonTree.toString());
Page<Accession> accessions = filterService.listAccessions(jsonTree, new PageRequest(jsonData.startAt - 1, jsonData.maxRecords, new Sort("acceNumb")));
return accessions;
}
Page<Accession> accessions = filterService.listAccessions(jsonTree, new PageRequest(jsonData.startAt - 1, jsonData.maxRecords, new Sort("acceNumb")));
return accessions;
}
public static class JsonData {
public String crop;
public Integer startAt;
public Integer maxRecords;
public String otherOptions;
}
public static class JsonData {
public String crop;
public Integer startAt;
public Integer maxRecords;
public String otherOptions;
}
private AccessionHeaderJson readAid3(JsonNode json) {
final AccessionHeaderJson dataJson = new AccessionHeaderJson();
......
package org.genesys2.server.servlet.controller.rest;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionAlias;
import org.genesys2.server.model.genesys.AccessionBreeding;
import org.genesys2.server.model.genesys.AccessionCollect;
import org.genesys2.server.model.genesys.AccessionExchange;
import org.genesys2.server.model.genesys.AccessionGeo;
import org.genesys2.server.model.genesys.AccessionRemark;
import org.genesys2.server.model.genesys.ExperimentTrait;
import org.genesys2.server.model.genesys.Method;
import org.genesys2.server.model.genesys.SvalbardData;
import org.genesys2.server.model.genesys.Taxonomy2;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.model.impl.FaoInstitute;
public class AccessionDetails {
public long version;
public Long id;
public String uuid;
public String acceNumb;
public String acqDate;
public String acqSrc;
public Boolean availability;
public Date createdDate;
public String duplSite;
public Boolean mlsStatus;
public Integer sampStat;
public List<Integer> storage;
public Institute institute;
public Country orgCty;
public Taxonomy taxonomy;
public ArrayList<Alias> aliases;
public Svalbard sgsv;
public ArrayList<Remark> remarks;
public ArrayList<String> crops;
public Geo geo;
public Collect coll;
public String pedigree;
public String donorCode;
public String donorName;
public String donorNumb;
public HashMap<String, List<Object>> traits;
public static AccessionDetails from(Accession accession) {
AccessionDetails ad = new AccessionDetails();
ad.version = accession.getVersion();
ad.id = accession.getId();
ad.uuid = accession.getUuid();
ad.acceNumb = accession.getAccessionName();
ad.acqDate = accession.getAcquisitionDate();
ad.acqSrc = accession.getAcquisitionSource();
ad.availability = accession.getAvailability();
ad.orgCty = Country.from(accession.getCountryOfOrigin());
ad.createdDate = accession.getCreatedDate();
ad.duplSite = accession.getDuplSite();
ad.institute = AccessionDetails.Institute.from(accession.getInstitute());
ad.mlsStatus = accession.getMlsStatus();
ad.sampStat = accession.getSampleStatus();
ad.storage = accession.getStoRage();
ad.taxonomy = Taxonomy.from(accession.getTaxonomy());
return ad;
}
public static class Institute {
public Long id;
public String acronym;
public String code;
public Country country;
public String fullName;
public static Institute from(FaoInstitute institute) {
Institute i = new Institute();
i.id = institute.getId();
i.acronym = institute.getAcronym();
i.code = institute.getCode();
i.country = Country.from(institute.getCountry());
i.fullName = institute.getFullName();
return i;
}
}
public static class Country {
public String iso3;
public String iso2;
public String name;
public static Country from(org.genesys2.server.model.impl.Country country) {
Country c = new Country();
c.iso3 = country.getCode3();
c.iso2 = country.getCode2();
c.name = country.getName();
return c;
}
}
public static class Taxonomy {
public String sciName;
public String genus;
public String species;
public String spAuthor;
public String subtax;
public String subtAuthor;
public static Taxonomy from(Taxonomy2 taxonomy) {
Taxonomy t = new Taxonomy();
t.sciName = taxonomy.getTaxonName();
t.genus = taxonomy.getGenus();
t.species = taxonomy.getSpecies();
t.spAuthor = StringUtils.defaultIfBlank(taxonomy.getSpAuthor(), null);
t.subtax = StringUtils.defaultIfBlank(taxonomy.getSubtaxa(), null);
t.subtAuthor = StringUtils.defaultIfBlank(taxonomy.getSubtAuthor(), null);
return t;
}
}
public void aliases(List<AccessionAlias> listAccessionAliases) {
if (listAccessionAliases == null || listAccessionAliases.isEmpty())
return;
this.aliases = new ArrayList<Alias>();
for (AccessionAlias aa : listAccessionAliases) {
this.aliases.add(Alias.from(aa));
}
}
public static class Alias {
public String name;
public String lang;
public String usedBy;
public static Alias from(AccessionAlias aa) {
Alias a = new Alias();
a.name = aa.getName();
a.lang = StringUtils.defaultIfBlank(aa.getLang(), null);
a.usedBy = StringUtils.defaultIfBlank(aa.getUsedBy(), null);
return a;
}
}
public void svalbard(SvalbardData svalbardData) {
this.sgsv = Svalbard.from(svalbardData);
}
public static class Svalbard {
public Float qty;
public String boxNo;
public String depositDate;
public static Svalbard from(SvalbardData svalbardData) {
if (svalbardData == null)
return null;
Svalbard s = new Svalbard();
s.boxNo = svalbardData.getBoxNumber();
s.qty = svalbardData.getQuantity();
s.depositDate = svalbardData.getDepositDate();
return s;
}
}
public void remarks(List<AccessionRemark> listAccessionRemarks) {
if (listAccessionRemarks == null || listAccessionRemarks.isEmpty())
return;
this.remarks = new ArrayList<Remark>();
for (AccessionRemark ar : listAccessionRemarks) {
this.remarks.add(Remark.from(ar));
}
}
public static class Remark {
public String field;
public String remark;
public static Remark from(AccessionRemark ar) {
Remark r = new Remark();
r.field = StringUtils.defaultIfBlank(ar.getFieldName(), null);
r.remark = StringUtils.defaultIfBlank(ar.getRemark(), null);
return r;
}
}
public void crops(List<Crop> crops) {
if (crops == null || crops.isEmpty())
return;
this.crops = new ArrayList<String>();
for (Crop c : crops) {
this.crops.add(c.getShortName());
}
}
public void geo(AccessionGeo ag) {
if (ag == null)
return;
this.geo = Geo.from(ag);
}
public static class Geo {
public String method;
public Double uncertainty;
public Double latitude;
public Double longitude;
public Double[] coordinates;
public Double elevation;
public String datum;
public static Geo from(AccessionGeo ag) {
if (ag == null)
return null;
Geo g = new Geo();
g.datum = StringUtils.defaultIfBlank(ag.getDatum(), null);
g.elevation = ag.getElevation();
g.coordinates = new Double[] { ag.getLongitude(), ag.getLatitude() };
g.longitude = ag.getLongitude();
g.latitude = ag.getLatitude();
g.uncertainty = ag.getUncertainty();
g.method = StringUtils.defaultIfBlank(ag.getMethod(), null);
return g;
}
}
public void collect(AccessionCollect collect) {
this.coll = Collect.from(collect);
}
public static class Collect {
public String collCode;
public String collDate;
public String collInstAddr;
public String collMissId;
public String collName;
public String collNumb;
public String collSite;
public Integer collSrc;
public static Collect from(AccessionCollect collect) {
if (collect == null)
return null;
Collect c = new Collect();
c.collCode = StringUtils.defaultIfBlank(collect.getCollCode(), null);
c.collDate = StringUtils.defaultIfBlank(collect.getCollDate(), null);
c.collInstAddr = StringUtils.defaultIfBlank(collect.getCollInstAddress(), null);
c.collMissId = StringUtils.defaultIfBlank(collect.getCollMissId(), null);
c.collName = StringUtils.defaultIfBlank(collect.getCollName(), null);
c.collNumb = StringUtils.defaultIfBlank(collect.getCollNumb(), null);
c.collSite = StringUtils.defaultIfBlank(collect.getCollSite(), null);
c.collSrc = collect.getCollSrc();
return c;
}
}
public void breeding(AccessionBreeding breeding) {
if (breeding == null)
return;
this.pedigree = StringUtils.defaultIfBlank(breeding.getPedigree(), null);
}
public void exch(AccessionExchange exch) {
if (exch == null)
return;
this.donorCode = StringUtils.defaultIfBlank(exch.getDonorInstitute(), null);
this.donorName = StringUtils.defaultIfBlank(exch.getDonorName(), null);
this.donorNumb = StringUtils.defaultIfBlank(exch.getAccNumbDonor(), null);
}
public void traits(List<Method> listMethods, Map<Long, List<ExperimentTrait>> accessionTraitValues) {
this.traits = new HashMap<String, List<Object>>();
for (Method m : listMethods) {
List<ExperimentTrait> vals = accessionTraitValues.get(m.getId());
ArrayList<Object> values = new ArrayList<Object>();
for (ExperimentTrait et : vals) {
if (et == null)
continue;
values.add(et.getValue());
}
this.traits.put("gm:"+m.getId(), values);
}
}
// public static class Trait {
//
// public String category;
// public String parameter;
// public String method;
// public ArrayList<Object> values;
//
// public static Trait from(Method m, List<ExperimentTrait> vals) {
// if (vals == null || vals.isEmpty())
// return null;
//
// Trait t = new Trait();
// t.category = m.getParameter().getCategory().getName();
// t.parameter = m.getParameter().getTitle();
// t.method = m.getMethod();
//
// t.values = new ArrayList<Object>();
// for (ExperimentTrait et : vals) {
// if (et == null)
// continue;
// t.values.add(et.getValue());
// }
//
// return t;
// }
//
// }
}
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