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
27 changes: 24 additions & 3 deletions src/main/java/com/uid2/shared/model/Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@ public class Service {
private final int serviceId;
@JsonProperty("site_id")
private int siteId;
@JsonProperty("link_id_regex")
private String linkIdRegex;
private String name;
private Set<Role> roles;

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

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

public int getServiceId() {
Expand All @@ -34,6 +41,14 @@ public void setSiteId(int siteId) {
this.siteId = siteId;
}

public String getLinkIdRegex() {
Comment thread
mcollins-ttd marked this conversation as resolved.
return linkIdRegex;
}

public void setLinkIdRegex(String linkIdRegex) {
this.linkIdRegex = linkIdRegex;
}

public String getName() {
return name;
}
Expand All @@ -57,19 +72,25 @@ public String toString() {
", siteId=" + siteId +
", name='" + name + '\'' +
", roles=" + roles +
", linkIdRegex=" + linkIdRegex +

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would it fail when linkIdRegex is null?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

no, java handles the concatenation by automatically converting null to "null"

'}';
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Service service = (Service) o;
return serviceId == service.serviceId && siteId == service.siteId && name.equals(service.name) && roles.equals(service.roles);
Service other = (Service) o;

return serviceId == other.serviceId
&& siteId == other.siteId
&& 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());
return Objects.hash(serviceId, siteId, name, roles.hashCode(), linkIdRegex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ public ParsingResult<Map<Integer, Service>> deserialize(InputStream inputStream)
int serviceId = serviceSpec.getInteger("service_id");
int siteId = serviceSpec.getInteger("site_id");
String name = serviceSpec.getString("name");
String linkIdRegex = serviceSpec.getString("link_id_regex");

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);
Service service = new Service(serviceId, siteId, name, roles, linkIdRegex);

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

private Service addService(JsonArray content, int serviceId, int siteId, String name, Set<Role> roles) {
Service service = new Service(serviceId, siteId, name, roles);
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);
JsonObject jo = JsonObject.mapFrom(service);
content.add(jo);
return service;
Expand All @@ -59,10 +59,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());
Service s2 = addService(content, 2, 123, "test1", Set.of(Role.GENERATOR));
Service s3 = addService(content, 3, 124, "Test Service 1", Set.of(Role.GENERATOR, Role.SHARING_PORTAL));
Service s4 = addService(content, 4, 125, "test2", Set.of(Role.MAINTAINER));
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");
when(cloudStorage.download("locationPath")).thenReturn(makeInputStream(content));

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