Skip to content

Commit e68f82f

Browse files
authored
Merge pull request #475 from IABTechLab/ian-UID2-3134-add-link-id-regex-field-to-services
add link id regex field to services
2 parents 0e00fc8 + ac73b2d commit e68f82f

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

src/main/java/com/uid2/shared/model/Service.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,21 @@ public class Service {
1212
private final int serviceId;
1313
@JsonProperty("site_id")
1414
private int siteId;
15+
@JsonProperty("link_id_regex")
16+
private String linkIdRegex;
1517
private String name;
1618
private Set<Role> roles;
1719

1820
public Service(int serviceId, int siteId, String name, Set<Role> roles) {
21+
this(serviceId, siteId, name, roles, null);
22+
}
23+
24+
public Service(int serviceId, int siteId, String name, Set<Role> roles, String linkIdRegex) {
1925
this.serviceId = serviceId;
2026
this.siteId = siteId;
2127
this.name = name;
2228
this.roles = Objects.requireNonNullElseGet(roles, HashSet::new);
29+
this.linkIdRegex = linkIdRegex;
2330
}
2431

2532
public int getServiceId() {
@@ -34,6 +41,14 @@ public void setSiteId(int siteId) {
3441
this.siteId = siteId;
3542
}
3643

44+
public String getLinkIdRegex() {
45+
return linkIdRegex;
46+
}
47+
48+
public void setLinkIdRegex(String linkIdRegex) {
49+
this.linkIdRegex = linkIdRegex;
50+
}
51+
3752
public String getName() {
3853
return name;
3954
}
@@ -57,19 +72,25 @@ public String toString() {
5772
", siteId=" + siteId +
5873
", name='" + name + '\'' +
5974
", roles=" + roles +
75+
", linkIdRegex=" + linkIdRegex +
6076
'}';
6177
}
6278

6379
@Override
6480
public boolean equals(Object o) {
6581
if (this == o) return true;
6682
if (o == null || getClass() != o.getClass()) return false;
67-
Service service = (Service) o;
68-
return serviceId == service.serviceId && siteId == service.siteId && name.equals(service.name) && roles.equals(service.roles);
83+
Service other = (Service) o;
84+
85+
return serviceId == other.serviceId
86+
&& siteId == other.siteId
87+
&& Objects.equals(name, other.name)
88+
&& Objects.equals(roles, other.roles)
89+
&& Objects.equals(linkIdRegex, other.linkIdRegex);
6990
}
7091

7192
@Override
7293
public int hashCode() {
73-
return Objects.hash(serviceId, siteId, name, roles.hashCode());
94+
return Objects.hash(serviceId, siteId, name, roles.hashCode(), linkIdRegex);
7495
}
7596
}

src/main/java/com/uid2/shared/store/parser/ServiceParser.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ public ParsingResult<Map<Integer, Service>> deserialize(InputStream inputStream)
2222
int serviceId = serviceSpec.getInteger("service_id");
2323
int siteId = serviceSpec.getInteger("site_id");
2424
String name = serviceSpec.getString("name");
25+
String linkIdRegex = serviceSpec.getString("link_id_regex");
2526

2627
JsonArray rolesSpec = serviceSpec.getJsonArray("roles");
2728
HashSet<Role> roles = new HashSet<>();
2829
for (int j = 0; j < rolesSpec.size(); j++) {
2930
roles.add(Enum.valueOf(Role.class, rolesSpec.getString(j)));
3031
}
3132

32-
Service service = new Service(serviceId, siteId, name, roles);
33+
Service service = new Service(serviceId, siteId, name, roles, linkIdRegex);
3334

3435
serviceMap.put(serviceId, service);
3536
}

src/test/java/com/uid2/shared/store/RotatingServiceStoreTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ private JsonObject makeMetadata(String location) {
4040
return metadata;
4141
}
4242

43-
private Service addService(JsonArray content, int serviceId, int siteId, String name, Set<Role> roles) {
44-
Service service = new Service(serviceId, siteId, name, roles);
43+
private Service addService(JsonArray content, int serviceId, int siteId, String name, Set<Role> roles, String linkIdRegex) {
44+
Service service = new Service(serviceId, siteId, name, roles, linkIdRegex);
4545
JsonObject jo = JsonObject.mapFrom(service);
4646
content.add(jo);
4747
return service;
@@ -59,10 +59,10 @@ public void loadContentEmptyArray() throws Exception {
5959
@Test
6060
public void loadContentMultipleServices() throws Exception {
6161
JsonArray content = new JsonArray();
62-
Service s1 = addService(content, 1, 123, "Test Service 1", Set.of());
63-
Service s2 = addService(content, 2, 123, "test1", Set.of(Role.GENERATOR));
64-
Service s3 = addService(content, 3, 124, "Test Service 1", Set.of(Role.GENERATOR, Role.SHARING_PORTAL));
65-
Service s4 = addService(content, 4, 125, "test2", Set.of(Role.MAINTAINER));
62+
Service s1 = addService(content, 1, 123, "Test Service 1", Set.of(), null);
63+
Service s2 = addService(content, 2, 123, "test1", Set.of(Role.GENERATOR), "regexA");
64+
Service s3 = addService(content, 3, 124, "Test Service 1", Set.of(Role.GENERATOR, Role.SHARING_PORTAL), null);
65+
Service s4 = addService(content, 4, 125, "test2", Set.of(Role.MAINTAINER), "regexB");
6666
when(cloudStorage.download("locationPath")).thenReturn(makeInputStream(content));
6767

6868
final long count = serviceStore.loadContent(makeMetadata("locationPath"));

0 commit comments

Comments
 (0)