Skip to content

add disabled field to services and service links #494

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 1, 2025
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
20 changes: 18 additions & 2 deletions src/main/java/com/uid2/shared/model/Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,23 @@ public class Service {
private String linkIdRegex;
private String name;
private Set<Role> roles;
private boolean disabled;

public Service(int serviceId, int siteId, String name, Set<Role> roles) {
this(serviceId, siteId, name, roles, null);
this(serviceId, siteId, name, roles, null, false);
}

public Service(int serviceId, int siteId, String name, Set<Role> roles, String linkIdRegex) {
this(serviceId, siteId, name, roles, linkIdRegex, false);
}

public Service(int serviceId, int siteId, String name, Set<Role> roles, String linkIdRegex, boolean disabled) {
this.serviceId = serviceId;
this.siteId = siteId;
this.name = name;
this.roles = Objects.requireNonNullElseGet(roles, HashSet::new);
this.linkIdRegex = linkIdRegex;
this.disabled = disabled;
}

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

public boolean isDisabled() {
return disabled;
}

public void setDisabled(boolean disabled) {
this.disabled = disabled;
}

@Override
public String toString() {
return "Service{" +
Expand All @@ -73,6 +87,7 @@ public String toString() {
", name='" + name + '\'' +
", roles=" + roles +
", linkIdRegex=" + linkIdRegex +
", disabled=" + disabled +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't we decide to use lombok at some point?

'}';
}

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

return serviceId == other.serviceId
&& siteId == other.siteId
&& disabled == other.disabled
&& Objects.equals(name, other.name)
&& Objects.equals(roles, other.roles)
&& Objects.equals(linkIdRegex, other.linkIdRegex);
}

@Override
public int hashCode() {
return Objects.hash(serviceId, siteId, name, roles.hashCode(), linkIdRegex);
return Objects.hash(serviceId, siteId, name, roles.hashCode(), linkIdRegex, disabled);
}
}
28 changes: 24 additions & 4 deletions src/main/java/com/uid2/shared/model/ServiceLink.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,26 @@ public class ServiceLink {
private String linkId;
private String name;
private Set<Role> roles;
private boolean disabled;

public ServiceLink(String linkId, int serviceId, int siteId, String name, Set<Role> roles) {
this(linkId, serviceId, siteId, name, roles, false);
}

@JsonCreator
public ServiceLink(
@JsonProperty("link_id") String linkId,
@JsonProperty("service_id") int serviceId,
@JsonProperty("site_id") int siteId,
@JsonProperty("name") String name,
@JsonProperty("roles") Set<Role> roles) {
@JsonProperty("roles") Set<Role> roles,
@JsonProperty("disabled") boolean disabled) {
this.linkId = linkId;
this.serviceId = serviceId;
this.siteId = siteId;
this.name = name;
this.roles = Objects.requireNonNullElseGet(roles, HashSet::new);
this.disabled = disabled;
}

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

public boolean isDisabled() {
return disabled;
}

public void setDisabled(boolean disabled) {
this.disabled = disabled;
}

@Override
public String toString() {
return "ServiceLink{" +
Expand All @@ -75,6 +90,7 @@ public String toString() {
", linkId='" + linkId + '\'' +
", name='" + name + '\'' +
", roles=" + roles +
", disabled=" + disabled +
'}';
}

Expand All @@ -83,12 +99,16 @@ public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ServiceLink serviceLink = (ServiceLink) o;
return siteId == serviceLink.siteId && serviceId == serviceLink.serviceId && linkId.equals(serviceLink.linkId)
&& name.equals(serviceLink.name) && roles.equals(serviceLink.roles);
return siteId == serviceLink.siteId
&& serviceId == serviceLink.serviceId
&& linkId.equals(serviceLink.linkId)
&& name.equals(serviceLink.name)
&& roles.equals(serviceLink.roles)
&& disabled == serviceLink.disabled;
}

@Override
public int hashCode() {
return Objects.hash(siteId, serviceId, linkId, name, roles.hashCode());
return Objects.hash(siteId, serviceId, linkId, name, roles.hashCode(), disabled);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ public ParsingResult<Map<Integer, Service>> deserialize(InputStream inputStream)
int siteId = serviceSpec.getInteger("site_id");
String name = serviceSpec.getString("name");
String linkIdRegex = serviceSpec.getString("link_id_regex");
boolean disabled = serviceSpec.getBoolean("disabled", false);

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

Service service = new Service(serviceId, siteId, name, roles, linkIdRegex);
Service service = new Service(serviceId, siteId, name, roles, linkIdRegex, disabled);

serviceMap.put(serviceId, service);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,32 @@ private JsonObject makeMetadata(String location) {
return metadata;
}

private ServiceLink addServiceLink(JsonArray content, String linkId, int serviceId, int siteId, String name, Set<Role> roles) {
ServiceLink link = new ServiceLink(linkId, serviceId, siteId, name, roles);
private ServiceLink addServiceLink(JsonArray content, String linkId, int serviceId, int siteId, String name, Set<Role> roles, boolean disabled) {
ServiceLink link = new ServiceLink(linkId, serviceId, siteId, name, roles, disabled);
JsonObject jo = JsonObject.mapFrom(link);
content.add(jo);
return link;
}

@Test
public void allConstructors(){
ServiceLink link = new ServiceLink("abc123", 1, 123, "Test Service 1", Set.of());
assertEquals("abc123", link.getLinkId());
assertEquals(1, link.getServiceId());
assertEquals(123, link.getSiteId());
assertEquals("Test Service 1", link.getName());
assertEquals(Set.of(), link.getRoles());
assertEquals(false, link.isDisabled());

link = new ServiceLink("abc123", 1, 123, "Test Service 1", Set.of(), true);
assertEquals("abc123", link.getLinkId());
assertEquals(1, link.getServiceId());
assertEquals(123, link.getSiteId());
assertEquals("Test Service 1", link.getName());
assertEquals(Set.of(), link.getRoles());
assertEquals(true, link.isDisabled());
}

@Test
public void loadContent_emptyArray_loadsZeroServiceLinks() throws Exception {
JsonArray content = new JsonArray();
Expand All @@ -62,10 +81,10 @@ public void loadContent_emptyArray_loadsZeroServiceLinks() throws Exception {
@Test
public void loadContent_multipleServiceLinksStored_loadsAllServiceLinks() throws Exception {
JsonArray content = new JsonArray();
ServiceLink l1 = addServiceLink(content, "abc123", 1, 123, "Test Service 1", Set.of());
ServiceLink l2 = addServiceLink(content, "abc123", 2, 123, "test1", Set.of(Role.MAPPER));
ServiceLink l3 = addServiceLink(content, "ghi789", 1, 123, "Test Service 1", Set.of(Role.MAPPER, Role.SHARER));
ServiceLink l4 = addServiceLink(content, "jkl1011", 3, 124, "test2", null);
ServiceLink l1 = addServiceLink(content, "abc123", 1, 123, "Test Service 1", Set.of(), false);
ServiceLink l2 = addServiceLink(content, "abc123", 2, 123, "test1", Set.of(Role.MAPPER), true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are introducing a mix of enabled/disabled in the test but what tests or assertions are we doing with these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

containsAll will use .equals()

Copy link
Contributor

@jon8787 jon8787 Jun 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, will there be tests be that assert that disabling a service link or service actually does disable it? Where would these go?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Operator, as this is where we will check if it's disabled

ServiceLink l3 = addServiceLink(content, "ghi789", 1, 123, "Test Service 1", Set.of(Role.MAPPER, Role.SHARER), false);
ServiceLink l4 = addServiceLink(content, "jkl1011", 3, 124, "test2", null, true);
when(cloudStorage.download("locationPath")).thenReturn(makeInputStream(content));

final long count = serviceLinkStore.loadContent(makeMetadata("locationPath"));
Expand All @@ -77,9 +96,9 @@ public void loadContent_multipleServiceLinksStored_loadsAllServiceLinks() throws
@Test
public void getServiceLink_multipleServiceLinksStored_findsCorrectServiceLink() throws Exception {
JsonArray content = new JsonArray();
ServiceLink l1 = addServiceLink(content, "abc123", 1, 123, "Test Service 1", Set.of());
ServiceLink l2 = addServiceLink(content, "abc123", 2, 123, "test1", Set.of(Role.MAPPER));
ServiceLink l3 = addServiceLink(content, "ghi789", 1, 123, "Test Service 1", Set.of(Role.MAPPER, Role.SHARER));
ServiceLink l1 = addServiceLink(content, "abc123", 1, 123, "Test Service 1", Set.of(), false);
ServiceLink l2 = addServiceLink(content, "abc123", 2, 123, "test1", Set.of(Role.MAPPER), true);
ServiceLink l3 = addServiceLink(content, "ghi789", 1, 123, "Test Service 1", Set.of(Role.MAPPER, Role.SHARER), false);

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

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

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

Expand Down
39 changes: 33 additions & 6 deletions src/test/java/com/uid2/shared/store/RotatingServiceStoreTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,40 @@ private JsonObject makeMetadata(String location) {
return metadata;
}

private Service addService(JsonArray content, int serviceId, int siteId, String name, Set<Role> roles, String linkIdRegex) {
Service service = new Service(serviceId, siteId, name, roles, linkIdRegex);
private Service addService(JsonArray content, int serviceId, int siteId, String name, Set<Role> roles, String linkIdRegex, boolean disabled) {
Service service = new Service(serviceId, siteId, name, roles, linkIdRegex, disabled);
JsonObject jo = JsonObject.mapFrom(service);
content.add(jo);
return service;
}

@Test
public void allConstructors(){
Service service = new Service(1, 123, "Test Service 1", Set.of());
assertEquals(1, service.getServiceId());
assertEquals(123, service.getSiteId());
assertEquals("Test Service 1", service.getName());
assertEquals(Set.of(), service.getRoles());
assertEquals(null, service.getLinkIdRegex());
assertEquals(false, service.isDisabled());

service = new Service(1, 123, "Test Service 1", Set.of(), "nonnull");
assertEquals(1, service.getServiceId());
assertEquals(123, service.getSiteId());
assertEquals("Test Service 1", service.getName());
assertEquals(Set.of(), service.getRoles());
assertEquals("nonnull", service.getLinkIdRegex());
assertEquals(false, service.isDisabled());

service = new Service(1, 123, "Test Service 1", Set.of(), "nonnull", true);
assertEquals(1, service.getServiceId());
assertEquals(123, service.getSiteId());
assertEquals("Test Service 1", service.getName());
assertEquals(Set.of(), service.getRoles());
assertEquals("nonnull", service.getLinkIdRegex());
assertEquals(true, service.isDisabled());
}

@Test
public void loadContentEmptyArray() throws Exception {
JsonArray content = new JsonArray();
Expand All @@ -59,10 +86,10 @@ public void loadContentEmptyArray() throws Exception {
@Test
public void loadContentMultipleServices() throws Exception {
JsonArray content = new JsonArray();
Service s1 = addService(content, 1, 123, "Test Service 1", Set.of(), null);
Service s2 = addService(content, 2, 123, "test1", Set.of(Role.GENERATOR), "regexA");
Service s3 = addService(content, 3, 124, "Test Service 1", Set.of(Role.GENERATOR, Role.SHARING_PORTAL), null);
Service s4 = addService(content, 4, 125, "test2", Set.of(Role.MAINTAINER), "regexB");
Service s1 = addService(content, 1, 123, "Test Service 1", Set.of(), null, false);
Service s2 = addService(content, 2, 123, "test1", Set.of(Role.GENERATOR), "regexA", true);
Service s3 = addService(content, 3, 124, "Test Service 1", Set.of(Role.GENERATOR, Role.SHARING_PORTAL), null, false);
Service s4 = addService(content, 4, 125, "test2", Set.of(Role.MAINTAINER), "regexB", true);
when(cloudStorage.download("locationPath")).thenReturn(makeInputStream(content));

final long count = serviceStore.loadContent(makeMetadata("locationPath"));
Expand Down
Loading