use of org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity in project ORCID-Source by ORCID.
the class Jaxb2JpaAdapterImpl method setOrgAffiliationRelations.
private void setOrgAffiliationRelations(ProfileEntity profileEntity, Affiliations affiliations) {
SortedSet<OrgAffiliationRelationEntity> existingOrgAffiliationEntities = profileEntity.getOrgAffiliationRelations();
if (existingOrgAffiliationEntities == null) {
existingOrgAffiliationEntities = new TreeSet<>();
}
Map<String, OrgAffiliationRelationEntity> existingOrgAffiliationsEntitiesMap = createOrgAffiliationEntitiesMap(existingOrgAffiliationEntities);
SortedSet<OrgAffiliationRelationEntity> updatedOrgAffiliationEntities = new TreeSet<>();
if (affiliations != null && !affiliations.getAffiliation().isEmpty()) {
for (Affiliation affiliation : affiliations.getAffiliation()) {
OrgAffiliationRelationEntity orgRelationEntity = getOrgAffiliationRelationEntity(affiliation, existingOrgAffiliationsEntitiesMap.get(affiliation.getPutCode()));
orgRelationEntity.setProfile(profileEntity);
updatedOrgAffiliationEntities.add(orgRelationEntity);
}
}
Map<String, OrgAffiliationRelationEntity> updatedOrgAffiliationEntitiesMap = createOrgAffiliationEntitiesMap(updatedOrgAffiliationEntities);
// Remove orphans
for (Iterator<OrgAffiliationRelationEntity> iterator = existingOrgAffiliationEntities.iterator(); iterator.hasNext(); ) {
OrgAffiliationRelationEntity existingEntity = iterator.next();
if (!updatedOrgAffiliationEntitiesMap.containsKey(String.valueOf(existingEntity.getId()))) {
iterator.remove();
}
}
// Add new
for (OrgAffiliationRelationEntity updatedEntity : updatedOrgAffiliationEntities) {
if (updatedEntity.getId() == null) {
existingOrgAffiliationEntities.add(updatedEntity);
}
}
profileEntity.setOrgAffiliationRelations(existingOrgAffiliationEntities);
}
use of org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity in project ORCID-Source by ORCID.
the class OrcidProfileManagerImpl method persistAddedAffiliations.
private void persistAddedAffiliations(String orcid, List<Affiliation> updatedAffiliationsList) {
ProfileEntity profileEntity = profileDao.find(orcid);
for (Affiliation updatedAffiliation : updatedAffiliationsList) {
OrgAffiliationRelationEntity orgAffiliationRelationEntity = jaxb2JpaAdapter.getNewOrgAffiliationRelationEntity(updatedAffiliation, profileEntity);
orgAffiliationRelationDao.persist(orgAffiliationRelationEntity);
}
orcidProfileCacheManager.remove(orcid);
}
use of org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity in project ORCID-Source by ORCID.
the class ProfileEntityManagerImpl method deprecateProfile.
/**
* Deprecates a profile
*
* @param deprecatedProfile
* The profile that want to be deprecated
* @param primaryProfile
* The primary profile for the deprecated profile
* @return true if the account was successfully deprecated, false otherwise
*/
@Override
@Transactional
public boolean deprecateProfile(String deprecatedOrcid, String primaryOrcid) {
boolean wasDeprecated = profileDao.deprecateProfile(deprecatedOrcid, primaryOrcid);
// If it was successfully deprecated
if (wasDeprecated) {
LOGGER.info("Account {} was deprecated to primary account: {}", deprecatedOrcid, primaryOrcid);
ProfileEntity deprecated = profileDao.find(deprecatedOrcid);
// Remove works
workManager.removeAllWorks(deprecatedOrcid);
// Remove funding
if (deprecated.getProfileFunding() != null) {
for (ProfileFundingEntity funding : deprecated.getProfileFunding()) {
fundingManager.removeProfileFunding(funding.getProfile().getId(), funding.getId());
}
}
// Remove affiliations
if (deprecated.getOrgAffiliationRelations() != null) {
for (OrgAffiliationRelationEntity affiliation : deprecated.getOrgAffiliationRelations()) {
orgAffiliationRelationDao.removeOrgAffiliationRelation(affiliation.getProfile().getId(), affiliation.getId());
}
}
// Remove external identifiers
if (deprecated.getExternalIdentifiers() != null) {
for (ExternalIdentifierEntity externalIdentifier : deprecated.getExternalIdentifiers()) {
externalIdentifierManager.deleteExternalIdentifier(deprecated.getId(), externalIdentifier.getId(), false);
}
}
// Remove researcher urls
if (deprecated.getResearcherUrls() != null) {
for (ResearcherUrlEntity rUrl : deprecated.getResearcherUrls()) {
researcherUrlManager.deleteResearcherUrl(deprecatedOrcid, rUrl.getId(), false);
}
}
// Remove other names
if (deprecated.getOtherNames() != null) {
for (OtherNameEntity otherName : deprecated.getOtherNames()) {
otherNamesManager.deleteOtherName(deprecatedOrcid, otherName.getId(), false);
}
}
// Remove keywords
if (deprecated.getKeywords() != null) {
for (ProfileKeywordEntity keyword : deprecated.getKeywords()) {
profileKeywordManager.deleteKeyword(deprecatedOrcid, keyword.getId(), false);
}
}
//Remove biography
if (biographyManager.exists(deprecatedOrcid)) {
Biography deprecatedBio = new Biography();
deprecatedBio.setContent(null);
deprecatedBio.setVisibility(Visibility.PRIVATE);
biographyManager.updateBiography(deprecatedOrcid, deprecatedBio);
}
//Set the deactivated names
if (recordNameManager.exists(deprecatedOrcid)) {
Name name = new Name();
name.setCreditName(new CreditName());
name.setGivenNames(new GivenNames("Given Names Deactivated"));
name.setFamilyName(new FamilyName("Family Name Deactivated"));
name.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE);
name.setPath(deprecatedOrcid);
recordNameManager.updateRecordName(deprecatedOrcid, name);
}
userConnectionDao.deleteByOrcid(deprecatedOrcid);
// Move all emails to the primary email
Set<EmailEntity> deprecatedAccountEmails = deprecated.getEmails();
if (deprecatedAccountEmails != null) {
// For each email in the deprecated profile
for (EmailEntity email : deprecatedAccountEmails) {
// Delete each email from the deprecated
// profile
LOGGER.info("About to move email {} from profile {} to profile {}", new Object[] { email.getId(), deprecatedOrcid, primaryOrcid });
emailManager.moveEmailToOtherAccount(email.getId(), deprecatedOrcid, primaryOrcid);
}
}
return true;
}
return false;
}
use of org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity in project ORCID-Source by ORCID.
the class JpaJaxbEducationAdapterTest method fromOrgAffiliationRelationEntityToEducationSummary.
@Test
public void fromOrgAffiliationRelationEntityToEducationSummary() {
OrgAffiliationRelationEntity entity = getEducationEntity();
assertNotNull(entity);
EducationSummary educationSummary = jpaJaxbEducationAdapter.toEducationSummary(entity);
assertNotNull(educationSummary);
assertEquals("education:department", educationSummary.getDepartmentName());
assertEquals(Long.valueOf(123456), educationSummary.getPutCode());
assertEquals("education:title", educationSummary.getRoleTitle());
assertEquals("private", educationSummary.getVisibility().value());
assertNotNull(educationSummary.getStartDate());
assertEquals("2000", educationSummary.getStartDate().getYear().getValue());
assertEquals("01", educationSummary.getStartDate().getMonth().getValue());
assertEquals("01", educationSummary.getStartDate().getDay().getValue());
assertEquals("2020", educationSummary.getEndDate().getYear().getValue());
assertEquals("02", educationSummary.getEndDate().getMonth().getValue());
assertEquals("02", educationSummary.getEndDate().getDay().getValue());
assertNotNull(educationSummary.getSource());
assertNotNull(educationSummary.getSource().retrieveSourcePath());
assertEquals("APP-000000001", educationSummary.getSource().retrieveSourcePath());
}
use of org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity in project ORCID-Source by ORCID.
the class JpaJaxbEducationAdapterTest method getEducationEntity.
private OrgAffiliationRelationEntity getEducationEntity() {
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.EDUCATION);
result.setDepartment("education: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("education:title");
result.setVisibility(Visibility.PRIVATE);
result.setClientSourceId("APP-000000001");
return result;
}
Aggregations