Search in sources :

Example 46 with Group

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());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ExternalIDs(org.orcid.jaxb.model.record_v2.ExternalIDs) Organization(org.orcid.jaxb.model.common_v2.Organization) GroupIdRecord(org.orcid.jaxb.model.groupid_v2.GroupIdRecord) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) OrganizationAddress(org.orcid.jaxb.model.common_v2.OrganizationAddress) FuzzyDate(org.orcid.jaxb.model.common_v2.FuzzyDate) URISyntaxException(java.net.URISyntaxException) JSONException(org.codehaus.jettison.json.JSONException) Month(org.orcid.jaxb.model.common_v2.Month) Year(org.orcid.jaxb.model.common_v2.Year) Day(org.orcid.jaxb.model.common_v2.Day) PeerReview(org.orcid.jaxb.model.record_v2.PeerReview) Test(org.junit.Test)

Example 47 with Group

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")));
}
Also used : Fundings(org.orcid.jaxb.model.record.summary_v2.Fundings) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) FundingSummary(org.orcid.jaxb.model.record.summary_v2.FundingSummary) Url(org.orcid.jaxb.model.common_v2.Url) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 48 with Group

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));
    }
}
Also used : ExternalIdentifiersContainer(org.orcid.jaxb.model.record_v2.ExternalIdentifiersContainer) GroupAble(org.orcid.jaxb.model.record_v2.GroupAble)

Example 49 with Group

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;
}
Also used : PeerReviewGroupKey(org.orcid.jaxb.model.record.summary_v2.PeerReviewGroupKey) PeerReviewSummary(org.orcid.jaxb.model.record.summary_v2.PeerReviewSummary) ExternalIdentifiersContainer(org.orcid.jaxb.model.record_v2.ExternalIdentifiersContainer) List(java.util.List) GroupAble(org.orcid.jaxb.model.record_v2.GroupAble)

Example 50 with Group

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....
}
Also used : ArrayList(java.util.ArrayList) GroupAble(org.orcid.jaxb.model.record_v2.GroupAble)

Aggregations

Test (org.junit.Test)24 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)19 ArrayList (java.util.ArrayList)14 WorkSummary (org.orcid.jaxb.model.record.summary_v2.WorkSummary)14 WorkGroup (org.orcid.jaxb.model.record.summary_v2.WorkGroup)13 PeerReview (org.orcid.jaxb.model.record_v2.PeerReview)11 ActivitiesSummary (org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary)10 Url (org.orcid.jaxb.model.common_v2.Url)9 Group (org.gluu.oxtrust.model.scim2.Group)8 Group (org.openstack4j.model.identity.v3.Group)8 ClientResponse (com.sun.jersey.api.client.ClientResponse)7 GluuGroup (org.gluu.oxtrust.model.GluuGroup)7 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)7 FundingGroup (org.orcid.jaxb.model.record.summary_v2.FundingGroup)7 GroupAble (org.orcid.jaxb.model.record_v2.GroupAble)7 GroupableActivity (org.orcid.jaxb.model.record_v2.GroupableActivity)7 Response (javax.ws.rs.core.Response)6 FundingSummary (org.orcid.jaxb.model.record.summary_v2.FundingSummary)6 Group (com.google.monitoring.v3.Group)5 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)5