-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c3160f
commit a0b9bc5
Showing
24 changed files
with
746 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/BulkOperationKey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.sitepark.ies.contentrepository.core.domain.entity; | ||
|
||
public enum BulkOperationKey { | ||
|
||
PURGE_LOCK("contentrepository.purge.lock"), | ||
PURGE_DEPUBLISH("contentrepository.purge.depublish"), | ||
PURGE_PURGE("contentrepository.purge.purge"), | ||
PURGE_CLEANUP("contentrepository.purge.cleanup"); | ||
|
||
private final String name; | ||
|
||
private BulkOperationKey(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return this.name; | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityBulkExecution.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package com.sitepark.ies.contentrepository.core.domain.entity; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
|
||
public class EntityBulkExecution { | ||
|
||
private final String[] topic; | ||
|
||
private final List<EntityBulkOperation> operations; | ||
|
||
private final EntityBulkOperation finalizer; | ||
|
||
protected EntityBulkExecution(Builder builder) { | ||
this.topic = builder.topic; | ||
this.operations = Collections.unmodifiableList(builder.operations); | ||
this.finalizer = builder.finalizer; | ||
} | ||
|
||
@SuppressFBWarnings("EI_EXPOSE_REP") | ||
public String[] getTopic() { | ||
return this.topic.clone(); | ||
} | ||
|
||
@SuppressFBWarnings("EI_EXPOSE_REP") | ||
public List<EntityBulkOperation> getOperations() { | ||
return this.operations; | ||
} | ||
|
||
public Optional<EntityBulkOperation> getFinalizer() { | ||
return Optional.ofNullable(this.finalizer); | ||
} | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
public static class Builder { | ||
|
||
private String[] topic; | ||
|
||
private final List<EntityBulkOperation> operations = new ArrayList<>(); | ||
|
||
private EntityBulkOperation finalizer; | ||
|
||
private Builder() { | ||
} | ||
|
||
/** | ||
* Topics are used to display all bulk operations for a specific topic. | ||
* Topics are hierarchical and the path of the topic is specified via | ||
* a string array. Topics are freely definable. | ||
* If e.g. all Topics of <code>level1</code> are queried, all | ||
* BulkExecutions recursively below <code>level1</code> are returned. | ||
*/ | ||
public Builder topic(String... topic) { | ||
assert topic != null; | ||
this.topic = topic.clone(); | ||
return this; | ||
} | ||
|
||
public Builder operation(EntityBulkOperation... operations) { | ||
assert operations != null; | ||
for (EntityBulkOperation operation : operations) { | ||
assert operation != null; | ||
this.operations.add(operation); | ||
} | ||
return this; | ||
} | ||
|
||
public Builder finalizer(EntityBulkOperation finalizer) { | ||
assert finalizer != null; | ||
this.finalizer = finalizer; | ||
return this; | ||
} | ||
|
||
public EntityBulkExecution build() { | ||
assert this.topic != null; | ||
assert !this.operations.isEmpty(); | ||
return new EntityBulkExecution(this); | ||
} | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityBulkOperation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.sitepark.ies.contentrepository.core.domain.entity; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.function.Consumer; | ||
|
||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
|
||
public class EntityBulkOperation { | ||
|
||
private final BulkOperationKey key; | ||
|
||
private final List<Entity> entityList; | ||
|
||
private final Consumer<Entity> consumer; | ||
|
||
protected EntityBulkOperation(Builder builder) { | ||
this.key = builder.key; | ||
this.entityList = Collections.unmodifiableList(builder.entityList); | ||
this.consumer = builder.consumer; | ||
} | ||
|
||
public BulkOperationKey getKey() { | ||
return this.key; | ||
} | ||
|
||
@SuppressFBWarnings("EI_EXPOSE_REP") | ||
public List<Entity> getEntityList() { | ||
return this.entityList; | ||
} | ||
|
||
public Consumer<Entity> getConsumer() { | ||
return this.consumer; | ||
} | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
public static class Builder { | ||
|
||
private BulkOperationKey key; | ||
|
||
private final List<Entity> entityList = new ArrayList<>(); | ||
|
||
private Consumer<Entity> consumer; | ||
|
||
private Builder() { | ||
} | ||
|
||
public Builder key(BulkOperationKey key) { | ||
assert key != null; | ||
this.key = key; | ||
return this; | ||
} | ||
|
||
public Builder entityList(List<Entity> entityList) { | ||
assert entityList != null; | ||
this.entityList.addAll(entityList); | ||
return this; | ||
} | ||
|
||
public Builder consumer(Consumer<Entity> consumer) { | ||
assert consumer != null; | ||
this.consumer = consumer; | ||
return this; | ||
} | ||
|
||
public EntityBulkOperation build() { | ||
assert this.key != null; | ||
assert !this.entityList.isEmpty(); | ||
assert this.consumer != null; | ||
return new EntityBulkOperation(this); | ||
} | ||
} | ||
} |
163 changes: 163 additions & 0 deletions
163
src/main/java/com/sitepark/ies/contentrepository/core/domain/entity/EntityTree.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
package com.sitepark.ies.contentrepository.core.domain.entity; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.LinkedHashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
|
||
@SuppressWarnings("PMD.UseConcurrentHashMap") | ||
public class EntityTree { | ||
|
||
private final Map<Long, Set<Long>> children = new HashMap<>(); | ||
|
||
private final Map<Long, Long> parents = new HashMap<>(); | ||
|
||
private final Map<Long, Entity> index = new HashMap<>(); | ||
|
||
/** | ||
* Returns all roots of the tree. | ||
* | ||
* Roots are all entries without a parent | ||
*/ | ||
public List<Entity> getRoots() { | ||
return this.getRootIdList().stream() | ||
.map(id -> this.index.get(id)) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
private Set<Long> getRootIdList() { | ||
Set<Long> knownRoots = this.children.get(null); | ||
Set<Long> roots = new HashSet<>(); | ||
if (knownRoots != null) { | ||
roots.addAll(knownRoots); | ||
} | ||
for (Long parent : this.parents.values()) { | ||
if (parent != null && !this.parents.containsKey(parent)) { | ||
roots.add(parent); | ||
} | ||
} | ||
return roots; | ||
} | ||
|
||
/** | ||
* Places an element in the tree. | ||
* | ||
* If no parent present, it is set as root element. | ||
*/ | ||
public void add(Entity entity) { | ||
|
||
if (entity == null) { | ||
return; | ||
} | ||
|
||
this.parents.put(entity.getId().get(), entity.getParent().orElse(null)); | ||
Set<Long> siblings = this.children.get(entity.getParent().orElse(null)); | ||
if (siblings == null) { | ||
siblings = new HashSet<>(); | ||
this.children.put(entity.getParent().orElse(null), siblings); | ||
} | ||
siblings.add(entity.getId().get()); | ||
this.index.put(entity.getId().get(), entity); | ||
} | ||
|
||
public Entity get(Long id) { | ||
return this.index.get(id); | ||
} | ||
|
||
public List<Entity> getChildren(Long parent) { | ||
Set<Long> children = this.children.get(parent); | ||
return children.stream() | ||
.map(id -> this.index.get(id)) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
/** | ||
* Liefert die Unterelemente des Parent rekusive. | ||
*/ | ||
public List<Entity> getChildrenRecursive(Long root) { | ||
Set<Long> children = this.getChildrenIdListRecursive(root); | ||
return children.stream() | ||
.map(id -> this.index.get(id)) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
private Set<Long> getChildrenIdListRecursive(Long root) { | ||
Set<Long> list = new LinkedHashSet<Long>(); | ||
Set<Long> children = this.children.get(root); | ||
if (children != null) { | ||
list.addAll(children); | ||
for (Long id : children) { | ||
Set<Long> grandChildren = this.getChildrenIdListRecursive(id); | ||
list.addAll(grandChildren); | ||
} | ||
} | ||
|
||
return list; | ||
} | ||
|
||
/** | ||
* Returns all elements of the tree in hierarchical order | ||
*/ | ||
public List<Entity> getAll() { | ||
Set<Long> rootIdList = this.getRootIdList(); | ||
List<Entity> list = new ArrayList<>(); | ||
for (Long rootId : rootIdList) { | ||
Entity root = this.index.get(rootId); | ||
if (root != null) { | ||
list.add(root); | ||
} | ||
List<Entity> childrenOrRoot = this.getChildrenRecursive(rootId); | ||
list.addAll(childrenOrRoot); | ||
} | ||
return list; | ||
} | ||
|
||
public boolean hasChildren(Long parent) { | ||
return this.children.containsKey(parent); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.toString(0); | ||
} | ||
|
||
public String toString(int indent) { | ||
return this.toString(indent, null); | ||
} | ||
|
||
public String toString(int indent, Long parent) { | ||
java.lang.StringBuilder b = new java.lang.StringBuilder(); | ||
this.toString(indent, parent, new java.lang.StringBuilder(), b); | ||
return b.toString(); | ||
} | ||
|
||
private void toString(int indent, Long parent, java.lang.StringBuilder indentPrefix, | ||
java.lang.StringBuilder b) { | ||
|
||
if (parent == null) { | ||
Set<Long> roots = this.getRootIdList(); | ||
for (Long child : roots) { | ||
this.toString(indent, child, indentPrefix, b); | ||
} | ||
} else { | ||
b.append(indentPrefix.toString()); | ||
b.append(this.index.get(parent)); | ||
b.append('\n'); | ||
|
||
if (this.hasChildren(parent)) { | ||
for (int i = 0; i < indent; i++) { | ||
indentPrefix.append(' '); | ||
} | ||
for (Long child : this.children.get(parent)) { | ||
this.toString(indent, child, indentPrefix, b); | ||
} | ||
indentPrefix.delete(indentPrefix.length() - indent, indentPrefix.length()); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.