Search in sources :

Example 1 with Contact

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

the class SalesForceAdapterTest method testCreateSalesForceRecordFromContact.

@Test
public void testCreateSalesForceRecordFromContact() {
    Contact contact = new Contact();
    contact.setAccountId("1234");
    JSONObject contactJson = salesForceAdapter.createSaleForceRecordFromContact(contact);
    assertEquals("{\"AccountId\":\"1234\"}", contactJson.toString());
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) Contact(org.orcid.core.salesforce.model.Contact) Test(org.junit.Test)

Example 2 with Contact

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

the class SalesForceAdapterTest method testCreateContactFromJson.

@Test
public void testCreateContactFromJson() throws IOException, JSONException {
    String inputString = IOUtils.toString(getClass().getResourceAsStream("/org/orcid/core/salesforce/salesforce_contacts_list.json"));
    JSONObject inputObject = new JSONObject(inputString);
    JSONArray records = inputObject.getJSONArray("records");
    JSONObject record = records.getJSONObject(0);
    JSONObject contactRoles = record.getJSONObject("Membership_Contact_Roles__r");
    JSONArray contactRoleRecords = contactRoles.getJSONArray("records");
    JSONObject contactRole = contactRoleRecords.getJSONObject(0);
    Contact contact = salesForceAdapter.createContactFromJson(contactRole);
    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) JSONArray(org.codehaus.jettison.json.JSONArray) Contact(org.orcid.core.salesforce.model.Contact) Test(org.junit.Test)

Example 3 with Contact

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

the class SalesForceAdapter method createContactsWithRolesFromJson.

public List<Contact> createContactsWithRolesFromJson(JSONObject object) {
    try {
        JSONObject firstRecord = extractFirstRecord(object);
        JSONObject contactRoles = firstRecord.getJSONObject("Membership_Contact_Roles__r");
        List<JSONObject> objectsList = extractObjectListFromRecords(contactRoles);
        return objectsList.stream().map(e -> mapperFacade.map(e, Contact.class)).collect(Collectors.toList());
    } catch (JSONException e) {
        throw new RuntimeException("Error getting contacts with roles list from SalesForce JSON", e);
    }
}
Also used : JsonUtils.extractString(org.orcid.core.utils.JsonUtils.extractString) Logger(org.slf4j.Logger) MalformedURLException(java.net.MalformedURLException) URL(java.net.URL) Resource(javax.annotation.Resource) Member(org.orcid.core.salesforce.model.Member) LoggerFactory(org.slf4j.LoggerFactory) JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) JsonUtils.extractObject(org.orcid.core.utils.JsonUtils.extractObject) Opportunity(org.orcid.core.salesforce.model.Opportunity) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) List(java.util.List) JsonUtils(org.orcid.core.utils.JsonUtils) JSONException(org.codehaus.jettison.json.JSONException) MapperFacade(ma.glasnost.orika.MapperFacade) Consortium(org.orcid.core.salesforce.model.Consortium) Contact(org.orcid.core.salesforce.model.Contact) Integration(org.orcid.core.salesforce.model.Integration) ContactRole(org.orcid.core.salesforce.model.ContactRole) JSONObject(org.codehaus.jettison.json.JSONObject) JSONException(org.codehaus.jettison.json.JSONException)

Example 4 with Contact

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

the class ResultContainer method findConsortium.

@RequestMapping(value = "/find-consortium.json", method = RequestMethod.GET)
@ResponseBody
public ConsortiumForm findConsortium(@RequestParam("id") String id) {
    MemberDetails memberDetails = salesForceManager.retrieveDetails(id);
    ConsortiumForm consortiumForm = ConsortiumForm.fromMemberDetails(memberDetails);
    List<Contact> contactsList = salesForceManager.retrieveContactsByAccountId(id);
    salesForceManager.addOrcidsToContacts(contactsList);
    consortiumForm.setContactsList(contactsList);
    consortiumForm.setRoleMap(generateSalesForceRoleMap());
    return consortiumForm;
}
Also used : ConsortiumForm(org.orcid.pojo.ajaxForm.ConsortiumForm) MemberDetails(org.orcid.core.salesforce.model.MemberDetails) Contact(org.orcid.core.salesforce.model.Contact) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 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)

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