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());
}
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;
}
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();
}
}
}
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);
}
}
}
}
}
}
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);
}
}
Aggregations