use of org.orcid.persistence.jpa.entities.OrgEntity 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.persistence.jpa.entities.OrgEntity in project ORCID-Source by ORCID.
the class ProfileFundingManagerImpl method createFunding.
/**
* Add a new funding to the given user
* @param orcid
* The user to add the funding
* @param funding
* The funding to add
* @return the added funding
*/
@Override
@Transactional
public Funding createFunding(String orcid, Funding funding, boolean isApiRequest) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
activityValidator.validateFunding(funding, sourceEntity, true, isApiRequest, null);
// Check for duplicates
List<ProfileFundingEntity> existingFundings = profileFundingDao.getByUser(orcid, getLastModified(orcid));
List<Funding> fundings = jpaJaxbFundingAdapter.toFunding(existingFundings);
if (fundings != null && isApiRequest) {
for (Funding exstingFunding : fundings) {
activityValidator.checkFundingExternalIdentifiersForDuplicates(funding.getExternalIdentifiers(), exstingFunding.getExternalIdentifiers(), exstingFunding.getSource(), sourceEntity);
}
}
ProfileFundingEntity profileFundingEntity = jpaJaxbFundingAdapter.toProfileFundingEntity(funding);
// Updates the give organization with the latest organization from database
OrgEntity updatedOrganization = orgManager.getOrgEntity(funding);
profileFundingEntity.setOrg(updatedOrganization);
// Set the source
if (sourceEntity.getSourceProfile() != null) {
profileFundingEntity.setSourceId(sourceEntity.getSourceProfile().getId());
}
if (sourceEntity.getSourceClient() != null) {
profileFundingEntity.setClientSourceId(sourceEntity.getSourceClient().getId());
}
ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
profileFundingEntity.setProfile(profile);
setIncomingWorkPrivacy(profileFundingEntity, profile);
DisplayIndexCalculatorHelper.setDisplayIndexOnNewEntity(profileFundingEntity, isApiRequest);
profileFundingDao.persist(profileFundingEntity);
profileFundingDao.flush();
if (isApiRequest) {
notificationManager.sendAmendEmail(orcid, AmendedSection.FUNDING, createItemList(profileFundingEntity));
}
return jpaJaxbFundingAdapter.toFunding(profileFundingEntity);
}
use of org.orcid.persistence.jpa.entities.OrgEntity in project ORCID-Source by ORCID.
the class AffiliationsManagerImpl method updateEmploymentAffiliation.
/**
* Updates a employment that belongs to the given user
*
* @param orcid
* The user
* @param employment
* The employment to update
* @return the updated employment
*/
@Override
public Employment updateEmploymentAffiliation(String orcid, Employment employment, boolean isApiRequest) {
OrgAffiliationRelationEntity employmentEntity = orgAffiliationRelationDao.getOrgAffiliationRelation(orcid, employment.getPutCode());
Visibility originalVisibility = employmentEntity.getVisibility();
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
// Save the original source
String existingSourceId = employmentEntity.getSourceId();
String existingClientSourceId = employmentEntity.getClientSourceId();
orcidSecurityManager.checkSource(employmentEntity);
activityValidator.validateEmployment(employment, sourceEntity, false, isApiRequest, originalVisibility);
jpaJaxbEmploymentAdapter.toOrgAffiliationRelationEntity(employment, employmentEntity);
employmentEntity.setVisibility(originalVisibility);
// Be sure it doesn't overwrite the source
employmentEntity.setSourceId(existingSourceId);
employmentEntity.setClientSourceId(existingClientSourceId);
// Updates the give organization with the latest organization from
// database, or, create a new one
OrgEntity updatedOrganization = orgManager.getOrgEntity(employment);
employmentEntity.setOrg(updatedOrganization);
employmentEntity.setAffiliationType(AffiliationType.EMPLOYMENT);
employmentEntity = orgAffiliationRelationDao.merge(employmentEntity);
orgAffiliationRelationDao.flush();
notificationManager.sendAmendEmail(orcid, AmendedSection.EMPLOYMENT, createItemList(employmentEntity));
return jpaJaxbEmploymentAdapter.toEmployment(employmentEntity);
}
use of org.orcid.persistence.jpa.entities.OrgEntity in project ORCID-Source by ORCID.
the class AffiliationsManagerImpl method updateEducationAffiliation.
/**
* Updates a education that belongs to the given user
*
* @param orcid
* The user
* @param education
* The education to update
* @return the updated education
*/
@Override
public Education updateEducationAffiliation(String orcid, Education education, boolean isApiRequest) {
OrgAffiliationRelationEntity educationEntity = orgAffiliationRelationDao.getOrgAffiliationRelation(orcid, education.getPutCode());
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
// Save the original source
String existingSourceId = educationEntity.getSourceId();
String existingClientSourceId = educationEntity.getClientSourceId();
Visibility originalVisibility = educationEntity.getVisibility();
orcidSecurityManager.checkSource(educationEntity);
activityValidator.validateEducation(education, sourceEntity, false, isApiRequest, originalVisibility);
jpaJaxbEducationAdapter.toOrgAffiliationRelationEntity(education, educationEntity);
educationEntity.setVisibility(originalVisibility);
// Be sure it doesn't overwrite the source
educationEntity.setSourceId(existingSourceId);
educationEntity.setClientSourceId(existingClientSourceId);
// Updates the give organization with the latest organization from
// database, or, create a new one
OrgEntity updatedOrganization = orgManager.getOrgEntity(education);
educationEntity.setOrg(updatedOrganization);
educationEntity.setAffiliationType(AffiliationType.EDUCATION);
educationEntity = orgAffiliationRelationDao.merge(educationEntity);
orgAffiliationRelationDao.flush();
notificationManager.sendAmendEmail(orcid, AmendedSection.EDUCATION, createItemList(educationEntity));
return jpaJaxbEducationAdapter.toEducation(educationEntity);
}
use of org.orcid.persistence.jpa.entities.OrgEntity in project ORCID-Source by ORCID.
the class JpaJaxbServiceAdapterTest method getEntity.
private OrgAffiliationRelationEntity getEntity() {
OrgEntity orgEntity = new OrgEntity();
orgEntity.setCity("org:city");
orgEntity.setCountry(org.orcid.jaxb.model.message.Iso3166Country.US);
orgEntity.setName("org:name");
orgEntity.setRegion("org:region");
orgEntity.setUrl("org:url");
orgEntity.setSource(new SourceEntity("APP-000000001"));
OrgAffiliationRelationEntity result = new OrgAffiliationRelationEntity();
result.setAffiliationType(AffiliationType.SERVICE);
result.setDepartment("service:department");
result.setEndDate(new EndDateEntity(2020, 2, 2));
result.setId(123456L);
result.setOrg(orgEntity);
result.setProfile(new ProfileEntity("0000-0001-0002-0003"));
result.setStartDate(new StartDateEntity(2000, 1, 1));
result.setTitle("service:title");
result.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE);
result.setClientSourceId("APP-000000001");
return result;
}
Aggregations