use of org.orcid.jaxb.model.record_rc4.Funding in project ORCID-Source by ORCID.
the class BlackBoxBaseRC3 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;
}
return result;
} catch (IOException e) {
throw new RuntimeException("Error reading notification from classpath", e);
}
}
use of org.orcid.jaxb.model.record_rc4.Funding in project ORCID-Source by ORCID.
the class MemberV2Test method testUpdateFundingWithProfileCreationTokenWhenClaimedAndNotSource.
@Test
public void testUpdateFundingWithProfileCreationTokenWhenClaimedAndNotSource() throws JSONException, InterruptedException, URISyntaxException {
long time = System.currentTimeMillis();
Funding funding = (Funding) unmarshallFromPath("/record_2.0_rc3/samples/funding-2.0_rc3.xml", Funding.class);
funding.setPutCode(null);
funding.setVisibility(Visibility.PUBLIC);
funding.getExternalIdentifiers().getExternalIdentifier().clear();
ExternalID fExtId = new ExternalID();
fExtId.setType(FundingExternalIdentifierType.GRANT_NUMBER.value());
fExtId.setValue("Funding Id " + time);
fExtId.setRelationship(Relationship.SELF);
funding.getExternalIdentifiers().getExternalIdentifier().add(fExtId);
String accessToken = getAccessToken();
ClientResponse postResponse = memberV2ApiClient.createFundingXml(this.getUser1OrcidId(), funding, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
String locationPath = postResponse.getLocation().getPath();
assertTrue("Location header path should match pattern, but was " + locationPath, locationPath.matches(".*/v2.0_rc3/" + this.getUser1OrcidId() + "/funding/\\d+"));
ClientResponse getResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
Funding gotFunding = getResponse.getEntity(Funding.class);
assertEquals("common:title", gotFunding.getTitle().getTitle().getContent());
assertEquals("common:translated-title", gotFunding.getTitle().getTranslatedTitle().getContent());
assertEquals("en", gotFunding.getTitle().getTranslatedTitle().getLanguageCode());
gotFunding.getTitle().getTitle().setContent("Updated title");
gotFunding.getTitle().getTranslatedTitle().setContent("Updated translated title");
gotFunding.getTitle().getTranslatedTitle().setLanguageCode("es");
String profileCreateToken = oauthHelper.getClientCredentialsAccessToken(this.getClient2ClientId(), this.getClient2ClientSecret(), ScopePathType.ORCID_PROFILE_CREATE);
ClientResponse putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), profileCreateToken, gotFunding);
assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
ClientResponse getAfterUpdateResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
Funding gotAfterUpdateFunding = getAfterUpdateResponse.getEntity(Funding.class);
assertEquals("common:title", gotAfterUpdateFunding.getTitle().getTitle().getContent());
assertEquals("common:translated-title", gotAfterUpdateFunding.getTitle().getTranslatedTitle().getContent());
assertEquals("en", gotAfterUpdateFunding.getTitle().getTranslatedTitle().getLanguageCode());
ClientResponse deleteResponse = memberV2ApiClient.deleteFundingXml(this.getUser1OrcidId(), gotFunding.getPutCode(), accessToken);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
use of org.orcid.jaxb.model.record_rc4.Funding in project ORCID-Source by ORCID.
the class PublicV2Test method createActivities.
private void createActivities() throws JSONException, InterruptedException, URISyntaxException {
String accessToken = getAccessToken();
long time = System.currentTimeMillis();
Work workToCreate = (Work) unmarshallFromPath("/record_2.0_rc1/samples/work-2.0_rc1.xml", Work.class);
for (int i = 0; i < 4; i++) {
workToCreate.setPutCode(null);
workToCreate.getWorkTitle().getTitle().setContent("Work # " + i);
workToCreate.getExternalIdentifiers().getExternalIdentifier().clear();
WorkExternalIdentifier wExtId = new WorkExternalIdentifier();
wExtId.setWorkExternalIdentifierId(new WorkExternalIdentifierId(time + " Work Id " + i));
wExtId.setWorkExternalIdentifierType(WorkExternalIdentifierType.AGR);
wExtId.setRelationship(Relationship.SELF);
workToCreate.getExternalIdentifiers().getExternalIdentifier().add(wExtId);
if (i == 0 || i == 3)
workToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PUBLIC);
else if (i == 1)
workToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.LIMITED);
else
workToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PRIVATE);
ClientResponse postResponse = memberV2ApiClient.createWorkXml(getUser1OrcidId(), workToCreate, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
}
Funding fundingToCreate = (Funding) unmarshallFromPath("/record_2.0_rc1/samples/funding-2.0_rc1.xml", Funding.class);
for (int i = 0; i < 4; i++) {
fundingToCreate.setPutCode(null);
fundingToCreate.getTitle().getTitle().setContent("Funding # " + i);
fundingToCreate.getExternalIdentifiers().getExternalIdentifier().clear();
FundingExternalIdentifier fExtId = new FundingExternalIdentifier();
fExtId.setType(FundingExternalIdentifierType.GRANT_NUMBER);
fExtId.setValue(time + " funding Id " + i);
fExtId.setRelationship(Relationship.SELF);
fundingToCreate.getExternalIdentifiers().getExternalIdentifier().add(fExtId);
if (i == 0 || i == 3)
fundingToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PUBLIC);
else if (i == 1)
fundingToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.LIMITED);
else
fundingToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PRIVATE);
ClientResponse postResponse = memberV2ApiClient.createFundingXml(getUser1OrcidId(), fundingToCreate, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
}
Employment employmentToCreate = (Employment) unmarshallFromPath("/record_2.0_rc1/samples/employment-2.0_rc1.xml", Employment.class);
for (int i = 0; i < 4; i++) {
employmentToCreate.setPutCode(null);
employmentToCreate.setRoleTitle("Employment # " + i);
if (i == 0 || i == 3)
employmentToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PUBLIC);
else if (i == 1)
employmentToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.LIMITED);
else
employmentToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PRIVATE);
ClientResponse postResponse = memberV2ApiClient.createEmploymentXml(getUser1OrcidId(), employmentToCreate, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
}
Education educationToCreate = (Education) unmarshallFromPath("/record_2.0_rc1/samples/education-2.0_rc1.xml", Education.class);
for (int i = 0; i < 4; i++) {
educationToCreate.setPutCode(null);
educationToCreate.setRoleTitle("Education # " + i);
if (i == 0 || i == 3)
educationToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PUBLIC);
else if (i == 1)
educationToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.LIMITED);
else
educationToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PRIVATE);
ClientResponse postResponse = memberV2ApiClient.createEducationXml(getUser1OrcidId(), educationToCreate, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
}
PeerReview peerReviewToCreate = (PeerReview) unmarshallFromPath("/record_2.0_rc1/samples/peer-review-2.0_rc1.xml", PeerReview.class);
for (int i = 0; i < 4; i++) {
peerReviewToCreate.setPutCode(null);
peerReviewToCreate.setGroupId(groupRecords.get(0).getGroupId());
peerReviewToCreate.getSubjectName().getTitle().setContent("PeerReview # " + i);
peerReviewToCreate.getCompletionDate().setDay(new Day(i + 1));
peerReviewToCreate.getCompletionDate().setMonth(new Month(i + 1));
peerReviewToCreate.getCompletionDate().setYear(new Year((i + 1) * 1000));
peerReviewToCreate.getExternalIdentifiers().getExternalIdentifier().get(0).getWorkExternalIdentifierId().setContent("extId-" + (i + 1));
if (i == 0 || i == 3) {
peerReviewToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PUBLIC);
} else if (i == 1) {
peerReviewToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.LIMITED);
} else {
peerReviewToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PRIVATE);
}
ClientResponse postResponse = memberV2ApiClient.createPeerReviewXml(getUser1OrcidId(), peerReviewToCreate, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
}
}
use of org.orcid.jaxb.model.record_rc4.Funding in project ORCID-Source by ORCID.
the class MemberV2ApiServiceDelegator_FundingTest method testUpdateFundingLeavingVisibilityNullTest.
@Test
public void testUpdateFundingLeavingVisibilityNullTest() {
SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4447", ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
Response response = serviceDelegator.viewFunding("4444-4444-4444-4447", 6L);
assertNotNull(response);
Funding funding = (Funding) response.getEntity();
assertNotNull(funding);
assertEquals(Visibility.PUBLIC, funding.getVisibility());
funding.setVisibility(null);
response = serviceDelegator.updateFunding("4444-4444-4444-4447", 6L, funding);
assertNotNull(response);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
funding = (Funding) response.getEntity();
assertEquals(Visibility.PUBLIC, funding.getVisibility());
}
use of org.orcid.jaxb.model.record_rc4.Funding in project ORCID-Source by ORCID.
the class MemberV2ApiServiceDelegator_FundingTest method testAddFundingWithInvalidExtIdTypeFail.
@Test
public void testAddFundingWithInvalidExtIdTypeFail() {
String orcid = "4444-4444-4444-4499";
SecurityContextTestUtils.setUpSecurityContext(orcid, ScopePathType.ACTIVITIES_READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
Funding funding = Utils.getFunding();
try {
funding.getExternalIdentifiers().getExternalIdentifier().get(0).setType("INVALID");
serviceDelegator.createFunding(orcid, funding);
fail();
} catch (ActivityIdentifierValidationException e) {
} catch (Exception e) {
fail();
}
funding.getExternalIdentifiers().getExternalIdentifier().get(0).setType("grant_number");
Response response = serviceDelegator.createFunding(orcid, funding);
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
Map<?, ?> map = response.getMetadata();
assertNotNull(map);
assertTrue(map.containsKey("Location"));
List<?> resultWithPutCode = (List<?>) map.get("Location");
Long putCode = Long.valueOf(String.valueOf(resultWithPutCode.get(0)));
// Delete it to roll back the test data
response = serviceDelegator.deleteFunding(orcid, putCode);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
}
Aggregations