Commit ce99959c authored by Matija Obreza's avatar Matija Obreza
Browse files

Refactored methods for GenesysJsonFactory

parent b43bf0e2
......@@ -21,6 +21,7 @@ import java.util.List;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionBreeding;
import org.genesys2.server.model.genesys.AccessionCollect;
import org.genesys2.server.model.genesys.AccessionGeo;
import org.genesys2.server.model.genesys.AccessionRemark;
......@@ -132,4 +133,23 @@ public class GenesysJsonFactory {
return r;
}
public static void addBreeding(final AccessionJson aj, final AccessionBreeding breeding) {
if (breeding != null) {
aj.setBredCode(breeding.getBreederCode());
aj.setAncest(breeding.getPedigree());
}
}
public static void addCollecting(final AccessionJson aj, final AccessionCollect collect) {
aj.setColl(from(collect));
}
public static void addGeo(final AccessionJson aj, final AccessionGeo geo) {
aj.setGeo(from(geo));
}
public static void addRemarks(final AccessionJson aj, List<AccessionRemark> remarks) {
aj.setRemarks(from(remarks));
}
}
......@@ -604,7 +604,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
String fieldName = null, remark = null;
int pos = remarkText.indexOf(':');
if (pos >= 0 && !remarkText.substring(0, pos - 1).trim().contains(" ")) {
if (pos >= 0 && !remarkText.substring(0, pos).trim().contains(" ")) {
String[] mcpdRemark = remarkText.split(":", 2);
if (mcpdRemark.length == 2) {
fieldName = StringUtils.defaultIfBlank(mcpdRemark[0].trim(), null);
......
......@@ -25,6 +25,7 @@ import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionBreeding;
import org.genesys2.server.model.genesys.AccessionCollect;
import org.genesys2.server.model.genesys.AccessionGeo;
import org.genesys2.server.model.genesys.AccessionRemark;
import org.genesys2.server.model.json.AccessionJson;
import org.genesys2.server.model.json.GenesysJsonFactory;
import org.genesys2.server.service.GenesysRESTService;
......@@ -54,17 +55,16 @@ public class GenesysRESTServiceImpl implements GenesysRESTService {
final AccessionJson aj = GenesysJsonFactory.from(accession);
final AccessionBreeding breeding = genesysService.listAccessionBreeding(accession);
if (breeding != null) {
aj.setBredCode(breeding.getBreederCode());
aj.setAncest(breeding.getPedigree());
}
GenesysJsonFactory.addBreeding(aj, breeding);
final AccessionCollect collect = genesysService.listAccessionCollect(accession);
aj.setColl(GenesysJsonFactory.from(collect));
GenesysJsonFactory.addCollecting(aj, collect);
final AccessionGeo geo = genesysService.listAccessionGeo(accession);
aj.setGeo(GenesysJsonFactory.from(geo));
GenesysJsonFactory.addGeo(aj, geo);
aj.setRemarks(GenesysJsonFactory.from(genesysService.listAccessionRemarks(accession)));
List<AccessionRemark> remarks = genesysService.listAccessionRemarks(accession);
GenesysJsonFactory.addRemarks(aj, remarks);
return aj;
}
......
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