use of org.orcid.jaxb.model.record_v2.Funding in project ORCID-Source by ORCID.
the class FundingsController method createFundingIdList.
/**
* Create a funding id list and sorts a map associated with the list in in
* the session
*
*/
private List<String> createFundingIdList(HttpServletRequest request) {
Map<String, String> languages = lm.buildLanguageMap(getUserLocale(), false);
String orcid = getEffectiveUserOrcid();
List<Funding> fundings = profileFundingManager.getFundingList(orcid, profileEntityManager.getLastModified(orcid));
HashMap<String, FundingForm> fundingsMap = new HashMap<String, FundingForm>();
List<String> fundingIds = new ArrayList<String>();
if (fundings != null) {
for (Funding funding : fundings) {
try {
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));
}
if (form.getContributors() != null) {
for (Contributor contributor : form.getContributors()) {
if (!PojoUtil.isEmpty(contributor.getOrcid())) {
String contributorOrcid = contributor.getOrcid().getValue();
if (profileEntityManager.orcidExists(contributorOrcid)) {
// contributor is an ORCID user - visibility of user's name in record must be taken into account
ProfileEntity profileEntity = profileEntityCacheManager.retrieve(contributorOrcid);
String publicContributorCreditName = cacheManager.getPublicCreditName(profileEntity);
contributor.setCreditName(Text.valueOf(publicContributorCreditName));
}
}
}
}
form.setCountryForDisplay(getMessage(buildInternationalizationKey(CountryIsoEntity.class, funding.getOrganization().getAddress().getCountry().name())));
String putCode = String.valueOf(funding.getPutCode());
fundingsMap.put(putCode, form);
fundingIds.add(putCode);
} catch (Exception e) {
LOGGER.error("Failed to parse as Funding. Put code" + funding.getPutCode(), e);
}
}
request.getSession().setAttribute(GRANT_MAP, fundingsMap);
}
return fundingIds;
}
use of org.orcid.jaxb.model.record_v2.Funding in project ORCID-Source by ORCID.
the class MemberV2ApiServiceDelegatorImpl method viewFunding.
@Override
public Response viewFunding(String orcid, Long putCode) {
Funding f = profileFundingManagerReadOnly.getFunding(orcid, putCode);
orcidSecurityManager.checkAndFilter(orcid, f, ScopePathType.FUNDING_READ_LIMITED);
ActivityUtils.setPathToActivity(f, orcid);
sourceUtils.setSourceName(f);
contributorUtils.filterContributorPrivateData(f);
return Response.ok(f).build();
}
use of org.orcid.jaxb.model.record_v2.Funding in project ORCID-Source by ORCID.
the class MemberV2ApiServiceDelegatorImpl method createFunding.
@Override
public Response createFunding(String orcid, Funding funding) {
orcidSecurityManager.checkClientAccessAndScopes(orcid, ScopePathType.FUNDING_CREATE);
clearSource(funding);
Funding f = profileFundingManager.createFunding(orcid, funding, true);
sourceUtils.setSourceName(f);
try {
return Response.created(new URI(String.valueOf(f.getPutCode()))).build();
} catch (URISyntaxException e) {
throw new RuntimeException(localeManager.resolveMessage("apiError.createfunding_response.exception"), e);
}
}
use of org.orcid.jaxb.model.record_v2.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_v2.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