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

Wide format for dataset observations

parent 5a0aa586
......@@ -19,8 +19,11 @@ package org.crophub.rest.common.persistence.domain;
import java.util.List;
import java.util.Map;
import org.crophub.rest.common.model.genesys.Accession;
import org.crophub.rest.common.model.genesys.AccessionTrait;
import org.crophub.rest.common.model.genesys.ExperimentTrait;
import org.crophub.rest.common.model.genesys.Metadata;
import org.crophub.rest.common.model.genesys.Method;
public interface TraitValueRepository {
......@@ -30,4 +33,6 @@ public interface TraitValueRepository {
Map<Long, List<ExperimentTrait>> getValues(List<AccessionTrait> accessionTraits);
Map<Long, Map<Long, Object>> getValues(Metadata metadata, List<Method> methods, List<Accession> accessions);
}
\ No newline at end of file
......@@ -25,8 +25,10 @@ import javax.sql.DataSource;
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.ExperimentTrait;
import org.crophub.rest.common.model.genesys.Metadata;
import org.crophub.rest.common.model.genesys.Method;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
......@@ -108,4 +110,42 @@ public class TraitValueRepositoryImpl implements TraitValueRepository {
LOG.warn("Done! " + methodValues);
return methodValues;
}
@Override
public Map<Long, Map<Long, Object>> getValues(Metadata metadata, List<Method> methods, List<Accession> accessions) {
Map<Long, Map<Long, Object>> accessionMetadataValues = new HashMap<Long, Map<Long, Object>>();
for (Accession accession : accessions) {
// create lists
accessionMetadataValues.put(accession.getId(), new HashMap<Long, Object>());
}
for (Method method : methods) {
// FIXME We're loading all entries for metadata, should limit only to the accessions in the list!
final List<Map<String, Object>> rows = this.jdbcTemplate.queryForList("select `ALIS_Id` as accessionId, `" + method.getFieldName()
+ "` as traitvalue from `" + method.getId() + "` where `Meta_Id`=?", new Object[] { metadata.getId() });
if (rows == null || rows.size() == 0) {
// Skip
continue;
}
for (final Map<String, Object> row : rows) {
long accessionId = (Integer) row.get("accessionId");
Object value = row.get("traitvalue");
if (value!=null) {
Map<Long, Object> accessionValues = accessionMetadataValues.get(accessionId);
if (accessionValues!=null)
accessionValues.put(method.getId(), value);
}
}
}
LOG.warn("Done! ");
return accessionMetadataValues;
}
}
......@@ -55,4 +55,6 @@ public interface GenesysService {
Map<Long, List<ExperimentTrait>> getAccessionTraitValues(Accession accession);
Map<Long, Map<Long, Object>> getMetadataTraitValues(Metadata metadata, List<Accession> content);
}
......@@ -152,4 +152,10 @@ public class GenesysServiceImpl implements GenesysService {
LOG.debug("Getting trait values for accession: " + accession);
return traitValueRepository.getValues(accessionTraitRepository.findByAccession(accession));
}
@Override
public Map<Long, Map<Long, Object>> getMetadataTraitValues(Metadata metadata, List<Accession> accessions) {
List<Method> methods = metadataMethodRepository.listMetadataMethods(metadata);
return traitValueRepository.getValues(metadata, methods, accessions);
}
}
......@@ -16,10 +16,12 @@
package org.crophub.rest.servlet.controller;
import org.crophub.rest.common.model.genesys.Accession;
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.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
......@@ -56,7 +58,12 @@ public class DatasetController extends BaseController {
}
model.addAttribute("metadata", metadata);
model.addAttribute("methods", genesysService.listMethods(metadata));
model.addAttribute("accessions", genesysService.listMetadataAccessions(metadata, new PageRequest(page - 1, 50)));
Page<Accession> accessions = genesysService.listMetadataAccessions(metadata, new PageRequest(page - 1, 50));
model.addAttribute("accessions", accessions);
// Map[accession.id][method.id]
model.addAttribute("accessionMethods", genesysService.getMetadataTraitValues(metadata, accessions.getContent()));
return "/metadata/view";
}
......
......@@ -52,21 +52,39 @@
<thead>
<tr>
<td><spring:message code="accession.accessionName" /></td>
<td><spring:message code="accession.origin" /></td>
<td><spring:message code="accession.taxonomy" /></td>
<td><spring:message code="accession.holdingInstitute" /></td>
<%-- <td><spring:message code="accession.origin" /></td>
--%> <td><spring:message code="accession.taxonomy" /></td>
<%-- <td><spring:message code="accession.holdingInstitute" /></td>
<td><spring:message code="accession.holdingCountry" /></td>
</tr>
--%>
<c:forEach items="${methods}" var="method">
<td>
<c:out value="${method.fieldName}" />
<c:if test="${method.unit ne ''}">[<c:out value="${method.unit}" />]</c:if>
</td>
</c:forEach>
</tr>
</thead>
<tbody>
<c:forEach items="${accessions.content}" var="accession" varStatus="status">
<tr>
<td><a href="<c:url value="/acn/id/${accession.id}" />"><b><c:out value="${accession.accessionName}" /></b></a></td>
<td><a href="<c:url value="/geo/${accession.origin.toLowerCase()}" />"><c:out value="${accession.countryOfOrigin.name}" /></a></td>
<td><c:out value="${accession.taxonomy.taxonName}" /></td>
<td><a href="<c:url value="/wiews/${accession.institute.code.toLowerCase()}" />"><c:out value="${accession.institute.code}" /></a></td>
<%-- <td><a href="<c:url value="/geo/${accession.origin.toLowerCase()}" />"><c:out value="${accession.countryOfOrigin.name}" /></a></td>
--%> <td><c:out value="${accession.taxonomy.taxonName}" /></td>
<%-- <td><a href="<c:url value="/wiews/${accession.institute.code.toLowerCase()}" />"><c:out value="${accession.institute.code}" /></a></td>
<td><a href="<c:url value="/geo/${accession.institute.country.code3.toLowerCase()}" />"><c:out value="${accession.institute.country.name}" /></a></td>
</tr>
--%>
<c:set value="${accessionMethods[accession.id]}" var="methodValues" />
<c:forEach items="${methods}" var="method">
<td>
<c:out value="${method.decode(methodValues[method.id])}" />
</td>
</c:forEach>
</tr>
</c:forEach>
</tbody>
</table>
......
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