1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.kuali.coeus.s2sgen.impl.person;
20
21
22 import org.kuali.coeus.propdev.api.core.ProposalDevelopmentDocumentContract;
23 import org.kuali.coeus.propdev.api.person.ProposalPersonContract;
24 import org.kuali.coeus.propdev.api.s2s.S2SConfigurationService;
25
26 import org.kuali.coeus.s2sgen.impl.citizenship.CitizenshipType;
27 import org.kuali.coeus.s2sgen.impl.citizenship.CitizenshipTypeService;
28 import org.kuali.coeus.s2sgen.api.core.ConfigurationConstants;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.beans.factory.annotation.Qualifier;
31 import org.springframework.stereotype.Component;
32
33 import java.util.ArrayList;
34 import java.util.List;
35
36 @Component("s2SProposalPersonService")
37 public class S2SProposalPersonServiceImpl implements S2SProposalPersonService {
38
39 @Autowired
40 @Qualifier("s2SConfigurationService")
41 private S2SConfigurationService s2SConfigurationService;
42
43 @Autowired
44 @Qualifier("citizenshipTypeService")
45 private CitizenshipTypeService citizenshipTypeService;
46
47
48
49
50
51
52
53
54
55
56 @Override
57 public List<ProposalPersonContract> getNKeyPersons(List<? extends ProposalPersonContract> proposalPersons, boolean firstN, int n) {
58 ProposalPersonContract proposalPerson, previousProposalPerson;
59 int size = proposalPersons.size();
60
61 for (int i = size - 1; i > 0; i--) {
62 proposalPerson = proposalPersons.get(i);
63 previousProposalPerson = proposalPersons.get(i - 1);
64 if (proposalPerson.getPersonId() != null && previousProposalPerson.getPersonId() != null
65 && proposalPerson.getPersonId().equals(previousProposalPerson.getPersonId())) {
66 proposalPersons.remove(i);
67 }
68 else if (proposalPerson.getRolodexId() != null && previousProposalPerson.getRolodexId() != null
69 && proposalPerson.getRolodexId().equals(previousProposalPerson.getRolodexId())) {
70 proposalPersons.remove(i);
71 }
72 }
73
74 size = proposalPersons.size();
75 if (firstN) {
76 List<ProposalPersonContract> firstNPersons = new ArrayList<ProposalPersonContract>();
77
78
79 if (size > n) {
80 size = n;
81 }
82
83 for (int i = 0; i < size; i++) {
84 firstNPersons.add(proposalPersons.get(i));
85 }
86 return firstNPersons;
87 }
88 else {
89
90 List<ProposalPersonContract> extraPersons = new ArrayList<ProposalPersonContract>();
91 for (int i = n; i < size; i++) {
92 extraPersons.add(proposalPersons.get(i));
93 }
94 return extraPersons;
95 }
96 }
97
98
99
100
101
102
103
104 @Override
105 public ProposalPersonContract getPrincipalInvestigator(ProposalDevelopmentDocumentContract pdDoc) {
106 ProposalPersonContract proposalPerson = null;
107 if (pdDoc != null) {
108 for (ProposalPersonContract person : pdDoc.getDevelopmentProposal().getProposalPersons()) {
109 if (person.isPrincipalInvestigator()) {
110 proposalPerson = person;
111 }
112 }
113 }
114 return proposalPerson;
115 }
116
117
118
119
120 @Override
121 public List<ProposalPersonContract> getCoInvestigators(ProposalDevelopmentDocumentContract pdDoc) {
122 List<ProposalPersonContract> investigators = new ArrayList<ProposalPersonContract>();
123 if (pdDoc != null) {
124 for (ProposalPersonContract person : pdDoc.getDevelopmentProposal().getProposalPersons()) {
125
126 if (person.isCoInvestigator() || person.isMultiplePi()) {
127 investigators.add(person);
128 }
129 }
130 }
131 return investigators;
132 }
133
134
135
136
137 @Override
138 public List<ProposalPersonContract> getKeyPersons(ProposalDevelopmentDocumentContract pdDoc) {
139 List<ProposalPersonContract> keyPersons = new ArrayList<ProposalPersonContract>();
140 if (pdDoc != null) {
141 for (ProposalPersonContract person : pdDoc.getDevelopmentProposal().getProposalPersons()) {
142 if (person.isKeyPerson()) {
143 keyPersons.add(person);
144 }
145 }
146 }
147 return keyPersons;
148 }
149
150
151
152
153
154 @Override
155 public CitizenshipType getCitizenship(ProposalPersonContract proposalPerson) {
156 String citizenSource = "1";
157 String piCitizenShipValue = s2SConfigurationService.getValueAsString(ConfigurationConstants.PI_CUSTOM_DATA);
158 if (piCitizenShipValue != null) {
159 citizenSource = piCitizenShipValue;
160 }
161 if (citizenSource.equals("0")) {
162 CitizenshipType citizenShipType = citizenshipTypeService.getCitizenshipDataFromExternalSource();
163 return citizenShipType;
164 }
165 else {
166 Integer citizenShip;
167 Boolean allowOverride = s2SConfigurationService.getValueAsBoolean(
168 ConfigurationConstants.ALLOW_PROPOSAL_PERSON_TO_OVERRIDE_KC_PERSON_EXTENDED_ATTRIBUTES);
169 if (allowOverride) {
170 citizenShip = proposalPerson.getCitizenshipType().getCode();
171 }
172 else {
173 citizenShip = proposalPerson.getPerson().getCitizenshipTypeCode();
174 }
175 CitizenshipType retVal = null;
176 String citizenShipCode = String.valueOf(citizenShip);
177 if (citizenShipCode.equals(s2SConfigurationService.getValueAsString(
178 ConfigurationConstants.NON_US_CITIZEN_WITH_TEMPORARY_VISA_TYPE_CODE))) {
179 return CitizenshipType.NON_US_CITIZEN_WITH_TEMPORARY_VISA;
180 }
181 else if (citizenShipCode.equals(s2SConfigurationService.getValueAsString(
182 ConfigurationConstants.PERMANENT_RESIDENT_OF_US_TYPE_CODE))) {
183 return CitizenshipType.PERMANENT_RESIDENT_OF_US;
184 }
185 else if (citizenShipCode.equals(s2SConfigurationService.getValueAsString(
186 ConfigurationConstants.US_CITIZEN_OR_NONCITIZEN_NATIONAL_TYPE_CODE))) {
187 return CitizenshipType.US_CITIZEN_OR_NONCITIZEN_NATIONAL;
188 }
189 else if (citizenShipCode.equals(s2SConfigurationService.getValueAsString(
190 ConfigurationConstants.PERMANENT_RESIDENT_OF_US_PENDING))) {
191 return CitizenshipType.PERMANENT_RESIDENT_OF_US_PENDING;
192 }
193 else {
194 throw new IllegalArgumentException("Invalid citizenship type provided");
195 }
196
197 }
198 }
199 }