Skip to content

Commit 81a39b0

Browse files
committed
add disabled field to services and service links
1 parent 91e2c63 commit 81a39b0

File tree

5 files changed

+60
-23
lines changed

5 files changed

+60
-23
lines changed

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@ 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;
@@ -65,6 +70,14 @@ public void setRoles(Set<Role> roles) {
6570
this.roles = Objects.requireNonNullElseGet(roles, HashSet::new);
6671
}
6772

73+
public boolean isDisabled() {
74+
return disabled;
75+
}
76+
77+
public void setDisabled(boolean disabled) {
78+
this.disabled = disabled;
79+
}
80+
6881
@Override
6982
public String toString() {
7083
return "Service{" +
@@ -73,6 +86,7 @@ public String toString() {
7386
", name='" + name + '\'' +
7487
", roles=" + roles +
7588
", linkIdRegex=" + linkIdRegex +
89+
", disabled=" + disabled +
7690
'}';
7791
}
7892

@@ -84,13 +98,14 @@ public boolean equals(Object o) {
8498

8599
return serviceId == other.serviceId
86100
&& siteId == other.siteId
101+
&& disabled == other.disabled
87102
&& Objects.equals(name, other.name)
88103
&& Objects.equals(roles, other.roles)
89104
&& Objects.equals(linkIdRegex, other.linkIdRegex);
90105
}
91106

92107
@Override
93108
public int hashCode() {
94-
return Objects.hash(serviceId, siteId, name, roles.hashCode(), linkIdRegex);
109+
return Objects.hash(serviceId, siteId, name, roles.hashCode(), linkIdRegex, disabled);
95110
}
96111
}

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

Lines changed: 25 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,17 @@ 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+
&& disabled == serviceLink.disabled
106+
&& name.equals(serviceLink.name)
107+
&& roles.equals(serviceLink.roles)
108+
&& disabled == serviceLink.disabled;
88109
}
89110

90111
@Override
91112
public int hashCode() {
92-
return Objects.hash(siteId, serviceId, linkId, name, roles.hashCode());
113+
return Objects.hash(siteId, serviceId, linkId, name, roles.hashCode(), disabled);
93114
}
94115
}

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: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ 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;
@@ -62,10 +62,10 @@ public void loadContent_emptyArray_loadsZeroServiceLinks() throws Exception {
6262
@Test
6363
public void loadContent_multipleServiceLinksStored_loadsAllServiceLinks() throws Exception {
6464
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);
65+
ServiceLink l1 = addServiceLink(content, "abc123", 1, 123, "Test Service 1", Set.of(), false);
66+
ServiceLink l2 = addServiceLink(content, "abc123", 2, 123, "test1", Set.of(Role.MAPPER), true);
67+
ServiceLink l3 = addServiceLink(content, "ghi789", 1, 123, "Test Service 1", Set.of(Role.MAPPER, Role.SHARER), false);
68+
ServiceLink l4 = addServiceLink(content, "jkl1011", 3, 124, "test2", null, true);
6969
when(cloudStorage.download("locationPath")).thenReturn(makeInputStream(content));
7070

7171
final long count = serviceLinkStore.loadContent(makeMetadata("locationPath"));
@@ -77,9 +77,9 @@ public void loadContent_multipleServiceLinksStored_loadsAllServiceLinks() throws
7777
@Test
7878
public void getServiceLink_multipleServiceLinksStored_findsCorrectServiceLink() throws Exception {
7979
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));
80+
ServiceLink l1 = addServiceLink(content, "abc123", 1, 123, "Test Service 1", Set.of(), false);
81+
ServiceLink l2 = addServiceLink(content, "abc123", 2, 123, "test1", Set.of(Role.MAPPER), true);
82+
ServiceLink l3 = addServiceLink(content, "ghi789", 1, 123, "Test Service 1", Set.of(Role.MAPPER, Role.SHARER), false);
8383

8484
when(cloudStorage.download("locationPath")).thenReturn(makeInputStream(content));
8585

@@ -98,7 +98,7 @@ public void getServiceLink_multipleServiceLinksStored_findsCorrectServiceLink()
9898
@Test
9999
public void createService_nullRole_createsServiceLinkWithEmptySetOfRoles() throws Exception {
100100
JsonArray content = new JsonArray();
101-
ServiceLink sl = addServiceLink(content, "jkl1011", 3, 124, "Test Service", null);
101+
ServiceLink sl = addServiceLink(content, "jkl1011", 3, 124, "Test Service", null, false);
102102

103103
when(cloudStorage.download("locationPath")).thenReturn(makeInputStream(content));
104104

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, 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;
@@ -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(), 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");
62+
Service s1 = addService(content, 1, 123, "Test Service 1", Set.of(), null, false);
63+
Service s2 = addService(content, 2, 123, "test1", Set.of(Role.GENERATOR), "regexA", true);
64+
Service s3 = addService(content, 3, 124, "Test Service 1", Set.of(Role.GENERATOR, Role.SHARING_PORTAL), null, false);
65+
Service s4 = addService(content, 4, 125, "test2", Set.of(Role.MAINTAINER), "regexB", true);
6666
when(cloudStorage.download("locationPath")).thenReturn(makeInputStream(content));
6767

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

0 commit comments

Comments
 (0)