use of org.orcid.core.salesforce.model.OpportunityContactRole in project ORCID-Source by ORCID.
the class SalesForceManagerImpl method createOpportunityContact.
private void createOpportunityContact(Contact contact, String opportunityId) {
String accountId = contact.getAccountId();
String contactOrcid = contact.getOrcid();
if (StringUtils.isBlank(contact.getEmail())) {
Email primaryEmail = emailManager.getEmails(contactOrcid).getEmails().stream().filter(e -> e.isPrimary()).findFirst().get();
contact.setEmail(primaryEmail.getEmail());
}
List<Contact> existingContacts = salesForceDao.retrieveAllContactsByAccountId(accountId);
Optional<Contact> existingContact = existingContacts.stream().filter(c -> {
if ((contact.getOrcid() != null && contact.getOrcid().equals(c.getOrcid())) || (contact.getEmail() != null && contact.getEmail().equals(c.getEmail()))) {
return true;
}
return false;
}).findFirst();
String contactId = existingContact.isPresent() ? existingContact.get().getId() : salesForceDao.createContact(contact);
OpportunityContactRole contactRole = new OpportunityContactRole();
contactRole.setContactId(contactId);
contactRole.setRoleType(ContactRoleType.MAIN_CONTACT);
contactRole.setOpportunityId(opportunityId);
salesForceDao.createOpportunityContactRole(contactRole);
addSalesForceConnection(accountId, contact);
}
Aggregations