Skip to content
Merged
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
138 changes: 111 additions & 27 deletions iabgpp-encoder/src/main/java/com/iab/gpp/encoder/GppModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@
import com.iab.gpp.encoder.section.UsCa;
import com.iab.gpp.encoder.section.UsCo;
import com.iab.gpp.encoder.section.UsCt;
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.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.UsTn;
import com.iab.gpp.encoder.section.UsTx;
import com.iab.gpp.encoder.section.UsUt;
import com.iab.gpp.encoder.section.UsVa;
Expand All @@ -31,10 +37,10 @@ public class GppModel {
private Map<String, EncodableSection> sections = new HashMap<>();

private String encodedString;

private boolean dirty = false;
private boolean decoded = true;

public GppModel() {

}
Expand All @@ -53,7 +59,7 @@ public void setFieldValue(String sectionName, String fieldName, Object value) {
this.dirty = false;
this.decoded = true;
}

EncodableSection section = null;
if (!this.sections.containsKey(sectionName)) {
if (sectionName.equals(TcfCaV1.NAME)) {
Expand Down Expand Up @@ -95,6 +101,24 @@ public void setFieldValue(String sectionName, String fieldName, Object value) {
} else if (sectionName.equals(UsTx.NAME)) {
section = new UsTx();
this.sections.put(UsTx.NAME, section);
} else if (sectionName.equals(UsDe.NAME)) {
section = new UsDe();
this.sections.put(UsDe.NAME, section);
} else if (sectionName.equals(UsIa.NAME)) {
section = new UsIa();
this.sections.put(UsIa.NAME, section);
} else if (sectionName.equals(UsNe.NAME)) {
section = new UsNe();
this.sections.put(UsNe.NAME, section);
} else if (sectionName.equals(UsNh.NAME)) {
section = new UsNh();
this.sections.put(UsNh.NAME, section);
} else if (sectionName.equals(UsNj.NAME)) {
section = new UsNj();
this.sections.put(UsNj.NAME, section);
} else if (sectionName.equals(UsTn.NAME)) {
section = new UsTn();
this.sections.put(UsTn.NAME, section);
}
} else {
section = this.sections.get(sectionName);
Expand All @@ -118,7 +142,7 @@ public Object getFieldValue(String sectionName, String fieldName) {
this.dirty = false;
this.decoded = true;
}

if (this.sections.containsKey(sectionName)) {
return this.sections.get(sectionName).getFieldValue(fieldName);
} else {
Expand All @@ -136,7 +160,7 @@ public boolean hasField(String sectionName, String fieldName) {
this.dirty = false;
this.decoded = true;
}

if (this.sections.containsKey(sectionName)) {
return this.sections.get(sectionName).hasField(fieldName);
} else {
Expand All @@ -154,7 +178,7 @@ public boolean hasSection(String sectionName) {
this.dirty = false;
this.decoded = true;
}

return this.sections.containsKey(sectionName);
}

Expand All @@ -164,7 +188,7 @@ public HeaderV1 getHeader() {
this.dirty = false;
this.decoded = true;
}

HeaderV1 header = new HeaderV1();
try {
header.setFieldValue("SectionIds", this.getSectionIds());
Expand All @@ -184,7 +208,7 @@ public EncodableSection getSection(String sectionName) {
this.dirty = false;
this.decoded = true;
}

if (this.sections.containsKey(sectionName)) {
return this.sections.get(sectionName);
} else {
Expand All @@ -202,7 +226,7 @@ public void deleteSection(String sectionName) {
this.dirty = false;
this.decoded = true;
}

if (this.sections.containsKey(sectionName)) {
this.sections.remove(sectionName);
this.dirty = true;
Expand Down Expand Up @@ -251,30 +275,54 @@ public UsUt getUsUtSection() {
public UsCt getUsCtSection() {
return (UsCt) getSection(UsCt.NAME);
}

public UsFl getUsFlSection() {
return (UsFl) getSection(UsFl.NAME);
}

public UsMt getUsMtSection() {
return (UsMt) getSection(UsMt.NAME);
}

public UsOr getUsOrSection() {
return (UsOr) getSection(UsOr.NAME);
}

public UsTx getUsTxSection() {
return (UsTx) getSection(UsTx.NAME);
}


public UsDe getUsDeSection() {
return (UsDe) getSection(UsDe.NAME);
}

public UsIa getUsIaSection() {
return (UsIa) getSection(UsIa.NAME);
}

public UsNe getUsNeSection() {
return (UsNe) getSection(UsNe.NAME);
}

public UsNh getUsNhSection() {
return (UsNh) getSection(UsNh.NAME);
}

public UsNj getUsNjSection() {
return (UsNj) getSection(UsNj.NAME);
}

public UsTn getUsTnSection() {
return (UsTn) getSection(UsTn.NAME);
}

public List<Integer> getSectionIds() {
if (!this.decoded) {
this.sections = this.decodeModel(this.encodedString);
this.dirty = false;
this.decoded = true;
}

List<Integer> sectionIds = new ArrayList<>();
for (int i = 0; i < Sections.SECTION_ORDER.size(); i++) {
String sectionName = Sections.SECTION_ORDER.get(i);
Expand Down Expand Up @@ -311,14 +359,14 @@ protected String encodeModel(Map<String, EncodableSection> sections) {
}

protected Map<String, EncodableSection> decodeModel(String str) {
if(str == null || str.isEmpty() || str.startsWith("D")) {
if (str == null || str.isEmpty() || str.startsWith("D")) {
Map<String, EncodableSection> sections = new HashMap<>();
if(str != null && !str.isEmpty()) {

if (str != null && !str.isEmpty()) {
String[] encodedSections = str.split("~");
HeaderV1 header = new HeaderV1(encodedSections[0]);
sections.put(HeaderV1.NAME, header);

@SuppressWarnings("unchecked")
List<Integer> sectionIds = (List<Integer>) header.getFieldValue("SectionIds");
for (int i = 0; i < sectionIds.size(); i++) {
Expand Down Expand Up @@ -361,12 +409,30 @@ protected Map<String, EncodableSection> decodeModel(String str) {
} else if (sectionIds.get(i).equals(UsTx.ID)) {
UsTx section = new UsTx(encodedSections[i + 1]);
sections.put(UsTx.NAME, section);
} else if (sectionIds.get(i).equals(UsDe.ID)) {
UsDe section = new UsDe(encodedSections[i + 1]);
sections.put(UsDe.NAME, section);
} else if (sectionIds.get(i).equals(UsIa.ID)) {
UsIa section = new UsIa(encodedSections[i + 1]);
sections.put(UsIa.NAME, section);
} else if (sectionIds.get(i).equals(UsNe.ID)) {
UsNe section = new UsNe(encodedSections[i + 1]);
sections.put(UsNe.NAME, section);
} else if (sectionIds.get(i).equals(UsNh.ID)) {
UsNh section = new UsNh(encodedSections[i + 1]);
sections.put(UsNh.NAME, section);
} else if (sectionIds.get(i).equals(UsNj.ID)) {
UsNj section = new UsNj(encodedSections[i + 1]);
sections.put(UsNj.NAME, section);
} else if (sectionIds.get(i).equals(UsTn.ID)) {
UsTn section = new UsTn(encodedSections[i + 1]);
sections.put(UsTn.NAME, section);
}
}
}

return sections;
} else if(str.startsWith("C")) {
} else if (str.startsWith("C")) {
// old tcfeu only string
Map<String, EncodableSection> sections = new HashMap<>();

Expand All @@ -393,7 +459,7 @@ public String encodeSection(String sectionName) {
this.dirty = false;
this.decoded = true;
}

if (this.sections.containsKey(sectionName)) {
return this.sections.get(sectionName).encode();
} else {
Expand Down Expand Up @@ -447,6 +513,24 @@ public void decodeSection(String sectionName, String encodedString) {
} else if (sectionName.equals(UsTx.NAME)) {
section = new UsTx();
this.sections.put(UsTx.NAME, section);
}else if (sectionName.equals(UsDe.NAME)) {
section = new UsDe();
this.sections.put(UsDe.NAME, section);
}else if (sectionName.equals(UsIa.NAME)) {
section = new UsIa();
this.sections.put(UsIa.NAME, section);
}else if (sectionName.equals(UsNe.NAME)) {
section = new UsNe();
this.sections.put(UsNe.NAME, section);
}else if (sectionName.equals(UsNh.NAME)) {
section = new UsNh();
this.sections.put(UsNh.NAME, section);
}else if (sectionName.equals(UsNj.NAME)) {
section = new UsNj();
this.sections.put(UsNj.NAME, section);
}else if (sectionName.equals(UsTn.NAME)) {
section = new UsTn();
this.sections.put(UsTn.NAME, section);
}
} else {
section = this.sections.get(sectionName);
Expand All @@ -456,7 +540,7 @@ public void decodeSection(String sectionName, String encodedString) {
section.decode(encodedString);
}
}

public String encode() {
if (this.encodedString == null || this.encodedString.isEmpty() || this.dirty) {
this.encodedString = encodeModel(this.sections);
Expand All @@ -466,12 +550,12 @@ public String encode() {

return this.encodedString;
}

public void decode(String encodedString) {
this.encodedString = encodedString;
this.dirty = false;
this.decoded = false;
}
}


}
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 UsDeField {

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> USDE_CORE_SEGMENT_FIELD_NAMES = Arrays.asList(new String[] {
UsDeField.VERSION,
UsDeField.PROCESSING_NOTICE,
UsDeField.SALE_OPT_OUT_NOTICE,
UsDeField.TARGETED_ADVERTISING_OPT_OUT_NOTICE,
UsDeField.SALE_OPT_OUT,
UsDeField.TARGETED_ADVERTISING_OPT_OUT,
UsDeField.SENSITIVE_DATA_PROCESSING,
UsDeField.KNOWN_CHILD_SENSITIVE_DATA_CONSENTS,
UsDeField.ADDITIONAL_DATA_PROCESSING_CONSENT,
UsDeField.MSPA_COVERED_TRANSACTION,
UsDeField.MSPA_OPT_OUT_OPTION_MODE,
UsDeField.MSPA_SERVICE_PROVIDER_MODE
});
//@formatter:on

//@formatter:off
public static List<String> USDE_GPC_SEGMENT_FIELD_NAMES = Arrays.asList(new String[] {
UsDeField.GPC_SEGMENT_TYPE,
UsDeField.GPC
});
//@formatter:on
}
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 UsIaField {

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 SENSITIVE_DATA_OPT_OUT_NOTICE = "SensitiveDataOptOutNotice";
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 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> USIA_CORE_SEGMENT_FIELD_NAMES = Arrays.asList(new String[] {
UsIaField.VERSION,
UsIaField.PROCESSING_NOTICE,
UsIaField.SALE_OPT_OUT_NOTICE,
UsIaField.TARGETED_ADVERTISING_OPT_OUT_NOTICE,
UsIaField.SENSITIVE_DATA_OPT_OUT_NOTICE,
UsIaField.SALE_OPT_OUT,
UsIaField.TARGETED_ADVERTISING_OPT_OUT,
UsIaField.SENSITIVE_DATA_PROCESSING,
UsIaField.KNOWN_CHILD_SENSITIVE_DATA_CONSENTS,
UsIaField.MSPA_COVERED_TRANSACTION,
UsIaField.MSPA_OPT_OUT_OPTION_MODE,
UsIaField.MSPA_SERVICE_PROVIDER_MODE
});
//@formatter:on

//@formatter:off
public static List<String> USIA_GPC_SEGMENT_FIELD_NAMES = Arrays.asList(new String[] {
UsIaField.GPC_SEGMENT_TYPE,
UsIaField.GPC
});
//@formatter:on
}
Loading