Search in sources :

Example 1 with GroupAble

use of org.orcid.jaxb.model.record_v2.GroupAble 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.common_v2.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.record.summary_v2.Fundings) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) FundingSummary(org.orcid.jaxb.model.record.summary_v2.FundingSummary) GroupableActivity(org.orcid.jaxb.model.record_v2.GroupableActivity) ActivitiesGroupGenerator(org.orcid.core.utils.activities.ActivitiesGroupGenerator) ActivitiesGroup(org.orcid.core.utils.activities.ActivitiesGroup) GroupAble(org.orcid.jaxb.model.record_v2.GroupAble) FundingGroup(org.orcid.jaxb.model.record.summary_v2.FundingGroup) GroupableActivityComparator(org.orcid.core.utils.activities.GroupableActivityComparator)

Example 2 with GroupAble

use of org.orcid.jaxb.model.record_v2.GroupAble 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.common_v2.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.record.summary_v2.PeerReviewGroupKey) PeerReviewGroup(org.orcid.jaxb.model.record.summary_v2.PeerReviewGroup) PeerReviews(org.orcid.jaxb.model.record.summary_v2.PeerReviews) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) GroupableActivity(org.orcid.jaxb.model.record_v2.GroupableActivity) GroupableActivityComparator(org.orcid.core.utils.activities.GroupableActivityComparator) PeerReviewSummary(org.orcid.jaxb.model.record.summary_v2.PeerReviewSummary) ActivitiesGroupGenerator(org.orcid.core.utils.activities.ActivitiesGroupGenerator) ActivitiesGroup(org.orcid.core.utils.activities.ActivitiesGroup) GroupAble(org.orcid.jaxb.model.record_v2.GroupAble)

Example 3 with GroupAble

use of org.orcid.jaxb.model.record_v2.GroupAble in project ORCID-Source by ORCID.

the class ActivitiesGroup method merge.

public void merge(ActivitiesGroup group) {
    Set<GroupableActivity> otherActivities = group.getActivities();
    Set<GroupAble> otherKeys = group.getGroupKeys();
    //The incoming groups should always contain at least one key, we should not merge activities without keys
    if (otherKeys.isEmpty())
        throw new IllegalArgumentException("Unable to merge a group without external identifiers");
    //Merge group keys
    for (GroupAble otherKey : otherKeys) {
        if (!groupKeys.contains(otherKey))
            groupKeys.add(otherKey);
    }
    //Merge activities
    for (GroupableActivity activity : otherActivities) {
        //We assume the activity is not already there, anyway it is a set
        activities.add(activity);
    }
}
Also used : GroupableActivity(org.orcid.jaxb.model.record_v2.GroupableActivity) GroupAble(org.orcid.jaxb.model.record_v2.GroupAble)

Example 4 with GroupAble

use of org.orcid.jaxb.model.record_v2.GroupAble 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.record.summary_v2.PeerReviewGroupKey) PeerReviewSummary(org.orcid.jaxb.model.record.summary_v2.PeerReviewSummary) ExternalIdentifiersContainer(org.orcid.jaxb.model.record_v2.ExternalIdentifiersContainer) List(java.util.List) GroupAble(org.orcid.jaxb.model.record_v2.GroupAble)

Example 5 with GroupAble

use of org.orcid.jaxb.model.record_v2.GroupAble in project ORCID-Source by ORCID.

the class ActivitiesGroupGenerator method group.

public void group(GroupableActivity activity) {
    if (groups.isEmpty()) {
        //If it is the first activity, create a new group for it
        ActivitiesGroup newGroup = new ActivitiesGroup(activity);
        groups.add(newGroup);
        for (GroupAble g : newGroup.getGroupKeys()) {
            lookup.put(g, newGroup);
        }
    } else {
        //If it is not the first activity, check which groups it belongs to
        List<ActivitiesGroup> belongsTo = new ArrayList<ActivitiesGroup>();
        ActivitiesGroup thisGroup = new ActivitiesGroup(activity);
        for (GroupAble g : thisGroup.getGroupKeys()) {
            if (lookup.containsKey(g))
                belongsTo.add(lookup.get(g));
        }
        //If it doesnt belong to any group, create a new group for it
        if (belongsTo.isEmpty()) {
            ActivitiesGroup newGroup = new ActivitiesGroup(activity);
            groups.add(newGroup);
            for (GroupAble g : newGroup.getGroupKeys()) {
                lookup.put(g, newGroup);
            }
        } else {
            //Get the first group it belongs to
            ActivitiesGroup firstGroup = belongsTo.get(0);
            firstGroup.add(activity);
            //If it belongs to other groups, merge them into the first one
            if (belongsTo.size() > 1) {
                for (int i = 1; i < belongsTo.size(); i++) {
                    //Merge the group
                    if (firstGroup != belongsTo.get(i)) {
                        firstGroup.merge(belongsTo.get(i));
                        //Remove it from the list of groups
                        groups.remove(belongsTo.get(i));
                    }
                }
            }
            for (GroupAble g : thisGroup.getGroupKeys()) {
                lookup.put(g, firstGroup);
            }
        }
    }
//TODO: make sure this orders correctly
//TODO: look at v1.2 post/put work....
}
Also used : ArrayList(java.util.ArrayList) GroupAble(org.orcid.jaxb.model.record_v2.GroupAble)

Aggregations

GroupAble (org.orcid.jaxb.model.record_v2.GroupAble)7 GroupableActivity (org.orcid.jaxb.model.record_v2.GroupableActivity)4 ActivitiesGroup (org.orcid.core.utils.activities.ActivitiesGroup)3 ActivitiesGroupGenerator (org.orcid.core.utils.activities.ActivitiesGroupGenerator)3 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)3 GroupableActivityComparator (org.orcid.core.utils.activities.GroupableActivityComparator)2 PeerReviewGroupKey (org.orcid.jaxb.model.record.summary_v2.PeerReviewGroupKey)2 PeerReviewSummary (org.orcid.jaxb.model.record.summary_v2.PeerReviewSummary)2 ExternalIdentifiersContainer (org.orcid.jaxb.model.record_v2.ExternalIdentifiersContainer)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 FundingGroup (org.orcid.jaxb.model.record.summary_v2.FundingGroup)1 FundingSummary (org.orcid.jaxb.model.record.summary_v2.FundingSummary)1 Fundings (org.orcid.jaxb.model.record.summary_v2.Fundings)1 PeerReviewGroup (org.orcid.jaxb.model.record.summary_v2.PeerReviewGroup)1 PeerReviews (org.orcid.jaxb.model.record.summary_v2.PeerReviews)1 WorkGroup (org.orcid.jaxb.model.record.summary_v2.WorkGroup)1 WorkSummary (org.orcid.jaxb.model.record.summary_v2.WorkSummary)1 Works (org.orcid.jaxb.model.record.summary_v2.Works)1