Skip to content

Commit 03dcbfc

Browse files
chuffChad Huff
andauthored
remove validation (#66)
* remove validation * fix lazy decoding in decodeSection --------- Co-authored-by: Chad Huff <[email protected]>
1 parent 8da3fe6 commit 03dcbfc

21 files changed

+19
-3628
lines changed

iabgpp-encoder/src/main/java/com/iab/gpp/encoder/GppModel.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,12 @@ public void decodeSection(int sectionId, String encodedString) {
472472
}
473473

474474
public void decodeSection(String sectionName, String encodedString) {
475+
if (!this.decoded) {
476+
this.sections = this.decodeModel(this.encodedString);
477+
this.dirty = false;
478+
this.decoded = true;
479+
}
480+
475481
EncodableSection section = null;
476482
if (!this.sections.containsKey(sectionName)) {
477483
if (sectionName.equals(TcfEuV2.NAME)) {
@@ -538,6 +544,7 @@ public void decodeSection(String sectionName, String encodedString) {
538544

539545
if (section != null) {
540546
section.decode(encodedString);
547+
this.dirty = true;
541548
}
542549
}
543550

iabgpp-encoder/src/main/java/com/iab/gpp/encoder/segment/UsCaCoreSegment.java

Lines changed: 9 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import com.iab.gpp.encoder.datatype.EncodableFixedInteger;
1010
import com.iab.gpp.encoder.datatype.EncodableFixedIntegerList;
1111
import com.iab.gpp.encoder.error.DecodingException;
12-
import com.iab.gpp.encoder.error.ValidationException;
1312
import com.iab.gpp.encoder.field.EncodableBitStringFields;
1413
import com.iab.gpp.encoder.field.UsCaField;
1514
import com.iab.gpp.encoder.section.UsCa;
@@ -35,16 +34,16 @@ public List<String> getFieldNames() {
3534

3635
@Override
3736
protected EncodableBitStringFields initializeFields() {
38-
Predicate<Integer> nullableBooleanAsTwoBitIntegerValidator = (n -> n >= 0 && n <= 2);
39-
Predicate<Integer> nonNullableBooleanAsTwoBitIntegerValidator = (n -> n >= 1 && n <= 2);
40-
Predicate<List<Integer>> nullableBooleanAsTwoBitIntegerListValidator = (l -> {
41-
for (int n : l) {
42-
if (n < 0 || n > 2) {
43-
return false;
44-
}
37+
Predicate<Integer> nullableBooleanAsTwoBitIntegerValidator = (n -> n >= 0 && n <= 2);
38+
Predicate<Integer> nonNullableBooleanAsTwoBitIntegerValidator = (n -> n >= 1 && n <= 2);
39+
Predicate<List<Integer>> nullableBooleanAsTwoBitIntegerListValidator = (l -> {
40+
for (int n : l) {
41+
if (n < 0 || n > 2) {
42+
return false;
4543
}
46-
return true;
47-
});
44+
}
45+
return true;
46+
});
4847

4948
EncodableBitStringFields fields = new EncodableBitStringFields();
5049
fields.put(UsCaField.VERSION, new EncodableFixedInteger(6, UsCa.VERSION));
@@ -94,97 +93,4 @@ protected void decodeSegment(String encodedString, EncodableBitStringFields fiel
9493
}
9594
}
9695

97-
@Override
98-
public void validate() {
99-
Integer sharingOptOutNotice = ((EncodableFixedInteger) fields.get(UsCaField.SHARING_OPT_OUT_NOTICE)).getValue();
100-
Integer sharingOptOut = ((EncodableFixedInteger) fields.get(UsCaField.SHARING_OPT_OUT)).getValue();
101-
Integer saleOptOutNotice = ((EncodableFixedInteger) fields.get(UsCaField.SALE_OPT_OUT_NOTICE)).getValue();
102-
Integer saleOptOut = ((EncodableFixedInteger) fields.get(UsCaField.SALE_OPT_OUT)).getValue();
103-
Integer mspaServiceProviderMode =
104-
((EncodableFixedInteger) fields.get(UsCaField.MSPA_SERVICE_PROVIDER_MODE)).getValue();
105-
Integer mspaOptOutOptionMode =
106-
((EncodableFixedInteger) fields.get(UsCaField.MSPA_OPT_OUT_OPTION_MODE)).getValue();
107-
Integer sensitiveDataLimtUserNotice =
108-
((EncodableFixedInteger) fields.get(UsCaField.SENSITIVE_DATA_LIMIT_USE_NOTICE)).getValue();
109-
110-
if (sharingOptOutNotice == 0) {
111-
if (sharingOptOut != 0) {
112-
throw new ValidationException(
113-
"Invalid usca sharing notice / opt out combination: {" + sharingOptOutNotice + " / " + sharingOptOut + "}");
114-
}
115-
} else if (sharingOptOutNotice == 1) {
116-
if (sharingOptOut != 1 && sharingOptOut != 2) {
117-
throw new ValidationException(
118-
"Invalid usca sharing notice / opt out combination: {" + sharingOptOutNotice + " / " + sharingOptOut + "}");
119-
}
120-
} else if (sharingOptOutNotice == 2) {
121-
if (sharingOptOut != 1) {
122-
throw new ValidationException(
123-
"Invalid usca sharing notice / opt out combination: {" + sharingOptOutNotice + " / " + sharingOptOut + "}");
124-
}
125-
}
126-
127-
if (saleOptOutNotice == 0) {
128-
if (saleOptOut != 0) {
129-
throw new ValidationException(
130-
"Invalid usca sale notice / opt out combination: {" + saleOptOutNotice + " / " + saleOptOut + "}");
131-
}
132-
} else if (saleOptOutNotice == 1) {
133-
if (saleOptOut != 1 && saleOptOut != 2) {
134-
throw new ValidationException(
135-
"Invalid usca sale notice / opt out combination: {" + saleOptOutNotice + " / " + saleOptOut + "}");
136-
}
137-
} else if (saleOptOutNotice == 2) {
138-
if (saleOptOut != 1) {
139-
throw new ValidationException(
140-
"Invalid usca sale notice / opt out combination: {" + saleOptOutNotice + " / " + saleOptOut + "}");
141-
}
142-
}
143-
144-
if (mspaServiceProviderMode == 0) {
145-
if (saleOptOutNotice != 0) {
146-
throw new ValidationException("Invalid usca mspa service provider mode / sale opt out notice combination: {"
147-
+ mspaServiceProviderMode + " / " + saleOptOutNotice + "}");
148-
}
149-
150-
if (sharingOptOutNotice != 0) {
151-
throw new ValidationException("Invalid usca mspa service provider mode / sharing opt out notice combination: {"
152-
+ mspaServiceProviderMode + " / " + sharingOptOutNotice + "}");
153-
}
154-
155-
if (sensitiveDataLimtUserNotice != 0) {
156-
throw new ValidationException(
157-
"Invalid usca mspa service provider mode / sensitive data limit use notice combination: {"
158-
+ mspaServiceProviderMode + " / " + sensitiveDataLimtUserNotice + "}");
159-
}
160-
} else if (mspaServiceProviderMode == 1) {
161-
if (mspaOptOutOptionMode != 2) {
162-
throw new ValidationException("Invalid usca mspa service provider / opt out option modes combination: {"
163-
+ mspaServiceProviderMode + " / " + mspaServiceProviderMode + "}");
164-
}
165-
166-
if (saleOptOutNotice != 0) {
167-
throw new ValidationException("Invalid usca mspa service provider mode / sale opt out notice combination: {"
168-
+ mspaServiceProviderMode + " / " + saleOptOutNotice + "}");
169-
}
170-
171-
if (sharingOptOutNotice != 0) {
172-
throw new ValidationException("Invalid usca mspa service provider mode / sharing opt out notice combination: {"
173-
+ mspaServiceProviderMode + " / " + sharingOptOutNotice + "}");
174-
}
175-
176-
if (sensitiveDataLimtUserNotice != 0) {
177-
throw new ValidationException(
178-
"Invalid usca mspa service provider mode / sensitive data limit use notice combination: {"
179-
+ mspaServiceProviderMode + " / " + sensitiveDataLimtUserNotice + "}");
180-
}
181-
} else if (mspaServiceProviderMode == 2) {
182-
if (mspaOptOutOptionMode != 1) {
183-
throw new ValidationException("Invalid usca mspa service provider / opt out option modes combination: {"
184-
+ mspaServiceProviderMode + " / " + mspaOptOutOptionMode + "}");
185-
}
186-
}
187-
}
188-
189-
19096
}

iabgpp-encoder/src/main/java/com/iab/gpp/encoder/segment/UsCoCoreSegment.java

Lines changed: 2 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import com.iab.gpp.encoder.datatype.EncodableFixedInteger;
1010
import com.iab.gpp.encoder.datatype.EncodableFixedIntegerList;
1111
import com.iab.gpp.encoder.error.DecodingException;
12-
import com.iab.gpp.encoder.error.ValidationException;
1312
import com.iab.gpp.encoder.field.EncodableBitStringFields;
1413
import com.iab.gpp.encoder.field.UsCoField;
1514
import com.iab.gpp.encoder.section.UsCo;
@@ -58,9 +57,8 @@ protected EncodableBitStringFields initializeFields() {
5857
new EncodableFixedInteger(2, 0).withValidator(nullableBooleanAsTwoBitIntegerValidator));
5958
fields.put(UsCoField.TARGETED_ADVERTISING_OPT_OUT,
6059
new EncodableFixedInteger(2, 0).withValidator(nullableBooleanAsTwoBitIntegerValidator));
61-
fields.put(UsCoField.SENSITIVE_DATA_PROCESSING,
62-
new EncodableFixedIntegerList(2, Arrays.asList(0, 0, 0, 0, 0, 0, 0))
63-
.withValidator(nullableBooleanAsTwoBitIntegerListValidator));
60+
fields.put(UsCoField.SENSITIVE_DATA_PROCESSING, new EncodableFixedIntegerList(2, Arrays.asList(0, 0, 0, 0, 0, 0, 0))
61+
.withValidator(nullableBooleanAsTwoBitIntegerListValidator));
6462
fields.put(UsCoField.KNOWN_CHILD_SENSITIVE_DATA_CONSENTS,
6563
new EncodableFixedInteger(2, 0).withValidator(nullableBooleanAsTwoBitIntegerValidator));
6664
fields.put(UsCoField.MSPA_COVERED_TRANSACTION,
@@ -92,75 +90,4 @@ protected void decodeSegment(String encodedString, EncodableBitStringFields fiel
9290
}
9391
}
9492

95-
@Override
96-
public void validate() {
97-
Integer saleOptOutNotice = ((EncodableFixedInteger) fields.get(UsCoField.SALE_OPT_OUT_NOTICE)).getValue();
98-
Integer saleOptOut = ((EncodableFixedInteger) fields.get(UsCoField.SALE_OPT_OUT)).getValue();
99-
Integer targetedAdvertisingOptOutNotice =
100-
((EncodableFixedInteger) fields.get(UsCoField.TARGETED_ADVERTISING_OPT_OUT_NOTICE)).getValue();
101-
Integer targetedAdvertisingOptOut =
102-
((EncodableFixedInteger) fields.get(UsCoField.TARGETED_ADVERTISING_OPT_OUT)).getValue();
103-
Integer mspaServiceProviderMode =
104-
((EncodableFixedInteger) fields.get(UsCoField.MSPA_SERVICE_PROVIDER_MODE)).getValue();
105-
Integer mspaOptOutOptionMode =
106-
((EncodableFixedInteger) fields.get(UsCoField.MSPA_OPT_OUT_OPTION_MODE)).getValue();
107-
108-
if (saleOptOutNotice == 0) {
109-
if (saleOptOut != 0) {
110-
throw new ValidationException(
111-
"Invalid usco sale notice / opt out combination: {" + saleOptOutNotice + " / " + saleOptOut + "}");
112-
}
113-
} else if (saleOptOutNotice == 1) {
114-
if (saleOptOut != 1 && saleOptOut != 2) {
115-
throw new ValidationException(
116-
"Invalid usco sale notice / opt out combination: {" + saleOptOutNotice + " / " + saleOptOut + "}");
117-
}
118-
} else if (saleOptOutNotice == 2) {
119-
if (saleOptOut != 1) {
120-
throw new ValidationException(
121-
"Invalid usco sale notice / opt out combination: {" + saleOptOutNotice + " / " + saleOptOut + "}");
122-
}
123-
}
124-
125-
if (targetedAdvertisingOptOutNotice == 0) {
126-
if (targetedAdvertisingOptOut != 0) {
127-
throw new ValidationException("Invalid usco targeted advertising notice / opt out combination: {"
128-
+ targetedAdvertisingOptOutNotice + " / " + targetedAdvertisingOptOut + "}");
129-
}
130-
} else if (targetedAdvertisingOptOutNotice == 1) {
131-
if (saleOptOut != 1 && saleOptOut != 2) {
132-
throw new ValidationException("Invalid usco targeted advertising notice / opt out combination: {"
133-
+ targetedAdvertisingOptOutNotice + " / " + targetedAdvertisingOptOut + "}");
134-
}
135-
} else if (targetedAdvertisingOptOutNotice == 2) {
136-
if (saleOptOut != 1) {
137-
throw new ValidationException("Invalid usco targeted advertising notice / opt out combination: {"
138-
+ targetedAdvertisingOptOutNotice + " / " + targetedAdvertisingOptOut + "}");
139-
}
140-
}
141-
142-
if (mspaServiceProviderMode == 0) {
143-
if (saleOptOutNotice != 0) {
144-
throw new ValidationException("Invalid usco mspa service provider mode / sale opt out notice combination: {"
145-
+ mspaServiceProviderMode + " / " + saleOptOutNotice + "}");
146-
}
147-
} else if (mspaServiceProviderMode == 1) {
148-
if (mspaOptOutOptionMode != 2) {
149-
throw new ValidationException("Invalid usco mspa service provider / opt out option modes combination: {"
150-
+ mspaServiceProviderMode + " / " + mspaServiceProviderMode + "}");
151-
}
152-
153-
if (saleOptOutNotice != 0) {
154-
throw new ValidationException("Invalid usco mspa service provider mode / sale opt out notice combination: {"
155-
+ mspaServiceProviderMode + " / " + saleOptOutNotice + "}");
156-
}
157-
} else if (mspaServiceProviderMode == 2) {
158-
if (mspaOptOutOptionMode != 1) {
159-
throw new ValidationException("Invalid usco mspa service provider / opt out option modes combination: {"
160-
+ mspaServiceProviderMode + " / " + mspaOptOutOptionMode + "}");
161-
}
162-
}
163-
}
164-
165-
16693
}

iabgpp-encoder/src/main/java/com/iab/gpp/encoder/segment/UsCtCoreSegment.java

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import com.iab.gpp.encoder.datatype.EncodableFixedInteger;
1010
import com.iab.gpp.encoder.datatype.EncodableFixedIntegerList;
1111
import com.iab.gpp.encoder.error.DecodingException;
12-
import com.iab.gpp.encoder.error.ValidationException;
1312
import com.iab.gpp.encoder.field.EncodableBitStringFields;
1413
import com.iab.gpp.encoder.field.UsCtField;
1514
import com.iab.gpp.encoder.section.UsCt;
@@ -92,75 +91,4 @@ protected void decodeSegment(String encodedString, EncodableBitStringFields fiel
9291
}
9392
}
9493

95-
@Override
96-
public void validate() {
97-
Integer saleOptOutNotice = ((EncodableFixedInteger) fields.get(UsCtField.SALE_OPT_OUT_NOTICE)).getValue();
98-
Integer saleOptOut = ((EncodableFixedInteger) fields.get(UsCtField.SALE_OPT_OUT)).getValue();
99-
Integer targetedAdvertisingOptOutNotice =
100-
((EncodableFixedInteger) fields.get(UsCtField.TARGETED_ADVERTISING_OPT_OUT_NOTICE)).getValue();
101-
Integer targetedAdvertisingOptOut =
102-
((EncodableFixedInteger) fields.get(UsCtField.TARGETED_ADVERTISING_OPT_OUT)).getValue();
103-
Integer mspaServiceProviderMode =
104-
((EncodableFixedInteger) fields.get(UsCtField.MSPA_SERVICE_PROVIDER_MODE)).getValue();
105-
Integer mspaOptOutOptionMode =
106-
((EncodableFixedInteger) fields.get(UsCtField.MSPA_OPT_OUT_OPTION_MODE)).getValue();
107-
108-
if (saleOptOutNotice == 0) {
109-
if (saleOptOut != 0) {
110-
throw new ValidationException(
111-
"Invalid usct sale notice / opt out combination: {" + saleOptOutNotice + " / " + saleOptOut + "}");
112-
}
113-
} else if (saleOptOutNotice == 1) {
114-
if (saleOptOut != 1 && saleOptOut != 2) {
115-
throw new ValidationException(
116-
"Invalid usct sale notice / opt out combination: {" + saleOptOutNotice + " / " + saleOptOut + "}");
117-
}
118-
} else if (saleOptOutNotice == 2) {
119-
if (saleOptOut != 1) {
120-
throw new ValidationException(
121-
"Invalid usct sale notice / opt out combination: {" + saleOptOutNotice + " / " + saleOptOut + "}");
122-
}
123-
}
124-
125-
if (targetedAdvertisingOptOutNotice == 0) {
126-
if (targetedAdvertisingOptOut != 0) {
127-
throw new ValidationException("Invalid usct targeted advertising notice / opt out combination: {"
128-
+ targetedAdvertisingOptOutNotice + " / " + targetedAdvertisingOptOut + "}");
129-
}
130-
} else if (targetedAdvertisingOptOutNotice == 1) {
131-
if (saleOptOut != 1 && saleOptOut != 2) {
132-
throw new ValidationException("Invalid usct targeted advertising notice / opt out combination: {"
133-
+ targetedAdvertisingOptOutNotice + " / " + targetedAdvertisingOptOut + "}");
134-
}
135-
} else if (targetedAdvertisingOptOutNotice == 2) {
136-
if (saleOptOut != 1) {
137-
throw new ValidationException("Invalid usct targeted advertising notice / opt out combination: {"
138-
+ targetedAdvertisingOptOutNotice + " / " + targetedAdvertisingOptOut + "}");
139-
}
140-
}
141-
142-
if (mspaServiceProviderMode == 0) {
143-
if (saleOptOutNotice != 0) {
144-
throw new ValidationException("Invalid usct mspa service provider mode / sale opt out notice combination: {"
145-
+ mspaServiceProviderMode + " / " + saleOptOutNotice + "}");
146-
}
147-
} else if (mspaServiceProviderMode == 1) {
148-
if (mspaOptOutOptionMode != 2) {
149-
throw new ValidationException("Invalid usct mspa service provider / opt out option modes combination: {"
150-
+ mspaServiceProviderMode + " / " + mspaServiceProviderMode + "}");
151-
}
152-
153-
if (saleOptOutNotice != 0) {
154-
throw new ValidationException("Invalid usct mspa service provider mode / sale opt out notice combination: {"
155-
+ mspaServiceProviderMode + " / " + saleOptOutNotice + "}");
156-
}
157-
} else if (mspaServiceProviderMode == 2) {
158-
if (mspaOptOutOptionMode != 1) {
159-
throw new ValidationException("Invalid usct mspa service provider / opt out option modes combination: {"
160-
+ mspaServiceProviderMode + " / " + mspaOptOutOptionMode + "}");
161-
}
162-
}
163-
}
164-
165-
16694
}

0 commit comments

Comments
 (0)