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);
}
}
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;
}
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));
}
}
}
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));
}
}
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&response_type=code&scope=/orcid-works/create&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());
}
Aggregations