use of org.orcid.jaxb.model.v3.dev1.search.Result in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_GeneralTest method testSearchByQuery.
@Test
public void testSearchByQuery() {
Search search = new Search();
Result result = new Result();
result.setOrcidIdentifier(new OrcidIdentifier("some-orcid-id"));
search.getResults().add(result);
OrcidSearchManager orcidSearchManager = Mockito.mock(OrcidSearchManagerImpl.class);
Mockito.when(orcidSearchManager.findOrcidIds(Matchers.<Map<String, List<String>>>any())).thenReturn(search);
OrcidSecurityManager orcidSecurityManager = Mockito.mock(OrcidSecurityManagerImpl.class);
Mockito.doNothing().when(orcidSecurityManager).checkScopes(Mockito.any(ScopePathType.class));
MemberV3ApiServiceDelegatorImpl delegator = new MemberV3ApiServiceDelegatorImpl();
ReflectionTestUtils.setField(delegator, "orcidSearchManager", orcidSearchManager);
ReflectionTestUtils.setField(delegator, "orcidSecurityManager", orcidSecurityManager);
Response response = delegator.searchByQuery(new HashMap<String, List<String>>());
assertNotNull(response);
assertNotNull(response.getEntity());
assertTrue(response.getEntity() instanceof Search);
assertEquals(1, ((Search) response.getEntity()).getResults().size());
assertEquals("some-orcid-id", ((Search) response.getEntity()).getResults().get(0).getOrcidIdentifier().getPath());
}
use of org.orcid.jaxb.model.v3.dev1.search.Result in project ORCID-Source by ORCID.
the class PeerReviewManagerReadOnlyImpl method groupPeerReviews.
/**
* Generate a grouped list of peer reviews with the given list of peer reviews
*
* @param peerReviews
* The list of peer reviews to group
* @param justPublic
* Specify if we want to group only the public elements in the given list
* @return PeerReviews element with the PeerReviewSummary elements grouped
*/
@Override
public PeerReviews groupPeerReviews(List<PeerReviewSummary> peerReviews, boolean justPublic) {
ActivitiesGroupGenerator groupGenerator = new ActivitiesGroupGenerator();
PeerReviews result = new PeerReviews();
for (PeerReviewSummary peerReview : peerReviews) {
if (justPublic && !peerReview.getVisibility().equals(org.orcid.jaxb.model.v3.dev1.common.Visibility.PUBLIC)) {
// If it is just public and the funding is not public, just
// ignore it
} else {
groupGenerator.group(peerReview);
}
}
List<ActivitiesGroup> groups = groupGenerator.getGroups();
for (ActivitiesGroup group : groups) {
Set<GroupAble> groupKeys = group.getGroupKeys();
Set<GroupableActivity> activities = group.getActivities();
PeerReviewGroup peerReviewGroup = new PeerReviewGroup();
// Fill the peer review groups with the external identifiers
if (groupKeys == null || groupKeys.isEmpty()) {
// Initialize the ids as an empty list
peerReviewGroup.getIdentifiers().getExternalIdentifier();
} else {
for (GroupAble groupKey : groupKeys) {
PeerReviewGroupKey key = (PeerReviewGroupKey) groupKey;
ExternalID id = new ExternalID();
// TODO: this is not nice
id.setType(PeerReviewGroupKey.KEY_NAME);
id.setValue(key.getGroupId());
peerReviewGroup.getIdentifiers().getExternalIdentifier().add(id);
}
}
// Fill the peer review group with the list of activities
for (GroupableActivity activity : activities) {
PeerReviewSummary peerReviewSummary = (PeerReviewSummary) activity;
peerReviewGroup.getPeerReviewSummary().add(peerReviewSummary);
}
// Sort the peer reviews
Collections.sort(peerReviewGroup.getPeerReviewSummary(), new GroupableActivityComparator());
result.getPeerReviewGroup().add(peerReviewGroup);
}
return result;
}
use of org.orcid.jaxb.model.v3.dev1.search.Result in project ORCID-Source by ORCID.
the class ProfileFundingManagerReadOnlyImpl method groupFundings.
/**
* Generate a grouped list of funding with the given list of funding
*
* @param fundings
* The list of fundings to group
* @param justPublic
* Specify if we want to group only the public elements in the given list
* @return Fundings element with the FundingSummary elements grouped
*/
@Override
public Fundings groupFundings(List<FundingSummary> fundings, boolean justPublic) {
ActivitiesGroupGenerator groupGenerator = new ActivitiesGroupGenerator();
Fundings result = new Fundings();
for (FundingSummary funding : fundings) {
if (justPublic && !funding.getVisibility().equals(org.orcid.jaxb.model.v3.dev1.common.Visibility.PUBLIC)) {
// If it is just public and the funding is not public, just
// ignore it
} else {
groupGenerator.group(funding);
}
}
List<ActivitiesGroup> groups = groupGenerator.getGroups();
for (ActivitiesGroup group : groups) {
Set<GroupAble> externalIdentifiers = group.getGroupKeys();
Set<GroupableActivity> activities = group.getActivities();
FundingGroup fundingGroup = new FundingGroup();
// Fill the funding groups with the external identifiers
if (externalIdentifiers == null || externalIdentifiers.isEmpty()) {
// Initialize the ids as an empty list
fundingGroup.getIdentifiers().getExternalIdentifier();
} else {
for (GroupAble extId : externalIdentifiers) {
ExternalID fundingExtId = (ExternalID) extId;
fundingGroup.getIdentifiers().getExternalIdentifier().add(fundingExtId.clone());
}
}
// Fill the funding group with the list of activities
for (GroupableActivity activity : activities) {
FundingSummary fundingSummary = (FundingSummary) activity;
fundingGroup.getFundingSummary().add(fundingSummary);
}
// Sort the fundings
Collections.sort(fundingGroup.getFundingSummary(), new GroupableActivityComparator());
result.getFundingGroup().add(fundingGroup);
}
return result;
}
use of org.orcid.jaxb.model.v3.dev1.search.Result in project ORCID-Source by ORCID.
the class BlackBoxBaseV3_0_dev1 method unmarshallFromPath.
public Object unmarshallFromPath(String path, Class<?> type) {
try (Reader reader = new InputStreamReader(getClass().getResourceAsStream(path))) {
Object obj = unmarshall(reader, type);
Object result = null;
if (Address.class.equals(type)) {
result = (Address) obj;
} else if (Education.class.equals(type)) {
result = (Education) obj;
} else if (Employment.class.equals(type)) {
result = (Employment) obj;
} else if (Funding.class.equals(type)) {
result = (Funding) obj;
} else if (Keyword.class.equals(type)) {
result = (Keyword) obj;
} else if (Work.class.equals(type)) {
result = (Work) obj;
} else if (PeerReview.class.equals(type)) {
result = (PeerReview) obj;
} else if (ResearcherUrl.class.equals(type)) {
result = (ResearcherUrl) obj;
} else if (PersonalDetails.class.equals(type)) {
result = (PersonalDetails) obj;
} else if (OtherName.class.equals(type)) {
result = (OtherName) obj;
} else if (PersonExternalIdentifier.class.equals(type)) {
result = (PersonExternalIdentifier) obj;
} else if (Distinction.class.equals(type)) {
result = (Distinction) obj;
} else if (InvitedPosition.class.equals(type)) {
result = (InvitedPosition) obj;
} else if (Membership.class.equals(type)) {
result = (Membership) obj;
} else if (Qualification.class.equals(type)) {
result = (Qualification) obj;
} else if (Service.class.equals(type)) {
result = (Service) obj;
}
return result;
} catch (IOException e) {
throw new RuntimeException("Error reading notification from classpath", e);
}
}
use of org.orcid.jaxb.model.v3.dev1.search.Result in project ORCID-Source by ORCID.
the class WorksTest method testGroupingNormalized.
@Test
public void testGroupingNormalized() throws InterruptedException, JSONException {
long time = System.currentTimeMillis();
String accessTokenForClient1 = getAccessToken();
String accessTokenForClient2 = getAccessToken(getUser1OrcidId(), getUser1Password(), getScopes(ScopePathType.ACTIVITIES_UPDATE, ScopePathType.ACTIVITIES_READ_LIMITED), getClient2ClientId(), getClient2ClientSecret(), getClient2RedirectUri());
// should result in two groups
Work work1 = (Work) unmarshallFromPath("/record_3.0_dev1/samples/read_samples/work-3.0_dev1.xml", Work.class);
work1.setPutCode(null);
work1.setSource(null);
work1.setVisibility(Visibility.PUBLIC);
work1.getExternalIdentifiers().getExternalIdentifier().clear();
org.orcid.jaxb.model.v3.dev1.record.WorkTitle title1 = new org.orcid.jaxb.model.v3.dev1.record.WorkTitle();
title1.setTitle(new Title("Work # 1" + time));
work1.setWorkTitle(title1);
ExternalID wExtId1 = new ExternalID();
wExtId1.setValue("VALUE" + time);
wExtId1.setType(WorkExternalIdentifierType.AGR.value());
wExtId1.setRelationship(Relationship.SELF);
wExtId1.setUrl(new Url("http://orcid.org/work#1"));
work1.getExternalIdentifiers().getExternalIdentifier().clear();
work1.getExternalIdentifiers().getExternalIdentifier().add(wExtId1);
Work work2 = (Work) unmarshallFromPath("/record_3.0_dev1/samples/read_samples/work-3.0_dev1.xml", Work.class);
work2.setPutCode(null);
work2.setSource(null);
work2.setVisibility(Visibility.PUBLIC);
org.orcid.jaxb.model.v3.dev1.record.WorkTitle title2 = new org.orcid.jaxb.model.v3.dev1.record.WorkTitle();
title2.setTitle(new Title("Work # 2" + time));
work2.setWorkTitle(title2);
work2.getExternalIdentifiers().getExternalIdentifier().clear();
ExternalID wExtId2 = new ExternalID();
wExtId2.setValue("value" + time);
wExtId2.setType(WorkExternalIdentifierType.AGR.value());
wExtId2.setRelationship(Relationship.SELF);
wExtId2.setUrl(new Url("http://orcid.org/work#2"));
work2.getExternalIdentifiers().getExternalIdentifier().clear();
work2.getExternalIdentifiers().getExternalIdentifier().add(wExtId2);
Work work3 = (Work) unmarshallFromPath("/record_3.0_dev1/samples/read_samples/work-3.0_dev1.xml", Work.class);
work3.setPutCode(null);
work3.setSource(null);
work3.setVisibility(Visibility.PUBLIC);
org.orcid.jaxb.model.v3.dev1.record.WorkTitle title3 = new org.orcid.jaxb.model.v3.dev1.record.WorkTitle();
title3.setTitle(new Title("Work # 3" + time));
work3.setWorkTitle(title3);
work3.getExternalIdentifiers().getExternalIdentifier().clear();
ExternalID wExtId3 = new ExternalID();
wExtId3.setValue("OtherValue" + time);
wExtId3.setType(WorkExternalIdentifierType.AGR.value());
wExtId3.setRelationship(Relationship.SELF);
wExtId3.setUrl(new Url("http://orcid.org/work#3"));
work3.getExternalIdentifiers().getExternalIdentifier().clear();
work3.getExternalIdentifiers().getExternalIdentifier().add(wExtId3);
// Add the three works
ClientResponse postResponse = memberV3Dev1ApiClient.createWorkXml(this.getUser1OrcidId(), work1, accessTokenForClient1);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
Long putCode1 = getPutCodeFromResponse(postResponse);
postResponse = memberV3Dev1ApiClient.createWorkXml(this.getUser1OrcidId(), work2, accessTokenForClient2);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
Long putCode2 = getPutCodeFromResponse(postResponse);
postResponse = memberV3Dev1ApiClient.createWorkXml(this.getUser1OrcidId(), work3, accessTokenForClient2);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
Long putCode3 = getPutCodeFromResponse(postResponse);
ClientResponse activitiesResponse = memberV3Dev1ApiClient.viewActivities(this.getUser1OrcidId(), accessTokenForClient1);
assertEquals(Response.Status.OK.getStatusCode(), activitiesResponse.getStatus());
ActivitiesSummary activities = activitiesResponse.getEntity(ActivitiesSummary.class);
assertNotNull(activities);
assertFalse(activities.getWorks().getWorkGroup().isEmpty());
WorkGroup work1Group = null;
WorkGroup work2Group = null;
WorkGroup work3Group = null;
boolean work1found = false;
boolean work2found = false;
boolean work3found = false;
for (WorkGroup group : activities.getWorks().getWorkGroup()) {
for (ExternalID id : group.getIdentifiers().getExternalIdentifier()) {
// If it is the ID is the one we are looking for
if (id.getNormalized().getValue().equals("value" + time)) {
for (WorkSummary summary : group.getWorkSummary()) {
String title = summary.getTitle().getTitle().getContent();
if (("Work # 1" + time).equals(title)) {
work1found = true;
work1Group = group;
assertEquals(2, group.getActivities().size());
} else if (("Work # 2" + time).equals(title)) {
work2found = true;
work2Group = group;
assertEquals(2, group.getActivities().size());
} else
fail();
}
} else if (id.getNormalized().getValue().equals("othervalue" + time)) {
for (WorkSummary summary : group.getWorkSummary()) {
String title = summary.getTitle().getTitle().getContent();
if (("Work # 3" + time).equals(title)) {
work3found = true;
work3Group = group;
assertEquals(1, group.getActivities().size());
} else
fail();
}
}
}
}
assertTrue(work1found);
assertTrue(work2found);
assertTrue(work3found);
// Check that work # 1 and Work # 2 are in the same work
assertEquals(work1Group, work2Group);
// Check that work # 3 is not in the same group than group # 1
assertThat(work3Group, not(work1Group));
// Remove all created works
ClientResponse deleteResponse = memberV3Dev1ApiClient.deleteWorkXml(this.getUser1OrcidId(), putCode1, accessTokenForClient1);
assertNotNull(deleteResponse);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
deleteResponse = memberV3Dev1ApiClient.deleteWorkXml(this.getUser1OrcidId(), putCode2, accessTokenForClient2);
assertNotNull(deleteResponse);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
deleteResponse = memberV3Dev1ApiClient.deleteWorkXml(this.getUser1OrcidId(), putCode3, accessTokenForClient2);
assertNotNull(deleteResponse);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Aggregations