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();
}
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"));
}
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;
}
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();
}
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();
}
Aggregations