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