Skip to content

Commit

Permalink
refactor: change id-type from long to string
Browse files Browse the repository at this point in the history
  • Loading branch information
sitepark-veltrup committed Feb 6, 2024
1 parent 8fbf451 commit 9aa27ee
Show file tree
Hide file tree
Showing 46 changed files with 665 additions and 459 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sitepark.ies.contentrepository.core.domain.entity;

import java.time.OffsetDateTime;
import java.util.Objects;
import java.util.Optional;

Expand All @@ -9,11 +10,11 @@
@JsonDeserialize(builder = Entity.EntityBuilder.class)
public class Entity {

private final long id;
private final String id;
private final Anchor anchor;
private final String name;
private final long parent;
private final long version;
private final String parent;
private final OffsetDateTime version;
private final boolean isGroup;

protected Entity(Builder<?> builder) {
Expand All @@ -25,8 +26,8 @@ protected Entity(Builder<?> builder) {
this.isGroup = builder.isGroup;
}

public Optional<Long> getId() {
if (this.id == 0) {
public Optional<String> getId() {
if (this.id == null) {
return Optional.empty();
} else {
return Optional.of(this.id);
Expand All @@ -41,16 +42,16 @@ public Optional<String> getName() {
return Optional.ofNullable(this.name);
}

public Optional<Long> getParent() {
if (this.parent == 0) {
public Optional<String> getParent() {
if (this.parent == null) {
return Optional.empty();
} else {
return Optional.of(this.parent);
}
}

public Optional<Long> getVersion() {
if (this.version == 0) {
public Optional<OffsetDateTime> getVersion() {
if (this.version == null) {
return Optional.empty();
} else {
return Optional.of(this.version);
Expand All @@ -72,14 +73,13 @@ public Builder<?> toBuilder() {
@Override
public final int hashCode() {

int hash = Long.hashCode(this.id);
hash = (this.anchor != null) ? 31 * hash + this.anchor.hashCode() : hash;
hash = (this.name != null) ? 31 * hash + this.name.hashCode() : hash;
hash = 31 * hash + Long.hashCode(this.version);
hash = 31 * hash + Long.hashCode(this.parent);
hash = 31 * hash + Boolean.hashCode(this.isGroup);

return hash;
return Objects.hash(
this.id,
this.anchor,
this.name,
this.parent,
this.version,
this.isGroup);
}

@Override
Expand All @@ -89,46 +89,29 @@ public final boolean equals(Object o) {
return false;
}

Entity entity = (Entity)o;
Entity that = (Entity)o;

if (!Objects.equals(this.id, entity.id)) {
return false;
} else if (!Objects.equals(this.anchor, entity.anchor)) {
return false;
} else if (this.isGroup != entity.isGroup) {
return false;
} else if (!Objects.equals(this.version, entity.version)) {
return false;
} else if (!Objects.equals(this.name, entity.name)) {
return false;
} else if (!Objects.equals(this.parent, entity.parent)) {
return false;
}

return true;
return Objects.equals(this.id, that.id) &&
Objects.equals(this.anchor, that.anchor) &&
Objects.equals(this.name, that.name) &&
Objects.equals(this.parent, that.parent) &&
Objects.equals(this.version, that.version) &&
Objects.equals(this.isGroup, that.isGroup);
}

@Override
public String toString() {
return new StringBuilder()
.append("Entity[")
.append("name: ")
.append(this.getName().orElse("UNNAMED"))
.append(", id: ").append(this.id)
.append(", anchor: ").append(this.anchor)
.append(", parent: ").append(this.parent)
.append(", version: ").append(this.version)
.append(", isGroup: ").append(this.isGroup)
.append(']').toString();
return "Entity [id=" + id + ", anchor=" + anchor + ", name=" + name + ", parent=" + parent + ", version="
+ version + ", isGroup=" + isGroup + "]";
}

public static abstract class Builder<B extends Builder<B>> {

private long id;
private String id;
private Anchor anchor;
private String name;
private long parent;
private long version;
private String parent;
private OffsetDateTime version;
private boolean isGroup;

protected Builder() {
Expand All @@ -143,7 +126,11 @@ protected Builder(Entity entity) {
this.isGroup = entity.isGroup;
}

public B id(long id) {
public B id(String id) {
Objects.requireNonNull(id, "id is null");
if (!Identifier.isId(id)) {
throw new IllegalArgumentException(id + " is not an id");
}
this.id = id;
return this.self();
}
Expand All @@ -169,12 +156,17 @@ public B name(String name) {
return this.self();
}

public B parent(long parent) {
public B parent(String parent) {
Objects.requireNonNull(parent, "parent is null");
if (!Identifier.isId(parent)) {
throw new IllegalArgumentException(parent + " is not an id");
}
this.parent = parent;
return this.self();
}

public B version(long version) {
public B version(OffsetDateTime version) {
Objects.requireNonNull(version, "version is null");
this.version = version;
return this.self();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.sitepark.ies.contentrepository.core.domain.entity;

import java.io.Serializable;
import java.time.OffsetDateTime;
import java.util.Objects;

public final class EntityLock implements Serializable {

private final long entity;
private final long user;
private final long created;
private final long lastAccess;
private final String entity;
private final String user;
private final OffsetDateTime created;
private final OffsetDateTime lastAccess;
private final long ttl;

private static final long serialVersionUID = 1L;
Expand All @@ -21,19 +22,19 @@ private EntityLock(Builder builder) {
this.ttl = builder.ttl;
}

public long getEntity() {
public String getEntity() {
return entity;
}

public long getUser() {
public String getUser() {
return user;
}

public long getCreated() {
public OffsetDateTime getCreated() {
return created;
}

public long getLastAccess() {
public OffsetDateTime getLastAccess() {
return lastAccess;
}

Expand Down Expand Up @@ -94,10 +95,10 @@ public String toString() {

public static class Builder {

private long entity;
private long user;
private long created;
private long lastAccess;
private String entity;
private String user;
private OffsetDateTime created;
private OffsetDateTime lastAccess;
private long ttl;

protected Builder() {
Expand All @@ -111,28 +112,32 @@ protected Builder(EntityLock entityLock) {
this.ttl = entityLock.ttl;
}

public Builder entity(long entity) {
public Builder entity(String entity) {
Objects.requireNonNull(entity, "entity is null");
if (!Identifier.isId(entity)) {
throw new IllegalArgumentException(entity + " is not an id");
}
this.entity = entity;
return this;
}

public Builder user(long user) {
public Builder user(String user) {
Objects.requireNonNull(user, "user is null");
if (!Identifier.isId(user)) {
throw new IllegalArgumentException(user + " is not an id");
}
this.user = user;
return this;
}

public Builder created(long created) {
if (created <= 0) {
throw new IllegalArgumentException("created should be greater then 0");
}
public Builder created(OffsetDateTime created) {
Objects.requireNonNull(created, "created is null");
this.created = created;
return this;
}

public Builder lastAccess(long lastAccess) {
if (lastAccess <= 0) {
throw new IllegalArgumentException("lastAccess should be greater then 0");
}
public Builder lastAccess(OffsetDateTime lastAccess) {
Objects.requireNonNull(lastAccess, "lastAccess is null");
this.lastAccess = lastAccess;
return this;
}
Expand Down
Loading

0 comments on commit 9aa27ee

Please sign in to comment.