use of org.orcid.jaxb.model.v3.dev1.common.Visibility 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);
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.v3.dev1.common.Visibility in project ORCID-Source by ORCID.
the class WorkspaceController method setKeywordsFormJson.
@RequestMapping(value = "/my-orcid/keywordsForms.json", method = RequestMethod.POST)
@ResponseBody
public KeywordsForm setKeywordsFormJson(HttpServletRequest request, @RequestBody KeywordsForm kf) throws NoSuchRequestHandlingMethodException {
kf.setErrors(new ArrayList<String>());
if (kf != null) {
Iterator<KeywordForm> it = kf.getKeywords().iterator();
while (it.hasNext()) {
KeywordForm k = it.next();
if (!PojoUtil.isEmpty(k.getContent())) {
if (k.getContent().length() > SiteConstants.KEYWORD_MAX_LENGTH) {
k.setContent(k.getContent().substring(0, SiteConstants.KEYWORD_MAX_LENGTH));
}
} else {
it.remove();
}
// Validate visibility is not null
validateVisibility(k);
copyErrors(k, kf);
copyErrors(k.getVisibility(), kf);
}
if (kf.getErrors().size() > 0) {
return kf;
}
Keywords updatedKeywords = kf.toKeywords();
profileKeywordManager.updateKeywords(getCurrentUserOrcid(), updatedKeywords);
}
return kf;
}
use of org.orcid.jaxb.model.v3.dev1.common.Visibility in project ORCID-Source by ORCID.
the class WorkspaceController method setWebsitesFormJson.
/**
* Retrieve all external identifiers as a json string
*/
@RequestMapping(value = "/my-orcid/websitesForms.json", method = RequestMethod.POST)
@ResponseBody
public WebsitesForm setWebsitesFormJson(HttpServletRequest request, @RequestBody WebsitesForm ws) throws NoSuchRequestHandlingMethodException {
ws.setErrors(new ArrayList<String>());
if (ws != null) {
Set<String> existingUrls = new HashSet<String>();
for (WebsiteForm w : ws.getWebsites()) {
// Clean old errors
w.setErrors(new ArrayList<String>());
// Validate url
validateUrl(w.getUrl());
copyErrors(w.getUrl(), w);
// Validate url name
if (isLongerThan(w.getUrlName(), SiteConstants.URL_NAME_MAX_LENGTH)) {
w.getErrors().add(getMessage("manualWork.length_less_X", SiteConstants.URL_NAME_MAX_LENGTH));
}
// Check there are no duplicates
if (existingUrls.contains(w.getUrl().getValue())) {
w.getErrors().add(getMessage("researcher_url.error.duplicated", w.getUrl()));
} else {
existingUrls.add(w.getUrl().getValue());
}
// Validate visibility is not null
validateVisibility(w);
copyErrors(w, ws);
copyErrors(w.getUrl(), ws);
copyErrors(w.getVisibility(), ws);
}
if (ws.getErrors().size() > 0) {
return ws;
}
ResearcherUrls rUrls = ws.toResearcherUrls();
researcherUrlManager.updateResearcherUrls(getCurrentUserOrcid(), rUrls);
}
return ws;
}
use of org.orcid.jaxb.model.v3.dev1.common.Visibility in project ORCID-Source by ORCID.
the class WorkspaceController method updateExternalIdentifierJson.
/**
* Update the visibility of the given external identifeirs
*/
@RequestMapping(value = "/my-orcid/externalIdentifiers.json", method = RequestMethod.POST)
@ResponseBody
public ExternalIdentifiersForm updateExternalIdentifierJson(HttpServletRequest request, @RequestBody ExternalIdentifiersForm externalIdentifiersForm) {
externalIdentifiersForm.setErrors(new ArrayList<String>());
// Validate visibility is not null
if (externalIdentifiersForm != null && externalIdentifiersForm.getExternalIdentifiers() != null) {
for (ExternalIdentifierForm extId : externalIdentifiersForm.getExternalIdentifiers()) {
// Validate visibility is not null
validateVisibility(extId);
copyErrors(extId, externalIdentifiersForm);
}
}
if (!externalIdentifiersForm.getErrors().isEmpty()) {
return externalIdentifiersForm;
}
PersonExternalIdentifiers externalIdentifiers = externalIdentifiersForm.toPersonExternalIdentifiers();
externalIdentifiers = externalIdentifierManager.updateExternalIdentifiers(getCurrentUserOrcid(), externalIdentifiers);
return externalIdentifiersForm;
}
use of org.orcid.jaxb.model.v3.dev1.common.Visibility in project ORCID-Source by ORCID.
the class WorkspaceController method getWebsitesFormJson.
/**
* Retrieve all external identifiers as a json string
*/
@RequestMapping(value = "/my-orcid/websitesForms.json", method = RequestMethod.GET)
@ResponseBody
public WebsitesForm getWebsitesFormJson(HttpServletRequest request) throws NoSuchRequestHandlingMethodException {
ResearcherUrls rUrls = researcherUrlManager.getResearcherUrls(getCurrentUserOrcid());
WebsitesForm form = WebsitesForm.valueOf(rUrls);
// Set the default visibility
ProfileEntity profile = profileEntityCacheManager.retrieve(getCurrentUserOrcid());
if (profile != null && profile.getActivitiesVisibilityDefault() != null) {
form.setVisibility(Visibility.valueOf(profile.getActivitiesVisibilityDefault()));
}
return form;
}
Aggregations