fix: process string and untyped literals differently (#296)
* fix: process string and untyped literals differently * fix for prev commit * review fixes * fix: generators fixes * chore: removed unused imports
This commit is contained in:
parent
a4bf5030da
commit
ceebd3e422
4 changed files with 35 additions and 50 deletions
|
@ -30,6 +30,8 @@ import edu.cornell.mannlib.vitro.webapp.i18n.I18n;
|
|||
|
||||
public class MultiValueEditSubmission {
|
||||
|
||||
private static final String LABEL = "label";
|
||||
|
||||
String editKey;
|
||||
|
||||
private Map<String,List<Literal>> literalsFromForm ;
|
||||
|
@ -172,20 +174,14 @@ public class MultiValueEditSubmission {
|
|||
/* maybe this could be static */
|
||||
public Literal createLiteral(String value, String datatypeUri, String lang) {
|
||||
if( datatypeUri != null && !datatypeUri.isEmpty() ){
|
||||
// UQAM Original code contained tow-dots ':' in place of '#'
|
||||
// if( "http://www.w3.org/2001/XMLSchema:anyURI".equals(datatypeUri) ){
|
||||
if( XSD.anyURI.getURI().equals(datatypeUri) ){
|
||||
// try {
|
||||
// return literalCreationModel.createTypedLiteral( URLEncoder.encode(value, "UTF8"), datatypeUri);
|
||||
return literalCreationModel.createTypedLiteral( value, datatypeUri);
|
||||
// } catch (UnsupportedEncodingException e) {
|
||||
// log.error(e, e);
|
||||
// }
|
||||
} else if ( XSD.xstring.getURI().equals(datatypeUri) || RDF.dtLangString.getURI().equals(datatypeUri) ){
|
||||
if( lang != null && lang.length() > 0 ) return ResourceFactory.createLangLiteral(value, lang);
|
||||
} else if ( RDF.dtLangString.getURI().equals(datatypeUri) ){
|
||||
if( StringUtils.isNotEmpty(lang) ) {
|
||||
return ResourceFactory.createLangLiteral(value, lang);
|
||||
}
|
||||
}
|
||||
return literalCreationModel.createTypedLiteral(value, datatypeUri);
|
||||
// UQAM take into account the linguistic context
|
||||
} else if( lang != null && lang.length() > 0 )
|
||||
return ResourceFactory.createLangLiteral(value, lang);
|
||||
return ResourceFactory.createPlainLiteral(value);
|
||||
|
@ -311,9 +307,9 @@ public class MultiValueEditSubmission {
|
|||
}
|
||||
// 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()) && getLabelLanguage)
|
||||
if (getLabelLanguage && isLangSetInFirstLiteral(editConfig) )
|
||||
{
|
||||
rangeLang = editConfig.getLiteralsInScope().get("label").get(0).getLanguage();
|
||||
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()) {
|
||||
|
@ -323,6 +319,7 @@ public class MultiValueEditSubmission {
|
|||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error(e,e);
|
||||
}
|
||||
literalsArray.add(createLiteral(
|
||||
value,
|
||||
|
@ -336,6 +333,26 @@ public class MultiValueEditSubmission {
|
|||
log.debug("could not find value for parameter " + var );
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isLangSetInFirstLiteral(EditConfigurationVTwo editConfig) {
|
||||
Map<String, List<Literal>> literalsInScope = editConfig.getLiteralsInScope();
|
||||
if (!literalsInScope.containsKey(LABEL)) {
|
||||
return false;
|
||||
}
|
||||
List<Literal> labelLiterals = literalsInScope.get(LABEL);
|
||||
if (labelLiterals == null) {
|
||||
return false;
|
||||
}
|
||||
if (labelLiterals.size() == 0) {
|
||||
return false;
|
||||
}
|
||||
Literal literal = labelLiterals.get(0);
|
||||
if (literal == null){
|
||||
return false;
|
||||
}
|
||||
|
||||
return StringUtils.isNotEmpty(literal.getLanguage());
|
||||
}
|
||||
//Add literal to form
|
||||
//Add uri to form
|
||||
public void addUriToForm(EditConfigurationVTwo editConfig, String var, String[] valuesArray) {
|
||||
|
|
|
@ -218,7 +218,7 @@ public class ProcessRdfForm {
|
|||
if (RDF.dtLangString.getURI().equals(aLiteratDT) && !aLiteral.getLanguage().isEmpty()) {
|
||||
newLiteral = aLiteral;
|
||||
}
|
||||
else if (XSD.xstring.getURI().equals(aLiteratDT) || RDF.dtLangString.getURI().equals(aLiteratDT)) {
|
||||
else if ( RDF.dtLangString.getURI().equals(aLiteratDT)) {
|
||||
String lang = vreq.getLocale().getLanguage();
|
||||
if (!vreq.getLocale().getCountry().isEmpty()) {
|
||||
lang += "-" + vreq.getLocale().getCountry();
|
||||
|
|
|
@ -12,8 +12,8 @@ import javax.servlet.http.HttpSession;
|
|||
|
||||
import org.apache.jena.ontology.OntModel;
|
||||
import org.apache.jena.rdf.model.Literal;
|
||||
import org.apache.jena.vocabulary.RDF;
|
||||
import org.apache.jena.vocabulary.RDFS;
|
||||
import org.apache.jena.vocabulary.XSD;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
|
@ -219,7 +219,7 @@ public class NewIndividualFormGenerator implements EditConfigurationGenerator {
|
|||
VitroRequest vreq, Map<String, FieldVTwo> fields) {
|
||||
FieldVTwo field = new FieldVTwo();
|
||||
field.setName("label");
|
||||
field.setRangeDatatypeUri( XSD.xstring.toString() );
|
||||
field.setRangeDatatypeUri( RDF.dtLangString.getURI() );
|
||||
|
||||
List<String> validators = new ArrayList<String>();
|
||||
validators.add("nonempty");
|
||||
|
|
|
@ -15,11 +15,9 @@ import org.apache.commons.logging.LogFactory;
|
|||
|
||||
import org.apache.jena.ontology.OntModel;
|
||||
import org.apache.jena.rdf.model.Literal;
|
||||
import org.apache.jena.vocabulary.XSD;
|
||||
import org.apache.jena.vocabulary.RDF;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
|
||||
|
@ -216,7 +214,7 @@ public class RDFSLabelGenerator implements EditConfigurationGenerator {
|
|||
FieldVTwo field = new FieldVTwo();
|
||||
field.setName(literalName);
|
||||
//queryForExisting is not being used anywhere in Field
|
||||
String rangeDatatypeUri = getRangeDatatypeUri(editConfiguration, vreq);
|
||||
String rangeDatatypeUri = RDF.dtLangString.getURI();
|
||||
String rangeLang = getRangeLang(editConfiguration, vreq);
|
||||
|
||||
List<String> validators = getFieldValidators(editConfiguration, vreq);
|
||||
|
@ -253,43 +251,13 @@ public class RDFSLabelGenerator implements EditConfigurationGenerator {
|
|||
return rangeLang;
|
||||
}
|
||||
|
||||
private String getRangeDatatypeUri(EditConfigurationVTwo editConfiguration,
|
||||
VitroRequest vreq) {
|
||||
Individual subject = EditConfigurationUtils.getSubjectIndividual(vreq);
|
||||
DataProperty prop = EditConfigurationUtils.getDataProperty(vreq);
|
||||
String rangeDatatypeUri = null;
|
||||
//rangeDefaultJson goes into literalk options
|
||||
//validations include dataype:rangedatatypeurijson
|
||||
//rangeDatatypeUri is rangeDAttypeUriJson
|
||||
//rangeLang = rangeLanJson
|
||||
DataPropertyStatement dps =EditConfigurationUtils.getDataPropertyStatement(vreq, vreq.getSession(), dataHash, predicateUri);
|
||||
if (dps != null) {
|
||||
|
||||
rangeDatatypeUri = dps.getDatatypeURI();
|
||||
if (rangeDatatypeUri == null) {
|
||||
log.debug("no range datatype uri set on rdfs:label statement for property " + predicateUri + "in RDFSLabelGenerator");
|
||||
} else {
|
||||
log.debug("range datatype uri of [" + rangeDatatypeUri + "] on rdfs:label statement for property " + predicateUri + "in RDFSLabelGenerator");
|
||||
}
|
||||
|
||||
} else {
|
||||
log.debug("No incoming rdfs:label statement for property "+predicateUri+"; adding a new statement");
|
||||
rangeDatatypeUri = XSD.xstring.getURI();
|
||||
}
|
||||
|
||||
if( rangeDatatypeUri != null && rangeDatatypeUri.trim().length() == 0)
|
||||
rangeDatatypeUri = null;
|
||||
|
||||
return rangeDatatypeUri;
|
||||
}
|
||||
|
||||
private List<String> getFieldValidators(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
|
||||
List<String> validatorList = new ArrayList<String>();
|
||||
String predicateUri =EditConfigurationUtils.getPredicateUri(vreq);
|
||||
if (predicateUri.equals(VitroVocabulary.LABEL) || predicateUri.equals(VitroVocabulary.RDF_TYPE)) {
|
||||
validatorList.add("nonempty");
|
||||
}
|
||||
String rangeDatatypeUri = getRangeDatatypeUri(editConfiguration, vreq);
|
||||
String rangeDatatypeUri = RDF.dtLangString.getURI();
|
||||
if (rangeDatatypeUri != null && !rangeDatatypeUri.isEmpty()) {
|
||||
validatorList.add("datatype:" + rangeDatatypeUri);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue