Search in sources :

Example 1 with OpportunityContactRole

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);
}
Also used : SalesForceManager(org.orcid.core.manager.SalesForceManager) SalesForceConnectionDao(org.orcid.persistence.dao.SalesForceConnectionDao) URL(java.net.URL) Date(java.util.Date) Member(org.orcid.core.salesforce.model.Member) GenericCacheManager(org.orcid.core.cache.GenericCacheManager) EmailManager(org.orcid.core.manager.EmailManager) ContactPermission(org.orcid.core.salesforce.model.ContactPermission) DateUtils(org.orcid.utils.DateUtils) MemberDetailsCacheKey(org.orcid.core.salesforce.cache.MemberDetailsCacheKey) StringUtils(org.apache.commons.lang3.StringUtils) ManagerReadOnlyBaseImpl(org.orcid.core.manager.read_only.impl.ManagerReadOnlyBaseImpl) ArrayList(java.util.ArrayList) SalesForceConnectionEntity(org.orcid.persistence.jpa.entities.SalesForceConnectionEntity) Map(java.util.Map) ContactRole(org.orcid.core.salesforce.model.ContactRole) SelfPopulatingCache(net.sf.ehcache.constructs.blocking.SelfPopulatingCache) Collection(java.util.Collection) Resource(javax.annotation.Resource) OrcidUnauthorizedException(org.orcid.core.exception.OrcidUnauthorizedException) Opportunity(org.orcid.core.salesforce.model.Opportunity) SlugUtils(org.orcid.core.salesforce.model.SlugUtils) Collectors(java.util.stream.Collectors) ObjectUtils(org.apache.commons.lang.ObjectUtils) Objects(java.util.Objects) List(java.util.List) MemberDetails(org.orcid.core.salesforce.model.MemberDetails) OrcidString(org.orcid.core.cache.OrcidString) SourceManager(org.orcid.core.manager.SourceManager) Consortium(org.orcid.core.salesforce.model.Consortium) Optional(java.util.Optional) Contact(org.orcid.core.salesforce.model.Contact) OrgId(org.orcid.core.salesforce.model.OrgId) OpportunityContactRole(org.orcid.core.salesforce.model.OpportunityContactRole) Email(org.orcid.jaxb.model.record_v2.Email) Pattern(java.util.regex.Pattern) ContactRoleType(org.orcid.core.salesforce.model.ContactRoleType) SubMember(org.orcid.core.salesforce.model.SubMember) ReleaseNameUtils(org.orcid.utils.ReleaseNameUtils) Collections(java.util.Collections) SalesForceDao(org.orcid.core.salesforce.dao.SalesForceDao) Email(org.orcid.jaxb.model.record_v2.Email) OpportunityContactRole(org.orcid.core.salesforce.model.OpportunityContactRole) OrcidString(org.orcid.core.cache.OrcidString) Contact(org.orcid.core.salesforce.model.Contact)

Aggregations

URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 Resource (javax.annotation.Resource)1 SelfPopulatingCache (net.sf.ehcache.constructs.blocking.SelfPopulatingCache)1 ObjectUtils (org.apache.commons.lang.ObjectUtils)1 StringUtils (org.apache.commons.lang3.StringUtils)1 GenericCacheManager (org.orcid.core.cache.GenericCacheManager)1 OrcidString (org.orcid.core.cache.OrcidString)1 OrcidUnauthorizedException (org.orcid.core.exception.OrcidUnauthorizedException)1 EmailManager (org.orcid.core.manager.EmailManager)1 SalesForceManager (org.orcid.core.manager.SalesForceManager)1