Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 fixed deletion of contact point #40 #41

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,41 @@
import de.muenchen.kobit.backend.competence.service.CompetenceService;
import de.muenchen.kobit.backend.contact.service.ContactService;
import de.muenchen.kobit.backend.contactpoint.repository.ContactPointRepository;
import de.muenchen.kobit.backend.decisiontree.relevance.service.RelevanceService;
import de.muenchen.kobit.backend.links.service.LinkService;
import java.util.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ContactPointDeletionService {

private static final Logger log = LoggerFactory.getLogger(ContactPointDeletionService.class);
private final ContactPointRepository contactPointRepository;
private final ContactService contactService;
private final LinkService linkService;
private final CompetenceService competenceService;
private final RelevanceService relevanceService;

ContactPointDeletionService(
ContactPointRepository contactPointRepository,
ContactService contactService,
LinkService linkService,
CompetenceService competenceService) {
CompetenceService competenceService,
RelevanceService relevanceService) {
this.contactPointRepository = contactPointRepository;
this.contactService = contactService;
this.linkService = linkService;
this.competenceService = competenceService;
this.relevanceService = relevanceService;
}

@Transactional
public void deleteContactPointView(UUID id) {
log.info("Deleting contact point: {}", id);
deleteRelevance(id);
deleteContacts(id);
deleteCompetences(id);
deleteLinks(id);
Expand All @@ -50,4 +59,8 @@ private void deleteContacts(UUID contactPointId) {
private void deleteContactPoint(UUID id) {
contactPointRepository.deleteById(id);
}

private void deleteRelevance(UUID id) {
relevanceService.deleteAllRelevancesByContactId(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ public interface RelevanceRepository extends JpaRepository<Relevance, RelevanceI

void deleteByPathId(UUID pathId);

void deleteAllByContactPointId(UUID contactPointId);

List<Relevance> findAllByPathId(UUID pathId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -54,6 +55,11 @@ public void setRelevanceOrder(RelevanceView relevanceView) {
}
}

@Transactional
public void deleteAllRelevancesByContactId(UUID contactId) {
relevanceRepository.deleteAllByContactPointId(contactId);
}

private void updateRelevance(List<RelevanceOrder> entries, Path path) {
relevanceRepository.deleteByPathId(path.getId());
createNewRelevanceOrder(entries, path);
Expand Down Expand Up @@ -92,7 +98,7 @@ private Path findExistingPathOrNull(Set<Competence> selectedPath) {
existingPaths.stream()
.filter(it -> hasMatchingCompetences(it, selectedPath))
.collect(Collectors.toList());
if (matchingPaths.size() > 0) {
if (!matchingPaths.isEmpty()) {
return matchingPaths.stream()
.findFirst()
.orElseThrow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import de.muenchen.kobit.backend.competence.service.CompetenceService;
import de.muenchen.kobit.backend.contact.service.ContactService;
import de.muenchen.kobit.backend.contactpoint.repository.ContactPointRepository;
import de.muenchen.kobit.backend.decisiontree.relevance.service.RelevanceService;
import de.muenchen.kobit.backend.links.service.LinkService;
import java.util.UUID;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -17,6 +18,7 @@ class ContactPointDeletionServiceTest {
private final ContactService contactService = mock(ContactService.class);
private final LinkService linkService = mock(LinkService.class);
private final CompetenceService competenceService = mock(CompetenceService.class);
private final RelevanceService relevanceService = mock(RelevanceService.class);

private ContactPointDeletionService deletionService;

Expand All @@ -25,7 +27,11 @@ void init() {
// clearAllCaches();
deletionService =
new ContactPointDeletionService(
contactPointRepository, contactService, linkService, competenceService);
contactPointRepository,
contactService,
linkService,
competenceService,
relevanceService);
}

@Test
Expand All @@ -35,5 +41,6 @@ void deleteContactPointTest() {
verify(competenceService).deleteCompetencesByContactPointId(id);
verify(linkService).deleteLinkByContactPointId(id);
verify(contactService).deleteContactsByContactPointId(id);
verify(relevanceService).deleteAllRelevancesByContactId(id);
}
}
Loading