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;
}
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;
}
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;
}
Aggregations