use of org.orcid.jaxb.model.record_v2.Funding in project ORCID-Source by ORCID.
the class JpaJaxbFundingAdapterTest method fromFundingEntityTest.
@Test
public void fromFundingEntityTest() throws JAXBException {
ProfileFundingEntity entity = getProfileFundingEntity();
assertNotNull(entity);
assertEquals("123456", entity.getNumericAmount().toString());
Funding funding = jpaJaxbFundingAdapter.toFunding(entity);
assertNotNull(funding);
assertEquals(Long.valueOf(12345), funding.getPutCode());
assertNotNull(funding.getAmount());
assertEquals("123456", funding.getAmount().getContent());
assertEquals("CRC", funding.getAmount().getCurrencyCode());
assertNotNull(funding.getContributors());
assertNotNull(funding.getContributors().getContributor());
assertEquals(1, funding.getContributors().getContributor().size());
assertEquals("8888-8888-8888-8880", funding.getContributors().getContributor().get(0).getContributorOrcid().getPath());
assertEquals("orcid.org", funding.getContributors().getContributor().get(0).getContributorOrcid().getHost());
assertEquals("http://orcid.org/8888-8888-8888-8880", funding.getContributors().getContributor().get(0).getContributorOrcid().getUri());
assertEquals("funding:creditName", funding.getContributors().getContributor().get(0).getCreditName().getContent());
assertEquals("funding:description", funding.getDescription());
assertNotNull(funding.getStartDate());
assertEquals("01", funding.getStartDate().getDay().getValue());
assertEquals("01", funding.getStartDate().getMonth().getValue());
assertEquals("2000", funding.getStartDate().getYear().getValue());
assertNotNull(funding.getEndDate());
assertEquals("01", funding.getEndDate().getDay().getValue());
assertEquals("01", funding.getEndDate().getMonth().getValue());
assertEquals("2020", funding.getEndDate().getYear().getValue());
assertEquals("funding:title", funding.getTitle().getTitle().getContent());
assertEquals("funding:translatedTitle", funding.getTitle().getTranslatedTitle().getContent());
assertEquals("ES", funding.getTitle().getTranslatedTitle().getLanguageCode());
assertEquals(FundingType.SALARY_AWARD, funding.getType());
assertEquals(Visibility.PRIVATE, funding.getVisibility());
}
use of org.orcid.jaxb.model.record_v2.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_rc1/samples/funding-2.0_rc1.xml", Funding.class);
funding.setPutCode(null);
funding.setVisibility(Visibility.PUBLIC);
funding.getExternalIdentifiers().getExternalIdentifier().clear();
FundingExternalIdentifier fExtId = new FundingExternalIdentifier();
fExtId.setType(FundingExternalIdentifierType.GRANT_NUMBER);
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_rc1/" + 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_v2.Funding in project ORCID-Source by ORCID.
the class MemberV2Test method testTokenWorksOnlyForTheScopeItWasIssued.
@SuppressWarnings({ "deprecation", "rawtypes" })
@Test
public void testTokenWorksOnlyForTheScopeItWasIssued() throws JSONException, InterruptedException, URISyntaxException {
long time = System.currentTimeMillis();
List<String> scopes = getScopes(ScopePathType.FUNDING_CREATE, ScopePathType.FUNDING_UPDATE);
String accessToken = getAccessToken(scopes);
Work work1 = (Work) unmarshallFromPath("/record_2.0_rc1/samples/work-2.0_rc1.xml", Work.class);
work1.setPutCode(null);
work1.getExternalIdentifiers().getExternalIdentifier().clear();
org.orcid.jaxb.model.record_rc1.WorkTitle title1 = new org.orcid.jaxb.model.record_rc1.WorkTitle();
title1.setTitle(new Title("Work # 1"));
work1.setWorkTitle(title1);
WorkExternalIdentifier wExtId1 = new WorkExternalIdentifier();
wExtId1.setWorkExternalIdentifierId(new WorkExternalIdentifierId("Work Id " + time));
wExtId1.setWorkExternalIdentifierType(WorkExternalIdentifierType.AGR);
wExtId1.setRelationship(Relationship.SELF);
wExtId1.setUrl(new Url("http://orcid.org/work#1"));
work1.getExternalIdentifiers().getWorkExternalIdentifier().clear();
work1.getExternalIdentifiers().getWorkExternalIdentifier().add(wExtId1);
//Add the work
ClientResponse postResponse = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), work1, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.FORBIDDEN.getStatusCode(), postResponse.getStatus());
Funding funding = (Funding) unmarshallFromPath("/record_2.0_rc1/samples/funding-2.0_rc1.xml", Funding.class);
funding.setPutCode(null);
funding.setVisibility(Visibility.PUBLIC);
funding.getExternalIdentifiers().getExternalIdentifier().clear();
FundingExternalIdentifier fExtId = new FundingExternalIdentifier();
fExtId.setType(FundingExternalIdentifierType.GRANT_NUMBER);
fExtId.setValue("Funding Id " + time);
fExtId.setRelationship(Relationship.SELF);
funding.getExternalIdentifiers().getExternalIdentifier().add(fExtId);
//Add the funding
postResponse = memberV2ApiClient.createFundingXml(this.getUser1OrcidId(), funding, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
// Delete funding
Map map = postResponse.getMetadata();
assertNotNull(map);
assertTrue(map.containsKey("Location"));
List resultWithPutCode = (List) map.get("Location");
String location = resultWithPutCode.get(0).toString();
Long putCode = Long.valueOf(location.substring(location.lastIndexOf('/') + 1));
ClientResponse deleteResponse = memberV2ApiClient.deleteFundingXml(this.getUser1OrcidId(), putCode, accessToken);
assertNotNull(deleteResponse);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
use of org.orcid.jaxb.model.record_v2.Funding in project ORCID-Source by ORCID.
the class MemberV2Test method createViewUpdateAndDeleteFunding.
@Test
public void createViewUpdateAndDeleteFunding() throws JSONException, InterruptedException, URISyntaxException {
long time = System.currentTimeMillis();
Funding funding = (Funding) unmarshallFromPath("/record_2.0_rc1/samples/funding-2.0_rc1.xml", Funding.class);
funding.setPutCode(null);
funding.setVisibility(Visibility.PUBLIC);
funding.getExternalIdentifiers().getExternalIdentifier().clear();
FundingExternalIdentifier fExtId = new FundingExternalIdentifier();
fExtId.setType(FundingExternalIdentifierType.GRANT_NUMBER);
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_rc1/" + 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");
//Save the original visibility
Visibility originalVisibility = gotFunding.getVisibility();
Visibility updatedVisibility = Visibility.PRIVATE.equals(originalVisibility) ? Visibility.LIMITED : Visibility.PRIVATE;
//Verify you cant update the visibility
gotFunding.setVisibility(updatedVisibility);
ClientResponse putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotFunding);
assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
OrcidError error = putResponse.getEntity(OrcidError.class);
assertNotNull(error);
assertEquals(Integer.valueOf(9035), error.getErrorCode());
//Set the visibility again to the initial one
gotFunding.setVisibility(originalVisibility);
putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotFunding);
assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
ClientResponse getAfterUpdateResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
Funding gotAfterUpdateFunding = getAfterUpdateResponse.getEntity(Funding.class);
assertEquals("Updated title", gotAfterUpdateFunding.getTitle().getTitle().getContent());
assertEquals("Updated translated title", gotAfterUpdateFunding.getTitle().getTranslatedTitle().getContent());
assertEquals("es", 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_v2.Funding in project ORCID-Source by ORCID.
the class PublicV2Test method checkFunding.
private void checkFunding(String readPublicToken) throws JSONException, InterruptedException, URISyntaxException {
Funding fundingToCreate = (Funding) unmarshallFromPath("/record_2.0_rc1/samples/funding-2.0_rc1.xml", Funding.class);
fundingToCreate.setPutCode(null);
fundingToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.PUBLIC);
String accessToken = getAccessToken();
ClientResponse postResponse = memberV2ApiClient.createFundingXml(getUser1OrcidId(), fundingToCreate, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
String path = postResponse.getLocation().getPath();
String putCode = path.substring(path.lastIndexOf('/') + 1, path.length());
ClientResponse getFundingResponse = null;
if (readPublicToken != null) {
getFundingResponse = publicV2ApiClient.viewFundingXml(getUser1OrcidId(), putCode, readPublicToken);
} else {
getFundingResponse = publicV2ApiClient.viewFundingXml(getUser1OrcidId(), putCode);
}
assertNotNull(getFundingResponse);
checkResponse(getFundingResponse);
Funding funding = getFundingResponse.getEntity(Funding.class);
assertNotNull(funding);
assertEquals("common:title", funding.getTitle().getTitle().getContent());
ClientResponse getFundingSummaryResponse = null;
if (readPublicToken != null) {
getFundingSummaryResponse = publicV2ApiClient.viewFundingSummaryXml(getUser1OrcidId(), putCode, readPublicToken);
} else {
getFundingSummaryResponse = publicV2ApiClient.viewFundingSummaryXml(getUser1OrcidId(), putCode);
}
assertNotNull(getFundingSummaryResponse);
checkResponse(getFundingSummaryResponse);
FundingSummary summary = getFundingSummaryResponse.getEntity(FundingSummary.class);
assertNotNull(summary);
assertEquals("common:title", summary.getTitle().getTitle().getContent());
}
Aggregations