diff --git a/ldes-fragmentisers/ldes-fragmentisers-common/pom.xml b/ldes-fragmentisers/ldes-fragmentisers-common/pom.xml
index 375fbcc4fe..496386d180 100644
--- a/ldes-fragmentisers/ldes-fragmentisers-common/pom.xml
+++ b/ldes-fragmentisers/ldes-fragmentisers-common/pom.xml
@@ -5,7 +5,7 @@
ldes-fragmentisers
be.vlaanderen.informatievlaanderen.vsds
- 3.3.0
+ 3.4.0-SNAPSHOT
4.0.0
@@ -19,12 +19,6 @@
${project.version}
-
- be.vlaanderen.informatievlaanderen.vsds
- ldes-server-retention
- ${project.version}
-
-
org.springframework.boot
diff --git a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/FragmentationStrategy.java b/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/FragmentationStrategy.java
index e1c5199d3f..9793c7de77 100644
--- a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/FragmentationStrategy.java
+++ b/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/FragmentationStrategy.java
@@ -1,12 +1,9 @@
package be.vlaanderen.informatievlaanderen.ldes.server.fragmentation;
import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.entities.Bucket;
-import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.entities.BucketisedMember;
import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.entities.FragmentationMember;
import io.micrometer.observation.Observation;
-import java.util.List;
-
public interface FragmentationStrategy {
- List addMemberToBucket(Bucket rootFragmentOfView, FragmentationMember member, Observation parentObservation);
+ void addMemberToBucket(Bucket rootBucketOfView, FragmentationMember member, Observation parentObservation);
}
\ No newline at end of file
diff --git a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/FragmentationStrategyBatchCollection.java b/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/FragmentationStrategyBatchCollection.java
index cbc68266af..d589f75a48 100644
--- a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/FragmentationStrategyBatchCollection.java
+++ b/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/FragmentationStrategyBatchCollection.java
@@ -4,7 +4,6 @@
import be.vlaanderen.informatievlaanderen.ldes.server.domain.model.ViewName;
import be.vlaanderen.informatievlaanderen.ldes.server.domain.model.ViewSpecification;
import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.factory.FragmentationStrategyCreator;
-import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.repository.BucketRepository;
import io.micrometer.observation.ObservationRegistry;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
@@ -16,16 +15,13 @@
@Component
public class FragmentationStrategyBatchCollection implements FragmentationStrategyCollection {
- private final BucketRepository bucketRepository;
private final Set fragmentationStrategySet;
private final FragmentationStrategyCreator fragmentationStrategyCreator;
private final ObservationRegistry observationRegistry;
public FragmentationStrategyBatchCollection(
- BucketRepository bucketRepository,
FragmentationStrategyCreator fragmentationStrategyCreator,
ObservationRegistry observationRegistry) {
- this.bucketRepository = bucketRepository;
this.fragmentationStrategyCreator = fragmentationStrategyCreator;
this.observationRegistry = observationRegistry;
this.fragmentationStrategySet = new HashSet<>();
@@ -78,7 +74,6 @@ private void removeFromStrategySet(Predicate
private FragmentationStrategyBatchExecutor createExecutor(ViewName viewName, ViewSpecification viewSpecification) {
final FragmentationStrategy fragmentationStrategy = fragmentationStrategyCreator
.createFragmentationStrategyForView(viewSpecification);
- final var rootBucketRetriever = new RootBucketRetriever(viewName, bucketRepository, observationRegistry);
- return new FragmentationStrategyBatchExecutor(viewName, fragmentationStrategy, rootBucketRetriever, observationRegistry);
+ return new FragmentationStrategyBatchExecutor(viewName, fragmentationStrategy, observationRegistry);
}
}
diff --git a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/FragmentationStrategyBatchExecutor.java b/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/FragmentationStrategyBatchExecutor.java
index b1bdc4c39e..73c64efe0a 100644
--- a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/FragmentationStrategyBatchExecutor.java
+++ b/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/FragmentationStrategyBatchExecutor.java
@@ -1,11 +1,11 @@
package be.vlaanderen.informatievlaanderen.ldes.server.fragmentation;
import be.vlaanderen.informatievlaanderen.ldes.server.domain.model.ViewName;
-import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.entities.BucketisedMember;
+import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.entities.Bucket;
import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.entities.FragmentationMember;
+import io.micrometer.observation.Observation;
import io.micrometer.observation.ObservationRegistry;
-import java.util.List;
import java.util.Objects;
import static io.micrometer.observation.Observation.createNotStarted;
@@ -14,26 +14,23 @@ public class FragmentationStrategyBatchExecutor {
private final FragmentationStrategy fragmentationStrategy;
private final ViewName viewName;
- private final RootBucketRetriever rootBucketRetriever;
private final ObservationRegistry observationRegistry;
@SuppressWarnings("java:S107")
public FragmentationStrategyBatchExecutor(ViewName viewName,
FragmentationStrategy fragmentationStrategy,
- RootBucketRetriever rootBucketRetriever,
ObservationRegistry observationRegistry) {
- this.rootBucketRetriever = rootBucketRetriever;
this.observationRegistry = observationRegistry;
this.fragmentationStrategy = fragmentationStrategy;
this.viewName = viewName;
}
- public List bucketise(FragmentationMember member) {
- var parentObservation = createNotStarted("execute fragmentation", observationRegistry).start();
- final var rootBucket = rootBucketRetriever.retrieveRootBucket(parentObservation);
- List bucketisedMembers = fragmentationStrategy.addMemberToBucket(rootBucket, member, parentObservation);
+ public Bucket bucketise(FragmentationMember member) {
+ final Observation parentObservation = createNotStarted("execute fragmentation", observationRegistry).start();
+ final Bucket rootBucket = Bucket.createRootBucketForView(viewName);
+ fragmentationStrategy.addMemberToBucket(rootBucket, member, parentObservation);
parentObservation.stop();
- return bucketisedMembers;
+ return rootBucket;
}
public boolean isPartOfCollection(String collectionName) {
diff --git a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/FragmentationStrategyDecorator.java b/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/FragmentationStrategyDecorator.java
index ce58eb633f..1c2d7a56e1 100644
--- a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/FragmentationStrategyDecorator.java
+++ b/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/FragmentationStrategyDecorator.java
@@ -1,35 +1,19 @@
package be.vlaanderen.informatievlaanderen.ldes.server.fragmentation;
import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.entities.Bucket;
-import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.entities.BucketisedMember;
import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.entities.FragmentationMember;
-import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.valueobjects.BucketRelation;
-import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.valueobjects.BucketRelationCreatedEvent;
import io.micrometer.observation.Observation;
-import org.springframework.context.ApplicationEventPublisher;
-
-import java.util.List;
public abstract class FragmentationStrategyDecorator implements FragmentationStrategy {
-
private final FragmentationStrategy fragmentationStrategy;
- private final ApplicationEventPublisher applicationEventPublisher;
-
- protected FragmentationStrategyDecorator(FragmentationStrategy fragmentationStrategy,
- ApplicationEventPublisher applicationEventPublisher) {
+ protected FragmentationStrategyDecorator(FragmentationStrategy fragmentationStrategy) {
this.fragmentationStrategy = fragmentationStrategy;
- this.applicationEventPublisher = applicationEventPublisher;
}
@Override
- public List addMemberToBucket(Bucket rootFragmentOfView, FragmentationMember member, Observation parentObservation) {
- return fragmentationStrategy.addMemberToBucket(rootFragmentOfView, member, parentObservation);
- }
-
- protected void addRelationFromParentToChild(Bucket parentBucket, Bucket childBucket) {
- BucketRelation bucketRelation = BucketRelation.createGenericRelation(parentBucket, childBucket);
- applicationEventPublisher.publishEvent(new BucketRelationCreatedEvent(bucketRelation));
+ public void addMemberToBucket(Bucket parentBucket, FragmentationMember member, Observation parentObservation) {
+ fragmentationStrategy.addMemberToBucket(parentBucket, member, parentObservation);
}
}
diff --git a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/FragmentationStrategyImpl.java b/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/FragmentationStrategyImpl.java
index e854d75339..d3be5d5dc2 100644
--- a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/FragmentationStrategyImpl.java
+++ b/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/FragmentationStrategyImpl.java
@@ -1,15 +1,12 @@
package be.vlaanderen.informatievlaanderen.ldes.server.fragmentation;
import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.entities.Bucket;
-import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.entities.BucketisedMember;
import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.entities.FragmentationMember;
import io.micrometer.observation.Observation;
-import java.util.List;
-
public class FragmentationStrategyImpl implements FragmentationStrategy {
@Override
- public List addMemberToBucket(Bucket bucket, FragmentationMember member, Observation parentObservation) {
- return List.of(new BucketisedMember(bucket.getBucketId(), member.getMemberId()));
+ public void addMemberToBucket(Bucket rootBucketOfView, FragmentationMember member, Observation parentObservation) {
+ rootBucketOfView.assignMember(member.getMemberId());
}
}
diff --git a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/RootBucketRetriever.java b/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/RootBucketRetriever.java
deleted file mode 100644
index f0d7386626..0000000000
--- a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/RootBucketRetriever.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package be.vlaanderen.informatievlaanderen.ldes.server.fragmentation;
-
-import be.vlaanderen.informatievlaanderen.ldes.server.domain.model.ViewName;
-import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.entities.Bucket;
-import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.exceptions.MissingRootFragmentException;
-import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.repository.BucketRepository;
-import io.micrometer.observation.Observation;
-import io.micrometer.observation.ObservationRegistry;
-
-public class RootBucketRetriever {
- private final ViewName viewName;
- private final BucketRepository bucketRepository;
- private final ObservationRegistry observationRegistry;
- private Bucket rootBucket;
-
- public RootBucketRetriever(ViewName viewName, BucketRepository bucketRepository, ObservationRegistry observationRegistry) {
- this.viewName = viewName;
- this.bucketRepository = bucketRepository;
- this.observationRegistry = observationRegistry;
- }
-
- public Bucket retrieveRootBucket(Observation parentObservation) {
- final Observation rootRetrievalObservation = Observation
- .createNotStarted("retrieve root of view %s".formatted(viewName.asString()), observationRegistry)
- .parentObservation(parentObservation)
- .start();
-
- if(rootBucket == null) {
- rootBucket = bucketRepository.retrieveRootBucket(viewName)
- .orElseThrow(() -> new MissingRootFragmentException(viewName.asString()));
- }
-
- rootRetrievalObservation.stop();
- return rootBucket;
- }
-}
diff --git a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/batch/BucketJobDefinitions.java b/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/batch/BucketJobDefinitions.java
index 6e90ae92e2..d3f706f925 100644
--- a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/batch/BucketJobDefinitions.java
+++ b/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/batch/BucketJobDefinitions.java
@@ -1,6 +1,6 @@
package be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.batch;
-import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.entities.BucketisedMember;
+import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.entities.Bucket;
import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.entities.FragmentationMember;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.repository.JobRepository;
@@ -8,15 +8,10 @@
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemWriter;
-import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.core.task.SimpleAsyncTaskExecutor;
-import org.springframework.core.task.TaskExecutor;
import org.springframework.transaction.PlatformTransactionManager;
-import java.util.List;
-
@Configuration
public class BucketJobDefinitions {
public static final String BUCKETISATION_STEP = "bucketisation";
@@ -26,23 +21,16 @@ public class BucketJobDefinitions {
public Step bucketiseMembersStep(JobRepository jobRepository,
PlatformTransactionManager transactionManager,
ItemReader memberReader,
- ItemProcessor> viewBucketProcessor,
- ItemWriter> writer,
- BucketMetricUpdater bucketMetricUpdater,
- @Qualifier("bucketTaskExecutor") TaskExecutor taskExecutor) {
+ ItemProcessor bucketProcessor,
+ ItemWriter bucketisationItemWriter,
+ BucketMetricUpdater bucketMetricUpdater) {
return new StepBuilder(BUCKETISATION_STEP, jobRepository)
- .>chunk(CHUNK_SIZE, transactionManager)
+ .chunk(CHUNK_SIZE, transactionManager)
.reader(memberReader)
- .processor(viewBucketProcessor)
- .writer(writer)
+ .processor(bucketProcessor)
+ .writer(bucketisationItemWriter)
.listener(bucketMetricUpdater)
.build();
}
- @Bean("bucketTaskExecutor")
- public TaskExecutor paginationTaskExecutor() {
- var taskExecutor = new SimpleAsyncTaskExecutor("spring_batch");
- taskExecutor.setConcurrencyLimit(1);
- return taskExecutor;
- }
}
diff --git a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/batch/BucketProcessors.java b/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/batch/BucketProcessors.java
index 4b86012728..ee7a5b9827 100644
--- a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/batch/BucketProcessors.java
+++ b/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/batch/BucketProcessors.java
@@ -2,7 +2,7 @@
import be.vlaanderen.informatievlaanderen.ldes.server.domain.model.ViewName;
import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.FragmentationStrategyCollection;
-import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.entities.BucketisedMember;
+import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.entities.Bucket;
import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.entities.FragmentationMember;
import org.springframework.batch.core.configuration.annotation.StepScope;
import org.springframework.batch.item.ItemProcessor;
@@ -10,13 +10,11 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import java.util.List;
-
@Configuration
public class BucketProcessors {
@Bean
@StepScope
- public ItemProcessor> viewBucketProcessor(
+ public ItemProcessor bucketProcessor(
FragmentationStrategyCollection fragmentationStrategyCollection,
@Value("#{jobParameters['collectionName']}") String collectionName,
@Value("#{jobParameters['viewName']}") String viewName
diff --git a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/entities/Bucket.java b/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/entities/Bucket.java
index 9b0aafdc88..9bdabe0890 100644
--- a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/entities/Bucket.java
+++ b/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/entities/Bucket.java
@@ -5,25 +5,29 @@
import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.exceptions.DuplicateFragmentPairException;
import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.valueobjects.BucketDescriptor;
import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.valueobjects.BucketDescriptorPair;
+import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.valueobjects.BucketRelation;
+import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.valueobjects.TreeRelation;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Objects;
-import java.util.Optional;
+import java.util.*;
+import java.util.stream.Stream;
public class Bucket {
- private final long bucketId;
+ private long bucketId;
private final BucketDescriptor bucketDescriptor;
private final ViewName viewName;
+ private final List children;
+ private long assignedMemberId;
- public Bucket(long bucketId, BucketDescriptor bucketDescriptor, ViewName viewName) {
+ public Bucket(long bucketId, BucketDescriptor bucketDescriptor, ViewName viewName, List children, long assignedMemberId) {
this.bucketId = bucketId;
this.bucketDescriptor = bucketDescriptor;
this.viewName = viewName;
+ this.children = new ArrayList<>(children);
+ this.assignedMemberId = assignedMemberId;
}
public Bucket(BucketDescriptor bucketDescriptor, ViewName viewName) {
- this(0, bucketDescriptor, viewName);
+ this(0, bucketDescriptor, viewName, new ArrayList<>(), 0);
}
public static Bucket createRootBucketForView(ViewName viewName) {
@@ -34,12 +38,12 @@ public long getBucketId() {
return bucketId;
}
- public ViewName getViewName() {
- return viewName;
+ public void setBucketId(long bucketId) {
+ this.bucketId = bucketId;
}
- public List getBucketDescriptorPairs() {
- return bucketDescriptor.getDescriptorPairs();
+ public ViewName getViewName() {
+ return viewName;
}
public BucketDescriptor getBucketDescriptor() {
@@ -50,6 +54,26 @@ public String getBucketDescriptorAsString() {
return bucketDescriptor.asDecodedString();
}
+ public ChildBucket addChildBucket(ChildBucket childBucket) {
+ final int index = children.indexOf(childBucket);
+ if (index == -1) {
+ children.add(childBucket);
+ return childBucket;
+ }
+ ChildBucket existingChildBucket = children.get(index);
+ existingChildBucket.addRelations(childBucket.getRelations());
+ return existingChildBucket;
+ }
+
+
+ public ChildBucket withRelations(TreeRelation... relationDefinition) {
+ return new ChildBucket(bucketId, bucketDescriptor, viewName, children, assignedMemberId, Set.of(relationDefinition));
+ }
+
+ public ChildBucket withGenericRelation() {
+ return withRelations(TreeRelation.generic());
+ }
+
public Bucket createChild(BucketDescriptorPair descriptorPair) {
return new Bucket(createChildDescriptor(descriptorPair), viewName);
}
@@ -63,6 +87,40 @@ public BucketDescriptor createChildDescriptor(BucketDescriptorPair descriptorPai
return new BucketDescriptor(childFragmentPairs);
}
+ public void assignMember(long memberId) {
+ assignedMemberId = memberId;
+ }
+
+ public Optional getMember() {
+ return Optional.of(assignedMemberId)
+ .filter(member -> member != 0)
+ .map(member -> new BucketisedMember(bucketId, member));
+ }
+
+ public List getChildren() {
+ return List.copyOf(children);
+ }
+
+ public List getAllDescendants() {
+ return children.stream()
+ .flatMap(child -> Stream.concat(Stream.of(child), child.getAllDescendants().stream()))
+ .toList();
+ }
+
+ public List getBucketTree() {
+ final List bucketTree = new ArrayList<>(List.of(this));
+ getAllDescendants().stream().distinct().forEach(bucketTree::add);
+ return bucketTree;
+ }
+
+ public List getChildRelations() {
+ return children.stream()
+ .flatMap(child -> child.getRelations().stream()
+ .map(relation -> new BucketRelation(createPartialUrl(), child.createPartialUrl(), relation))
+ )
+ .toList();
+ }
+
public String createPartialUrl() {
return "/" + viewName.asString() + (bucketDescriptor.isEmpty() ? "" : "?" + bucketDescriptor.asDecodedString());
}
diff --git a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/entities/ChildBucket.java b/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/entities/ChildBucket.java
new file mode 100644
index 0000000000..6b75a60161
--- /dev/null
+++ b/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/entities/ChildBucket.java
@@ -0,0 +1,26 @@
+package be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.entities;
+
+import be.vlaanderen.informatievlaanderen.ldes.server.domain.model.ViewName;
+import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.valueobjects.BucketDescriptor;
+import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.valueobjects.TreeRelation;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+public class ChildBucket extends Bucket {
+ private final Set relations;
+
+ public ChildBucket(long bucketId, BucketDescriptor bucketDescriptor, ViewName viewName, List children, long assignedMemberId, Set relations) {
+ super(bucketId, bucketDescriptor, viewName, children, assignedMemberId);
+ this.relations = new HashSet<>(relations);
+ }
+
+ public Set getRelations() {
+ return relations;
+ }
+
+ public void addRelations(Set relations) {
+ this.relations.addAll(relations);
+ }
+}
diff --git a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/entities/Fragment.java b/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/entities/Fragment.java
deleted file mode 100644
index 9aa76a9928..0000000000
--- a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/entities/Fragment.java
+++ /dev/null
@@ -1,164 +0,0 @@
-package be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.entities;
-
-import be.vlaanderen.informatievlaanderen.ldes.server.domain.model.FragmentPair;
-import be.vlaanderen.informatievlaanderen.ldes.server.domain.model.LdesFragmentIdentifier;
-import be.vlaanderen.informatievlaanderen.ldes.server.domain.model.TreeRelation;
-import be.vlaanderen.informatievlaanderen.ldes.server.domain.model.ViewName;
-import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.exceptions.DuplicateFragmentPairException;
-import org.jetbrains.annotations.Nullable;
-
-import java.time.LocalDateTime;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Objects;
-import java.util.Optional;
-
-public class Fragment {
-
- public static final String ROOT = "root";
- private final LdesFragmentIdentifier identifier;
- private Boolean immutable;
- private int nrOfMembersAdded;
- private final List relations;
- private LocalDateTime deleteTime;
- private LocalDateTime nextUpdateTs = null;
-
- public Fragment(LdesFragmentIdentifier identifier) {
- this(identifier, false, 0, new ArrayList<>(), null);
- }
-
- public Fragment(LdesFragmentIdentifier identifier, Boolean immutable, int nrOfMembersAdded,
- List relations, LocalDateTime deleteTime) {
- this.identifier = identifier;
- this.immutable = immutable;
- this.nrOfMembersAdded = nrOfMembersAdded;
- this.relations = relations;
- this.deleteTime = deleteTime;
- }
-
- public LdesFragmentIdentifier getFragmentId() {
- return identifier;
- }
-
- public String getFragmentIdString() {
- return identifier.asDecodedFragmentId();
- }
-
- public List getFragmentPairs() {
- return this.identifier.getFragmentPairs();
- }
-
- public void makeImmutable() {
- this.immutable = true;
- }
-
- public boolean isImmutable() {
- return this.immutable;
- }
-
- public Fragment createChild(FragmentPair fragmentPair) {
- List childFragmentPairs = new ArrayList<>(this.identifier.getFragmentPairs().stream().toList());
- if (hasChildWithSameFragmentKey(fragmentPair, childFragmentPairs)) {
- throw new DuplicateFragmentPairException(identifier.asDecodedFragmentId(), fragmentPair.fragmentKey());
- }
- childFragmentPairs.add(fragmentPair);
- return new Fragment(new LdesFragmentIdentifier(getViewName(), childFragmentPairs));
- }
-
- private static boolean hasChildWithSameFragmentKey(FragmentPair fragmentPair, List childFragmentPairs) {
- return childFragmentPairs
- .stream()
- .map(FragmentPair::fragmentKey)
- .anyMatch(key -> key.equals(fragmentPair.fragmentKey()));
- }
-
- public Optional getValueOfKey(String key) {
- return this.identifier.getValueOfFragmentPairKey(key);
- }
-
- public ViewName getViewName() {
- return this.identifier.getViewName();
- }
-
- public int getNrOfMembersAdded() {
- return this.nrOfMembersAdded;
- }
-
- public int incrementNrOfMembersAdded() {
- return this.nrOfMembersAdded++;
- }
-
- public Optional getParentId() {
- return identifier.getParentId();
- }
-
- public String getParentIdAsString() {
- return identifier.getParentId().map(LdesFragmentIdentifier::asDecodedFragmentId).orElse(ROOT);
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o)
- return true;
- if (o == null || getClass() != o.getClass())
- return false;
- Fragment that = (Fragment) o;
- return Objects.equals(getFragmentId(), that.getFragmentId());
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(getFragmentId());
- }
-
- public void addRelation(TreeRelation relation) {
- relations.add(relation);
- }
-
- public boolean containsRelation(TreeRelation parentChildRelation) {
- return relations.contains(parentChildRelation);
- }
-
- public List getRelations() {
- return relations;
- }
-
- public boolean isRoot() {
- return this.identifier.getFragmentPairs().isEmpty();
- }
-
- public LocalDateTime getDeleteTime() {
- return deleteTime;
- }
-
- public void removeRelationToIdentifier(LdesFragmentIdentifier fragmentIdentifier) {
- relations.removeIf(treeRelation -> treeRelation.treeNode().equals(fragmentIdentifier));
- }
-
- public boolean isConnectedTo(Fragment otherFragment) {
- return getRelations()
- .stream()
- .anyMatch(treeRelation -> treeRelation.treeNode()
- .equals(otherFragment.getFragmentId()));
- }
-
- @Nullable
- public LocalDateTime getNextUpdateTs() {
- return nextUpdateTs;
- }
-
- public void setNextUpdateTs(@Nullable LocalDateTime nextUpdateTs) {
- this.nextUpdateTs = nextUpdateTs;
- }
-
- @Override
- public String toString() {
- return "Fragment{" +
- "identifier=" + identifier +
- ", immutable=" + immutable +
- ", nrOfMembersAdded=" + nrOfMembersAdded +
- ", relations=" + relations +
- ", deleteTime=" + deleteTime +
- '}';
- }
-}
diff --git a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/factory/RootFragmentCreator.java b/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/factory/RootFragmentCreator.java
deleted file mode 100644
index f9f394780c..0000000000
--- a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/factory/RootFragmentCreator.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.factory;
-
-import be.vlaanderen.informatievlaanderen.ldes.server.domain.model.ViewName;
-import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.entities.Fragment;
-
-public interface RootFragmentCreator {
-
- Fragment createRootFragmentForView(ViewName viewName);
-
-}
diff --git a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/repository/BucketRepository.java b/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/repository/BucketRepository.java
index 8fa3978003..b2adaec89e 100644
--- a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/repository/BucketRepository.java
+++ b/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/repository/BucketRepository.java
@@ -2,14 +2,10 @@
import be.vlaanderen.informatievlaanderen.ldes.server.domain.model.ViewName;
import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.entities.Bucket;
-import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.valueobjects.BucketDescriptor;
import java.util.Optional;
public interface BucketRepository {
- Optional retrieveBucket(ViewName viewName, BucketDescriptor bucketDescriptor);
-
Bucket insertBucket(Bucket bucket);
-
Optional retrieveRootBucket(ViewName viewName);
}
diff --git a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/repository/BucketisedMemberRepository.java b/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/repository/BucketisedMemberRepository.java
deleted file mode 100644
index eaf60df278..0000000000
--- a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/repository/BucketisedMemberRepository.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.repository;
-
-import be.vlaanderen.informatievlaanderen.ldes.server.domain.model.ViewName;
-
-public interface BucketisedMemberRepository {
- void deleteByViewName(ViewName viewName);
- void deleteByCollection(String collectionName);
-}
diff --git a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/services/MemberRetriever.java b/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/services/MemberRetriever.java
deleted file mode 100644
index d3bd28e84f..0000000000
--- a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/services/MemberRetriever.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.services;
-
-import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.entities.FragmentationMember;
-
-import java.util.Optional;
-
-public interface MemberRetriever {
-
- Optional findFirstByCollectionNameAndSequenceNrGreaterThanAndInEventSource(String collectionName, long sequenceNr);
-}
diff --git a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/valueobjects/BucketRelation.java b/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/valueobjects/BucketRelation.java
index 0dc1bcb726..6453a49df3 100644
--- a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/valueobjects/BucketRelation.java
+++ b/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/valueobjects/BucketRelation.java
@@ -1,17 +1,4 @@
package be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.valueobjects;
-import be.vlaanderen.informatievlaanderen.ldes.server.domain.constants.RdfConstants;
-import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.entities.Bucket;
-
-public record BucketRelation(
- Bucket fromBucket,
- Bucket toBucket,
- String treeRelationType,
- String treeValue,
- String treeValueType,
- String treePath
-) {
- public static BucketRelation createGenericRelation(Bucket fromBucket, Bucket toBucket) {
- return new BucketRelation(fromBucket, toBucket, RdfConstants.GENERIC_TREE_RELATION, "", "", "");
- }
-}
+public record BucketRelation(String fromPartialUrl, String toPartialUrl, TreeRelation relation) {
+}
\ No newline at end of file
diff --git a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/valueobjects/BucketRelationCreatedEvent.java b/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/valueobjects/BucketRelationCreatedEvent.java
deleted file mode 100644
index 27295eb786..0000000000
--- a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/valueobjects/BucketRelationCreatedEvent.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.valueobjects;
-
-public record BucketRelationCreatedEvent(BucketRelation bucketRelation) {
-}
diff --git a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/valueobjects/TreeRelation.java b/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/valueobjects/TreeRelation.java
new file mode 100644
index 0000000000..c3efcde7f0
--- /dev/null
+++ b/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/valueobjects/TreeRelation.java
@@ -0,0 +1,11 @@
+package be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.valueobjects;
+
+import be.vlaanderen.informatievlaanderen.ldes.server.domain.constants.RdfConstants;
+
+public record TreeRelation(String treeRelationType, String treeValue, String treeValueType, String treePath) {
+
+ public static TreeRelation generic() {
+ return new TreeRelation(RdfConstants.GENERIC_TREE_RELATION, "", "", "");
+ }
+
+}
diff --git a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/module-info.java b/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/module-info.java
index e0c48359eb..a139eaa489 100644
--- a/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/module-info.java
+++ b/ldes-fragmentisers/ldes-fragmentisers-common/src/main/java/module-info.java
@@ -1,6 +1,5 @@
open module ldes.fragmentation.domain {
requires ldes.ingest.domain;
- requires ldes.server.retention;
requires ldes.domain;
requires spring.batch.core;
requires spring.batch.infrastructure;
@@ -16,7 +15,5 @@
requires spring.core;
exports be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.entities;
exports be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.repository;
- exports be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.services;
exports be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.valueobjects;
-
}
\ No newline at end of file
diff --git a/ldes-fragmentisers/ldes-fragmentisers-common/src/test/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/FragmentationServiceTest.java b/ldes-fragmentisers/ldes-fragmentisers-common/src/test/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/FragmentationServiceTest.java
index b9870856e7..35af7951dc 100644
--- a/ldes-fragmentisers/ldes-fragmentisers-common/src/test/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/FragmentationServiceTest.java
+++ b/ldes-fragmentisers/ldes-fragmentisers-common/src/test/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/FragmentationServiceTest.java
@@ -33,8 +33,8 @@
@RunWith(SpringRunner.class)
@SpringBatchTest
@EnableAutoConfiguration
-@ContextConfiguration(classes = {SpringBatchConfiguration.class, FragmentationService.class })
-@TestPropertySource(properties = { "ldes-server.fragmentation-cron=*/1 * * * * *"})
+@ContextConfiguration(classes = {SpringBatchConfiguration.class, FragmentationService.class})
+@TestPropertySource(properties = {"ldes-server.fragmentation-cron=*/1 * * * * *"})
class FragmentationServiceTest {
@MockBean(name = BUCKETISATION_STEP)
Step bucketStep;
@@ -87,8 +87,7 @@ void when_unprocessedViews_then_triggerJobsForEachViewThatIsntRunningAlready() t
String collection = "collection";
when(memberMetricsRepository.getUnprocessedViews())
- .thenReturn(List.of(new ViewName(collection, "v1"),
- new ViewName(collection, "v2")));
+ .thenReturn(List.of(new ViewName(collection, "v1"), new ViewName(collection, "v2")));
JobExecution jobExecution = mock(JobExecution.class);
JobParameters jobParameters = new JobParametersBuilder()
diff --git a/ldes-fragmentisers/ldes-fragmentisers-common/src/test/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/FragmentationStrategyBatchCollectionTest.java b/ldes-fragmentisers/ldes-fragmentisers-common/src/test/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/FragmentationStrategyBatchCollectionTest.java
index 6c2aff5693..8100a0c520 100644
--- a/ldes-fragmentisers/ldes-fragmentisers-common/src/test/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/FragmentationStrategyBatchCollectionTest.java
+++ b/ldes-fragmentisers/ldes-fragmentisers-common/src/test/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/FragmentationStrategyBatchCollectionTest.java
@@ -7,7 +7,6 @@
import be.vlaanderen.informatievlaanderen.ldes.server.domain.model.ViewName;
import be.vlaanderen.informatievlaanderen.ldes.server.domain.model.ViewSpecification;
import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.factory.FragmentationStrategyCreator;
-import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.repository.BucketRepository;
import io.micrometer.observation.ObservationRegistry;
import org.junit.jupiter.api.Test;
@@ -21,10 +20,9 @@ class FragmentationStrategyBatchCollectionTest {
private static final String COLLECTION_NAME = "collectionName";
private final FragmentationStrategyCreator fragmentationStrategyCreator = mock(FragmentationStrategyCreator.class);
private final ObservationRegistry observationRegistry = mock(ObservationRegistry.class);
- private final BucketRepository bucketRepository = mock(BucketRepository.class);
private final FragmentationStrategyBatchCollection fragmentationStrategyCollection = new FragmentationStrategyBatchCollection(
- bucketRepository, fragmentationStrategyCreator, observationRegistry);
+ fragmentationStrategyCreator, observationRegistry);
@Test
void when_ViewAddedEventIsReceived_FragmentationStrategyIsAddedToMap() {
@@ -81,9 +79,8 @@ private InitViewAddedResult initAddView() {
ViewSpecification viewSpecification = new ViewSpecification(viewName, List.of(), List.of(), 100);
FragmentationStrategy fragmentationStrategy = mock(FragmentationStrategy.class);
- final var rootBucketRetriever = new RootBucketRetriever(viewName, mock(), observationRegistry);
FragmentationStrategyBatchExecutor fragmentationStrategyExecutor =
- new FragmentationStrategyBatchExecutor(viewName, fragmentationStrategy, rootBucketRetriever, observationRegistry);
+ new FragmentationStrategyBatchExecutor(viewName, fragmentationStrategy, observationRegistry);
return new InitViewAddedResult(viewName, viewSpecification, fragmentationStrategy,
fragmentationStrategyExecutor);
diff --git a/ldes-fragmentisers/ldes-fragmentisers-common/src/test/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/FragmentationStrategyBatchExecutorTest.java b/ldes-fragmentisers/ldes-fragmentisers-common/src/test/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/FragmentationStrategyBatchExecutorTest.java
index cebc5d811b..1f9824a5ac 100644
--- a/ldes-fragmentisers/ldes-fragmentisers-common/src/test/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/FragmentationStrategyBatchExecutorTest.java
+++ b/ldes-fragmentisers/ldes-fragmentisers-common/src/test/java/be/vlaanderen/informatievlaanderen/ldes/server/fragmentation/FragmentationStrategyBatchExecutorTest.java
@@ -30,8 +30,6 @@ class FragmentationStrategyBatchExecutorTest {
private ExecutorService executorService;
@Mock
private FragmentationStrategy fragmentationStrategy;
- @Mock
- private RootBucketRetriever rootBucketRetriever;
@Nested
class ExecuteNext {
@@ -41,16 +39,15 @@ class ExecuteNext {
@Test
void when_ExecuteIsCalled_then_AllLogicIsWrappedByTheExecutorService() {
ObservationRegistry observationRegistry = ObservationRegistry.NOOP;
- var executor = new FragmentationStrategyBatchExecutor(viewName, fragmentationStrategy, rootBucketRetriever,
+ var executor = new FragmentationStrategyBatchExecutor(viewName, fragmentationStrategy,
observationRegistry);
var member = mock(FragmentationMember.class);
executor.bucketise(member);
- verify(rootBucketRetriever).retrieveRootBucket(any());
verify(fragmentationStrategy).addMemberToBucket(any(), eq(member), any());
- verifyNoMoreInteractions(fragmentationStrategy, rootBucketRetriever);
+ verifyNoMoreInteractions(fragmentationStrategy);
}
}
@@ -58,7 +55,7 @@ void when_ExecuteIsCalled_then_AllLogicIsWrappedByTheExecutorService() {
void isPartOfCollection() {
final ViewName viewNameA = ViewName.fromString("col/viewA");
var executorA = new FragmentationStrategyBatchExecutor(viewNameA, null,
- null, null);
+ null);
assertTrue(executorA.isPartOfCollection(viewNameA.getCollectionName()));
assertFalse(executorA.isPartOfCollection("other"));
@@ -68,7 +65,7 @@ void isPartOfCollection() {
void getViewName() {
final ViewName viewNameA = ViewName.fromString("col/viewA");
var executorA = new FragmentationStrategyBatchExecutor(viewNameA, null,
- null, null);
+ null);
assertEquals(viewNameA, executorA.getViewName());
}
@@ -88,19 +85,19 @@ static class EqualityTestProvider implements ArgumentsProvider {
private static final ViewName viewNameA = ViewName.fromString("col/viewA");
private static final FragmentationStrategyBatchExecutor executorA = new FragmentationStrategyBatchExecutor(viewNameA,
- null, null, null);
+ null, null);
@Override
public Stream extends Arguments> provideArguments(ExtensionContext context) {
return Stream.of(
Arguments.of(equals(), executorA, executorA),
Arguments.of(equals(), executorA,
- new FragmentationStrategyBatchExecutor(viewNameA, null, null, null)),
+ new FragmentationStrategyBatchExecutor(viewNameA, null, null)),
Arguments.of(equals(), executorA,
new FragmentationStrategyBatchExecutor(viewNameA, mock(FragmentationStrategy.class),
- mock(RootBucketRetriever.class), mock(ObservationRegistry.class))),
+ mock(ObservationRegistry.class))),
Arguments.of(notEquals(), executorA,
- new FragmentationStrategyBatchExecutor(ViewName.fromString("col/viewB"), null, null, null)));
+ new FragmentationStrategyBatchExecutor(ViewName.fromString("col/viewB"), null, null)));
}
private static BiConsumer
+
+ be.vlaanderen.informatievlaanderen.vsds
+ postgres-liquibase
+ ${project.version}
+ test
+
\ No newline at end of file
diff --git a/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/PageMemberPostgresRepository.java b/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/PageMemberPostgresRepository.java
index fcbe111d7c..9037e48cfb 100644
--- a/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/PageMemberPostgresRepository.java
+++ b/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/PageMemberPostgresRepository.java
@@ -1,6 +1,8 @@
package be.vlaanderen.informatievlaanderen.ldes.server.pagination.postgres;
import be.vlaanderen.informatievlaanderen.ldes.server.domain.model.ViewName;
+import be.vlaanderen.informatievlaanderen.ldes.server.pagination.entities.Page;
+import be.vlaanderen.informatievlaanderen.ldes.server.pagination.postgres.entity.PageEntity;
import be.vlaanderen.informatievlaanderen.ldes.server.pagination.postgres.repository.PageMemberEntityRepository;
import be.vlaanderen.informatievlaanderen.ldes.server.retention.repositories.PageMemberRepository;
import org.springframework.data.jpa.repository.Modifying;
@@ -10,13 +12,13 @@
import java.util.List;
@Repository
-public class PageMemberPostgresRepository implements PageMemberRepository {
+public class PageMemberPostgresRepository implements PageMemberRepository, be.vlaanderen.informatievlaanderen.ldes.server.pagination.repositories.PageMemberRepository {
private final PageMemberEntityRepository entityRepository;
- public PageMemberPostgresRepository(PageMemberEntityRepository entityRepository) {
+ public PageMemberPostgresRepository(PageMemberEntityRepository entityRepository) {
this.entityRepository = entityRepository;
- }
+ }
@Override
@Transactional
@@ -30,4 +32,14 @@ public void setPageMembersToNewPage(long newPageId, List pageIds) {
public void deleteByViewNameAndMembersIds(ViewName viewName, List memberIds) {
entityRepository.deleteAllByBucket_View_EventStream_NameAndBucket_View_NameAndMember_IdIn(viewName.getCollectionName(), viewName.getViewName(), memberIds);
}
+
+ @Override
+ public List getUnpaginatedMembersForBucket(long bucketId) {
+ return entityRepository.findByBucketIdAndPageIdIsNullOrderByMemberId(bucketId);
+ }
+
+ @Override
+ public void assignMembersToPage(Page openPage, List pageMembers) {
+ entityRepository.updatePageForMembers(new PageEntity(openPage.getId()), openPage.getBucketId(), pageMembers);
+ }
}
diff --git a/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/PagePostgresRepository.java b/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/PagePostgresRepository.java
index d625537e2a..56a2cd20b8 100644
--- a/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/PagePostgresRepository.java
+++ b/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/PagePostgresRepository.java
@@ -4,7 +4,9 @@
import be.vlaanderen.informatievlaanderen.ldes.server.fetching.entities.CompactionCandidate;
import be.vlaanderen.informatievlaanderen.ldes.server.pagination.entities.Page;
import be.vlaanderen.informatievlaanderen.ldes.server.pagination.postgres.batch.PaginationRowMapper;
+import be.vlaanderen.informatievlaanderen.ldes.server.pagination.postgres.entity.PageEntity;
import be.vlaanderen.informatievlaanderen.ldes.server.pagination.postgres.repository.PageEntityRepository;
+import be.vlaanderen.informatievlaanderen.ldes.server.pagination.repositories.PageRelationRepository;
import be.vlaanderen.informatievlaanderen.ldes.server.pagination.repositories.PageRepository;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
@@ -12,31 +14,33 @@
import java.time.LocalDateTime;
import java.util.List;
-import java.util.Objects;
import java.util.stream.Stream;
@Repository
public class PagePostgresRepository implements PageRepository {
private final JdbcTemplate jdbcTemplate;
private final PageEntityRepository pageEntityRepository;
+ private final PageRelationRepository pageRelationRepository;
- public PagePostgresRepository(JdbcTemplate jdbcTemplate, PageEntityRepository pageEntityRepository) {
+ public PagePostgresRepository(JdbcTemplate jdbcTemplate, PageEntityRepository pageEntityRepository, PageRelationRepository pageRelationRepository) {
this.jdbcTemplate = jdbcTemplate;
this.pageEntityRepository = pageEntityRepository;
+ this.pageRelationRepository = pageRelationRepository;
}
@Override
@Transactional(readOnly = true)
public Page getOpenPage(long bucketId) {
String sql = """
- select DISTINCT p.page_id, p.bucket_id, p.partial_url, v.page_size, COUNT(member_id) AS assigned_members
- FROM pages p
- LEFT JOIN page_members m ON p.page_id = m.page_id
- JOIN buckets b ON p.bucket_id = b.bucket_id
- JOIN views v ON v.view_id = b.view_id
- where b.bucket_id = ? AND p.page_id NOT IN (SELECT from_page_id FROM page_relations)
- group by p.page_id, v.page_size
- order by page_id
+ select p.page_id, p.bucket_id, p.partial_url, v.page_size, COUNT(member_id) AS assigned_members
+ from pages p
+ left join page_members pm on pm.page_id = p.page_id
+ JOIN buckets b ON p.bucket_id = b.bucket_id
+ JOIN views v ON v.view_id = b.view_id
+ join bucket_last_page blp on blp.bucket_id = b.bucket_id AND blp.last_page_id = p.page_id
+ where b.bucket_id = ?
+ group by p.page_id, v.page_size
+ order by page_id
""";
return jdbcTemplate.query(sql, new PaginationRowMapper(), bucketId)
.stream()
@@ -46,27 +50,15 @@ select DISTINCT p.page_id, p.bucket_id, p.partial_url, v.page_size, COUNT(member
@Override
@Transactional
- public int createPage(Long bucketId, String partialUrl) {
- String sql = """
- INSERT INTO pages (bucket_id, expiration, partial_url)
- VALUES (?, NULL, ?)
- ON CONFLICT (partial_url) DO UPDATE SET bucket_id = pages.bucket_id
- RETURNING page_id;
- """;
+ public Page createNextPage(Page parentPage) {
+ String partialUrl = parentPage.createChildPartialUrl().asString();
+ PageEntity newPage = new PageEntity(parentPage.getBucketId(), partialUrl);
- return Objects.requireNonNull(jdbcTemplate.queryForObject(sql, Long.class, bucketId, partialUrl)).intValue();
- }
+ pageEntityRepository.save(newPage);
+ pageRelationRepository.insertGenericBucketRelation(parentPage.getId(), newPage.getId());
+ pageEntityRepository.setPageImmutable(parentPage.getId());
- @Override
- @Transactional
- public void setPageImmutable(long pageId) {
- pageEntityRepository.setPageImmutable(pageId);
- }
-
- @Override
- @Transactional
- public void setChildrenImmutableByBucketId(long bucketId) {
- pageEntityRepository.setAllChildrenImmutableByBucketId(bucketId);
+ return new Page(newPage.getId(), parentPage.getBucketId(), partialUrl, parentPage.getPageSize());
}
@Override
diff --git a/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/PageRelationPostgresRepository.java b/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/PageRelationPostgresRepository.java
index 7129565ed7..f894a98293 100644
--- a/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/PageRelationPostgresRepository.java
+++ b/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/PageRelationPostgresRepository.java
@@ -1,8 +1,7 @@
package be.vlaanderen.informatievlaanderen.ldes.server.pagination.postgres;
import be.vlaanderen.informatievlaanderen.ldes.server.domain.constants.RdfConstants;
-import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.valueobjects.BucketRelation;
-import be.vlaanderen.informatievlaanderen.ldes.server.pagination.postgres.repository.RelationEntityRepository;
+import be.vlaanderen.informatievlaanderen.ldes.server.pagination.postgres.repository.PageRelationEntityRepository;
import be.vlaanderen.informatievlaanderen.ldes.server.pagination.repositories.PageRelationRepository;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
@@ -11,34 +10,21 @@
@Repository
public class PageRelationPostgresRepository implements PageRelationRepository {
- private final RelationEntityRepository relationEntityRepository;
+ private final PageRelationEntityRepository pageRelationEntityRepository;
- public PageRelationPostgresRepository(RelationEntityRepository relationEntityRepository) {
- this.relationEntityRepository = relationEntityRepository;
+ public PageRelationPostgresRepository(PageRelationEntityRepository pageRelationEntityRepository) {
+ this.pageRelationEntityRepository = pageRelationEntityRepository;
}
@Override
@Transactional
public void insertGenericBucketRelation(long fromPageId, long toPageId) {
- relationEntityRepository.insertRelation(fromPageId, toPageId, RdfConstants.GENERIC_TREE_RELATION);
- }
-
- @Override
- @Transactional
- public void insertBucketRelation(BucketRelation bucketRelation) {
- relationEntityRepository.insertRelation(
- bucketRelation.fromBucket().createPartialUrl(),
- bucketRelation.toBucket().createPartialUrl(),
- bucketRelation.treeRelationType(),
- bucketRelation.treeValue(),
- bucketRelation.treeValueType(),
- bucketRelation.treePath()
- );
+ pageRelationEntityRepository.insertRelation(fromPageId, toPageId, RdfConstants.GENERIC_TREE_RELATION);
}
@Override
@Transactional
public void updateCompactionBucketRelations(List compactedPageIds, long targetId) {
- relationEntityRepository.updateToPageRelations(compactedPageIds, targetId);
+ pageRelationEntityRepository.updateToPageRelations(compactedPageIds, targetId);
}
}
diff --git a/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/TreeNodePostgresRepository.java b/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/TreeNodePostgresRepository.java
index 89e41ac970..e3fb6d592c 100644
--- a/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/TreeNodePostgresRepository.java
+++ b/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/TreeNodePostgresRepository.java
@@ -3,7 +3,7 @@
import be.vlaanderen.informatievlaanderen.ldes.server.domain.events.admin.EventStreamCreatedEvent;
import be.vlaanderen.informatievlaanderen.ldes.server.domain.events.admin.EventStreamDeletedEvent;
import be.vlaanderen.informatievlaanderen.ldes.server.domain.model.EventStream;
-import be.vlaanderen.informatievlaanderen.ldes.server.domain.model.LdesFragmentIdentifier;
+import be.vlaanderen.informatievlaanderen.ldes.server.fetching.valueobjects.LdesFragmentIdentifier;
import be.vlaanderen.informatievlaanderen.ldes.server.fetching.entities.Member;
import be.vlaanderen.informatievlaanderen.ldes.server.fetching.entities.TreeNode;
import be.vlaanderen.informatievlaanderen.ldes.server.fetching.repository.TreeNodeRepository;
@@ -13,7 +13,7 @@
import be.vlaanderen.informatievlaanderen.ldes.server.pagination.postgres.projection.TreeRelationProjection;
import be.vlaanderen.informatievlaanderen.ldes.server.pagination.postgres.repository.PageEntityRepository;
import be.vlaanderen.informatievlaanderen.ldes.server.pagination.postgres.repository.PageMemberEntityRepository;
-import be.vlaanderen.informatievlaanderen.ldes.server.pagination.postgres.repository.RelationEntityRepository;
+import be.vlaanderen.informatievlaanderen.ldes.server.pagination.postgres.repository.PageRelationEntityRepository;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Repository;
@@ -25,13 +25,13 @@
@Repository
public class TreeNodePostgresRepository implements TreeNodeRepository {
private final PageEntityRepository pageEntityRepository;
- private final RelationEntityRepository relationEntityRepository;
+ private final PageRelationEntityRepository pageRelationEntityRepository;
private final PageMemberEntityRepository pageMemberEntityRepository;
private final Map versionObjectCreatorMap = new HashMap<>();
- public TreeNodePostgresRepository(PageEntityRepository pageEntityRepository, RelationEntityRepository relationEntityRepository, PageMemberEntityRepository pageMemberEntityRepository) {
+ public TreeNodePostgresRepository(PageEntityRepository pageEntityRepository, PageRelationEntityRepository pageRelationEntityRepository, PageMemberEntityRepository pageMemberEntityRepository) {
this.pageEntityRepository = pageEntityRepository;
- this.relationEntityRepository = relationEntityRepository;
+ this.pageRelationEntityRepository = pageRelationEntityRepository;
this.pageMemberEntityRepository = pageMemberEntityRepository;
}
@@ -40,7 +40,7 @@ public Optional findByFragmentIdentifier(LdesFragmentIdentifier fragme
return pageEntityRepository
.findTreeNodeByPartialUrl(fragmentIdentifier.asDecodedFragmentId())
.map(page -> {
- final List relations = relationEntityRepository.findDistinctByFromPageId(page.getId());
+ final List relations = pageRelationEntityRepository.findDistinctByFromPageId(page.getId());
var versionObjectCreator = versionObjectCreatorMap.get(page.getCollectionName());
@@ -60,7 +60,7 @@ public Optional findTreeNodeWithoutMembers(LdesFragmentIdentifier frag
return pageEntityRepository
.findTreeNodeByPartialUrl(fragmentIdentifier.asDecodedFragmentId())
.map(page -> {
- final List relations = relationEntityRepository.findDistinctByFromPageId(page.getId());
+ final List relations = pageRelationEntityRepository.findDistinctByFromPageId(page.getId());
return TreeNodeMapper.fromProjection(page, relations, List.of());
});
}
diff --git a/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/batch/BucketPartitioner.java b/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/batch/BucketPartitioner.java
index 40bdd806ce..a31f7f2d08 100644
--- a/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/batch/BucketPartitioner.java
+++ b/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/batch/BucketPartitioner.java
@@ -17,8 +17,7 @@ public class BucketPartitioner implements Partitioner{
static final String SQL = """
SELECT pm.bucket_id
FROM page_members pm
- JOIN buckets b on b.bucket_id = pm.bucket_id
- JOIN views v on v.view_id = b.view_id
+ JOIN views v on v.view_id = pm.view_id
JOIN collections c on c.collection_id = v.collection_id
WHERE c.name = ? AND v.name = ? AND page_id IS NULL
GROUP BY pm.bucket_id
diff --git a/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/batch/PageAssignmentsWriter.java b/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/batch/PageAssignmentsWriter.java
deleted file mode 100644
index ee91c6c072..0000000000
--- a/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/batch/PageAssignmentsWriter.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package be.vlaanderen.informatievlaanderen.ldes.server.pagination.postgres.batch;
-
-import be.vlaanderen.informatievlaanderen.ldes.server.pagination.valueobjects.PageAssignment;
-import org.springframework.batch.item.Chunk;
-import org.springframework.batch.item.ItemWriter;
-import org.springframework.batch.item.database.JdbcBatchItemWriter;
-import org.springframework.batch.item.database.builder.JdbcBatchItemWriterBuilder;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.stereotype.Component;
-
-import javax.sql.DataSource;
-import java.util.Collection;
-import java.util.List;
-
-@Component
-public class PageAssignmentsWriter implements ItemWriter> {
- private final JdbcBatchItemWriter delegateWriter;
-
- public PageAssignmentsWriter(JdbcBatchItemWriter batchItemWriter) {
- this.delegateWriter = batchItemWriter;
- }
-
- @Override
-
- public void write(Chunk extends List> chunk) throws Exception {
- var items = chunk.getItems()
- .stream()
- .flatMap(Collection::stream)
- .toList();
-
- if (!items.isEmpty()) {
- delegateWriter.write(new Chunk<>(items));
- }
- }
-
- @Configuration
- public static class BatchPageAssignmentWriterConfig {
- private static final String SQL = """
- UPDATE page_members
- SET page_id = ?
- WHERE bucket_id = ? AND member_id = ?
- """;
-
- @Bean
- JdbcBatchItemWriter batchPageAssignmentWriter(DataSource dataSource) {
- return new JdbcBatchItemWriterBuilder()
- .dataSource(dataSource)
- .sql(SQL)
- .itemPreparedStatementSetter((item, ps) -> {
- ps.setLong(1, item.pageId());
- ps.setLong(2, item.bucketId());
- ps.setLong(3, item.memberId());
- })
- .build();
- }
- }
-
-}
diff --git a/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/batch/UnpagedReader.java b/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/batch/UnpagedReader.java
deleted file mode 100644
index 46b0f23d8c..0000000000
--- a/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/batch/UnpagedReader.java
+++ /dev/null
@@ -1,80 +0,0 @@
-package be.vlaanderen.informatievlaanderen.ldes.server.pagination.postgres.batch;
-
-import be.vlaanderen.informatievlaanderen.ldes.server.pagination.entities.UnpagedMember;
-import org.springframework.batch.core.configuration.annotation.StepScope;
-import org.springframework.batch.item.ExecutionContext;
-import org.springframework.batch.item.ItemStreamException;
-import org.springframework.batch.item.ItemStreamReader;
-import org.springframework.batch.item.database.JdbcCursorItemReader;
-import org.springframework.batch.item.database.builder.JdbcCursorItemReaderBuilder;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Bean;
-import org.springframework.stereotype.Component;
-
-import javax.sql.DataSource;
-import java.util.ArrayList;
-import java.util.List;
-
-import static be.vlaanderen.informatievlaanderen.ldes.server.pagination.batch.PaginationJobDefinitions.CHUNK_SIZE;
-
-
-@Component
-@StepScope
-public class UnpagedReader implements ItemStreamReader> {
- private static final String SQL = """
- SELECT member_id, bucket_id
- FROM page_members
- WHERE bucket_id = ?
- AND page_id IS NULL
- ORDER BY member_id
- """;
- private final ItemStreamReader delegate;
-
- public UnpagedReader(ItemStreamReader delegate) {
- this.delegate = delegate;
- }
-
- @Override
- public List read() throws Exception {
- List items = new ArrayList<>(CHUNK_SIZE);
-
- for (int i = 0; i < CHUNK_SIZE; i++) {
- UnpagedMember item = delegate.read();
- if (item == null) {
- // If there are no more items, return what we have (even if it's less than the bundle size)
- return items.isEmpty() ? null : items;
- }
- items.add(item);
- }
-
- return items;
- }
-
- @Override
- public void open(ExecutionContext executionContext) throws ItemStreamException {
- delegate.open(executionContext);
- }
-
- @Override
- public void update(ExecutionContext executionContext) throws ItemStreamException {
- delegate.update(executionContext);
- }
-
- @Override
- public void close() throws ItemStreamException {
- delegate.close();
- }
-
- @Bean
- @StepScope
- JdbcCursorItemReader delegateReader(DataSource dataSource,
- @Value("#{stepExecutionContext['bucketId']}") Long bucketId) {
- return new JdbcCursorItemReaderBuilder()
- .name("unpagedReader")
- .dataSource(dataSource)
- .sql(SQL)
- .preparedStatementSetter(ps -> ps.setLong(1, bucketId))
- .rowMapper((rs, rowNum) -> new UnpagedMember(rs.getLong(1), rs.getLong(2)))
- .build();
- }
-}
\ No newline at end of file
diff --git a/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/entity/PageEntity.java b/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/entity/PageEntity.java
index 104c77a579..7bd32d38c5 100644
--- a/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/entity/PageEntity.java
+++ b/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/entity/PageEntity.java
@@ -31,16 +31,19 @@ public class PageEntity {
private String partialUrl;
@OneToMany(mappedBy = "fromPage")
- private List relations;
+ private List relations;
public PageEntity() {
}
- public PageEntity(BucketEntity bucket, String partialUrl, List relations) {
- this.bucket = bucket;
- this.immutable = true;
+ public PageEntity(Long pageId) {
+ this.id = pageId;
+ }
+
+ public PageEntity(Long bucketId, String partialUrl) {
+ this.bucket = new BucketEntity(bucketId);
+ this.immutable = false;
this.partialUrl = partialUrl;
- this.relations = relations;
}
public Long getId() {
@@ -67,11 +70,15 @@ public String getPartialUrl() {
return partialUrl;
}
- public List getRelations() {
+ public List getRelations() {
return relations;
}
public boolean isView() {
return bucket.getView().getComposedViewName().equals("/%s".formatted(partialUrl));
}
+
+ public void setId(Long id) {
+ this.id = id;
+ }
}
diff --git a/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/entity/PageMemberEntity.java b/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/entity/PageMemberEntity.java
index fd5fdf72f3..6612d9a235 100644
--- a/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/entity/PageMemberEntity.java
+++ b/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/entity/PageMemberEntity.java
@@ -28,4 +28,24 @@ public class PageMemberEntity {
@OnDelete(action = OnDeleteAction.CASCADE)
@JoinColumn(name = "page_id", columnDefinition = "BIGINT")
private PageEntity page;
+
+ public void setPage(PageEntity page) {
+ this.page = page;
+ }
+
+ public void setMember(Long memberId) {
+ this.member = new MemberEntity(memberId);
+ }
+
+ public MemberEntity getMember() {
+ return member;
+ }
+
+ public BucketEntity getBucket() {
+ return bucket;
+ }
+
+ public PageEntity getPage() {
+ return page;
+ }
}
diff --git a/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/entity/PageMemberId.java b/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/entity/PageMemberId.java
index 6f1e84351b..b20c6c4bfa 100644
--- a/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/entity/PageMemberId.java
+++ b/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/entity/PageMemberId.java
@@ -13,6 +13,14 @@ public class PageMemberId implements Serializable {
@Column(name = "bucket_id", nullable = false, columnDefinition = "BIGINT")
private Long bucketId;
+ public PageMemberId() {
+ }
+
+ public PageMemberId(Long memberId, Long bucketId) {
+ this.memberId = memberId;
+ this.bucketId = bucketId;
+ }
+
@Override
public final boolean equals(Object o) {
if (this == o) return true;
diff --git a/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/entity/RelationEntity.java b/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/entity/PageRelationEntity.java
similarity index 65%
rename from ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/entity/RelationEntity.java
rename to ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/entity/PageRelationEntity.java
index 2e569cf011..28053b7e7b 100644
--- a/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/entity/RelationEntity.java
+++ b/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/entity/PageRelationEntity.java
@@ -6,7 +6,7 @@
@Entity
@Table(name = "page_relations")
-public class RelationEntity {
+public class PageRelationEntity {
@EmbeddedId
private RelationId relationId;
@@ -34,35 +34,13 @@ public class RelationEntity {
@Column(name = "path", columnDefinition = "VARCHAR(255)")
private String treePath;
-
- public RelationEntity() {
- }
-
- public RelationEntity(PageEntity fromPage, PageEntity toPage, String treeRelationType, String treeValue, String treeValueType, String treePath) {
- this.fromPage = fromPage;
- this.toPage = toPage;
- this.treeRelationType = treeRelationType;
- this.treeValue = treeValue;
- this.treeValueType = treeValueType;
- this.treePath = treePath;
- }
-
- public RelationEntity(RelationId relationId, String treeRelationType, String treeValue, String treeValueType, String treePath) {
- this.relationId = relationId;
- this.treeRelationType = treeRelationType;
- this.treeValue = treeValue;
- this.treeValueType = treeValueType;
- this.treePath = treePath;
+ protected PageRelationEntity() {
}
public RelationId getRelationId() {
return relationId;
}
- public PageEntity getFromPage() {
- return fromPage;
- }
-
public PageEntity getToPage() {
return toPage;
}
diff --git a/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/mapper/TreeRelationMapper.java b/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/mapper/TreeRelationMapper.java
index a6ca3a68a9..3cec2777cd 100644
--- a/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/mapper/TreeRelationMapper.java
+++ b/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/mapper/TreeRelationMapper.java
@@ -1,23 +1,12 @@
package be.vlaanderen.informatievlaanderen.ldes.server.pagination.postgres.mapper;
-import be.vlaanderen.informatievlaanderen.ldes.server.domain.model.LdesFragmentIdentifier;
-import be.vlaanderen.informatievlaanderen.ldes.server.domain.model.TreeRelation;
-import be.vlaanderen.informatievlaanderen.ldes.server.pagination.postgres.entity.RelationEntity;
+import be.vlaanderen.informatievlaanderen.ldes.server.fetching.valueobjects.LdesFragmentIdentifier;
+import be.vlaanderen.informatievlaanderen.ldes.server.fetching.valueobjects.TreeRelation;
import be.vlaanderen.informatievlaanderen.ldes.server.pagination.postgres.projection.TreeRelationProjection;
public class TreeRelationMapper {
private TreeRelationMapper() {}
- public static TreeRelation fromRelationEntity(RelationEntity relationEntity) {
- return new TreeRelation(
- relationEntity.getTreePath(),
- LdesFragmentIdentifier.fromFragmentId(relationEntity.getToPage().getPartialUrl()),
- relationEntity.getTreeValue(),
- relationEntity.getTreeValueType(),
- relationEntity.getTreeRelationType()
- );
- }
-
public static TreeRelation fromProjection(TreeRelationProjection projection) {
return new TreeRelation(
projection.getTreePath(),
diff --git a/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/repository/PageEntityRepository.java b/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/repository/PageEntityRepository.java
index 54558b5551..289e4a77f3 100644
--- a/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/repository/PageEntityRepository.java
+++ b/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/repository/PageEntityRepository.java
@@ -21,18 +21,6 @@ public interface PageEntityRepository extends JpaRepository {
@Query(value = "UPDATE pages SET immutable = true WHERE page_id = ?", nativeQuery = true)
void setPageImmutable(long pageId);
- @Modifying
- @Query(value = """
- update pages set immutable = true
- where page_id in (
- select distinct r.to_page_id from pages p
- inner join buckets b on b.bucket_id = p.bucket_id
- inner join page_relations r on r.from_page_id = p.page_id
- where b.bucket_id = :bucketId
- )
- """, nativeQuery = true)
- void setAllChildrenImmutableByBucketId(long bucketId);
-
@Modifying
@Query(value = """
UPDATE pages
@@ -47,7 +35,7 @@ JOIN views USING (view_id)
@Query(value = "SELECT p.id as fragmentId, COUNT(*) AS size, r.toPage.id AS toPage, p.immutable AS immutable, " +
"p.expiration AS expiration, " +
"p.bucket.bucketId AS bucketId, p.partialUrl AS partialUrl " +
- "FROM PageEntity p JOIN BucketEntity b ON p.bucket = b JOIN ViewEntity v ON b.view = v JOIN RelationEntity r ON p = r.fromPage " +
+ "FROM PageEntity p JOIN BucketEntity b ON p.bucket = b JOIN ViewEntity v ON b.view = v JOIN PageRelationEntity r ON p = r.fromPage " +
"WHERE v.eventStream.name = :collectionName AND v.name = :viewName " +
"GROUP BY p.id, r.toPage.id " +
"HAVING COUNT(*) < :capacityPerPage")
diff --git a/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/repository/PageMemberEntityRepository.java b/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/repository/PageMemberEntityRepository.java
index 860a3ea641..19214a1dab 100644
--- a/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/repository/PageMemberEntityRepository.java
+++ b/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/repository/PageMemberEntityRepository.java
@@ -1,12 +1,14 @@
package be.vlaanderen.informatievlaanderen.ldes.server.pagination.postgres.repository;
import be.vlaanderen.informatievlaanderen.ldes.server.ingest.postgres.projection.TreeMemberProjection;
+import be.vlaanderen.informatievlaanderen.ldes.server.pagination.postgres.entity.PageEntity;
import be.vlaanderen.informatievlaanderen.ldes.server.pagination.postgres.entity.PageMemberEntity;
import be.vlaanderen.informatievlaanderen.ldes.server.pagination.postgres.entity.PageMemberId;
import jakarta.persistence.Tuple;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
import java.util.List;
@@ -14,31 +16,38 @@ public interface PageMemberEntityRepository extends JpaRepository findAllMembersByPageId(long pageId);
- @Modifying
- @Query("UPDATE PageMemberEntity m SET m.page = (SELECT p FROM PageEntity p WHERE p.id = :newPageId) WHERE m.page.id IN (:pageIds)")
- void setPageMembersToNewPage(long newPageId, List pageIds);
+ @Modifying
+ @Query("UPDATE PageMemberEntity m SET m.page = (SELECT p FROM PageEntity p WHERE p.id = :newPageId) WHERE m.page.id IN (:pageIds)")
+ void setPageMembersToNewPage(long newPageId, List pageIds);
@Query(value = """
- select v.name, count(*)
- from page_members
- JOIN buckets b on b.bucket_id = page_members.bucket_id
- JOIN views v on v.view_id = b.view_id
- JOIN collections c on c.collection_id = v.collection_id
- WHERE c.name = :collectionName
- group by v.name
- """, nativeQuery = true)
+ select v.name, vs.bucketized_count as count
+ from view_stats vs
+ JOIN views v on v.view_id = vs.view_id
+ JOIN collections c on c.collection_id = v.collection_id
+ WHERE c.name = :collectionName
+ """, nativeQuery = true)
List getBucketisedMemberCounts(String collectionName);
@Query(value = """
- select v.name, count(*)
- from page_members
- JOIN buckets b on b.bucket_id = page_members.bucket_id
- JOIN views v on v.view_id = b.view_id
- JOIN collections c on c.collection_id = v.collection_id
- WHERE page_id IS NOT NULL AND c.name = :collectionName
- group by v.name
- """, nativeQuery = true)
+ select v.name, vs.paginated_count as count
+ from view_stats vs
+ JOIN views v on v.view_id = vs.view_id
+ JOIN collections c on c.collection_id = v.collection_id
+ WHERE c.name = :collectionName
+ """, nativeQuery = true)
List getPaginatedMemberCounts(String collectionName);
+ @Modifying
+ @Query("""
+ UPDATE PageMemberEntity p SET p.page = :page WHERE p.pageMemberId.bucketId = :bucketId
+ AND p.pageMemberId.memberId IN :memberIds
+ """)
+ void updatePageForMembers(@Param("page") PageEntity page, @Param("bucketId") Long bucketId, @Param("memberIds") List memberIds);
+
+ @Query("SELECT pm.pageMemberId.memberId FROM PageMemberEntity pm WHERE pm.pageMemberId.bucketId = :bucketId AND " +
+ "pm.page IS NULL ORDER BY pm.pageMemberId.memberId")
+ List findByBucketIdAndPageIdIsNullOrderByMemberId(long bucketId);
+
void deleteAllByBucket_View_EventStream_NameAndBucket_View_NameAndMember_IdIn(String collectionName, String viewName, List memberIds);
}
\ No newline at end of file
diff --git a/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/repository/RelationEntityRepository.java b/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/repository/PageRelationEntityRepository.java
similarity index 85%
rename from ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/repository/RelationEntityRepository.java
rename to ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/repository/PageRelationEntityRepository.java
index 02f3293fd6..7f4bf5f80e 100644
--- a/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/repository/RelationEntityRepository.java
+++ b/ldes-server-infra-postgres/postgres-pagination-repository/src/main/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/repository/PageRelationEntityRepository.java
@@ -1,6 +1,6 @@
package be.vlaanderen.informatievlaanderen.ldes.server.pagination.postgres.repository;
-import be.vlaanderen.informatievlaanderen.ldes.server.pagination.postgres.entity.RelationEntity;
+import be.vlaanderen.informatievlaanderen.ldes.server.pagination.postgres.entity.PageRelationEntity;
import be.vlaanderen.informatievlaanderen.ldes.server.pagination.postgres.entity.RelationId;
import be.vlaanderen.informatievlaanderen.ldes.server.pagination.postgres.projection.TreeRelationProjection;
import org.springframework.data.jpa.repository.JpaRepository;
@@ -9,7 +9,7 @@
import java.util.List;
-public interface RelationEntityRepository extends JpaRepository {
+public interface PageRelationEntityRepository extends JpaRepository {
@Modifying
@Query(value = """
@@ -29,7 +29,7 @@ INSERT INTO page_relations (from_page_id, to_page_id, relation_type, value, valu
List findDistinctByFromPageId(long pageId);
@Modifying
- @Query("UPDATE RelationEntity r SET r.toPage = ( SELECT p FROM PageEntity p WHERE p.id = :targetId ) " +
+ @Query("UPDATE PageRelationEntity r SET r.toPage = ( SELECT p FROM PageEntity p WHERE p.id = :targetId ) " +
"WHERE r.toPage.id IN :ids OR r.fromPage.id IN : ids")
void updateToPageRelations(List ids, long targetId);
}
diff --git a/ldes-server-infra-postgres/postgres-pagination-repository/src/test/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/PaginationSteps.java b/ldes-server-infra-postgres/postgres-pagination-repository/src/test/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/PaginationSteps.java
new file mode 100644
index 0000000000..395bb21d35
--- /dev/null
+++ b/ldes-server-infra-postgres/postgres-pagination-repository/src/test/java/be/vlaanderen/informatievlaanderen/ldes/server/pagination/postgres/PaginationSteps.java
@@ -0,0 +1,119 @@
+package be.vlaanderen.informatievlaanderen.ldes.server.pagination.postgres;
+
+import be.vlaanderen.informatievlaanderen.ldes.server.fragmentation.postgres.entity.BucketEntity;
+import be.vlaanderen.informatievlaanderen.ldes.server.pagination.entities.Page;
+import io.cucumber.java.Before;
+import io.cucumber.java.en.And;
+import io.cucumber.java.en.Given;
+import io.cucumber.java.en.Then;
+import io.cucumber.java.en.When;
+
+import java.time.LocalDateTime;
+import java.util.List;
+import java.util.stream.LongStream;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class PaginationSteps extends PostgresPaginationIntegrationTest {
+ private List memberIds;
+ private int pageCount;
+ private Long bucketId;
+ private Integer viewId;
+ private Page openPage;
+
+ @Before
+ public void setUp() {
+ pageCount = pageEntityRepository.findAll().size();
+ final BucketEntity bucket = bucketEntityRepository.findAll().getFirst();
+ bucketId = bucket.getBucketId();
+ viewId = bucket.getView().getId();
+ openPage = pageRepository.getOpenPage(bucketId);
+ }
+
+ @Given("I have {int} unpaged members in one bucket")
+ public void iHaveUnpagedMembersForBucket(int memberCount) {
+ memberIds = LongStream.rangeClosed(1, memberCount).boxed().toList();
+
+ saveMembers(memberIds);
+ saveMemberBuckets(memberIds);
+ }
+
+ @When("I assign the members to the page")
+ public void iAssignTheMembersToThePage() {
+ pageMemberRepository.assignMembersToPage(openPage, memberIds);
+ }
+
+ @Then("I expect a new page is created")
+ public void iExpectANewPageIsCreated() {
+ var currentPageCount = pageEntityRepository.count();
+ assertThat(currentPageCount).isGreaterThan(pageCount);
+ }
+
+ @Then("the open page has space for {int} more members")
+ public void theOpenPageContainsMembers(int memberCount) {
+ var page = pageRepository.getOpenPage(bucketId);
+ assertThat(page.getAvailableMemberSpace()).isEqualTo(memberCount);
+ }
+
+ @Then("I expect no more unpaged members")
+ public void iExpectNoMoreUnpagedMembers() {
+ var unpagedMembersCount = pageMemberEntityRepository.findAll()
+ .stream()
+ .filter(entity -> entity.getBucket() == null)
+ .count();
+ assertThat(unpagedMembersCount).isZero();
+ }
+
+ @When("I create a page given the mutable page")
+ public void iCreateAPageGivenTheMutablePage() {
+ openPage = pageRepository.getOpenPage(bucketId);
+ pageRepository.createNextPage(openPage);
+ }
+
+ @And("The old page has a generic relation to the new page")
+ public void theOldPageHasAGenericRelationToTheNewPage() {
+ var oldOpenPageId = openPage.getId();
+ openPage = pageRepository.getOpenPage(bucketId);
+ var newOpenPageId = openPage.getId();
+
+ var relationPresent = pageRelationEntityRepository.findAll()
+ .stream()
+ .anyMatch(pageRelationEntity ->
+ pageRelationEntity.getRelationId().getFromPageId().equals(oldOpenPageId) &&
+ pageRelationEntity.getRelationId().getToPageId().equals(newOpenPageId) &&
+ pageRelationEntity.getTreeRelationType().equals("https://w3id.org/tree#Relation"));
+
+ assertThat(relationPresent).isTrue();
+ }
+
+ private void saveMembers(List memberIds) {
+ var collectionId = eventStreamEntityRepository.findAll().getFirst().getId();
+ String eventStream = "http://example.com/es";
+ String sql = "INSERT INTO members (subject, collection_id, version_of, timestamp, transaction_id, member_model, old_id) VALUES (?,?,?,?,?,?,?)";
+
+
+ final List