Commit 1fe4eb23 authored by Matija Obreza's avatar Matija Obreza

Spring 3.2.4 fixes issue with JdbcTemplate and closing connections

Decode coded values
parent af8237ec
......@@ -41,7 +41,7 @@
<log4j.version>1.2.17</log4j.version>
<aspectj.version>1.7.2</aspectj.version>
<spring.framework.version>3.2.2.RELEASE</spring.framework.version>
<spring.framework.version>3.2.4.RELEASE</spring.framework.version>
<spring.security.version>3.1.4.RELEASE</spring.security.version>
<spring.data.core.version>1.5.1.RELEASE</spring.data.core.version>
<spring.data.jpa.version>1.3.2.RELEASE</spring.data.jpa.version>
......
......@@ -157,6 +157,11 @@ public class Method implements java.io.Serializable {
public boolean isCoded() {
return this.fieldType == 0;
}
// FIXME String?
public Object decode(Object value) {
return isCoded() && value!=null ? TraitCode.decode(this.options, value.toString()) : value;
}
/**
* Get list of codes for a coded descriptor.
......
package org.crophub.rest.common.model.genesys;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils;
/**
* Class representing one coded trait descriptor value.
*
* @author mobreza
*/
public class TraitCode {
final static Pattern p = Pattern.compile("([^,]+),([^;$]*)(;|$)");
private final String code;
private final String value;
public TraitCode(final String code, final String value) {
this.code = code;
this.value = value;
}
public String getCode() {
return code;
}
public String getValue() {
return value;
}
@Override
public String toString() {
return MessageFormat.format("Coded code={0} value={1}", code,
value);
}
public static String decode(final String options, final String value) {
if (StringUtils.isNotBlank(options)) {
final Matcher m = p.matcher(options);
while (m.find()) {
if (m.group(1).equalsIgnoreCase(value)) {
return m.group(2);
}
}
}
return value;
}
public static List<TraitCode> parseOptions(final String options) {
final List<TraitCode> codes = new ArrayList<TraitCode>();
if (StringUtils.isNotBlank(options)) {
final Matcher m = p.matcher(options);
while (m.find()) {
codes.add(new TraitCode(m.group(1), m
.group(2)));
}
}
return codes;
}
public static Map<String, TraitCode> parseOptionsMap(final String options) {
final Map<String, TraitCode> map = new HashMap<String, TraitCode>();
for (final TraitCode code : parseOptions(options)) {
map.put(code.getCode(), code);
}
return map;
}
}
......@@ -21,7 +21,6 @@ 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 {
......@@ -29,6 +28,6 @@ public interface TraitValueRepository {
//
// List<ExperimentTrait> getValues(Accession accession, Method method);
Map<Method, List<ExperimentTrait>> getValues(List<AccessionTrait> accessionTraits);
Map<Long, List<ExperimentTrait>> getValues(List<AccessionTrait> accessionTraits);
}
\ No newline at end of file
......@@ -76,13 +76,13 @@ public class TraitValueRepositoryImpl implements TraitValueRepository {
// }
@Override
public Map<Method, List<ExperimentTrait>> getValues(List<AccessionTrait> accessionTraits) {
public Map<Long, List<ExperimentTrait>> getValues(List<AccessionTrait> accessionTraits) {
if (accessionTraits == null) {
LOG.warn("Null accessionTraits list not acceptable");
throw new NullPointerException();
}
Map<Method, List<ExperimentTrait>> methodValues = new HashMap<Method, List<ExperimentTrait>>();
Map<Long, List<ExperimentTrait>> methodValues = new HashMap<Long, List<ExperimentTrait>>();
for (AccessionTrait at : accessionTraits) {
Method method = at.getMethod();
......@@ -92,7 +92,7 @@ public class TraitValueRepositoryImpl implements TraitValueRepository {
if (rows == null || rows.size() == 0) {
// Skip
break;
continue;
}
final List<ExperimentTrait> ret = new ArrayList<ExperimentTrait>();
......@@ -102,8 +102,7 @@ public class TraitValueRepositoryImpl implements TraitValueRepository {
ret.add(et);
}
methodValues.put(method, ret);
break;
methodValues.put(method.getId(), ret);
}
LOG.warn("Done! " + methodValues);
......
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;
......@@ -152,29 +149,7 @@ public class GenesysServiceImpl implements GenesysService {
@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;
LOG.debug("Getting trait values for accession: " + accession);
return traitValueRepository.getValues(accessionTraitRepository.findByAccession(accession));
}
}
......@@ -81,7 +81,7 @@
<td><c:out value="${method.parameter.title}" /></td>
<td><c:forEach items="${methodValues[method.id]}" var="val">
<div>
<c:out value="${val.value}" />
<c:out value="${method.decode(val.value)}" />
<span class="uom"><c:out value="${method.unit}" /></span>
</div>
</c:forEach></td>
......
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