Skip to content

Commit 52d6372

Browse files
authored
Merge pull request #494 from IABTechLab/ian-UID2-2084-add-disable-service-service-link
add disabled field to services and service links
2 parents 7fdbb13 + 20a7bc4 commit 52d6372

File tree

5 files changed

+106
-23
lines changed

5 files changed

+106
-23
lines changed

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,23 @@ public class Service {
1616
private String linkIdRegex;
1717
private String name;
1818
private Set<Role> roles;
19+
private boolean disabled;
1920

2021
public Service(int serviceId, int siteId, String name, Set<Role> roles) {
21-
this(serviceId, siteId, name, roles, null);
22+
this(serviceId, siteId, name, roles, null, false);
2223
}
2324

2425
public Service(int serviceId, int siteId, String name, Set<Role> roles, String linkIdRegex) {
26+
this(serviceId, siteId, name, roles, linkIdRegex, false);
27+
}
28+
29+
public Service(int serviceId, int siteId, String name, Set<Role> roles, String linkIdRegex, boolean disabled) {
2530
this.serviceId = serviceId;
2631
this.siteId = siteId;
2732
this.name = name;
2833
this.roles = Objects.requireNonNullElseGet(roles, HashSet::new);
2934
this.linkIdRegex = linkIdRegex;
35+
this.disabled = disabled;
3036
}
3137

3238
public int getServiceId() {
@@ -65,6 +71,14 @@ public void setRoles(Set<Role> roles) {
6571
this.roles = Objects.requireNonNullElseGet(roles, HashSet::new);
6672
}
6773

74+
public boolean isDisabled() {
75+
return disabled;
76+
}
77+
78+
public void setDisabled(boolean disabled) {
79+
this.disabled = disabled;
80+
}
81+
6882
@Override
6983
public String toString() {
7084
return "Service{" +
@@ -73,6 +87,7 @@ public String toString() {
7387
", name='" + name + '\'' +
7488
", roles=" + roles +
7589
", linkIdRegex=" + linkIdRegex +
90+
", disabled=" + disabled +
7691
'}';
7792
}
7893

@@ -84,13 +99,14 @@ public boolean equals(Object o) {
8499

85100
return serviceId == other.serviceId
86101
&& siteId == other.siteId
102+
&& disabled == other.disabled
87103
&& Objects.equals(name, other.name)
88104
&& Objects.equals(roles, other.roles)
89105
&& Objects.equals(linkIdRegex, other.linkIdRegex);
90106
}
91107

92108
@Override
93109
public int hashCode() {
94-
return Objects.hash(serviceId, siteId, name, roles.hashCode(), linkIdRegex);
110+
return Objects.hash(serviceId, siteId, name, roles.hashCode(), linkIdRegex, disabled);
95111
}
96112
}

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,26 @@ public class ServiceLink {
2020
private String linkId;
2121
private String name;
2222
private Set<Role> roles;
23+
private boolean disabled;
24+
25+
public ServiceLink(String linkId, int serviceId, int siteId, String name, Set<Role> roles) {
26+
this(linkId, serviceId, siteId, name, roles, false);
27+
}
2328

2429
@JsonCreator
2530
public ServiceLink(
2631
@JsonProperty("link_id") String linkId,
2732
@JsonProperty("service_id") int serviceId,
2833
@JsonProperty("site_id") int siteId,
2934
@JsonProperty("name") String name,
30-
@JsonProperty("roles") Set<Role> roles) {
35+
@JsonProperty("roles") Set<Role> roles,
36+
@JsonProperty("disabled") boolean disabled) {
3137
this.linkId = linkId;
3238
this.serviceId = serviceId;
3339
this.siteId = siteId;
3440
this.name = name;
3541
this.roles = Objects.requireNonNullElseGet(roles, HashSet::new);
42+
this.disabled = disabled;
3643
}
3744

3845
public String getLinkId() {
@@ -67,6 +74,14 @@ public void setRoles(Set<Role> roles) {
6774
this.roles = Objects.requireNonNullElseGet(roles, HashSet::new);
6875
}
6976

77+
public boolean isDisabled() {
78+
return disabled;
79+
}
80+
81+
public void setDisabled(boolean disabled) {
82+
this.disabled = disabled;
83+
}
84+
7085
@Override
7186
public String toString() {
7287
return "ServiceLink{" +
@@ -75,6 +90,7 @@ public String toString() {
7590
", linkId='" + linkId + '\'' +
7691
", name='" + name + '\'' +
7792
", roles=" + roles +
93+
", disabled=" + disabled +
7894
'}';
7995
}
8096

@@ -83,12 +99,16 @@ public boolean equals(Object o) {
8399
if (this == o) return true;
84100
if (o == null || getClass() != o.getClass()) return false;
85101
ServiceLink serviceLink = (ServiceLink) o;
86-
return siteId == serviceLink.siteId && serviceId == serviceLink.serviceId && linkId.equals(serviceLink.linkId)
87-
&& name.equals(serviceLink.name) && roles.equals(serviceLink.roles);
102+
return siteId == serviceLink.siteId
103+
&& serviceId == serviceLink.serviceId
104+
&& linkId.equals(serviceLink.linkId)
105+
&& name.equals(serviceLink.name)
106+
&& roles.equals(serviceLink.roles)
107+
&& disabled == serviceLink.disabled;
88108
}
89109

90110
@Override
91111
public int hashCode() {
92-
return Objects.hash(siteId, serviceId, linkId, name, roles.hashCode());
112+
return Objects.hash(siteId, serviceId, linkId, name, roles.hashCode(), disabled);
93113
}
94114
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ public ParsingResult<Map<Integer, Service>> deserialize(InputStream inputStream)
2323
int siteId = serviceSpec.getInteger("site_id");
2424
String name = serviceSpec.getString("name");
2525
String linkIdRegex = serviceSpec.getString("link_id_regex");
26+
boolean disabled = serviceSpec.getBoolean("disabled", false);
2627

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

33-
Service service = new Service(serviceId, siteId, name, roles, linkIdRegex);
34+
Service service = new Service(serviceId, siteId, name, roles, linkIdRegex, disabled);
3435

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

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

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,32 @@ private JsonObject makeMetadata(String location) {
4141
return metadata;
4242
}
4343

44-
private ServiceLink addServiceLink(JsonArray content, String linkId, int serviceId, int siteId, String name, Set<Role> roles) {
45-
ServiceLink link = new ServiceLink(linkId, serviceId, siteId, name, roles);
44+
private ServiceLink addServiceLink(JsonArray content, String linkId, int serviceId, int siteId, String name, Set<Role> roles, boolean disabled) {
45+
ServiceLink link = new ServiceLink(linkId, serviceId, siteId, name, roles, disabled);
4646
JsonObject jo = JsonObject.mapFrom(link);
4747
content.add(jo);
4848
return link;
4949
}
5050

51+
@Test
52+
public void allConstructors(){
53+
ServiceLink link = new ServiceLink("abc123", 1, 123, "Test Service 1", Set.of());
54+
assertEquals("abc123", link.getLinkId());
55+
assertEquals(1, link.getServiceId());
56+
assertEquals(123, link.getSiteId());
57+
assertEquals("Test Service 1", link.getName());
58+
assertEquals(Set.of(), link.getRoles());
59+
assertEquals(false, link.isDisabled());
60+
61+
link = new ServiceLink("abc123", 1, 123, "Test Service 1", Set.of(), true);
62+
assertEquals("abc123", link.getLinkId());
63+
assertEquals(1, link.getServiceId());
64+
assertEquals(123, link.getSiteId());
65+
assertEquals("Test Service 1", link.getName());
66+
assertEquals(Set.of(), link.getRoles());
67+
assertEquals(true, link.isDisabled());
68+
}
69+
5170
@Test
5271
public void loadContent_emptyArray_loadsZeroServiceLinks() throws Exception {
5372
JsonArray content = new JsonArray();
@@ -62,10 +81,10 @@ public void loadContent_emptyArray_loadsZeroServiceLinks() throws Exception {
6281
@Test
6382
public void loadContent_multipleServiceLinksStored_loadsAllServiceLinks() throws Exception {
6483
JsonArray content = new JsonArray();
65-
ServiceLink l1 = addServiceLink(content, "abc123", 1, 123, "Test Service 1", Set.of());
66-
ServiceLink l2 = addServiceLink(content, "abc123", 2, 123, "test1", Set.of(Role.MAPPER));
67-
ServiceLink l3 = addServiceLink(content, "ghi789", 1, 123, "Test Service 1", Set.of(Role.MAPPER, Role.SHARER));
68-
ServiceLink l4 = addServiceLink(content, "jkl1011", 3, 124, "test2", null);
84+
ServiceLink l1 = addServiceLink(content, "abc123", 1, 123, "Test Service 1", Set.of(), false);
85+
ServiceLink l2 = addServiceLink(content, "abc123", 2, 123, "test1", Set.of(Role.MAPPER), true);
86+
ServiceLink l3 = addServiceLink(content, "ghi789", 1, 123, "Test Service 1", Set.of(Role.MAPPER, Role.SHARER), false);
87+
ServiceLink l4 = addServiceLink(content, "jkl1011", 3, 124, "test2", null, true);
6988
when(cloudStorage.download("locationPath")).thenReturn(makeInputStream(content));
7089

7190
final long count = serviceLinkStore.loadContent(makeMetadata("locationPath"));
@@ -77,9 +96,9 @@ public void loadContent_multipleServiceLinksStored_loadsAllServiceLinks() throws
7796
@Test
7897
public void getServiceLink_multipleServiceLinksStored_findsCorrectServiceLink() throws Exception {
7998
JsonArray content = new JsonArray();
80-
ServiceLink l1 = addServiceLink(content, "abc123", 1, 123, "Test Service 1", Set.of());
81-
ServiceLink l2 = addServiceLink(content, "abc123", 2, 123, "test1", Set.of(Role.MAPPER));
82-
ServiceLink l3 = addServiceLink(content, "ghi789", 1, 123, "Test Service 1", Set.of(Role.MAPPER, Role.SHARER));
99+
ServiceLink l1 = addServiceLink(content, "abc123", 1, 123, "Test Service 1", Set.of(), false);
100+
ServiceLink l2 = addServiceLink(content, "abc123", 2, 123, "test1", Set.of(Role.MAPPER), true);
101+
ServiceLink l3 = addServiceLink(content, "ghi789", 1, 123, "Test Service 1", Set.of(Role.MAPPER, Role.SHARER), false);
83102

84103
when(cloudStorage.download("locationPath")).thenReturn(makeInputStream(content));
85104

@@ -98,7 +117,7 @@ public void getServiceLink_multipleServiceLinksStored_findsCorrectServiceLink()
98117
@Test
99118
public void createService_nullRole_createsServiceLinkWithEmptySetOfRoles() throws Exception {
100119
JsonArray content = new JsonArray();
101-
ServiceLink sl = addServiceLink(content, "jkl1011", 3, 124, "Test Service", null);
120+
ServiceLink sl = addServiceLink(content, "jkl1011", 3, 124, "Test Service", null, false);
102121

103122
when(cloudStorage.download("locationPath")).thenReturn(makeInputStream(content));
104123

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

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,40 @@ 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, String linkIdRegex) {
44-
Service service = new Service(serviceId, siteId, name, roles, linkIdRegex);
43+
private Service addService(JsonArray content, int serviceId, int siteId, String name, Set<Role> roles, String linkIdRegex, boolean disabled) {
44+
Service service = new Service(serviceId, siteId, name, roles, linkIdRegex, disabled);
4545
JsonObject jo = JsonObject.mapFrom(service);
4646
content.add(jo);
4747
return service;
4848
}
4949

50+
@Test
51+
public void allConstructors(){
52+
Service service = new Service(1, 123, "Test Service 1", Set.of());
53+
assertEquals(1, service.getServiceId());
54+
assertEquals(123, service.getSiteId());
55+
assertEquals("Test Service 1", service.getName());
56+
assertEquals(Set.of(), service.getRoles());
57+
assertEquals(null, service.getLinkIdRegex());
58+
assertEquals(false, service.isDisabled());
59+
60+
service = new Service(1, 123, "Test Service 1", Set.of(), "nonnull");
61+
assertEquals(1, service.getServiceId());
62+
assertEquals(123, service.getSiteId());
63+
assertEquals("Test Service 1", service.getName());
64+
assertEquals(Set.of(), service.getRoles());
65+
assertEquals("nonnull", service.getLinkIdRegex());
66+
assertEquals(false, service.isDisabled());
67+
68+
service = new Service(1, 123, "Test Service 1", Set.of(), "nonnull", true);
69+
assertEquals(1, service.getServiceId());
70+
assertEquals(123, service.getSiteId());
71+
assertEquals("Test Service 1", service.getName());
72+
assertEquals(Set.of(), service.getRoles());
73+
assertEquals("nonnull", service.getLinkIdRegex());
74+
assertEquals(true, service.isDisabled());
75+
}
76+
5077
@Test
5178
public void loadContentEmptyArray() throws Exception {
5279
JsonArray content = new JsonArray();
@@ -59,10 +86,10 @@ public void loadContentEmptyArray() throws Exception {
5986
@Test
6087
public void loadContentMultipleServices() throws Exception {
6188
JsonArray content = new JsonArray();
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");
89+
Service s1 = addService(content, 1, 123, "Test Service 1", Set.of(), null, false);
90+
Service s2 = addService(content, 2, 123, "test1", Set.of(Role.GENERATOR), "regexA", true);
91+
Service s3 = addService(content, 3, 124, "Test Service 1", Set.of(Role.GENERATOR, Role.SHARING_PORTAL), null, false);
92+
Service s4 = addService(content, 4, 125, "test2", Set.of(Role.MAINTAINER), "regexB", true);
6693
when(cloudStorage.download("locationPath")).thenReturn(makeInputStream(content));
6794

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

0 commit comments

Comments
 (0)