Commit 220386fc authored by Matija Obreza's avatar Matija Obreza
Browse files

Accession#sampStat converted to Integer

parent 3b06011f
......@@ -73,7 +73,7 @@ public class Accession extends VersionedAuditedModel {
private String dublInst;
@Column(name = "sampStat", length = 3)
private String sampleStatus;
private Integer sampleStatus;
@Column(name = "storage", length = 12)
private String storage;
......@@ -176,11 +176,11 @@ public class Accession extends VersionedAuditedModel {
this.dublInst = dublInst;
}
public String getSampleStatus() {
public Integer getSampleStatus() {
return this.sampleStatus;
}
public void setSampleStatus(final String sampleStatus) {
public void setSampleStatus(final Integer sampleStatus) {
this.sampleStatus = sampleStatus;
}
......
......@@ -16,6 +16,8 @@
package org.genesys2.server.service.impl;
import static org.genesys2.util.NumberUtils.areEqual;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
......@@ -192,7 +194,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
if (value != null) {
Boolean inMls = value.isNull() ? null : value.asBoolean();
if (inMls != accession.getMlsStatus()) {
if (!areEqual(inMls, accession.getMlsStatus())) {
accession.setMlsStatus(inMls);
updated = true;
}
......@@ -201,7 +203,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
if (value != null) {
Boolean availability = value.isNull() ? null : value.asBoolean();
if (availability != accession.getMlsStatus()) {
if (!areEqual(availability, accession.getMlsStatus())) {
accession.setAvailability(availability);
updated = true;
}
......@@ -218,8 +220,8 @@ public class BatchRESTServiceImpl implements BatchRESTService {
value = accnJson.get("sampStat");
if (value != null) {
Integer sampStat = value.isNull() || !value.isNumber() ? null : value.asInt();
if (!StringUtils.equals("" + sampStat, accession.getSampleStatus())) {
accession.setSampleStatus(StringUtils.defaultIfBlank("" + sampStat, null));
if (!areEqual(sampStat, accession.getSampleStatus())) {
accession.setSampleStatus(sampStat);
updated = true;
}
}
......@@ -370,7 +372,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
if (toSaveBreed.size() > 0) {
genesysService.saveBreeding(toSaveBreed);
}
if (toSaveExch.size() > 0) {
genesysService.saveExchange(toSaveExch);
}
......
......@@ -26,13 +26,12 @@ public abstract class NumberUtils {
/**
* Utility to parse doubles
*
*
* @param doubleString
* @param factor
* @return
*/
public static Double parseDouble(final String doubleString,
final double factor) {
public static Double parseDouble(final String doubleString, final double factor) {
if (StringUtils.isBlank(doubleString)) {
return null;
}
......@@ -52,10 +51,8 @@ public abstract class NumberUtils {
* @param factor
* @return
*/
public static Double parseDoubleIgnore0(final String doubleString,
final double factor) {
if (StringUtils.isBlank(doubleString)
|| doubleString.trim().equals("0")) {
public static Double parseDoubleIgnore0(final String doubleString, final double factor) {
if (StringUtils.isBlank(doubleString) || doubleString.trim().equals("0")) {
return null;
}
......@@ -66,4 +63,11 @@ public abstract class NumberUtils {
return null;
}
}
/**
* Compare two Integers, Longs, or whatever
*/
public static <T> boolean areEqual(T a, T b) {
return (a == null && b == null) || (a != null && a.equals(b)) || (b != null && b.equals(a));
}
}
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