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