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(UsIn::new);
constructors.add(UsMd::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 UsIn getUsInSection() {
return (UsIn) getSection(UsIn.ID);
}

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

public UsMd getUsMdSection() {
return (UsMd) getSection(UsMd.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,62 @@
package com.iab.gpp.encoder.field;

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

public enum UsInField implements FieldKey {
SECTION_ID(new EncodableFixedInteger<>("SectionID", 6, UsIn.ID)),
VERSION(new EncodableFixedInteger<>("Version", 6, UsIn.VERSION)),
SUB_SECTIONS(new EncodableFibonacciIntegerRange<>("SubSections")),

MSPA_VERSION(new EncodableFixedInteger<>("MspaVersion", 6, 0)),
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));

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_HEADER_SEGMENT_FIELD_NAMES =
new FieldNames<>(UsInField.SECTION_ID, UsInField.VERSION, UsInField.SUB_SECTIONS);

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_CONSENTS_SEGMENT_FIELD_NAMES =
new FieldNames<>(UsInField.SENSITIVE_DATA_PROCESSING);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.iab.gpp.encoder.field;

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

public enum UsKyField implements FieldKey {
SECTION_ID(new EncodableFixedInteger<>("SectionID", 6, UsKy.ID)),
VERSION(new EncodableFixedInteger<>("Version", 6, UsKy.VERSION)),
SUB_SECTIONS(new EncodableFibonacciIntegerRange<>("SubSections")),

MSPA_VERSION(new EncodableFixedInteger<>("MspaVersion", 6, 0)),
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));

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_HEADER_SEGMENT_FIELD_NAMES =
new FieldNames<>(UsKyField.SECTION_ID, UsKyField.VERSION, UsKyField.SUB_SECTIONS);

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_CONSENTS_SEGMENT_FIELD_NAMES =
new FieldNames<>(UsKyField.SENSITIVE_DATA_PROCESSING);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
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.EncodableFibonacciIntegerRange;
import com.iab.gpp.encoder.datatype.EncodableFixedInteger;
import com.iab.gpp.encoder.section.UsMd;

public enum UsMdField implements FieldKey {
SECTION_ID(new EncodableFixedInteger<>("SectionID", 6, UsMd.ID)),
VERSION(new EncodableFixedInteger<>("Version", 6, UsMd.VERSION)),
SUB_SECTIONS(new EncodableFibonacciIntegerRange<>("SubSections")),

MSPA_VERSION(new EncodableFixedInteger<>("MspaVersion", 6, 0)),
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_SUBSECTION_TYPE(new EncodableFixedInteger<>("GpcSubSectionType", 2, 1)),
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_HEADER_SEGMENT_FIELD_NAMES =
new FieldNames<>(UsMdField.SECTION_ID, UsMdField.VERSION, UsMdField.SUB_SECTIONS);

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_SUBSECTION_TYPE, UsMdField.GPC);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.iab.gpp.encoder.field;

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

public enum UsRiField implements FieldKey {
SECTION_ID(new EncodableFixedInteger<>("SectionID", 6, UsRi.ID)),
VERSION(new EncodableFixedInteger<>("Version", 6, UsRi.VERSION)),
SUB_SECTIONS(new EncodableFibonacciIntegerRange<>("SubSections")),

MSPA_VERSION(new EncodableFixedInteger<>("MspaVersion", 6, 0)),
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));

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_HEADER_SEGMENT_FIELD_NAMES =
new FieldNames<>(UsRiField.SECTION_ID, UsRiField.VERSION, UsRiField.SUB_SECTIONS);

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_CONSENTS_SEGMENT_FIELD_NAMES =
new FieldNames<>(UsRiField.SENSITIVE_DATA_PROCESSING);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.iab.gpp.encoder.section;

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

public abstract class AbstractUsSectionWithHeader<E extends Enum<E> & FieldKey>
extends AbstractUsSection<E> {

@SafeVarargs
protected AbstractUsSectionWithHeader(EncodableSegment<E>... segments) {
super(segments);
}

protected abstract E getSubSectionsKey();

public IntegerSet getSubSections() {
return (IntegerSet) getSegment(0).getFieldValue(getSubSectionsKey());
}

@Override
protected final void doDecode(CharSequence encodedString) {
List<CharSequence> encodedSegments = SlicedCharSequence.split(encodedString, '.');
getSegment(0).decode(encodedSegments.get(0));
IntegerSet subSections = getSubSections();
subSections.addInt(0);
PrimitiveIterator.OfInt it = subSections.iterator();
while (it.hasNext()) {
int subSectionIndex = 1 + it.nextInt();
getSegment(subSectionIndex).decode(encodedSegments.get(subSectionIndex));
}
}

@Override
protected final CharSequence doEncode() {
int size = size();
List<CharSequence> encodedSegments = new ArrayList<>(size);
IntegerSet subSections = getSubSections();
for (int i = 2; i < size(); i++) {
EncodableSegment<E> segment = getSegment(i);
if (segment.shouldEncode()) {
subSections.add(i - 1);
}
}
encodedSegments.add(getSegment(0).encodeCharSequence());
encodedSegments.add(getSegment(1).encodeCharSequence());
PrimitiveIterator.OfInt it = subSections.iterator();
while (it.hasNext()) {
int subSectionIndex = 1 + it.nextInt();
encodedSegments.add(getSegment(subSectionIndex).encodeCharSequence());
}
return SlicedCharSequence.join('.', encodedSegments);
}
}
Loading
Loading