Skip to content

Commit

Permalink
refactor: use long as id, and more supplements
Browse files Browse the repository at this point in the history
  • Loading branch information
sitepark-veltrup committed May 24, 2022
1 parent 1c651c0 commit 3d9e04c
Show file tree
Hide file tree
Showing 23 changed files with 404 additions and 118 deletions.
8 changes: 7 additions & 1 deletion pmd-ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@
<rule ref="category/java/bestpractices.xml/JUnit4TestShouldUseTestAnnotation"/>
-->
<rule ref="category/java/bestpractices.xml/JUnitAssertionsShouldIncludeMessage"/>
<rule ref="category/java/bestpractices.xml/JUnitTestContainsTooManyAsserts"/>
<!-- See https://github.com/pmd/pmd/discussions/3015 -->
<rule
ref="category/java/bestpractices.xml/JUnitTestContainsTooManyAsserts">
<properties>
<property name="maximumAsserts" value="2" />
</properties>
</rule>
<rule ref="category/java/bestpractices.xml/JUnitTestsShouldIncludeAssert"/>
<rule ref="category/java/bestpractices.xml/JUnitUseExpected"/>
<rule ref="category/java/bestpractices.xml/LooseCoupling"/>
Expand Down
22 changes: 19 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,24 @@
</licenses>

<properties>
<junit.version>5.8.2</junit.version>
<spotbugs.version>4.6.0</spotbugs.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>11</maven.compiler.release>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>${junit.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>

<dependency>
Expand Down Expand Up @@ -56,19 +69,16 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>1.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -77,6 +87,12 @@
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.5.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
2 changes: 1 addition & 1 deletion spotbug-exclude-filter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<!-- https://spotbugs.readthedocs.io/en/stable/filter.html -->
<Match>
<Bug
pattern="REC_CATCH_EXCEPTION,RV_CHECK_FOR_POSITIVE_INDEXOF,BC_UNCONFIRMED_CAST_OF_RETURN_VALUE" />
pattern="REC_CATCH_EXCEPTION,RV_CHECK_FOR_POSITIVE_INDEXOF,BC_UNCONFIRMED_CAST_OF_RETURN_VALUE,THROWS_METHOD_THROWS_CLAUSE_THROWABLE" />
</Match>

<Match>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

public final class EntityLock implements Serializable {

private final Identifier entity;
private final Identifier user;
private final long entity;
private final long user;
private final long created;
private final long lastAccess;
private final long ttl;
Expand All @@ -20,11 +20,11 @@ private EntityLock(Builder builder) {
this.ttl = builder.ttl;
}

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

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

Expand Down Expand Up @@ -55,8 +55,8 @@ public String toString() {

public static class Builder {

private Identifier entity;
private Identifier user;
private long entity;
private long user;
private long created;
private long lastAccess;
private long ttl;
Expand All @@ -72,14 +72,12 @@ private Builder(EntityLock entityLock) {
this.ttl = entityLock.ttl;
}

public Builder entity(Identifier entity) {
assert entity != null;
public Builder entity(long entity) {
this.entity = entity;
return this;
}

public Builder user(Identifier user) {
assert user != null;
public Builder user(long user) {
this.user = user;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@

public final class RecycleBinItem {

private final Identifier identifier;
private final Identifier parent;
private final long id;
private final long parent;
private final Entity entity;
private final List<RecycleBinItem> children;

private RecycleBinItem(Builder builder) {
this.identifier = builder.identifier;
this.id = builder.id;
this.parent = builder.parent;
this.entity = builder.entity;
this.children = builder.children;
}

public Identifier getIdentifier() {
return this.identifier;
public long getId() {
return this.id;
}

public Identifier getParent() {
public long getParent() {
return this.parent;
}

Expand All @@ -44,27 +44,25 @@ public Builder toBuilder() {

public static class Builder {

private Identifier identifier;
private Identifier parent;
private long id;
private long parent;
private Entity entity;
private List<RecycleBinItem> children = new ArrayList<>();

private Builder() {}
private Builder(RecycleBinItem recycleBinItem) {
this.identifier = recycleBinItem.identifier;
this.id = recycleBinItem.id;
this.parent = recycleBinItem.parent;
this.entity = recycleBinItem.entity;
this.children = new ArrayList<>(recycleBinItem.children);
}

public Builder identifier(Identifier identifier) {
assert identifier != null;
this.identifier = identifier;
public Builder identifier(long id) {
this.id = id;
return this;
}

public Builder parent(Identifier parent) {
assert parent != null;
public Builder parent(long parent) {
this.parent = parent;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
package com.sitepark.ies.contentrepository.core.domain.exception;

import com.sitepark.ies.contentrepository.core.domain.entity.Identifier;

public class EntityNotFound extends ContentRepositoryException {

private static final long serialVersionUID = 1L;

private final Identifier identifier;
private final long id;

public EntityNotFound(Identifier identifier) {
public EntityNotFound(long id) {
super();
this.identifier = identifier;
this.id = id;
}

public Identifier getIdentifier() {
return this.identifier;
public long getId() {
return this.id;
}

@Override
public String getMessage() {
return "Entity with identifier " + this.identifier + " not found";
return "Entity with id " + this.id + " not found";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.sitepark.ies.contentrepository.core.domain.exception;

public class GroupNotEmpty extends ContentRepositoryException {
private static final long serialVersionUID = 1L;

private final long id;

public GroupNotEmpty(long id) {
super();
this.id = id;
}

public long getId() {
return this.id;
}

@Override
public String getMessage() {
return "Group with id " + this.id + " not empty";
}

}
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package com.sitepark.ies.contentrepository.core.port;

import com.sitepark.ies.contentrepository.core.domain.entity.Identifier;

public interface AccessControl {

boolean isEntityCreateable(Identifier parent);
boolean isEntityReadable(Identifier identifier);
boolean isEntityWritable(Identifier identifier);
boolean isEntityRemovable(Identifier identifier);
boolean isEntityCreateable(long parent);
boolean isEntityReadable(long id);
boolean isEntityWritable(long id);
boolean isEntityRemovable(long id);

boolean isGroupCreateable(Identifier parent);
boolean isGroupReadable(Identifier identifier);
boolean isGroupWritable(Identifier identifier);
boolean isGroupRemoveable(Identifier identifier);
boolean isGroupCreateable(long parent);
boolean isGroupReadable(long id);
boolean isGroupWritable(long id);
boolean isGroupRemoveable(long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
import com.sitepark.ies.contentrepository.core.domain.entity.Identifier;

public interface ContentRepository {
boolean isGroup(long id);
boolean isEmptyGroup(long id);
Optional<Entity> store(Entity entity);
Optional<Entity> get(Identifier identifier);
Optional<Entity> remove(Identifier identifier);
Optional<Entity> get(long id);
void removeEntity(long id);
void removeGroup(long id);
Optional<Identifier> resolveAnchor(Anchor anchor);
List<Long> getAllMediaReferences(Identifier identifier);
long resolve(Identifier identifier);
List<Long> getAllMediaReferences(long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import java.util.Optional;

import com.sitepark.ies.contentrepository.core.domain.entity.EntityLock;
import com.sitepark.ies.contentrepository.core.domain.entity.Identifier;

public interface EntityLockManager {
Optional<EntityLock> getLock(Identifier identifier);
void lock(Identifier identifier);
void unlock(Identifier identifier);
Optional<EntityLock> getLock(long id);
void lock(long id);
void unlock(long id);
List<EntityLock> getLockList();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

import com.sitepark.ies.contentrepository.core.domain.entity.HistoryEntry;
import com.sitepark.ies.contentrepository.core.domain.entity.HistoryEntryType;
import com.sitepark.ies.contentrepository.core.domain.entity.Identifier;

public interface HistoryManager {
void purge(Identifier identifier);
HistoryEntry createEntry(Identifier identifier, long timestamp, HistoryEntryType type);
List<HistoryEntry> getHistory(Identifier identifier);
void purge(long id);
HistoryEntry createEntry(long id, long timestamp, HistoryEntryType type);
List<HistoryEntry> getHistory(long id);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.sitepark.ies.contentrepository.core.port;

public interface IdGenerator {
Long generate();
long generate();
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.sitepark.ies.contentrepository.core.port;

import com.sitepark.ies.contentrepository.core.domain.entity.Identifier;

public interface Publisher {
void republish(Identifier identifier, long version);
void depublish(Identifier identifier);
void republish(long id, long version);
void depublish(long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
import java.util.List;
import java.util.Optional;

import com.sitepark.ies.contentrepository.core.domain.entity.Identifier;
import com.sitepark.ies.contentrepository.core.domain.entity.RecycleBinItem;
import com.sitepark.ies.contentrepository.core.domain.entity.RecycleBinItemFilter;

public interface RecycleBin {
Optional<RecycleBinItem> get(Identifier identifier);
Optional<RecycleBinItem> get(long id);
void add(RecycleBinItem item);
void remove(Identifier identifier);
void removeByObject(long id);
List<RecycleBinItem> find(RecycleBinItemFilter filter);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.sitepark.ies.contentrepository.core.port;

import com.sitepark.ies.contentrepository.core.domain.entity.Entity;
import com.sitepark.ies.contentrepository.core.domain.entity.Identifier;

public interface SearchIndex {
void index(Entity entity);
void remove(Identifier identifier);
void remove(long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@

import com.sitepark.ies.contentrepository.core.domain.entity.Entity;
import com.sitepark.ies.contentrepository.core.domain.entity.EntityVersion;
import com.sitepark.ies.contentrepository.core.domain.entity.Identifier;

public interface VersioningManager {

void removeAllVersions(Identifier identifier);
void removeAllVersions(long id);
Entity createNewVersion(Entity entity);
Entity revertToVersion(EntityVersion version);
Entity getVersion(EntityVersion version);
Entity getNextVersionSince(long timestamp);
List<Long> getAllMediaReferences(Identifier identifier);
List<Long> getAllMediaReferences(long id);

}
Loading

0 comments on commit 3d9e04c

Please sign in to comment.