use of org.orcid.jaxb.model.common_rc1.Visibility in project ORCID-Source by ORCID.
the class ProfileEntityManagerImpl method claimProfileAndUpdatePreferences.
@Override
@Transactional
public boolean claimProfileAndUpdatePreferences(String orcid, String email, Locale locale, Claim claim) {
// Verify the email
boolean emailVerified = emailManager.verifySetCurrentAndPrimary(orcid, email);
if (!emailVerified) {
throw new InvalidParameterException("Unable to claim and verify email: " + email + " for user: " + orcid);
}
// Update the profile entity fields
ProfileEntity profile = profileDao.find(orcid);
profile.setLastModified(new Date());
profile.setIndexingStatus(IndexingStatus.REINDEX);
profile.setClaimed(true);
profile.setCompletedDate(new Date());
if (locale != null) {
profile.setLocale(org.orcid.jaxb.model.common_v2.Locale.fromValue(locale.value()));
}
if (claim != null) {
profile.setSendChangeNotifications(claim.getSendChangeNotifications().getValue());
profile.setSendOrcidNews(claim.getSendOrcidNews().getValue());
profile.setActivitiesVisibilityDefault(Visibility.valueOf(claim.getActivitiesVisibilityDefault().getVisibility().name()));
}
// Update the visibility for every bio element to the visibility
// selected by the user
// Update the bio
org.orcid.jaxb.model.common_v2.Visibility defaultVisibility = org.orcid.jaxb.model.common_v2.Visibility.fromValue(claim.getActivitiesVisibilityDefault().getVisibility().value());
if (profile.getBiographyEntity() != null) {
profile.getBiographyEntity().setVisibility(defaultVisibility);
}
// Update address
if (profile.getAddresses() != null) {
for (AddressEntity a : profile.getAddresses()) {
a.setVisibility(defaultVisibility);
}
}
// Update the keywords
if (profile.getKeywords() != null) {
for (ProfileKeywordEntity k : profile.getKeywords()) {
k.setVisibility(defaultVisibility);
}
}
// Update the other names
if (profile.getOtherNames() != null) {
for (OtherNameEntity o : profile.getOtherNames()) {
o.setVisibility(defaultVisibility);
}
}
// Update the researcher urls
if (profile.getResearcherUrls() != null) {
for (ResearcherUrlEntity r : profile.getResearcherUrls()) {
r.setVisibility(defaultVisibility);
}
}
// Update the external identifiers
if (profile.getExternalIdentifiers() != null) {
for (ExternalIdentifierEntity e : profile.getExternalIdentifiers()) {
e.setVisibility(defaultVisibility);
}
}
profileDao.merge(profile);
profileDao.flush();
return true;
}
use of org.orcid.jaxb.model.common_rc1.Visibility in project ORCID-Source by ORCID.
the class ProfileEntityManagerImpl method getMemberDisplayName.
private String getMemberDisplayName(ProfileEntity member) {
RecordNameEntity recordName = member.getRecordNameEntity();
if (recordName == null) {
return StringUtils.EMPTY;
}
// If it is a member, return the credit name
if (OrcidType.GROUP.equals(member.getOrcidType())) {
return recordName.getCreditName();
}
Visibility namesVisibilty = recordName.getVisibility();
if (Visibility.PUBLIC.equals(namesVisibilty)) {
if (!PojoUtil.isEmpty(recordName.getCreditName())) {
return recordName.getCreditName();
} else {
String displayName = recordName.getGivenNames();
String familyName = recordName.getFamilyName();
if (StringUtils.isNotBlank(familyName)) {
displayName += " " + familyName;
}
return displayName;
}
}
return StringUtils.EMPTY;
}
use of org.orcid.jaxb.model.common_rc1.Visibility in project ORCID-Source by ORCID.
the class ProfileFundingManagerImpl method updateFunding.
/**
* Updates a funding that belongs to the given user
* @param orcid
* The user
* @param funding
* The funding to update
* @return the updated funding
*/
@Override
public Funding updateFunding(String orcid, Funding funding, boolean isApiRequest) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
ProfileFundingEntity pfe = profileFundingDao.getProfileFunding(orcid, funding.getPutCode());
Visibility originalVisibility = pfe.getVisibility();
// Save the original source
String existingSourceId = pfe.getSourceId();
String existingClientSourceId = pfe.getClientSourceId();
activityValidator.validateFunding(funding, sourceEntity, false, isApiRequest, originalVisibility);
if (!isApiRequest) {
List<ProfileFundingEntity> existingFundings = profileFundingDao.getByUser(orcid, getLastModified(orcid));
for (ProfileFundingEntity existingFunding : existingFundings) {
Funding existing = jpaJaxbFundingAdapter.toFunding(existingFunding);
if (!existing.getPutCode().equals(funding.getPutCode())) {
activityValidator.checkFundingExternalIdentifiersForDuplicates(funding.getExternalIdentifiers(), existing.getExternalIdentifiers(), existing.getSource(), sourceEntity);
}
}
}
orcidSecurityManager.checkSource(pfe);
jpaJaxbFundingAdapter.toProfileFundingEntity(funding, pfe);
pfe.setVisibility(originalVisibility);
// Be sure it doesn't overwrite the source
pfe.setSourceId(existingSourceId);
pfe.setClientSourceId(existingClientSourceId);
// Updates the give organization with the latest organization from database, or, create a new one
OrgEntity updatedOrganization = orgManager.getOrgEntity(funding);
pfe.setOrg(updatedOrganization);
pfe = profileFundingDao.merge(pfe);
profileFundingDao.flush();
if (!isApiRequest) {
notificationManager.sendAmendEmail(orcid, AmendedSection.FUNDING, createItemList(pfe));
}
return jpaJaxbFundingAdapter.toFunding(pfe);
}
use of org.orcid.jaxb.model.common_rc1.Visibility in project ORCID-Source by ORCID.
the class WorkManagerImpl method updateWork.
@Override
@Transactional
public Work updateWork(String orcid, Work work, boolean isApiRequest) {
WorkEntity workEntity = workDao.getWork(orcid, work.getPutCode());
Visibility originalVisibility = workEntity.getVisibility();
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
// Save the original source
String existingSourceId = workEntity.getSourceId();
String existingClientSourceId = workEntity.getClientSourceId();
if (isApiRequest) {
activityValidator.validateWork(work, sourceEntity, false, isApiRequest, workEntity.getVisibility());
List<Work> existingWorks = this.findWorks(orcid);
for (Work existing : existingWorks) {
// Dont compare the updated peer review with the DB version
if (!existing.getPutCode().equals(work.getPutCode())) {
activityValidator.checkExternalIdentifiersForDuplicates(work.getExternalIdentifiers(), existing.getExternalIdentifiers(), existing.getSource(), sourceEntity);
}
}
} else {
// validate external ID vocab
externalIDValidator.validateWorkOrPeerReview(work.getExternalIdentifiers());
}
orcidSecurityManager.checkSource(workEntity);
jpaJaxbWorkAdapter.toWorkEntity(work, workEntity);
workEntity.setVisibility(originalVisibility);
// Be sure it doesn't overwrite the source
workEntity.setSourceId(existingSourceId);
workEntity.setClientSourceId(existingClientSourceId);
workDao.merge(workEntity);
workDao.flush();
notificationManager.sendAmendEmail(orcid, AmendedSection.WORK, createItemList(workEntity));
return jpaJaxbWorkAdapter.toWork(workEntity);
}
use of org.orcid.jaxb.model.common_rc1.Visibility in project ORCID-Source by ORCID.
the class AddressManagerImpl method updateAddress.
@Override
@Transactional
public Address updateAddress(String orcid, Long putCode, Address address, boolean isApiRequest) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
AddressEntity updatedEntity = addressDao.getAddress(orcid, putCode);
Visibility originalVisibility = Visibility.fromValue(updatedEntity.getVisibility().value());
// Save the original source
String existingSourceId = updatedEntity.getSourceId();
String existingClientSourceId = updatedEntity.getClientSourceId();
// If it is an update from the API, check the source and preserve the original visibility
if (isApiRequest) {
orcidSecurityManager.checkSource(updatedEntity);
}
// Validate the address
PersonValidator.validateAddress(address, sourceEntity, false, isApiRequest, originalVisibility);
// Validate it is not duplicated
List<AddressEntity> existingAddresses = addressDao.getAddresses(orcid, getLastModified(orcid));
for (AddressEntity existing : existingAddresses) {
// If it is not the same element
if (!existing.getId().equals(address.getPutCode())) {
if (isDuplicated(existing, address, sourceEntity)) {
Map<String, String> params = new HashMap<String, String>();
params.put("type", "address");
params.put("value", address.getCountry().getValue().value());
throw new OrcidDuplicatedElementException(params);
}
}
}
adapter.toAddressEntity(address, updatedEntity);
updatedEntity.setLastModified(new Date());
// Be sure it doesn't overwrite the source
updatedEntity.setSourceId(existingSourceId);
updatedEntity.setClientSourceId(existingClientSourceId);
addressDao.merge(updatedEntity);
return adapter.toAddress(updatedEntity);
}
Aggregations