Handle preferred language when creating new class and property groups (#383)

* Handle preferred language when creating new class and property groups

* Convert tabs to spaces in affected lines.
This commit is contained in:
Brian Lowe 2023-05-01 10:52:11 +03:00 committed by GitHub
parent dec725a022
commit c527de5ad8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 19 deletions

View file

@ -31,6 +31,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.InsertException;
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao;
import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryConfig;
public class PropertyGroupDaoJena extends JenaBaseDao implements PropertyGroupDao {
@ -142,7 +143,7 @@ public class PropertyGroupDaoJena extends JenaBaseDao implements PropertyGroupDa
edu.cornell.mannlib.vitro.webapp.beans.Individual groupInd =
new IndividualImpl(); // We should make a factory for these
groupInd.setNamespace(DEFAULT_NAMESPACE+"vitroPropertyGroup");
groupInd.setNamespace(DEFAULT_NAMESPACE + "vitroPropertyGroup");
groupInd.setName(group.getName());
groupInd.setVClassURI(PROPERTYGROUP.getURI());
groupInd.setURI(group.getURI());
@ -156,8 +157,12 @@ public class PropertyGroupDaoJena extends JenaBaseDao implements PropertyGroupDa
WebappDaoFactory wadfForURIGeneration = null;
try {
wadfForURIGeneration = new WebappDaoFactoryJena(
unionForURIGeneration);
// Ensure that the temporary WebappDaoFactory has the same
// preferred languages as the main one for this DAO.
WebappDaoFactoryConfig wadfConfig = new WebappDaoFactoryConfig();
wadfConfig.setPreferredLanguages(getWebappDaoFactory().getPreferredLanguages());
wadfForURIGeneration = new WebappDaoFactoryJena(new SimpleOntModelSelector(
unionForURIGeneration), wadfConfig, null);
groupURI = wadfForURIGeneration
.getIndividualDao().insertNewIndividual(groupInd);
} catch (InsertException ie) {
@ -183,11 +188,9 @@ public class PropertyGroupDaoJena extends JenaBaseDao implements PropertyGroupDa
if (group.getPublicDescription() != null
&& group.getPublicDescription().length()>0) {
try {
groupJenaInd.addProperty(
PUBLIC_DESCRIPTION_ANNOT,
group.getPublicDescription(),
XSDDatatype.XSDstring);
} catch (Exception ex) {
updatePlainLiteralValue(groupJenaInd, PUBLIC_DESCRIPTION_ANNOT,
group.getPublicDescription(), getDefaultLanguage());
} catch (Exception ex) {
log.error(
"error setting public description for "
+ groupInd.getURI());
@ -225,15 +228,13 @@ public class PropertyGroupDaoJena extends JenaBaseDao implements PropertyGroupDa
try {
Individual groupInd = ontModel.getIndividual(group.getURI());
try {
groupInd.setLabel(group.getName(), getDefaultLanguage());
updateRDFSLabel(groupInd, group.getName(), getDefaultLanguage());
} catch (Exception e) {
log.error("error updating name for "+groupInd.getURI());
}
try {
groupInd.removeAll(PUBLIC_DESCRIPTION_ANNOT);
if (group.getPublicDescription()!=null && group.getPublicDescription().length()>0) {
groupInd.addProperty(PUBLIC_DESCRIPTION_ANNOT, group.getPublicDescription(), XSDDatatype.XSDstring);
}
updatePlainLiteralValue(groupInd, PUBLIC_DESCRIPTION_ANNOT,
group.getPublicDescription(), getDefaultLanguage());
} catch (Exception e) {
log.error("Error updating public description for "+groupInd.getURI());
}

View file

@ -5,14 +5,12 @@ package edu.cornell.mannlib.vitro.webapp.dao.jena;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.ListIterator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.jena.datatypes.xsd.XSDDatatype;
import org.apache.jena.ontology.Individual;
import org.apache.jena.ontology.OntModel;
@ -30,6 +28,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.InsertException;
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryConfig;
public class VClassGroupDaoJena extends JenaBaseDao implements VClassGroupDao {
@ -191,9 +190,9 @@ public class VClassGroupDaoJena extends JenaBaseDao implements VClassGroupDao {
edu.cornell.mannlib.vitro.webapp.beans.Individual groupInd =
new IndividualImpl(); // We should make a factory for these
groupInd.setURI(vcg.getURI());
groupInd.setNamespace(DEFAULT_NAMESPACE+"vitroClassGroup");
groupInd.setName(vcg.getPublicName());
groupInd.setNamespace(DEFAULT_NAMESPACE + "vitroClassGroup");
groupInd.setVClassURI(CLASSGROUP.getURI());
groupInd.setName(vcg.getPublicName());
String groupURI = null;
@ -204,8 +203,12 @@ public class VClassGroupDaoJena extends JenaBaseDao implements VClassGroupDao {
WebappDaoFactory wadfForURIGeneration = null;
try {
wadfForURIGeneration = new WebappDaoFactoryJena(
unionForURIGeneration);
// Ensure that the temporary WebappDaoFactory has the same
// preferred languages as the main one for this DAO.
WebappDaoFactoryConfig wadfConfig = new WebappDaoFactoryConfig();
wadfConfig.setPreferredLanguages(getWebappDaoFactory().getPreferredLanguages());
wadfForURIGeneration = new WebappDaoFactoryJena(new SimpleOntModelSelector(
unionForURIGeneration), wadfConfig, null);
groupURI = wadfForURIGeneration
.getIndividualDao().insertNewIndividual(groupInd);
} catch (InsertException ie) {