-
Notifications
You must be signed in to change notification settings - Fork 18
Minnesota #85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minnesota #85
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package com.iab.gpp.encoder.field; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| public class UsMnField { | ||
|
|
||
| public static String VERSION = "Version"; | ||
| public static String PROCESSING_NOTICE = "ProcessingNotice"; | ||
| public static String SALE_OPT_OUT_NOTICE = "SaleOptOutNotice"; | ||
| public static String TARGETED_ADVERTISING_OPT_OUT_NOTICE = "TargetedAdvertisingOptOutNotice"; | ||
| public static String SALE_OPT_OUT = "SaleOptOut"; | ||
| public static String TARGETED_ADVERTISING_OPT_OUT = "TargetedAdvertisingOptOut"; | ||
| public static String SENSITIVE_DATA_PROCESSING = "SensitiveDataProcessing"; | ||
| public static String KNOWN_CHILD_SENSITIVE_DATA_CONSENTS = "KnownChildSensitiveDataConsents"; | ||
| public static String ADDITIONAL_DATA_PROCESSING_CONSENT = "AdditionalDataProcessingConsent"; | ||
| public static String MSPA_COVERED_TRANSACTION = "MspaCoveredTransaction"; | ||
| public static String MSPA_OPT_OUT_OPTION_MODE = "MspaOptOutOptionMode"; | ||
| public static String MSPA_SERVICE_PROVIDER_MODE = "MspaServiceProviderMode"; | ||
|
|
||
| public static String GPC_SEGMENT_TYPE = "GpcSegmentType"; | ||
| public static String GPC_SEGMENT_INCLUDED = "GpcSegmentIncluded"; | ||
| public static String GPC = "Gpc"; | ||
|
|
||
| //@formatter:off | ||
| public static List<String> USMN_CORE_SEGMENT_FIELD_NAMES = Arrays.asList(new String[] { | ||
| UsMnField.VERSION, | ||
| UsMnField.PROCESSING_NOTICE, | ||
| UsMnField.SALE_OPT_OUT_NOTICE, | ||
| UsMnField.TARGETED_ADVERTISING_OPT_OUT_NOTICE, | ||
| UsMnField.SALE_OPT_OUT, | ||
| UsMnField.TARGETED_ADVERTISING_OPT_OUT, | ||
| UsMnField.SENSITIVE_DATA_PROCESSING, | ||
| UsMnField.KNOWN_CHILD_SENSITIVE_DATA_CONSENTS, | ||
| UsMnField.ADDITIONAL_DATA_PROCESSING_CONSENT, | ||
| UsMnField.MSPA_COVERED_TRANSACTION, | ||
| UsMnField.MSPA_OPT_OUT_OPTION_MODE, | ||
| UsMnField.MSPA_SERVICE_PROVIDER_MODE | ||
| }); | ||
| //@formatter:on | ||
|
|
||
| //@formatter:off | ||
| public static List<String> USMN_GPC_SEGMENT_FIELD_NAMES = Arrays.asList(new String[] { | ||
| UsMnField.GPC_SEGMENT_TYPE, | ||
| UsMnField.GPC | ||
| }); | ||
| //@formatter:on | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| package com.iab.gpp.encoder.section; | ||
|
|
||
| import com.iab.gpp.encoder.field.UsDeField; | ||
| import com.iab.gpp.encoder.segment.EncodableSegment; | ||
| import com.iab.gpp.encoder.segment.UsDeCoreSegment; | ||
| import com.iab.gpp.encoder.segment.UsDeGpcSegment; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class UsMn extends AbstractLazilyEncodableSection { | ||
|
|
||
| public static int ID = 23; | ||
| public static int VERSION = 1; | ||
| public static String NAME = "usmn"; | ||
|
|
||
| public UsMn() { | ||
| super(); | ||
| } | ||
|
|
||
| public UsMn(String encodedString) { | ||
| super(); | ||
| decode(encodedString); | ||
| } | ||
|
|
||
| @Override | ||
| public int getId() { | ||
| return UsMn.ID; | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return UsMn.NAME; | ||
| } | ||
|
|
||
| @Override | ||
| public int getVersion() { | ||
| return UsMn.VERSION; | ||
| } | ||
|
|
||
| @Override | ||
| protected List<EncodableSegment> initializeSegments() { | ||
| List<EncodableSegment> segments = new ArrayList<>(); | ||
| segments.add(new UsDeCoreSegment()); | ||
| segments.add(new UsDeGpcSegment()); | ||
| return segments; | ||
| } | ||
|
|
||
| @Override | ||
| protected List<EncodableSegment> decodeSection(String encodedString) { | ||
| List<EncodableSegment> segments = initializeSegments(); | ||
|
|
||
| if (encodedString != null && !encodedString.isEmpty()) { | ||
| String[] encodedSegments = encodedString.split("\\."); | ||
|
|
||
| if (encodedSegments.length > 0) { | ||
| segments.get(0).decode(encodedSegments[0]); | ||
| } | ||
|
|
||
| if (encodedSegments.length > 1) { | ||
| segments.get(1).setFieldValue(UsDeField.GPC_SEGMENT_INCLUDED, true); | ||
| segments.get(1).decode(encodedSegments[1]); | ||
| } else { | ||
| segments.get(1).setFieldValue(UsDeField.GPC_SEGMENT_INCLUDED, false); | ||
| } | ||
| } | ||
|
|
||
| return segments; | ||
| } | ||
|
|
||
| @Override | ||
| protected String encodeSection(List<EncodableSegment> segments) { | ||
| List<String> encodedSegments = new ArrayList<>(); | ||
|
|
||
| if (!segments.isEmpty()) { | ||
| encodedSegments.add(segments.get(0).encode()); | ||
| if (segments.size() >= 2 && segments.get(1).getFieldValue(UsDeField.GPC_SEGMENT_INCLUDED).equals(true)) { | ||
| encodedSegments.add(segments.get(1).encode()); | ||
| } | ||
| } | ||
|
|
||
| return String.join(".", encodedSegments); | ||
| } | ||
|
|
||
|
|
||
| public Integer getProcessingNotice() { | ||
| return (Integer) this.getFieldValue(UsDeField.PROCESSING_NOTICE); | ||
| } | ||
|
|
||
| public Integer getSaleOptOutNotice() { | ||
| return (Integer) this.getFieldValue(UsDeField.SALE_OPT_OUT_NOTICE); | ||
|
chuff marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| public Integer getTargetedAdvertisingOptOutNotice() { | ||
| return (Integer) this.getFieldValue(UsDeField.TARGETED_ADVERTISING_OPT_OUT_NOTICE); | ||
| } | ||
|
|
||
| public Integer getSaleOptOut() { | ||
| return (Integer) this.getFieldValue(UsDeField.SALE_OPT_OUT); | ||
| } | ||
|
|
||
| public Integer getTargetedAdvertisingOptOut() { | ||
| return (Integer) this.getFieldValue(UsDeField.TARGETED_ADVERTISING_OPT_OUT); | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| public List<Integer> getSensitiveDataProcessing() { | ||
| return (List<Integer>) this.getFieldValue(UsDeField.SENSITIVE_DATA_PROCESSING); | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| public List<Integer> getKnownChildSensitiveDataConsents() { | ||
| return (List<Integer>) this.getFieldValue(UsDeField.KNOWN_CHILD_SENSITIVE_DATA_CONSENTS); | ||
| } | ||
|
|
||
| public Integer getAdditionalDataProcessingConsent() { | ||
| return (Integer) this.getFieldValue(UsDeField.ADDITIONAL_DATA_PROCESSING_CONSENT); | ||
| } | ||
|
|
||
| public Integer getMspaCoveredTransaction() { | ||
| return (Integer) this.getFieldValue(UsDeField.MSPA_COVERED_TRANSACTION); | ||
| } | ||
|
|
||
| public Integer getMspaOptOutOptionMode() { | ||
| return (Integer) this.getFieldValue(UsDeField.MSPA_OPT_OUT_OPTION_MODE); | ||
| } | ||
|
|
||
| public Integer getMspaServiceProviderMode() { | ||
| return (Integer) this.getFieldValue(UsDeField.MSPA_SERVICE_PROVIDER_MODE); | ||
| } | ||
|
|
||
| public Integer getGpcSegmentType() { | ||
| return (Integer) this.getFieldValue(UsDeField.GPC_SEGMENT_TYPE); | ||
| } | ||
|
|
||
| public Boolean getGpcSegmentIncluded() { | ||
| return (Boolean) this.getFieldValue(UsDeField.GPC_SEGMENT_INCLUDED); | ||
| } | ||
|
|
||
| public Boolean getGpc() { | ||
| return (Boolean) this.getFieldValue(UsDeField.GPC); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| package com.iab.gpp.encoder.segment; | ||
|
|
||
| import com.iab.gpp.encoder.base64.AbstractBase64UrlEncoder; | ||
| import com.iab.gpp.encoder.base64.CompressedBase64UrlEncoder; | ||
| import com.iab.gpp.encoder.bitstring.BitStringEncoder; | ||
| import com.iab.gpp.encoder.datatype.EncodableFixedInteger; | ||
| import com.iab.gpp.encoder.datatype.EncodableFixedIntegerList; | ||
| import com.iab.gpp.encoder.error.DecodingException; | ||
| import com.iab.gpp.encoder.field.EncodableBitStringFields; | ||
| import com.iab.gpp.encoder.field.UsMnField; | ||
| import com.iab.gpp.encoder.section.UsMn; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.function.Predicate; | ||
|
|
||
| public class UsMnCoreSegment extends AbstractLazilyEncodableSegment<EncodableBitStringFields> { | ||
|
|
||
| private AbstractBase64UrlEncoder base64UrlEncoder = CompressedBase64UrlEncoder.getInstance(); | ||
| private BitStringEncoder bitStringEncoder = BitStringEncoder.getInstance(); | ||
|
|
||
| public UsMnCoreSegment() { | ||
| super(); | ||
| } | ||
|
|
||
| public UsMnCoreSegment(String encodedString) { | ||
| super(); | ||
| this.decode(encodedString); | ||
| } | ||
|
|
||
| @Override | ||
| public List<String> getFieldNames() { | ||
| return UsMnField.USMN_CORE_SEGMENT_FIELD_NAMES; | ||
| } | ||
|
|
||
| @Override | ||
| protected EncodableBitStringFields initializeFields() { | ||
| Predicate<Integer> nullableBooleanAsTwoBitIntegerValidator = (n -> n >= 0 && n <= 2); | ||
| Predicate<Integer> nonNullableBooleanAsTwoBitIntegerValidator = (n -> n >= 1 && n <= 2); | ||
| Predicate<List<Integer>> nullableBooleanAsTwoBitIntegerListValidator = (l -> { | ||
| for (int n : l) { | ||
| if (n < 0 || n > 2) { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| }); | ||
|
|
||
| EncodableBitStringFields fields = new EncodableBitStringFields(); | ||
| fields.put(UsMnField.VERSION, new EncodableFixedInteger(6, UsMn.VERSION)); | ||
| fields.put(UsMnField.PROCESSING_NOTICE, | ||
| new EncodableFixedInteger(2, 0).withValidator(nullableBooleanAsTwoBitIntegerValidator)); | ||
| fields.put(UsMnField.SALE_OPT_OUT_NOTICE, | ||
| new EncodableFixedInteger(2, 0).withValidator(nullableBooleanAsTwoBitIntegerValidator)); | ||
| fields.put(UsMnField.TARGETED_ADVERTISING_OPT_OUT_NOTICE, | ||
| new EncodableFixedInteger(2, 0).withValidator(nullableBooleanAsTwoBitIntegerValidator)); | ||
| fields.put(UsMnField.SALE_OPT_OUT, | ||
| new EncodableFixedInteger(2, 0).withValidator(nullableBooleanAsTwoBitIntegerValidator)); | ||
| fields.put(UsMnField.TARGETED_ADVERTISING_OPT_OUT, | ||
| new EncodableFixedInteger(2, 0).withValidator(nullableBooleanAsTwoBitIntegerValidator)); | ||
| fields.put(UsMnField.SENSITIVE_DATA_PROCESSING, | ||
| new EncodableFixedIntegerList(2, Arrays.asList(0, 0, 0, 0, 0, 0, 0, 0, 0)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is |
||
| .withValidator(nullableBooleanAsTwoBitIntegerListValidator)); | ||
| fields.put(UsMnField.KNOWN_CHILD_SENSITIVE_DATA_CONSENTS, | ||
| new EncodableFixedIntegerList(2, Arrays.asList(0, 0, 0, 0, 0)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is |
||
| .withValidator(nullableBooleanAsTwoBitIntegerListValidator)); | ||
| fields.put(UsMnField.ADDITIONAL_DATA_PROCESSING_CONSENT, | ||
| new EncodableFixedInteger(2, 0).withValidator(nullableBooleanAsTwoBitIntegerValidator)); | ||
| fields.put(UsMnField.MSPA_COVERED_TRANSACTION, | ||
| new EncodableFixedInteger(2, 1).withValidator(nonNullableBooleanAsTwoBitIntegerValidator)); | ||
| fields.put(UsMnField.MSPA_OPT_OUT_OPTION_MODE, | ||
| new EncodableFixedInteger(2, 0).withValidator(nullableBooleanAsTwoBitIntegerValidator)); | ||
| fields.put(UsMnField.MSPA_SERVICE_PROVIDER_MODE, | ||
| new EncodableFixedInteger(2, 0).withValidator(nullableBooleanAsTwoBitIntegerValidator)); | ||
| return fields; | ||
| } | ||
|
|
||
| @Override | ||
| protected String encodeSegment(EncodableBitStringFields fields) { | ||
| String bitString = bitStringEncoder.encode(fields, getFieldNames()); | ||
| String encodedString = base64UrlEncoder.encode(bitString); | ||
| return encodedString; | ||
| } | ||
|
|
||
| @Override | ||
| protected void decodeSegment(String encodedString, EncodableBitStringFields fields) { | ||
| if (encodedString == null || encodedString.isEmpty()) { | ||
| this.fields.reset(fields); | ||
| } | ||
| try { | ||
| String bitString = base64UrlEncoder.decode(encodedString); | ||
| bitStringEncoder.decode(bitString, getFieldNames(), fields); | ||
| } catch (Exception e) { | ||
| throw new DecodingException("Unable to decode UsMnCoreSegment '" + encodedString + "'", e); | ||
| } | ||
| } | ||
|
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.