use of org.orcid.jaxb.model.record_rc3.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_rc2/samples/work-2.0_rc2.xml", Work.class);
work1.setPutCode(null);
work1.getExternalIdentifiers().getExternalIdentifier().clear();
org.orcid.jaxb.model.record_rc2.WorkTitle title1 = new org.orcid.jaxb.model.record_rc2.WorkTitle();
title1.setTitle(new Title("Work # 1"));
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);
//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_rc2/samples/funding-2.0_rc2.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);
//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_rc3.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_rc3.Funding in project ORCID-Source by ORCID.
the class FundingsController method getFundingJson.
/**
* List fundings associated with a profile
* */
@RequestMapping(value = "/getFunding.json", method = RequestMethod.GET)
@ResponseBody
public FundingForm getFundingJson(@RequestParam(value = "fundingId") Long fundingId) {
if (fundingId == null)
return null;
Map<String, String> languages = lm.buildLanguageMap(getUserLocale(), false);
Funding funding = profileFundingManager.getFunding(getEffectiveUserOrcid(), fundingId);
FundingForm form = FundingForm.valueOf(funding);
if (funding.getType() != null) {
form.setFundingTypeForDisplay(getMessage(buildInternationalizationKey(org.orcid.jaxb.model.message.FundingType.class, funding.getType().value())));
}
// Set translated title language name
if (!(funding.getTitle().getTranslatedTitle() == null) && !StringUtils.isEmpty(funding.getTitle().getTranslatedTitle().getLanguageCode())) {
String languageName = languages.get(funding.getTitle().getTranslatedTitle().getLanguageCode());
form.getFundingTitle().getTranslatedTitle().setLanguageName(languageName);
}
// Set the formatted amount
if (funding.getAmount() != null && StringUtils.isNotBlank(funding.getAmount().getContent())) {
BigDecimal bigDecimal = new BigDecimal(funding.getAmount().getContent());
String formattedAmount = formatAmountString(bigDecimal);
form.setAmount(Text.valueOf(formattedAmount));
}
form.setCountryForDisplay(getMessage(buildInternationalizationKey(CountryIsoEntity.class, funding.getOrganization().getAddress().getCountry().name())));
return form;
}
use of org.orcid.jaxb.model.record_rc3.Funding in project ORCID-Source by ORCID.
the class FundingsController method editFunding.
private void editFunding(FundingForm fundingForm) throws Exception {
// Set the right value for the amount
setAmountWithTheCorrectFormat(fundingForm);
// Set the credit name
setTypeToExternalIdentifiers(fundingForm);
// Add to database
Funding funding = fundingForm.toFunding();
funding = profileFundingManager.updateFunding(getEffectiveUserOrcid(), funding, false);
// Send the new funding sub type for indexing
if (fundingForm.getOrganizationDefinedFundingSubType() != null && !PojoUtil.isEmpty(fundingForm.getOrganizationDefinedFundingSubType().getSubtype()) && !fundingForm.getOrganizationDefinedFundingSubType().isAlreadyIndexed())
profileFundingManager.addFundingSubType(fundingForm.getOrganizationDefinedFundingSubType().getSubtype().getValue(), getEffectiveUserOrcid());
}
use of org.orcid.jaxb.model.record_rc3.Funding in project ORCID-Source by ORCID.
the class FundingsController method addFunding.
private void addFunding(FundingForm fundingForm) throws Exception {
// Set the right value for the amount
setAmountWithTheCorrectFormat(fundingForm);
// Set default type for external identifiers
setTypeToExternalIdentifiers(fundingForm);
// Add to database
Funding funding = fundingForm.toFunding();
funding = profileFundingManager.createFunding(getEffectiveUserOrcid(), funding, false);
// Send the new funding sub type for indexing
if (fundingForm.getOrganizationDefinedFundingSubType() != null && !PojoUtil.isEmpty(fundingForm.getOrganizationDefinedFundingSubType().getSubtype()) && !fundingForm.getOrganizationDefinedFundingSubType().isAlreadyIndexed())
profileFundingManager.addFundingSubType(fundingForm.getOrganizationDefinedFundingSubType().getSubtype().getValue(), getEffectiveUserOrcid());
}
Aggregations