use of org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary in project ORCID-Source by ORCID.
the class ConvertVrc2ToVrc3Test method upgradeActivitiesToVrc3Test.
@Test
public void upgradeActivitiesToVrc3Test() throws JAXBException {
JAXBContext jaxbContext1 = JAXBContext.newInstance(ActivitiesSummary.class);
JAXBContext jaxbContext2 = JAXBContext.newInstance(org.orcid.jaxb.model.record.summary_rc3.ActivitiesSummary.class);
Unmarshaller jaxbUnmarshaller1 = jaxbContext1.createUnmarshaller();
Unmarshaller jaxbUnmarshaller2 = jaxbContext2.createUnmarshaller();
InputStream rc2Stream = ConvertVrc2ToVrc3Test.class.getClassLoader().getResourceAsStream("test-activities-2.0_rc2.xml");
InputStream rc3Stream = ConvertVrc2ToVrc3Test.class.getClassLoader().getResourceAsStream("test-activities-2.0_rc3.xml");
ActivitiesSummary rc2Activities = (ActivitiesSummary) jaxbUnmarshaller1.unmarshal(rc2Stream);
org.orcid.jaxb.model.record.summary_rc3.ActivitiesSummary rc3Activities1 = (org.orcid.jaxb.model.record.summary_rc3.ActivitiesSummary) jaxbUnmarshaller2.unmarshal(rc3Stream);
V2Convertible result = versionConverterV2_0_rc2ToV2_0_rc3.upgrade(new V2Convertible(rc2Activities, "v2_rc2"));
org.orcid.jaxb.model.record.summary_rc3.ActivitiesSummary rc3Activities2 = (org.orcid.jaxb.model.record.summary_rc3.ActivitiesSummary) result.getObjectToConvert();
assertEquals(rc3Activities1, rc3Activities2);
}
use of org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary in project ORCID-Source by ORCID.
the class ConvertVrc3ToVrc4Test method upgradeActivitiesToVrc3Test.
@Test
public void upgradeActivitiesToVrc3Test() throws JAXBException {
JAXBContext jaxbContext1 = JAXBContext.newInstance(ActivitiesSummary.class);
JAXBContext jaxbContext2 = JAXBContext.newInstance(org.orcid.jaxb.model.record.summary_rc4.ActivitiesSummary.class);
Unmarshaller jaxbUnmarshaller1 = jaxbContext1.createUnmarshaller();
Unmarshaller jaxbUnmarshaller2 = jaxbContext2.createUnmarshaller();
InputStream rc3Stream = ConvertVrc3ToVrc4Test.class.getClassLoader().getResourceAsStream("test-activities-2.0_rc3.xml");
InputStream rc4Stream = ConvertVrc3ToVrc4Test.class.getClassLoader().getResourceAsStream("test-activities-2.0_rc4.xml");
ActivitiesSummary rc3Activities = (ActivitiesSummary) jaxbUnmarshaller1.unmarshal(rc3Stream);
org.orcid.jaxb.model.record.summary_rc4.ActivitiesSummary rc4Activities1 = (org.orcid.jaxb.model.record.summary_rc4.ActivitiesSummary) jaxbUnmarshaller2.unmarshal(rc4Stream);
V2Convertible result = versionConverterV2_0_rc3ToV2_0_rc4.upgrade(new V2Convertible(rc3Activities, "v2_rc3"));
org.orcid.jaxb.model.record.summary_rc4.ActivitiesSummary rc4Activities2 = (org.orcid.jaxb.model.record.summary_rc4.ActivitiesSummary) result.getObjectToConvert();
assertEquals(rc4Activities1, rc4Activities2);
}
use of org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary in project ORCID-Source by ORCID.
the class WorksTest method testWorksWithPartOfRelationshipDontGetGrouped.
@Test
public void testWorksWithPartOfRelationshipDontGetGrouped() throws JSONException, InterruptedException, URISyntaxException {
long time = System.currentTimeMillis();
String accessTokenForClient1 = getAccessToken();
String accessTokenForClient2 = getAccessToken(getUser1OrcidId(), getUser1Password(), getScopes(ScopePathType.ACTIVITIES_UPDATE, ScopePathType.ACTIVITIES_READ_LIMITED), getClient2ClientId(), getClient2ClientSecret(), getClient2RedirectUri());
Work work1 = (Work) unmarshallFromPath("/record_2.0/samples/read_samples/work-2.0.xml", Work.class);
work1.setPutCode(null);
work1.setSource(null);
work1.setVisibility(Visibility.PUBLIC);
work1.getExternalIdentifiers().getExternalIdentifier().clear();
org.orcid.jaxb.model.record_v2.WorkTitle title1 = new org.orcid.jaxb.model.record_v2.WorkTitle();
title1.setTitle(new Title("Work # 1" + time));
work1.setWorkTitle(title1);
ExternalID wExtId1 = new ExternalID();
wExtId1.setValue("Work Id " + 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_2.0/samples/read_samples/work-2.0.xml", Work.class);
work2.setPutCode(null);
work2.setSource(null);
work2.setVisibility(Visibility.PUBLIC);
org.orcid.jaxb.model.record_v2.WorkTitle title2 = new org.orcid.jaxb.model.record_v2.WorkTitle();
title2.setTitle(new Title("Work # 2" + time));
work2.setWorkTitle(title2);
work2.getExternalIdentifiers().getExternalIdentifier().clear();
ExternalID wExtId2 = new ExternalID();
wExtId2.setValue("Work Id " + time);
wExtId2.setType(WorkExternalIdentifierType.AGR.value());
wExtId2.setRelationship(Relationship.PART_OF);
wExtId2.setUrl(new Url("http://orcid.org/work#2"));
work2.getExternalIdentifiers().getExternalIdentifier().clear();
work2.getExternalIdentifiers().getExternalIdentifier().add(wExtId2);
Work work3 = (Work) unmarshallFromPath("/record_2.0/samples/read_samples/work-2.0.xml", Work.class);
work3.setPutCode(null);
work3.setSource(null);
work3.setVisibility(Visibility.PUBLIC);
org.orcid.jaxb.model.record_v2.WorkTitle title3 = new org.orcid.jaxb.model.record_v2.WorkTitle();
title3.setTitle(new Title("Work # 3" + time));
work3.setWorkTitle(title3);
work3.getExternalIdentifiers().getExternalIdentifier().clear();
ExternalID wExtId3 = new ExternalID();
wExtId3.setValue("Work Id " + 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 = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), work1, accessTokenForClient1);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
Long putCode1 = getPutCodeFromResponse(postResponse);
postResponse = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), work2, accessTokenForClient1);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
Long putCode2 = getPutCodeFromResponse(postResponse);
postResponse = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), work3, accessTokenForClient2);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
Long putCode3 = getPutCodeFromResponse(postResponse);
ClientResponse activitiesResponse = memberV2ApiClient.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()) {
if (group.getIdentifiers().getExternalIdentifier() == null || group.getIdentifiers().getExternalIdentifier().isEmpty()) {
for (WorkSummary summary : group.getWorkSummary()) {
String title = summary.getTitle().getTitle().getContent();
if (("Work # 2" + time).equals(title)) {
work2found = true;
work2Group = group;
}
}
} else {
for (ExternalID id : group.getIdentifiers().getExternalIdentifier()) {
//If it is the ID is the one we are looking for
if (id.getValue().equals("Work Id " + time)) {
for (WorkSummary summary : group.getWorkSummary()) {
String title = summary.getTitle().getTitle().getContent();
if (("Work # 1" + time).equals(title)) {
work1found = true;
work1Group = group;
} else if (("Work # 3" + time).equals(title)) {
work3found = true;
work3Group = group;
}
}
}
}
}
}
assertTrue(work1found);
assertTrue(work2found);
assertTrue(work3found);
//Check that work # 1 and Work # 3 are in the same work
assertEquals(work1Group, work3Group);
//Check that work # 2 is not in the same group than group # 1
assertThat(work2Group, not(work1Group));
//Remove all created works
ClientResponse deleteResponse = memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), putCode1, accessTokenForClient1);
assertNotNull(deleteResponse);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
deleteResponse = memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), putCode2, accessTokenForClient1);
assertNotNull(deleteResponse);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
deleteResponse = memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), putCode3, accessTokenForClient2);
assertNotNull(deleteResponse);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
use of org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary in project ORCID-Source by ORCID.
the class WorksTest method testWorksWithPartOfRelationshipDontGetGrouped.
@Test
public void testWorksWithPartOfRelationshipDontGetGrouped() throws JSONException, InterruptedException, URISyntaxException {
long time = System.currentTimeMillis();
String accessTokenForClient1 = getAccessToken();
String accessTokenForClient2 = getAccessToken(getUser1OrcidId(), getUser1Password(), getScopes(ScopePathType.ACTIVITIES_UPDATE, ScopePathType.ACTIVITIES_READ_LIMITED), getClient2ClientId(), getClient2ClientSecret(), getClient2RedirectUri());
Work work1 = (Work) unmarshallFromPath("/record_2.0_rc4/samples/work-2.0_rc4.xml", Work.class);
work1.setPutCode(null);
work1.setVisibility(Visibility.PUBLIC);
work1.getExternalIdentifiers().getExternalIdentifier().clear();
org.orcid.jaxb.model.record_rc4.WorkTitle title1 = new org.orcid.jaxb.model.record_rc4.WorkTitle();
title1.setTitle(new Title("Work # 1" + time));
work1.setWorkTitle(title1);
ExternalID wExtId1 = new ExternalID();
wExtId1.setValue("Work Id " + 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_2.0_rc4/samples/work-2.0_rc4.xml", Work.class);
work2.setPutCode(null);
work2.setVisibility(Visibility.PUBLIC);
org.orcid.jaxb.model.record_rc4.WorkTitle title2 = new org.orcid.jaxb.model.record_rc4.WorkTitle();
title2.setTitle(new Title("Work # 2" + time));
work2.setWorkTitle(title2);
work2.getExternalIdentifiers().getExternalIdentifier().clear();
ExternalID wExtId2 = new ExternalID();
wExtId2.setValue("Work Id " + time);
wExtId2.setType(WorkExternalIdentifierType.AGR.value());
wExtId2.setRelationship(Relationship.PART_OF);
wExtId2.setUrl(new Url("http://orcid.org/work#2"));
work2.getExternalIdentifiers().getExternalIdentifier().clear();
work2.getExternalIdentifiers().getExternalIdentifier().add(wExtId2);
Work work3 = (Work) unmarshallFromPath("/record_2.0_rc4/samples/work-2.0_rc4.xml", Work.class);
work3.setPutCode(null);
work3.setVisibility(Visibility.PUBLIC);
org.orcid.jaxb.model.record_rc4.WorkTitle title3 = new org.orcid.jaxb.model.record_rc4.WorkTitle();
title3.setTitle(new Title("Work # 3" + time));
work3.setWorkTitle(title3);
work3.getExternalIdentifiers().getExternalIdentifier().clear();
ExternalID wExtId3 = new ExternalID();
wExtId3.setValue("Work Id " + 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 = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), work1, accessTokenForClient1);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
Long putCode1 = getPutCodeFromResponse(postResponse);
postResponse = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), work2, accessTokenForClient1);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
Long putCode2 = getPutCodeFromResponse(postResponse);
postResponse = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), work3, accessTokenForClient2);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
Long putCode3 = getPutCodeFromResponse(postResponse);
ClientResponse activitiesResponse = memberV2ApiClient.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()) {
if (group.getIdentifiers().getExternalIdentifier() == null || group.getIdentifiers().getExternalIdentifier().isEmpty()) {
for (WorkSummary summary : group.getWorkSummary()) {
String title = summary.getTitle().getTitle().getContent();
if (("Work # 2" + time).equals(title)) {
work2found = true;
work2Group = group;
}
}
} else {
for (ExternalID id : group.getIdentifiers().getExternalIdentifier()) {
//If it is the ID is the one we are looking for
if (id.getValue().equals("Work Id " + time)) {
for (WorkSummary summary : group.getWorkSummary()) {
String title = summary.getTitle().getTitle().getContent();
if (("Work # 1" + time).equals(title)) {
work1found = true;
work1Group = group;
} else if (("Work # 3" + time).equals(title)) {
work3found = true;
work3Group = group;
}
}
}
}
}
}
assertTrue(work1found);
assertTrue(work2found);
assertTrue(work3found);
//Check that work # 1 and Work # 3 are in the same work
assertEquals(work1Group, work3Group);
//Check that work # 2 is not in the same group than group # 1
assertThat(work2Group, not(work1Group));
//Remove all created works
ClientResponse deleteResponse = memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), putCode1, accessTokenForClient1);
assertNotNull(deleteResponse);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
deleteResponse = memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), putCode2, accessTokenForClient1);
assertNotNull(deleteResponse);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
deleteResponse = memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), putCode3, accessTokenForClient2);
assertNotNull(deleteResponse);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
use of org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary in project ORCID-Source by ORCID.
the class MemberV2PerformanceTest method cleanActivities.
private void cleanActivities() throws JSONException, InterruptedException, URISyntaxException {
String token = getAccessToken();
// Remove all activities
ClientResponse activitiesResponse = memberV2ApiClient.viewActivities(this.getUser1OrcidId(), token);
assertNotNull(activitiesResponse);
ActivitiesSummary summary = activitiesResponse.getEntity(ActivitiesSummary.class);
assertNotNull(summary);
if (summary.getEducations() != null && !summary.getEducations().getSummaries().isEmpty()) {
for (EducationSummary education : summary.getEducations().getSummaries()) {
memberV2ApiClient.deleteEducationXml(this.getUser1OrcidId(), education.getPutCode(), token);
}
}
if (summary.getEmployments() != null && !summary.getEmployments().getSummaries().isEmpty()) {
for (EmploymentSummary employment : summary.getEmployments().getSummaries()) {
memberV2ApiClient.deleteEmploymentXml(this.getUser1OrcidId(), employment.getPutCode(), token);
}
}
if (summary.getFundings() != null && !summary.getFundings().getFundingGroup().isEmpty()) {
for (FundingGroup group : summary.getFundings().getFundingGroup()) {
for (FundingSummary funding : group.getFundingSummary()) {
memberV2ApiClient.deleteFundingXml(this.getUser1OrcidId(), funding.getPutCode(), token);
}
}
}
if (summary.getWorks() != null && !summary.getWorks().getWorkGroup().isEmpty()) {
for (WorkGroup group : summary.getWorks().getWorkGroup()) {
for (WorkSummary work : group.getWorkSummary()) {
memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), work.getPutCode(), token);
}
}
}
if (summary.getPeerReviews() != null && !summary.getPeerReviews().getPeerReviewGroup().isEmpty()) {
for (PeerReviewGroup group : summary.getPeerReviews().getPeerReviewGroup()) {
for (PeerReviewSummary peerReview : group.getPeerReviewSummary()) {
memberV2ApiClient.deletePeerReviewXml(this.getUser1OrcidId(), peerReview.getPutCode(), token);
}
}
}
}
Aggregations