Search in sources :

Example 11 with MemberDetails

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;
}
Also used : SalesForceManager(org.orcid.core.manager.SalesForceManager) SalesForceConnectionDao(org.orcid.persistence.dao.SalesForceConnectionDao) URL(java.net.URL) Date(java.util.Date) Member(org.orcid.core.salesforce.model.Member) GenericCacheManager(org.orcid.core.cache.GenericCacheManager) EmailManager(org.orcid.core.manager.EmailManager) ContactPermission(org.orcid.core.salesforce.model.ContactPermission) DateUtils(org.orcid.utils.DateUtils) MemberDetailsCacheKey(org.orcid.core.salesforce.cache.MemberDetailsCacheKey) StringUtils(org.apache.commons.lang3.StringUtils) ManagerReadOnlyBaseImpl(org.orcid.core.manager.read_only.impl.ManagerReadOnlyBaseImpl) ArrayList(java.util.ArrayList) SalesForceConnectionEntity(org.orcid.persistence.jpa.entities.SalesForceConnectionEntity) Map(java.util.Map) ContactRole(org.orcid.core.salesforce.model.ContactRole) SelfPopulatingCache(net.sf.ehcache.constructs.blocking.SelfPopulatingCache) Collection(java.util.Collection) Resource(javax.annotation.Resource) OrcidUnauthorizedException(org.orcid.core.exception.OrcidUnauthorizedException) Opportunity(org.orcid.core.salesforce.model.Opportunity) SlugUtils(org.orcid.core.salesforce.model.SlugUtils) Collectors(java.util.stream.Collectors) ObjectUtils(org.apache.commons.lang.ObjectUtils) Objects(java.util.Objects) List(java.util.List) MemberDetails(org.orcid.core.salesforce.model.MemberDetails) OrcidString(org.orcid.core.cache.OrcidString) SourceManager(org.orcid.core.manager.SourceManager) Consortium(org.orcid.core.salesforce.model.Consortium) Optional(java.util.Optional) Contact(org.orcid.core.salesforce.model.Contact) OrgId(org.orcid.core.salesforce.model.OrgId) OpportunityContactRole(org.orcid.core.salesforce.model.OpportunityContactRole) Email(org.orcid.jaxb.model.record_v2.Email) Pattern(java.util.regex.Pattern) ContactRoleType(org.orcid.core.salesforce.model.ContactRoleType) SubMember(org.orcid.core.salesforce.model.SubMember) ReleaseNameUtils(org.orcid.utils.ReleaseNameUtils) Collections(java.util.Collections) SalesForceDao(org.orcid.core.salesforce.dao.SalesForceDao) OrcidString(org.orcid.core.cache.OrcidString) MemberDetails(org.orcid.core.salesforce.model.MemberDetails) Member(org.orcid.core.salesforce.model.Member) SubMember(org.orcid.core.salesforce.model.SubMember) URL(java.net.URL)

Example 12 with MemberDetails

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;
}
Also used : MalformedURLException(java.net.MalformedURLException) MemberDetails(org.orcid.core.salesforce.model.MemberDetails) Member(org.orcid.core.salesforce.model.Member) SubMember(org.orcid.core.salesforce.model.SubMember) URL(java.net.URL)

Example 13 with 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;
}
Also used : MemberDetails(org.orcid.core.salesforce.model.MemberDetails)

Example 14 with MemberDetails

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;
}
Also used : MemberDetails(org.orcid.core.salesforce.model.MemberDetails) Member(org.orcid.core.salesforce.model.Member) SubMember(org.orcid.core.salesforce.model.SubMember) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 15 with MemberDetails

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);
    }
}
Also used : OrcidUnauthorizedException(org.orcid.core.exception.OrcidUnauthorizedException) MemberDetails(org.orcid.core.salesforce.model.MemberDetails)

Aggregations

MemberDetails (org.orcid.core.salesforce.model.MemberDetails)15 Member (org.orcid.core.salesforce.model.Member)8 SubMember (org.orcid.core.salesforce.model.SubMember)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)5 URL (java.net.URL)4 OrcidUnauthorizedException (org.orcid.core.exception.OrcidUnauthorizedException)3 MemberDetailsCacheKey (org.orcid.core.salesforce.cache.MemberDetailsCacheKey)3 Contact (org.orcid.core.salesforce.model.Contact)3 Opportunity (org.orcid.core.salesforce.model.Opportunity)3 MalformedURLException (java.net.MalformedURLException)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Date (java.util.Date)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Resource (javax.annotation.Resource)2 SelfPopulatingCache (net.sf.ehcache.constructs.blocking.SelfPopulatingCache)2