use of org.orcid.core.salesforce.model.MemberDetails in project ORCID-Source by ORCID.
the class SalesForceManagerImpl method checkExistingSubMember.
@Override
public boolean checkExistingSubMember(Member member, String parentAccountId) {
boolean subMemberExists = false;
URL websiteUrl = member.getWebsiteUrl();
Optional<Member> firstExistingMember = findBestWebsiteMatch(websiteUrl);
if (firstExistingMember.isPresent()) {
String subMemberAcccountId = firstExistingMember.get().getId();
MemberDetails memberDetails = retrieveDetails(parentAccountId);
subMemberExists = memberDetails.getSubMembers().stream().anyMatch(s -> subMemberAcccountId.equals(s.getOpportunity().getTargetAccountId()));
}
return subMemberExists;
}
use of org.orcid.core.salesforce.model.MemberDetails in project ORCID-Source by ORCID.
the class MemberDetailsForm method toMemberDetails.
public MemberDetails toMemberDetails() {
MemberDetails memberDetails = new MemberDetails();
Member member = new Member();
memberDetails.setMember(member);
member.setId(getAccountId());
member.setPublicDisplayName(getName().getValue());
Text website = getWebsite();
if (website != null) {
try {
String websiteValue = website.getValue();
if (StringUtils.isNotBlank(websiteValue)) {
if (!websiteValue.startsWith("http")) {
websiteValue = "http://" + websiteValue;
}
member.setWebsiteUrl(new URL(websiteValue));
}
} catch (MalformedURLException e) {
throw new RuntimeException("Error parsing website", e);
}
}
member.setPublicDisplayEmail(getEmail().getValue());
member.setDescription(getDescription().getValue());
Text communityText = getCommunity();
if (communityText != null) {
member.setResearchCommunity(CommunityType.valueOf(communityText.getValue()));
}
return memberDetails;
}
use of org.orcid.core.salesforce.model.MemberDetails in project ORCID-Source by ORCID.
the class SalesForceDaoImpl method retrieveDetailsFromSalesForce.
/**
* @throws SalesForceUnauthorizedException
* If the status code from SalesForce is 401, e.g. access token
* expired.
*/
private MemberDetails retrieveDetailsFromSalesForce(String accessToken, String memberId, String consortiumLeadId) throws SalesForceUnauthorizedException {
MemberDetails details = new MemberDetails();
String parentOrgName = retrieveParentOrgNameFromSalesForce(accessToken, consortiumLeadId);
details.setParentOrgName(parentOrgName);
details.setParentOrgSlug(SlugUtils.createSlug(consortiumLeadId, parentOrgName));
details.setIntegrations(retrieveIntegrationsFromSalesForce(accessToken, memberId));
return details;
}
use of org.orcid.core.salesforce.model.MemberDetails in project ORCID-Source by ORCID.
the class SelfServiceController method updateMemberDetails.
@RequestMapping(value = "/update-member-details.json", method = RequestMethod.POST)
@ResponseBody
public MemberDetailsForm updateMemberDetails(@RequestBody MemberDetailsForm consortium) {
MemberDetails memberDetails = consortium.toMemberDetails();
Member member = memberDetails.getMember();
checkAccess(member.getId());
salesForceManager.updateMember(member);
return consortium;
}
use of org.orcid.core.salesforce.model.MemberDetails in project ORCID-Source by ORCID.
the class SelfServiceController method checkAccess.
private void checkAccess(String memberId) {
List<String> usersAuthorizedAccountIds = salesForceManager.retrieveAccountIdsByOrcid(sourceManager.retrieveSourceOrcid());
MemberDetails memberDetails = salesForceManager.retrieveDetails(memberId);
if (!(usersAuthorizedAccountIds.contains(memberId) || usersAuthorizedAccountIds.contains(memberDetails.getMember().getConsortiumLeadId()))) {
throw new OrcidUnauthorizedException("You are not authorized for account ID = " + memberId);
}
}
Aggregations