use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.
the class ExternalIdentifierManagerImpl method createExternalIdentifier.
@Override
public PersonExternalIdentifier createExternalIdentifier(String orcid, PersonExternalIdentifier externalIdentifier, boolean isApiRequest) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
// Validate external identifier
PersonValidator.validateExternalIdentifier(externalIdentifier, sourceEntity, true, isApiRequest, null, requireRelationshipOnExternalIdentifier);
// Validate it is not duplicated
List<ExternalIdentifierEntity> existingExternalIdentifiers = externalIdentifierDao.getExternalIdentifiers(orcid, getLastModified(orcid));
for (ExternalIdentifierEntity existing : existingExternalIdentifiers) {
if (isDuplicated(existing, externalIdentifier, sourceEntity)) {
Map<String, String> params = new HashMap<String, String>();
params.put("type", "external-identifier");
params.put("value", externalIdentifier.getUrl().getValue());
throw new OrcidDuplicatedElementException(params);
}
}
ExternalIdentifierEntity newEntity = jpaJaxbExternalIdentifierAdapter.toExternalIdentifierEntity(externalIdentifier);
ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
newEntity.setOwner(profile);
newEntity.setDateCreated(new Date());
if (sourceEntity.getSourceProfile() != null) {
newEntity.setSourceId(sourceEntity.getSourceProfile().getId());
}
if (sourceEntity.getSourceClient() != null) {
newEntity.setClientSourceId(sourceEntity.getSourceClient().getId());
}
setIncomingPrivacy(newEntity, profile);
DisplayIndexCalculatorHelper.setDisplayIndexOnNewEntity(newEntity, isApiRequest);
externalIdentifierDao.persist(newEntity);
return jpaJaxbExternalIdentifierAdapter.toExternalIdentifier(newEntity);
}
use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.
the class AffiliationsManagerImpl method createEmploymentAffiliation.
/**
* Add a new employment to the given user
*
* @param orcid
* The user to add the employment
* @param employment
* The employment to add
* @return the added employment
* */
@Override
public Employment createEmploymentAffiliation(String orcid, Employment employment, boolean isApiRequest) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
activityValidator.validateEmployment(employment, sourceEntity, true, isApiRequest, null);
OrgAffiliationRelationEntity employmentEntity = jpaJaxbEmploymentAdapter.toOrgAffiliationRelationEntity(employment);
// Updates the give organization with the latest organization from
// database
OrgEntity updatedOrganization = orgManager.getOrgEntity(employment);
employmentEntity.setOrg(updatedOrganization);
// Set source id
if (sourceEntity.getSourceProfile() != null) {
employmentEntity.setSourceId(sourceEntity.getSourceProfile().getId());
}
if (sourceEntity.getSourceClient() != null) {
employmentEntity.setClientSourceId(sourceEntity.getSourceClient().getId());
}
ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
employmentEntity.setProfile(profile);
setIncomingWorkPrivacy(employmentEntity, profile);
employmentEntity.setAffiliationType(AffiliationType.EMPLOYMENT);
orgAffiliationRelationDao.persist(employmentEntity);
orgAffiliationRelationDao.flush();
notificationManager.sendAmendEmail(orcid, AmendedSection.EMPLOYMENT, createItem(employmentEntity));
return jpaJaxbEmploymentAdapter.toEmployment(employmentEntity);
}
use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.
the class AffiliationsManagerImpl method createEducationAffiliation.
/**
* Add a new education to the given user
*
* @param orcid
* The user to add the education
* @param education
* The education to add
* @return the added education
* */
@Override
public Education createEducationAffiliation(String orcid, Education education, boolean isApiRequest) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
activityValidator.validateEducation(education, sourceEntity, true, isApiRequest, null);
OrgAffiliationRelationEntity educationEntity = jpaJaxbEducationAdapter.toOrgAffiliationRelationEntity(education);
// Updates the give organization with the latest organization from
// database
OrgEntity updatedOrganization = orgManager.getOrgEntity(education);
educationEntity.setOrg(updatedOrganization);
// Set source id
if (sourceEntity.getSourceProfile() != null) {
educationEntity.setSourceId(sourceEntity.getSourceProfile().getId());
}
if (sourceEntity.getSourceClient() != null) {
educationEntity.setClientSourceId(sourceEntity.getSourceClient().getId());
}
ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
educationEntity.setProfile(profile);
setIncomingWorkPrivacy(educationEntity, profile);
educationEntity.setAffiliationType(AffiliationType.EDUCATION);
orgAffiliationRelationDao.persist(educationEntity);
orgAffiliationRelationDao.flush();
notificationManager.sendAmendEmail(orcid, AmendedSection.EDUCATION, createItem(educationEntity));
return jpaJaxbEducationAdapter.toEducation(educationEntity);
}
use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.
the class EmailManagerImpl method addEmail.
@Override
@Transactional
public void addEmail(HttpServletRequest request, String orcid, Email email) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
String sourceId = sourceEntity.getSourceProfile() == null ? null : sourceEntity.getSourceProfile().getId();
String clientSourceId = sourceEntity.getSourceClient() == null ? null : sourceEntity.getSourceClient().getId();
Email currentPrimaryEmail = findPrimaryEmail(orcid);
// Create the new email
emailDao.addEmail(orcid, email.getEmail(), email.getVisibility(), sourceId, clientSourceId);
// if primary email changed send notification.
if (email.isPrimary() && !StringUtils.equals(currentPrimaryEmail.getEmail(), email.getEmail())) {
request.getSession().setAttribute(EmailConstants.CHECK_EMAIL_VALIDATED, false);
notificationManager.sendEmailAddressChangedNotification(orcid, email.getEmail(), currentPrimaryEmail.getEmail());
}
// send verifcation email for new address
notificationManager.sendVerificationEmail(orcid, email.getEmail());
}
use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.
the class GroupIdRecordManagerImpl method createGroupIdRecord.
@Override
public GroupIdRecord createGroupIdRecord(GroupIdRecord groupIdRecord) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
activityValidator.validateGroupIdRecord(groupIdRecord, true, sourceEntity);
validateDuplicate(groupIdRecord);
GroupIdRecordEntity entity = jpaJaxbGroupIdRecordAdapter.toGroupIdRecordEntity(groupIdRecord);
if (sourceEntity != null) {
if (sourceEntity.getSourceClient() != null) {
entity.setClientSourceId(sourceEntity.getSourceClient().getClientId());
} else if (sourceEntity.getSourceProfile() != null) {
entity.setSourceId(sourceEntity.getSourceProfile().getId());
}
}
groupIdRecordDao.persist(entity);
return jpaJaxbGroupIdRecordAdapter.toGroupIdRecord(entity);
}
Aggregations