Commit 89227162 authored by Matija Obreza's avatar Matija Obreza

Metadata (experiments), Methods

parent e3fb08f8
......@@ -2,6 +2,8 @@ eclipse.preferences.version=1
encoding//src/main/resources=UTF-8
encoding//src/main/webapp/WEB-INF/jsp/country/data.jsp=UTF-8
encoding//src/main/webapp/WEB-INF/jsp/login.jsp=UTF-8
encoding//src/main/webapp/WEB-INF/jsp/metadata/index.jsp=UTF-8
encoding//src/main/webapp/WEB-INF/jsp/metadata/view.jsp=UTF-8
encoding//src/main/webapp/WEB-INF/jsp/wiews/data.jsp=UTF-8
encoding//src/main/webapp/WEB-INF/jsp/wiews/index.jsp=UTF-8
encoding//src/test/resources=UTF-8
......
......@@ -23,13 +23,10 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
@SuppressWarnings("serial")
@MappedSuperclass
public abstract class BusinessModel implements HibernateModel {
/**
*
*/
private static final long serialVersionUID = -7550280319451806328L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", unique = true, nullable = false, length = 20)
......
package org.crophub.rest.common.model.genesys;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name = "accessiontrait")
public class AccessionTrait implements Serializable {
private static final long serialVersionUID = -240056837800843686L;
private Long id;
private Accession accession;
private Metadata metadata;
private Method method;
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@ManyToOne(cascade = {}, optional = false)
@JoinColumn(name = "accessionId")
public Accession getAccession() {
return accession;
}
public void setAccession(Accession accession) {
this.accession = accession;
}
@ManyToOne(cascade = {}, optional = false)
@JoinColumn(name = "metadataId")
public Metadata getMetadata() {
return metadata;
}
public void setMetadata(Metadata metadata) {
this.metadata = metadata;
}
@ManyToOne(cascade = {}, optional = false)
@JoinColumn(name = "methodId")
public Method getMethod() {
return method;
}
public void setMethod(Method method) {
this.method = method;
}
}
......@@ -59,10 +59,8 @@ public class Metadata implements java.io.Serializable {
this.title = title;
}
public Metadata(final String institute, final String title, final String SDate, final String EDate,
final String location,
final Double long_, final Double lat, final Double alt,
final String citation, final String description) {
public Metadata(final String institute, final String title, final String SDate, final String EDate, final String location, final Double long_,
final Double lat, final Double alt, final String citation, final String description) {
this.institute = institute;
this.title = title;
this.SDate = SDate;
......@@ -77,6 +75,7 @@ public class Metadata implements java.io.Serializable {
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "Meta_id")
public Long getId() {
return this.id;
}
......@@ -103,7 +102,7 @@ public class Metadata implements java.io.Serializable {
this.title = title;
}
@Column(length = 10)
@Column(name = "S_Date", length = 10)
public String getSDate() {
return this.SDate;
}
......@@ -112,7 +111,7 @@ public class Metadata implements java.io.Serializable {
this.SDate = SDate;
}
@Column(length = 10)
@Column(name = "E_Date", length = 10)
public String getEDate() {
return this.EDate;
}
......@@ -130,6 +129,7 @@ public class Metadata implements java.io.Serializable {
this.location = location;
}
@Column(name = "Long")
public Double getLongitude() {
return this.longitude;
}
......@@ -138,6 +138,7 @@ public class Metadata implements java.io.Serializable {
this.longitude = longitude;
}
@Column(name = "Lat")
public Double getLatitude() {
return this.latitude;
}
......@@ -146,6 +147,7 @@ public class Metadata implements java.io.Serializable {
this.latitude = latitude;
}
@Column(name = "Alt")
public Double getAltitude() {
return this.altitude;
}
......@@ -174,9 +176,7 @@ public class Metadata implements java.io.Serializable {
@Override
public String toString() {
return MessageFormat
.format("Metadata id={0,number,#} inst={2} title={1}",
id, title, institute);
return MessageFormat.format("Metadata id={0,number,#} inst={2} title={1}", id, title, institute);
}
}
......@@ -28,7 +28,7 @@ import javax.persistence.Table;
import javax.persistence.Transient;
@Entity
@Table(name = "method")
@Table(name = "methods")
public class Method implements java.io.Serializable {
/**
......@@ -51,6 +51,7 @@ public class Method implements java.io.Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="Method_Id")
public Long getId() {
return this.id;
}
......@@ -70,7 +71,7 @@ public class Method implements java.io.Serializable {
// }
@ManyToOne(cascade = {}, optional = false)
@JoinColumn(name = "parameterId", nullable = false)
@JoinColumn(name = "Par_Id", nullable = false)
public Parameter getParameter() {
return this.parameter;
}
......@@ -187,7 +188,7 @@ public class Method implements java.io.Serializable {
// return TraitCode.parseOptionsMap(this.options);
// }
@Column(name = "dataRange", length = 32)
@Column(name = "Range", length = 32)
public String getRange() {
return this.range;
}
......
......@@ -24,7 +24,7 @@ import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "parameter")
@Table(name = "parameters")
public class Parameter implements java.io.Serializable {
/**
......@@ -32,17 +32,17 @@ public class Parameter implements java.io.Serializable {
*/
private static final long serialVersionUID = -4831244149317371274L;
private Long id;
// private Language language;
// private Crop crop;
// private Category category;
// private Language language;
// private Crop crop;
// private Category category;
private String title;
public Parameter() {
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "Par_Id")
public Long getId() {
return this.id;
}
......@@ -51,35 +51,35 @@ public class Parameter implements java.io.Serializable {
this.id = parId;
}
// @ManyToOne(cascade = {}, optional = false)
// @JoinColumn(name = "languageId")
// public Language getLanguage() {
// return this.language;
// }
//
// public void setLanguage(final Language language) {
// this.language = language;
// }
//
// @ManyToOne(cascade = {}, optional = false)
// @JoinColumn(name = "cropId")
// public Crop getCrop() {
// return this.crop;
// }
//
// public void setCrop(final Crop crop) {
// this.crop = crop;
// }
//
// @ManyToOne(cascade = {}, optional = false)
// @JoinColumn(name = "categoryId", nullable = false)
// public Category getCategory() {
// return this.category;
// }
//
// public void setCategory(final Category category) {
// this.category = category;
// }
// @ManyToOne(cascade = {}, optional = false)
// @JoinColumn(name = "languageId")
// public Language getLanguage() {
// return this.language;
// }
//
// public void setLanguage(final Language language) {
// this.language = language;
// }
//
// @ManyToOne(cascade = {}, optional = false)
// @JoinColumn(name = "cropId")
// public Crop getCrop() {
// return this.crop;
// }
//
// public void setCrop(final Crop crop) {
// this.crop = crop;
// }
//
// @ManyToOne(cascade = {}, optional = false)
// @JoinColumn(name = "categoryId", nullable = false)
// public Category getCategory() {
// return this.category;
// }
//
// public void setCategory(final Category category) {
// this.category = category;
// }
@Column(nullable = false, length = 32)
public String getTitle() {
......@@ -90,12 +90,12 @@ public class Parameter implements java.io.Serializable {
this.title = title;
}
// @Override
// public String toString() {
// return MessageFormat
// .format("Parameter id={0,number,#} title={1} lang={2} crop={3} cat={4}",
// id, title, language.getId(), crop.getName(),
// category.getTitle());
// }
// @Override
// public String toString() {
// return MessageFormat
// .format("Parameter id={0,number,#} title={1} lang={2} crop={3} cat={4}",
// id, title, language.getId(), crop.getName(),
// category.getTitle());
// }
}
/**
* Copyright 2013 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.crophub.rest.common.persistence.domain;
import java.util.List;
import org.crophub.rest.common.model.genesys.Accession;
import org.crophub.rest.common.model.genesys.AccessionTrait;
import org.crophub.rest.common.model.genesys.Metadata;
import org.crophub.rest.common.model.genesys.Method;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
public interface AccessionTraitRepository extends JpaRepository<AccessionTrait, Long> {
List<AccessionTrait> findByAccession(Accession accession);
List<AccessionTrait> findByMetadata(Metadata metadata);
List<AccessionTrait> findByMethod(Method method);
@Query("select distinct at.metadata from AccessionTrait at where at.accession = ?1")
List<Metadata> listMetadata(Accession accession);
@Query("select distinct at.method from AccessionTrait at where at.accession = ?1")
List<Method> listMethods(Accession accession);
@Query("select distinct at.accession from AccessionTrait at where at.metadata = ?1")
Page<Accession> listMetadataAccessions(Metadata metadata, Pageable pageable);
@Query("select distinct at.method from AccessionTrait at where at.metadata = ?1")
List<Method> listMetadataMethods(Metadata metadata);
}
......@@ -7,9 +7,12 @@ import org.crophub.rest.common.model.genesys.AllAccnames;
import org.crophub.rest.common.model.genesys.AllAcqBreeding;
import org.crophub.rest.common.model.genesys.AllAcqCollect;
import org.crophub.rest.common.model.genesys.AllAcqExchange;
import org.crophub.rest.common.model.genesys.Metadata;
import org.crophub.rest.common.model.genesys.Method;
import org.crophub.rest.common.model.impl.Country;
import org.crophub.rest.common.model.impl.FaoInstitute;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
public interface GenesysService {
......@@ -36,4 +39,14 @@ public interface GenesysService {
List<AllAcqBreeding> listAccessionBreeding(Accession accession);
List<Metadata> listMetadata(Accession accession);
Page<Metadata> listMetadata(PageRequest pageRequest);
Metadata getMetadata(long metadataId);
List<Method> listMethods(Metadata metadata);
Page<Accession> listMetadataAccessions(Metadata metadata, PageRequest pageRequest);
}
......@@ -7,96 +7,128 @@ import org.crophub.rest.common.model.genesys.AllAccnames;
import org.crophub.rest.common.model.genesys.AllAcqBreeding;
import org.crophub.rest.common.model.genesys.AllAcqCollect;
import org.crophub.rest.common.model.genesys.AllAcqExchange;
import org.crophub.rest.common.model.genesys.Metadata;
import org.crophub.rest.common.model.genesys.Method;
import org.crophub.rest.common.model.impl.Country;
import org.crophub.rest.common.model.impl.FaoInstitute;
import org.crophub.rest.common.persistence.domain.AccessionBreedingRepository;
import org.crophub.rest.common.persistence.domain.AccessionCollectRepository;
import org.crophub.rest.common.persistence.domain.AccessionNameRepository;
import org.crophub.rest.common.persistence.domain.AccessionRepository;
import org.crophub.rest.common.persistence.domain.AccessionTraitRepository;
import org.crophub.rest.common.persistence.domain.MetadataRepository;
import org.crophub.rest.common.persistence.domain.MethodRepository;
import org.crophub.rest.common.service.GenesysService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@Transactional(readOnly=true)
@Transactional(readOnly = true)
public class GenesysServiceImpl implements GenesysService {
@Autowired
private AccessionRepository accessionRepository;
@Autowired
private AccessionBreedingRepository accessionBreedingRepository;
@Autowired
private AccessionCollectRepository accessionCollectRepository;
@Autowired
private AccessionNameRepository accessionNamesRepository;
@Autowired
private AccessionTraitRepository accessionTraitRepository;
@Autowired
private MetadataRepository metadataRepository;
@Autowired
private MethodRepository methodRepository;
@Override
public long countByInstitute(FaoInstitute institute) {
return accessionRepository.countByInstitute(institute);
}
@Override
public long countByOrigin(String isoCode3) {
return accessionRepository.countByOrigin(isoCode3);
}
@Override
public long countByLocation(String isoCode3) {
return accessionRepository.countByLocation(isoCode3);
}
@Override
public Page<Accession> listAccessionsByOrigin(Country country, Pageable pageable) {
return accessionRepository.findByOrigin(country.getCode3(), pageable);
}
@Override
public Page<Accession> listAccessionsByInstitute(FaoInstitute faoInstitute, Pageable pageable) {
return accessionRepository.findByInstitute(faoInstitute, pageable);
}
@Override
public Accession getAccession(long accessionId) {
return accessionRepository.findOne(accessionId);
}
@Override
public List<Accession> listAccessions(FaoInstitute faoInstitute, String accessionName) {
return accessionRepository.findByInstituteAndAccessionName(faoInstitute, accessionName);
}
@Override
public List<AllAcqBreeding> listAccessionBreeding(Accession accession) {
// TODO Auto-generated method stub
return null;
}
@Override
public List<AllAcqCollect> listAccessionCollect(Accession accession) {
// TODO Auto-generated method stub
return null;
}
@Override
public List<AllAcqExchange> listAccessionExchange(Accession accession) {
// TODO Auto-generated method stub
return null;
}
@Override
public AllAccnames listAccessionNames(Accession accession) {
return accessionNamesRepository.findOne(accession.getId());
}
@Override
public List<Metadata> listMetadata(Accession accession) {
return accessionTraitRepository.listMetadata(accession);
}
@Override
public Page<Metadata> listMetadata(PageRequest pageRequest) {
return metadataRepository.findAll(pageRequest);
}
@Override
public Metadata getMetadata(long metadataId) {
return metadataRepository.findOne(metadataId);
}
@Override
public List<Method> listMethods(Metadata metadata) {
return accessionTraitRepository.listMetadataMethods(metadata);
}
@Override
public Page<Accession> listMetadataAccessions(Metadata metadata, PageRequest pageRequest) {
return accessionTraitRepository.listMetadataAccessions(metadata, pageRequest);
}
}
......@@ -36,6 +36,9 @@ public class AccessionController extends BaseController {
model.addAttribute("accessionCollect", genesysService.listAccessionCollect(accession));
model.addAttribute("accessionBreeding", genesysService.listAccessionBreeding(accession));
model.addAttribute("metadatas", genesysService.listMetadata(accession));
return "/accession/details";
}
......
......@@ -16,16 +16,17 @@
package org.crophub.rest.servlet.controller;
import java.util.List;
import org.crophub.rest.common.model.impl.Dataset;
import org.crophub.rest.common.service.DataService;
import org.crophub.rest.common.model.genesys.Metadata;
import org.crophub.rest.common.service.GenesysService;
import org.crophub.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.Validator;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
* Controller which simply handles *.html requests
......@@ -35,27 +36,29 @@ import org.springframework.web.bind.annotation.RequestMapping;
public class DatasetController extends BaseController {
@Autowired
private DataService dataService;
private GenesysService genesysService;
@Autowired
private Validator validator;
@RequestMapping("/")
public String index(ModelMap model) {
List<Dataset> datasets = dataService.list();
model.addAttribute("datasets", datasets);
return "/dataset/index";
public String index(ModelMap model, @RequestParam(value = "page", required = false, defaultValue = "1") int page) {
model.addAttribute("metadatas", genesysService.listMetadata(new PageRequest(page - 1, 50)));
return "/metadata/index";
}
@RequestMapping("/view/{id}")
public String view(ModelMap model, @PathVariable(value = "id") long datasetId) {
_logger.debug("Viewing data for " + datasetId);
Dataset dataset=dataService.getDataset(datasetId);
model.addAttribute("dataset", dataset);
model.addAttribute("entrySize", dataService.countEntries(dataset));
model.addAttribute("dataSize", dataService.countData(dataset));
model.addAttribute("descriptors", dataService.getDescriptors(dataset));
return "/dataset/view";
public String view(ModelMap model, @PathVariable(value = "id") long metadataId, @RequestParam(value = "page", required = false, defaultValue = "1")