View Javadoc
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       * This method limits the number of key persons to n, returns list of key persons, first n in case firstN is true, or all other
31       * than first n, in case of firstN being false
32       *
33       * @param proposalPersons list of {@link org.kuali.coeus.propdev.api.person.ProposalPersonContract}
34       * @param firstN value that determines whether the returned list should contain first n persons or the rest of persons
35       * @param n number of key persons that are considered as not extra persons
36       * @return list of {@link org.kuali.coeus.propdev.api.person.ProposalPersonContract}
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              // Make sure we don't exceed the size of the list.
61              if (size > n) {
62                  size = n;
63              }
64              // remove extras
65              for (int i = 0; i < size; i++) {
66                  firstNPersons.add(proposalPersons.get(i));
67              }
68              return firstNPersons;
69          }
70          else {
71              // return extra people
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       * This method is to get PrincipalInvestigator from person list
82       *
83       * @param pdDoc Proposal development document.
84       * @return ProposalPerson PrincipalInvestigator for the proposal.
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      * Finds all the Investigators associated with the provided pdDoc.
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                 //multi-pis are still considered co-i within S2S.
108                 if (person.isCoInvestigator() || person.isMultiplePi()) {
109                     investigators.add(person);
110                 }
111             }
112         }
113         return investigators;
114     }
115 
116     /**
117      * Finds all the key Person associated with the provided pdDoc.
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      * Implementation should return one of the enums defined in PHS398CareerDevelopmentAwardSup11V11 form schema. For now, it
134      * returns US RESIDENT as default
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 }