Search in sources :

Example 16 with Funding

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

the class PublicV3ApiServiceDelegatorTest method testViewFundings.

@Test
public void testViewFundings() {
    Response response = serviceDelegator.viewFundings(ORCID);
    assertNotNull(response);
    Fundings fundings = (Fundings) response.getEntity();
    assertNotNull(fundings);
    assertEquals("/0000-0000-0000-0003/fundings", fundings.getPath());
    assertNotNull(fundings.getLastModifiedDate());
    assertNotNull(fundings.getLastModifiedDate().getValue());
    assertEquals(1, fundings.getFundingGroup().size());
    assertEquals(1, fundings.getFundingGroup().get(0).getFundingSummary().size());
    FundingSummary funding = fundings.getFundingGroup().get(0).getFundingSummary().get(0);
    assertNotNull(funding.getTitle());
    assertNotNull(funding.getTitle().getTitle());
    assertEquals(Long.valueOf(10), funding.getPutCode());
    assertNotNull(funding.getLastModifiedDate());
    assertNotNull(funding.getLastModifiedDate().getValue());
    assertEquals("/0000-0000-0000-0003/funding/10", funding.getPath());
    assertEquals("PUBLIC", funding.getTitle().getTitle().getContent());
    assertEquals(Visibility.PUBLIC.value(), funding.getVisibility().value());
    assertEquals("APP-5555555555555555", funding.getSource().retrieveSourcePath());
}
Also used : Response(javax.ws.rs.core.Response) Fundings(org.orcid.jaxb.model.v3.dev1.record.summary.Fundings) FundingSummary(org.orcid.jaxb.model.v3.dev1.record.summary.FundingSummary) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 17 with Funding

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

the class PublicAPISecurityManagerV3Test method checkIsPublicActivitiesSummaryTest.

@Test
public void checkIsPublicActivitiesSummaryTest() {
    ActivitiesSummary as = getActivitiesSummaryElement();
    publicAPISecurityManagerV3.filter(as);
    // Assert it have all activities
    assertEquals(3, as.getEducations().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getEducations());
    assertEquals(3, as.getEmployments().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getEmployments());
    assertEquals(3, as.getFundings().getFundingGroup().size());
    assertGroupContainsOnlyPublicElements(as.getFundings());
    assertEquals(3, as.getPeerReviews().getPeerReviewGroup().size());
    assertGroupContainsOnlyPublicElements(as.getPeerReviews());
    assertEquals(3, as.getWorks().getWorkGroup().size());
    assertGroupContainsOnlyPublicElements(as.getWorks());
    assertEquals(3, as.getDistinctions().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getDistinctions());
    assertEquals(3, as.getInvitedPositions().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getInvitedPositions());
    assertEquals(3, as.getMemberships().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getMemberships());
    assertEquals(3, as.getQualifications().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getQualifications());
    assertEquals(3, as.getServices().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getServices());
    // Assert it filters educations
    as = getActivitiesSummaryElement();
    setVisibility(as.getEducations().getSummaries(), Visibility.LIMITED, Visibility.PRIVATE, Visibility.LIMITED);
    publicAPISecurityManagerV3.filter(as);
    assertNotNull(as.getEducations());
    assertTrue(as.getEducations().getSummaries().isEmpty());
    assertEquals(3, as.getEmployments().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getEmployments());
    assertEquals(3, as.getFundings().getFundingGroup().size());
    assertGroupContainsOnlyPublicElements(as.getFundings());
    assertEquals(3, as.getPeerReviews().getPeerReviewGroup().size());
    assertGroupContainsOnlyPublicElements(as.getPeerReviews());
    assertEquals(3, as.getWorks().getWorkGroup().size());
    assertGroupContainsOnlyPublicElements(as.getWorks());
    assertEquals(3, as.getDistinctions().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getDistinctions());
    assertEquals(3, as.getInvitedPositions().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getInvitedPositions());
    assertEquals(3, as.getMemberships().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getMemberships());
    assertEquals(3, as.getQualifications().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getQualifications());
    assertEquals(3, as.getServices().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getServices());
    // Assert it filters employments
    as = getActivitiesSummaryElement();
    setVisibility(as.getEmployments().getSummaries(), Visibility.LIMITED, Visibility.PRIVATE, Visibility.LIMITED);
    publicAPISecurityManagerV3.filter(as);
    assertEquals(3, as.getEducations().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getEducations());
    assertNotNull(as.getEmployments());
    assertTrue(as.getEmployments().getSummaries().isEmpty());
    assertEquals(3, as.getFundings().getFundingGroup().size());
    assertGroupContainsOnlyPublicElements(as.getFundings());
    assertEquals(3, as.getPeerReviews().getPeerReviewGroup().size());
    assertGroupContainsOnlyPublicElements(as.getPeerReviews());
    assertEquals(3, as.getWorks().getWorkGroup().size());
    assertGroupContainsOnlyPublicElements(as.getWorks());
    assertEquals(3, as.getDistinctions().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getDistinctions());
    assertEquals(3, as.getInvitedPositions().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getInvitedPositions());
    assertEquals(3, as.getMemberships().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getMemberships());
    assertEquals(3, as.getQualifications().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getQualifications());
    assertEquals(3, as.getServices().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getServices());
    // Assert it filters distinctions
    as = getActivitiesSummaryElement();
    setVisibility(as.getDistinctions().getSummaries(), Visibility.LIMITED, Visibility.PRIVATE, Visibility.LIMITED);
    publicAPISecurityManagerV3.filter(as);
    assertEquals(3, as.getEducations().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getEducations());
    assertEquals(3, as.getEmployments().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getEmployments());
    assertEquals(3, as.getFundings().getFundingGroup().size());
    assertGroupContainsOnlyPublicElements(as.getFundings());
    assertEquals(3, as.getPeerReviews().getPeerReviewGroup().size());
    assertGroupContainsOnlyPublicElements(as.getPeerReviews());
    assertEquals(3, as.getWorks().getWorkGroup().size());
    assertGroupContainsOnlyPublicElements(as.getWorks());
    assertTrue(as.getDistinctions().getSummaries().isEmpty());
    assertEquals(3, as.getInvitedPositions().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getInvitedPositions());
    assertEquals(3, as.getMemberships().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getMemberships());
    assertEquals(3, as.getQualifications().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getQualifications());
    assertEquals(3, as.getServices().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getServices());
    // Assert it filters invited positions
    as = getActivitiesSummaryElement();
    setVisibility(as.getInvitedPositions().getSummaries(), Visibility.LIMITED, Visibility.PRIVATE, Visibility.LIMITED);
    publicAPISecurityManagerV3.filter(as);
    assertEquals(3, as.getEducations().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getEducations());
    assertEquals(3, as.getEmployments().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getEmployments());
    assertEquals(3, as.getFundings().getFundingGroup().size());
    assertGroupContainsOnlyPublicElements(as.getFundings());
    assertEquals(3, as.getPeerReviews().getPeerReviewGroup().size());
    assertGroupContainsOnlyPublicElements(as.getPeerReviews());
    assertEquals(3, as.getWorks().getWorkGroup().size());
    assertGroupContainsOnlyPublicElements(as.getWorks());
    assertEquals(3, as.getDistinctions().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getDistinctions());
    assertTrue(as.getInvitedPositions().getSummaries().isEmpty());
    assertEquals(3, as.getMemberships().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getMemberships());
    assertEquals(3, as.getQualifications().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getQualifications());
    assertEquals(3, as.getServices().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getServices());
    // Assert it filters memberships
    as = getActivitiesSummaryElement();
    setVisibility(as.getMemberships().getSummaries(), Visibility.LIMITED, Visibility.PRIVATE, Visibility.LIMITED);
    publicAPISecurityManagerV3.filter(as);
    assertEquals(3, as.getEducations().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getEducations());
    assertEquals(3, as.getEmployments().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getEmployments());
    assertEquals(3, as.getFundings().getFundingGroup().size());
    assertGroupContainsOnlyPublicElements(as.getFundings());
    assertEquals(3, as.getPeerReviews().getPeerReviewGroup().size());
    assertGroupContainsOnlyPublicElements(as.getPeerReviews());
    assertEquals(3, as.getWorks().getWorkGroup().size());
    assertGroupContainsOnlyPublicElements(as.getWorks());
    assertEquals(3, as.getDistinctions().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getDistinctions());
    assertEquals(3, as.getInvitedPositions().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getInvitedPositions());
    assertTrue(as.getMemberships().getSummaries().isEmpty());
    assertEquals(3, as.getQualifications().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getQualifications());
    assertEquals(3, as.getServices().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getServices());
    // Assert it filters qualifications
    as = getActivitiesSummaryElement();
    setVisibility(as.getQualifications().getSummaries(), Visibility.LIMITED, Visibility.PRIVATE, Visibility.LIMITED);
    publicAPISecurityManagerV3.filter(as);
    assertEquals(3, as.getEducations().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getEducations());
    assertEquals(3, as.getEmployments().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getEmployments());
    assertEquals(3, as.getFundings().getFundingGroup().size());
    assertGroupContainsOnlyPublicElements(as.getFundings());
    assertEquals(3, as.getPeerReviews().getPeerReviewGroup().size());
    assertGroupContainsOnlyPublicElements(as.getPeerReviews());
    assertEquals(3, as.getWorks().getWorkGroup().size());
    assertGroupContainsOnlyPublicElements(as.getWorks());
    assertEquals(3, as.getDistinctions().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getDistinctions());
    assertEquals(3, as.getInvitedPositions().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getInvitedPositions());
    assertEquals(3, as.getMemberships().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getMemberships());
    assertTrue(as.getQualifications().getSummaries().isEmpty());
    assertEquals(3, as.getServices().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getServices());
    // Assert it filters services
    as = getActivitiesSummaryElement();
    setVisibility(as.getServices().getSummaries(), Visibility.LIMITED, Visibility.PRIVATE, Visibility.LIMITED);
    publicAPISecurityManagerV3.filter(as);
    assertEquals(3, as.getEducations().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getEducations());
    assertEquals(3, as.getEmployments().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getEmployments());
    assertEquals(3, as.getFundings().getFundingGroup().size());
    assertGroupContainsOnlyPublicElements(as.getFundings());
    assertEquals(3, as.getPeerReviews().getPeerReviewGroup().size());
    assertGroupContainsOnlyPublicElements(as.getPeerReviews());
    assertEquals(3, as.getWorks().getWorkGroup().size());
    assertGroupContainsOnlyPublicElements(as.getWorks());
    assertEquals(3, as.getDistinctions().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getDistinctions());
    assertEquals(3, as.getInvitedPositions().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getInvitedPositions());
    assertEquals(3, as.getMemberships().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getMemberships());
    assertEquals(3, as.getQualifications().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getQualifications());
    assertTrue(as.getServices().getSummaries().isEmpty());
    // Assert it filters funding
    as = getActivitiesSummaryElement();
    setVisibility(as.getFundings(), Visibility.LIMITED, Visibility.PRIVATE, Visibility.LIMITED);
    publicAPISecurityManagerV3.filter(as);
    assertEquals(3, as.getEducations().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getEducations());
    assertEquals(3, as.getEmployments().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getEmployments());
    assertTrue(as.getFundings().getFundingGroup().isEmpty());
    assertEquals(3, as.getPeerReviews().getPeerReviewGroup().size());
    assertGroupContainsOnlyPublicElements(as.getPeerReviews());
    assertEquals(3, as.getWorks().getWorkGroup().size());
    assertGroupContainsOnlyPublicElements(as.getWorks());
    assertEquals(3, as.getDistinctions().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getDistinctions());
    assertEquals(3, as.getInvitedPositions().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getInvitedPositions());
    assertEquals(3, as.getMemberships().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getMemberships());
    assertEquals(3, as.getQualifications().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getQualifications());
    assertEquals(3, as.getServices().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getServices());
    // Assert it filters peer reviews
    as = getActivitiesSummaryElement();
    setVisibility(as.getPeerReviews(), Visibility.LIMITED, Visibility.PRIVATE, Visibility.LIMITED);
    publicAPISecurityManagerV3.filter(as);
    assertEquals(3, as.getEducations().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getEducations());
    assertEquals(3, as.getEmployments().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getEmployments());
    assertEquals(3, as.getFundings().getFundingGroup().size());
    assertGroupContainsOnlyPublicElements(as.getFundings());
    assertTrue(as.getPeerReviews().getPeerReviewGroup().isEmpty());
    assertEquals(3, as.getWorks().getWorkGroup().size());
    assertGroupContainsOnlyPublicElements(as.getWorks());
    assertEquals(3, as.getDistinctions().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getDistinctions());
    assertEquals(3, as.getInvitedPositions().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getInvitedPositions());
    assertEquals(3, as.getMemberships().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getMemberships());
    assertEquals(3, as.getQualifications().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getQualifications());
    assertEquals(3, as.getServices().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getServices());
    // Assert it filters works
    as = getActivitiesSummaryElement();
    setVisibility(as.getWorks(), Visibility.LIMITED, Visibility.PRIVATE, Visibility.LIMITED);
    publicAPISecurityManagerV3.filter(as);
    assertEquals(3, as.getEducations().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getEducations());
    assertEquals(3, as.getEmployments().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getEmployments());
    assertEquals(3, as.getFundings().getFundingGroup().size());
    assertGroupContainsOnlyPublicElements(as.getFundings());
    assertEquals(3, as.getPeerReviews().getPeerReviewGroup().size());
    assertGroupContainsOnlyPublicElements(as.getPeerReviews());
    assertTrue(as.getWorks().getWorkGroup().isEmpty());
    assertEquals(3, as.getDistinctions().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getDistinctions());
    assertEquals(3, as.getInvitedPositions().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getInvitedPositions());
    assertEquals(3, as.getMemberships().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getMemberships());
    assertEquals(3, as.getQualifications().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getQualifications());
    assertEquals(3, as.getServices().getSummaries().size());
    assertContainerContainsOnlyPublicElements(as.getServices());
}
Also used : ActivitiesSummary(org.orcid.jaxb.model.v3.dev1.record.summary.ActivitiesSummary) Test(org.junit.Test)

Example 18 with Funding

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

the class PeerReviewManagerReadOnlyImpl method groupPeerReviews.

/**
 * Generate a grouped list of peer reviews with the given list of peer reviews
 *
 * @param peerReviews
 *          The list of peer reviews to group
 * @param justPublic
 *          Specify if we want to group only the public elements in the given list
 * @return PeerReviews element with the PeerReviewSummary elements grouped
 */
@Override
public PeerReviews groupPeerReviews(List<PeerReviewSummary> peerReviews, boolean justPublic) {
    ActivitiesGroupGenerator groupGenerator = new ActivitiesGroupGenerator();
    PeerReviews result = new PeerReviews();
    for (PeerReviewSummary peerReview : peerReviews) {
        if (justPublic && !peerReview.getVisibility().equals(org.orcid.jaxb.model.v3.dev1.common.Visibility.PUBLIC)) {
        // If it is just public and the funding is not public, just
        // ignore it
        } else {
            groupGenerator.group(peerReview);
        }
    }
    List<ActivitiesGroup> groups = groupGenerator.getGroups();
    for (ActivitiesGroup group : groups) {
        Set<GroupAble> groupKeys = group.getGroupKeys();
        Set<GroupableActivity> activities = group.getActivities();
        PeerReviewGroup peerReviewGroup = new PeerReviewGroup();
        // Fill the peer review groups with the external identifiers
        if (groupKeys == null || groupKeys.isEmpty()) {
            // Initialize the ids as an empty list
            peerReviewGroup.getIdentifiers().getExternalIdentifier();
        } else {
            for (GroupAble groupKey : groupKeys) {
                PeerReviewGroupKey key = (PeerReviewGroupKey) groupKey;
                ExternalID id = new ExternalID();
                // TODO: this is not nice
                id.setType(PeerReviewGroupKey.KEY_NAME);
                id.setValue(key.getGroupId());
                peerReviewGroup.getIdentifiers().getExternalIdentifier().add(id);
            }
        }
        // Fill the peer review group with the list of activities
        for (GroupableActivity activity : activities) {
            PeerReviewSummary peerReviewSummary = (PeerReviewSummary) activity;
            peerReviewGroup.getPeerReviewSummary().add(peerReviewSummary);
        }
        // Sort the peer reviews
        Collections.sort(peerReviewGroup.getPeerReviewSummary(), new GroupableActivityComparator());
        result.getPeerReviewGroup().add(peerReviewGroup);
    }
    return result;
}
Also used : PeerReviewGroupKey(org.orcid.jaxb.model.v3.dev1.record.summary.PeerReviewGroupKey) PeerReviewGroup(org.orcid.jaxb.model.v3.dev1.record.summary.PeerReviewGroup) PeerReviews(org.orcid.jaxb.model.v3.dev1.record.summary.PeerReviews) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) GroupableActivity(org.orcid.jaxb.model.v3.dev1.record.GroupableActivity) GroupableActivityComparator(org.orcid.core.utils.v3.activities.GroupableActivityComparator) PeerReviewSummary(org.orcid.jaxb.model.v3.dev1.record.summary.PeerReviewSummary) ActivitiesGroupGenerator(org.orcid.core.utils.v3.activities.ActivitiesGroupGenerator) ActivitiesGroup(org.orcid.core.utils.v3.activities.ActivitiesGroup) GroupAble(org.orcid.jaxb.model.v3.dev1.record.GroupAble)

Example 19 with Funding

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

the class ProfileFundingManagerReadOnlyImpl method groupFundings.

/**
 * Generate a grouped list of funding with the given list of funding
 *
 * @param fundings
 *          The list of fundings to group
 * @param justPublic
 *          Specify if we want to group only the public elements in the given list
 * @return Fundings element with the FundingSummary elements grouped
 */
@Override
public Fundings groupFundings(List<FundingSummary> fundings, boolean justPublic) {
    ActivitiesGroupGenerator groupGenerator = new ActivitiesGroupGenerator();
    Fundings result = new Fundings();
    for (FundingSummary funding : fundings) {
        if (justPublic && !funding.getVisibility().equals(org.orcid.jaxb.model.v3.dev1.common.Visibility.PUBLIC)) {
        // If it is just public and the funding is not public, just
        // ignore it
        } else {
            groupGenerator.group(funding);
        }
    }
    List<ActivitiesGroup> groups = groupGenerator.getGroups();
    for (ActivitiesGroup group : groups) {
        Set<GroupAble> externalIdentifiers = group.getGroupKeys();
        Set<GroupableActivity> activities = group.getActivities();
        FundingGroup fundingGroup = new FundingGroup();
        // Fill the funding groups with the external identifiers
        if (externalIdentifiers == null || externalIdentifiers.isEmpty()) {
            // Initialize the ids as an empty list
            fundingGroup.getIdentifiers().getExternalIdentifier();
        } else {
            for (GroupAble extId : externalIdentifiers) {
                ExternalID fundingExtId = (ExternalID) extId;
                fundingGroup.getIdentifiers().getExternalIdentifier().add(fundingExtId.clone());
            }
        }
        // Fill the funding group with the list of activities
        for (GroupableActivity activity : activities) {
            FundingSummary fundingSummary = (FundingSummary) activity;
            fundingGroup.getFundingSummary().add(fundingSummary);
        }
        // Sort the fundings
        Collections.sort(fundingGroup.getFundingSummary(), new GroupableActivityComparator());
        result.getFundingGroup().add(fundingGroup);
    }
    return result;
}
Also used : Fundings(org.orcid.jaxb.model.v3.dev1.record.summary.Fundings) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) FundingSummary(org.orcid.jaxb.model.v3.dev1.record.summary.FundingSummary) GroupableActivity(org.orcid.jaxb.model.v3.dev1.record.GroupableActivity) ActivitiesGroupGenerator(org.orcid.core.utils.v3.activities.ActivitiesGroupGenerator) ActivitiesGroup(org.orcid.core.utils.v3.activities.ActivitiesGroup) GroupAble(org.orcid.jaxb.model.v3.dev1.record.GroupAble) FundingGroup(org.orcid.jaxb.model.v3.dev1.record.summary.FundingGroup) GroupableActivityComparator(org.orcid.core.utils.v3.activities.GroupableActivityComparator)

Example 20 with Funding

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

the class ActivityValidator method validateFunding.

public void validateFunding(Funding funding, SourceEntity sourceEntity, boolean createFlag, boolean isApiRequest, Visibility originalVisibility) {
    FundingTitle title = funding.getTitle();
    if (title == null || title.getTitle() == null || StringUtils.isEmpty(title.getTitle().getContent())) {
        throw new ActivityTitleValidationException();
    }
    // translated title language code
    if (title != null && title.getTranslatedTitle() != null && !PojoUtil.isEmpty(title.getTranslatedTitle().getContent())) {
        // If translated title language code is null or invalid
        if (PojoUtil.isEmpty(title.getTranslatedTitle().getLanguageCode()) || !Arrays.stream(SiteConstants.AVAILABLE_ISO_LANGUAGES).anyMatch(title.getTranslatedTitle().getLanguageCode()::equals)) {
            Map<String, String> params = new HashMap<String, String>();
            String values = Arrays.stream(SiteConstants.AVAILABLE_ISO_LANGUAGES).collect(Collectors.joining(", "));
            params.put("type", "translated title -> language code");
            params.put("values", values);
            throw new ActivityTypeValidationException(params);
        }
    }
    if (isApiRequest) {
        if (funding.getExternalIdentifiers() == null || funding.getExternalIdentifiers().getExternalIdentifier() == null || funding.getExternalIdentifiers().getExternalIdentifier().isEmpty()) {
            throw new ActivityIdentifierValidationException();
        }
    }
    if (funding.getAmount() != null) {
        Amount amount = funding.getAmount();
        if (PojoUtil.isEmpty(amount.getCurrencyCode()) && !PojoUtil.isEmpty(amount.getContent())) {
            throw new OrcidValidationException("Please specify a currency code");
        } else if (!PojoUtil.isEmpty(amount.getCurrencyCode()) && PojoUtil.isEmpty(amount.getContent())) {
            throw new OrcidValidationException("Please specify an amount or remove the amount tag");
        }
    }
    if (funding.getPutCode() != null && createFlag) {
        Map<String, String> params = new HashMap<String, String>();
        if (sourceEntity != null) {
            params.put("clientName", sourceEntity.getSourceName());
        }
        throw new InvalidPutCodeException(params);
    }
    if (isApiRequest) {
        validateDisambiguatedOrg(funding);
    }
    // Check that we are not changing the visibility
    if (isApiRequest && !createFlag) {
        Visibility updatedVisibility = funding.getVisibility();
        validateVisibilityDoesntChange(updatedVisibility, originalVisibility);
    }
    externalIDValidator.validateFunding(funding.getExternalIdentifiers());
}
Also used : ActivityTitleValidationException(org.orcid.core.exception.ActivityTitleValidationException) HashMap(java.util.HashMap) InvalidPutCodeException(org.orcid.core.exception.InvalidPutCodeException) Amount(org.orcid.jaxb.model.v3.dev1.common.Amount) OrcidValidationException(org.orcid.core.exception.OrcidValidationException) ActivityTypeValidationException(org.orcid.core.exception.ActivityTypeValidationException) Visibility(org.orcid.jaxb.model.v3.dev1.common.Visibility) FundingTitle(org.orcid.jaxb.model.v3.dev1.record.FundingTitle) TransientNonEmptyString(org.orcid.jaxb.model.v3.dev1.common.TransientNonEmptyString) ActivityIdentifierValidationException(org.orcid.core.exception.ActivityIdentifierValidationException)

Aggregations

Test (org.junit.Test)76 Funding (org.orcid.jaxb.model.v3.dev1.record.Funding)72 FundingSummary (org.orcid.jaxb.model.v3.dev1.record.summary.FundingSummary)24 Response (javax.ws.rs.core.Response)23 DBUnitTest (org.orcid.test.DBUnitTest)23 ActivitiesSummary (org.orcid.jaxb.model.v3.dev1.record.summary.ActivitiesSummary)20 ExternalID (org.orcid.jaxb.model.v3.dev1.record.ExternalID)15 EducationSummary (org.orcid.jaxb.model.v3.dev1.record.summary.EducationSummary)12 EmploymentSummary (org.orcid.jaxb.model.v3.dev1.record.summary.EmploymentSummary)12 PeerReviewSummary (org.orcid.jaxb.model.v3.dev1.record.summary.PeerReviewSummary)12 WorkSummary (org.orcid.jaxb.model.v3.dev1.record.summary.WorkSummary)12 DistinctionSummary (org.orcid.jaxb.model.v3.dev1.record.summary.DistinctionSummary)10 InvitedPositionSummary (org.orcid.jaxb.model.v3.dev1.record.summary.InvitedPositionSummary)10 MembershipSummary (org.orcid.jaxb.model.v3.dev1.record.summary.MembershipSummary)10 QualificationSummary (org.orcid.jaxb.model.v3.dev1.record.summary.QualificationSummary)10 ServiceSummary (org.orcid.jaxb.model.v3.dev1.record.summary.ServiceSummary)10 Url (org.orcid.jaxb.model.v3.dev1.common.Url)9 FundingContributor (org.orcid.jaxb.model.v3.dev1.record.FundingContributor)9 ArrayList (java.util.ArrayList)8 ExternalIDs (org.orcid.jaxb.model.v3.dev1.record.ExternalIDs)8