Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VIVO-1925] i18n: Editing labels results in new label #188

Merged
merged 4 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.ResourceFactory;
import org.apache.jena.vocabulary.XSD;
import org.apache.jena.vocabulary.RDF;

import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral;
Expand Down Expand Up @@ -180,7 +181,7 @@ public Literal createLiteral(String value, String datatypeUri, String lang) {
// } catch (UnsupportedEncodingException e) {
// log.error(e, e);
// }
} else if ( XSD.xstring.getURI().equals(datatypeUri) ){
} else if ( XSD.xstring.getURI().equals(datatypeUri) || RDF.dtLangString.getURI().equals(datatypeUri) ){
if( lang != null && lang.length() > 0 ) return ResourceFactory.createLangLiteral(value, lang);
}
return literalCreationModel.createTypedLiteral(value, datatypeUri);
Expand Down Expand Up @@ -303,9 +304,21 @@ public void addLiteralToForm(EditConfigurationVTwo editConfig, FieldVTwo field,
String rangeLang = field.getRangeLang(); //UQAM Default value
try {
if (_vreq != null ) {
rangeLang = _vreq.getLocale().getLanguage();
if (!_vreq.getLocale().getCountry().isEmpty()) {
rangeLang += "-" + _vreq.getLocale().getCountry();
// only if the request comes from the rdfsLabelGenerator the language should be used
Boolean get_label_language = false;
if (!StringUtils.isBlank(editConfig.formUrl) && editConfig.formUrl.contains("RDFSLabelGenerator")) {
get_label_language = true;
dofeldsc marked this conversation as resolved.
Show resolved Hide resolved
}
// if the language is set in the given Literal, this language-tag should be used and remain the same
// for example when you edit an label with an langauge-tag (no matter which language is selected globally)
if (!StringUtils.isBlank(editConfig.getLiteralsInScope().get("label").get(0).getLanguage()) && get_label_language)
{
rangeLang = editConfig.getLiteralsInScope().get("label").get(0).getLanguage();
} else { // if the literal has no langauge-tag, use the language which is globally selected
rangeLang = _vreq.getLocale().getLanguage();
if (!_vreq.getLocale().getCountry().isEmpty()) {
rangeLang += "-" + _vreq.getLocale().getCountry();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.jena.shared.Lock;
import org.apache.jena.vocabulary.RDF;
import org.apache.jena.vocabulary.XSD;
import org.apache.commons.lang3.StringUtils;

import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.InsertException;
Expand Down Expand Up @@ -128,7 +129,7 @@ private AdditionsAndRetractions createNewStatements(
subInValuesToN3( configuration, submission, requiredN3, optionalN3, null , null, vreq);

/* parse N3 to RDF Models, No retractions since all of the statements are new. */
return parseN3ToChange(requiredN3, optionalN3, null, null, vreq);
return parseN3ToChange(requiredN3, optionalN3, null, null, vreq, null);
}

/* for a list of N3 strings, substitute in the subject, predicate and object URIs
Expand Down Expand Up @@ -174,7 +175,7 @@ protected AdditionsAndRetractions editExistingStatements(

return parseN3ToChange(
N3RequiredAssert,N3OptionalAssert,
N3RequiredRetract, N3OptionalRetract, vreq);
N3RequiredRetract, N3OptionalRetract, vreq, editConfig);
}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -214,7 +215,10 @@ protected void subInValuesToN3(
/*
* do it only if aLiteral are xstring datatype
*/
if (XSD.xstring.getURI().equals(aLiteratDT) || RDF.dtLangString.getURI().equals(aLiteratDT)) {
if (RDF.dtLangString.getURI().equals(aLiteratDT) && !aLiteral.getLanguage().isEmpty()) {
newLiteral = aLiteral;
}
else if (XSD.xstring.getURI().equals(aLiteratDT) || RDF.dtLangString.getURI().equals(aLiteratDT)) {
String lang = vreq.getLocale().getLanguage();
if (!vreq.getLocale().getCountry().isEmpty()) {
lang += "-" + vreq.getLocale().getCountry();
Expand Down Expand Up @@ -299,7 +303,7 @@ public static void applyChangesToWriteModel(

protected AdditionsAndRetractions parseN3ToChange(
List<String> requiredAdds, List<String> optionalAdds,
List<String> requiredDels, List<String> optionalDels, VitroRequest vreq) throws Exception{
List<String> requiredDels, List<String> optionalDels, VitroRequest vreq, EditConfigurationVTwo editConfig) throws Exception{

List<Model> adds = parseN3ToRDF(requiredAdds, REQUIRED);
adds.addAll( parseN3ToRDF(optionalAdds, OPTIONAL));
Expand All @@ -308,9 +312,20 @@ protected AdditionsAndRetractions parseN3ToChange(
String lingCxt=null;
//UQAM Taking into account the linguistic context in retract
try {
lingCxt = vreq.getLocale().getLanguage();
if (!vreq.getLocale().getCountry().isEmpty()) {
lingCxt += "-" + vreq.getLocale().getCountry();
// only if the request comes from the rdfsLabelGenerator the language should be used
Boolean get_label_language = false;
dofeldsc marked this conversation as resolved.
Show resolved Hide resolved
if (!StringUtils.isBlank(editConfig.formUrl) && editConfig.formUrl.contains("RDFSLabelGenerator")) {
get_label_language = true;
}
// if the language is set in the given Literal, this language-tag should be used and remain the same
// for example when you edit an label with an langauge-tag (no matter which language is selected globally)
if (editConfig != null && !StringUtils.isBlank(editConfig.getLiteralsInScope().get("label").get(0).getLanguage()) && get_label_language) {
lingCxt = editConfig.getLiteralsInScope().get("label").get(0).getLanguage();
} else { // if the literal has no langauge-tag, use the language which is globally selected
lingCxt = vreq.getLocale().getLanguage();
if (!vreq.getLocale().getCountry().isEmpty()) {
lingCxt += "-" + vreq.getLocale().getCountry();
}
}
} catch (Exception e) {
}
Expand Down