Search in sources :

Example 11 with Activity

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

the class Api3_0_Dev1LastModifiedDatesHelper method calculateLastModified.

public static void calculateLastModified(Group group) {
    Collection<? extends GroupableActivity> activities = group.getActivities();
    if (activities != null && !activities.isEmpty()) {
        Iterator<? extends GroupableActivity> activitiesIterator = activities.iterator();
        LastModifiedDate latest = null;
        while (activitiesIterator.hasNext()) {
            GroupableActivity activity = activitiesIterator.next();
            if (activity.getLastModifiedDate() != null && activity.getLastModifiedDate().after(latest)) {
                latest = activity.getLastModifiedDate();
            }
        }
        group.setLastModifiedDate(latest);
    }
}
Also used : LastModifiedDate(org.orcid.jaxb.model.v3.dev1.common.LastModifiedDate) GroupableActivity(org.orcid.jaxb.model.v3.dev1.record.GroupableActivity)

Example 12 with Activity

use of org.orcid.jaxb.model.v3.dev1.record.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.v3.dev1.record.GroupAble)

Example 13 with Activity

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

the class JpaJaxbNotificationAdapterTest method testToNotificationAmendedEntity.

@Test
public void testToNotificationAmendedEntity() {
    NotificationAmended notification = new NotificationAmended();
    notification.setNotificationType(NotificationType.AMENDED);
    Source source = new Source();
    notification.setSource(source);
    SourceClientId clientId = new SourceClientId();
    source.setSourceClientId(clientId);
    clientId.setPath("APP-5555-5555-5555-5555");
    Items activities = new Items();
    notification.setItems(activities);
    Item activity = new Item();
    activities.getItems().add(activity);
    activity.setItemType(ItemType.WORK);
    activity.setItemName("Latest Research Article");
    ExternalID extId = new ExternalID();
    activity.setExternalIdentifier(extId);
    extId.setType("doi");
    extId.setValue("1234/abc123");
    NotificationEntity notificationEntity = jpaJaxbNotificationAdapter.toNotificationEntity(notification);
    assertTrue(notificationEntity instanceof NotificationAmendedEntity);
    NotificationAmendedEntity notificationAmendedEntity = (NotificationAmendedEntity) notificationEntity;
    assertNotNull(notificationEntity);
    assertEquals(org.orcid.jaxb.model.notification_v2.NotificationType.AMENDED, notificationEntity.getNotificationType());
    // Source
    assertNull(notificationAmendedEntity.getSourceId());
    assertNull(notificationAmendedEntity.getClientSourceId());
    assertNull(notificationAmendedEntity.getElementSourceId());
}
Also used : NotificationAmendedEntity(org.orcid.persistence.jpa.entities.NotificationAmendedEntity) Item(org.orcid.jaxb.model.v3.dev1.notification.permission.Item) SourceClientId(org.orcid.jaxb.model.v3.dev1.common.SourceClientId) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) Items(org.orcid.jaxb.model.v3.dev1.notification.permission.Items) NotificationEntity(org.orcid.persistence.jpa.entities.NotificationEntity) Source(org.orcid.jaxb.model.v3.dev1.common.Source) NotificationAmended(org.orcid.jaxb.model.v3.dev1.notification.amended.NotificationAmended) Test(org.junit.Test)

Example 14 with Activity

use of org.orcid.jaxb.model.v3.dev1.record.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.v3.dev1.common.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.v3.dev1.record.summary.WorkGroup) WorkSummary(org.orcid.jaxb.model.v3.dev1.record.summary.WorkSummary) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) GroupableActivity(org.orcid.jaxb.model.v3.dev1.record.GroupableActivity) ActivitiesGroupGenerator(org.orcid.core.utils.v3.activities.ActivitiesGroupGenerator) Works(org.orcid.jaxb.model.v3.dev1.record.summary.Works) ActivitiesGroup(org.orcid.core.utils.v3.activities.ActivitiesGroup) GroupAble(org.orcid.jaxb.model.v3.dev1.record.GroupAble)

Example 15 with Activity

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

the class ActivitiesGroupGeneratorBaseTest method checkActivitiesBelongsToTheSameGroup.

/**
 * Check that the given activitys belongs to the same group in a list of given groups
 */
public void checkActivitiesBelongsToTheSameGroup(List<ActivitiesGroup> groups, GroupableActivity... activities) {
    GroupableActivity first = activities[0];
    assertNotNull(first);
    ActivitiesGroup theGroup = getGroupThatContainsActivity(groups, first);
    assertNotNull(theGroup);
    for (GroupableActivity activity : activities) {
        assertTrue(theGroup.belongsToGroup(activity));
    }
}
Also used : GroupableActivity(org.orcid.jaxb.model.v3.dev1.record.GroupableActivity)

Aggregations

Test (org.junit.Test)8 GroupableActivity (org.orcid.jaxb.model.v3.dev1.record.GroupableActivity)8 ExternalID (org.orcid.jaxb.model.v3.dev1.record.ExternalID)7 GroupAble (org.orcid.jaxb.model.v3.dev1.record.GroupAble)7 FundingSummary (org.orcid.jaxb.model.v3.dev1.record.summary.FundingSummary)4 ActivitiesGroup (org.orcid.core.utils.v3.activities.ActivitiesGroup)3 ActivitiesGroupGenerator (org.orcid.core.utils.v3.activities.ActivitiesGroupGenerator)3 PeerReviewSummary (org.orcid.jaxb.model.v3.dev1.record.summary.PeerReviewSummary)3 WorkSummary (org.orcid.jaxb.model.v3.dev1.record.summary.WorkSummary)3 ClientResponse (com.sun.jersey.api.client.ClientResponse)2 BaseTest (org.orcid.core.BaseTest)2 GroupableActivityComparator (org.orcid.core.utils.v3.activities.GroupableActivityComparator)2 LastModifiedDate (org.orcid.jaxb.model.v3.dev1.common.LastModifiedDate)2 Source (org.orcid.jaxb.model.v3.dev1.common.Source)2 SourceClientId (org.orcid.jaxb.model.v3.dev1.common.SourceClientId)2 Title (org.orcid.jaxb.model.v3.dev1.common.Title)2 Url (org.orcid.jaxb.model.v3.dev1.common.Url)2 OrcidError (org.orcid.jaxb.model.v3.dev1.error.OrcidError)2 Item (org.orcid.jaxb.model.v3.dev1.notification.permission.Item)2 Items (org.orcid.jaxb.model.v3.dev1.notification.permission.Items)2