Search in sources :

Example 1 with ProjectInvestigator

use of edu.cornell.kfs.module.ezra.businessobject.ProjectInvestigator in project cu-kfs by CU-CommunityApps.

the class EzraServiceImpl method createProjectDirectors.

private List<ProposalProjectDirector> createProjectDirectors(String projectId, EzraProject project) {
    List<ProposalProjectDirector> projDirs = new ArrayList<ProposalProjectDirector>();
    Investigator investigator = (Investigator) businessObjectService.findBySinglePrimaryKey(Investigator.class, project.getProjectDirectorId());
    if (investigator != null) {
        PersonService ps = SpringContext.getBean(PersonService.class);
        if (investigator.getNetId() != null) {
            Person director = ps.getPersonByPrincipalName(investigator.getNetId());
            if (director != null) {
                Map primaryKeys = new HashMap();
                primaryKeys.put("principalId", director.getPrincipalId());
                primaryKeys.put("proposalNumber", projectId);
                ProposalProjectDirector ppd = (ProposalProjectDirector) businessObjectService.findByPrimaryKey(ProposalProjectDirector.class, primaryKeys);
                if (ObjectUtils.isNull(ppd)) {
                    ppd = new ProposalProjectDirector();
                }
                // else {
                // ppd.setVersionNumber(ppd.getVersionNumber());
                // }
                ppd.setPrincipalId(director.getPrincipalId());
                ppd.setProposalNumber(project.getProjectId());
                ppd.setProposalPrimaryProjectDirectorIndicator(true);
                ppd.setActive(true);
                KimApiServiceLocator.getRoleService().assignPrincipalToRole(director.getPrincipalId(), "KFS-SYS", "Contracts & Grants Project Director", new HashMap<String, String>());
                projDirs.add(ppd);
            } else {
                LOG.error("PI: " + investigator.getNetId() + " for award :" + projectId + " is not in kfs");
            }
        } else {
            LOG.error("PI netId for award :" + projectId + " is null");
        }
    } else {
        LOG.error("Null PI: " + project.getProjectDirectorId());
    }
    Map fieldValues = new HashMap();
    fieldValues.put("projectId", projectId.toString());
    fieldValues.put("investigatorRole", "CO");
    List<ProjectInvestigator> pis = (List<ProjectInvestigator>) businessObjectService.findMatching(ProjectInvestigator.class, fieldValues);
    for (ProjectInvestigator pi : pis) {
        if (pi.getInvestigatorId() != null) {
            Investigator inv = (Investigator) businessObjectService.findBySinglePrimaryKey(Investigator.class, pi.getInvestigatorId());
            if (inv != null) {
                PersonService ps = SpringContext.getBean(PersonService.class);
                if (inv.getNetId() != null) {
                    Person director = ps.getPersonByPrincipalName(inv.getNetId());
                    if (director != null) {
                        Map primaryKeys = new HashMap();
                        primaryKeys.put("principalId", director.getPrincipalId());
                        primaryKeys.put("proposalNumber", projectId);
                        ProposalProjectDirector ppd = (ProposalProjectDirector) businessObjectService.findByPrimaryKey(ProposalProjectDirector.class, primaryKeys);
                        if (ObjectUtils.isNull(ppd)) {
                            ppd = new ProposalProjectDirector();
                        }
                        ppd.setPrincipalId(director.getPrincipalId());
                        ppd.setProposalNumber(project.getProjectId());
                        ppd.setProposalPrimaryProjectDirectorIndicator(false);
                        ppd.setActive(true);
                        KimApiServiceLocator.getRoleService().assignPrincipalToRole(director.getPrincipalId(), "KFS-SYS", "Contracts & Grants Project Director", new HashMap<String, String>());
                        // check to make sure that this project director is not already in the list.
                        for (ProposalProjectDirector projDir : projDirs) {
                            if (projDir.getPrincipalId().equals(ppd.getPrincipalId()))
                                continue;
                        }
                        projDirs.add(ppd);
                    } else {
                        LOG.error("Investigator: " + investigator.getNetId() + " is for award :" + projectId + " is not in kfs");
                    }
                } else {
                    LOG.error("Invesigator netId for award :" + projectId + " is null");
                }
            } else {
                LOG.error("Null investigator: " + pi.getInvestigatorId());
            }
        } else {
            LOG.error("Null investigator id: ");
        }
    }
    return projDirs;
}
Also used : HashMap(java.util.HashMap) PersonService(org.kuali.rice.kim.api.identity.PersonService) ArrayList(java.util.ArrayList) ProposalProjectDirector(org.kuali.kfs.module.cg.businessobject.ProposalProjectDirector) Investigator(edu.cornell.kfs.module.ezra.businessobject.Investigator) ProjectInvestigator(edu.cornell.kfs.module.ezra.businessobject.ProjectInvestigator) ArrayList(java.util.ArrayList) List(java.util.List) ProjectInvestigator(edu.cornell.kfs.module.ezra.businessobject.ProjectInvestigator) Person(org.kuali.rice.kim.api.identity.Person) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Investigator (edu.cornell.kfs.module.ezra.businessobject.Investigator)1 ProjectInvestigator (edu.cornell.kfs.module.ezra.businessobject.ProjectInvestigator)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ProposalProjectDirector (org.kuali.kfs.module.cg.businessobject.ProposalProjectDirector)1 Person (org.kuali.rice.kim.api.identity.Person)1 PersonService (org.kuali.rice.kim.api.identity.PersonService)1