Search in sources :

Example 26 with Source

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

the class OrcidJaxbCopyManagerImpl method copyActivitiesToExistingPreservingVisibility.

@SuppressWarnings({ "unchecked", "rawtypes" })
private void copyActivitiesToExistingPreservingVisibility(ActivitiesContainer existingActivities, ActivitiesContainer updatedActivities, Visibility defaultVisibility) {
    if (updatedActivities == null) {
        return;
    }
    if (existingActivities == null) {
        try {
            existingActivities = updatedActivities.getClass().newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
    Map<String, ? extends Activity> updatedActivitiesMap = updatedActivities.retrieveActivitiesAsMap();
    Source targetSource = createSource();
    for (Iterator<? extends Activity> existingActivitiesIterator = existingActivities.retrieveActivities().iterator(); existingActivitiesIterator.hasNext(); ) {
        Activity existingActivity = existingActivitiesIterator.next();
        Activity updatedActivity = updatedActivitiesMap.get(existingActivity.getPutCode());
        if (updatedActivity == null) {
            if (!(Visibility.PRIVATE.equals(existingActivity.getVisibility()) || isFromDifferentSource(existingActivity))) {
                // Remove existing activities unless they are private (we
                // need to keep those because the API user won't even know
                // they are there) or they are from another source
                existingActivitiesIterator.remove();
            }
        } else {
            // Check the source of the existing activity is the same as
            // the current source
            checkSource(existingActivity);
            if (updatedActivity.getVisibility() == null || !updatedActivity.getVisibility().equals(existingActivity.getVisibility())) {
                // Keep the visibility from the existing activity unless
                // was set by API user
                updatedActivity.setVisibility(existingActivity.getVisibility());
            }
            addSourceToActivity(updatedActivity, targetSource);
            // Can remove existing object because will be replaced by
            // incoming
            existingActivitiesIterator.remove();
        }
    }
    for (Activity updatedActivity : updatedActivities.retrieveActivities()) {
        // Set default visibility for any remaining incoming affiliations
        if (updatedActivity.getVisibility() == null) {
            updatedActivity.setVisibility(defaultVisibility);
        }
        if (updatedActivity.getPutCode() == null) {
            // Check source is correct for any newly added activities, if
            // mentioned
            addSourceToActivity(updatedActivity, targetSource);
        }
        if (updatedActivity instanceof OrcidWork) {
            ((OrcidWork) updatedActivity).setModified(true);
        }
    }
    existingActivities.retrieveActivities().addAll((List) updatedActivities.retrieveActivities());
}
Also used : OrcidWork(org.orcid.jaxb.model.message.OrcidWork) Activity(org.orcid.jaxb.model.message.Activity) Source(org.orcid.jaxb.model.message.Source)

Example 27 with Source

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

the class OrcidJaxbCopyManagerImpl method createSource.

private Source createSource() {
    SourceEntity entity = sourceManager.retrieveSourceEntity();
    Source source = new Source();
    if (entity.getSourceClient() != null && !PojoUtil.isEmpty(entity.getSourceClient().getId())) {
        if (OrcidStringUtils.isValidOrcid(entity.getSourceClient().getId())) {
            source.setSourceOrcid(new SourceOrcid(entity.getSourceClient().getId()));
        } else {
            source.setSourceClientId(new SourceClientId(entity.getSourceClient().getId()));
        }
    } else if (entity.getSourceProfile() != null && !PojoUtil.isEmpty(entity.getSourceProfile().getId())) {
        source.setSourceClientId(null);
        source.setSourceOrcid(new SourceOrcid(entity.getSourceProfile().getId()));
    }
    return source;
}
Also used : SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) SourceClientId(org.orcid.jaxb.model.message.SourceClientId) SourceOrcid(org.orcid.jaxb.model.message.SourceOrcid) Source(org.orcid.jaxb.model.message.Source)

Example 28 with Source

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

the class OrcidProfileManagerImpl method checkWorkExternalIdentifiersAreNotDuplicated.

/**
 * Checks if the list of updated works contains any duplicated external
 * identifier, if so, it will throw an exception The newOrcidWorksList MUST
 * be deduped before getting into this method
 *
 * @param updatedOrcidWorksList
 *            the deduped list of works
 * @throws IllegalArgumentException
 *             if there is a duplicated external identifier
 */
public void checkWorkExternalIdentifiersAreNotDuplicated(List<OrcidWork> newOrcidWorksList, List<OrcidWork> existingWorkList) {
    // from the same source, so, we can skip the work source comparison
    if (newOrcidWorksList != null) {
        for (int i = 0; i < newOrcidWorksList.size(); i++) {
            OrcidWork newWork = newOrcidWorksList.get(i);
            for (int j = 0; j < newOrcidWorksList.size(); j++) {
                // If they are not the same work
                if (i != j) {
                    OrcidWork newWorkToCompare = newOrcidWorksList.get(j);
                    // If newWork have external identifiers
                    if (newWork.getWorkExternalIdentifiers() != null && newWork.getWorkExternalIdentifiers().getWorkExternalIdentifier() != null && !newWork.getWorkExternalIdentifiers().getWorkExternalIdentifier().isEmpty()) {
                        // For each external id on the outer work
                        for (WorkExternalIdentifier workExtId : newWork.getWorkExternalIdentifiers().getWorkExternalIdentifier()) {
                            if (newWorkToCompare.getWorkExternalIdentifiers() != null && newWorkToCompare.getWorkExternalIdentifiers().getWorkExternalIdentifier() != null && !newWorkToCompare.getWorkExternalIdentifiers().getWorkExternalIdentifier().isEmpty()) {
                                // the inner work
                                for (WorkExternalIdentifier workExtIdToCompare : newWorkToCompare.getWorkExternalIdentifiers().getWorkExternalIdentifier()) {
                                    // If the ext ids are the same
                                    if (workExtId.equals(workExtIdToCompare)) {
                                        Title title = (newWork.getWorkTitle() == null || newWork.getWorkTitle().getTitle() == null) ? null : newWork.getWorkTitle().getTitle();
                                        Title titleToCompare = (newWorkToCompare.getWorkTitle() == null || newWorkToCompare.getWorkTitle().getTitle() == null) ? null : newWorkToCompare.getWorkTitle().getTitle();
                                        if (!isTheSameTitle(title, titleToCompare) && !areBothExtIdsPartOf(newWork.getWorkType(), workExtId, workExtIdToCompare)) {
                                            String extIdContent = (workExtId.getWorkExternalIdentifierId() == null || PojoUtil.isEmpty(workExtId.getWorkExternalIdentifierId().getContent())) ? "" : workExtId.getWorkExternalIdentifierId().getContent();
                                            String title1 = (title == null) ? "" : title.getContent();
                                            String title2 = (titleToCompare == null) ? "" : titleToCompare.getContent();
                                            String errorMessage = String.format("Works \"%s\" and \"%s\" have the same external id \"%s\"", title1, title2, extIdContent);
                                            throw new IllegalArgumentException(errorMessage);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    // Then, if it already have works
    if (existingWorkList != null && existingWorkList.size() > 0) {
        // Check for duplicates between the existing works and the new works
        if (newOrcidWorksList != null) {
            for (OrcidWork orcidWork : newOrcidWorksList) {
                Source workSource = orcidWork.getSource();
                for (OrcidWork existingWork : existingWorkList) {
                    Source existingWorkSource = existingWork.getSource();
                    // If both works have the same source
                    if (isTheSameSource(workSource, existingWorkSource)) {
                        // If the new work have external identifiers
                        if (orcidWork.getWorkExternalIdentifiers() != null && orcidWork.getWorkExternalIdentifiers().getWorkExternalIdentifier() != null && !orcidWork.getWorkExternalIdentifiers().getWorkExternalIdentifier().isEmpty()) {
                            // For each external identifier in the new work
                            for (WorkExternalIdentifier newExternalIdentifier : orcidWork.getWorkExternalIdentifiers().getWorkExternalIdentifier()) {
                                if (existingWork.getWorkExternalIdentifiers() != null && existingWork.getWorkExternalIdentifiers().getWorkExternalIdentifier() != null && !existingWork.getWorkExternalIdentifiers().getWorkExternalIdentifier().isEmpty()) {
                                    // identifiers
                                    for (WorkExternalIdentifier existingExternalIdentifier : existingWork.getWorkExternalIdentifiers().getWorkExternalIdentifier()) {
                                        // If the ext ids are the same
                                        if (newExternalIdentifier.equals(existingExternalIdentifier)) {
                                            // Compare the titles, if they
                                            // are different, set it as
                                            // duplicated
                                            Title title = (orcidWork.getWorkTitle() == null || orcidWork.getWorkTitle().getTitle() == null) ? null : orcidWork.getWorkTitle().getTitle();
                                            Title titleToCompare = (existingWork.getWorkTitle() == null || existingWork.getWorkTitle().getTitle() == null) ? null : existingWork.getWorkTitle().getTitle();
                                            if (!isTheSameTitle(title, titleToCompare) && !areBothExtIdsPartOf(orcidWork.getWorkType(), existingExternalIdentifier, newExternalIdentifier)) {
                                                String extIdContent = (existingExternalIdentifier.getWorkExternalIdentifierId() == null || PojoUtil.isEmpty(existingExternalIdentifier.getWorkExternalIdentifierId().getContent())) ? "" : existingExternalIdentifier.getWorkExternalIdentifierId().getContent();
                                                String title1 = (title == null) ? "" : title.getContent();
                                                String title2 = (titleToCompare == null) ? "" : titleToCompare.getContent();
                                                String errorMessage = String.format("Works \"%s\" and \"%s\"(put-code '%s') have the same external id \"%s\"", title1, title2, existingWork.getPutCode(), extIdContent);
                                                throw new IllegalArgumentException(errorMessage);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : OrcidWork(org.orcid.jaxb.model.message.OrcidWork) Title(org.orcid.jaxb.model.message.Title) WorkExternalIdentifier(org.orcid.jaxb.model.message.WorkExternalIdentifier) Source(org.orcid.jaxb.model.message.Source)

Example 29 with Source

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

the class OrcidProfileToSolrDocument method convert.

@Deprecated
public OrcidSolrDocument convert(OrcidProfile profile) {
    // Check if the profile is locked
    if (profile.isLocked()) {
        profile.downgradeToOrcidIdentifierOnly();
    }
    OrcidSolrDocument profileIndexDocument = new OrcidSolrDocument();
    profileIndexDocument.setOrcid(profile.getOrcidIdentifier().getPath());
    OrcidDeprecated orcidDeprecated = profile.getOrcidDeprecated();
    if (orcidDeprecated != null) {
        profileIndexDocument.setPrimaryRecord(orcidDeprecated.getPrimaryRecord() != null ? orcidDeprecated.getPrimaryRecord().getOrcidIdentifier().getPath() : null);
    }
    OrcidBio orcidBio = profile.getOrcidBio();
    if (orcidBio != null) {
        PersonalDetails personalDetails = orcidBio.getPersonalDetails();
        boolean persistPersonalDetails = personalDetails != null;
        if (persistPersonalDetails) {
            profileIndexDocument.setFamilyName(personalDetails.getFamilyName() != null ? personalDetails.getFamilyName().getContent() : null);
            profileIndexDocument.setGivenNames(personalDetails.getGivenNames() != null ? personalDetails.getGivenNames().getContent() : null);
            profileIndexDocument.setCreditName(personalDetails.getCreditName() != null ? personalDetails.getCreditName().getContent() : null);
            List<OtherName> otherNames = personalDetails.getOtherNames() != null ? personalDetails.getOtherNames().getOtherName() : null;
            if (otherNames != null && !otherNames.isEmpty()) {
                List<String> names = new ArrayList<String>();
                for (OtherName otherName : otherNames) {
                    names.add(otherName.getContent());
                }
                profileIndexDocument.setOtherNames(names);
            }
        }
        ContactDetails contactDetails = orcidBio.getContactDetails();
        if (contactDetails != null) {
            for (Email email : contactDetails.getEmail()) {
                profileIndexDocument.addEmailAddress(email.getValue());
            }
        }
        ExternalIdentifiers externalIdentifiers = orcidBio.getExternalIdentifiers();
        if (externalIdentifiers != null) {
            List<String> extIdOrcids = new ArrayList<String>();
            List<String> extIdRefs = new ArrayList<String>();
            List<String> extIdOrcidsAndRefs = new ArrayList<String>();
            for (ExternalIdentifier externalIdentifier : externalIdentifiers.getExternalIdentifier()) {
                Source source = externalIdentifier.getSource();
                String sourcePath = null;
                if (source != null) {
                    sourcePath = source.retrieveSourcePath();
                    if (sourcePath != null) {
                        extIdOrcids.add(sourcePath);
                    }
                }
                ExternalIdReference externalIdReference = externalIdentifier.getExternalIdReference();
                if (externalIdReference != null) {
                    extIdRefs.add(externalIdReference.getContent());
                }
                if (NullUtils.noneNull(sourcePath, externalIdReference)) {
                    extIdOrcidsAndRefs.add(sourcePath + "=" + externalIdReference.getContent());
                }
            }
            if (!extIdOrcids.isEmpty()) {
                profileIndexDocument.setExternalIdSources(extIdOrcids);
            }
            if (!extIdRefs.isEmpty()) {
                profileIndexDocument.setExternalIdReferences(extIdRefs);
            }
            if (!extIdOrcidsAndRefs.isEmpty()) {
                profileIndexDocument.setExternalIdSourcesAndReferences(extIdOrcidsAndRefs);
            }
        }
        OrcidActivities orcidActivities = profile.getOrcidActivities();
        if (orcidActivities != null) {
            if (orcidBio != null && orcidBio.getKeywords() != null) {
                List<Keyword> keyWords = orcidBio.getKeywords().getKeyword();
                if (keyWords != null && keyWords.size() > 0) {
                    List<String> keywordValues = new ArrayList<String>();
                    for (Keyword keyword : keyWords) {
                        keywordValues.add(keyword.getContent());
                    }
                    profileIndexDocument.setKeywords(keywordValues);
                }
            }
        }
        List<OrcidWork> orcidWorks = profile.retrieveOrcidWorks() != null ? profile.retrieveOrcidWorks().getOrcidWork() : null;
        if (orcidWorks != null) {
            List<String> workTitles = new ArrayList<String>();
            Map<WorkExternalIdentifierType, List<String>> allExternalIdentifiers = new HashMap<WorkExternalIdentifierType, List<String>>();
            for (OrcidWork orcidWork : orcidWorks) {
                if (orcidWork.getWorkExternalIdentifiers() != null) {
                    for (WorkExternalIdentifier workExternalIdentifier : orcidWork.getWorkExternalIdentifiers().getWorkExternalIdentifier()) {
                        /**
                         * Creates a map that contains all different
                         * external identifiers for the current work
                         */
                        boolean nullSafeCheckForWorkExternalIdentifier = workExternalIdentifier.getWorkExternalIdentifierId() != null && !StringUtils.isBlank(workExternalIdentifier.getWorkExternalIdentifierId().getContent());
                        if (nullSafeCheckForWorkExternalIdentifier) {
                            WorkExternalIdentifierType type = workExternalIdentifier.getWorkExternalIdentifierType();
                            if (!allExternalIdentifiers.containsKey(type)) {
                                List<String> content = new ArrayList<String>();
                                content.add(workExternalIdentifier.getWorkExternalIdentifierId().getContent());
                                allExternalIdentifiers.put(type, content);
                            } else {
                                allExternalIdentifiers.get(type).add(workExternalIdentifier.getWorkExternalIdentifierId().getContent());
                            }
                        }
                    }
                }
                if (orcidWork.getWorkTitle() != null) {
                    Title workMainTitle = orcidWork.getWorkTitle().getTitle();
                    Subtitle worksubTitle = orcidWork.getWorkTitle().getSubtitle();
                    TranslatedTitle translatedTitle = orcidWork.getWorkTitle().getTranslatedTitle();
                    if (workMainTitle != null && !StringUtils.isBlank(workMainTitle.getContent())) {
                        workTitles.add(workMainTitle.getContent());
                    }
                    if (worksubTitle != null && !StringUtils.isBlank(worksubTitle.getContent())) {
                        workTitles.add(worksubTitle.getContent());
                    }
                    if (translatedTitle != null && !StringUtils.isBlank(translatedTitle.getContent())) {
                        workTitles.add(translatedTitle.getContent());
                    }
                }
            }
            profileIndexDocument.setWorkTitles(workTitles);
            // Set the list of external identifiers to the document list
            addExternalIdentifiersToIndexDocument(profileIndexDocument, allExternalIdentifiers);
        }
        List<Funding> orcidFundings = profile.retrieveFundings() != null ? profile.retrieveFundings().getFundings() : null;
        if (orcidFundings != null) {
            List<String> fundingTitle = new ArrayList<String>();
            for (Funding orcidFunding : orcidFundings) {
                FundingTitle title = orcidFunding.getTitle();
                if (title != null) {
                    if (title.getTitle() != null && !StringUtils.isBlank(title.getTitle().getContent())) {
                        fundingTitle.add(title.getTitle().getContent());
                    }
                    if (title.getTranslatedTitle() != null && StringUtils.isBlank(title.getTranslatedTitle().getContent())) {
                        fundingTitle.add(title.getTranslatedTitle().getContent());
                    }
                }
            }
            profileIndexDocument.setFundingTitles(fundingTitle);
        }
    }
    OrcidMessage orcidMessage = new OrcidMessage();
    orcidMessage.setMessageVersion(OrcidMessage.DEFAULT_VERSION);
    orcidMessage.setOrcidProfile(profile);
    OrcidHistory orcidHistory = profile.getOrcidHistory();
    if (orcidHistory != null) {
        LastModifiedDate lastModifiedDate = orcidHistory.getLastModifiedDate();
        if (lastModifiedDate != null) {
            profileIndexDocument.setProfileLastModifiedDate(lastModifiedDate.getValue().toGregorianCalendar().getTime());
        }
        SubmissionDate submissionDate = orcidHistory.getSubmissionDate();
        if (submissionDate != null) {
            profileIndexDocument.setProfileSubmissionDate(submissionDate.getValue().toGregorianCalendar().getTime());
        }
    }
    return profileIndexDocument;
}
Also used : LastModifiedDate(org.orcid.jaxb.model.message.LastModifiedDate) Email(org.orcid.jaxb.model.message.Email) OrcidBio(org.orcid.jaxb.model.message.OrcidBio) HashMap(java.util.HashMap) Funding(org.orcid.jaxb.model.message.Funding) ArrayList(java.util.ArrayList) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) SubmissionDate(org.orcid.jaxb.model.message.SubmissionDate) Source(org.orcid.jaxb.model.message.Source) ContactDetails(org.orcid.jaxb.model.message.ContactDetails) OrcidSolrDocument(org.orcid.utils.solr.entities.OrcidSolrDocument) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) ArrayList(java.util.ArrayList) List(java.util.List) ExternalIdentifiers(org.orcid.jaxb.model.message.ExternalIdentifiers) WorkExternalIdentifierType(org.orcid.jaxb.model.message.WorkExternalIdentifierType) ExternalIdReference(org.orcid.jaxb.model.message.ExternalIdReference) Keyword(org.orcid.jaxb.model.message.Keyword) WorkExternalIdentifier(org.orcid.jaxb.model.message.WorkExternalIdentifier) ExternalIdentifier(org.orcid.jaxb.model.message.ExternalIdentifier) OtherName(org.orcid.jaxb.model.message.OtherName) Title(org.orcid.jaxb.model.message.Title) FundingTitle(org.orcid.jaxb.model.message.FundingTitle) TranslatedTitle(org.orcid.jaxb.model.message.TranslatedTitle) PersonalDetails(org.orcid.jaxb.model.message.PersonalDetails) OrcidActivities(org.orcid.jaxb.model.message.OrcidActivities) Subtitle(org.orcid.jaxb.model.message.Subtitle) OrcidDeprecated(org.orcid.jaxb.model.message.OrcidDeprecated) TranslatedTitle(org.orcid.jaxb.model.message.TranslatedTitle) OrcidHistory(org.orcid.jaxb.model.message.OrcidHistory) WorkExternalIdentifier(org.orcid.jaxb.model.message.WorkExternalIdentifier) FundingTitle(org.orcid.jaxb.model.message.FundingTitle) OrcidDeprecated(org.orcid.jaxb.model.message.OrcidDeprecated)

Example 30 with Source

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

the class OrcidIndexManagerImplTest method createExternalIdentifier.

private ExternalIdentifier createExternalIdentifier(String orcid, String reference) {
    ExternalIdentifier externalIdentifier1 = new ExternalIdentifier();
    Source source = new Source();
    source.setSourceOrcid(new SourceOrcid(orcid));
    externalIdentifier1.setSource(source);
    externalIdentifier1.setExternalIdReference(new ExternalIdReference(reference));
    // you have to set this as visibility will filter out null visibilities.
    externalIdentifier1.setVisibility(Visibility.PUBLIC);
    return externalIdentifier1;
}
Also used : ExternalIdReference(org.orcid.jaxb.model.message.ExternalIdReference) WorkExternalIdentifier(org.orcid.jaxb.model.message.WorkExternalIdentifier) ExternalIdentifier(org.orcid.jaxb.model.message.ExternalIdentifier) SourceOrcid(org.orcid.jaxb.model.message.SourceOrcid) Source(org.orcid.jaxb.model.message.Source)

Aggregations

Source (org.orcid.jaxb.model.message.Source)30 OrcidWork (org.orcid.jaxb.model.message.OrcidWork)14 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)11 SourceOrcid (org.orcid.jaxb.model.message.SourceOrcid)10 SubmissionDate (org.orcid.jaxb.model.message.SubmissionDate)9 Title (org.orcid.jaxb.model.message.Title)9 FundingTitle (org.orcid.jaxb.model.message.FundingTitle)8 OrcidHistory (org.orcid.jaxb.model.message.OrcidHistory)8 Test (org.junit.Test)7 Subtitle (org.orcid.jaxb.model.message.Subtitle)7 WorkExternalIdentifier (org.orcid.jaxb.model.message.WorkExternalIdentifier)7 Transactional (org.springframework.transaction.annotation.Transactional)7 Date (java.util.Date)6 WorkTitle (org.orcid.jaxb.model.message.WorkTitle)6 HashMap (java.util.HashMap)5 Claimed (org.orcid.jaxb.model.message.Claimed)5 Email (org.orcid.jaxb.model.message.Email)5 ExternalIdentifier (org.orcid.jaxb.model.message.ExternalIdentifier)5 OrcidWorks (org.orcid.jaxb.model.message.OrcidWorks)5 SourceClientId (org.orcid.jaxb.model.message.SourceClientId)5