Search in sources :

Example 6 with Opportunity

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

the class SalesForceManagerImpl method flagOpportunityAsClosed.

@Override
public void flagOpportunityAsClosed(String opportunityId) {
    String accountId = retrieveAccountIdByOrcid(sourceManager.retrieveRealUserOrcid());
    MemberDetails memberDetails = retrieveDetails(accountId);
    boolean authorized = memberDetails.getSubMembers().stream().anyMatch(s -> opportunityId.equals(s.getOpportunity().getId()));
    if (authorized) {
        Opportunity opportunity = new Opportunity();
        opportunity.setId(opportunityId);
        opportunity.setStageName(OPPORTUNITY_CLOSED_LOST);
        salesForceDao.updateOpportunity(opportunity);
    }
    // Need to make more granular!
    evictAll();
}
Also used : Opportunity(org.orcid.core.salesforce.model.Opportunity) MemberDetails(org.orcid.core.salesforce.model.MemberDetails)

Example 7 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, Contact initialContact) {
    String consortiumLeadId = member.getConsortiumLeadId();
    Member consortium = retrieveMember(consortiumLeadId);
    String consortiumOwnerId = consortium.getOwnerId();
    Opportunity opportunity = new Opportunity();
    URL websiteUrl = member.getWebsiteUrl();
    Optional<Member> firstExistingMember = findBestWebsiteMatch(websiteUrl);
    String accountId = null;
    if (firstExistingMember.isPresent()) {
        accountId = firstExistingMember.get().getId();
    } else {
        member.setParentId(consortiumLeadId);
        member.setOwnerId(consortiumOwnerId);
        member.setCountry(consortium.getCountry());
        accountId = salesForceDao.createMember(member);
    }
    opportunity.setOwnerId(consortiumOwnerId);
    opportunity.setTargetAccountId(accountId);
    opportunity.setConsortiumLeadId(consortiumLeadId);
    opportunity.setType(OPPORTUNITY_TYPE);
    opportunity.setMemberType(getPremiumConsortiumMemberTypeId());
    opportunity.setStageName(OPPORTUNITY_INITIAL_STAGE_NAME);
    opportunity.setCloseDate(calculateCloseDate());
    opportunity.setMembershipStartDate(consortium.getLastMembershipStartDate());
    opportunity.setMembershipEndDate(consortium.getLastMembershipEndDate());
    opportunity.setRecordTypeId(getConsortiumMemberRecordTypeId());
    opportunity.setName(OPPORTUNITY_NAME);
    String opportunityId = createOpportunity(opportunity);
    initialContact.setAccountId(accountId);
    createOpportunityContact(initialContact, opportunityId);
    removeMemberDetailsFromCache(consortiumLeadId);
    salesForceConsortiumCache.remove(consortiumLeadId);
    return accountId;
}
Also used : Opportunity(org.orcid.core.salesforce.model.Opportunity) OrcidString(org.orcid.core.cache.OrcidString) Member(org.orcid.core.salesforce.model.Member) SubMember(org.orcid.core.salesforce.model.SubMember) URL(java.net.URL)

Example 8 with Opportunity

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

the class SalesForceManagerImpl method checkOpportunityUpdatePermissions.

private void checkOpportunityUpdatePermissions(Opportunity opportunity) {
    Opportunity retrievedOpportunity = salesForceDao.retrieveOpportunity(opportunity.getId());
    if (!opportunity.getConsortiumLeadId().equals(retrievedOpportunity.getConsortiumLeadId())) {
        throw new IllegalStateException("Opportunity consortium lead mismatch");
    }
    if (!opportunity.getTargetAccountId().equals(retrievedOpportunity.getTargetAccountId())) {
        throw new IllegalStateException("Opportunity target account mismatch");
    }
    List<String> accountIds = retrieveAccountIdsByOrcid(sourceManager.retrieveRealUserOrcid());
    boolean authorized = accountIds.contains(retrievedOpportunity.getConsortiumLeadId());
    if (!authorized) {
        throw new OrcidUnauthorizedException("Insufficient permissions to update opportunity");
    }
}
Also used : OrcidUnauthorizedException(org.orcid.core.exception.OrcidUnauthorizedException) Opportunity(org.orcid.core.salesforce.model.Opportunity) OrcidString(org.orcid.core.cache.OrcidString)

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