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

MCPDUtil#toIntegers, #toStrings

parent b26d0a06
package org.genesys2.server.model.elastic;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
......@@ -20,6 +18,7 @@ import org.genesys2.server.model.genesys.AccessionRemark;
import org.genesys2.server.model.genesys.SvalbardData;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.model.impl.Organization;
import org.genesys2.util.MCPDUtil;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Version;
import org.springframework.data.elasticsearch.annotations.Document;
......@@ -31,8 +30,6 @@ import org.springframework.data.elasticsearch.annotations.FieldType;
public class AccessionDetails {
private static final Logger LOG = Logger.getLogger(AccessionDetails.class);
static Pattern mcpdSplit = Pattern.compile("\\w*;\\w*");
@Version
private Long version;
@Id
......@@ -97,13 +94,12 @@ public class AccessionDetails {
ad.acqSrc = accession.getAcquisitionSource();
ad.available = accession.getAvailability();
ad.orgCty = Country.from(accession.getCountryOfOrigin());
if (StringUtils.isNotBlank(accession.getDuplSite()))
ad.duplSite = Arrays.asList(mcpdSplit.split(accession.getDuplSite()));
ad.duplSite = MCPDUtil.toStrings(accession.getDuplSite());
ad.institute = Institute.from(accession.getInstitute());
ad.mlsStatus = accession.getMlsStatus();
ad.art15 = accession.getInTrust();
ad.sampStat = accession.getSampleStatus();
ad.storage = accession.getStoRage();
ad.storage = MCPDUtil.toIntegers(accession.getStorage());
ad.taxonomy = Taxonomy.from(accession.getTaxonomy());
if (ad.taxonomy == null) {
......
package org.genesys2.server.model.elastic;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.genesys2.server.model.genesys.AccessionCollect;
import org.genesys2.util.MCPDUtil;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldIndex;
import org.springframework.data.elasticsearch.annotations.FieldType;
......@@ -31,7 +31,7 @@ public class Collect {
Collect c = new Collect();
if (StringUtils.isNotBlank(collect.getCollCode()))
c.collCode = new HashSet<String>(Arrays.asList(AccessionDetails.mcpdSplit.split(collect.getCollCode())));
c.collCode = new HashSet<String>(MCPDUtil.toStrings(collect.getCollCode()));
c.collDate = StringUtils.defaultIfBlank(collect.getCollDate(), null);
c.collInstAddr = StringUtils.defaultIfBlank(collect.getCollInstAddress(), null);
c.collMissId = StringUtils.defaultIfBlank(collect.getCollMissId(), null);
......
......@@ -16,11 +16,15 @@
package org.genesys2.util;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils;
public class MCPDUtil {
static Pattern mcpdSplit = Pattern.compile("\\w*;\\w*");
public static String toMcpdArray(List<Integer> integers) {
if (integers == null || integers.size() == 0)
......@@ -36,4 +40,26 @@ public class MCPDUtil {
return StringUtils.defaultIfBlank(s, null);
}
public static List<Integer> toIntegers(String ints) {
if (StringUtils.isBlank(ints))
return null;
List<Integer> is = new ArrayList<Integer>();
for (String i : mcpdSplit.split(ints)) {
if (StringUtils.isBlank(i))
continue;
try {
is.add(Integer.parseInt(i));
} catch (NumberFormatException e) {
}
}
return is;
}
public static List<String> toStrings(String strings) {
if (StringUtils.isBlank(strings))
return null;
return Arrays.asList(mcpdSplit.split(strings));
}
}
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