Search in sources :

Example 96 with Work

use of org.orcid.jaxb.model.v3.dev1.record.Work in project ORCID-Source by ORCID.

the class PublicAPISecurityManagerV3Impl method filter.

@Override
public void filter(WorkBulk workBulk) {
    if (workBulk != null && workBulk.getBulk() != null) {
        List<BulkElement> filtered = new ArrayList<>();
        for (int i = 0; i < workBulk.getBulk().size(); i++) {
            BulkElement bulkElement = workBulk.getBulk().get(i);
            if (bulkElement instanceof OrcidError) {
                filtered.add(bulkElement);
            } else {
                try {
                    checkIsPublic((Work) bulkElement);
                    filtered.add(bulkElement);
                } catch (OrcidNonPublicElementException e) {
                    filtered.add(orcidCoreExceptionMapper.getV3OrcidError(e));
                }
            }
        }
        workBulk.setBulk(filtered);
    }
}
Also used : OrcidError(org.orcid.jaxb.model.v3.dev1.error.OrcidError) BulkElement(org.orcid.jaxb.model.record.bulk.BulkElement) OrcidNonPublicElementException(org.orcid.core.exception.OrcidNonPublicElementException) ArrayList(java.util.ArrayList)

Example 97 with Work

use of org.orcid.jaxb.model.v3.dev1.record.Work in project ORCID-Source by ORCID.

the class ContributorUtilsTest method testFilterContributorPrivateDataForWorkWithPublicName.

@Test
public void testFilterContributorPrivateDataForWorkWithPublicName() {
    when(profileEntityManager.orcidExists(anyString())).thenReturn(true);
    when(profileEntityCacheManager.retrieve(anyString())).thenReturn(new ProfileEntity());
    when(cacheManager.getPublicCreditName(any(ProfileEntity.class))).thenReturn("a public name");
    Work work = getWorkWithOrcidContributor();
    contributorUtils.filterContributorPrivateData(work);
    Contributor contributor = work.getWorkContributors().getContributor().get(0);
    assertNull(contributor.getContributorEmail());
    assertEquals("a public name", contributor.getCreditName().getContent());
}
Also used : Work(org.orcid.jaxb.model.v3.dev1.record.Work) FundingContributor(org.orcid.jaxb.model.v3.dev1.record.FundingContributor) Contributor(org.orcid.jaxb.model.v3.dev1.common.Contributor) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Test(org.junit.Test)

Example 98 with Work

use of org.orcid.jaxb.model.v3.dev1.record.Work in project ORCID-Source by ORCID.

the class ContributorUtilsTest method testFilterContributorPrivateDataForWorkWithInvalidOrcidRecord.

@Test
public void testFilterContributorPrivateDataForWorkWithInvalidOrcidRecord() {
    when(profileEntityManager.orcidExists(anyString())).thenReturn(false);
    Work work = getWorkWithOrcidContributor();
    contributorUtils.filterContributorPrivateData(work);
    Contributor contributor = work.getWorkContributors().getContributor().get(0);
    assertNull(contributor.getContributorEmail());
    assertEquals("original credit name", contributor.getCreditName().getContent());
}
Also used : Work(org.orcid.jaxb.model.v3.dev1.record.Work) FundingContributor(org.orcid.jaxb.model.v3.dev1.record.FundingContributor) Contributor(org.orcid.jaxb.model.v3.dev1.common.Contributor) Test(org.junit.Test)

Example 99 with Work

use of org.orcid.jaxb.model.v3.dev1.record.Work in project ORCID-Source by ORCID.

the class ContributorUtilsTest method testFilterContributorPrivateDataForWorkWithPrivateName.

@Test
public void testFilterContributorPrivateDataForWorkWithPrivateName() {
    when(profileEntityManager.orcidExists(anyString())).thenReturn(true);
    when(profileEntityCacheManager.retrieve(anyString())).thenReturn(new ProfileEntity());
    when(cacheManager.getPublicCreditName(any(ProfileEntity.class))).thenReturn(null);
    Work work = getWorkWithOrcidContributor();
    contributorUtils.filterContributorPrivateData(work);
    Contributor contributor = work.getWorkContributors().getContributor().get(0);
    assertNull(contributor.getContributorEmail());
    assertEquals("", contributor.getCreditName().getContent());
}
Also used : Work(org.orcid.jaxb.model.v3.dev1.record.Work) FundingContributor(org.orcid.jaxb.model.v3.dev1.record.FundingContributor) Contributor(org.orcid.jaxb.model.v3.dev1.common.Contributor) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Test(org.junit.Test)

Example 100 with Work

use of org.orcid.jaxb.model.v3.dev1.record.Work in project ORCID-Source by ORCID.

the class ContributorUtilsTest method testFilterContributorPrivateDataForWorkWithNoOrcidRecord.

@Test
public void testFilterContributorPrivateDataForWorkWithNoOrcidRecord() {
    Work work = getWorkWithContributorWithoutOrcid();
    contributorUtils.filterContributorPrivateData(work);
    Contributor contributor = work.getWorkContributors().getContributor().get(0);
    assertNull(contributor.getContributorEmail());
    assertEquals("original credit name", contributor.getCreditName().getContent());
}
Also used : Work(org.orcid.jaxb.model.v3.dev1.record.Work) FundingContributor(org.orcid.jaxb.model.v3.dev1.record.FundingContributor) Contributor(org.orcid.jaxb.model.v3.dev1.common.Contributor) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)154 Work (org.orcid.jaxb.model.v3.dev1.record.Work)141 ExternalID (org.orcid.jaxb.model.v3.dev1.record.ExternalID)46 DBUnitTest (org.orcid.test.DBUnitTest)41 Response (javax.ws.rs.core.Response)39 Title (org.orcid.jaxb.model.v3.dev1.common.Title)29 WorkTitle (org.orcid.jaxb.model.v3.dev1.record.WorkTitle)29 WorkSummary (org.orcid.jaxb.model.v3.dev1.record.summary.WorkSummary)29 Url (org.orcid.jaxb.model.v3.dev1.common.Url)28 ExternalIDs (org.orcid.jaxb.model.v3.dev1.record.ExternalIDs)24 WorkBulk (org.orcid.jaxb.model.v3.dev1.record.WorkBulk)22 OrcidError (org.orcid.jaxb.model.v3.dev1.error.OrcidError)21 BaseTest (org.orcid.core.BaseTest)20 NoResultException (javax.persistence.NoResultException)17 OrcidAccessControlException (org.orcid.core.exception.OrcidAccessControlException)17 OrcidUnauthorizedException (org.orcid.core.exception.OrcidUnauthorizedException)17 OrcidVisibilityException (org.orcid.core.exception.OrcidVisibilityException)17 VisibilityMismatchException (org.orcid.core.exception.VisibilityMismatchException)17 WrongSourceException (org.orcid.core.exception.WrongSourceException)17 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)15