Search in sources :

Example 31 with Group

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

the class ActivitiesGroup method belongsToGroup.

@Deprecated
public /**
 * This method is only used by tests to confirm accuracy of ActivitiesGroupGenerator and should not be used in production
 *
 * @param activity
 * @return
 */
boolean belongsToGroup(GroupableActivity activity) {
    boolean isPeerReview = PeerReviewSummary.class.isAssignableFrom(activity.getClass());
    // If there are no grouping keys
    if (groupKeys == null || groupKeys.isEmpty()) {
        if (isPeerReview) {
            return false;
        } else {
            if (activity.getExternalIdentifiers() == null || activity.getExternalIdentifiers().getExternalIdentifier() == null || activity.getExternalIdentifiers().getExternalIdentifier().isEmpty()) {
                // If the activity doesn't have any external identifier, check if the activity is in the group
                if (activities.contains(activity))
                    return true;
                else
                    return false;
            } else {
                // If any of the activities pass the grouping validation, the activity must belong to other group
                for (GroupAble extId : activity.getExternalIdentifiers().getExternalIdentifier()) {
                    if (extId.isGroupAble())
                        return false;
                }
                // If none of the activities pass the groupings validation, so, lets check if the group actually contains the activity
                if (activities.contains(activity))
                    return true;
                else
                    return false;
            }
        }
    }
    if (isPeerReview) {
        PeerReviewSummary peerReviewSummary = (PeerReviewSummary) activity;
        PeerReviewGroupKey prgk = new PeerReviewGroupKey();
        prgk.setGroupId(peerReviewSummary.getGroupId());
        if (prgk.isGroupAble()) {
            if (groupKeys.contains(prgk)) {
                return true;
            }
        }
    } else {
        // Check existing keys
        ExternalIdentifiersContainer container = activity.getExternalIdentifiers();
        if (container != null) {
            List<? extends GroupAble> extIds = (List<? extends GroupAble>) container.getExternalIdentifier();
            for (GroupAble extId : extIds) {
                // First check keys restrictions
                if (extId.isGroupAble()) {
                    // If any of the keys already exists on this group, return true
                    if (containsKey(extId))
                        return true;
                }
            }
        }
    }
    return false;
}
Also used : PeerReviewGroupKey(org.orcid.jaxb.model.v3.dev1.record.summary.PeerReviewGroupKey) PeerReviewSummary(org.orcid.jaxb.model.v3.dev1.record.summary.PeerReviewSummary) ExternalIdentifiersContainer(org.orcid.jaxb.model.v3.dev1.record.ExternalIdentifiersContainer) List(java.util.List) GroupAble(org.orcid.jaxb.model.v3.dev1.record.GroupAble)

Example 32 with Group

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

the class Api3_0_Dev1LastModifiedDatesHelper method calculateLastModified.

public static void calculateLastModified(GroupsContainer groupsContainer) {
    if (groupsContainer.retrieveGroups() != null && !groupsContainer.retrieveGroups().isEmpty()) {
        List<? extends Group> groupsRc1 = new ArrayList<>(groupsContainer.retrieveGroups());
        List<Group> groups = new ArrayList<>(groupsContainer.retrieveGroups());
        if (groupsRc1.get(0).getActivities() != null && !groupsRc1.get(0).getActivities().isEmpty()) {
            LastModifiedDate latest = null;
            for (Group group : groups) {
                calculateLastModified(group);
                if (group.getLastModifiedDate() != null && group.getLastModifiedDate().after(latest)) {
                    latest = group.getLastModifiedDate();
                }
            }
            groupsContainer.setLastModifiedDate(latest);
        }
    }
}
Also used : Group(org.orcid.jaxb.model.v3.dev1.record.Group) LastModifiedDate(org.orcid.jaxb.model.v3.dev1.common.LastModifiedDate) ArrayList(java.util.ArrayList)

Example 33 with Group

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

the class ActivitiesGroupGeneratorBaseTest method checkExternalIdentifiers.

/**
 * Checks that all the external identifiers in the activity are contained in the group external identifiers
 */
public void checkExternalIdentifiers(GroupableActivity activity, ActivitiesGroup group) {
    ExternalIdentifiersContainer extIdsContainer = activity.getExternalIdentifiers();
    List<? extends GroupAble> extIds = extIdsContainer.getExternalIdentifier();
    Set<GroupAble> groupExtIds = group.getGroupKeys();
    for (Object o : extIds) {
        GroupAble extId = (GroupAble) o;
        // If the ext id pass the grouping validation, it must be in the ext ids list
        if (extId.isGroupAble())
            assertTrue(groupExtIds.contains(extId));
    }
}
Also used : ExternalIdentifiersContainer(org.orcid.jaxb.model.v3.dev1.record.ExternalIdentifiersContainer) GroupAble(org.orcid.jaxb.model.v3.dev1.record.GroupAble)

Example 34 with Group

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

the class ActivitiesGroupGenerator_GroupingFundingsTest method groupFundings_DontGroupFundingsWithoutExtIds_Test.

/**
 * Test that two groups without ext ids dont get grouped
 */
@Test
public void groupFundings_DontGroupFundingsWithoutExtIds_Test() {
    ActivitiesGroupGenerator generator = new ActivitiesGroupGenerator();
    Map<String, FundingSummary> fundings = generateFundings();
    // Group the first group
    FundingSummary funding8 = fundings.get("funding-8");
    FundingSummary funding9 = fundings.get("funding-9");
    generator.group(funding8);
    generator.group(funding9);
    List<ActivitiesGroup> groups = generator.getGroups();
    assertNotNull(groups);
    assertEquals(2, groups.size());
    // Check there are two activities in each group
    assertEquals(1, groups.get(0).getActivities().size());
    assertEquals(1, groups.get(1).getActivities().size());
    // Check there are five external ids in each group
    assertEquals(0, groups.get(0).getGroupKeys().size());
    assertEquals(0, groups.get(1).getGroupKeys().size());
    checkActivityIsOnGroups(funding8, groups);
    checkActivityIsOnGroups(funding9, groups);
    checkActivitiesDontBelongsToTheSameGroup(groups, funding8, funding9);
}
Also used : FundingSummary(org.orcid.jaxb.model.v3.dev1.record.summary.FundingSummary) Test(org.junit.Test)

Example 35 with Group

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

the class ActivitiesGroupGenerator_GroupingFundingsTest method groupFundings_2GroupsOf2Fundings_Test.

/**
 * Test grouping (funding-1 and funding-2) and (funding-5 and funding-6)
 */
@Test
public void groupFundings_2GroupsOf2Fundings_Test() {
    ActivitiesGroupGenerator generator = new ActivitiesGroupGenerator();
    Map<String, FundingSummary> fundings = generateFundings();
    FundingSummary funding1 = fundings.get("funding-1");
    FundingSummary funding2 = fundings.get("funding-2");
    FundingSummary funding5 = fundings.get("funding-5");
    FundingSummary funding6 = fundings.get("funding-6");
    generator.group(funding1);
    generator.group(funding2);
    generator.group(funding5);
    generator.group(funding6);
    List<ActivitiesGroup> groups = generator.getGroups();
    assertNotNull(groups);
    assertEquals(2, groups.size());
    // Check there are two activities in each group
    assertEquals(2, groups.get(0).getActivities().size());
    assertEquals(2, groups.get(1).getActivities().size());
    // Check there are five external ids in each group
    assertEquals(5, groups.get(0).getGroupKeys().size());
    assertEquals(5, groups.get(1).getGroupKeys().size());
    // Check each funding
    checkActivityIsOnGroups(funding1, groups);
    checkActivityIsOnGroups(funding2, groups);
    checkActivityIsOnGroups(funding5, groups);
    checkActivityIsOnGroups(funding6, groups);
    // Check funding1 and funding2 are in the same group
    checkActivitiesBelongsToTheSameGroup(groups, funding1, funding2);
    // Check funding6 and funding7 are in the same group
    checkActivitiesBelongsToTheSameGroup(groups, funding5, funding6);
    // Check fundings are not mixed
    checkActivitiesDontBelongsToTheSameGroup(groups, funding1, funding5);
    checkActivitiesDontBelongsToTheSameGroup(groups, funding1, funding6);
    checkActivitiesDontBelongsToTheSameGroup(groups, funding2, funding5);
    checkActivitiesDontBelongsToTheSameGroup(groups, funding2, funding6);
}
Also used : FundingSummary(org.orcid.jaxb.model.v3.dev1.record.summary.FundingSummary) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)47 WorkSummary (org.orcid.jaxb.model.v3.dev1.record.summary.WorkSummary)26 WorkGroup (org.orcid.jaxb.model.v3.dev1.record.summary.WorkGroup)18 FundingSummary (org.orcid.jaxb.model.v3.dev1.record.summary.FundingSummary)17 BaseTest (org.orcid.core.BaseTest)16 ExternalID (org.orcid.jaxb.model.v3.dev1.record.ExternalID)15 PeerReviewSummary (org.orcid.jaxb.model.v3.dev1.record.summary.PeerReviewSummary)14 ActivitiesSummary (org.orcid.jaxb.model.v3.dev1.record.summary.ActivitiesSummary)13 PeerReviewGroup (org.orcid.jaxb.model.v3.dev1.record.summary.PeerReviewGroup)13 Works (org.orcid.jaxb.model.v3.dev1.record.summary.Works)13 FundingGroup (org.orcid.jaxb.model.v3.dev1.record.summary.FundingGroup)12 DBUnitTest (org.orcid.test.DBUnitTest)11 ArrayList (java.util.ArrayList)10 Response (javax.ws.rs.core.Response)10 Url (org.orcid.jaxb.model.v3.dev1.common.Url)8 GroupIdRecord (org.orcid.jaxb.model.v3.dev1.groupid.GroupIdRecord)8 GroupableActivity (org.orcid.jaxb.model.v3.dev1.record.GroupableActivity)8 PeerReview (org.orcid.jaxb.model.v3.dev1.record.PeerReview)8 ClientResponse (com.sun.jersey.api.client.ClientResponse)7 TransientNonEmptyString (org.orcid.jaxb.model.v3.dev1.common.TransientNonEmptyString)7