Search in sources :

Example 1 with ContactRole

use of org.orcid.core.salesforce.model.ContactRole in project ORCID-Source by ORCID.

the class SalesForceMapperFacadeFactory method registerContactRoleMap.

private void registerContactRoleMap(MapperFactory mapperFactory) {
    ConverterFactory converterFactory = mapperFactory.getConverterFactory();
    converterFactory.registerConverter(new ContactRoleConverter());
    converterFactory.registerConverter(new ReverseContactRoleConverter());
    ClassMapBuilder<ContactRole, JSONObject> classMap = mapperFactory.classMap(ContactRole.class, JSONObject.class).mapNulls(false).mapNullsInReverse(false);
    classMap.field("id", "Id");
    classMap.field("accountId", "Organization__c");
    classMap.field("contactId", "Contact__c");
    classMap.field("votingContact", "Voting_Contact__c");
    classMap.field("roleType", "Member_Org_Role__c");
    classMap.register();
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) ConverterFactory(ma.glasnost.orika.converter.ConverterFactory) ContactRole(org.orcid.core.salesforce.model.ContactRole)

Example 2 with ContactRole

use of org.orcid.core.salesforce.model.ContactRole in project ORCID-Source by ORCID.

the class SalesForceManagerImplTest method testUpdateContact2.

@Test
public void testUpdateContact2() {
    // Switch from main to technical contact
    Contact contact = new Contact();
    contact.setId("contact2Id");
    contact.setAccountId("account1");
    ContactRole role = new ContactRole(ContactRoleType.TECHNICAL_CONTACT);
    role.setId("contact2Idrole1Id");
    contact.setRole(role);
    salesForceManager.updateContact(contact);
    verify(salesForceDao, times(1)).createContactRole(argThat(r -> {
        return "contact2Id".equals(r.getContactId()) && "account1Id".equals(r.getAccountId()) && ContactRoleType.TECHNICAL_CONTACT.equals(r.getRoleType());
    }));
    verify(salesForceDao, times(1)).removeContactRole(eq("contact2Idrole1Id"));
}
Also used : SalesForceManager(org.orcid.core.manager.SalesForceManager) SalesForceConnectionDao(org.orcid.persistence.dao.SalesForceConnectionDao) TargetProxyHelper(org.orcid.test.TargetProxyHelper) SelfPopulatingCache(net.sf.ehcache.constructs.blocking.SelfPopulatingCache) Mock(org.mockito.Mock) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) ArrayList(java.util.ArrayList) MockitoAnnotations(org.mockito.MockitoAnnotations) List(java.util.List) SalesForceConnectionEntity(org.orcid.persistence.jpa.entities.SalesForceConnectionEntity) Matchers.argThat(org.mockito.Matchers.argThat) Matchers.eq(org.mockito.Matchers.eq) SourceManager(org.orcid.core.manager.SourceManager) Contact(org.orcid.core.salesforce.model.Contact) ContactRole(org.orcid.core.salesforce.model.ContactRole) ContactRoleType(org.orcid.core.salesforce.model.ContactRoleType) Before(org.junit.Before) SalesForceDao(org.orcid.core.salesforce.dao.SalesForceDao) ContactRole(org.orcid.core.salesforce.model.ContactRole) Contact(org.orcid.core.salesforce.model.Contact) Test(org.junit.Test)

Example 3 with ContactRole

use of org.orcid.core.salesforce.model.ContactRole in project ORCID-Source by ORCID.

the class SalesForceManagerImplTest method createContactRole.

private ContactRole createContactRole(String contactId, String roleId, ContactRoleType roleType) {
    ContactRole contactRole = new ContactRole();
    contactRole.setId(roleId);
    contactRole.setRoleType(roleType);
    contactRole.setContactId(contactId);
    return contactRole;
}
Also used : ContactRole(org.orcid.core.salesforce.model.ContactRole)

Example 4 with ContactRole

use of org.orcid.core.salesforce.model.ContactRole in project ORCID-Source by ORCID.

the class SalesForceManagerImpl method updateContact.

@Override
public void updateContact(Contact contact) {
    String accountId = retrieveAccountIdByOrcid(sourceManager.retrieveRealUserOrcid());
    removeContactRole(contact);
    ContactRole contactRole = new ContactRole();
    contactRole.setAccountId(accountId);
    contactRole.setContactId(contact.getId());
    contactRole.setRoleType(contact.getRole().getRoleType());
    contactRole.setVotingContact(contact.getRole().isVotingContact());
    String contactRoleId = salesForceDao.createContactRole(contactRole);
    contact.getRole().setId(contactRoleId);
    // Need to make more granular!
    evictAll();
}
Also used : ContactRole(org.orcid.core.salesforce.model.ContactRole)

Example 5 with ContactRole

use of org.orcid.core.salesforce.model.ContactRole in project ORCID-Source by ORCID.

the class SalesForceManagerImpl method createContact.

@Override
public void createContact(Contact contact) {
    String accountId = retrieveAccountIdByOrcid(sourceManager.retrieveRealUserOrcid());
    contact.setAccountId(accountId);
    if (StringUtils.isBlank(contact.getEmail())) {
        String contactOrcid = contact.getOrcid();
        Email primaryEmail = emailManager.getEmails(contactOrcid, getLastModified(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 -> contact.getOrcid().equals(c.getOrcid())).findFirst();
    String contactId = existingContact.isPresent() ? existingContact.get().getId() : salesForceDao.createContact(contact);
    ContactRole contactRole = new ContactRole();
    contactRole.setContactId(contactId);
    contactRole.setRoleType(ContactRoleType.OTHER_CONTACT);
    contactRole.setAccountId(contact.getAccountId());
    salesForceDao.createContactRole(contactRole);
    // Need to make more granular!
    evictAll();
}
Also used : SalesForceManager(org.orcid.core.manager.SalesForceManager) SalesForceConnectionDao(org.orcid.persistence.dao.SalesForceConnectionDao) Date(java.util.Date) Member(org.orcid.core.salesforce.model.Member) EmailManager(org.orcid.core.manager.EmailManager) 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) Calendar(java.util.Calendar) 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) Opportunity(org.orcid.core.salesforce.model.Opportunity) SlugUtils(org.orcid.core.salesforce.model.SlugUtils) Collectors(java.util.stream.Collectors) List(java.util.List) MemberDetails(org.orcid.core.salesforce.model.MemberDetails) SourceManager(org.orcid.core.manager.SourceManager) Consortium(org.orcid.core.salesforce.model.Consortium) Optional(java.util.Optional) Contact(org.orcid.core.salesforce.model.Contact) Email(org.orcid.jaxb.model.record_v2.Email) 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) ContactRole(org.orcid.core.salesforce.model.ContactRole) Contact(org.orcid.core.salesforce.model.Contact)

Aggregations

ContactRole (org.orcid.core.salesforce.model.ContactRole)5 List (java.util.List)2 SelfPopulatingCache (net.sf.ehcache.constructs.blocking.SelfPopulatingCache)2 SalesForceManager (org.orcid.core.manager.SalesForceManager)2 SourceManager (org.orcid.core.manager.SourceManager)2 SalesForceDao (org.orcid.core.salesforce.dao.SalesForceDao)2 Contact (org.orcid.core.salesforce.model.Contact)2 ContactRoleType (org.orcid.core.salesforce.model.ContactRoleType)2 SalesForceConnectionDao (org.orcid.persistence.dao.SalesForceConnectionDao)2 SalesForceConnectionEntity (org.orcid.persistence.jpa.entities.SalesForceConnectionEntity)2 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Date (java.util.Date)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Resource (javax.annotation.Resource)1 ConverterFactory (ma.glasnost.orika.converter.ConverterFactory)1