Skip to content
Closed
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
13 changes: 13 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 @@ -101,6 +101,9 @@ public void setFieldValue(String sectionName, String fieldName, Object value) {
} else if (sectionName.equals(UsMn.NAME)) {
section = new UsMn();
this.sections.put(UsMn.NAME, section);
} else if (sectionName.equals(UsRi.NAME)) {
section = new UsRi();
this.sections.put(UsRi.NAME, section);
}
} else {
section = this.sections.get(sectionName);
Expand Down Expand Up @@ -302,6 +305,10 @@ public UsMn getUsMnSection() {
return (UsMn) getSection(UsMn.NAME);
}

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

public List<Integer> getSectionIds() {
if (!this.decoded) {
this.sections = this.decodeModel(this.encodedString);
Expand Down Expand Up @@ -416,6 +423,9 @@ protected Map<String, EncodableSection> decodeModel(String str) {
} else if (sectionIds.get(i).equals(UsMn.ID)) {
UsMn section = new UsMn(encodedSections[i + 1]);
sections.put(UsMn.NAME, section);
} else if (sectionIds.get(i).equals(UsRi.ID)) {
UsRi section = new UsRi(encodedSections[i + 1]);
sections.put(UsRi.NAME, section);
}
}
}
Expand Down Expand Up @@ -529,6 +539,9 @@ public void decodeSection(String sectionName, String encodedString) {
}else if (sectionName.equals(UsMn.NAME)) {
section = new UsMn();
this.sections.put(UsMn.NAME, section);
}else if (sectionName.equals(UsRi.NAME)) {
section = new UsRi();
this.sections.put(UsRi.NAME, section);
}
} else {
section = this.sections.get(sectionName);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.iab.gpp.encoder.field;

import java.util.Arrays;
import java.util.List;

public class UsRiField {

public static String MSPA_VERSION = "MspaVersion";
public static String MSPA_COVERED_TRANSACTION = "MspaCoveredTransaction";
public static String MSPA_MODE = "MspaMode";
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 KNOWN_CHILD_SENSITIVE_DATA_CONSENTS = "KnownChildSensitiveDataConsents";
public static String ADDITIONAL_DATA_PROCESSING_CONSENT = "AdditionalDataProcessingConsent";
public static String SENSITIVE_DATA_PROCESSING = "SensitiveDataProcessing";

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> USRI_CORE_SEGMENT_FIELD_NAMES = Arrays.asList(new String[] {
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,
UsRiField.SENSITIVE_DATA_PROCESSING
});
//@formatter:on

//@formatter:off
public static List<String> USRI_GPC_SEGMENT_FIELD_NAMES = Arrays.asList(new String[] {
UsRiField.GPC_SEGMENT_TYPE,
UsRiField.GPC
});
//@formatter:on
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class Sections {
SECTION_ID_NAME_MAP.put(UsNj.ID, UsNj.NAME);
SECTION_ID_NAME_MAP.put(UsTn.ID, UsTn.NAME);
SECTION_ID_NAME_MAP.put(UsMn.ID, UsMn.NAME);
SECTION_ID_NAME_MAP.put(UsRi.ID, UsRi.NAME);

SECTION_ORDER = new ArrayList<Integer>(SECTION_ID_NAME_MAP.keySet()).stream().sorted()
.map(id -> SECTION_ID_NAME_MAP.get(id)).collect(Collectors.toList());
Expand Down
140 changes: 140 additions & 0 deletions iabgpp-encoder/src/main/java/com/iab/gpp/encoder/section/UsRi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package com.iab.gpp.encoder.section;

import com.iab.gpp.encoder.field.UsRiField;
import com.iab.gpp.encoder.segment.*;

import java.util.ArrayList;
import java.util.List;

public class UsRi extends AbstractLazilyEncodableSection {

public static int ID = 27;
public static int VERSION = 1;
public static String NAME = "usri";

public UsRi() {
super();
}

public UsRi(String encodedString) {
super();
decode(encodedString);
}

@Override
public int getId() {
return UsRi.ID;
}

@Override
public String getName() {
return UsRi.NAME;
}

@Override
public int getVersion() {
return UsRi.VERSION;
}

@Override
protected List<EncodableSegment> initializeSegments() {
List<EncodableSegment> segments = new ArrayList<>();
segments.add(new UsRiCoreSegment());
segments.add(new UsRiGpcSegment());
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(UsRiField.GPC_SEGMENT_INCLUDED, true);
segments.get(1).decode(encodedSegments[1]);
} else {
segments.get(1).setFieldValue(UsRiField.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(UsRiField.GPC_SEGMENT_INCLUDED).equals(true)) {
encodedSegments.add(segments.get(1).encode());
}
}

return String.join(".", encodedSegments);
}


public Integer getMspaVersion() {
return (Integer) this.getFieldValue(UsRiField.MSPA_VERSION);
}

public Integer getMspaCoveredTransaction() {
return (Integer) this.getFieldValue(UsRiField.MSPA_COVERED_TRANSACTION);
}

public Integer getMspaMode() {
return (Integer) this.getFieldValue(UsRiField.MSPA_MODE);
}

public Integer getProcessingNotice() {
return (Integer) this.getFieldValue(UsRiField.PROCESSING_NOTICE);
}

public Integer getSaleOptOutNotice() {
return (Integer) this.getFieldValue(UsRiField.SALE_OPT_OUT_NOTICE);
}

public Integer getTargetedAdvertisingOptOutNotice() {
return (Integer) this.getFieldValue(UsRiField.TARGETED_ADVERTISING_OPT_OUT_NOTICE);
}

public Integer getSaleOptOut() {
return (Integer) this.getFieldValue(UsRiField.SALE_OPT_OUT);
}

public Integer getTargetedAdvertisingOptOut() {
return (Integer) this.getFieldValue(UsRiField.TARGETED_ADVERTISING_OPT_OUT);
}

public Integer getKnownChildSensitiveDataConsents() {
return (Integer) this.getFieldValue(UsRiField.KNOWN_CHILD_SENSITIVE_DATA_CONSENTS);
}

public Integer getAdditionalDataProcessingConsent() {
return (Integer) this.getFieldValue(UsRiField.ADDITIONAL_DATA_PROCESSING_CONSENT);
}

@SuppressWarnings("unchecked")
public List<Integer> getSensitiveDataProcessing() {
return (List<Integer>) this.getFieldValue(UsRiField.SENSITIVE_DATA_PROCESSING);
}

public Integer getGpcSegmentType() {
return (Integer) this.getFieldValue(UsRiField.GPC_SEGMENT_TYPE);
}

public Boolean getGpcSegmentIncluded() {
return (Boolean) this.getFieldValue(UsRiField.GPC_SEGMENT_INCLUDED);
}

public Boolean getGpc() {
return (Boolean) this.getFieldValue(UsRiField.GPC);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
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.UsRiField;
import com.iab.gpp.encoder.section.UsRi;

import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

public class UsRiCoreSegment extends AbstractLazilyEncodableSegment<EncodableBitStringFields> {

private AbstractBase64UrlEncoder base64UrlEncoder = CompressedBase64UrlEncoder.getInstance();
private BitStringEncoder bitStringEncoder = BitStringEncoder.getInstance();

public UsRiCoreSegment() {
super();
}

public UsRiCoreSegment(String encodedString) {
super();
this.decode(encodedString);
}

@Override
public List<String> getFieldNames() {
return UsRiField.USRI_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(UsRiField.MSPA_VERSION, new EncodableFixedInteger(6, UsRi.VERSION));
fields.put(UsRiField.MSPA_COVERED_TRANSACTION,
new EncodableFixedInteger(2, 1).withValidator(nonNullableBooleanAsTwoBitIntegerValidator));
fields.put(UsRiField.MSPA_MODE,
new EncodableFixedInteger(2, 0).withValidator(nullableBooleanAsTwoBitIntegerValidator));
fields.put(UsRiField.PROCESSING_NOTICE,
new EncodableFixedInteger(2, 0).withValidator(nullableBooleanAsTwoBitIntegerValidator));
fields.put(UsRiField.SALE_OPT_OUT_NOTICE,
new EncodableFixedInteger(2, 0).withValidator(nullableBooleanAsTwoBitIntegerValidator));
fields.put(UsRiField.TARGETED_ADVERTISING_OPT_OUT_NOTICE,
new EncodableFixedInteger(2, 0).withValidator(nullableBooleanAsTwoBitIntegerValidator));
fields.put(UsRiField.SALE_OPT_OUT,
new EncodableFixedInteger(2, 0).withValidator(nullableBooleanAsTwoBitIntegerValidator));
fields.put(UsRiField.TARGETED_ADVERTISING_OPT_OUT,
new EncodableFixedInteger(2, 0).withValidator(nullableBooleanAsTwoBitIntegerValidator));
fields.put(UsRiField.KNOWN_CHILD_SENSITIVE_DATA_CONSENTS,
new EncodableFixedInteger(2, 0).withValidator(nullableBooleanAsTwoBitIntegerValidator));
fields.put(UsRiField.ADDITIONAL_DATA_PROCESSING_CONSENT,
new EncodableFixedInteger(2, 0).withValidator(nullableBooleanAsTwoBitIntegerValidator));
fields.put(UsRiField.SENSITIVE_DATA_PROCESSING,
new EncodableFixedIntegerList(2, Arrays.asList(0, 0, 0, 0, 0, 0, 0, 0))
.withValidator(nullableBooleanAsTwoBitIntegerListValidator));
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 UsRiCoreSegment '" + encodedString + "'", e);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
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.EncodableBoolean;
import com.iab.gpp.encoder.datatype.EncodableFixedInteger;
import com.iab.gpp.encoder.error.DecodingException;
import com.iab.gpp.encoder.field.EncodableBitStringFields;
import com.iab.gpp.encoder.field.UsRiField;

import java.util.List;

public class UsRiGpcSegment extends AbstractLazilyEncodableSegment<EncodableBitStringFields> {

private AbstractBase64UrlEncoder base64UrlEncoder = CompressedBase64UrlEncoder.getInstance();
private BitStringEncoder bitStringEncoder = BitStringEncoder.getInstance();

public UsRiGpcSegment() {
super();
}

public UsRiGpcSegment(String encodedString) {
super();
this.decode(encodedString);
}

@Override
public List<String> getFieldNames() {
return UsRiField.USRI_GPC_SEGMENT_FIELD_NAMES;
}

@Override
protected EncodableBitStringFields initializeFields() {
EncodableBitStringFields fields = new EncodableBitStringFields();
fields.put(UsRiField.GPC_SEGMENT_TYPE, new EncodableFixedInteger(2, 1));
fields.put(UsRiField.GPC_SEGMENT_INCLUDED, new EncodableBoolean(true));
fields.put(UsRiField.GPC, new EncodableBoolean(false));
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 UsRiGpcSegment '" + encodedString + "'", e);
}
}
}
Loading
Loading