Skip to content

Commit

Permalink
Feature: VSDSPUB-349: Add Gone status to soft deleted fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
WLefever-Cegeka committed Nov 17, 2022
1 parent a3c3130 commit adf29cb
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 50 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package be.vlaanderen.informatievlaanderen.ldes.server.domain.exceptions;

public class DeletedFragmentException extends RuntimeException {
private final String fragmentId;

public DeletedFragmentException(String fragmentId) {
super();
this.fragmentId = fragmentId;
}

@Override
public String getMessage() {
return "Fragment with following identifier has been deleted: " + fragmentId;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ public void setSoftDeleted(boolean softDeleted) {
this.fragmentInfo.setSoftDeleted(softDeleted);
}

public void setSoftDeleted(boolean softDeleted) {
this.fragmentInfo.setSoftDeleted(softDeleted);
}

public boolean isImmutable() {
return this.fragmentInfo.getImmutable();
}
Expand All @@ -75,4 +71,8 @@ public LdesFragment createChild(FragmentPair fragmentPair) {
public void removeRelation(TreeRelation treeRelation) {
relations.remove(treeRelation);
}

public boolean isSoftDeleted() {
return this.getFragmentInfo().getSoftDeleted();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Optional<LdesFragment> retrieveMutableFragment(String viewName,

Optional<LdesFragment> retrieveRootFragment(String viewName);

Stream<LdesFragment> retrieveImmutableFragmentsOfView(String viewName);
Stream<LdesFragment> retrieveNonDeletedImmutableFragmentsOfView(String viewName);

Optional<LdesFragment> retrieveNonDeletedChildFragment(String viewName,
List<FragmentPair> fragmentPairList);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package be.vlaanderen.informatievlaanderen.ldes.server.domain.ldesfragment.services;

import be.vlaanderen.informatievlaanderen.ldes.server.domain.config.LdesConfig;
import be.vlaanderen.informatievlaanderen.ldes.server.domain.exceptions.DeletedFragmentException;
import be.vlaanderen.informatievlaanderen.ldes.server.domain.exceptions.MissingFragmentException;
import be.vlaanderen.informatievlaanderen.ldes.server.domain.ldesfragment.entities.LdesFragment;
import be.vlaanderen.informatievlaanderen.ldes.server.domain.ldesfragment.repository.LdesFragmentRepository;
Expand All @@ -22,12 +23,16 @@ public FragmentFetchServiceImpl(LdesConfig ldesConfig,

@Override
public LdesFragment getFragment(LdesFragmentRequest ldesFragmentRequest) {
return ldesFragmentRepository
LdesFragment ldesFragment = ldesFragmentRepository
.retrieveFragment(ldesFragmentRequest)
.orElseThrow(
() -> new MissingFragmentException(

ldesConfig.getHostName() + new FragmentInfo(ldesFragmentRequest.viewName(),
ldesFragmentRequest.fragmentPairs()).generateFragmentId()));
if (ldesFragment.isSoftDeleted())
throw new DeletedFragmentException(
ldesConfig.getHostName() + new FragmentInfo(ldesFragmentRequest.viewName(),
ldesFragmentRequest.fragmentPairs()).generateFragmentId());
return ldesFragment;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public TreeNodeRemoverImpl(LdesFragmentRepository ldesFragmentRepository,
public void removeTreeNodes() {
retentionPolicyMap.forEach((view, retentionPolicies) -> {
List<LdesFragment> ldesFragments = ldesFragmentRepository
.retrieveImmutableFragmentsOfView(view)
.retrieveNonDeletedImmutableFragmentsOfView(view)
.filter(ldesFragment -> retentionPolicies
.stream()
.allMatch(retentionPolicy -> retentionPolicy.matchesPolicy(ldesFragment)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,6 @@ public void setSoftDeleted(Boolean softDeleted) {
this.softDeleted = softDeleted;
}

public Boolean getSoftDeleted() {
return softDeleted;
}

public void setSoftDeleted(Boolean softDeleted) {
this.softDeleted = softDeleted;
}

public FragmentInfo createChild(FragmentPair fragmentPair) {
ArrayList<FragmentPair> childFragmentPairs = new ArrayList<>(this.fragmentPairs.stream().toList());
childFragmentPairs.add(fragmentPair);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public TreeMemberRemoverImpl(MemberReferencesRepository memberReferencesReposito
public void tryRemovingMember(String memberId) {
if (!memberReferencesRepository.hasMemberReferences(memberId)) {
memberRepository.deleteMember(memberId);
memberReferencesRepository.deleteMemberReference(memberId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ public interface MemberReferencesRepository {

boolean hasMemberReferences(final String memberId);

void deleteMemberReference(String memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ class TreeNodeRemoverImplTest {
void when_NodeIsImmutableAndSatisfiesRetentionPoliciesOfView_NodeCanBeSoftDeleted() {
LdesFragment notReadyToDeleteFragment = notReadyToDeleteFragment();
LdesFragment readyToDeleteFragment = readyToDeleteFragment();
when(fragmentRepository.retrieveImmutableFragmentsOfView("view"))
when(fragmentRepository.retrieveNonDeletedImmutableFragmentsOfView("view"))
.thenReturn(Stream.of(notReadyToDeleteFragment, readyToDeleteFragment));

treeNodeRemover.removeTreeNodes();

verify(fragmentRepository, times(1)).retrieveImmutableFragmentsOfView("view");
verify(fragmentRepository, times(1)).retrieveNonDeletedImmutableFragmentsOfView("view");
verify(fragmentRepository, times(1)).saveFragment(readyToDeleteFragment);
assertTrue(readyToDeleteFragment.getFragmentInfo().getSoftDeleted());
verifyNoMoreInteractions(fragmentRepository);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ public Optional<LdesFragment> retrieveRootFragment(String viewName) {
}

@Override
public Stream<LdesFragment> retrieveImmutableFragmentsOfView(String viewName) {
public Stream<LdesFragment> retrieveNonDeletedImmutableFragmentsOfView(String viewName) {
return repository
.findAllByImmutableAndViewName(true, viewName)
.findAllByImmutableAndSoftDeletedAndViewName(true, false, viewName)
.stream()
.map(LdesFragmentEntity::toLdesFragment);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ public synchronized boolean hasMemberReferences(String memberId) {
.map(MemberReferencesEntity::hasMemberReferences)
.orElseThrow(() -> new MemberNotFoundException(memberId));
}

@Override
public synchronized void deleteMemberReference(String memberId) {
repository.deleteById(memberId);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@ Optional<LdesFragmentEntity> findLdesFragmentEntityByRootAndViewName(
List<LdesFragmentEntity> findAllByImmutableAndViewName(
Boolean immutable, String viewName);

List<LdesFragmentEntity> findAllByImmutableAndSoftDeletedAndViewName(Boolean immutable, Boolean softDeleted,
String viewName);

List<LdesFragmentEntity> findAllBySoftDeletedAndViewName(Boolean softDeleted, String viewName);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package be.vlaanderen.informatievlaanderen.ldes.server.rest.exceptionhandling;

import be.vlaanderen.informatievlaanderen.ldes.server.domain.exceptions.DeletedFragmentException;
import be.vlaanderen.informatievlaanderen.ldes.server.domain.exceptions.MissingFragmentException;
import be.vlaanderen.informatievlaanderen.ldes.server.domain.exceptions.RdfFormatException;
import org.springframework.http.HttpHeaders;
Expand All @@ -22,6 +23,14 @@ protected ResponseEntity<Object> handleMissingFragmentException(
new HttpHeaders(), HttpStatus.NOT_FOUND, request);
}

@ExceptionHandler(value = { DeletedFragmentException.class })
protected ResponseEntity<Object> handleDeletedFragmentException(
RuntimeException ex, WebRequest request) {
String bodyOfResponse = ex.getMessage();
return handleExceptionInternal(ex, bodyOfResponse,
new HttpHeaders(), HttpStatus.GONE, request);
}

@ExceptionHandler(value = { RdfFormatException.class })
protected ResponseEntity<Object> handleRdfFormatException(
RuntimeException ex, WebRequest request) {
Expand Down

0 comments on commit adf29cb

Please sign in to comment.