Search in sources :

Example 31 with OrgEntity

use of org.orcid.persistence.jpa.entities.OrgEntity in project ORCID-Source by ORCID.

the class OrcidProfileManagerImpl method checkAndUpdateDisambiguatedOrganization.

private void checkAndUpdateDisambiguatedOrganization(List<Affiliation> affiliations) {
    if (affiliations != null && !affiliations.isEmpty()) {
        for (Affiliation affiliation : affiliations) {
            Organization org = affiliation.getOrganization();
            OrgEntity orgEntity = orgManager.getOrgEntity(org);
            // If the org exists
            if (orgEntity != null) {
                // And it have a disambiguated org
                if (orgEntity.getOrgDisambiguated() != null) {
                    // Update the desambiguated org
                    org.setDisambiguatedOrganization(adapter.getDisambiguatedOrganization(orgEntity.getOrgDisambiguated()));
                } else {
                    // Null the disambiguated organization
                    org.setDisambiguatedOrganization(null);
                }
            }
        }
    }
}
Also used : Organization(org.orcid.jaxb.model.message.Organization) Affiliation(org.orcid.jaxb.model.message.Affiliation) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity)

Example 32 with OrgEntity

use of org.orcid.persistence.jpa.entities.OrgEntity in project ORCID-Source by ORCID.

the class JpaJaxbPeerReviewAdapterTest method getPeerReviewEntity.

private PeerReviewEntity getPeerReviewEntity() {
    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"));
    PeerReviewEntity result = new PeerReviewEntity();
    result.setOrg(orgEntity);
    result.setCompletionDate(new CompletionDateEntity(2015, 1, 1));
    result.setExternalIdentifiersJson("{\"workExternalIdentifier\":[{\"relationship\":\"SELF\",\"url\":{\"value\":\"http://orcid.org\"},\"workExternalIdentifierType\":\"SOURCE_WORK_ID\",\"workExternalIdentifierId\":{\"content\":\"peer-review:external-identifier-id\"}}]}");
    result.setProfile(new ProfileEntity("0000-0001-0002-0003"));
    result.setRole(Role.MEMBER);
    result.setType(PeerReviewType.EVALUATION);
    result.setUrl("peer-review:url");
    result.setSubjectExternalIdentifiersJson("{\"relationship\":\"SELF\",\"url\":{\"value\":\"http://orcid.org\"},\"workExternalIdentifierType\":\"SOURCE_WORK_ID\",\"workExternalIdentifierId\":{\"content\":\"peer-review:subject-external-identifier-id\"}}");
    result.setSubjectContainerName("peer-review:subject-container-name");
    result.setSubjectName("peer-review:subject-name");
    result.setSubjectTranslatedName("peer-review:subject-translated-name");
    result.setSubjectTranslatedNameLanguageCode("en");
    result.setSubjectUrl("peer-review:subject-url");
    result.setSubjectType(WorkType.BOOK_REVIEW);
    result.setVisibility(Visibility.PRIVATE);
    result.setClientSourceId("APP-000000001");
    result.setGroupId("orcid-generated:12345");
    result.setId(12345L);
    return result;
}
Also used : CompletionDateEntity(org.orcid.persistence.jpa.entities.CompletionDateEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) PeerReviewEntity(org.orcid.persistence.jpa.entities.PeerReviewEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity)

Example 33 with OrgEntity

use of org.orcid.persistence.jpa.entities.OrgEntity in project ORCID-Source by ORCID.

the class OrcidProfileManagerImplTest method testOrgReuse.

@Test
@Transactional
@Rollback(true)
public void testOrgReuse() {
    OrcidProfile profile1 = createBasicProfile();
    OrcidHistory history = new OrcidHistory();
    history.setSubmissionDate(new SubmissionDate(DateUtils.convertToXMLGregorianCalendar(new Date())));
    profile1.setOrcidHistory(history);
    history.setClaimed(new Claimed(true));
    OrcidActivities orcidActivities = profile1.getOrcidActivities();
    Affiliations affiliations = new Affiliations();
    orcidActivities.setAffiliations(affiliations);
    Affiliation affiliation = new Affiliation();
    affiliations.getAffiliation().add(affiliation);
    Organization organization = new Organization();
    affiliation.setOrganization(organization);
    organization.setName("New College");
    OrganizationAddress organizationAddress = new OrganizationAddress();
    organization.setAddress(organizationAddress);
    organizationAddress.setCity("Edinburgh");
    organizationAddress.setCountry(Iso3166Country.GB);
    orcidProfileManager.createOrcidProfile(profile1, false, false);
    ProfileEntity profileEntity = profileDao.find(TEST_ORCID);
    assertEquals(1, profileEntity.getOrgAffiliationRelations().size());
    OrgEntity orgEntity = profileEntity.getOrgAffiliationRelations().iterator().next().getOrg();
    assertNotNull(orgEntity);
    // Now create another profile with the same affiliation and check that
    // the org is reused;
    String otherOrcid = "4444-4444-4444-4448";
    OrcidProfile profile2 = createBasicProfile();
    profile2.setOrcidIdentifier(otherOrcid);
    List<Email> emailList2 = profile2.getOrcidBio().getContactDetails().getEmail();
    emailList2.clear();
    emailList2.add(new Email("another@semantico.com"));
    profile2.getOrcidActivities().setAffiliations(affiliations);
    orcidProfileManager.createOrcidProfile(profile2, false, false);
    ProfileEntity profileEntity2 = profileDao.find(otherOrcid);
    assertEquals(1, profileEntity2.getOrgAffiliationRelations().size());
    OrgEntity orgEntity2 = profileEntity2.getOrgAffiliationRelations().iterator().next().getOrg();
    assertNotNull(orgEntity);
    assertEquals(orgEntity.getId(), orgEntity2.getId());
}
Also used : Organization(org.orcid.jaxb.model.message.Organization) Email(org.orcid.jaxb.model.message.Email) OrganizationAddress(org.orcid.jaxb.model.message.OrganizationAddress) SubmissionDate(org.orcid.jaxb.model.message.SubmissionDate) OrcidActivities(org.orcid.jaxb.model.message.OrcidActivities) SubmissionDate(org.orcid.jaxb.model.message.SubmissionDate) Date(java.util.Date) ApprovalDate(org.orcid.jaxb.model.message.ApprovalDate) Claimed(org.orcid.jaxb.model.message.Claimed) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Affiliations(org.orcid.jaxb.model.message.Affiliations) OrcidHistory(org.orcid.jaxb.model.message.OrcidHistory) Affiliation(org.orcid.jaxb.model.message.Affiliation) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 34 with OrgEntity

use of org.orcid.persistence.jpa.entities.OrgEntity 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, createItemList(employmentEntity));
    return jpaJaxbEmploymentAdapter.toEmployment(employmentEntity);
}
Also used : SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) OrgAffiliationRelationEntity(org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity)

Example 35 with OrgEntity

use of org.orcid.persistence.jpa.entities.OrgEntity 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, createItemList(educationEntity));
    return jpaJaxbEducationAdapter.toEducation(educationEntity);
}
Also used : SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) OrgAffiliationRelationEntity(org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity)

Aggregations

OrgEntity (org.orcid.persistence.jpa.entities.OrgEntity)53 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)30 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)26 OrgAffiliationRelationEntity (org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity)17 EndDateEntity (org.orcid.persistence.jpa.entities.EndDateEntity)11 StartDateEntity (org.orcid.persistence.jpa.entities.StartDateEntity)11 Test (org.junit.Test)10 OrgDisambiguatedEntity (org.orcid.persistence.jpa.entities.OrgDisambiguatedEntity)8 PeerReviewEntity (org.orcid.persistence.jpa.entities.PeerReviewEntity)8 AmbiguousOrgEntity (org.orcid.persistence.jpa.entities.AmbiguousOrgEntity)7 File (java.io.File)6 Path (java.nio.file.Path)6 ProfileFundingEntity (org.orcid.persistence.jpa.entities.ProfileFundingEntity)6 Transactional (org.springframework.transaction.annotation.Transactional)5 Date (java.util.Date)4 Visibility (org.orcid.jaxb.model.common_v2.Visibility)4 Organization (org.orcid.jaxb.model.message.Organization)4 CompletionDateEntity (org.orcid.persistence.jpa.entities.CompletionDateEntity)4 HashSet (java.util.HashSet)3 Iso3166Country (org.orcid.jaxb.model.message.Iso3166Country)3