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