Skip to content
Snippets Groups Projects
Commit a57f08c7 authored by Jan Tymel's avatar Jan Tymel
Browse files

Add OneToMany mapping of QuestionPhaseRelation to TrainingPhase

Resolves #7
parent 7a3f8de8
No related branches found
No related tags found
No related merge requests found
...@@ -26,7 +26,7 @@ public class QuestionPhaseRelation { ...@@ -26,7 +26,7 @@ public class QuestionPhaseRelation {
private QuestionnairePhase questionnairePhase; private QuestionnairePhase questionnairePhase;
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
private TrainingPhase relatedPhase; private TrainingPhase relatedTrainingPhase;
@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST) @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
@JoinTable(name = "question_phase_relation_question", @JoinTable(name = "question_phase_relation_question",
...@@ -61,12 +61,12 @@ public class QuestionPhaseRelation { ...@@ -61,12 +61,12 @@ public class QuestionPhaseRelation {
this.questionnairePhase = questionnairePhase; this.questionnairePhase = questionnairePhase;
} }
public TrainingPhase getRelatedPhase() { public TrainingPhase getRelatedTrainingPhase() {
return relatedPhase; return relatedTrainingPhase;
} }
public void setRelatedPhase(TrainingPhase relatedPhase) { public void setRelatedTrainingPhase(TrainingPhase relatedPhase) {
this.relatedPhase = relatedPhase; this.relatedTrainingPhase = relatedPhase;
} }
public Set<Question> getQuestions() { public Set<Question> getQuestions() {
......
...@@ -23,6 +23,10 @@ public class TrainingPhase extends AbstractPhase { ...@@ -23,6 +23,10 @@ public class TrainingPhase extends AbstractPhase {
@OneToMany(mappedBy = "trainingPhase", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) @OneToMany(mappedBy = "trainingPhase", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
private List<DecisionMatrixRow> decisionMatrix; private List<DecisionMatrixRow> decisionMatrix;
@OrderBy
@OneToMany(mappedBy = "relatedTrainingPhase", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
private List<QuestionPhaseRelation> questionPhaseRelations = new ArrayList<>();
public String getEstimatedDuration() { public String getEstimatedDuration() {
return estimatedDuration; return estimatedDuration;
} }
...@@ -62,4 +66,12 @@ public class TrainingPhase extends AbstractPhase { ...@@ -62,4 +66,12 @@ public class TrainingPhase extends AbstractPhase {
public void setDecisionMatrix(List<DecisionMatrixRow> decisionMatrix) { public void setDecisionMatrix(List<DecisionMatrixRow> decisionMatrix) {
this.decisionMatrix = decisionMatrix; this.decisionMatrix = decisionMatrix;
} }
public List<QuestionPhaseRelation> getQuestionPhaseRelations() {
return questionPhaseRelations;
}
public void setQuestionPhaseRelations(List<QuestionPhaseRelation> questionPhaseRelations) {
this.questionPhaseRelations = questionPhaseRelations;
}
} }
...@@ -2,11 +2,6 @@ package com.example.demo.repository; ...@@ -2,11 +2,6 @@ package com.example.demo.repository;
import com.example.demo.domain.QuestionPhaseRelation; import com.example.demo.domain.QuestionPhaseRelation;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
public interface QuestionPhaseRelationRepository extends JpaRepository<QuestionPhaseRelation, Long> { public interface QuestionPhaseRelationRepository extends JpaRepository<QuestionPhaseRelation, Long> {
@Query("SELECT COALESCE(MAX(q.order), -1) FROM QuestionPhaseRelation q WHERE q.questionnairePhase.id = :phaseId")
Integer getCurrentMaxOrder(@Param("phaseId") Long phaseId);
} }
...@@ -127,7 +127,7 @@ public class QuestionnairePhaseService { ...@@ -127,7 +127,7 @@ public class QuestionnairePhaseService {
questionPhaseRelation.setOrder(order); questionPhaseRelation.setOrder(order);
questionPhaseRelation.setSuccessRate(phaseRelation.getSuccessRate()); questionPhaseRelation.setSuccessRate(phaseRelation.getSuccessRate());
questionPhaseRelation.setRelatedPhase(trainingPhase); questionPhaseRelation.setRelatedTrainingPhase(trainingPhase);
questionPhaseRelation.setQuestionnairePhase(questionnairePhase); questionPhaseRelation.setQuestionnairePhase(questionnairePhase);
questionnairePhaseRelations.add(questionPhaseRelation); questionnairePhaseRelations.add(questionPhaseRelation);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment