From 954cf43cafae50742e9278ff8c8ce2b38924bf5d Mon Sep 17 00:00:00 2001 From: Toni Prieto Date: Wed, 26 Oct 2022 10:57:29 +0200 Subject: [PATCH] Changes to use the translations of CC API when no default locale is configured and correct language code used for CC metadata --- .../CCLicenseConnectorServiceImpl.java | 2 +- .../license/CreativeCommonsServiceImpl.java | 9 +++--- .../SubmissionCCLicenseRestRepository.java | 29 +++++++++++++++++-- dspace/config/dspace.cfg | 2 +- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/dspace-api/src/main/java/org/dspace/license/CCLicenseConnectorServiceImpl.java b/dspace-api/src/main/java/org/dspace/license/CCLicenseConnectorServiceImpl.java index 619227432d..cdecadba52 100644 --- a/dspace-api/src/main/java/org/dspace/license/CCLicenseConnectorServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/license/CCLicenseConnectorServiceImpl.java @@ -106,7 +106,7 @@ public class CCLicenseConnectorServiceImpl implements CCLicenseConnectorService, for (String license : licenses) { - String licenseUri = ccLicenseUrl + "/license/" + license; + String licenseUri = ccLicenseUrl + "/license/" + license + "?locale=" + language; HttpGet licenseHttpGet = new HttpGet(licenseUri); try (CloseableHttpResponse response = client.execute(licenseHttpGet)) { CCLicense ccLicense = retrieveLicenseObject(license, response); diff --git a/dspace-api/src/main/java/org/dspace/license/CreativeCommonsServiceImpl.java b/dspace-api/src/main/java/org/dspace/license/CreativeCommonsServiceImpl.java index 96f110c101..95dccd6c34 100644 --- a/dspace-api/src/main/java/org/dspace/license/CreativeCommonsServiceImpl.java +++ b/dspace-api/src/main/java/org/dspace/license/CreativeCommonsServiceImpl.java @@ -430,9 +430,10 @@ public class CreativeCommonsServiceImpl implements CreativeCommonsService, Initi } - private void addLicenseField(Context context, Item item, String field, String value) throws SQLException { + private void addLicenseField(Context context, Item item, String field, String language, String value) + throws SQLException { String[] params = splitField(field); - itemService.addMetadata(context, item, params[0], params[1], params[2], params[3], value); + itemService.addMetadata(context, item, params[0], params[1], params[2], language, value); } @@ -688,12 +689,12 @@ public class CreativeCommonsServiceImpl implements CreativeCommonsService, Initi String uriField = getCCField("uri"); String nameField = getCCField("name"); - addLicenseField(context, item, uriField, licenseUri); + addLicenseField(context, item, uriField, null, licenseUri); if (configurationService.getBooleanProperty("cc.submit.addbitstream")) { setLicenseRDF(context, item, fetchLicenseRDF(doc)); } if (configurationService.getBooleanProperty("cc.submit.setname")) { - addLicenseField(context, item, nameField, licenseName); + addLicenseField(context, item, nameField, "en", licenseName); } } diff --git a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/SubmissionCCLicenseRestRepository.java b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/SubmissionCCLicenseRestRepository.java index 0dab42f9bd..356b3f22bf 100644 --- a/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/SubmissionCCLicenseRestRepository.java +++ b/dspace-server-webapp/src/main/java/org/dspace/app/rest/repository/SubmissionCCLicenseRestRepository.java @@ -8,11 +8,14 @@ package org.dspace.app.rest.repository; import java.util.List; +import java.util.Locale; +import org.apache.commons.lang3.StringUtils; import org.dspace.app.rest.model.SubmissionCCLicenseRest; import org.dspace.core.Context; import org.dspace.license.CCLicense; import org.dspace.license.service.CreativeCommonsService; +import org.dspace.services.ConfigurationService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -29,10 +32,23 @@ public class SubmissionCCLicenseRestRepository extends DSpaceRestRepository findAll(final Context context, final Pageable pageable) { - List allCCLicenses = creativeCommonsService.findAllCCLicenses(); + String defaultCCLocale = configurationService.getProperty("cc.license.locale"); + + Locale currentLocale = context.getCurrentLocale(); + List allCCLicenses; + // when no default CC locale is defined, current locale is used + if (currentLocale != null && StringUtils.isBlank(defaultCCLocale)) { + allCCLicenses = creativeCommonsService.findAllCCLicenses(currentLocale.toString()); + } else { + allCCLicenses = creativeCommonsService.findAllCCLicenses(); + } return converter.toRestPage(allCCLicenses, pageable, utils.obtainProjection()); } diff --git a/dspace/config/dspace.cfg b/dspace/config/dspace.cfg index 8e532310c1..55fedae088 100644 --- a/dspace/config/dspace.cfg +++ b/dspace/config/dspace.cfg @@ -1008,7 +1008,7 @@ cc.license.jurisdiction = us # Locale for CC dialogs # A locale in the form language or language-country. -# If no default locale is defined the CC default locale will be used +# If no default locale is defined the current supported locale will be used cc.license.locale = en