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