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