Search in sources :

Example 26 with Group

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

the class GroupIdRecordManagerTest method testCreateDuplicateGroupIdRecords.

@Test
public void testCreateDuplicateGroupIdRecords() {
    GroupIdRecord g1 = new GroupIdRecord();
    g1.setDescription("Description");
    g1.setGroupId("orcid-generated:valid-group-id#1");
    g1.setName("Group # " + System.currentTimeMillis());
    g1.setType("publisher");
    // Create the first one
    g1 = groupIdRecordManager.createGroupIdRecord(g1);
    Long putCode = g1.getPutCode();
    assertNotNull(g1.getSource());
    assertNotNull(g1.getSource().getSourceClientId());
    assertEquals(CLIENT_ID, g1.getSource().getSourceClientId().getPath());
    // Try to create a duplicate
    try {
        g1.setPutCode(null);
        g1 = groupIdRecordManager.createGroupIdRecord(g1);
        fail();
    } catch (DuplicatedGroupIdRecordException e) {
    } catch (Exception e) {
        fail();
    }
    // Try to create a UPPER duplicate
    try {
        g1.setPutCode(null);
        g1.setGroupId("orcid-generated:VALID-GROUP-ID#1");
        g1 = groupIdRecordManager.createGroupIdRecord(g1);
        fail();
    } catch (DuplicatedGroupIdRecordException e) {
    } catch (Exception e) {
        fail();
    }
    // Try to create a duplicate mixed cases
    try {
        g1.setPutCode(null);
        g1.setGroupId("orcid-generated:VaLiD-GrOuP-Id#1");
        g1 = groupIdRecordManager.createGroupIdRecord(g1);
        fail();
    } catch (DuplicatedGroupIdRecordException e) {
    } catch (Exception e) {
        fail();
    }
    // Create a different one
    g1.setPutCode(null);
    g1.setGroupId("orcid-generated:valid-group-id#2");
    GroupIdRecord g2 = groupIdRecordManager.createGroupIdRecord(g1);
    assertNotNull(g2);
    assertNotNull(g2.getPutCode());
    assertTrue(!g2.getPutCode().equals(putCode));
    assertEquals("orcid-generated:valid-group-id#2", g2.getGroupId());
    assertNotNull(g2.getSource());
    assertNotNull(g2.getSource().getSourceClientId());
    assertEquals(CLIENT_ID, g2.getSource().getSourceClientId().getPath());
    // Try to create again a duplicate for any of the two existing
    try {
        g1.setPutCode(null);
        g1.setGroupId("orcid-generated:VaLiD-GrOuP-Id#1");
        g1 = groupIdRecordManager.createGroupIdRecord(g1);
        fail();
    } catch (DuplicatedGroupIdRecordException e) {
    } catch (Exception e) {
        fail();
    }
    try {
        g1.setPutCode(null);
        g1.setGroupId("orcid-generated:VaLiD-GrOuP-Id#2");
        g1 = groupIdRecordManager.createGroupIdRecord(g1);
        fail();
    } catch (DuplicatedGroupIdRecordException e) {
    } catch (Exception e) {
        fail();
    }
    groupIdRecordManager.deleteGroupIdRecord(putCode);
    groupIdRecordManager.deleteGroupIdRecord(g2.getPutCode());
}
Also used : GroupIdRecord(org.orcid.jaxb.model.v3.dev1.groupid.GroupIdRecord) DuplicatedGroupIdRecordException(org.orcid.core.exception.DuplicatedGroupIdRecordException) InvalidPutCodeException(org.orcid.core.exception.InvalidPutCodeException) OrcidValidationException(org.orcid.core.exception.OrcidValidationException) DuplicatedGroupIdRecordException(org.orcid.core.exception.DuplicatedGroupIdRecordException) GroupIdRecordNotFoundException(org.orcid.core.exception.GroupIdRecordNotFoundException) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 27 with Group

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

the class ClientManagerReadOnlyTest method getClient.

private Client getClient(String randomString) {
    Client client = new Client();
    client.setAllowAutoDeprecate(true);
    client.setPersistentTokensEnabled(true);
    client.setClientType(ClientType.CREATOR);
    client.setDescription("description " + randomString);
    client.setGroupProfileId("group-profile-id " + randomString);
    client.setId(randomString);
    client.setName("client-name " + randomString);
    client.setWebsite("client-website " + randomString);
    client.setAuthenticationProviderId("authentication-provider-id " + randomString);
    Set<ClientRedirectUri> clientRedirectUris = new HashSet<ClientRedirectUri>();
    ClientRedirectUri rUri1 = new ClientRedirectUri();
    Set<ScopePathType> scopes1 = new HashSet<ScopePathType>();
    scopes1.add(ScopePathType.ACTIVITIES_READ_LIMITED);
    rUri1.setPredefinedClientScopes(scopes1);
    rUri1.setRedirectUri("redirect-uri-1 " + randomString);
    rUri1.setRedirectUriType("type-1 " + randomString);
    rUri1.setUriActType("uri-act-type-1 " + randomString);
    rUri1.setUriGeoArea("uri-geo-area-1 " + randomString);
    ClientRedirectUri rUri2 = new ClientRedirectUri();
    Set<ScopePathType> scopes2 = new HashSet<ScopePathType>();
    scopes2.add(ScopePathType.ACTIVITIES_UPDATE);
    rUri2.setPredefinedClientScopes(scopes2);
    rUri2.setRedirectUri("redirect-uri-2 " + randomString);
    rUri2.setRedirectUriType("type-2 " + randomString);
    rUri2.setUriActType("uri-act-type-2 " + randomString);
    rUri2.setUriGeoArea("uri-geo-area-2 " + randomString);
    ClientRedirectUri rUri3 = new ClientRedirectUri();
    Set<ScopePathType> scopes3 = new HashSet<ScopePathType>();
    scopes3.add(ScopePathType.AFFILIATIONS_CREATE);
    rUri3.setPredefinedClientScopes(scopes3);
    rUri3.setRedirectUri("redirect-uri-3 " + randomString);
    rUri3.setRedirectUriType("type-3 " + randomString);
    rUri3.setUriActType("uri-act-type-3 " + randomString);
    rUri3.setUriGeoArea("uri-geo-area-3 " + randomString);
    clientRedirectUris.add(rUri1);
    clientRedirectUris.add(rUri2);
    clientRedirectUris.add(rUri3);
    client.setClientRedirectUris(clientRedirectUris);
    return client;
}
Also used : ClientRedirectUri(org.orcid.jaxb.model.v3.dev1.client.ClientRedirectUri) ScopePathType(org.orcid.jaxb.model.message.ScopePathType) Client(org.orcid.jaxb.model.v3.dev1.client.Client) HashSet(java.util.HashSet)

Example 28 with Group

use of org.orcid.jaxb.model.v3.dev1.record.Group 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();
        }
    }
}
Also used : ExternalIDs(org.orcid.jaxb.model.v3.dev1.record.ExternalIDs) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) GroupableActivity(org.orcid.jaxb.model.v3.dev1.record.GroupableActivity)

Example 29 with Group

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

the class SourceUtils method setSourceName.

public void setSourceName(ActivitiesSummary as) {
    if (as == null) {
        return;
    }
    if (as.getEducations() != null) {
        Educations educations = as.getEducations();
        List<EducationSummary> list = educations.getSummaries();
        if (list != null) {
            for (EducationSummary summary : list) {
                setSourceName(summary);
            }
        }
    }
    if (as.getEmployments() != null) {
        Employments employments = as.getEmployments();
        List<EmploymentSummary> list = employments.getSummaries();
        if (list != null) {
            for (EmploymentSummary summary : list) {
                setSourceName(summary);
            }
        }
    }
    if (as.getFundings() != null) {
        Fundings fundings = as.getFundings();
        List<FundingGroup> groups = fundings.getFundingGroup();
        if (groups != null) {
            for (FundingGroup group : groups) {
                List<FundingSummary> summaryList = group.getFundingSummary();
                if (summaryList != null) {
                    for (FundingSummary summary : summaryList) {
                        setSourceName(summary);
                    }
                }
            }
        }
    }
    if (as.getPeerReviews() != null) {
        PeerReviews peerReviews = as.getPeerReviews();
        List<PeerReviewGroup> groups = peerReviews.getPeerReviewGroup();
        if (groups != null) {
            for (PeerReviewGroup group : groups) {
                List<PeerReviewSummary> summaryList = group.getPeerReviewSummary();
                if (summaryList != null) {
                    for (PeerReviewSummary summary : summaryList) {
                        setSourceName(summary);
                    }
                }
            }
        }
    }
    if (as.getWorks() != null) {
        Works works = as.getWorks();
        List<WorkGroup> groups = works.getWorkGroup();
        if (groups != null) {
            for (WorkGroup group : groups) {
                List<WorkSummary> summaryList = group.getWorkSummary();
                if (summaryList != null) {
                    for (WorkSummary summary : summaryList) {
                        setSourceName(summary);
                    }
                }
            }
        }
    }
}
Also used : PeerReviewGroup(org.orcid.jaxb.model.v3.dev1.record.summary.PeerReviewGroup) Fundings(org.orcid.jaxb.model.v3.dev1.record.summary.Fundings) PeerReviews(org.orcid.jaxb.model.v3.dev1.record.summary.PeerReviews) FundingGroup(org.orcid.jaxb.model.v3.dev1.record.summary.FundingGroup) Employments(org.orcid.jaxb.model.v3.dev1.record.summary.Employments) WorkGroup(org.orcid.jaxb.model.v3.dev1.record.summary.WorkGroup) WorkSummary(org.orcid.jaxb.model.v3.dev1.record.summary.WorkSummary) EducationSummary(org.orcid.jaxb.model.v3.dev1.record.summary.EducationSummary) PeerReviewSummary(org.orcid.jaxb.model.v3.dev1.record.summary.PeerReviewSummary) Educations(org.orcid.jaxb.model.v3.dev1.record.summary.Educations) FundingSummary(org.orcid.jaxb.model.v3.dev1.record.summary.FundingSummary) EmploymentSummary(org.orcid.jaxb.model.v3.dev1.record.summary.EmploymentSummary) Works(org.orcid.jaxb.model.v3.dev1.record.summary.Works)

Example 30 with Group

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

Aggregations

Test (org.junit.Test)47 WorkSummary (org.orcid.jaxb.model.v3.dev1.record.summary.WorkSummary)26 WorkGroup (org.orcid.jaxb.model.v3.dev1.record.summary.WorkGroup)18 FundingSummary (org.orcid.jaxb.model.v3.dev1.record.summary.FundingSummary)17 BaseTest (org.orcid.core.BaseTest)16 ExternalID (org.orcid.jaxb.model.v3.dev1.record.ExternalID)15 PeerReviewSummary (org.orcid.jaxb.model.v3.dev1.record.summary.PeerReviewSummary)14 ActivitiesSummary (org.orcid.jaxb.model.v3.dev1.record.summary.ActivitiesSummary)13 PeerReviewGroup (org.orcid.jaxb.model.v3.dev1.record.summary.PeerReviewGroup)13 Works (org.orcid.jaxb.model.v3.dev1.record.summary.Works)13 FundingGroup (org.orcid.jaxb.model.v3.dev1.record.summary.FundingGroup)12 DBUnitTest (org.orcid.test.DBUnitTest)11 ArrayList (java.util.ArrayList)10 Response (javax.ws.rs.core.Response)10 Url (org.orcid.jaxb.model.v3.dev1.common.Url)8 GroupIdRecord (org.orcid.jaxb.model.v3.dev1.groupid.GroupIdRecord)8 GroupableActivity (org.orcid.jaxb.model.v3.dev1.record.GroupableActivity)8 PeerReview (org.orcid.jaxb.model.v3.dev1.record.PeerReview)8 ClientResponse (com.sun.jersey.api.client.ClientResponse)7 TransientNonEmptyString (org.orcid.jaxb.model.v3.dev1.common.TransientNonEmptyString)7