Search in sources :

Example 6 with MemberType

use of org.orcid.jaxb.model.clientgroup.MemberType in project ORCID-Source by ORCID.

the class MembersManagerImpl method getMember.

@Override
@Transactional
public Member getMember(String memberId) {
    Member member = new Member();
    String orcid = memberId;
    if (!OrcidStringUtils.isValidOrcid(memberId)) {
        Map<String, String> ids = emailManager.findOricdIdsByCommaSeparatedEmails(memberId);
        // Check if it is using the email
        if (ids != null && ids.containsKey(memberId)) {
            orcid = ids.get(memberId);
        } else {
            // Check if can find it by name
            try {
                orcid = profileEntityManager.findByCreditName(memberId);
            } catch (Exception e) {
                member.getErrors().add(getMessage("manage_member.email_not_found"));
                orcid = null;
            }
        }
    }
    if (PojoUtil.isEmpty(orcid)) {
        member.getErrors().add(getMessage("manage_member.email_not_found"));
    } else {
        if (profileEntityManager.orcidExists(orcid)) {
            MemberType groupType = profileEntityManager.getGroupType(orcid);
            if (groupType != null) {
                ProfileEntity memberProfile = profileDao.find(orcid);
                member = Member.fromProfileEntity(memberProfile);
                Set<Client> clients = clientManagerReadOnly.getClients(orcid);
                List<org.orcid.pojo.ajaxForm.Client> clientsList = new ArrayList<org.orcid.pojo.ajaxForm.Client>();
                clients.forEach(c -> {
                    clientsList.add(org.orcid.pojo.ajaxForm.Client.fromModelObject(c));
                });
                member.setClients(clientsList);
            } else {
                member.getErrors().add(getMessage("manage_members.orcid_is_not_a_member"));
            }
        } else {
            member.getErrors().add(getMessage("manage_members.orcid_doesnt_exists"));
        }
    }
    return member;
}
Also used : ArrayList(java.util.ArrayList) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) MemberType(org.orcid.jaxb.model.clientgroup.MemberType) Client(org.orcid.jaxb.model.client_v2.Client) Member(org.orcid.pojo.ajaxForm.Member) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with MemberType

use of org.orcid.jaxb.model.clientgroup.MemberType in project ORCID-Source by ORCID.

the class MembersManagerImpl method updateMemeber.

@Override
public Member updateMemeber(Member member) throws IllegalArgumentException {
    String memberId = member.getGroupOrcid().getValue();
    String name = member.getGroupName().getValue();
    String email = member.getEmail().getValue();
    String salesForceId = member.getSalesforceId() == null ? null : member.getSalesforceId().getValue();
    MemberType memberType = MemberType.fromValue(member.getType().getValue());
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        protected void doInTransactionWithoutResult(TransactionStatus status) {
            boolean memberChangedType = false;
            ProfileEntity memberEntity = profileDao.find(member.getGroupOrcid().getValue());
            memberEntity.setLastModified(new Date());
            memberEntity.setIndexingStatus(IndexingStatus.PENDING);
            memberEntity.getRecordNameEntity().setCreditName(name);
            memberEntity.setSalesforeId(salesForceId);
            if (!memberType.equals(memberEntity.getGroupType())) {
                memberEntity.setGroupType(memberType);
                memberChangedType = true;
            }
            EmailEntity primaryEmail = memberEntity.getPrimaryEmail();
            if (!email.equals(primaryEmail.getId())) {
                if (emailManager.emailExists(email)) {
                    throw new IllegalArgumentException("Email already exists");
                }
                Date now = new Date();
                EmailEntity newPrimaryEmail = new EmailEntity();
                newPrimaryEmail.setLastModified(now);
                newPrimaryEmail.setDateCreated(now);
                newPrimaryEmail.setCurrent(true);
                newPrimaryEmail.setId(email);
                newPrimaryEmail.setPrimary(true);
                newPrimaryEmail.setVerified(true);
                newPrimaryEmail.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE);
                memberEntity.setPrimaryEmail(newPrimaryEmail);
            }
            profileDao.merge(memberEntity);
            if (memberChangedType) {
                updateClientTypeDueMemberTypeUpdate(memberId, memberType);
            }
        }
    });
    clearCache();
    return member;
}
Also used : MemberType(org.orcid.jaxb.model.clientgroup.MemberType) TransactionStatus(org.springframework.transaction.TransactionStatus) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date)

Example 8 with MemberType

use of org.orcid.jaxb.model.clientgroup.MemberType in project ORCID-Source by ORCID.

the class ClientsController method manageClients.

@RequestMapping
public ModelAndView manageClients() {
    ModelAndView mav = new ModelAndView("member_developer_tools");
    String memberId = getCurrentUserOrcid();
    ProfileEntity entity = profileEntityCacheManager.retrieve(memberId);
    MemberType memberType = entity.getGroupType();
    mav.addObject("member_id", memberId);
    mav.addObject("member_type", memberType);
    Set<org.orcid.jaxb.model.v3.dev1.client.Client> clients = clientManagerReadOnly.getClients(memberId);
    if (clients.isEmpty()) {
        mav.addObject("allow_more_clients", true);
    } else if (MemberType.PREMIUM.equals(memberType) || MemberType.PREMIUM_INSTITUTION.equals(memberType)) {
        mav.addObject("is_premium", true);
        mav.addObject("allow_more_clients", true);
    } else {
        mav.addObject("allow_more_clients", false);
    }
    return mav;
}
Also used : MemberType(org.orcid.jaxb.model.clientgroup.MemberType) ModelAndView(org.springframework.web.servlet.ModelAndView) Client(org.orcid.pojo.ajaxForm.Client) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

MemberType (org.orcid.jaxb.model.clientgroup.MemberType)8 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)5 ArrayList (java.util.ArrayList)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 Date (java.util.Date)2 EmailEntity (org.orcid.persistence.jpa.entities.EmailEntity)2 Member (org.orcid.pojo.ajaxForm.Member)2 TransactionStatus (org.springframework.transaction.TransactionStatus)2 Transactional (org.springframework.transaction.annotation.Transactional)2 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 TreeMap (java.util.TreeMap)1 Client (org.orcid.jaxb.model.client_v2.Client)1 Client (org.orcid.jaxb.model.v3.dev1.client.Client)1 CustomEmailEntity (org.orcid.persistence.jpa.entities.CustomEmailEntity)1 Client (org.orcid.pojo.ajaxForm.Client)1 CustomEmailForm (org.orcid.pojo.ajaxForm.CustomEmailForm)1 ModelAttribute (org.springframework.web.bind.annotation.ModelAttribute)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1