Search in sources :

Example 6 with Activity

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

Example 7 with Activity

use of org.orcid.jaxb.model.v3.dev1.record.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.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 8 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(ActivitiesContainer actContainer) {
    if (actContainer != null) {
        Collection<? extends Activity> activities = actContainer.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();
                }
            }
            actContainer.setLastModifiedDate(new LastModifiedDate(latest));
        }
    }
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) LastModifiedDate(org.orcid.jaxb.model.v3.dev1.common.LastModifiedDate) GroupableActivity(org.orcid.jaxb.model.v3.dev1.record.GroupableActivity) Activity(org.orcid.jaxb.model.v3.dev1.record.Activity)

Example 9 with Activity

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

Example 10 with Activity

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

the class JpaJaxbNotificationAdapterTest method testToNotificationPermissionEntity.

@Test
public void testToNotificationPermissionEntity() {
    NotificationPermission notification = new NotificationPermission();
    notification.setNotificationType(NotificationType.PERMISSION);
    String authorizationUrlString = "https://orcid.org/oauth/authorize?client_id=APP-U4UKCNSSIM1OCVQY&amp;response_type=code&amp;scope=/orcid-works/create&amp;redirect_uri=http://somethirdparty.com";
    AuthorizationUrl url = new AuthorizationUrl();
    notification.setAuthorizationUrl(url);
    notification.setNotificationIntro("This is the intro");
    notification.setNotificationSubject("This is the subject");
    Source source = new Source();
    notification.setSource(source);
    SourceClientId clientId = new SourceClientId();
    source.setSourceClientId(clientId);
    clientId.setPath("APP-5555-5555-5555-5555");
    url.setUri(authorizationUrlString);
    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 NotificationAddItemsEntity);
    NotificationAddItemsEntity addActivitiesEntity = (NotificationAddItemsEntity) notificationEntity;
    assertNotNull(notificationEntity);
    assertEquals(org.orcid.jaxb.model.notification_v2.NotificationType.PERMISSION, notificationEntity.getNotificationType());
    assertEquals(authorizationUrlString, addActivitiesEntity.getAuthorizationUrl());
    assertEquals(notification.getNotificationIntro(), notificationEntity.getNotificationIntro());
    assertEquals(notification.getNotificationSubject(), notificationEntity.getNotificationSubject());
    // Source
    assertNull(notificationEntity.getSourceId());
    assertNull(notificationEntity.getClientSourceId());
    assertNull(notificationEntity.getElementSourceId());
    Set<NotificationItemEntity> activityEntities = addActivitiesEntity.getNotificationItems();
    assertNotNull(activityEntities);
    assertEquals(1, activityEntities.size());
    NotificationItemEntity activityEntity = activityEntities.iterator().next();
    assertEquals(org.orcid.jaxb.model.notification.permission_v2.ItemType.WORK, activityEntity.getItemType());
    assertEquals("Latest Research Article", activityEntity.getItemName());
    assertEquals("DOI", activityEntity.getExternalIdType());
    assertEquals("1234/abc123", activityEntity.getExternalIdValue());
}
Also used : AuthorizationUrl(org.orcid.jaxb.model.v3.dev1.notification.permission.AuthorizationUrl) NotificationAddItemsEntity(org.orcid.persistence.jpa.entities.NotificationAddItemsEntity) 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) NotificationPermission(org.orcid.jaxb.model.v3.dev1.notification.permission.NotificationPermission) Items(org.orcid.jaxb.model.v3.dev1.notification.permission.Items) NotificationItemEntity(org.orcid.persistence.jpa.entities.NotificationItemEntity) NotificationEntity(org.orcid.persistence.jpa.entities.NotificationEntity) Source(org.orcid.jaxb.model.v3.dev1.common.Source) Test(org.junit.Test)

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