Search in sources :

Example 1 with OrcidNonPublicElementException

use of org.orcid.core.exception.OrcidNonPublicElementException in project ORCID-Source by ORCID.

the class PublicAPISecurityManagerV2Test method checkIsPublicNameTest.

@Test
public void checkIsPublicNameTest() {
    Name n = new Name();
    n.setVisibility(Visibility.PUBLIC);
    publicAPISecurityManagerV2.checkIsPublic(n);
    try {
        n.setVisibility(Visibility.LIMITED);
        publicAPISecurityManagerV2.checkIsPublic(n);
        fail();
    } catch (OrcidNonPublicElementException e) {
    }
    try {
        n.setVisibility(Visibility.PRIVATE);
        publicAPISecurityManagerV2.checkIsPublic(n);
        fail();
    } catch (OrcidNonPublicElementException e) {
    }
}
Also used : OrcidNonPublicElementException(org.orcid.core.exception.OrcidNonPublicElementException) OtherName(org.orcid.jaxb.model.record_v2.OtherName) Name(org.orcid.jaxb.model.record_v2.Name) Test(org.junit.Test)

Example 2 with OrcidNonPublicElementException

use of org.orcid.core.exception.OrcidNonPublicElementException in project ORCID-Source by ORCID.

the class PublicAPISecurityManagerV2Test method checkIsPublicBiographyTest.

@Test
public void checkIsPublicBiographyTest() {
    Biography b = new Biography();
    b.setVisibility(Visibility.PUBLIC);
    b.setContent("Bio test");
    publicAPISecurityManagerV2.checkIsPublic(b);
    try {
        b.setVisibility(Visibility.LIMITED);
        publicAPISecurityManagerV2.checkIsPublic(b);
        fail();
    } catch (OrcidNonPublicElementException e) {
    }
    try {
        b.setVisibility(Visibility.PRIVATE);
        publicAPISecurityManagerV2.checkIsPublic(b);
        fail();
    } catch (OrcidNonPublicElementException e) {
    }
}
Also used : OrcidNonPublicElementException(org.orcid.core.exception.OrcidNonPublicElementException) Biography(org.orcid.jaxb.model.record_v2.Biography) Test(org.junit.Test)

Example 3 with OrcidNonPublicElementException

use of org.orcid.core.exception.OrcidNonPublicElementException in project ORCID-Source by ORCID.

the class PublicAPISecurityManagerV2Impl method filter.

@Override
public void filter(Person person) {
    if (person == null) {
        return;
    }
    if (person.getAddresses() != null) {
        filter(person.getAddresses());
    }
    if (person.getEmails() != null) {
        filter(person.getEmails());
    }
    if (person.getExternalIdentifiers() != null) {
        filter(person.getExternalIdentifiers());
    }
    if (person.getKeywords() != null) {
        filter(person.getKeywords());
    }
    if (person.getOtherNames() != null) {
        filter(person.getOtherNames());
    }
    if (person.getResearcherUrls() != null) {
        filter(person.getResearcherUrls());
    }
    Name name = person.getName();
    if (name != null) {
        try {
            checkIsPublic(name);
        } catch (OrcidNonPublicElementException ex) {
            person.setName(null);
        }
    }
    Biography bio = person.getBiography();
    if (bio != null) {
        try {
            checkIsPublic(bio);
        } catch (OrcidNonPublicElementException ex) {
            person.setBiography(null);
        }
    }
}
Also used : OrcidNonPublicElementException(org.orcid.core.exception.OrcidNonPublicElementException) Biography(org.orcid.jaxb.model.record_v2.Biography) Name(org.orcid.jaxb.model.record_v2.Name)

Example 4 with OrcidNonPublicElementException

use of org.orcid.core.exception.OrcidNonPublicElementException in project ORCID-Source by ORCID.

the class PublicAPISecurityManagerV2Impl 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.getOrcidError(e));
                }
            }
        }
        workBulk.setBulk(filtered);
    }
}
Also used : OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) BulkElement(org.orcid.jaxb.model.record_v2.BulkElement) OrcidNonPublicElementException(org.orcid.core.exception.OrcidNonPublicElementException) ArrayList(java.util.ArrayList)

Aggregations

OrcidNonPublicElementException (org.orcid.core.exception.OrcidNonPublicElementException)4 Test (org.junit.Test)2 Biography (org.orcid.jaxb.model.record_v2.Biography)2 Name (org.orcid.jaxb.model.record_v2.Name)2 ArrayList (java.util.ArrayList)1 OrcidError (org.orcid.jaxb.model.error_v2.OrcidError)1 BulkElement (org.orcid.jaxb.model.record_v2.BulkElement)1 OtherName (org.orcid.jaxb.model.record_v2.OtherName)1