use of org.orcid.jaxb.model.record_v2.GroupableActivity in project ORCID-Source by ORCID.
the class OrcidSecurityManagerImpl method filterExternalIdentifiers.
/**
* Filter the group external identifiers to match the external identifiers
* that belongs to the activities it have after filtering
*
* @param group
* The group we want to filter the external identifiers
*/
private void filterExternalIdentifiers(Group group) {
// Iterate over every external identifier and check if it is still
// present in the list of filtered elements
ExternalIDs extIds = group.getIdentifiers();
Iterator<ExternalID> extIdsIt = extIds.getExternalIdentifier().iterator();
while (extIdsIt.hasNext()) {
ExternalID extId = extIdsIt.next();
boolean found = false;
for (GroupableActivity summary : group.getActivities()) {
if (summary.getExternalIdentifiers() != null) {
if (summary.getExternalIdentifiers().getExternalIdentifier().contains(extId)) {
found = true;
break;
}
}
}
// If the ext id is not found, remove it from the list of ext ids
if (!found) {
extIdsIt.remove();
}
}
}
use of org.orcid.jaxb.model.record_v2.GroupableActivity 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.record_v2.GroupableActivity in project ORCID-Source by ORCID.
the class Api2_0_LastModifiedDatesHelper 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);
}
}
use of org.orcid.jaxb.model.record_v2.GroupableActivity 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.record_v2.GroupableActivity 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....
}
Aggregations