Search in sources :

Example 46 with OrgEntity

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

the class JSONPeerReviewWorkExternalIdentifierConverterV3Test 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(org.orcid.jaxb.model.record_v2.Role.MEMBER);
    result.setType(org.orcid.jaxb.model.record_v2.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(org.orcid.jaxb.model.record_v2.WorkType.BOOK_REVIEW);
    result.setVisibility(org.orcid.jaxb.model.common_v2.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 47 with OrgEntity

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

the class OrgManagerImpl method matchOrCreateOrg.

private OrgEntity matchOrCreateOrg(OrgEntity org) {
    OrgEntity match = orgDao.findByAddressAndDisambiguatedOrg(org.getName(), org.getCity(), org.getRegion(), org.getCountry(), org.getOrgDisambiguated());
    if (match != null) {
        return match;
    }
    SourceEntity entity = sourceManager.retrieveSourceEntity();
    if (entity != null) {
        SourceEntity newEntity = new SourceEntity();
        if (entity.getSourceClient() != null) {
            newEntity.setSourceClient(new ClientDetailsEntity(entity.getSourceClient().getId()));
        }
        if (entity.getSourceProfile() != null) {
            newEntity.setSourceProfile(new ProfileEntity(entity.getSourceProfile().getId()));
        }
        org.setSource(newEntity);
    }
    orgDao.persist(org);
    return org;
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity) AmbiguousOrgEntity(org.orcid.persistence.jpa.entities.AmbiguousOrgEntity)

Example 48 with OrgEntity

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

the class PeerReviewManagerImpl method updatePeerReview.

@Override
public PeerReview updatePeerReview(String orcid, PeerReview peerReview, boolean isApiRequest) {
    PeerReviewEntity existingEntity = peerReviewDao.getPeerReview(orcid, peerReview.getPutCode());
    Visibility originalVisibility = Visibility.fromValue(existingEntity.getVisibility().value());
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    // Save the original source
    String existingSourceId = existingEntity.getSourceId();
    String existingClientSourceId = existingEntity.getClientSourceId();
    // If request comes from the API perform validations
    if (isApiRequest) {
        activityValidator.validatePeerReview(peerReview, sourceEntity, false, isApiRequest, originalVisibility);
        validateGroupId(peerReview);
        List<PeerReview> existingReviews = this.findPeerReviews(orcid);
        for (PeerReview existing : existingReviews) {
            // Dont compare the updated peer review with the DB version
            if (!existing.getPutCode().equals(peerReview.getPutCode())) {
                activityValidator.checkExternalIdentifiersForDuplicates(peerReview.getExternalIdentifiers(), existing.getExternalIdentifiers(), existing.getSource(), sourceManager.retrieveSourceEntity());
            }
        }
    } else {
        // check vocab of external identifiers
        externalIDValidator.validateWorkOrPeerReview(peerReview.getExternalIdentifiers());
        externalIDValidator.validateWorkOrPeerReview(peerReview.getSubjectExternalIdentifier());
    }
    PeerReviewEntity updatedEntity = new PeerReviewEntity();
    orcidSecurityManager.checkSource(existingEntity);
    jpaJaxbPeerReviewAdapter.toPeerReviewEntity(peerReview, updatedEntity);
    updatedEntity.setProfile(new ProfileEntity(orcid));
    updatedEntity.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(originalVisibility.value()));
    // Be sure it doesn't overwrite the source
    updatedEntity.setSourceId(existingSourceId);
    updatedEntity.setClientSourceId(existingClientSourceId);
    OrgEntity updatedOrganization = orgManager.getOrgEntity(peerReview);
    updatedEntity.setOrg(updatedOrganization);
    updatedEntity = peerReviewDao.merge(updatedEntity);
    peerReviewDao.flush();
    notificationManager.sendAmendEmail(orcid, AmendedSection.PEER_REVIEW, createItemList(updatedEntity));
    return jpaJaxbPeerReviewAdapter.toPeerReview(updatedEntity);
}
Also used : PeerReviewEntity(org.orcid.persistence.jpa.entities.PeerReviewEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) Visibility(org.orcid.jaxb.model.v3.dev1.common.Visibility) PeerReview(org.orcid.jaxb.model.v3.dev1.record.PeerReview) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity)

Example 49 with OrgEntity

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 = Visibility.fromValue(pfe.getVisibility().value());
    // 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(org.orcid.jaxb.model.common_v2.Visibility.fromValue(originalVisibility.value()));
    // 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);
}
Also used : Funding(org.orcid.jaxb.model.v3.dev1.record.Funding) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) Visibility(org.orcid.jaxb.model.v3.dev1.common.Visibility) ProfileFundingEntity(org.orcid.persistence.jpa.entities.ProfileFundingEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity)

Example 50 with OrgEntity

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);
}
Also used : Funding(org.orcid.jaxb.model.v3.dev1.record.Funding) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) ProfileFundingEntity(org.orcid.persistence.jpa.entities.ProfileFundingEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity) Transactional(org.springframework.transaction.annotation.Transactional)

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