Search in sources :

Example 1 with Consortium

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

the class GetConsortiumFromSalesForceById method main.

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

Example 2 with Consortium

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

Consortium (org.orcid.core.salesforce.model.Consortium)2 ArrayList (java.util.ArrayList)1 JSONArray (org.codehaus.jettison.json.JSONArray)1 JSONException (org.codehaus.jettison.json.JSONException)1 JSONObject (org.codehaus.jettison.json.JSONObject)1 SalesForceManager (org.orcid.core.manager.SalesForceManager)1 Opportunity (org.orcid.core.salesforce.model.Opportunity)1 ApplicationContext (org.springframework.context.ApplicationContext)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1