Commit f7c73f13 authored by Matija Obreza's avatar Matija Obreza

Display C&E data

parent 30e22d35
package org.crophub.rest.common.model.genesys;
public class ExperimentTrait {
private long experimentId;
private Object value;
public ExperimentTrait(final long experimentId, final Object value) {
this.experimentId = experimentId;
this.value = value;
}
public long getExperimentId() {
return experimentId;
}
public void setExperimentId(final long experimentId) {
this.experimentId = experimentId;
}
public Object getValue() {
return value;
}
public void setValue(final Object value) {
this.value = value;
}
@Override
public String toString() {
return "{" + value + ", " + experimentId + "}";
}
}
......@@ -20,6 +20,8 @@ import java.util.List;
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.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
......@@ -35,4 +37,7 @@ public interface FaoInstituteRepository extends
@Query("from FaoInstitute fi where fi.country = ?1 and fi.accessionCount > 0")
List<FaoInstitute> findByCountryActive(Country country, Sort sort);
@Query("from FaoInstitute fi where fi.accessionCount > 0")
Page<FaoInstitute> findAllActive(Pageable pageable);
}
......@@ -17,15 +17,18 @@
package org.crophub.rest.common.persistence.domain;
import java.util.List;
import java.util.Map;
import org.crophub.rest.common.model.genesys.AccessionTrait;
import org.crophub.rest.common.model.genesys.ExperimentTrait;
import org.crophub.rest.common.model.genesys.Method;
public interface TraitValueRepository {
int count(Method method);
// int count(Method method);
//
// List<ExperimentTrait> getValues(Accession accession, Method method);
// List<ExperimentTrait> getValues(Long accessionId, Method method);
List<?> getValues(Method method);
Map<Method, List<ExperimentTrait>> getValues(List<AccessionTrait> accessionTraits);
}
\ No newline at end of file
......@@ -16,12 +16,17 @@
package org.crophub.rest.common.persistence.domain;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.crophub.rest.common.model.genesys.AccessionTrait;
import org.crophub.rest.common.model.genesys.ExperimentTrait;
import org.crophub.rest.common.model.genesys.Method;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
......@@ -34,69 +39,74 @@ public class TraitValueRepositoryImpl implements TraitValueRepository {
public static final Log LOG = LogFactory.getLog(TraitValueRepository.class);
private JdbcTemplate jdbcTemplate;
@Autowired
private AccessionTraitRepository accessionTraitRepository;
@Autowired
public void setDataSource(final DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
/*
* (non-Javadoc)
*
* @see
* org.croptrust.genesys.data.repositories.TraitValueRepository#count(org
* .croptrust.genesys.data.core.entities.Method)
*/
// /*
// * (non-Javadoc)
// *
// * @see
// * org.croptrust.genesys.data.repositories.TraitValueRepository#count(org
// * .croptrust.genesys.data.core.entities.Method)
// */
// @Override
// public int count(final Method method) {
// LOG.trace("Counting for " + method);
//
// final int count = this.jdbcTemplate.queryForInt("select count(`" +
// method.getFieldName() + "`) from `" + method.getId() + "`");
//
// return count;
// }
//
// @Override
// public List<?> getValues(final Method method) {
// LOG.trace("Querying for " + method);
//
// final Class<?> requiredType = method.getDataType();
// final List<?> ret = this.jdbcTemplate.queryForList("select `" +
// method.getFieldName() + "` from `" + method.getId() + "`", requiredType);
//
// return ret;
// }
@Override
public int count(final Method method) {
LOG.trace("Counting for " + method);
public Map<Method, List<ExperimentTrait>> getValues(List<AccessionTrait> accessionTraits) {
if (accessionTraits == null) {
LOG.warn("Null accessionTraits list not acceptable");
throw new NullPointerException();
}
final int count = this.jdbcTemplate.queryForInt("select count(`"
+ method.getFieldName() + "`) from `" + method.getId() + "`");
Map<Method, List<ExperimentTrait>> methodValues = new HashMap<Method, List<ExperimentTrait>>();
return count;
}
for (AccessionTrait at : accessionTraits) {
Method method = at.getMethod();
@Override
public List<?> getValues(final Method method) {
LOG.trace("Querying for " + method);
final List<Map<String, Object>> rows = this.jdbcTemplate.queryForList("select Meta_id as metadataId, `" + method.getFieldName()
+ "` as traitvalue from `" + method.getId() + "` where `ALIS_Id`=?", new Object[] { at.getAccession().getId() });
final Class<?> requiredType = method.getDataType();
final List<?> ret = this.jdbcTemplate.queryForList(
"select `" + method.getFieldName() + "` from `"
+ method.getId() + "`", requiredType);
if (rows == null || rows.size() == 0) {
// Skip
break;
}
return ret;
}
final List<ExperimentTrait> ret = new ArrayList<ExperimentTrait>();
for (final Map<String, Object> row : rows) {
final ExperimentTrait et = new ExperimentTrait((Integer) row.get("metadataId"), row.get("traitvalue"));
ret.add(et);
}
// @Override
// public List<ExperimentTrait> getValues(final Long accessionId,
// final Method method) {
// LOG.trace("Querying " + accessionId + " for " + method);
//
// // final Class<?> requiredType = method.getDataType();
// // final List<?> ret = this.jdbcTemplate.queryForList(
// // "select `" + method.getFieldName() + "` from `"
// // + method.getId() + "` where `ALIS_Id`=?",
// // new Object[] { accessionId }, requiredType);
//
// final List<Map<String, Object>> rows = this.jdbcTemplate.queryForList(
// "select Meta_id as metadataId, `" + method.getFieldName()
// + "` as traitvalue from `"
// + method.getId() + "` where `ALIS_Id`=?",
// new Object[] { accessionId });
//
// if (rows == null || rows.size() == 0) {
// return null;
// }
//
// final List<ExperimentTrait> ret = new ArrayList<ExperimentTrait>();
//
// for (final Map<String, Object> row : rows) {
// final ExperimentTrait et = new ExperimentTrait(
// (Integer) row.get("metadataId"), row.get("traitvalue"));
// ret.add(et);
// }
//
// return ret;
// }
methodValues.put(method, ret);
break;
}
LOG.warn("Done! " + methodValues);
return methodValues;
}
}
package org.crophub.rest.common.service;
import java.util.List;
import java.util.Map;
import org.crophub.rest.common.model.genesys.Accession;
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.ExperimentTrait;
import org.crophub.rest.common.model.genesys.Metadata;
import org.crophub.rest.common.model.genesys.Method;
import org.crophub.rest.common.model.impl.Country;
......@@ -49,4 +51,8 @@ public interface GenesysService {
Page<Accession> listMetadataAccessions(Metadata metadata, PageRequest pageRequest);
List<Method> listMethods(Accession accession);
Map<Long, List<ExperimentTrait>> getAccessionTraitValues(Accession accession);
}
......@@ -22,6 +22,7 @@ import java.util.List;
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;
/**
......@@ -39,4 +40,6 @@ public interface InstituteService {
List<FaoInstitute> listByCountryActive(Country country);
Page<FaoInstitute> listActive(PageRequest pageRequest);
}
package org.crophub.rest.common.service.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.crophub.rest.common.model.genesys.Accession;
import org.crophub.rest.common.model.genesys.AccessionTrait;
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.ExperimentTrait;
import org.crophub.rest.common.model.genesys.Metadata;
import org.crophub.rest.common.model.genesys.Method;
import org.crophub.rest.common.model.impl.Country;
......@@ -19,6 +26,7 @@ import org.crophub.rest.common.persistence.domain.AccessionTraitRepository;
import org.crophub.rest.common.persistence.domain.MetadataMethodRepository;
import org.crophub.rest.common.persistence.domain.MetadataRepository;
import org.crophub.rest.common.persistence.domain.MethodRepository;
import org.crophub.rest.common.persistence.domain.TraitValueRepository;
import org.crophub.rest.common.service.GenesysService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
......@@ -31,6 +39,8 @@ import org.springframework.transaction.annotation.Transactional;
@Transactional(readOnly = true)
public class GenesysServiceImpl implements GenesysService {
public static final Log LOG = LogFactory.getLog(GenesysServiceImpl.class);
@Autowired
private AccessionRepository accessionRepository;
......@@ -46,6 +56,8 @@ public class GenesysServiceImpl implements GenesysService {
private MetadataRepository metadataRepository;
@Autowired
private MetadataMethodRepository metadataMethodRepository;
@Autowired
private TraitValueRepository traitValueRepository;
@Autowired
private MethodRepository methodRepository;
......@@ -113,6 +125,11 @@ public class GenesysServiceImpl implements GenesysService {
return accessionTraitRepository.listMetadata(accession);
}
@Override
public List<Method> listMethods(Accession accession) {
return accessionTraitRepository.listMethods(accession);
}
@Override
public Page<Metadata> listMetadata(PageRequest pageRequest) {
return metadataRepository.findAll(pageRequest);
......@@ -133,4 +150,31 @@ public class GenesysServiceImpl implements GenesysService {
return accessionTraitRepository.listMetadataAccessions(metadata, pageRequest);
}
@Override
public Map<Long, List<ExperimentTrait>> getAccessionTraitValues(Accession accession) {
LOG.info("Getting stuff for accession: " + accession);
// FIXME Does not work!
// Map<Method, List<ExperimentTrait>> x =
// traitValueRepository.getValues(accessionTraitRepository.findByAccession(accession));
Map<Long, List<ExperimentTrait>> methodValues = new HashMap<Long, List<ExperimentTrait>>();
for (AccessionTrait at : accessionTraitRepository.findByAccession(accession)) {
Method method = at.getMethod();
final List<ExperimentTrait> ret = new ArrayList<ExperimentTrait>();
for (int i = (int) (Math.random() * 3); i >= 0; i--) {
final ExperimentTrait et = new ExperimentTrait(1, Math.random());
ret.add(et);
}
methodValues.put(method.getId(), ret);
}
LOG.warn("Done! " + methodValues);
return methodValues;
}
}
......@@ -41,6 +41,7 @@ import org.crophub.rest.common.persistence.domain.FaoInstituteRepository;
import org.crophub.rest.common.service.InstituteService;
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.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
......@@ -67,6 +68,11 @@ public class InstituteServiceImpl implements InstituteService {
return instituteRepository.findAll(pageable);
}
@Override
public Page<FaoInstitute> listActive(PageRequest pageRequest) {
return instituteRepository.findAllActive(pageRequest);
}
@Override
public FaoInstitute getInstitute(String wiewsCode) {
return instituteRepository.findByCode(wiewsCode);
......
......@@ -37,7 +37,8 @@ public class AccessionController extends BaseController {
model.addAttribute("accessionBreeding", genesysService.listAccessionBreeding(accession));
model.addAttribute("metadatas", genesysService.listMetadata(accession));
model.addAttribute("methods", genesysService.listMethods(accession));
model.addAttribute("methodValues", genesysService.getAccessionTraitValues(accession));
return "/accession/details";
}
......
......@@ -31,6 +31,15 @@ public class WiewsController extends BaseController {
return "/wiews/index";
}
@RequestMapping("/active")
public String viewGenesys(ModelMap model, @RequestParam(value = "page", required = false, defaultValue = "1") int page) {
model.addAttribute("activeOnly", true);
model.addAttribute("faoInstitutes", instituteService.listActive(new PageRequest(page - 1, 50, new Sort("code"))));
return "/wiews/index";
}
@RequestMapping("/{wiewsCode}")
public String view(ModelMap model, @PathVariable(value = "wiewsCode") String wiewsCode) {
_logger.debug("Viewing country " + wiewsCode);
......
......@@ -95,13 +95,16 @@ faoInstitute.accessionCount={0} accessions in Genesys.
faoInstitute.statistics=Institute statistics
faoInstitutes.page.data.title=Accessions in {0}
faoInstitute.accessions.at=Accessions held at {0}
faoInstitutes.viewAll=View all registered institutes
faoInstitutes.viewActiveOnly=View institutes with accessions in Genesys
view.accessions=View accessions...
paged.pageOfPages=Page {0} of {1}
paged.totalElements={0} entries
accessions.number={0} accessions
accession.metadatas=Datasets
accession.methods=Characterization & Evaluation data
accession.accessionName=Accession
accession.origin=Country of origin
......@@ -112,6 +115,9 @@ accession.otherNames=Also known as
accession.inTrust=In Trust
accession.mlsStatus=MLS Status
accession.inSvalbard=Svalbardized
accession.inTrust.true=This accession is under Article 15 of the International Treaty on Plant Genetic Resources for Food and Agriculture.
accession.mlsStatus.true=This accession is in the Multilateral System of ITPGRFA.
accession.inSvalbard.true=Super-safety duplicated in Svalbard Seed Vault.
accession.page.profile.title=Accession profile: {0}
......
......@@ -87,7 +87,7 @@
<a href="<c:url value="/" />">Home</a>
<a href="<c:url value="/data/" />">Datasets</a>
<a href="<c:url value="/geo/" />">Countries</a>
<a href="<c:url value="/wiews/" />">WIEWS</a>
<a href="<c:url value="/wiews/active" />">Institutes</a>
</div>
<div id="dialog"></div>
......
......@@ -12,15 +12,26 @@
<small><c:out value="${accession.instituteCode}" /></small>
</h1>
<c:if test="${accession.inTrust eq true}">
<div class="alert"><spring:message code="accession.inTrust.true" /></div>
</c:if>
<c:if test="${accession.inSvalbard eq true}">
<div class="alert"><spring:message code="accession.inSvalbard.true" /></div>
</c:if>
<c:if test="${accession.mlsStatus eq true}">
<div class="alert"><spring:message code="accession.mlsStatus.true" /></div>
</c:if>
<table>
<tbody>
<tr>
<td><spring:message code="accession.holdingInstitute" /></td>
<td>
<a href="<c:url value="/wiews/${accession.instituteCode.toLowerCase()}" />">
<c:out value="${accession.institute.fullName}" />
</a>
</td>
<td><a href="<c:url value="/wiews/${accession.instituteCode.toLowerCase()}" />"> <c:out value="${accession.institute.fullName}" />
</a></td>
</tr>
<tr>
<td><spring:message code="accession.holdingCountry" /></td>
......@@ -30,20 +41,16 @@
<td><spring:message code="accession.accessionName" /></td>
<td><c:out value="${accession.accessionName}" /></td>
</tr>
<c:if test="${accession.countryOfOrigin ne null}">
<tr>
<td><spring:message code="accession.origin" /></td>
<td>
<img src="http://genesys-pgr.org/images/flags/${accession.origin.toUpperCase()}.png" />
<a href="<c:url value="/geo/${accession.origin.toLowerCase()}" />">
<c:out value="${accession.countryOfOrigin.name}" />
</a>
</td>
<td><img src="http://genesys-pgr.org/images/flags/${accession.origin.toUpperCase()}.png" /> <a href="<c:url value="/geo/${accession.origin.toLowerCase()}" />"> <c:out value="${accession.countryOfOrigin.name}" />
</a></td>
</tr>
</c:if>
<tr>
<td><spring:message code="taxonomy.genus" /></td>
<td><c:out value="${accession.taxonomy.genus}" /></td>
......@@ -58,34 +65,47 @@
</tr>
<tr>
<td><spring:message code="accession.otherNames" /></td>
<td>
<c:out value="${accessionNames.accNames}" /><br />
<c:out value="${accessionNames.otherIds}" />
</td>
</tr>
<tr>
<td><spring:message code="accession.inTrust" /></td>
<td><c:out value="${accession.inTrust}" /></td>
</tr>
<tr>
<td><spring:message code="accession.inSvalbard" /></td>
<td><c:out value="${accession.inSvalbard}" /></td>
</tr>
<tr>
<td><spring:message code="accession.mlsStatus" /></td>
<td><c:out value="${accession.mlsStatus}" /></td>
<td><c:out value="${accessionNames.accNames}" /><br /> <c:out value="${accessionNames.otherIds}" /></td>
</tr>
</tbody>
</table>
<h2>Metadata</h2>
<c:forEach items="${metadatas}" var="metadata" varStatus="status">
<div><a href="<c:url value="/data/view/${metadata.id}" />"><c:out value="${metadata.title}" /></a> <c:out value="${metadata.institute}" /></div>
<div><c:out value="${metadata.description}" /></div>
</c:forEach>
<c:if test="${methods.size() gt 0}">
<h2>
<spring:message code="accession.methods" />
</h2>
<table>
<tbody>
<c:forEach items="${methods}" var="method" varStatus="status">
<tr>
<td><c:out value="${method.parameter.title}" /></td>
<td><c:forEach items="${methodValues[method.id]}" var="val">
<div>
<c:out value="${val.value}" />
<span class="uom"><c:out value="${method.unit}" /></span>
</div>
</c:forEach></td>
<td><c:out value="${method.method}" /></td>
</tr>
</c:forEach>
</tbody>
</table>
</c:if>
<c:if test="${metadatas.size() gt 0}">
<h2>
<spring:message code="accession.metadatas" />
</h2>
<c:forEach items="${metadatas}" var="metadata" varStatus="status">
<div>
<a href="<c:url value="/data/view/${metadata.id}" />"><c:out value="${metadata.title}" /></a>
<c:out value="${metadata.institute}" />
</div>
<div>
<c:out value="${metadata.description}" />
</div>
</c:forEach>
</c:if>
</body>
</html>
\ No newline at end of file
......@@ -10,6 +10,13 @@
<h1>
<spring:message code="faoInstitutes.page.list.title" />
</h1>
<c:if test="${activeOnly eq true}">
<div><a href="<c:url value="/wiews/" />"><spring:message code="faoInstitutes.viewAll" /></a></div>
</c:if>
<c:if test="${activeOnly ne true}">
<div><a href="<c:url value="/wiews/genesys" />"><spring:message code="faoInstitutes.viewActiveOnly" /></a></div>
</c:if>
<div class="nav-header"><a href="?page=${faoInstitutes.number}">⇇ Previous</a> <a href="?page=${faoInstitutes.number + 2}">Next ⇉</a></div>
......
......@@ -62,3 +62,7 @@ img.country-flag {
img.country-flag.bigger {
height: 50px;
}
.uom {
margin-left: 1em;
}
\ No newline at end of file
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