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

42 change decision tree #43

Open
wants to merge 28 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9ac31db
changed decision tree - removed escalationIndex #42
Sep 11, 2024
bdcf060
changed decision tree - added fk and changed description #42
Sep 11, 2024
8843412
changed decision tree - added decision-points #42
Sep 11, 2024
0646311
corrected tests #42
Sep 12, 2024
5688ebd
corrected tests #42
Sep 12, 2024
0602944
Merge remote-tracking branch 'origin/42-change-decision-tree' into 42…
Sep 12, 2024
af7570c
wrong spelling #42
Sep 17, 2024
6568060
wrong spelling #42
Sep 17, 2024
d0923c5
Merge remote-tracking branch 'origin/42-change-decision-tree' into 42…
Sep 17, 2024
66515a3
spelling mistakes and wrong order #42
Sep 24, 2024
1bb4a2c
spelling mistakes and wrong order #42
Sep 24, 2024
bf1251c
Merge remote-tracking branch 'origin/42-change-decision-tree' into 42…
Sep 24, 2024
c9a02b6
improved local deployment
Oct 31, 2024
1a00cdc
:bug: bugfix for changing tree #42
Oct 31, 2024
f5dbdb0
:rotating_light:
Oct 31, 2024
57f68fc
:bug: fixing null check
Nov 13, 2024
5dcc6bc
:art: spotless
Nov 13, 2024
6029538
:bug: fixed equals bug
Nov 13, 2024
4be1022
:art: spotless
Nov 13, 2024
90a4e2d
configurable logback-path
Nov 14, 2024
f0f2efc
banner logback information
Nov 14, 2024
79d79c8
reworked CompetenceService
Dec 3, 2024
b3b9775
:fire: removed special cases of contactpoints
Dec 3, 2024
1e588a4
updated manipulationservice
Dec 3, 2024
88eb352
updated decisiontreeservice
Dec 3, 2024
7d72349
updated relevanceservice
Dec 3, 2024
3ce2824
:rotating_light: spotless
Dec 3, 2024
d70d387
:rotating_light: spotless
Dec 3, 2024
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 @@ -67,20 +67,20 @@ public enum Competence {

// reasons of discrimination
ETHNIC_RACIAL(
"Diskriminierung aufgrund ethnischer oder rassistischer Motive, Religion oder"
+ " Weltanschauung, Alter",
""),
DISABLED("Diskriminierung aufgrund Behinderung", ""),
SEXUAL_IDENTITY("Diskriminierung aufgrund sexueller oder geschlechtlicher Identität", ""),
"wegen rassistischer Motive, der ethnischen Herkunft, Religion, Weltanschauung", ""),
DISABLED("wegen Behinderung", ""),
SEXUAL_IDENTITY("wegen der sexuellen Identität", ""),
AGE("wegen des Alters", ""),
SEXUALITY("wegen des Geschlechts", ""),

// sexual discrimination
EQUALITY("Gleichstellung Mann Frau", ""),
LGBTIQ("LGBTIQ*", ""),

// Health Issues
ADDICTION("Suchtproblem", ""),
PHYSICAL("körperliches Problem", ""),
PSYCHOLOGICAL("psychisches Problem", "");
ADDICTION("Sucht", ""),
PHYSICAL("Körperliche Probleme", ""),
PSYCHOLOGICAL("Psychische Probleme", "");

public final String germanDescription;
public final String shortDescription;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,10 @@ public class CompetenceService {
}

public List<ContactPointView> findAllContactPointsForCompetences(
List<Competence> competences, String department) {
Set<UUID> keys = getContactPointIds(competences);
if (isSpecialCase(competences)) {
keys.addAll(specialCaseContactPoints(competences));
}
return getMatchingContactPoints(department, keys).stream()
.map(mapper::contactPointToView)
.collect(Collectors.toList());
}
List<UUID> foundCPs, List<Competence> competences, String department) {
Set<UUID> keys = new HashSet<>(foundCPs);

public List<ContactPointView> findAllContactPointsForCompetences(List<Competence> competences) {
Set<UUID> keys = getContactPointIds(competences);
if (isSpecialCase(competences)) {
keys.addAll(specialCaseContactPoints(competences));
}
return contactPointRepository.findAllByIdIn(keys).stream()
return getMatchingContactPoints(department, keys).stream()
.map(mapper::contactPointToView)
.collect(Collectors.toList());
}
Expand All @@ -68,6 +56,7 @@ public List<Competence> findAllCompetencesForId(UUID contactPointId) {
}

private List<ContactPoint> getMatchingContactPoints(String department, Set<UUID> keys) {

log.debug("getMatchingContactPoints | department {}", department);
if (department == null) {
return keys.stream()
Expand All @@ -86,6 +75,15 @@ private List<ContactPoint> getMatchingContactPoints(String department, Set<UUID>
.collect(toList());
}

// Extremly hacky workaround for trashy datastructure - please improve in the future
public Competence getCompetenceByEnumString(String enumAsString) {
String splittedString = enumAsString.split("\\.")[1].split("\\(")[0];

log.debug("getCompetenceByEnumString | splittedString {}", splittedString);

return Competence.valueOf(splittedString);
}

@Transactional
public void deleteCompetencesByContactPointId(UUID contactPointId) {
competenceRepository.deleteAllByContactPointId(contactPointId);
Expand All @@ -98,6 +96,7 @@ public void deleteCompetenceAndContactPointPair(
it -> competenceRepository.deleteByContactPointIdAndCompetence(contactPointId, it));
}

@Transactional
public void createCompetenceToContactPoint(UUID contactPointId, Competence competence) {
createCompetenceToContactPoint(new CompetenceToContactPoint(contactPointId, competence));
}
Expand All @@ -124,31 +123,4 @@ private Set<UUID> getContactPointIds(List<Competence> competences) {
}
return matchingKeys;
}

/**
* @param competences - list of competences selected in the decision tree
* @return true if a special case is given A special case are some contact points for juniors.
* These are not only responsible for the Juniors, they are also responsible if an executive
* or employee has a problem with a junior.
*/
private boolean isSpecialCase(List<Competence> competences) {
return ((competences.contains(Competence.EXECUTIVE)
&& competences.contains(Competence.OPPOSITE_JUNIOR))
|| (competences.contains(Competence.EMPLOYEE)
&& competences.contains(Competence.OPPOSITE_JUNIOR)));
}

private Set<UUID> specialCaseContactPoints(List<Competence> competences) {
if (competences.contains(Competence.EXECUTIVE)
&& competences.contains(Competence.OPPOSITE_JUNIOR)) {
competences.remove(Competence.EXECUTIVE);
competences.add(Competence.EXECUTIVE_JUNIOR);
}
if (competences.contains(Competence.EMPLOYEE)
&& competences.contains(Competence.OPPOSITE_JUNIOR)) {
competences.remove(Competence.EMPLOYEE);
competences.add(Competence.EMPLOYEE_JUNIOR);
}
return getContactPointIds(competences);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import de.muenchen.kobit.backend.contactpoint.repository.ContactPointRepository;
import de.muenchen.kobit.backend.contactpoint.view.ContactPointView;
import de.muenchen.kobit.backend.contactpoint.view.ListItemToCompetenceView;
import de.muenchen.kobit.backend.decisiontree.relevance.model.Path;
import de.muenchen.kobit.backend.decisiontree.relevance.model.Relevance;
import de.muenchen.kobit.backend.decisiontree.relevance.model.RelevanceCompetence;
import de.muenchen.kobit.backend.decisiontree.relevance.service.RelevanceService;
import de.muenchen.kobit.backend.decisiontree.relevance.view.RelevanceOrder;
import de.muenchen.kobit.backend.decisiontree.relevance.view.RelevanceView;
Expand All @@ -22,11 +25,7 @@
import de.muenchen.kobit.backend.validation.exception.ContactPointValidationException;
import de.muenchen.kobit.backend.validation.exception.contactpoint.InvalidCompetenceException;
import de.muenchen.kobit.backend.validation.exception.contactpoint.InvalidContactPointException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.UUID;
import java.util.*;
import java.util.stream.Collectors;
import javax.persistence.EntityNotFoundException;
import org.slf4j.Logger;
Expand Down Expand Up @@ -83,10 +82,105 @@ public void updateContactPointCompetence(List<ListItemToCompetenceView> competen
log.debug("updateContactPointCompetence | competences: {}", competences.toString());
log.debug(
"updateContactPointCompetence | competencesViews: {}", competenceViews.toString());
removeContactPointsForCompetence(competences);
updateRelevance(competenceViews, competences);
/**
* For one cp (A) and curent Path (P) and Competences (COM) 1. Get all paths of A expect the
* P 2. Get a unique (optional) list of all the competences from all Paths from 1. 3. Get
* all competences COM of Path P 4. Subtract all competences (of 2.) from COM 5. Remove the
* competences of 4. from the contactpoint A
*/
List<UUID> cpToUpdate = getContactPointsToUpdate(competenceViews, competences);

log.debug("updateContactPointCompetence | CPs to update: {}", cpToUpdate.toString());

cpToUpdate.forEach(cp -> removeUnusedCompetences(cp, competences));

/* competenceViews.forEach(
competenceView ->
removeUnusedCompetences(competenceView.getListItem(), competences));*/

competenceViews.forEach(
it -> saveNewCompetencePair(it.getListItem().getId(), it.getCompetences()));
listItemToCompetenceView ->
saveNewCompetencePair(
listItemToCompetenceView.getListItem().getId(),
listItemToCompetenceView
.getCompetences())); // set new competences for all
updateRelevance(competenceViews, competences);
}

private List<UUID> getContactPointsToUpdate(
List<ListItemToCompetenceView> competenceViews, List<Competence> competences) {
Path currentPath = relevanceService.getPath(new HashSet<>(competences));
if (currentPath == null) {
return Collections.emptyList();
}
log.debug("cpManipulation | pathID: {}", currentPath.getId());

List<UUID> currentCPIds =
relevanceService.getAllRelevancesByPathId(currentPath.getId()).stream()
.map(Relevance::getContactPointId)
.collect(Collectors.toList());
log.debug("getContactPointsToUpdate | currentCPIds: {}", currentCPIds);

List<UUID> receivedCPIds =
competenceViews.stream()
.map(cpv -> cpv.getListItem().getId())
.collect(Collectors.toList());
log.debug("getContactPointsToUpdate | receivedCPIds: {}", receivedCPIds);

currentCPIds.removeAll(receivedCPIds);

return currentCPIds;
}

private void removeUnusedCompetences(UUID cpID, List<Competence> competences) {
log.debug("removeUnusedCompetences | competences: {}", competences.toString());
Path currentPath = relevanceService.getPath(new HashSet<>(competences));
if (currentPath == null) {
return;
}
log.debug("removeUnusedCompetences | currentPath: {}", currentPath.getId().toString());

Set<RelevanceCompetence> otherRelevanceCompetences =
relevanceService.getAllRelevancesByContactPointId(cpID).stream()
.filter(relevance -> !relevance.getPathId().equals(currentPath.getId()))
.map(
relevance ->
relevanceService.getAllRelevanceCompetencesByPathId(
relevance.getPathId()))
.flatMap(Collection::stream)
.collect(Collectors.toSet());
log.debug(
"removeUnusedCompetences | otherRelevanceCompetences: {}",
otherRelevanceCompetences.stream()
.map(RelevanceCompetence::getId)
.collect(Collectors.toList()));

HashSet<RelevanceCompetence> toRemove = new HashSet<>(currentPath.getCompetences());
log.debug(
"removeUnusedCompetences | toRemove: {}",
toRemove.stream().map(RelevanceCompetence::getId).collect(Collectors.toList()));

toRemove.removeAll(otherRelevanceCompetences);

log.debug(
"removeUnusedCompetences | toRemove: {}",
toRemove.stream()
.map(RelevanceCompetence::getCompetence)
.collect(Collectors.toList())
.toString());

List<Competence> competencesToRemove =
toRemove.stream()
.map(
relevanceCompetence ->
competenceService.getCompetenceByEnumString(
relevanceCompetence.getCompetence()))
.collect(Collectors.toList());
log.debug(
"removeUnusedCompetences | competencesToRemove: {}",
competencesToRemove.toString());

competenceService.deleteCompetenceAndContactPointPair(cpID, competencesToRemove);
}

private void updateRelevance(
Expand Down Expand Up @@ -145,15 +239,6 @@ private void validateId(UUID contactPointId, UUID pathID) throws InvalidContactP
}
}

private void removeContactPointsForCompetence(List<Competence> competences) {
List<ContactPointView> existingCompetences =
competenceService.findAllContactPointsForCompetences(competences);
existingCompetences.forEach(
it ->
competenceService.deleteCompetenceAndContactPointPair(
it.getId(), competences));
}

private void saveNewCompetencePair(UUID id, List<Competence> competences) {
for (Competence competence : competences) {
competenceService.createCompetenceToContactPoint(id, competence);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,55 @@
public class DiscriminationBranch {

private final String roleQuestion = "Welche Rolle haben Sie?";
private final String kindOfDiscrimination =
"Aus welchem Grund werden Sie/fühlen Sie sich diskriminiert?";
private final String kindOfDiscrimination = "Aus welchem Grund fühlen Sie sich diskriminiert?";
private final String kindOfSexualDiscrimination =
"Mann-Frau Diskriminierung oder LGBTIQ* Diskriminierung?";

// Welche Rolle haben Sie?
private final DecisionPoint n1 =
new DecisionPoint(
Competence.DISCRIMINATION,
roleQuestion,
List.of(
Competence.EMPLOYEE.toCompetenceView(),
Competence.EXECUTIVE.toCompetenceView(),
Competence.JUNIOR.toCompetenceView()));

// Aus welchem grund fühlen Sie sich diskrimiert?
private final DecisionPoint n2 =
new DecisionPoint(
Competence.EMPLOYEE,
kindOfDiscrimination,
List.of(
Competence.ETHNIC_RACIAL.toCompetenceView(),
Competence.AGE.toCompetenceView(),
Competence.DISABLED.toCompetenceView(),
Competence.SEXUALITY.toCompetenceView(),
Competence.SEXUAL_IDENTITY.toCompetenceView()));
private final DecisionPoint n3 =
new DecisionPoint(
Competence.JUNIOR,
kindOfDiscrimination,
List.of(
Competence.ETHNIC_RACIAL.toCompetenceView(),
Competence.AGE.toCompetenceView(),
Competence.DISABLED.toCompetenceView(),
Competence.SEXUALITY.toCompetenceView(),
Competence.SEXUAL_IDENTITY.toCompetenceView()));

private final DecisionPoint n4 =
new DecisionPoint(
Competence.EXECUTIVE,
kindOfDiscrimination,
List.of(
Competence.ETHNIC_RACIAL.toCompetenceView(),
Competence.AGE.toCompetenceView(),
Competence.DISABLED.toCompetenceView(),
Competence.SEXUALITY.toCompetenceView(),
Competence.SEXUAL_IDENTITY.toCompetenceView()));

// other
private final DecisionPoint n5 =
new DecisionPoint(
Competence.SEXUAL_IDENTITY,
kindOfSexualDiscrimination,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@Component
public class HealthIssuesBranch {

private static final String kindOfHealthIssues = "Welches gesundheitliches Problem haben Sie?";
private static final String kindOfHealthIssues = "Welches gesundheitliche Problem haben Sie?";

private final DecisionPoint n1 =
new DecisionPoint(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ public class MobbingBranch {

private final String whoIsMobbing = "Durch wen werden Sie gemobbt/fühlen Sie sich gemobbt?";

private final String stressQuestion = "Wie hoch ist ihre persönliche Belastung?";
private final String stressQuestion = "Wie hoch ist Ihre persönliche Belastung?";

private final DecisionPoint n1 =
new DecisionPoint(
Competence.MOBBING,
roleQuestion,
List.of(
Competence.EMPLOYEE.toCompetenceView(),
Competence.JUNIOR.toCompetenceView(),
Competence.EXECUTIVE.toCompetenceView()));
Competence.EXECUTIVE.toCompetenceView(),
Competence.JUNIOR.toCompetenceView()));

private final DecisionPoint n2 =
new DecisionPoint(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,31 +85,6 @@ public class WorkConflictBranch {
Competence.STRESS_MEDIUM.toCompetenceView(),
Competence.STRESS_HIGH.toCompetenceView()));

private final DecisionPoint n9 =
new DecisionPoint(
Competence.STRESS_HIGH,
escalationIndex,
List.of(
Competence.ESCALATION_LOW.toCompetenceView(),
Competence.ESCALATION_MEDIUM.toCompetenceView(),
Competence.ESCALATION_HIGH.toCompetenceView()));
private final DecisionPoint n10 =
new DecisionPoint(
Competence.STRESS_MEDIUM,
escalationIndex,
List.of(
Competence.ESCALATION_LOW.toCompetenceView(),
Competence.ESCALATION_MEDIUM.toCompetenceView(),
Competence.ESCALATION_HIGH.toCompetenceView()));
private final DecisionPoint n11 =
new DecisionPoint(
Competence.STRESS_LOW,
escalationIndex,
List.of(
Competence.ESCALATION_LOW.toCompetenceView(),
Competence.ESCALATION_MEDIUM.toCompetenceView(),
Competence.ESCALATION_HIGH.toCompetenceView()));

private final HashMap<Competence, DecisionPoint> branchMap = new HashMap<>();

public WorkConflictBranch() {
Expand All @@ -121,9 +96,6 @@ public WorkConflictBranch() {
branchMap.put(n6.getCompetence(), n6);
branchMap.put(n7.getCompetence(), n7);
branchMap.put(n8.getCompetence(), n8);
branchMap.put(n9.getCompetence(), n9);
branchMap.put(n10.getCompetence(), n10);
branchMap.put(n11.getCompetence(), n11);
}

public DecisionPoint getNextNode(Competence competence) {
Expand Down
Loading
Loading