Search in sources :

Example 71 with JSONArray

use of org.codehaus.jettison.json.JSONArray in project ORCID-Source by ORCID.

the class SalesForceAdapterTest method testCreateMemberFromSalesForceRecordWithNullValues.

@Test
public void testCreateMemberFromSalesForceRecordWithNullValues() throws IOException, JSONException {
    String inputString = IOUtils.toString(getClass().getResourceAsStream("/org/orcid/core/salesforce/salesforce_members_list.json"));
    JSONObject inputObject = new JSONObject(inputString);
    JSONArray records = inputObject.getJSONArray("records");
    JSONObject record = records.getJSONObject(1);
    record.put("Name", (String) null);
    Member member = salesForceAdapter.createMemberFromSalesForceRecord(record);
    assertEquals("001J000001pZwWYIA0", member.getId());
    assertNull(member.getName());
    assertEquals("http://org3.edu", member.getWebsiteUrl().toString());
    assertEquals(CommunityType.RESEARCH_INSTITUTE, member.getResearchCommunity());
    assertEquals("New Zealand", member.getCountry());
    assertEquals("This is the public display description for Org 3 Consortium Member", member.getDescription());
    assertEquals("https://dl.dropboxusercontent.com/s/yk2tgl9ze7z7y2g/test_logo.png", member.getLogoUrl().toString());
    assertEquals("orcid@org3.org", member.getPublicDisplayEmail());
    assertEquals("006J000000LThfcIAD", member.getMainOpportunityId());
    assertNull(member.getConsortiumLeadId());
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) Member(org.orcid.core.salesforce.model.Member) Test(org.junit.Test)

Example 72 with JSONArray

use of org.codehaus.jettison.json.JSONArray in project ORCID-Source by ORCID.

the class SalesForceAdapterTest method testCreateOpportunityFromSalesForceRecord.

@Test
public void testCreateOpportunityFromSalesForceRecord() throws IOException, JSONException {
    String inputString = IOUtils.toString(getClass().getResourceAsStream("/org/orcid/core/salesforce/salesforce_opportunities_list.json"));
    JSONArray inputArray = new JSONArray(inputString);
    Opportunity opportunity = salesForceAdapter.createOpportunityFromSalesForceRecord(inputArray.getJSONObject(1));
    assertEquals("[ORG2 ACCOUNT ID]", opportunity.getTargetAccountId());
    assertEquals("Invoice Paid", opportunity.getStageName());
    assertEquals("2016-12-21", opportunity.getCloseDate());
    assertEquals("New", opportunity.getType());
    assertEquals("[PREMIUM CONSORTIUM MEMBER ID]", opportunity.getMemberType());
    assertEquals("2017-01-01", opportunity.getMembershipStartDate());
    assertEquals("2017-12-31", opportunity.getMembershipEndDate());
    assertEquals("[ORG1 ACCOUNT ID]", opportunity.getConsortiumLeadId());
    assertEquals("2017 Membership-Org 2 Consortium Member", opportunity.getName());
    assertEquals("[CONSORTIUM MEMBER RECORD TYPE ID]", opportunity.getRecordTypeId());
}
Also used : Opportunity(org.orcid.core.salesforce.model.Opportunity) JSONArray(org.codehaus.jettison.json.JSONArray) Test(org.junit.Test)

Example 73 with JSONArray

use of org.codehaus.jettison.json.JSONArray 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 74 with JSONArray

use of org.codehaus.jettison.json.JSONArray in project ORCID-Source by ORCID.

the class SalesForceAdapterTest method testCreateMemberFromSalesForceRecord.

@Test
public void testCreateMemberFromSalesForceRecord() throws IOException, JSONException {
    String inputString = IOUtils.toString(getClass().getResourceAsStream("/org/orcid/core/salesforce/salesforce_members_list.json"));
    JSONObject inputObject = new JSONObject(inputString);
    JSONArray records = inputObject.getJSONArray("records");
    Member member = salesForceAdapter.createMemberFromSalesForceRecord(records.getJSONObject(0));
    assertEquals("001J000001pZwWXIA0", member.getId());
    assertEquals("Org 2 Consortium Member", member.getName());
    assertEquals("001J000001pZwWXIA0-org-2-consortium-member", member.getSlug());
    assertEquals("http://org2.edu", member.getWebsiteUrl().toString());
    assertEquals(CommunityType.RESEARCH_INSTITUTE, member.getResearchCommunity());
    assertEquals("New Zealand", member.getCountry());
    assertEquals("This is the public display description for Org 2 Consortium Member", member.getDescription());
    assertEquals("https://dl.dropboxusercontent.com/s/yk2tgl9ze7z7y2g/test_logo.png", member.getLogoUrl().toString());
    assertEquals("orcid@org2.org", member.getPublicDisplayEmail());
    assertEquals("006J000000LThfbIAD", member.getMainOpportunityId());
    assertEquals("001J000001pZwWWIA0", member.getConsortiumLeadId());
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) Member(org.orcid.core.salesforce.model.Member) Test(org.junit.Test)

Example 75 with JSONArray

use of org.codehaus.jettison.json.JSONArray in project ORCID-Source by ORCID.

the class SalesForceAdapter method createConsortiumFromJson.

public Consortium createConsortiumFromJson(JSONObject results) {
    try {
        int numFound = JsonUtils.extractInt(results, "totalSize");
        if (numFound == 0) {
            return null;
        }
        Consortium consortium = new Consortium();
        List<Opportunity> opportunityList = new ArrayList<>();
        consortium.setOpportunities(opportunityList);
        JSONArray records = results.getJSONArray("records");
        JSONObject firstRecord = records.getJSONObject(0);
        JSONObject opportunities = extractObject(firstRecord, "ConsortiaOpportunities__r");
        if (opportunities != null) {
            JSONArray opportunityRecords = opportunities.getJSONArray("records");
            for (int i = 0; i < opportunityRecords.length(); i++) {
                Opportunity salesForceOpportunity = new Opportunity();
                JSONObject opportunity = opportunityRecords.getJSONObject(i);
                salesForceOpportunity.setId(extractOpportunityId(opportunity));
                JSONObject account = extractObject(opportunity, "Account");
                salesForceOpportunity.setTargetAccountId(extractAccountId(account));
                // salesForceOpportunity.setAccountName(JsonUtils.extractString(account,
                // "Name"));
                salesForceOpportunity.setAccountName(JsonUtils.extractString(account, "Public_Display_Name__c"));
                opportunityList.add(salesForceOpportunity);
            }
            return consortium;
        }
    } catch (JSONException e) {
        throw new RuntimeException("Error getting consortium record from SalesForce JSON", e);
    }
    return null;
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) Opportunity(org.orcid.core.salesforce.model.Opportunity) Consortium(org.orcid.core.salesforce.model.Consortium) ArrayList(java.util.ArrayList) JSONArray(org.codehaus.jettison.json.JSONArray) JSONException(org.codehaus.jettison.json.JSONException)

Aggregations

JSONArray (org.codehaus.jettison.json.JSONArray)338 JSONObject (org.codehaus.jettison.json.JSONObject)280 Test (org.junit.Test)123 WebResource (com.sun.jersey.api.client.WebResource)65 ClientResponse (com.sun.jersey.api.client.ClientResponse)64 JSONException (org.codehaus.jettison.json.JSONException)64 ArrayList (java.util.ArrayList)38 Test (org.testng.annotations.Test)30 Map (java.util.Map)23 HashMap (java.util.HashMap)22 Vertex (com.tinkerpop.blueprints.Vertex)20 Job (org.apache.hadoop.mapreduce.v2.app.job.Job)20 Produces (javax.ws.rs.Produces)17 MockNM (org.apache.hadoop.yarn.server.resourcemanager.MockNM)14 GET (javax.ws.rs.GET)13 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)13 IOException (java.io.IOException)12 JobId (org.apache.hadoop.mapreduce.v2.api.records.JobId)12 HashSet (java.util.HashSet)10 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)9