@@ -34,59 +34,72 @@ public class HybridGradedCommentService {
3434 public HybridGradedCommentDTO persistOrUpdate (HybridGradedCommentDTO hybridGradedCommentDTO ) {
3535 log .debug ("Request to save HybridGradedComment : {}" , hybridGradedCommentDTO );
3636 var hybridGradedComment = hybridGradedCommentMapper .toEntity (hybridGradedCommentDTO );
37- boolean shouldUpdate =false ;
37+ // boolean shouldUpdate = false;
3838
39- if (hybridGradedComment .id != null ){
39+ if (hybridGradedComment .id != null ) {
4040 HybridGradedComment h2 = HybridGradedComment .findById (hybridGradedComment .id );
41- if (h2 != null ){
42- var oldGrade = h2 .grade ;
43- var oldRelative = h2 .relative ;
44- var oldStep = h2 .step ;
45- if (hybridGradedComment .grade != oldGrade || hybridGradedComment .step != oldStep || hybridGradedComment .relative != oldRelative ){
46- shouldUpdate =true ;
47- }
48-
49- }
50- }
51- hybridGradedComment = HybridGradedComment .persistOrUpdate (hybridGradedComment );
52- if (shouldUpdate ){
53- List <Answer2HybridGradedComment > ans = Answer2HybridGradedComment .findAllAnswerHybridGradedCommentByCommentIdWithFetchWithStepvalueUpperThan0 (hybridGradedComment .id ).list (); //.stream().filter(an3 -> an3.stepValue>0).collect(Collectors.toList());
54- for ( Answer2HybridGradedComment an : ans ){
55- var st = an .studentResponse ;
56- var ans2 = an .studentResponse .hybridcommentsValues ;
57-
58- var currentNote = 0.0 ;
59- var absoluteNote2Add = 0.0 ;
60- double pourcentage = 0.0 ;
61- if (st .question != null && st .question .defaultpoint != null ){
62- pourcentage = st .question .defaultpoint .doubleValue () *4 ;
63-
64- }
65- for (Answer2HybridGradedComment an2 : ans2 ){
66- var stepValue = an2 .stepValue !=null ? an2 .stepValue .doubleValue (): 0.0 ;
67- if (stepValue > 0 ) {
68- var relative = an2 .hybridcomments .relative != null ? an2 .hybridcomments .relative : false ;
69- var step = an2 .hybridcomments .step != null ? an2 .hybridcomments .step .doubleValue () : 1.0 ;
70- var grade = an2 .hybridcomments .grade != null ? an2 .hybridcomments .grade .doubleValue () : 0.0 ;
71- if (relative ) {
72- pourcentage = pourcentage + (stepValue / step ) * grade ;
73- } else {
74- absoluteNote2Add = absoluteNote2Add + (stepValue / step ) * grade ;
41+ if (h2 != null ) {
42+ var oldGrade = h2 .grade ;
43+ var oldRelative = h2 .relative ;
44+ var oldStep = h2 .step ;
45+ if (hybridGradedComment .grade != oldGrade || hybridGradedComment .step != oldStep
46+ || hybridGradedComment .relative != oldRelative ) {
47+ List <Answer2HybridGradedComment > ans = Answer2HybridGradedComment
48+ .findAllAnswerHybridGradedCommentByCommentIdWithFetchWithStepvalueUpperThan0 (
49+ hybridGradedComment .id )
50+ .list (); // .stream().filter(an3 -> an3.stepValue>0).collect(Collectors.toList());
51+ for (Answer2HybridGradedComment an : ans ) {
52+ var st = an .studentResponse ;
53+ var ans2 = an .studentResponse .hybridcommentsValues ;
54+
55+ var currentNote = 0.0 ;
56+ var absoluteNote2Add = 0.0 ;
57+ double pourcentage = 0.0 ;
58+ if (st .question != null && st .question .defaultpoint != null ) {
59+ pourcentage = st .question .defaultpoint .doubleValue () * 4 ;
60+
61+ }
62+ for (Answer2HybridGradedComment an2 : ans2 ) {
63+ var stepValue = an2 .stepValue != null ? an2 .stepValue .doubleValue () : 0.0 ;
64+ if (stepValue > 0 ) {
65+ var relative = an2 .hybridcomments .relative != null ? an2 .hybridcomments .relative
66+ : false ;
67+ var step = an2 .hybridcomments .step != null ? an2 .hybridcomments .step .doubleValue ()
68+ : 1.0 ;
69+ var grade = an2 .hybridcomments .grade != null ? an2 .hybridcomments .grade .doubleValue ()
70+ : 0.0 ;
71+ if (relative ) {
72+ pourcentage = pourcentage + (stepValue / step ) * grade ;
73+ } else {
74+ absoluteNote2Add = absoluteNote2Add + (stepValue / step ) * grade ;
75+ }
7576 }
76- }
77- }
78- var point = st .question .quarterpoint !=null ? st .question .quarterpoint .doubleValue (): 0.0 ;
79- currentNote = (point * pourcentage ) / 400.0 + absoluteNote2Add ;
80- if (currentNote > point && !st .question .canExceedTheMax ) {
81- currentNote = point ;
82- } else if (currentNote < 0 && !st .question .canBeNegative ) {
83- currentNote = 0 ;
77+ }
78+ var point = st .question .quarterpoint != null ? st .question .quarterpoint .doubleValue () : 0.0 ;
79+ currentNote = (point * pourcentage ) / 400.0 + absoluteNote2Add ;
80+ if (currentNote > point && !st .question .canExceedTheMax ) {
81+ currentNote = point ;
82+ } else if (currentNote < 0 && !st .question .canBeNegative ) {
83+ currentNote = 0 ;
84+ }
85+ st .quarternote = Double .valueOf (currentNote * 100 ).intValue ();
86+ st .persistOrUpdate ();
8487 }
85- st .quarternote = Double .valueOf (currentNote *100 ).intValue ();
86- st .persistOrUpdate ();
8788 }
89+
8890 }
8991
92+ h2 .description = hybridGradedComment .description ;
93+ h2 .grade = hybridGradedComment .grade ;
94+ h2 .relative = hybridGradedComment .relative ;
95+ h2 .step = hybridGradedComment .step ;
96+ h2 .text = hybridGradedComment .text ;
97+ hybridGradedComment = HybridGradedComment .persistOrUpdate (h2 );
98+
99+
100+ } else {
101+ hybridGradedComment = HybridGradedComment .persistOrUpdate (hybridGradedComment );
102+ }
90103
91104 return hybridGradedCommentMapper .toDto (hybridGradedComment );
92105 }
@@ -101,10 +114,10 @@ public void delete(Long id) {
101114 log .debug ("Request to delete HybridGradedComment : {}" , id );
102115 this .answer2HybridGradedCommentService .deleteAllAnswerHybridGradedCommentByCommentId (id );
103116 HybridGradedComment
104- .findByIdOptional (id )
105- .ifPresent (hybridGradedComment -> {
106- hybridGradedComment .delete ();
107- });
117+ .findByIdOptional (id )
118+ .ifPresent (hybridGradedComment -> {
119+ hybridGradedComment .delete ();
120+ });
108121 }
109122
110123 /**
@@ -116,23 +129,25 @@ public void delete(Long id) {
116129 public Optional <HybridGradedCommentDTO > findOne (Long id ) {
117130 log .debug ("Request to get HybridGradedComment : {}" , id );
118131 return HybridGradedComment
119- .findByIdOptional (id )
120- .map (hybridGradedComment -> hybridGradedCommentMapper .toDto ((HybridGradedComment ) hybridGradedComment ));
132+ .findByIdOptional (id )
133+ .map (hybridGradedComment -> hybridGradedCommentMapper .toDto ((HybridGradedComment ) hybridGradedComment ));
121134 }
122135
123136 /**
124137 * Get all the hybridGradedComments.
138+ *
125139 * @param page the pagination information.
126140 * @return the list of entities.
127141 */
128142 public Paged <HybridGradedCommentDTO > findAll (Page page ) {
129143 log .debug ("Request to get all HybridGradedComments" );
130144 return new Paged <>(HybridGradedComment .findAll ().page (page ))
131- .map (hybridGradedComment -> hybridGradedCommentMapper .toDto ((HybridGradedComment ) hybridGradedComment ));
145+ .map (hybridGradedComment -> hybridGradedCommentMapper .toDto ((HybridGradedComment ) hybridGradedComment ));
132146 }
133147
134148 public Paged <HybridGradedCommentDTO > findHybridGradedCommentByQuestionId (Page page , long qId ) {
135- log .debug ("Request to get all GradedComments by QID" );
149+ log .debug ("Request to get all GradedComments by QID" );
136150 return new Paged <>(HybridGradedComment .findByQuestionId (qId ).page (page ))
137- .map (hgradedComment -> hybridGradedCommentMapper .toDto ((HybridGradedComment ) hgradedComment )); }
151+ .map (hgradedComment -> hybridGradedCommentMapper .toDto ((HybridGradedComment ) hgradedComment ));
152+ }
138153}
0 commit comments