Search in sources :

Example 16 with Activity

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

the class WorkManagerReadOnlyImpl method groupWorks.

/**
     * Generate a grouped list of works with the given list of works
     * 
     * @param works
     *            The list of works to group
     * @param justPublic
     *            Specify if we want to group only the public elements in the
     *            given list
     * @return Works element with the WorkSummary elements grouped
     */
@Override
public Works groupWorks(List<WorkSummary> works, boolean justPublic) {
    ActivitiesGroupGenerator groupGenerator = new ActivitiesGroupGenerator();
    Works result = new Works();
    // Group all works
    for (WorkSummary work : works) {
        if (justPublic && !work.getVisibility().equals(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC)) {
        // If it is just public and the work is not public, just ignore
        // it
        } else {
            groupGenerator.group(work);
        }
    }
    List<ActivitiesGroup> groups = groupGenerator.getGroups();
    for (ActivitiesGroup group : groups) {
        Set<GroupAble> externalIdentifiers = group.getGroupKeys();
        Set<GroupableActivity> activities = group.getActivities();
        WorkGroup workGroup = new WorkGroup();
        // Fill the work groups with the external identifiers
        if (externalIdentifiers == null || externalIdentifiers.isEmpty()) {
            // Initialize the ids as an empty list
            workGroup.getIdentifiers().getExternalIdentifier();
        } else {
            for (GroupAble extId : externalIdentifiers) {
                ExternalID workExtId = (ExternalID) extId;
                workGroup.getIdentifiers().getExternalIdentifier().add(workExtId.clone());
            }
        }
        // Fill the work group with the list of activities
        for (GroupableActivity activity : activities) {
            WorkSummary workSummary = (WorkSummary) activity;
            workGroup.getWorkSummary().add(workSummary);
        }
        // Sort the works
        workGroup.getWorkSummary().sort(WorkComparators.ALL);
        result.getWorkGroup().add(workGroup);
    }
    // Sort the groups!
    result.getWorkGroup().sort(WorkComparators.GROUP);
    return result;
}
Also used : WorkGroup(org.orcid.jaxb.model.record.summary_v2.WorkGroup) WorkSummary(org.orcid.jaxb.model.record.summary_v2.WorkSummary) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) GroupableActivity(org.orcid.jaxb.model.record_v2.GroupableActivity) ActivitiesGroupGenerator(org.orcid.core.utils.activities.ActivitiesGroupGenerator) Works(org.orcid.jaxb.model.record.summary_v2.Works) ActivitiesGroup(org.orcid.core.utils.activities.ActivitiesGroup) GroupAble(org.orcid.jaxb.model.record_v2.GroupAble)

Example 17 with Activity

use of org.orcid.jaxb.model.record_v2.Activity 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.record_v2.ExternalIdentifiersContainer) GroupAble(org.orcid.jaxb.model.record_v2.GroupAble)

Example 18 with Activity

use of org.orcid.jaxb.model.record_v2.Activity 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 19 with Activity

use of org.orcid.jaxb.model.record_v2.Activity 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)

Example 20 with Activity

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

the class Api2_0_LastModifiedDatesHelper method calculateLastModified.

public static void calculateLastModified(ActivitiesContainer actContainerV2) {
    if (actContainerV2 != null) {
        Collection<? extends Activity> activities = actContainerV2.retrieveActivities();
        if (activities != null && !activities.isEmpty()) {
            Iterator<? extends Activity> activitiesIterator = activities.iterator();
            XMLGregorianCalendar latest = activitiesIterator.next().getLastModifiedDate().getValue();
            while (activitiesIterator.hasNext()) {
                Activity activity = activitiesIterator.next();
                if (latest.compare(activity.getLastModifiedDate().getValue()) == -1) {
                    latest = activity.getLastModifiedDate().getValue();
                }
            }
            actContainerV2.setLastModifiedDate(new LastModifiedDate(latest));
        }
    }
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) LastModifiedDate(org.orcid.jaxb.model.common_v2.LastModifiedDate) Activity(org.orcid.jaxb.model.record_v2.Activity) GroupableActivity(org.orcid.jaxb.model.record_v2.GroupableActivity)

Aggregations

GroupableActivity (org.orcid.jaxb.model.record_v2.GroupableActivity)8 GroupAble (org.orcid.jaxb.model.record_v2.GroupAble)7 Test (org.junit.Test)6 PeerReviewSummary (org.orcid.jaxb.model.record.summary_v2.PeerReviewSummary)6 FundingGroup (org.orcid.jaxb.model.record.summary_v2.FundingGroup)5 FundingSummary (org.orcid.jaxb.model.record.summary_v2.FundingSummary)5 Fundings (org.orcid.jaxb.model.record.summary_v2.Fundings)5 PeerReviewGroup (org.orcid.jaxb.model.record.summary_v2.PeerReviewGroup)5 PeerReviews (org.orcid.jaxb.model.record.summary_v2.PeerReviews)5 WorkGroup (org.orcid.jaxb.model.record.summary_v2.WorkGroup)5 WorkSummary (org.orcid.jaxb.model.record.summary_v2.WorkSummary)5 Works (org.orcid.jaxb.model.record.summary_v2.Works)5 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)5 ClientResponse (com.sun.jersey.api.client.ClientResponse)4 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)4 EducationSummary (org.orcid.jaxb.model.record.summary_v2.EducationSummary)4 Educations (org.orcid.jaxb.model.record.summary_v2.Educations)4 EmploymentSummary (org.orcid.jaxb.model.record.summary_v2.EmploymentSummary)4 Employments (org.orcid.jaxb.model.record.summary_v2.Employments)4 Address (org.orcid.jaxb.model.record_v2.Address)4