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.ObjectPropertyDao;
import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao; import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryConfig;
public class PropertyGroupDaoJena extends JenaBaseDao implements PropertyGroupDao { 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 = edu.cornell.mannlib.vitro.webapp.beans.Individual groupInd =
new IndividualImpl(); // We should make a factory for these new IndividualImpl(); // We should make a factory for these
groupInd.setNamespace(DEFAULT_NAMESPACE+"vitroPropertyGroup"); groupInd.setNamespace(DEFAULT_NAMESPACE + "vitroPropertyGroup");
groupInd.setName(group.getName()); groupInd.setName(group.getName());
groupInd.setVClassURI(PROPERTYGROUP.getURI()); groupInd.setVClassURI(PROPERTYGROUP.getURI());
groupInd.setURI(group.getURI()); groupInd.setURI(group.getURI());
@ -156,8 +157,12 @@ public class PropertyGroupDaoJena extends JenaBaseDao implements PropertyGroupDa
WebappDaoFactory wadfForURIGeneration = null; WebappDaoFactory wadfForURIGeneration = null;
try { try {
wadfForURIGeneration = new WebappDaoFactoryJena( // Ensure that the temporary WebappDaoFactory has the same
unionForURIGeneration); // 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 groupURI = wadfForURIGeneration
.getIndividualDao().insertNewIndividual(groupInd); .getIndividualDao().insertNewIndividual(groupInd);
} catch (InsertException ie) { } catch (InsertException ie) {
@ -183,11 +188,9 @@ public class PropertyGroupDaoJena extends JenaBaseDao implements PropertyGroupDa
if (group.getPublicDescription() != null if (group.getPublicDescription() != null
&& group.getPublicDescription().length()>0) { && group.getPublicDescription().length()>0) {
try { try {
groupJenaInd.addProperty( updatePlainLiteralValue(groupJenaInd, PUBLIC_DESCRIPTION_ANNOT,
PUBLIC_DESCRIPTION_ANNOT, group.getPublicDescription(), getDefaultLanguage());
group.getPublicDescription(), } catch (Exception ex) {
XSDDatatype.XSDstring);
} catch (Exception ex) {
log.error( log.error(
"error setting public description for " "error setting public description for "
+ groupInd.getURI()); + groupInd.getURI());
@ -225,15 +228,13 @@ public class PropertyGroupDaoJena extends JenaBaseDao implements PropertyGroupDa
try { try {
Individual groupInd = ontModel.getIndividual(group.getURI()); Individual groupInd = ontModel.getIndividual(group.getURI());
try { try {
groupInd.setLabel(group.getName(), getDefaultLanguage()); updateRDFSLabel(groupInd, group.getName(), getDefaultLanguage());
} catch (Exception e) { } catch (Exception e) {
log.error("error updating name for "+groupInd.getURI()); log.error("error updating name for "+groupInd.getURI());
} }
try { try {
groupInd.removeAll(PUBLIC_DESCRIPTION_ANNOT); updatePlainLiteralValue(groupInd, PUBLIC_DESCRIPTION_ANNOT,
if (group.getPublicDescription()!=null && group.getPublicDescription().length()>0) { group.getPublicDescription(), getDefaultLanguage());
groupInd.addProperty(PUBLIC_DESCRIPTION_ANNOT, group.getPublicDescription(), XSDDatatype.XSDstring);
}
} catch (Exception e) { } catch (Exception e) {
log.error("Error updating public description for "+groupInd.getURI()); 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.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
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 org.apache.jena.datatypes.xsd.XSDDatatype; import org.apache.jena.datatypes.xsd.XSDDatatype;
import org.apache.jena.ontology.Individual; import org.apache.jena.ontology.Individual;
import org.apache.jena.ontology.OntModel; 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.VClassDao;
import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryConfig;
public class VClassGroupDaoJena extends JenaBaseDao implements VClassGroupDao { 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 = edu.cornell.mannlib.vitro.webapp.beans.Individual groupInd =
new IndividualImpl(); // We should make a factory for these new IndividualImpl(); // We should make a factory for these
groupInd.setURI(vcg.getURI()); groupInd.setURI(vcg.getURI());
groupInd.setNamespace(DEFAULT_NAMESPACE+"vitroClassGroup"); groupInd.setNamespace(DEFAULT_NAMESPACE + "vitroClassGroup");
groupInd.setName(vcg.getPublicName());
groupInd.setVClassURI(CLASSGROUP.getURI()); groupInd.setVClassURI(CLASSGROUP.getURI());
groupInd.setName(vcg.getPublicName());
String groupURI = null; String groupURI = null;
@ -204,8 +203,12 @@ public class VClassGroupDaoJena extends JenaBaseDao implements VClassGroupDao {
WebappDaoFactory wadfForURIGeneration = null; WebappDaoFactory wadfForURIGeneration = null;
try { try {
wadfForURIGeneration = new WebappDaoFactoryJena( // Ensure that the temporary WebappDaoFactory has the same
unionForURIGeneration); // 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 groupURI = wadfForURIGeneration
.getIndividualDao().insertNewIndividual(groupInd); .getIndividualDao().insertNewIndividual(groupInd);
} catch (InsertException ie) { } catch (InsertException ie) {