/
Proposal.java
1111 lines (953 loc) · 39.9 KB
/
Proposal.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package org.xcolab.client.proposals.pojo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import edu.mit.cci.roma.client.Scenario;
import edu.mit.cci.roma.client.Simulation;
import org.apache.commons.lang3.StringUtils;
import org.xcolab.client.admin.ContestTypeClient;
import org.xcolab.client.admin.attributes.configuration.ConfigurationAttributeKey;
import org.xcolab.client.admin.attributes.platform.PlatformAttributeKey;
import org.xcolab.client.admin.pojo.ContestType;
import org.xcolab.client.comment.CommentClient;
import org.xcolab.client.comment.ThreadClient;
import org.xcolab.client.comment.pojo.CommentThread;
import org.xcolab.client.contest.ContestClient;
import org.xcolab.client.contest.ContestClientUtil;
import org.xcolab.client.contest.ContestTeamMemberClient;
import org.xcolab.client.contest.ContestTeamMemberClientUtil;
import org.xcolab.client.contest.ProposalTemplateClient;
import org.xcolab.client.contest.ProposalTemplateClientUtil;
import org.xcolab.client.contest.exceptions.ContestNotFoundException;
import org.xcolab.client.contest.pojo.Contest;
import org.xcolab.client.contest.pojo.phases.ContestPhase;
import org.xcolab.client.contest.pojo.templates.ProposalTemplate;
import org.xcolab.client.contest.pojo.templates.ProposalTemplateSectionDefinition;
import org.xcolab.client.members.MembersClient;
import org.xcolab.client.members.exceptions.MemberNotFoundException;
import org.xcolab.client.members.pojo.Member;
import org.xcolab.client.modeling.roma.RomaClientUtil;
import org.xcolab.client.proposals.MembershipClient;
import org.xcolab.client.proposals.MembershipClientUtil;
import org.xcolab.client.proposals.ProposalAttributeClient;
import org.xcolab.client.proposals.ProposalAttributeClientUtil;
import org.xcolab.client.proposals.ProposalClient;
import org.xcolab.client.proposals.ProposalClientUtil;
import org.xcolab.client.proposals.ProposalJudgeRatingClient;
import org.xcolab.client.proposals.ProposalJudgeRatingClientUtil;
import org.xcolab.client.proposals.ProposalMemberRatingClient;
import org.xcolab.client.proposals.ProposalMemberRatingClientUtil;
import org.xcolab.client.proposals.ProposalPhaseClient;
import org.xcolab.client.proposals.ProposalPhaseClientUtil;
import org.xcolab.client.proposals.enums.ProposalAttributeKeys;
import org.xcolab.client.proposals.enums.ProposalUnversionedAttributeName;
import org.xcolab.client.proposals.exceptions.Proposal2PhaseNotFoundException;
import org.xcolab.client.proposals.helpers.ProposalAttributeHelper;
import org.xcolab.client.proposals.helpers.ProposalContestPhaseAttributeHelper;
import org.xcolab.client.proposals.helpers.ProposalUnversionedAttributeHelper;
import org.xcolab.client.proposals.pojo.attributes.ProposalAttribute;
import org.xcolab.client.proposals.pojo.attributes.ProposalUnversionedAttribute;
import org.xcolab.client.proposals.pojo.evaluation.judges.ProposalRating;
import org.xcolab.client.proposals.pojo.phases.Proposal2Phase;
import org.xcolab.client.proposals.pojo.phases.ProposalContestPhaseAttribute;
import org.xcolab.client.proposals.pojo.proposals.ProposalRatings;
import org.xcolab.client.proposals.pojo.proposals.ProposalRibbon;
import org.xcolab.client.proposals.pojo.team.ProposalTeamMembershipRequest;
import org.xcolab.commons.html.HtmlUtil;
import org.xcolab.util.enums.contest.ProposalContestPhaseAttributeKeys;
import org.xcolab.util.enums.membershiprequest.MembershipRequestStatus;
import org.xcolab.util.enums.modeling.ModelRegions;
import org.xcolab.util.enums.promotion.AssessmentStatus;
import org.xcolab.util.enums.promotion.ContestPhasePromoteType;
import org.xcolab.util.enums.promotion.JudgingSystemActions;
import org.xcolab.util.http.caching.CacheName;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(Include.NON_NULL)
public class Proposal extends AbstractProposal implements Serializable {
private static final Long LONG_DEFAULT_VAL = -1L;
private static final String STRING_DEFAULT_VAL = "";
private final Clients clients;
protected final Contest contest;
protected final ContestPhase contestPhase;
protected final Proposal2Phase proposal2Phase;
protected final ProposalContestPhaseAttributeHelper proposalContestPhaseAttributeHelper;
private final ProposalAttributeHelper proposalAttributeHelper;
private final ProposalUnversionedAttributeHelper unversionedAttributeHelper;
protected List<ProposalTeamMember> members;
private List<ProposalTemplateSectionDefinition> sections;
protected ProposalRatings proposalRatings;
private ProposalRibbon ribbonWrapper;
private List<ProposalTeamMembershipRequest> membershipRequests;
private List<Member> supporters;
public Proposal(Proposal proposal, ContestPhase contestPhase) {
this(proposal, proposal.getCurrentVersion(), null, contestPhase, null);
}
public Proposal(Proposal proposal, int version) {
this(proposal, version, null, null, null);
}
public Proposal(Proposal value) {
super(value);
this.clients = new Clients();
ContestAssociation contestAssociation = new ContestAssociation();
this.contestPhase = contestAssociation.getContestPhase();
this.contest = contestAssociation.getContest();
this.proposal2Phase = contestAssociation.getProposal2Phase();
proposalContestPhaseAttributeHelper =
new ProposalContestPhaseAttributeHelper(this, contestPhase);
proposalAttributeHelper = new ProposalAttributeHelper(this, this.getVersion(),
clients.proposalAttribute);
unversionedAttributeHelper = new ProposalUnversionedAttributeHelper(this,
clients.proposalAttribute);
}
public Proposal(Proposal proposal, ContestPhase contestPhase, Proposal2Phase proposal2Phase) {
this(proposal, proposal.getCurrentVersion(), null, contestPhase, proposal2Phase);
}
public Proposal(Proposal proposal, Integer version, Contest contest) {
this(proposal, version, contest, null, null);
}
public Proposal(Proposal proposal, Integer version, Contest contest,
ContestPhase contestPhase, Proposal2Phase proposal2Phase) {
super(proposal);
this.clients = new Clients();
ContestAssociation contestAssociation =
new ContestAssociation(contest, contestPhase, proposal2Phase);
this.contestPhase = contestAssociation.getContestPhase();
this.contest = contestAssociation.getContest();
this.proposal2Phase = contestAssociation.getProposal2Phase();
proposalContestPhaseAttributeHelper =
new ProposalContestPhaseAttributeHelper(this, this.contestPhase);
final int currentVersion = version != null ? version : proposal.getVersion();
proposalAttributeHelper = new ProposalAttributeHelper(this, currentVersion,
clients.proposalAttribute);
unversionedAttributeHelper = new ProposalUnversionedAttributeHelper(this,
clients.proposalAttribute);
}
public Proposal() {
super();
this.clients = new Clients();
this.setId(0L);
ContestAssociation contestAssociation = new ContestAssociation();
this.contestPhase = contestAssociation.getContestPhase();
this.contest = contestAssociation.getContest();
this.proposal2Phase = contestAssociation.getProposal2Phase();
proposalContestPhaseAttributeHelper =
new ProposalContestPhaseAttributeHelper(this, contestPhase);
proposalAttributeHelper = new ProposalAttributeHelper(this, this.getVersion(),
clients.proposalAttribute);
unversionedAttributeHelper = new ProposalUnversionedAttributeHelper(this,
clients.proposalAttribute);
}
public Proposal(AbstractProposal abstractProposal) {
super(abstractProposal);
this.clients = new Clients();
ContestAssociation contestAssociation = new ContestAssociation();
this.contestPhase = contestAssociation.getContestPhase();
this.contest = contestAssociation.getContest();
this.proposal2Phase = contestAssociation.getProposal2Phase();
proposalContestPhaseAttributeHelper =
new ProposalContestPhaseAttributeHelper(this, contestPhase);
proposalAttributeHelper = new ProposalAttributeHelper(this, this.getVersion(),
clients.proposalAttribute);
unversionedAttributeHelper = new ProposalUnversionedAttributeHelper(this,
clients.proposalAttribute);
}
@JsonIgnore
public String getProposalLinkUrl(Contest contest) {
return getProposalLinkUrl(contest, 0L);
}
@JsonIgnore
public String getProposalLinkUrl(Contest contest, long contestPhaseId) {
Long proposalId = this.getId();
ContestType contestType = ContestTypeClient.getContestType(contest.getContestTypeId());
String link = contestType.getContestBaseUrl();
String friendlyUrlStringProposal = contestType.getFriendlyUrlStringProposal();
if (contestPhaseId > 0) {
long activePhaseId =
clients.contest.getActivePhase(contest.getId()).getId();
if (activePhaseId == contestPhaseId) {
link += "/%d/%s/c/" + friendlyUrlStringProposal + "/%d";
return String.format(link, contest.getContestYear(), contest.getContestUrlName(),
proposalId);
}
link += "/%d/%s/phase/%d/" + friendlyUrlStringProposal + "/%d";
return String.format(link, contest.getContestYear(), contest.getContestUrlName(),
contestPhaseId, proposalId);
}
link += "/%d/%s/c/" + friendlyUrlStringProposal + "/%d";
return String
.format(link, contest.getContestYear(), contest.getContestUrlName(), proposalId);
}
@JsonIgnore
public boolean isDeleted() {
if (this.getId() == 0) {
return false;
}
final ContestPhase contestPhase = clients.contest.getContestPhase(
clients.proposal.getLatestContestPhaseIdInProposal(this.getId()));
long visibleAttributeValue = 1;
if (contestPhase != null) {
ProposalContestPhaseAttribute pcpa = clients.proposalPhase
.getProposalContestPhaseAttribute(this.getId(),
contestPhase.getId(),
ProposalContestPhaseAttributeKeys.VISIBLE);
if (pcpa != null) {
visibleAttributeValue = pcpa.getNumericValue();
}
}
return !this.getVisible() || visibleAttributeValue == 0;
}
@JsonIgnore
public String getCleanPitch() {
return HtmlUtil.cleanAll(getPitch());
}
@JsonIgnore
public String getPitch() {
return proposalAttributeHelper.getAttributeValueString(ProposalAttributeKeys.PITCH, "");
}
@JsonIgnore
public String getName() {
return proposalAttributeHelper.getAttributeValueString(ProposalAttributeKeys.NAME, "");
}
@JsonIgnore
public String getDescription() {
return proposalAttributeHelper.getAttributeValueString(ProposalAttributeKeys.DESCRIPTION, "");
}
@JsonIgnore
public boolean isUserAmongFellows(long userId) {
for (Long fellowId : clients.contestTeamMember.getFellowsForContest(contest.getId())) {
if (fellowId == userId) {
return true;
}
}
return false;
}
@JsonIgnore
public boolean isUserAmongJudges(long userId) {
for (Long judge : clients.contestTeamMember.getJudgesForContest(contest.getId())) {
if (judge == userId) {
return true;
}
}
return false;
}
@JsonIgnore
public boolean isJudgingContestPhase() {
return ContestPhasePromoteType.getPromoteType(contestPhase.getContestPhaseAutopromote())
== ContestPhasePromoteType.PROMOTE_JUDGED;
}
@JsonIgnore
public String getTeam() {
return proposalAttributeHelper.getAttributeValueString(ProposalAttributeKeys.TEAM, "");
}
@JsonIgnore
public Member getAuthor() {
try {
return MembersClient.getMember(this.getAuthorUserId());
} catch (MemberNotFoundException e) {
throw new IllegalStateException("Author " + this.getAuthorUserId()
+ " of proposal " + this.getId() + " does not exist");
}
}
@JsonIgnore
public long getSupportersCount() {
return clients.proposalMemberRating.getProposalSupportersCount(this.getId());
}
@JsonIgnore
public long getSupportersCountCached() {
return clients.proposalMemberRating.getProposalSupportersCountCached(this.getId());
}
@JsonIgnore
public long getCommentsCount() {
if (this.getId() > 0) {
return CommentClient.instance().countComments(this.getDiscussionId());
}
return 0;
}
@JsonIgnore
public long getEvaluationCommentsCount() {
return 0;
}
@JsonIgnore
private long createDiscussionThread(String threadTitleSuffix, boolean isQuiet) {
final ContestType contestType = getContest().getContestType();
CommentThread thread = new CommentThread();
thread.setAuthorUserId(getAuthorUserId());
thread.setTitle(contestType.getProposalName() + getName() + threadTitleSuffix);
thread.setIsQuiet(isQuiet);
return ThreadClient.instance().createThread(thread).getId();
}
@JsonIgnore
public long getDiscussionIdOrCreate() {
Long discussionId = getDiscussionId();
if (discussionId == null) {
discussionId = createDiscussionThread(" comments", false);
setDiscussionId(discussionId);
clients.proposal.updateProposal(this);
}
return discussionId;
}
@JsonIgnore
public long getResultsDiscussionIdOrCreate() {
Long discussionId = getDiscussionId();
if (discussionId == null) {
discussionId = createDiscussionThread(" results discussion", true);
setResultsDiscussionId(discussionId);
clients.proposal.updateProposal(this);
}
return discussionId;
}
@JsonIgnore
public Date getLastupdatedAt() {
return this.getUpdatedAt();
}
@JsonIgnore
public Date getLastupdatedAtForContestPhase() {
if (proposal2Phase.getVersionTo() == -1) {
return getLastupdatedAt();
}
return clients.proposal
.getProposalVersionByProposalIdVersion(this.getId(), this.getVersion()).getCreatedAt();
}
@JsonIgnore
public boolean isOpen() {
if (this.getId() > 0) {
ProposalAttribute attribute = clients.proposalAttribute
.getProposalAttribute(this.getId(), ProposalAttributeKeys.OPEN, 0L);
return attribute != null && attribute.getNumericValue() > 0;
} else {
return false;
}
}
@JsonIgnore
public long getImageId() {
return proposalAttributeHelper.getAttributeValueLong(ProposalAttributeKeys.IMAGE_ID, 0L, 0);
}
@JsonIgnore
public String getLogoPath() {
String imageDomain = PlatformAttributeKey.CDN_URL_IMAGES_UPLOADED.get();
if (getImageId() == 0 && getContest().getDefaultProposalLogoId() != null) {
return imageDomain + "/image/proposal/" + getContest().getDefaultProposalLogoId();
}
return imageDomain + "/image/proposal/" + getImageId();
}
@JsonIgnore
public String getProposalUrl() {
return this.getProposalLinkUrl(contest);
}
@JsonIgnore
public String getAbsoluteProposalUrl() {
return ConfigurationAttributeKey.COLAB_URL_PRODUCTION.get() + getProposalUrl();
}
@JsonIgnore
public String getProposalDiscussionUrl() {
boolean isSeparateTab = ConfigurationAttributeKey.PROPOSALS_COMMENTS_IN_SEPARATE_TAB.get();
if (isSeparateTab) {
return this.getProposalLinkUrl(contest) + "/tab/COMMENTS";
}
return getProposalUrl() + "#Comments";
}
@JsonIgnore
public String getProposalUrl(ContestPhase inPhase) {
return this.getProposalLinkUrl(contest, inPhase.getId());
}
@JsonIgnore
public List<Member> getSupporters() {
if (supporters == null) {
supporters = clients.proposalMemberRating.getProposalSupporters(getId()).stream()
.map(supporter -> MembersClient.getMemberOrNull(supporter.getUserId()))
.filter(Objects::nonNull)
.collect(Collectors.toList());
}
return supporters;
}
@JsonIgnore
public String getAuthorName() {
String authorName = getTeam();
if (StringUtils.isBlank(authorName)) {
authorName = getAuthor().getDisplayName();
}
return authorName;
}
@JsonIgnore
public Contest getContest() {
return contest;
}
@JsonIgnore
public boolean isContestMatchesLatestContest() {
final long contestId = getContest().getId();
final Contest currentContestForProposal =
clients.proposal.getCurrentContestForProposal(getId());
return contestId == currentContestForProposal.getId();
}
@JsonIgnore
public boolean getIsLatestVersion() {
return getCurrentVersion() == this.getVersion();
}
@JsonIgnore
public Contest getWasMovedToContest() {
try {
Contest c = clients.proposal.getCurrentContestForProposal(this.getId());
if (c.getId() != contest.getId().longValue()) {
try {
return clients.contest.getContest(c.getId());
} catch (ContestNotFoundException ignored) {
}
}
return null;
} catch (ContestNotFoundException e) {
return null;
}
}
@JsonIgnore
public ProposalVersion getSelectedVersion() {
for (ProposalVersion pv : clients.proposal.getAllProposalVersions(this.getId())) {
if (pv.getVersion() == this.getVersion()) {
return pv;
}
}
return null;
}
@JsonIgnore
public ProposalAttributeHelper getProposalAttributeHelper() {
return proposalAttributeHelper;
}
@JsonIgnore
public Integer getCurrentVersion() {
return clients.proposal.getMaxVersion(getId());
}
@JsonIgnore
public int getVersion() {
return this.getCurrentVersion() != null ? this.getCurrentVersion() : 0;
}
@JsonIgnore
public long getcontestId() {
return contest.getId();
}
@JsonIgnore
public boolean isVisible() {
return !this.isDeleted();
}
@JsonIgnore
public boolean isVisibleInContest(long contestId) {
try {
if (this.getId() == 0) {
return true;
}
final Contest currentContest =
clients.proposal.getCurrentContestForProposal(this.getId());
return !isDeleted() && currentContest.getId() == contestId;
} catch (ContestNotFoundException ignored) {
return false;
}
}
@JsonIgnore
public ContestPhase getContestPhase() {
return contestPhase;
}
@JsonIgnore
public List<ProposalTeamMember> getMembers() {
if (members == null) {
members = new ArrayList<>();
for (Member member : clients.proposal.getProposalMembers(getId())) {
final ProposalTeamMember teamMemberWrapper = new ProposalTeamMember(
this, member);
members.add(teamMemberWrapper);
}
}
return members;
}
@JsonIgnore
public boolean isFeatured() {
return getRibbonWrapper().getRibbon() > 0;
}
@JsonIgnore
public JudgingSystemActions.AdvanceDecision getJudgeDecision() {
long judgingDecision = proposalContestPhaseAttributeHelper.getAttributeLongValue(ProposalContestPhaseAttributeKeys.JUDGE_DECISION, 0, LONG_DEFAULT_VAL);
return JudgingSystemActions.AdvanceDecision.fromInt((int) judgingDecision);
}
@JsonIgnore
public JudgingSystemActions.FellowAction getFellowAction() {
Long action = proposalContestPhaseAttributeHelper.getAttributeLongValue(ProposalContestPhaseAttributeKeys.FELLOW_ACTION, 0, LONG_DEFAULT_VAL);
return JudgingSystemActions.FellowAction.fromInt(action.intValue());
}
@JsonIgnore
public String getFellowActionComment() {
return proposalContestPhaseAttributeHelper.getAttributeStringValue(ProposalContestPhaseAttributeKeys.FELLOW_ACTION_COMMENT, 0, STRING_DEFAULT_VAL);
}
@JsonIgnore
public String getProposalReview() {
return proposalContestPhaseAttributeHelper.getAttributeStringValue(ProposalContestPhaseAttributeKeys.PROPOSAL_REVIEW, 0, STRING_DEFAULT_VAL);
}
@JsonIgnore
public List<Long> getSelectedJudges() {
List<Long> selectedJudges = new ArrayList<>();
// All judges are selected when screening is disabled
if (!contestPhase.getFellowScreeningActive()) {
selectedJudges
.addAll(clients.contestTeamMember.getJudgesForContest(contest.getId()));
} else {
String s = proposalContestPhaseAttributeHelper.getAttributeStringValue(ProposalContestPhaseAttributeKeys.SELECTED_JUDGES, 0, STRING_DEFAULT_VAL);
if (s.isEmpty()) {
return selectedJudges;
}
for (String element : s.split(";")) {
selectedJudges.add(Long.parseLong(element));
}
}
return selectedJudges;
}
@JsonIgnore
public List<Member> getSelectedJudgeUsers() {
List<Member> selectedJudges = new ArrayList<>();
// All judges are selected when screening is disabled
if (!contestPhase.getFellowScreeningActive()) {
for (Long judgeId : clients.contestTeamMember.getJudgesForContest(contest.getId())) {
try {
Member judge = MembersClient.getMember(judgeId);
selectedJudges.add(judge);
} catch (MemberNotFoundException ignored) {
}
}
} else {
String s = proposalContestPhaseAttributeHelper.getAttributeStringValue(ProposalContestPhaseAttributeKeys.SELECTED_JUDGES, 0, STRING_DEFAULT_VAL);
if (s.isEmpty()) {
return selectedJudges;
}
for (String element : s.split(";")) {
try {
Member judge = MembersClient.getMember(Long.parseLong(element));
selectedJudges.add(judge);
} catch (MemberNotFoundException ignored) {
}
}
}
return selectedJudges;
}
@JsonIgnore
public boolean getIsUserAmongSelectedJudges(long judgeId) {
if (!getFellowScreeningNecessary()) {
return isUserAmongJudges(judgeId);
}
return getSelectedJudges().stream()
.anyMatch(userId -> Objects.equals(userId, judgeId));
}
@JsonIgnore
public long getVotesCount() {
return getVotesCountInternal(CacheName.NONE);
}
@JsonIgnore
public long getVotesCountFromCache() {
return getVotesCountInternal(CacheName.MEMBER_RATING);
}
private long getVotesCountInternal(CacheName cacheName) {
if (this.getId() > 0) {
long votingPhasePK = contest.getVotingPhasePK();
return clients.proposalMemberRating.countProposalVotesInContestPhaseProposalId(
votingPhasePK, this.getId(), cacheName);
}
return 0;
}
@JsonIgnore
public List<ProposalTemplateSectionDefinition> getSections() {
if (sections == null) {
sections = new ArrayList<>();
if (contest != null) {
ProposalTemplate proposalTemplate = clients.proposalTemplate.getProposalTemplate(contest.getProposalTemplateId());
if (proposalTemplate != null) {
for (ProposalTemplateSectionDefinition psd : clients.proposalTemplate
.getProposalTemplateSectionDefinitionByProposalTemplateId(proposalTemplate.getId(),true)) {
sections.add(new ProposalTemplateSectionDefinition(psd, this));
}
}
}
}
return sections;
}
protected boolean getFellowScreeningNecessary() {
return contestPhase.getFellowScreeningActive();
}
@JsonIgnore
public List<ProposalTeamMembershipRequest> getMembershipRequests() {
if (this.membershipRequests == null) {
membershipRequests = new ArrayList<>();
for (ProposalTeamMembershipRequest m : clients.membership.getMembershipRequests(this.getId())) {
if (m.getStatusId() == MembershipRequestStatus.STATUS_PENDING_REQUESTED) {
membershipRequests.add((m));
}
}
}
return this.membershipRequests;
}
@JsonIgnore
public List<String[]> getAllModelRegions() {
List<String[]> modelRegions = new ArrayList<>();
for (ModelRegions modelRegion : ModelRegions.values()) {
modelRegions.add(new String[]{modelRegion.getModelRegionName(), modelRegion.getModelRegionTitle()});
}
return modelRegions;
}
@JsonIgnore
public String getModelRegion() {
ProposalAttribute attr = proposalAttributeHelper.getAttributeOrNull(ProposalAttributeKeys.REGION);
if (attr == null) {
return "";
}
return attr.getStringValue();
}
@JsonIgnore
public void setModelRegion(String region, Long userId) {
ProposalAttributeClientUtil.setProposalAttribute(createProposalAttribute(this.getId(), ProposalAttributeKeys.REGION, region),userId);
}
private static ProposalAttribute createProposalAttribute(Long proposalId, String name, String stringValue){
ProposalAttribute proposalAttribute = new ProposalAttribute();
proposalAttribute.setProposalId(proposalId);
proposalAttribute.setName(name);
proposalAttribute.setStringValue(stringValue);
return proposalAttribute;
}
@JsonIgnore
public Long getModelId() {
return contest.getDefaultModelId();
}
@JsonIgnore
public void setScenarioId(Long scenarioId, Long isConsolidatedScenario, Long userId) {
ProposalAttribute proposalAttribute = new ProposalAttribute();
proposalAttribute.setProposalId(this.getId());
proposalAttribute.setName(ProposalAttributeKeys.SCENARIO_ID);
proposalAttribute.setNumericValue(isConsolidatedScenario);
proposalAttribute.setAdditionalId(scenarioId);
ProposalAttributeClientUtil.setProposalAttribute(proposalAttribute,userId);
}
@JsonIgnore
public Long getScenarioId() {
ProposalAttribute attr = proposalAttributeHelper.getAttributeOrNull(ProposalAttributeKeys.SCENARIO_ID);
if (attr == null) {
return 0L;
}
return attr.getNumericValue();
}
@JsonIgnore
public Boolean isConsolidatedScenario(Long scenarioId) {
ProposalAttribute attr = proposalAttributeHelper.getAttributeOrNull(ProposalAttributeKeys.SCENARIO_ID);
return attr != null && attr.getAdditionalId() == 1;
}
@JsonIgnore
public Map<Long, List<Proposal>> getSubProposalPerModel() {
Map<Long, List<Proposal>> subProposalPerModel = new HashMap<>();
List<Proposal> subProposals = ProposalClientUtil.getContestIntegrationRelevantSubproposals(this.getId());
for (Proposal subProposal : subProposals) {
Long modelId = subProposal.getModelIdForStoredScenario();
if (!subProposalPerModel.containsKey(modelId)) {
subProposalPerModel.put(modelId, Collections.singletonList(subProposal));
} else {
subProposalPerModel.get(modelId).add(subProposal);
}
}
return subProposalPerModel;
}
@JsonIgnore
public Scenario getScenario() throws IOException {
return getScenarioByProposalId(this.getId());
}
@JsonIgnore
public Scenario getScenarioByProposalId(Long proposalId) throws IOException {
return RomaClientUtil.client().getScenario(proposalId);
}
private static Long getModelIdForScenarioId(Long scenarioId) {
Long modelId;
try {
Scenario scenario = RomaClientUtil.client().getScenario(scenarioId);
Simulation simulation = scenario.getSimulation();
modelId = simulation.getId();
} catch (IOException e) {
modelId = 0L;
}
return modelId;
}
@JsonIgnore
public List<Scenario> getSubProposalScenarios() throws IOException {
List<Scenario> subProposalScenarios = new ArrayList<>();
List<Proposal> subProposals = ProposalClientUtil.getContestIntegrationRelevantSubproposals(this.getId());
for (Proposal subProposal : subProposals) {
Scenario scenarioForSubProposal = getScenarioByProposalId(subProposal.getId());
subProposalScenarios.add(scenarioForSubProposal);
}
return subProposalScenarios;
}
private Long getModelIdForStoredScenario() {
return getModelIdForScenarioId(this.getId());
}
@JsonIgnore
public List<Long> getSubProposalScenarioIds() {
List<Long> subProposalScenarioIds = new ArrayList<>();
Map<Long, List<Proposal>> subProposalPerModel = getSubProposalPerModel();
if (!subProposalPerModel.isEmpty()) {
for (Map.Entry<Long, List<Proposal>> entry : subProposalPerModel.entrySet()) {
List<Proposal> proposals = entry.getValue();
for (Proposal proposal : proposals) {
subProposalScenarioIds.add(proposal.getScenarioId());
}
}
}
return subProposalScenarioIds;
}
@JsonIgnore
public String getImpactCommentAuthor() {
ProposalUnversionedAttribute authorCommentAttribute = unversionedAttributeHelper
.getAttributeOrNull(ProposalUnversionedAttributeName.IMPACT_AUTHOR_COMMENT
.toString(), 0);
if (authorCommentAttribute != null) {
final String authorComment = authorCommentAttribute.getStringValue();
if (StringUtils.isNotBlank(authorComment)) {
return authorComment;
}
}
return "";
}
@JsonIgnore
public String getImpactCommentIaf() {
ProposalUnversionedAttribute iafCommentAttribute = unversionedAttributeHelper
.getAttributeOrNull(ProposalUnversionedAttributeName.IMPACT_IAF_COMMENT
.toString(), 0);
if (iafCommentAttribute != null) {
final String iafComment = iafCommentAttribute.getStringValue();
if (StringUtils.isNotBlank(iafComment)) {
return iafComment;
}
}
return "";
}
/**
* Determine if fellows are done with proposal
*/
@JsonIgnore
public AssessmentStatus getScreeningStatus() {
switch (getFellowAction()) {
case INCOMPLETE:
case OFFTOPIC:
case NOT_ADVANCE_OTHER:
return AssessmentStatus.NEGATIVE;
case PASS_TO_JUDGES:
return AssessmentStatus.POSITIVE;
default:
return AssessmentStatus.UNKNOWN;
}
}
/**
* Determine if IA fellows are done with proposal
*/
@JsonIgnore
public AssessmentStatus getImpactAssessmentStatus() {
final String impactCommentIaf = getImpactCommentIaf();
if (impactCommentIaf.startsWith("Done")) {
return AssessmentStatus.POSITIVE;
}
if (impactCommentIaf.startsWith("Started")) {
return AssessmentStatus.NEGATIVE;
}
return AssessmentStatus.UNKNOWN;
}
/**
* Determine if judges are done with proposal
*/
@JsonIgnore
public AssessmentStatus getJudgeStatus() {
if (getFellowAction() == JudgingSystemActions.FellowAction.INCOMPLETE
|| getFellowAction() == JudgingSystemActions.FellowAction.OFFTOPIC
|| getFellowAction() == JudgingSystemActions.FellowAction.NOT_ADVANCE_OTHER) {
return AssessmentStatus.NEGATIVE;
}
if (!getSelectedJudges().isEmpty() && getAllJudgesReviewFinished()) {
return AssessmentStatus.POSITIVE;
}
return AssessmentStatus.UNKNOWN;
}
/**
* Determines whether the screening/advance decision of the proposal is done
*/
@JsonIgnore
public AssessmentStatus getOverallStatus() {
if (getJudgeDecision() == JudgingSystemActions.AdvanceDecision.MOVE_ON
&& (getProposalReview()!=null)) {
return AssessmentStatus.POSITIVE;
}
if (getJudgeDecision() == JudgingSystemActions.AdvanceDecision.DONT_MOVE_ON
&& (getProposalReview()!=null)
|| getScreeningStatus() == AssessmentStatus.NEGATIVE) {
return AssessmentStatus.NEGATIVE;
}
return AssessmentStatus.UNKNOWN;
}
@JsonIgnore
public Member getUserForSelectedVersion() {
try {
return MembersClient.getMember(getSelectedVersion().getAuthorUserId());
} catch (MemberNotFoundException e) {
return null;
}
}
@JsonIgnore
public boolean getAllJudgesReviewFinished() {
if (!getSelectedJudges().isEmpty()) {
for (long userId : getSelectedJudges()) {
List<ProposalRating> proposalRatings = ProposalJudgeRatingClientUtil
.getProposalRatingsByProposalUserContestPhase(this.getId(),
contestPhase.getId(),userId);
ProposalRatings wrapper = new ProposalRatings(userId, proposalRatings);
if (!wrapper.isReviewComplete()) {
return false;
}
}
}
return true;
}
@JsonIgnore
public boolean getIsReviewFinishedForJudge(long judgeId) {
List<ProposalRating> proposalRatings = ProposalJudgeRatingClientUtil
.getProposalRatingsByProposalUserContestPhase(
getId(), contestPhase.getId(), judgeId);
ProposalRatings wrapper = new ProposalRatings(judgeId, proposalRatings);
return wrapper.isReviewComplete();
}
@JsonIgnore
public Proposal getBaseProposal() {
long baseProposalId = proposalAttributeHelper
.getAttributeValueLong(ProposalAttributeKeys.BASE_PROPOSAL_ID, 0);
if (baseProposalId > 0) {
long baseProposalContestId = proposalAttributeHelper
.getAttributeValueLong(ProposalAttributeKeys.BASE_PROPOSAL_CONTEST_ID, 0);
if (baseProposalContestId > 0) {
return clients.proposal.getProposal(baseProposalId);
}
}
return null;
}
@JsonIgnore
public List<ProposalRating> getRatings() {
if (this.proposalRatings == null) {
return new ArrayList<>();
}
return this.proposalRatings.getRatings();
}
@JsonIgnore
public String getRatingComment() {
if (this.proposalRatings == null) {
return "";
}
return this.proposalRatings.getComment();
}
@JsonIgnore
public Boolean getRatingShouldAdvance() {
if (this.proposalRatings == null) {
return null;
}
return this.proposalRatings.getShouldAdvance();
}
@JsonIgnore
public ProposalRibbon getRibbonWrapper() {
if (ribbonWrapper == null) {
ribbonWrapper = new ProposalRibbon(this);
}