Search in sources :

Example 41 with Visibility

use of org.orcid.jaxb.model.common_rc1.Visibility in project ORCID-Source by ORCID.

the class MigrateNamesAndBioToTheirOwnTables method migrateData.

private void migrateData() {
    LOG.debug("Starting migration process");
    List<Object[]> profileElements = Collections.emptyList();
    int counter = 0;
    int batchCount = 0;
    do {
        LOG.debug("About to fetch a batch from DB");
        profileElements = profileDao.findProfilesWhereNamesAreNotMigrated(batchSize);
        LOG.debug("Procesing batch, profiles processed so far: " + counter);
        for (final Object[] profileElement : profileElements) {
            String orcid = (String) profileElement[0];
            String givenNames = (String) profileElement[1];
            String familyName = (String) profileElement[2];
            String creditName = (String) profileElement[3];
            String namesVisibility = (String) profileElement[4];
            String biography = (String) profileElement[5];
            String biographyVisibility = (String) profileElement[6];
            String defaultVisibility = (String) profileElement[7];
            transactionTemplate.execute(new TransactionCallbackWithoutResult() {

                @Override
                protected void doInTransactionWithoutResult(TransactionStatus status) {
                    LOG.info("Migrating names for profile: {}", orcid);
                    if (!recordNameDao.exists(orcid)) {
                        ProfileEntity profile = new ProfileEntity(orcid);
                        RecordNameEntity recordName = new RecordNameEntity();
                        recordName.setProfile(profile);
                        recordName.setCreditName(creditName);
                        recordName.setFamilyName(familyName);
                        recordName.setGivenNames(givenNames);
                        if (PojoUtil.isEmpty(namesVisibility)) {
                            recordName.setVisibility(Visibility.fromValue(OrcidVisibilityDefaults.NAMES_DEFAULT.getVisibility().value()));
                        } else {
                            recordName.setVisibility(Visibility.fromValue(namesVisibility));
                        }
                        recordNameDao.createRecordName(recordName);
                    }
                    LOG.info("Migrating biography for profile: {}", orcid);
                    if (!biographyDao.exists(orcid)) {
                        Visibility visibility = Visibility.fromValue(OrcidVisibilityDefaults.BIOGRAPHY_DEFAULT.getVisibility().value());
                        if (!PojoUtil.isEmpty(biographyVisibility)) {
                            visibility = Visibility.fromValue(biographyVisibility);
                        } else if (!PojoUtil.isEmpty(defaultVisibility)) {
                            visibility = Visibility.fromValue(defaultVisibility);
                        }
                        biographyDao.persistBiography(orcid, biography, visibility);
                    }
                }
            });
            counter += 1;
        }
        batchCount += 1;
        LOG.info("Batches processed so far: {}", String.valueOf(batchCount));
        // Stop if we ran the number of batches
        if (numberOfBatches > 0) {
            if (batchCount >= numberOfBatches) {
                profileElements = null;
            }
        }
    } while (profileElements != null && !profileElements.isEmpty());
    LOG.debug("Finished migration process");
}
Also used : RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) TransactionStatus(org.springframework.transaction.TransactionStatus) Visibility(org.orcid.jaxb.model.common_v2.Visibility) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Example 42 with Visibility

use of org.orcid.jaxb.model.common_rc1.Visibility in project ORCID-Source by ORCID.

the class ResearcherUrlManagerImpl method updateResearcherUrl.

@Override
@Transactional
public ResearcherUrl updateResearcherUrl(String orcid, ResearcherUrl researcherUrl, boolean isApiRequest) {
    ResearcherUrlEntity updatedResearcherUrlEntity = researcherUrlDao.getResearcherUrl(orcid, researcherUrl.getPutCode());
    Visibility originalVisibility = Visibility.fromValue(updatedResearcherUrlEntity.getVisibility().value());
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    // Save the original source
    String existingSourceId = updatedResearcherUrlEntity.getSourceId();
    String existingClientSourceId = updatedResearcherUrlEntity.getClientSourceId();
    // Validate the researcher url
    PersonValidator.validateResearcherUrl(researcherUrl, sourceEntity, false, isApiRequest, originalVisibility);
    // Validate it is not duplicated
    List<ResearcherUrlEntity> existingResearcherUrls = researcherUrlDao.getResearcherUrls(orcid, getLastModified(orcid));
    for (ResearcherUrlEntity existing : existingResearcherUrls) {
        if (isDuplicated(existing, researcherUrl, sourceEntity)) {
            Map<String, String> params = new HashMap<String, String>();
            params.put("type", "researcher-url");
            params.put("value", researcherUrl.getUrlName());
            throw new OrcidDuplicatedElementException(params);
        }
    }
    orcidSecurityManager.checkSource(updatedResearcherUrlEntity);
    jpaJaxbResearcherUrlAdapter.toResearcherUrlEntity(researcherUrl, updatedResearcherUrlEntity);
    updatedResearcherUrlEntity.setLastModified(new Date());
    // Be sure it doesn't overwrite the source
    updatedResearcherUrlEntity.setSourceId(existingSourceId);
    updatedResearcherUrlEntity.setClientSourceId(existingClientSourceId);
    researcherUrlDao.merge(updatedResearcherUrlEntity);
    return jpaJaxbResearcherUrlAdapter.toResearcherUrl(updatedResearcherUrlEntity);
}
Also used : HashMap(java.util.HashMap) ResearcherUrlEntity(org.orcid.persistence.jpa.entities.ResearcherUrlEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) OrcidDuplicatedElementException(org.orcid.core.exception.OrcidDuplicatedElementException) Visibility(org.orcid.jaxb.model.common_v2.Visibility) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 43 with Visibility

use of org.orcid.jaxb.model.common_rc1.Visibility in project ORCID-Source by ORCID.

the class ExternalIdentifierManagerImpl method updateExternalIdentifier.

@Override
public PersonExternalIdentifier updateExternalIdentifier(String orcid, PersonExternalIdentifier externalIdentifier, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    ExternalIdentifierEntity updatedExternalIdentifierEntity = externalIdentifierDao.getExternalIdentifierEntity(orcid, externalIdentifier.getPutCode());
    // Save the original source
    String existingSourceId = updatedExternalIdentifierEntity.getSourceId();
    String existingClientSourceId = updatedExternalIdentifierEntity.getClientSourceId();
    Visibility originalVisibility = Visibility.fromValue(updatedExternalIdentifierEntity.getVisibility().value());
    // Validate external identifier
    PersonValidator.validateExternalIdentifier(externalIdentifier, sourceEntity, false, isApiRequest, originalVisibility, 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);
        }
    }
    orcidSecurityManager.checkSource(updatedExternalIdentifierEntity);
    jpaJaxbExternalIdentifierAdapter.toExternalIdentifierEntity(externalIdentifier, updatedExternalIdentifierEntity);
    updatedExternalIdentifierEntity.setLastModified(new Date());
    // Set source
    updatedExternalIdentifierEntity.setSourceId(existingSourceId);
    updatedExternalIdentifierEntity.setClientSourceId(existingClientSourceId);
    externalIdentifierDao.merge(updatedExternalIdentifierEntity);
    return jpaJaxbExternalIdentifierAdapter.toExternalIdentifier(updatedExternalIdentifierEntity);
}
Also used : HashMap(java.util.HashMap) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) ExternalIdentifierEntity(org.orcid.persistence.jpa.entities.ExternalIdentifierEntity) OrcidDuplicatedElementException(org.orcid.core.exception.OrcidDuplicatedElementException) Visibility(org.orcid.jaxb.model.common_v2.Visibility) Date(java.util.Date)

Example 44 with Visibility

use of org.orcid.jaxb.model.common_rc1.Visibility in project ORCID-Source by ORCID.

the class OtherNameManagerImpl method updateOtherName.

@Override
@Transactional
public OtherName updateOtherName(String orcid, Long putCode, OtherName otherName, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    OtherNameEntity updatedOtherNameEntity = otherNameDao.getOtherName(orcid, putCode);
    Visibility originalVisibility = Visibility.fromValue(updatedOtherNameEntity.getVisibility().value());
    // Save the original source
    String existingSourceId = updatedOtherNameEntity.getSourceId();
    String existingClientSourceId = updatedOtherNameEntity.getClientSourceId();
    // Validate the other name
    PersonValidator.validateOtherName(otherName, sourceEntity, false, isApiRequest, originalVisibility);
    // Validate it is not duplicated
    List<OtherNameEntity> existingOtherNames = otherNameDao.getOtherNames(orcid, getLastModified(orcid));
    for (OtherNameEntity existing : existingOtherNames) {
        if (isDuplicated(existing, otherName, sourceEntity)) {
            Map<String, String> params = new HashMap<String, String>();
            params.put("type", "otherName");
            params.put("value", otherName.getContent());
            throw new OrcidDuplicatedElementException(params);
        }
    }
    orcidSecurityManager.checkSource(updatedOtherNameEntity);
    jpaJaxbOtherNameAdapter.toOtherNameEntity(otherName, updatedOtherNameEntity);
    updatedOtherNameEntity.setLastModified(new Date());
    // Be sure it doesn't overwrite the source
    updatedOtherNameEntity.setSourceId(existingSourceId);
    updatedOtherNameEntity.setClientSourceId(existingClientSourceId);
    otherNameDao.merge(updatedOtherNameEntity);
    return jpaJaxbOtherNameAdapter.toOtherName(updatedOtherNameEntity);
}
Also used : HashMap(java.util.HashMap) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) OrcidDuplicatedElementException(org.orcid.core.exception.OrcidDuplicatedElementException) OtherNameEntity(org.orcid.persistence.jpa.entities.OtherNameEntity) Visibility(org.orcid.jaxb.model.common_v2.Visibility) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 45 with Visibility

use of org.orcid.jaxb.model.common_rc1.Visibility 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 = existingEntity.getVisibility();
    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(originalVisibility);
    // 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.common_v2.Visibility) PeerReview(org.orcid.jaxb.model.record_v2.PeerReview) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity)

Aggregations

Visibility (org.orcid.jaxb.model.common_v2.Visibility)55 ClientResponse (com.sun.jersey.api.client.ClientResponse)36 Test (org.junit.Test)36 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)12 OrcidError (org.orcid.jaxb.model.error_v2.OrcidError)11 HashMap (java.util.HashMap)10 OrcidError (org.orcid.jaxb.model.error_rc1.OrcidError)9 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)9 Visibility (org.orcid.jaxb.model.common_rc2.Visibility)8 Date (java.util.Date)7 Visibility (org.orcid.jaxb.model.common_rc1.Visibility)7 Visibility (org.orcid.jaxb.model.common_rc3.Visibility)6 Work (org.orcid.jaxb.model.record_v2.Work)6 OrcidDuplicatedElementException (org.orcid.core.exception.OrcidDuplicatedElementException)5 Funding (org.orcid.jaxb.model.record_v2.Funding)5 PeerReview (org.orcid.jaxb.model.record_v2.PeerReview)5 Visibility (org.orcid.jaxb.model.common_rc4.Visibility)4 OrcidError (org.orcid.jaxb.model.error_rc3.OrcidError)4 OrgEntity (org.orcid.persistence.jpa.entities.OrgEntity)4 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)4