Search in sources :

Example 21 with WorkExternalIdentifier

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

the class OrcidProfileManagerImplTest method getWorkInsideOrcidProfile.

private OrcidProfile getWorkInsideOrcidProfile(String defaultTitle, String orcid) {
    OrcidWork orcidWork = new OrcidWork();
    //Set title
    WorkTitle title = new WorkTitle();
    if (defaultTitle != null)
        title.setTitle(new Title(defaultTitle));
    else
        title.setTitle(new Title("Title"));
    orcidWork.setWorkTitle(title);
    //Set external identifiers
    WorkExternalIdentifier extId1 = new WorkExternalIdentifier();
    extId1.setWorkExternalIdentifierId(new WorkExternalIdentifierId("doi-" + defaultTitle));
    extId1.setWorkExternalIdentifierType(WorkExternalIdentifierType.DOI);
    WorkExternalIdentifier extId2 = new WorkExternalIdentifier();
    if (defaultTitle != null)
        extId2.setWorkExternalIdentifierId(new WorkExternalIdentifierId("issn-" + defaultTitle));
    else
        extId2.setWorkExternalIdentifierId(new WorkExternalIdentifierId("issn-" + System.currentTimeMillis()));
    extId2.setWorkExternalIdentifierType(WorkExternalIdentifierType.ISSN);
    WorkExternalIdentifiers extIds = new WorkExternalIdentifiers();
    extIds.getWorkExternalIdentifier().add(extId1);
    extIds.getWorkExternalIdentifier().add(extId2);
    orcidWork.setWorkExternalIdentifiers(extIds);
    orcidWork.setWorkType(WorkType.ARTISTIC_PERFORMANCE);
    OrcidProfile profile = new OrcidProfile();
    profile.setOrcidIdentifier(orcid);
    List<OrcidWork> workList = new ArrayList<OrcidWork>();
    workList.add(orcidWork);
    OrcidWorks orcidWorks = new OrcidWorks();
    orcidWorks.setOrcidWork(workList);
    profile.setOrcidWorks(orcidWorks);
    return profile;
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) WorkExternalIdentifiers(org.orcid.jaxb.model.message.WorkExternalIdentifiers) WorkTitle(org.orcid.jaxb.model.message.WorkTitle) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) WorkExternalIdentifierId(org.orcid.jaxb.model.message.WorkExternalIdentifierId) ArrayList(java.util.ArrayList) Title(org.orcid.jaxb.model.message.Title) WorkTitle(org.orcid.jaxb.model.message.WorkTitle) FundingTitle(org.orcid.jaxb.model.message.FundingTitle) WorkExternalIdentifier(org.orcid.jaxb.model.message.WorkExternalIdentifier) OrcidWorks(org.orcid.jaxb.model.message.OrcidWorks)

Example 22 with WorkExternalIdentifier

use of org.orcid.jaxb.model.message.WorkExternalIdentifier 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 in existing works, if any is found, log it
        for (int i = 0; i < existingWorkList.size(); i++) {
            OrcidWork existingWork = existingWorkList.get(i);
            Source workSource = existingWork.getSource();
            for (int j = 0; j < existingWorkList.size(); j++) {
                // If it is not the same index
                if (i != j) {
                    OrcidWork existingWorkToCompare = existingWorkList.get(j);
                    Source workSourceToCompare = existingWorkToCompare.getSource();
                    // If both works have the same source
                    if (isTheSameSource(workSource, workSourceToCompare)) {
                        // If the work have external identifiers
                        if (existingWork.getWorkExternalIdentifiers() != null && existingWork.getWorkExternalIdentifiers().getWorkExternalIdentifier() != null && !existingWork.getWorkExternalIdentifiers().getWorkExternalIdentifier().isEmpty()) {
                            // Compare each external identifier
                            for (WorkExternalIdentifier workExtId : existingWork.getWorkExternalIdentifiers().getWorkExternalIdentifier()) {
                                // If the workToCompare have ext ids
                                if (existingWorkToCompare.getWorkExternalIdentifiers() != null && existingWorkToCompare.getWorkExternalIdentifiers().getWorkExternalIdentifier() != null && !existingWorkToCompare.getWorkExternalIdentifiers().getWorkExternalIdentifier().isEmpty()) {
                                    // rules:
                                    for (WorkExternalIdentifier workToCompareExtId : existingWorkToCompare.getWorkExternalIdentifiers().getWorkExternalIdentifier()) {
                                        // If the ext ids are the same
                                        if (workExtId.equals(workToCompareExtId)) {
                                            // Compare the titles, if they
                                            // are different, set it as
                                            // duplicated
                                            Title title = (existingWork.getWorkTitle() == null || existingWork.getWorkTitle().getTitle() == null) ? null : existingWork.getWorkTitle().getTitle();
                                            Title titleToCompare = (existingWorkToCompare.getWorkTitle() == null || existingWorkToCompare.getWorkTitle().getTitle() == null) ? null : existingWorkToCompare.getWorkTitle().getTitle();
                                            if (!isTheSameTitle(title, titleToCompare)) {
                                                String extIdContent = (workExtId.getWorkExternalIdentifierId() == null || PojoUtil.isEmpty(workExtId.getWorkExternalIdentifierId().getContent())) ? "" : workExtId.getWorkExternalIdentifierId().getContent();
                                                LOG.error("Works {} and {} have the same external identifier {}", new Object[] { existingWork.getPutCode(), existingWorkToCompare.getPutCode(), extIdContent });
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        // 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)

Aggregations

WorkExternalIdentifier (org.orcid.jaxb.model.message.WorkExternalIdentifier)22 WorkExternalIdentifierId (org.orcid.jaxb.model.message.WorkExternalIdentifierId)17 WorkExternalIdentifiers (org.orcid.jaxb.model.message.WorkExternalIdentifiers)16 OrcidWork (org.orcid.jaxb.model.message.OrcidWork)15 Title (org.orcid.jaxb.model.message.Title)13 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)11 FundingTitle (org.orcid.jaxb.model.message.FundingTitle)10 WorkTitle (org.orcid.jaxb.model.message.WorkTitle)10 OrcidActivities (org.orcid.jaxb.model.message.OrcidActivities)8 Test (org.junit.Test)7 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)7 OrcidWorks (org.orcid.jaxb.model.message.OrcidWorks)6 Source (org.orcid.jaxb.model.message.Source)5 Transactional (org.springframework.transaction.annotation.Transactional)5 OrcidIdentifier (org.orcid.jaxb.model.message.OrcidIdentifier)4 DBUnitTest (org.orcid.test.DBUnitTest)4 ArrayList (java.util.ArrayList)3 ContactDetails (org.orcid.jaxb.model.message.ContactDetails)3 Email (org.orcid.jaxb.model.message.Email)3 ExternalIdentifier (org.orcid.jaxb.model.message.ExternalIdentifier)3