Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions iabgpp-encoder/src/main/java/com/iab/gpp/encoder/GppModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@
import com.iab.gpp.encoder.section.UsDe;
import com.iab.gpp.encoder.section.UsFl;
import com.iab.gpp.encoder.section.UsIa;
import com.iab.gpp.encoder.section.UsIn;
import com.iab.gpp.encoder.section.UsKy;
import com.iab.gpp.encoder.section.UsMd;
import com.iab.gpp.encoder.section.UsMn;
import com.iab.gpp.encoder.section.UsMt;
import com.iab.gpp.encoder.section.UsNat;
import com.iab.gpp.encoder.section.UsNe;
import com.iab.gpp.encoder.section.UsNh;
import com.iab.gpp.encoder.section.UsNj;
import com.iab.gpp.encoder.section.UsOr;
import com.iab.gpp.encoder.section.UsRi;
import com.iab.gpp.encoder.section.UsTn;
import com.iab.gpp.encoder.section.UsTx;
import com.iab.gpp.encoder.section.UsUt;
Expand Down Expand Up @@ -66,6 +70,10 @@ public class GppModel extends AbstractEncodable {
constructors.add(UsNj::new);
constructors.add(UsTn::new);
constructors.add(UsMn::new);
constructors.add(UsMd::new);
constructors.add(UsIn::new);
constructors.add(UsKy::new);
constructors.add(UsRi::new);

for (Supplier<EncodableSection<?>> constructor : constructors) {
EncodableSection<?> prototype = constructor.get();
Expand Down Expand Up @@ -265,6 +273,22 @@ public UsMn getUsMnSection() {
return (UsMn) getSection(UsMn.ID);
}

public UsMd getUsMdSection() {
return (UsMd) getSection(UsMd.ID);
}

public UsIn getUsInSection() {
return (UsIn) getSection(UsIn.ID);
}

public UsKy getUsKySection() {
return (UsKy) getSection(UsKy.ID);
}

public UsRi getUsRiSection() {
return (UsRi) getSection(UsRi.ID);
}

public IntegerSet getSectionIds() {
ensureDecode();
return header.getSectionsIds();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.iab.gpp.encoder.field;

import com.iab.gpp.encoder.datatype.DataType;
import com.iab.gpp.encoder.datatype.EncodableFixedInteger;
import com.iab.gpp.encoder.datatype.EncodableFixedIntegerList;
import com.iab.gpp.encoder.datatype.UnencodableBoolean;
import com.iab.gpp.encoder.section.UsIn;

public enum UsInField implements FieldKey {
MSPA_VERSION(new EncodableFixedInteger<>("MspaVersion", 6, UsIn.VERSION)),
MSPA_COVERED_TRANSACTION(
new EncodableFixedInteger<>("MspaCoveredTransaction", 2, 1, VALIDATOR_12)),
MSPA_MODE(new EncodableFixedInteger<>("MspaMode", 2, 0, VALIDATOR_012)),
PROCESSING_NOTICE(new EncodableFixedInteger<>("ProcessingNotice", 2, 0, VALIDATOR_012)),
SALE_OPT_OUT_NOTICE(new EncodableFixedInteger<>("SaleOptOutNotice", 2, 0, VALIDATOR_012)),
TARGETED_ADVERTISING_OPT_OUT_NOTICE(
new EncodableFixedInteger<>("TargetedAdvertisingOptOutNotice", 2, 0, VALIDATOR_012)),
SALE_OPT_OUT(new EncodableFixedInteger<>("SaleOptOut", 2, 0, VALIDATOR_012)),
TARGETED_ADVERTISING_OPT_OUT(
new EncodableFixedInteger<>("TargetedAdvertisingOptOut", 2, 0, VALIDATOR_012)),
KNOWN_CHILD_SENSITIVE_DATA_CONSENTS(
new EncodableFixedInteger<>("KnownChildSensitiveDataConsents", 2, 0, VALIDATOR_012)),
ADDITIONAL_DATA_PROCESSING_CONSENT(
new EncodableFixedInteger<>("AdditionalDataProcessingConsent", 2, 0, VALIDATOR_012)),

SENSITIVE_DATA_PROCESSING(
new EncodableFixedIntegerList<>("SensitiveDataProcessing", 2, 8, VALIDATOR_LIST_012)),
SENSITIVE_DATA_CONSENT_SEGMENT_INCLUDED(
new UnencodableBoolean<>("SensitiveDataConsentSegmentIncluded", true));

private final DataType<UsInField, ?> type;

UsInField(DataType<UsInField, ?> type) {
this.type = type;
}

@Override
public DataType<UsInField, ?> getType() {
return type;
}

public static final FieldNames<UsInField> USIN_CORE_SEGMENT_FIELD_NAMES =
new FieldNames<>(
UsInField.MSPA_VERSION,
UsInField.MSPA_COVERED_TRANSACTION,
UsInField.MSPA_MODE,
UsInField.PROCESSING_NOTICE,
UsInField.SALE_OPT_OUT_NOTICE,
UsInField.TARGETED_ADVERTISING_OPT_OUT_NOTICE,
UsInField.SALE_OPT_OUT,
UsInField.TARGETED_ADVERTISING_OPT_OUT,
UsInField.KNOWN_CHILD_SENSITIVE_DATA_CONSENTS,
UsInField.ADDITIONAL_DATA_PROCESSING_CONSENT);

public static final FieldNames<UsInField> USIN_SENSITIVE_DATA_CONSENT_SEGMENT_FIELD_NAMES =
new FieldNames<>(
UsInField.SENSITIVE_DATA_CONSENT_SEGMENT_INCLUDED, UsInField.SENSITIVE_DATA_PROCESSING);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.iab.gpp.encoder.field;

import com.iab.gpp.encoder.datatype.DataType;
import com.iab.gpp.encoder.datatype.EncodableFixedInteger;
import com.iab.gpp.encoder.datatype.EncodableFixedIntegerList;
import com.iab.gpp.encoder.datatype.UnencodableBoolean;
import com.iab.gpp.encoder.section.UsKy;

public enum UsKyField implements FieldKey {
MSPA_VERSION(new EncodableFixedInteger<>("MspaVersion", 6, UsKy.VERSION)),
MSPA_COVERED_TRANSACTION(
new EncodableFixedInteger<>("MspaCoveredTransaction", 2, 1, VALIDATOR_12)),
MSPA_MODE(new EncodableFixedInteger<>("MspaMode", 2, 0, VALIDATOR_012)),
PROCESSING_NOTICE(new EncodableFixedInteger<>("ProcessingNotice", 2, 0, VALIDATOR_012)),
SALE_OPT_OUT_NOTICE(new EncodableFixedInteger<>("SaleOptOutNotice", 2, 0, VALIDATOR_012)),
TARGETED_ADVERTISING_OPT_OUT_NOTICE(
new EncodableFixedInteger<>("TargetedAdvertisingOptOutNotice", 2, 0, VALIDATOR_012)),
SALE_OPT_OUT(new EncodableFixedInteger<>("SaleOptOut", 2, 0, VALIDATOR_012)),
TARGETED_ADVERTISING_OPT_OUT(
new EncodableFixedInteger<>("TargetedAdvertisingOptOut", 2, 0, VALIDATOR_012)),
KNOWN_CHILD_SENSITIVE_DATA_CONSENTS(
new EncodableFixedInteger<>("KnownChildSensitiveDataConsents", 2, 0, VALIDATOR_012)),
ADDITIONAL_DATA_PROCESSING_CONSENT(
new EncodableFixedInteger<>("AdditionalDataProcessingConsent", 2, 0, VALIDATOR_012)),

SENSITIVE_DATA_PROCESSING(
new EncodableFixedIntegerList<>("SensitiveDataProcessing", 2, 8, VALIDATOR_LIST_012)),
SENSITIVE_DATA_CONSENT_SEGMENT_INCLUDED(
new UnencodableBoolean<>("SensitiveDataConsentSegmentIncluded", true));

private final DataType<UsKyField, ?> type;

UsKyField(DataType<UsKyField, ?> type) {
this.type = type;
}

@Override
public DataType<UsKyField, ?> getType() {
return type;
}

public static final FieldNames<UsKyField> USKY_CORE_SEGMENT_FIELD_NAMES =
new FieldNames<>(
UsKyField.MSPA_VERSION,
UsKyField.MSPA_COVERED_TRANSACTION,
UsKyField.MSPA_MODE,
UsKyField.PROCESSING_NOTICE,
UsKyField.SALE_OPT_OUT_NOTICE,
UsKyField.TARGETED_ADVERTISING_OPT_OUT_NOTICE,
UsKyField.SALE_OPT_OUT,
UsKyField.TARGETED_ADVERTISING_OPT_OUT,
UsKyField.KNOWN_CHILD_SENSITIVE_DATA_CONSENTS,
UsKyField.ADDITIONAL_DATA_PROCESSING_CONSENT);

public static final FieldNames<UsKyField> USKY_SENSITIVE_DATA_CONSENT_SEGMENT_FIELD_NAMES =
new FieldNames<>(
UsKyField.SENSITIVE_DATA_CONSENT_SEGMENT_INCLUDED, UsKyField.SENSITIVE_DATA_PROCESSING);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.iab.gpp.encoder.field;

import com.iab.gpp.encoder.datatype.DataType;
import com.iab.gpp.encoder.datatype.EncodableBoolean;
import com.iab.gpp.encoder.datatype.EncodableFixedInteger;
import com.iab.gpp.encoder.datatype.UnencodableBoolean;
import com.iab.gpp.encoder.section.UsMd;

public enum UsMdField implements FieldKey {
MSPA_VERSION(new EncodableFixedInteger<>("MspaVersion", 6, UsMd.VERSION)),
MSPA_COVERED_TRANSACTION(
new EncodableFixedInteger<>("MspaCoveredTransaction", 2, 1, VALIDATOR_12)),
MSPA_MODE(new EncodableFixedInteger<>("MspaMode", 2, 0, VALIDATOR_012)),
PROCESSING_NOTICE(new EncodableFixedInteger<>("ProcessingNotice", 2, 0, VALIDATOR_012)),
SALE_OPT_OUT_NOTICE(new EncodableFixedInteger<>("SaleOptOutNotice", 2, 0, VALIDATOR_012)),
TARGETED_ADVERTISING_OPT_OUT_NOTICE(
new EncodableFixedInteger<>("TargetedAdvertisingOptOutNotice", 2, 0, VALIDATOR_012)),
SALE_OPT_OUT(new EncodableFixedInteger<>("SaleOptOut", 2, 0, VALIDATOR_012)),
TARGETED_ADVERTISING_OPT_OUT(
new EncodableFixedInteger<>("TargetedAdvertisingOptOut", 2, 0, VALIDATOR_012)),
ADDITIONAL_DATA_PROCESSING_CONSENT(
new EncodableFixedInteger<>("AdditionalDataProcessingConsent", 2, 0, VALIDATOR_012)),

GPC_SEGMENT_TYPE(new EncodableFixedInteger<>("GpcSegmentType", 2, 1)),
GPC_SEGMENT_INCLUDED(new UnencodableBoolean<>("GpcSegmentIncluded", true)),
GPC(new EncodableBoolean<>("Gpc", false));

private final DataType<UsMdField, ?> type;

UsMdField(DataType<UsMdField, ?> type) {
this.type = type;
}

@Override
public DataType<UsMdField, ?> getType() {
return type;
}

public static final FieldNames<UsMdField> USMD_CORE_SEGMENT_FIELD_NAMES =
new FieldNames<>(
UsMdField.MSPA_VERSION,
UsMdField.MSPA_COVERED_TRANSACTION,
UsMdField.MSPA_MODE,
UsMdField.PROCESSING_NOTICE,
UsMdField.SALE_OPT_OUT_NOTICE,
UsMdField.TARGETED_ADVERTISING_OPT_OUT_NOTICE,
UsMdField.SALE_OPT_OUT,
UsMdField.TARGETED_ADVERTISING_OPT_OUT,
UsMdField.ADDITIONAL_DATA_PROCESSING_CONSENT);

public static final FieldNames<UsMdField> USMD_GPC_SEGMENT_FIELD_NAMES =
new FieldNames<>(UsMdField.GPC_SEGMENT_TYPE, UsMdField.GPC_SEGMENT_INCLUDED, UsMdField.GPC);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.iab.gpp.encoder.field;

import com.iab.gpp.encoder.datatype.DataType;
import com.iab.gpp.encoder.datatype.EncodableFixedInteger;
import com.iab.gpp.encoder.datatype.EncodableFixedIntegerList;
import com.iab.gpp.encoder.datatype.UnencodableBoolean;
import com.iab.gpp.encoder.section.UsRi;

public enum UsRiField implements FieldKey {
MSPA_VERSION(new EncodableFixedInteger<>("MspaVersion", 6, UsRi.VERSION)),
MSPA_COVERED_TRANSACTION(
new EncodableFixedInteger<>("MspaCoveredTransaction", 2, 1, VALIDATOR_12)),
MSPA_MODE(new EncodableFixedInteger<>("MspaMode", 2, 0, VALIDATOR_012)),
PROCESSING_NOTICE(new EncodableFixedInteger<>("ProcessingNotice", 2, 0, VALIDATOR_012)),
SALE_OPT_OUT_NOTICE(new EncodableFixedInteger<>("SaleOptOutNotice", 2, 0, VALIDATOR_012)),
TARGETED_ADVERTISING_OPT_OUT_NOTICE(
new EncodableFixedInteger<>("TargetedAdvertisingOptOutNotice", 2, 0, VALIDATOR_012)),
SALE_OPT_OUT(new EncodableFixedInteger<>("SaleOptOut", 2, 0, VALIDATOR_012)),
TARGETED_ADVERTISING_OPT_OUT(
new EncodableFixedInteger<>("TargetedAdvertisingOptOut", 2, 0, VALIDATOR_012)),
KNOWN_CHILD_SENSITIVE_DATA_CONSENTS(
new EncodableFixedInteger<>("KnownChildSensitiveDataConsents", 2, 0, VALIDATOR_012)),
ADDITIONAL_DATA_PROCESSING_CONSENT(
new EncodableFixedInteger<>("AdditionalDataProcessingConsent", 2, 0, VALIDATOR_012)),

SENSITIVE_DATA_PROCESSING(
new EncodableFixedIntegerList<>("SensitiveDataProcessing", 2, 8, VALIDATOR_LIST_012)),
SENSITIVE_DATA_CONSENT_SEGMENT_INCLUDED(
new UnencodableBoolean<>("SensitiveDataConsentSegmentIncluded", true));

private final DataType<UsRiField, ?> type;

UsRiField(DataType<UsRiField, ?> type) {
this.type = type;
}

@Override
public DataType<UsRiField, ?> getType() {
return type;
}

public static final FieldNames<UsRiField> USRI_CORE_SEGMENT_FIELD_NAMES =
new FieldNames<>(
UsRiField.MSPA_VERSION,
UsRiField.MSPA_COVERED_TRANSACTION,
UsRiField.MSPA_MODE,
UsRiField.PROCESSING_NOTICE,
UsRiField.SALE_OPT_OUT_NOTICE,
UsRiField.TARGETED_ADVERTISING_OPT_OUT_NOTICE,
UsRiField.SALE_OPT_OUT,
UsRiField.TARGETED_ADVERTISING_OPT_OUT,
UsRiField.KNOWN_CHILD_SENSITIVE_DATA_CONSENTS,
UsRiField.ADDITIONAL_DATA_PROCESSING_CONSENT);

public static final FieldNames<UsRiField> USRI_SENSITIVE_DATA_CONSENT_SEGMENT_FIELD_NAMES =
new FieldNames<>(
UsRiField.SENSITIVE_DATA_CONSENT_SEGMENT_INCLUDED, UsRiField.SENSITIVE_DATA_PROCESSING);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.iab.gpp.encoder.section;

import com.iab.gpp.encoder.field.FieldKey;
import com.iab.gpp.encoder.segment.EncodableSegment;
import java.util.ArrayList;
import java.util.List;

/**
* Base class for US sections whose core segment is optionally followed by a "Sensitive Data
* Consents" segment (e.g. Indiana, Kentucky, Rhode Island). Mirrors {@link
* AbstractUsSectionWithGpc}, but the optional second segment carries sensitive data consents rather
* than GPC.
*/
public abstract class AbstractUsSectionWithSensitiveDataConsent<E extends Enum<E> & FieldKey>
extends AbstractUsSection<E> {

protected AbstractUsSectionWithSensitiveDataConsent(
EncodableSegment<E> coreSegment, EncodableSegment<E> sensitiveDataConsentSegment) {
super(coreSegment, sensitiveDataConsentSegment);
}

protected abstract E getSensitiveDataConsentSegmentIncludedKey();

@Override
protected final void doDecode(CharSequence encodedString) {
List<CharSequence> encodedSegments = SlicedCharSequence.split(encodedString, '.');
int numEncodedSegments = encodedSegments.size();

if (numEncodedSegments > 0) {
getSegment(0).decode(encodedSegments.get(0));
}

E sensitiveDataConsentSegmentIncludedKey = getSensitiveDataConsentSegmentIncludedKey();
if (numEncodedSegments > 1) {
getSegment(1).setFieldValue(sensitiveDataConsentSegmentIncludedKey, Boolean.TRUE);
getSegment(1).decode(encodedSegments.get(1));
} else {
getSegment(1).setFieldValue(sensitiveDataConsentSegmentIncludedKey, Boolean.FALSE);
}
}

@Override
protected final CharSequence doEncode() {
int size = size();
List<CharSequence> encodedSegments = new ArrayList<>(size);

encodedSegments.add(getSegment(0).encodeCharSequence());
if (size >= 2 && getSensitiveDataConsentSegmentIncluded()) {
encodedSegments.add(getSegment(1).encodeCharSequence());
}

return SlicedCharSequence.join('.', encodedSegments);
}

public Boolean getSensitiveDataConsentSegmentIncluded() {
return (Boolean) getSegment(1).getFieldValue(getSensitiveDataConsentSegmentIncludedKey());
}
}
Loading
Loading