Skip to content

Commit

Permalink
refactor: add Exception-suffix for exception-classes (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
sitepark-veltrup authored Nov 2, 2023
1 parent ce6f77e commit ae3ed25
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.regex.Pattern;

import com.fasterxml.jackson.annotation.JsonValue;
import com.sitepark.ies.contentrepository.core.domain.exception.InvalidAnchor;
import com.sitepark.ies.contentrepository.core.domain.exception.InvalidAnchorException;

public final class Anchor implements Serializable {

Expand Down Expand Up @@ -49,16 +49,16 @@ public String getName() {
}

/**
* @throws InvalidAnchor
* @throws InvalidAnchorException
*/
private static void validate(String name) {

if (ONLY_NUMBERS_PATTERN.matcher(name).matches()) {
throw new InvalidAnchor(name, "Anchor must not only consist of numbers");
throw new InvalidAnchorException(name, "Anchor must not only consist of numbers");
}

if (!VALIDATOR_PATTERN.matcher(name).matches()) {
throw new InvalidAnchor(name, "Anchor contains Spaces");
throw new InvalidAnchorException(name, "Anchor contains Spaces");
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.sitepark.ies.contentrepository.core.domain.exception;

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

public AccessDeniedException(String message) {
super(message);
}

public AccessDeniedException(String message, Throwable t) {
super(message, t);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

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

public class AnchorAlreadyExists extends ContentRepositoryException {
public class AnchorAlreadyExistsException extends ContentRepositoryException {

private static final long serialVersionUID = 1L;

private final Anchor anchor;

private final long owner;

public AnchorAlreadyExists(Anchor anchor, long owner) {
public AnchorAlreadyExistsException(Anchor anchor, long owner) {
super();
this.anchor = anchor;
this.owner = owner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

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

public class AnchorNotFound extends ContentRepositoryException {
public class AnchorNotFoundException extends ContentRepositoryException {

private static final long serialVersionUID = 1L;

private final Anchor anchor;

public AnchorNotFound(Anchor anchor) {
public AnchorNotFoundException(Anchor anchor) {
super();
this.anchor = anchor;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

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

public class EntityLocked extends ContentRepositoryException {
public class EntityLockedException extends ContentRepositoryException {

private static final long serialVersionUID = 1L;

private final EntityLock lock;

public EntityLocked(EntityLock lock) {
public EntityLockedException(EntityLock lock) {
super();
this.lock = lock;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.sitepark.ies.contentrepository.core.domain.exception;

public class EntityNotFound extends ContentRepositoryException {
public class EntityNotFoundException extends ContentRepositoryException {

private static final long serialVersionUID = 1L;

private final long id;

public EntityNotFound(long id) {
public EntityNotFoundException(long id) {
super();
this.id = id;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.sitepark.ies.contentrepository.core.domain.exception;

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

private final long id;

public GroupNotEmpty(long id) {
public GroupNotEmptyException(long id) {
super();
this.id = id;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.sitepark.ies.contentrepository.core.domain.exception;

public class InvalidAnchor extends ContentRepositoryException {
public class InvalidAnchorException extends ContentRepositoryException {

private final String name;

private static final long serialVersionUID = 1L;

public InvalidAnchor(String name, String message) {
public InvalidAnchorException(String name, String message) {
super(message);
this.name = name;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.sitepark.ies.contentrepository.core.domain.exception;

public class ParentMissing extends ContentRepositoryException {
public class ParentMissingException extends ContentRepositoryException {
private static final long serialVersionUID = 1L;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import com.sitepark.ies.contentrepository.core.domain.entity.EntityTree;
import com.sitepark.ies.contentrepository.core.domain.entity.query.Query;
import com.sitepark.ies.contentrepository.core.domain.entity.query.SubTreeQuery;
import com.sitepark.ies.contentrepository.core.domain.exception.AccessDenied;
import com.sitepark.ies.contentrepository.core.domain.exception.GroupNotEmpty;
import com.sitepark.ies.contentrepository.core.domain.exception.AccessDeniedException;
import com.sitepark.ies.contentrepository.core.domain.exception.GroupNotEmptyException;
import com.sitepark.ies.contentrepository.core.port.AccessControl;
import com.sitepark.ies.contentrepository.core.port.ContentRepository;
import com.sitepark.ies.contentrepository.core.port.EntityBulkExecutor;
Expand Down Expand Up @@ -129,11 +129,11 @@ private void accessControl(List<Entity> entityList) {
long id = entity.getId().get();
if (entity.isGroup()) {
if (!this.accessControl.isGroupRemoveable(id)) {
throw new AccessDenied("Not allowed to remove group " + id);
throw new AccessDeniedException("Not allowed to remove group " + id);
}
} else {
if (!this.accessControl.isEntityRemovable(id)) {
throw new AccessDenied("Not allowed to remove entity " + id);
throw new AccessDeniedException("Not allowed to remove entity " + id);
}
}
});
Expand Down Expand Up @@ -203,7 +203,7 @@ private EntityBulkOperation buildPurgeOperation(List<Entity> entityList) {
long id = entity.getId().get();

if (this.repository.isGroup(id) && !this.repository.isEmptyGroup(id)) {
throw new GroupNotEmpty(id);
throw new GroupNotEmptyException(id);
}

if (LOGGER.isInfoEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.sitepark.ies.contentrepository.core.domain.exception.AccessDenied;
import com.sitepark.ies.contentrepository.core.domain.exception.GroupNotEmpty;
import com.sitepark.ies.contentrepository.core.domain.exception.AccessDeniedException;
import com.sitepark.ies.contentrepository.core.domain.exception.GroupNotEmptyException;
import com.sitepark.ies.contentrepository.core.port.AccessControl;
import com.sitepark.ies.contentrepository.core.port.ContentRepository;
import com.sitepark.ies.contentrepository.core.port.EntityLockManager;
Expand Down Expand Up @@ -64,11 +64,11 @@ protected PurgeEntity(ContentRepository repository, EntityLockManager lockManage
public void purgeEntity(long id) {

if (!this.accessControl.isEntityRemovable(id)) {
throw new AccessDenied("Not allowed to remove entity " + id);
throw new AccessDeniedException("Not allowed to remove entity " + id);
}

if (this.repository.isGroup(id) && !this.repository.isEmptyGroup(id)) {
throw new GroupNotEmpty(id);
throw new GroupNotEmptyException(id);
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import com.sitepark.ies.contentrepository.core.domain.entity.Entity;
import com.sitepark.ies.contentrepository.core.domain.entity.HistoryEntryType;
import com.sitepark.ies.contentrepository.core.domain.entity.RecycleBinItem;
import com.sitepark.ies.contentrepository.core.domain.exception.AccessDenied;
import com.sitepark.ies.contentrepository.core.domain.exception.EntityNotFound;
import com.sitepark.ies.contentrepository.core.domain.exception.AccessDeniedException;
import com.sitepark.ies.contentrepository.core.domain.exception.EntityNotFoundException;
import com.sitepark.ies.contentrepository.core.port.AccessControl;
import com.sitepark.ies.contentrepository.core.port.ContentRepository;
import com.sitepark.ies.contentrepository.core.port.HistoryManager;
Expand All @@ -33,10 +33,10 @@ protected RecoverEntity(ContentRepository repository, HistoryManager historyMana
public void recover(long id) {

Optional<RecycleBinItem> recycleBinItem = this.recycleBin.get(id);
recycleBinItem.orElseThrow(() -> new EntityNotFound(id));
recycleBinItem.orElseThrow(() -> new EntityNotFoundException(id));

if (!this.accessControl.isGroupCreateable(recycleBinItem.get().getParent())) {
throw new AccessDenied("Not allowed to recover entity " + recycleBinItem.get().getId()
throw new AccessDeniedException("Not allowed to recover entity " + recycleBinItem.get().getId()
+ " in group " + recycleBinItem.get().getParent());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import com.sitepark.ies.contentrepository.core.domain.entity.EntityLock;
import com.sitepark.ies.contentrepository.core.domain.entity.HistoryEntryType;
import com.sitepark.ies.contentrepository.core.domain.entity.RecycleBinItem;
import com.sitepark.ies.contentrepository.core.domain.exception.AccessDenied;
import com.sitepark.ies.contentrepository.core.domain.exception.EntityLocked;
import com.sitepark.ies.contentrepository.core.domain.exception.AccessDeniedException;
import com.sitepark.ies.contentrepository.core.domain.exception.EntityLockedException;
import com.sitepark.ies.contentrepository.core.port.AccessControl;
import com.sitepark.ies.contentrepository.core.port.ContentRepository;
import com.sitepark.ies.contentrepository.core.port.EntityLockManager;
Expand Down Expand Up @@ -42,7 +42,7 @@ protected RemoveEntity(ContentRepository repository, EntityLockManager lockManag
public void remove(long id) {

if (!this.accessControl.isEntityRemovable(id)) {
throw new AccessDenied("Not allowed to remove entity " + id);
throw new AccessDeniedException("Not allowed to remove entity " + id);
}

Optional<Entity> entity = this.repository.get(id);
Expand All @@ -53,7 +53,7 @@ public void remove(long id) {
try {
Optional<EntityLock> lock = this.lockManager.getLock(id);
lock.ifPresent(l -> {
throw new EntityLocked(l);
throw new EntityLockedException(l);
});

this.searchIndex.remove(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import com.sitepark.ies.contentrepository.core.domain.entity.Entity;
import com.sitepark.ies.contentrepository.core.domain.entity.EntityLock;
import com.sitepark.ies.contentrepository.core.domain.entity.HistoryEntryType;
import com.sitepark.ies.contentrepository.core.domain.exception.AccessDenied;
import com.sitepark.ies.contentrepository.core.domain.exception.EntityLocked;
import com.sitepark.ies.contentrepository.core.domain.exception.EntityNotFound;
import com.sitepark.ies.contentrepository.core.domain.exception.ParentMissing;
import com.sitepark.ies.contentrepository.core.domain.exception.AccessDeniedException;
import com.sitepark.ies.contentrepository.core.domain.exception.EntityLockedException;
import com.sitepark.ies.contentrepository.core.domain.exception.EntityNotFoundException;
import com.sitepark.ies.contentrepository.core.domain.exception.ParentMissingException;
import com.sitepark.ies.contentrepository.core.domain.service.ContentDiffer;
import com.sitepark.ies.contentrepository.core.port.AccessControl;
import com.sitepark.ies.contentrepository.core.port.ContentRepository;
Expand Down Expand Up @@ -54,12 +54,12 @@ public long store(Entity entity) {
private long create(Entity newEntity) {

Optional<Long> parent = newEntity.getParent();
parent.orElseThrow(() -> new ParentMissing());
parent.orElseThrow(() -> new ParentMissingException());

long parentId = parent.get();

if (!this.accessControl.isEntityCreateable(parentId)) {
throw new AccessDenied("Not allowed to create entity in group " + parent);
throw new AccessDeniedException("Not allowed to create entity in group " + parent);
}

long generatedId = this.idGenerator.generate();
Expand All @@ -84,16 +84,16 @@ private long update(Entity updateEntity) {
long id = updateEntity.getId().get();

Optional<Entity> existsEntity = this.repository.get(id);
existsEntity.orElseThrow(() -> new EntityNotFound(id));
existsEntity.orElseThrow(() -> new EntityNotFoundException(id));

if (!this.accessControl.isEntityWritable(id)) {
throw new AccessDenied("Not allowed to update entity " + id);
throw new AccessDeniedException("Not allowed to update entity " + id);
}

try {
Optional<EntityLock> lock = this.lockManager.getLock(id);
lock.ifPresent(l -> {
throw new EntityLocked(l);
throw new EntityLockedException(l);
});

ChangeSet changeSet = this.contentDiffer.diff(updateEntity, existsEntity.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import org.mockito.InOrder;

import com.sitepark.ies.contentrepository.core.domain.entity.EntityLock;
import com.sitepark.ies.contentrepository.core.domain.exception.AccessDenied;
import com.sitepark.ies.contentrepository.core.domain.exception.EntityLocked;
import com.sitepark.ies.contentrepository.core.domain.exception.AccessDeniedException;
import com.sitepark.ies.contentrepository.core.domain.exception.EntityLockedException;
import com.sitepark.ies.contentrepository.core.port.AccessControl;
import com.sitepark.ies.contentrepository.core.port.ContentRepository;
import com.sitepark.ies.contentrepository.core.port.EntityLockManager;
Expand Down Expand Up @@ -44,7 +44,7 @@ void testAccessDenied() {
null,
null,
null);
assertThrows(AccessDenied.class, () -> {
assertThrows(AccessDeniedException.class, () -> {
purgeEntity.purgeEntity(10L);
});
}
Expand All @@ -58,7 +58,7 @@ void testEntityIsLocked() {
when(accessControl.isEntityRemovable(anyLong())).thenReturn(true);

EntityLockManager lockManager = mock(EntityLockManager.class);
doThrow(new EntityLocked(EntityLock.builder().entity(10L).build())).when(lockManager).lock(anyLong());
doThrow(new EntityLockedException(EntityLock.builder().entity(10L).build())).when(lockManager).lock(anyLong());

var purgeEntity = new PurgeEntity(
repository,
Expand All @@ -73,10 +73,10 @@ void testEntityIsLocked() {
null);
//purgeEntity.purgeEntity(10L);

EntityLocked entityLocked = assertThrows(EntityLocked.class, () -> {
EntityLockedException entityLockedException = assertThrows(EntityLockedException.class, () -> {
purgeEntity.purgeEntity(10L);
}, "entity should be locked");
assertEquals(10L, entityLocked.getLock().getEntity(), "unexpected entity id");
assertEquals(10L, entityLockedException.getLock().getEntity(), "unexpected entity id");
}

@SuppressWarnings("PMD")
Expand Down

0 comments on commit ae3ed25

Please sign in to comment.