mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-18 07:23:08 +00:00
Merge pull request #8547 from toniprieto/translate-cc
Use translations of Creative Commons API
This commit is contained in:
@@ -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);
|
||||
|
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
@@ -691,12 +692,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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<Subm
|
||||
@Autowired
|
||||
protected CreativeCommonsService creativeCommonsService;
|
||||
|
||||
@Autowired
|
||||
protected ConfigurationService configurationService;
|
||||
|
||||
@Override
|
||||
@PreAuthorize("hasAuthority('AUTHENTICATED')")
|
||||
public SubmissionCCLicenseRest findOne(final Context context, final String licenseId) {
|
||||
CCLicense ccLicense = creativeCommonsService.findOne(licenseId);
|
||||
|
||||
String defaultCCLocale = configurationService.getProperty("cc.license.locale");
|
||||
|
||||
Locale currentLocale = context.getCurrentLocale();
|
||||
CCLicense ccLicense;
|
||||
// when no default CC locale is defined, current locale is used
|
||||
if (currentLocale != null && StringUtils.isBlank(defaultCCLocale)) {
|
||||
ccLicense = creativeCommonsService.findOne(licenseId, currentLocale.toString());
|
||||
} else {
|
||||
ccLicense = creativeCommonsService.findOne(licenseId);
|
||||
}
|
||||
if (ccLicense == null) {
|
||||
throw new ResourceNotFoundException("No CC license could be found for ID: " + licenseId );
|
||||
}
|
||||
@@ -43,7 +59,16 @@ public class SubmissionCCLicenseRestRepository extends DSpaceRestRepository<Subm
|
||||
@PreAuthorize("hasAuthority('AUTHENTICATED')")
|
||||
public Page<SubmissionCCLicenseRest> findAll(final Context context, final Pageable pageable) {
|
||||
|
||||
List<CCLicense> allCCLicenses = creativeCommonsService.findAllCCLicenses();
|
||||
String defaultCCLocale = configurationService.getProperty("cc.license.locale");
|
||||
|
||||
Locale currentLocale = context.getCurrentLocale();
|
||||
List<CCLicense> 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());
|
||||
}
|
||||
|
||||
|
@@ -1015,7 +1015,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
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user