fix: retain language tags on editing data properties with backend editor (#315)
* fix: retain language tags on editing data properties with backend editor * fix: replace label in backend editor in default language. Avoid side effect of removing all other labels.
This commit is contained in:
parent
acd2bf6a59
commit
6c95f5ab38
6 changed files with 63 additions and 12 deletions
|
@ -8,6 +8,7 @@ public class DynamicFieldRow {
|
||||||
|
|
||||||
private int id = -1;
|
private int id = -1;
|
||||||
private String value = null;
|
private String value = null;
|
||||||
|
private String language = "";
|
||||||
private Map parameterMap = null;
|
private Map parameterMap = null;
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
|
@ -34,4 +35,13 @@ public class DynamicFieldRow {
|
||||||
this.parameterMap = parameterMap;
|
this.parameterMap = parameterMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getLanguage() {
|
||||||
|
return language;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLanguage(String language) {
|
||||||
|
if (language != null) {
|
||||||
|
this.language = language;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,10 +23,14 @@ import edu.cornell.mannlib.vedit.beans.FormObject;
|
||||||
import edu.cornell.mannlib.vedit.beans.DynamicField;
|
import edu.cornell.mannlib.vedit.beans.DynamicField;
|
||||||
import edu.cornell.mannlib.vedit.beans.DynamicFieldRow;
|
import edu.cornell.mannlib.vedit.beans.DynamicFieldRow;
|
||||||
import org.apache.commons.codec.binary.Base64;
|
import org.apache.commons.codec.binary.Base64;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vedit.tags.EditTag;
|
import edu.cornell.mannlib.vedit.tags.EditTag;
|
||||||
|
|
||||||
public class DynamicFieldsTag extends EditTag {
|
public class DynamicFieldsTag extends EditTag {
|
||||||
|
|
||||||
|
private static final String LANGUAGE = "language";
|
||||||
|
|
||||||
private char PATH_SEP = File.separatorChar;
|
private char PATH_SEP = File.separatorChar;
|
||||||
|
|
||||||
public final String MARKUP_FILE_PATH = "templates"+PATH_SEP+"edit"+PATH_SEP+"specific"+PATH_SEP;
|
public final String MARKUP_FILE_PATH = "templates"+PATH_SEP+"edit"+PATH_SEP+"specific"+PATH_SEP;
|
||||||
|
@ -175,7 +179,12 @@ public class DynamicFieldsTag extends EditTag {
|
||||||
String key = (String) paramIt.next();
|
String key = (String) paramIt.next();
|
||||||
String value = (String) row.getParameterMap().get(key);
|
String value = (String) row.getParameterMap().get(key);
|
||||||
byte[] valueInBase64 = Base64.encodeBase64(value.getBytes());
|
byte[] valueInBase64 = Base64.encodeBase64(value.getBytes());
|
||||||
taName.append(key).append(":").append(new String(valueInBase64)).append(";");
|
taName.append(key).append(":").append(new String(valueInBase64));
|
||||||
|
if (StringUtils.isNotBlank(row.getLanguage())) {
|
||||||
|
byte[] encodedLang = Base64.encodeBase64(row.getLanguage().getBytes());
|
||||||
|
taName.append(":").append(LANGUAGE).append(":").append(new String(encodedLang));
|
||||||
|
}
|
||||||
|
taName.append(";");
|
||||||
}
|
}
|
||||||
if (row.getValue().length() > 0) {
|
if (row.getValue().length() > 0) {
|
||||||
String templateWithVars = templateMarkup;
|
String templateWithVars = templateMarkup;
|
||||||
|
|
|
@ -369,6 +369,9 @@ public class FormUtils {
|
||||||
for (String aParam : param) {
|
for (String aParam : param) {
|
||||||
String[] p = aParam.split(":");
|
String[] p = aParam.split(":");
|
||||||
beanParamMap.put(p[0], new String(Base64.decodeBase64(p[1].getBytes())));
|
beanParamMap.put(p[0], new String(Base64.decodeBase64(p[1].getBytes())));
|
||||||
|
if (p.length > 3) {
|
||||||
|
beanParamMap.put(p[2], new String(Base64.decodeBase64(p[3].getBytes())));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return beanParamMap;
|
return beanParamMap;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,9 +20,12 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.JSPPageHandler;
|
import edu.cornell.mannlib.vitro.webapp.utils.JSPPageHandler;
|
||||||
import org.apache.commons.collections4.map.ListOrderedMap;
|
import org.apache.commons.collections4.map.ListOrderedMap;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import com.ctc.wstx.util.StringUtil;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vedit.beans.DynamicField;
|
import edu.cornell.mannlib.vedit.beans.DynamicField;
|
||||||
import edu.cornell.mannlib.vedit.beans.DynamicFieldRow;
|
import edu.cornell.mannlib.vedit.beans.DynamicFieldRow;
|
||||||
import edu.cornell.mannlib.vedit.beans.EditProcessObject;
|
import edu.cornell.mannlib.vedit.beans.EditProcessObject;
|
||||||
|
@ -250,7 +253,12 @@ public class EntityRetryController extends BaseEditController {
|
||||||
//TODO: UGH
|
//TODO: UGH
|
||||||
//row.setId(existingValue.getId());
|
//row.setId(existingValue.getId());
|
||||||
row.setParameterMap(parameterMap);
|
row.setParameterMap(parameterMap);
|
||||||
row.setValue(existingValue.getData());
|
String value = existingValue.getData();
|
||||||
|
row.setValue(value);
|
||||||
|
String language = existingValue.getLanguage();
|
||||||
|
if (!StringUtils.isBlank(language)) {
|
||||||
|
row.setLanguage(language);
|
||||||
|
}
|
||||||
if (dynamo.getRowList() == null)
|
if (dynamo.getRowList() == null)
|
||||||
dynamo.setRowList(new ArrayList());
|
dynamo.setRowList(new ArrayList());
|
||||||
dynamo.getRowList().add(row);
|
dynamo.getRowList().add(row);
|
||||||
|
|
|
@ -14,6 +14,7 @@ import java.util.Random;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.lang3.NotImplementedException;
|
import org.apache.commons.lang3.NotImplementedException;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
@ -286,15 +287,14 @@ public class IndividualDaoJena extends JenaBaseDao implements IndividualDao {
|
||||||
ontModel.getBaseModel().notifyEvent(new IndividualUpdateEvent(getWebappDaoFactory().getUserURI(),true,ent.getURI()));
|
ontModel.getBaseModel().notifyEvent(new IndividualUpdateEvent(getWebappDaoFactory().getUserURI(),true,ent.getURI()));
|
||||||
org.apache.jena.ontology.Individual ind = ontModel.getIndividual(ent.getURI());
|
org.apache.jena.ontology.Individual ind = ontModel.getIndividual(ent.getURI());
|
||||||
if (ind != null) {
|
if (ind != null) {
|
||||||
if (ent.getName() != null && ( (ind.getLabel(getDefaultLanguage())==null) || (ind.getLabel(getDefaultLanguage())!=null && ent.getName()!=null && !ent.getName().equals(ind.getLabel(getDefaultLanguage())) ) ) ) {
|
|
||||||
|
String newLabel = ent.getName();
|
||||||
// removal of existing values done this odd way to trigger
|
String oldLabel = ind.getLabel(getDefaultLanguage());
|
||||||
// the change listeners
|
if ( newLabel != null && !newLabel.equals(oldLabel) ) {
|
||||||
Model temp = ModelFactory.createDefaultModel();
|
if (oldLabel == null) {
|
||||||
temp.add(ontModel.listStatements(ind, RDFS.label, (RDFNode) null));
|
oldLabel = "";
|
||||||
ontModel.remove(temp);
|
}
|
||||||
|
replaceOldLabelWithNewInDefaultLanguage(ontModel, ind, newLabel, oldLabel);
|
||||||
ind.setLabel(ent.getName(), getDefaultLanguage());
|
|
||||||
}
|
}
|
||||||
Set<String> oldTypeURIsSet = new HashSet<String>();
|
Set<String> oldTypeURIsSet = new HashSet<String>();
|
||||||
for (Iterator<Resource> typeIt = ind.listRDFTypes(true); typeIt.hasNext();) {
|
for (Iterator<Resource> typeIt = ind.listRDFTypes(true); typeIt.hasNext();) {
|
||||||
|
@ -347,6 +347,23 @@ public class IndividualDaoJena extends JenaBaseDao implements IndividualDao {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void replaceOldLabelWithNewInDefaultLanguage(OntModel ontModel, org.apache.jena.ontology.Individual ind,
|
||||||
|
final String newLabel, final String oldLabel) {
|
||||||
|
Model temp = ModelFactory.createDefaultModel();
|
||||||
|
StmtIterator statements = ontModel.listStatements(ind, RDFS.label, (RDFNode) null);
|
||||||
|
while (statements.hasNext()) {
|
||||||
|
Statement statement = (Statement) statements.next();
|
||||||
|
Literal object = statement.getLiteral();
|
||||||
|
String lexicalForm = object.getLexicalForm();
|
||||||
|
String language = object.getLanguage();
|
||||||
|
if (oldLabel.equals(lexicalForm) && language.equals(getDefaultLanguage()) ) {
|
||||||
|
temp.add(statement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ontModel.remove(temp);
|
||||||
|
ind.addLabel(newLabel, getDefaultLanguage());
|
||||||
|
}
|
||||||
|
|
||||||
public void markModified(Individual ind) {
|
public void markModified(Individual ind) {
|
||||||
markModified(ind,getOntModel());
|
markModified(ind,getOntModel());
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,8 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.BasicValidationVTwo;
|
||||||
|
|
||||||
public class IndividualDataPropertyStatementProcessor implements ChangeListener {
|
public class IndividualDataPropertyStatementProcessor implements ChangeListener {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(IndividualDataPropertyStatementProcessor.class.getName());
|
private static final String LANGUAGE = "language";
|
||||||
|
private static final Log log = LogFactory.getLog(IndividualDataPropertyStatementProcessor.class.getName());
|
||||||
|
|
||||||
public void doInserted(Object newObj, EditProcessObject epo) {
|
public void doInserted(Object newObj, EditProcessObject epo) {
|
||||||
processDataprops(epo);
|
processDataprops(epo);
|
||||||
|
@ -53,6 +54,9 @@ public class IndividualDataPropertyStatementProcessor implements ChangeListener
|
||||||
try {
|
try {
|
||||||
Map beanParamMap = FormUtils.beanParamMapFromString(keyArg[3]);
|
Map beanParamMap = FormUtils.beanParamMapFromString(keyArg[3]);
|
||||||
String dataPropertyURI = (String) beanParamMap.get("DatatypePropertyURI");
|
String dataPropertyURI = (String) beanParamMap.get("DatatypePropertyURI");
|
||||||
|
if (beanParamMap.containsKey(LANGUAGE)) {
|
||||||
|
dataPropertyStmt.setLanguage((String) beanParamMap.get(LANGUAGE));
|
||||||
|
}
|
||||||
if (!deletedDataPropertyURIs.contains(dataPropertyURI)) {
|
if (!deletedDataPropertyURIs.contains(dataPropertyURI)) {
|
||||||
deletedDataPropertyURIs.add(dataPropertyURI);
|
deletedDataPropertyURIs.add(dataPropertyURI);
|
||||||
dataPropertyStatementDao.deleteDataPropertyStatementsForIndividualByDataProperty(((Individual) epo.getNewBean()).getURI(), dataPropertyURI);
|
dataPropertyStatementDao.deleteDataPropertyStatementsForIndividualByDataProperty(((Individual) epo.getNewBean()).getURI(), dataPropertyURI);
|
||||||
|
|
Loading…
Add table
Reference in a new issue