Search in sources :

Example 6 with Contact

use of org.orcid.core.salesforce.model.Contact 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 7 with Contact

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

the class SalesForceAdapterTest method testCreateContactsFromJson.

@Test
public void testCreateContactsFromJson() throws IOException, JSONException {
    String inputString = IOUtils.toString(getClass().getResourceAsStream("/org/orcid/core/salesforce/salesforce_contacts_list.json"));
    JSONObject inputObject = new JSONObject(inputString);
    List<Contact> contactsList = salesForceAdapter.createContactsWithRolesFromJson(inputObject);
    assertEquals(2, contactsList.size());
    Contact contact = contactsList.get(0);
    assertEquals("Contact1FirstName Contact1LastName", contact.getName());
    assertEquals("contact1@mailinator.com", contact.getEmail());
    assertEquals(ContactRoleType.MAIN_CONTACT, contact.getRole().getRoleType());
    assertTrue(contact.getRole().isVotingContact());
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) Contact(org.orcid.core.salesforce.model.Contact) Test(org.junit.Test)

Example 8 with Contact

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

the class ManageConsortiumController method getContacts.

@RequestMapping(value = "/get-contacts.json", method = RequestMethod.GET)
@ResponseBody
public ContactsForm getContacts() {
    String accountId = salesForceManager.retrieveAccountIdByOrcid(getCurrentUserOrcid());
    ContactsForm contactsForm = new ContactsForm();
    List<Contact> contactsList = salesForceManager.retrieveContactsByAccountId(accountId);
    salesForceManager.addOrcidsToContacts(contactsList);
    contactsForm.setContactsList(contactsList);
    contactsForm.setRoleMap(generateSalesForceRoleMap());
    return contactsForm;
}
Also used : ContactsForm(org.orcid.pojo.ajaxForm.ContactsForm) Contact(org.orcid.core.salesforce.model.Contact) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 9 with Contact

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

the class ManageConsortiumController method validateContacts.

@RequestMapping(value = "/validate-contacts.json", method = RequestMethod.POST)
@ResponseBody
public ContactsForm validateContacts(@RequestBody ContactsForm contactsForm) {
    List<String> errors = contactsForm.getErrors();
    errors.clear();
    int agreementSignatoryContactCount = 0;
    int mainContactCount = 0;
    int votingContactCount = 0;
    for (Contact contact : contactsForm.getContactsList()) {
        if (ContactRoleType.AGREEMENT_SIGNATORY.equals(contact.getRole().getRoleType())) {
            agreementSignatoryContactCount++;
        }
        if (ContactRoleType.MAIN_CONTACT.equals(contact.getRole().getRoleType())) {
            mainContactCount++;
        }
        if (contact.getRole().isVotingContact()) {
            votingContactCount++;
        }
    }
    if (agreementSignatoryContactCount == 0) {
        errors.add(getMessage("manage_consortium.contacts_must_have_agreement_signatory_contact"));
    }
    if (agreementSignatoryContactCount > 1) {
        errors.add(getMessage("manage_consortium.contacts_must_not_have_more_than_one_agreement_signatory_contact"));
    }
    if (mainContactCount == 0) {
        errors.add(getMessage("manage_consortium.contacts_must_have_main_contact"));
    }
    if (mainContactCount > 1) {
        errors.add(getMessage("manage_consortium.contacts_must_not_have_more_than_one_main_contact"));
    }
    if (votingContactCount == 0) {
        errors.add(getMessage("manage_consortium.contacts_must_have_voting_contact"));
    }
    if (votingContactCount > 1) {
        errors.add(getMessage("manage_consortium.contacts_must_not_have_more_than_one_voting_contact"));
    }
    return contactsForm;
}
Also used : Contact(org.orcid.core.salesforce.model.Contact) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 10 with Contact

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

the class GetContactsFromSalesForceByAccountId method main.

@SuppressWarnings("resource")
public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("orcid-core-context.xml");
    SalesForceManager salesForceManager = (SalesForceManager) context.getBean("salesForceManager");
    List<Contact> contacts = salesForceManager.retrieveContactsByAccountId(args[0]);
    System.out.println(contacts);
    System.exit(0);
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SalesForceManager(org.orcid.core.manager.SalesForceManager) Contact(org.orcid.core.salesforce.model.Contact)

Aggregations

Contact (org.orcid.core.salesforce.model.Contact)10 JSONObject (org.codehaus.jettison.json.JSONObject)4 Test (org.junit.Test)4 List (java.util.List)3 SalesForceManager (org.orcid.core.manager.SalesForceManager)3 ContactRole (org.orcid.core.salesforce.model.ContactRole)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 ArrayList (java.util.ArrayList)2 Collectors (java.util.stream.Collectors)2 Resource (javax.annotation.Resource)2 SelfPopulatingCache (net.sf.ehcache.constructs.blocking.SelfPopulatingCache)2 StringUtils (org.apache.commons.lang3.StringUtils)2 JSONArray (org.codehaus.jettison.json.JSONArray)2 SourceManager (org.orcid.core.manager.SourceManager)2 SalesForceDao (org.orcid.core.salesforce.dao.SalesForceDao)2 Consortium (org.orcid.core.salesforce.model.Consortium)2 ContactRoleType (org.orcid.core.salesforce.model.ContactRoleType)2 Member (org.orcid.core.salesforce.model.Member)2 MemberDetails (org.orcid.core.salesforce.model.MemberDetails)2