Search in sources :

Example 1 with Opportunity

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

the class SalesForceManagerImpl method createMember.

@Override
public String createMember(Member member) {
    Opportunity opportunity = new Opportunity();
    Optional<Member> firstExistingMember = salesForceDao.retrieveMembersByWebsite(member.getWebsiteUrl().toString()).stream().findFirst();
    String accountId = null;
    if (firstExistingMember.isPresent()) {
        accountId = firstExistingMember.get().getId();
    } else {
        accountId = salesForceDao.createMember(member);
    }
    opportunity.setTargetAccountId(accountId);
    opportunity.setConsortiumLeadId(retrieveAccountIdByOrcid(sourceManager.retrieveRealUserOrcid()));
    opportunity.setType(OPPORTUNITY_TYPE);
    opportunity.setMemberType(getPremiumConsortiumMemberTypeId());
    opportunity.setStageName(OPPORTUNITY_INITIAL_STAGE_NAME);
    opportunity.setCloseDate(calculateCloseDate());
    opportunity.setMembershipStartDate(calculateMembershipStartDate());
    opportunity.setMembershipEndDate(calculateMembershipEndDate());
    opportunity.setRecordTypeId(getConsortiumMemberRecordTypeId());
    opportunity.setName(OPPORTUNITY_NAME);
    createOpportunity(opportunity);
    evictAll();
    return accountId;
}
Also used : Opportunity(org.orcid.core.salesforce.model.Opportunity) Member(org.orcid.core.salesforce.model.Member) SubMember(org.orcid.core.salesforce.model.SubMember)

Example 2 with Opportunity

use of org.orcid.core.salesforce.model.Opportunity 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 = createOpportunityFromSalesForceRecord(opportunityRecords.getJSONObject(i));
                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)

Example 3 with Opportunity

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

the class SalesForceManagerImpl method flagOpportunityAsRemovalNotRequested.

@Override
public void flagOpportunityAsRemovalNotRequested(Opportunity opportunity) {
    String userOrcid = sourceManager.retrieveRealUserOrcid();
    checkOpportunityUpdatePermissions(opportunity);
    Opportunity updatedOpportunity = new Opportunity();
    updatedOpportunity.setId(opportunity.getId());
    updatedOpportunity.setRemovalRequested(false);
    updatedOpportunity.setNextStep("Removal request cancelled by " + userOrcid);
    salesForceDao.updateOpportunity(updatedOpportunity);
    salesForceMembersListCache.removeAll();
    String consortiumLeadId = opportunity.getConsortiumLeadId();
    removeMemberDetailsFromCache(consortiumLeadId);
    salesForceConsortiumCache.remove(consortiumLeadId);
}
Also used : Opportunity(org.orcid.core.salesforce.model.Opportunity) OrcidString(org.orcid.core.cache.OrcidString)

Example 4 with Opportunity

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

the class SalesForceManagerImpl method flagOpportunityAsRemovalRequested.

@Override
public void flagOpportunityAsRemovalRequested(Opportunity opportunity) {
    String userOrcid = sourceManager.retrieveRealUserOrcid();
    String consortiumLeadId = opportunity.getConsortiumLeadId();
    checkOpportunityUpdatePermissions(opportunity);
    Opportunity updatedOpportunity = new Opportunity();
    updatedOpportunity.setId(opportunity.getId());
    updatedOpportunity.setRemovalRequested(true);
    updatedOpportunity.setNextStep("Removal requested by " + userOrcid);
    salesForceDao.updateOpportunity(updatedOpportunity);
    salesForceMembersListCache.removeAll();
    removeMemberDetailsFromCache(consortiumLeadId);
    salesForceConsortiumCache.remove(consortiumLeadId);
}
Also used : Opportunity(org.orcid.core.salesforce.model.Opportunity) OrcidString(org.orcid.core.cache.OrcidString)

Example 5 with Opportunity

use of org.orcid.core.salesforce.model.Opportunity 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("Another consortium member org", opportunity.getAccountName());
    assertEquals("Another consortium member org Public Display Name", opportunity.getAccountPublicDisplayName());
    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());
    assertEquals("Next step description", opportunity.getNextStep());
    assertTrue(opportunity.isRemovalRequested());
}
Also used : Opportunity(org.orcid.core.salesforce.model.Opportunity) JSONArray(org.codehaus.jettison.json.JSONArray) Test(org.junit.Test)

Aggregations

Opportunity (org.orcid.core.salesforce.model.Opportunity)8 OrcidString (org.orcid.core.cache.OrcidString)4 JSONArray (org.codehaus.jettison.json.JSONArray)2 Member (org.orcid.core.salesforce.model.Member)2 SubMember (org.orcid.core.salesforce.model.SubMember)2 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 JSONException (org.codehaus.jettison.json.JSONException)1 JSONObject (org.codehaus.jettison.json.JSONObject)1 Test (org.junit.Test)1 OrcidUnauthorizedException (org.orcid.core.exception.OrcidUnauthorizedException)1 Consortium (org.orcid.core.salesforce.model.Consortium)1 MemberDetails (org.orcid.core.salesforce.model.MemberDetails)1