Skip to content

Commit bfa6138

Browse files
committed
Handle metadata flag verifyInternalEanChecksum
1 parent e91226d commit bfa6138

File tree

4 files changed

+31
-13
lines changed

4 files changed

+31
-13
lines changed

core/src/main/java/io/snabble/sdk/MetadataDownloader.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.Map;
1313
import java.util.Set;
1414

15+
import io.snabble.sdk.utils.JsonUtils;
1516
import io.snabble.sdk.utils.Logger;
1617
import io.snabble.sdk.utils.StringDownloader;
1718

@@ -25,6 +26,7 @@ class MetadataDownloader extends StringDownloader {
2526

2627
private boolean hasData = false;
2728
private RoundingMode roundingMode;
29+
private boolean verifyInternalEanChecksum;
2830

2931
public MetadataDownloader(SnabbleSdk sdk,
3032
String bundledFileAssetPath) {
@@ -72,6 +74,7 @@ protected void onDownloadFinished(String content) {
7274
if (jsonObject.has("project")) {
7375
this.project = jsonObject.get("project").getAsJsonObject();
7476
this.roundingMode = parseRoundingMode(project.get("roundingMode"));
77+
this.verifyInternalEanChecksum = JsonUtils.getBooleanOpt(project, "verifyInternalEanChecksum", true);
7578
}
7679

7780
this.urls = Collections.unmodifiableMap(urls);
@@ -125,4 +128,8 @@ public JsonObject getProject() {
125128
public RoundingMode getRoundingMode() {
126129
return roundingMode;
127130
}
131+
132+
public boolean isVerifyingInternalEanChecksum() {
133+
return verifyInternalEanChecksum;
134+
}
128135
}

core/src/main/java/io/snabble/sdk/SnabbleSdk.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,10 @@ public RoundingMode getRoundingMode() {
590590
return metadataDownloader.getRoundingMode();
591591
}
592592

593+
public boolean isVerifyingInternalEanChecksum() {
594+
return metadataDownloader.isVerifyingInternalEanChecksum();
595+
}
596+
593597
public Checkout getCheckout() {
594598
return checkout;
595599
}

core/src/main/java/io/snabble/sdk/codes/EAN13.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,41 @@
44

55
import java.io.Serializable;
66

7+
import io.snabble.sdk.SnabbleSdk;
8+
79
public class EAN13 extends ScannableCode implements Serializable {
810
private String lookupCode;
911
private int embeddedData;
10-
private boolean hasAmountData;
12+
private boolean hasUnitData;
1113
private boolean hasPriceData;
1214
private boolean hasWeighData;
1315

14-
public EAN13(String code, String[] weighPrefixes, String[] pricePrefixes, String[] amountPrefixes) {
16+
private boolean verifyInternalEanChecksum;
17+
18+
EAN13(String code, SnabbleSdk snabbleSdk) {
1519
super(code);
1620

1721
if(!isEan13(code)){
1822
throw new IllegalArgumentException("Not a valid EAN13 code");
1923
}
2024

21-
for (String prefix : weighPrefixes) {
25+
verifyInternalEanChecksum = snabbleSdk.isVerifyingInternalEanChecksum();
26+
27+
for (String prefix : snabbleSdk.getWeighPrefixes()) {
2228
if (code.startsWith(prefix)) {
2329
hasWeighData = true;
2430
}
2531
}
2632

27-
for (String prefix : pricePrefixes) {
33+
for (String prefix : snabbleSdk.getPricePrefixes()) {
2834
if (code.startsWith(prefix)) {
2935
hasPriceData = true;
3036
}
3137
}
3238

33-
for (String prefix : amountPrefixes) {
39+
for (String prefix : snabbleSdk.getUnitPrefixes()) {
3440
if (code.startsWith(prefix)) {
35-
hasAmountData = true;
41+
hasUnitData = true;
3642
}
3743
}
3844

@@ -42,7 +48,7 @@ public EAN13(String code, String[] weighPrefixes, String[] pricePrefixes, String
4248
} else {
4349
lookupCode = code;
4450
hasWeighData = false;
45-
hasAmountData = false;
51+
hasUnitData = false;
4652
hasPriceData = false;
4753
}
4854
}
@@ -59,7 +65,7 @@ public int getEmbeddedData() {
5965

6066
@Override
6167
public boolean hasAmountData() {
62-
return hasAmountData;
68+
return hasUnitData;
6369
}
6470

6571
@Override
@@ -74,7 +80,7 @@ public boolean hasWeighData() {
7480

7581
@Override
7682
public boolean hasEmbeddedData(){
77-
return hasAmountData || hasPriceData || hasWeighData;
83+
return hasUnitData || hasPriceData || hasWeighData;
7884
}
7985

8086
@Override
@@ -83,6 +89,10 @@ public boolean isEmbeddedDataOk() {
8389
return false;
8490
}
8591

92+
if(!verifyInternalEanChecksum){
93+
return true;
94+
}
95+
8696
String code = getCode();
8797
int digit = Character.digit(code.charAt(6), 10);
8898
int check = internalChecksum(code);

core/src/main/java/io/snabble/sdk/codes/ScannableCode.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ public boolean isEmbeddedDataOk() {
4545

4646
public static ScannableCode parse(SnabbleSdk snabbleSdk, String code){
4747
if(EAN13.isEan13(code)){
48-
return new EAN13(code,
49-
snabbleSdk.getWeighPrefixes(),
50-
snabbleSdk.getPricePrefixes(),
51-
snabbleSdk.getUnitPrefixes());
48+
return new EAN13(code, snabbleSdk);
5249
} else {
5350
return new ScannableCode(code);
5451
}

0 commit comments

Comments
 (0)