use of org.orcid.jaxb.model.record_v2.Group in project ORCID-Source by ORCID.
the class PublicProfileVisibilityTest method peerReviewPrivacyTest.
@Test
public void peerReviewPrivacyTest() throws InterruptedException, JSONException, URISyntaxException {
// Create peer review group
String accessToken = getAccessToken(getScopes(ScopePathType.PERSON_READ_LIMITED, ScopePathType.PERSON_UPDATE, ScopePathType.ACTIVITIES_READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE));
List<GroupIdRecord> groups = createGroupIds();
assertNotNull(groups);
assertTrue(groups.size() > 0);
GroupIdRecord g1 = groups.get(0);
// Create peer review
long time = System.currentTimeMillis();
PeerReview peerReview = new PeerReview();
peerReview.setGroupId(g1.getGroupId());
ExternalIDs extIds = new ExternalIDs();
peerReview.setExternalIdentifiers(extIds);
peerReview.getExternalIdentifiers().getExternalIdentifier().clear();
ExternalID wExtId = new ExternalID();
wExtId.setValue("Work Id " + time);
wExtId.setType(WorkExternalIdentifierType.AGR.value());
wExtId.setRelationship(Relationship.SELF);
peerReview.getExternalIdentifiers().getExternalIdentifier().add(wExtId);
Organization organization = new Organization();
organization.setName("My org name " + System.currentTimeMillis());
OrganizationAddress address = new OrganizationAddress();
address.setCity("Imagination city");
address.setCountry(Iso3166Country.US);
organization.setAddress(address);
peerReview.setOrganization(organization);
peerReview.setRole(Role.CHAIR);
peerReview.setType(PeerReviewType.EVALUATION);
peerReview.setCompletionDate(new FuzzyDate(new Year(2016), new Month(1), new Day(1)));
ClientResponse postResponse = memberV2ApiClient.createPeerReviewXml(this.getUser1OrcidId(), peerReview, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
ClientResponse getResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
peerReview = getResponse.getEntity(PeerReview.class);
showMyOrcidPage();
changePeerReviewVisibility(g1.getName(), Visibility.PRIVATE);
try {
//Verify it doesn't appear in the public page
showPublicProfilePage(getUser1OrcidId());
peerReviewAppearsInPublicPage(g1.getName());
fail();
} catch (Exception e) {
}
showMyOrcidPage();
changePeerReviewVisibility(g1.getName(), Visibility.LIMITED);
try {
//Verify it doesn't appear in the public page
showPublicProfilePage(getUser1OrcidId());
peerReviewAppearsInPublicPage(g1.getName());
fail();
} catch (Exception e) {
}
showMyOrcidPage();
changePeerReviewVisibility(g1.getName(), Visibility.PUBLIC);
showPublicProfilePage(getUser1OrcidId());
peerReviewAppearsInPublicPage(g1.getName());
// Rollback
ClientResponse deleteResponse = memberV2ApiClient.deletePeerReviewXml(this.getUser1OrcidId(), peerReview.getPutCode(), accessToken);
assertNotNull(deleteResponse);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
use of org.orcid.jaxb.model.record_v2.Group in project ORCID-Source by ORCID.
the class ProfileFundingManagerTest method testGroupFundings.
@Test
public void testGroupFundings() {
/**
* They should be grouped as
*
* Group 1: Funding 1 + Funding 4
* Group 2: Funding 2 + Funding 5
* Group 3: Funding 3
* Group 4: Funding 6
* */
FundingSummary s1 = getFundingSummary("Funding 1", "ext-id-1", Visibility.PUBLIC);
FundingSummary s2 = getFundingSummary("Funding 2", "ext-id-2", Visibility.LIMITED);
FundingSummary s3 = getFundingSummary("Funding 3", "ext-id-3", Visibility.PRIVATE);
FundingSummary s4 = getFundingSummary("Funding 4", "ext-id-1", Visibility.PRIVATE);
FundingSummary s5 = getFundingSummary("Funding 5", "ext-id-2", Visibility.PUBLIC);
FundingSummary s6 = getFundingSummary("Funding 6", "ext-id-4", Visibility.PRIVATE);
List<FundingSummary> fundingList1 = Arrays.asList(s1, s2, s3, s4, s5, s6);
Fundings fundings1 = profileFundingManager.groupFundings(fundingList1, false);
assertNotNull(fundings1);
assertEquals(4, fundings1.getFundingGroup().size());
//Group 1 have all with ext-id-1
assertEquals(2, fundings1.getFundingGroup().get(0).getFundingSummary().size());
assertEquals(1, fundings1.getFundingGroup().get(0).getIdentifiers().getExternalIdentifier().size());
assertEquals("ext-id-1", fundings1.getFundingGroup().get(0).getIdentifiers().getExternalIdentifier().get(0).getValue());
//Group 2 have all with ext-id-2
assertEquals(2, fundings1.getFundingGroup().get(1).getFundingSummary().size());
assertEquals(1, fundings1.getFundingGroup().get(1).getIdentifiers().getExternalIdentifier().size());
assertEquals("ext-id-2", fundings1.getFundingGroup().get(1).getIdentifiers().getExternalIdentifier().get(0).getValue());
//Group 3 have ext-id-3
assertEquals(1, fundings1.getFundingGroup().get(2).getFundingSummary().size());
assertEquals(1, fundings1.getFundingGroup().get(2).getIdentifiers().getExternalIdentifier().size());
assertEquals("ext-id-3", fundings1.getFundingGroup().get(2).getIdentifiers().getExternalIdentifier().get(0).getValue());
//Group 4 have ext-id-4
assertEquals(1, fundings1.getFundingGroup().get(3).getFundingSummary().size());
assertEquals(1, fundings1.getFundingGroup().get(3).getIdentifiers().getExternalIdentifier().size());
assertEquals("ext-id-4", fundings1.getFundingGroup().get(3).getIdentifiers().getExternalIdentifier().get(0).getValue());
FundingSummary s7 = getFundingSummary("Funding 7", "ext-id-4", Visibility.PRIVATE);
//Add ext-id-3 to work 7, so, it join group 3 and group 4 in a single group
ExternalID extId = new ExternalID();
extId.setRelationship(Relationship.SELF);
extId.setType("doi");
extId.setUrl(new Url("http://orcid.org"));
extId.setValue("ext-id-3");
s7.getExternalIdentifiers().getExternalIdentifier().add(extId);
/**
* Now, they should be grouped as
*
* Group 1: Funding 1 + Funding 4
* Group 2: Funding 2 + Funding 5
* Group 3: Funding 3 + Funding 6 + Funding 7
* */
List<FundingSummary> fundingsList2 = Arrays.asList(s1, s2, s3, s4, s5, s6, s7);
Fundings fundings2 = profileFundingManager.groupFundings(fundingsList2, false);
assertNotNull(fundings2);
assertEquals(3, fundings2.getFundingGroup().size());
//Group 1 have all with ext-id-1
assertEquals(2, fundings2.getFundingGroup().get(0).getFundingSummary().size());
assertEquals(1, fundings2.getFundingGroup().get(0).getIdentifiers().getExternalIdentifier().size());
assertEquals("ext-id-1", fundings2.getFundingGroup().get(0).getIdentifiers().getExternalIdentifier().get(0).getValue());
//Group 2 have all with ext-id-2
assertEquals(2, fundings2.getFundingGroup().get(1).getFundingSummary().size());
assertEquals(1, fundings2.getFundingGroup().get(1).getIdentifiers().getExternalIdentifier().size());
assertEquals("ext-id-2", fundings2.getFundingGroup().get(1).getIdentifiers().getExternalIdentifier().get(0).getValue());
//Group 3 have all with ext-id-3 and ext-id-4
assertEquals(3, fundings2.getFundingGroup().get(2).getFundingSummary().size());
assertEquals(2, fundings2.getFundingGroup().get(2).getIdentifiers().getExternalIdentifier().size());
assertThat(fundings2.getFundingGroup().get(2).getIdentifiers().getExternalIdentifier().get(0).getValue(), anyOf(is("ext-id-3"), is("ext-id-4")));
assertThat(fundings2.getFundingGroup().get(2).getIdentifiers().getExternalIdentifier().get(1).getValue(), anyOf(is("ext-id-3"), is("ext-id-4")));
}
use of org.orcid.jaxb.model.record_v2.Group 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.record_v2.Group 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.Group 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