NIHVIVO-1761 bugfix for backend property deletion
This commit is contained in:
parent
46739ea3cd
commit
aad1ea806b
8 changed files with 139 additions and 54 deletions
|
@ -215,7 +215,10 @@ public class OperationController extends BaseEditController {
|
|||
Object newObj = null;
|
||||
if (epo.getOriginalBean() != null) { // we're updating or deleting an existing bean
|
||||
if (epo.getImplementationClass() != null) {
|
||||
newObj = OperationUtils.cloneBean(epo.getOriginalBean(), epo.getImplementationClass());
|
||||
newObj = OperationUtils.cloneBean(
|
||||
epo.getOriginalBean(),
|
||||
epo.getImplementationClass(),
|
||||
epo.getBeanClass());
|
||||
} else {
|
||||
newObj = OperationUtils.cloneBean(epo.getOriginalBean());
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ public class OperationUtils{
|
|||
* @return
|
||||
*/
|
||||
public static Object cloneBean (Object bean) {
|
||||
return cloneBean(bean, bean.getClass());
|
||||
return cloneBean(bean, bean.getClass(), bean.getClass());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -76,39 +76,61 @@ public class OperationUtils{
|
|||
* @param bean
|
||||
* @return
|
||||
*/
|
||||
public static Object cloneBean (Object bean, Class beanClass){
|
||||
public static Object cloneBean (Object bean, Class beanClass, Class iface){
|
||||
Object newBean = null;
|
||||
try {
|
||||
newBean = beanClass.newInstance();
|
||||
Method[] beanMeths = beanClass.getMethods();
|
||||
Method[] beanMeths = iface.getMethods();
|
||||
for (int i=0; i<beanMeths.length ; ++i) {
|
||||
String methName = beanMeths[i].getName();
|
||||
if (methName.indexOf("get")==0){
|
||||
Method beanMeth = beanMeths[i];
|
||||
String methName = beanMeth.getName();
|
||||
if (methName.startsWith("get")
|
||||
&& beanMeth.getParameterTypes().length == 0 ) {
|
||||
String fieldName = methName.substring(3,methName.length());
|
||||
Class returnType = beanMeths[i].getReturnType();
|
||||
Class returnType = beanMeth.getReturnType();
|
||||
try {
|
||||
Class[] args = new Class[1];
|
||||
args[0] = returnType;
|
||||
Method setterMethod = beanClass.getMethod("set"+fieldName,args);
|
||||
Method setterMethod = iface.getMethod("set"+fieldName,args);
|
||||
try {
|
||||
Object fieldVal = beanMeths[i].invoke(bean,(Object[])null);
|
||||
Object fieldVal = beanMeth.invoke(bean,(Object[])null);
|
||||
try {
|
||||
Object[] setArgs = new Object[1];
|
||||
setArgs[0] = fieldVal;
|
||||
setterMethod.invoke(newBean,setArgs);
|
||||
} catch (IllegalAccessException iae) {
|
||||
log.error("edu.cornell.mannlib.vitro.edit.utils.OperationUtils encountered IllegalAccessException invoking "+setterMethod.getName());
|
||||
log.error(OperationUtils.class.getName() +
|
||||
".cloneBean() " +
|
||||
" encountered IllegalAccessException " +
|
||||
" invoking " +
|
||||
setterMethod.getName(), iae);
|
||||
throw new RuntimeException(iae);
|
||||
} catch (InvocationTargetException ite) {
|
||||
log.error("edu.cornell.mannlib.vitro.edit.utils.OperationUtils encountered InvocationTargetException invoking "+setterMethod.getName());
|
||||
log.error(ite.getTargetException().getClass().toString());
|
||||
log.error(OperationUtils.class.getName() +
|
||||
".cloneBean() " +
|
||||
" encountered InvocationTargetException"
|
||||
+ " invoking "
|
||||
+ setterMethod.getName(), ite);
|
||||
throw new RuntimeException(ite);
|
||||
}
|
||||
} catch (IllegalAccessException iae) {
|
||||
log.error(OperationUtils.class.getName()+" encountered IllegalAccessException invoking "+beanMeths[i].getName());
|
||||
log.error(OperationUtils.class.getName() +
|
||||
".cloneBean() encountered " +
|
||||
" IllegalAccessException invoking " +
|
||||
beanMeths[i].getName(), iae);
|
||||
throw new RuntimeException(iae);
|
||||
} catch (InvocationTargetException ite) {
|
||||
log.error(OperationUtils.class.getName()+" encountered InvocationTargetException invoking "+beanMeths[i].getName());
|
||||
log.error(ite.getTargetException().getClass().toString());
|
||||
log.error(OperationUtils.class.getName() +
|
||||
".cloneBean() encountered " +
|
||||
" InvocationTargetException invoking " +
|
||||
beanMeths[i].getName(), ite);
|
||||
throw new RuntimeException(ite);
|
||||
} catch (IllegalArgumentException iae) {
|
||||
// log.error(OperationUtils.class.getName()+" found that "+beanMeths[i].getName()+" requires one or more arguments. Skipping.");
|
||||
log.error(OperationUtils.class.getName() +
|
||||
".cloneBean() encountered " +
|
||||
" IllegalArgumentException invoking " +
|
||||
beanMeths[i].getName(), iae);
|
||||
throw new RuntimeException(iae);
|
||||
}
|
||||
} catch (NoSuchMethodException nsme){
|
||||
// ignore this field because there is no setter method
|
||||
|
|
|
@ -65,25 +65,39 @@ public class DataPropertyStatementDaoJena extends JenaBaseDao implements DataPro
|
|||
this.dwf = dwf;
|
||||
}
|
||||
|
||||
public void deleteDataPropertyStatement(DataPropertyStatement dataPropertyStmt) {
|
||||
deleteDataPropertyStatement(dataPropertyStmt, getOntModelSelector().getABoxModel());
|
||||
}
|
||||
|
||||
public void deleteDataPropertyStatement( DataPropertyStatement dataPropertyStatement, OntModel ontModel )
|
||||
public void deleteDataPropertyStatement( DataPropertyStatement dataPropertyStatement )
|
||||
{
|
||||
OntModel ontModel = getOntModelSelector().getABoxModel();
|
||||
try {
|
||||
ontModel.enterCriticalSection(Lock.WRITE);
|
||||
getOntModel().getBaseModel().notifyEvent(new IndividualUpdateEvent(getWebappDaoFactory().getUserURI(),true,dataPropertyStatement.getIndividualURI()));
|
||||
com.hp.hpl.jena.ontology.Individual ind = ontModel.getIndividual(dataPropertyStatement.getIndividualURI());
|
||||
Property prop = ontModel.getProperty(dataPropertyStatement.getDatapropURI());
|
||||
Literal l = jenaLiteralFromDataPropertyStatement(dataPropertyStatement, ontModel);
|
||||
getOntModel().getBaseModel().notifyEvent(
|
||||
new IndividualUpdateEvent(
|
||||
getWebappDaoFactory().getUserURI(),
|
||||
true,
|
||||
dataPropertyStatement.getIndividualURI()));
|
||||
com.hp.hpl.jena.ontology.Individual ind = ontModel.getIndividual(
|
||||
dataPropertyStatement.getIndividualURI());
|
||||
OntModel tboxModel = getOntModelSelector().getTBoxModel();
|
||||
tboxModel.enterCriticalSection(Lock.READ);
|
||||
try {
|
||||
Property prop = tboxModel.getProperty(
|
||||
dataPropertyStatement.getDatapropURI());
|
||||
Literal l = jenaLiteralFromDataPropertyStatement(
|
||||
dataPropertyStatement, ontModel);
|
||||
if (ind != null && prop != null && l != null) {
|
||||
ontModel.getBaseModel().remove(ind, prop, l);
|
||||
}
|
||||
} finally {
|
||||
getOntModel().getBaseModel().notifyEvent(new IndividualUpdateEvent(getWebappDaoFactory().getUserURI(),false,dataPropertyStatement.getIndividualURI()));
|
||||
tboxModel.leaveCriticalSection();
|
||||
}
|
||||
} finally {
|
||||
getOntModel().getBaseModel().notifyEvent(
|
||||
new IndividualUpdateEvent(
|
||||
getWebappDaoFactory().getUserURI(),
|
||||
false,
|
||||
dataPropertyStatement.getIndividualURI()));
|
||||
ontModel.leaveCriticalSection();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -143,19 +157,29 @@ public class DataPropertyStatementDaoJena extends JenaBaseDao implements DataPro
|
|||
deleteDataPropertyStatementsForIndividualByDataProperty(individualURI, dataPropertyURI, getOntModelSelector().getABoxModel());
|
||||
}
|
||||
|
||||
public void deleteDataPropertyStatementsForIndividualByDataProperty(String individualURI, String dataPropertyURI, OntModel ontModel) {
|
||||
public void deleteDataPropertyStatementsForIndividualByDataProperty(
|
||||
String individualURI,
|
||||
String dataPropertyURI,
|
||||
OntModel ontModel) {
|
||||
|
||||
ontModel.enterCriticalSection(Lock.WRITE);
|
||||
getOntModel().getBaseModel().notifyEvent(new IndividualUpdateEvent(getWebappDaoFactory().getUserURI(),true,individualURI));
|
||||
getOntModel().getBaseModel().notifyEvent(new IndividualUpdateEvent(
|
||||
getWebappDaoFactory().getUserURI(),
|
||||
true,
|
||||
individualURI));
|
||||
try {
|
||||
Resource indRes = ontModel.getResource(individualURI);
|
||||
DatatypeProperty datatypeProperty = ontModel.getDatatypeProperty(dataPropertyURI);
|
||||
if (indRes != null && datatypeProperty != null) {
|
||||
Resource indRes = ResourceFactory.createResource(individualURI);
|
||||
Property datatypeProperty = ResourceFactory.createProperty(
|
||||
dataPropertyURI);
|
||||
ontModel.removeAll(indRes, datatypeProperty, (Literal)null);
|
||||
}
|
||||
} finally {
|
||||
getOntModel().getBaseModel().notifyEvent(new IndividualUpdateEvent(getWebappDaoFactory().getUserURI(),false,individualURI));
|
||||
getOntModel().getBaseModel().notifyEvent(new IndividualUpdateEvent(
|
||||
getWebappDaoFactory().getUserURI(),
|
||||
false,
|
||||
individualURI));
|
||||
ontModel.leaveCriticalSection();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void deleteDataPropertyStatementsForIndividualByDataProperty(Individual individual, DataProperty dataProperty) {
|
||||
|
|
|
@ -24,6 +24,7 @@ import com.hp.hpl.jena.ontology.OntModel;
|
|||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||
import com.hp.hpl.jena.ontology.OntResource;
|
||||
import com.hp.hpl.jena.query.Dataset;
|
||||
import com.hp.hpl.jena.query.Query;
|
||||
import com.hp.hpl.jena.query.QueryExecution;
|
||||
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
||||
import com.hp.hpl.jena.query.QueryFactory;
|
||||
|
@ -427,7 +428,7 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
|||
if (sunrise != null) {
|
||||
return sunrise;
|
||||
} else {
|
||||
|
||||
constructProperty(ind, VitroVocabulary.SUNRISE);
|
||||
ind.getOntModel().enterCriticalSection(Lock.READ);
|
||||
try {
|
||||
sunrise = webappDaoFactory.getJenaBaseDao()
|
||||
|
@ -435,7 +436,6 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
|||
ind,webappDaoFactory.getJenaBaseDao().SUNRISE);
|
||||
return sunrise;
|
||||
} finally {
|
||||
|
||||
ind.getOntModel().leaveCriticalSection();
|
||||
}
|
||||
}
|
||||
|
@ -445,7 +445,7 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
|||
if (sunset != null) {
|
||||
return sunset;
|
||||
} else {
|
||||
|
||||
constructProperty(ind, VitroVocabulary.SUNSET);
|
||||
ind.getOntModel().enterCriticalSection(Lock.READ);
|
||||
try {
|
||||
sunset = webappDaoFactory.getJenaBaseDao()
|
||||
|
@ -463,7 +463,7 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
|||
if (timekey != null) {
|
||||
return timekey;
|
||||
} else {
|
||||
|
||||
constructProperty(ind, VitroVocabulary.TIMEKEY);
|
||||
ind.getOntModel().enterCriticalSection(Lock.READ);
|
||||
try {
|
||||
timekey = webappDaoFactory.getJenaBaseDao()
|
||||
|
@ -554,7 +554,7 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
|||
if (this.blurb != null) {
|
||||
return blurb;
|
||||
} else {
|
||||
|
||||
constructProperty(ind, VitroVocabulary.BLURB);
|
||||
ind.getOntModel().enterCriticalSection(Lock.READ);
|
||||
try {
|
||||
blurb = webappDaoFactory.getJenaBaseDao().getPropertyStringValue(ind,webappDaoFactory.getJenaBaseDao().BLURB);
|
||||
|
@ -570,7 +570,7 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
|||
if (this.description != null) {
|
||||
return description;
|
||||
} else {
|
||||
|
||||
constructProperty(ind, VitroVocabulary.DESCRIPTION);
|
||||
ind.getOntModel().enterCriticalSection(Lock.READ);
|
||||
try {
|
||||
description = webappDaoFactory.getJenaBaseDao()
|
||||
|
@ -584,6 +584,24 @@ public class IndividualSDB extends IndividualImpl implements Individual {
|
|||
}
|
||||
}
|
||||
|
||||
private synchronized void constructProperty(OntResource ind, String propertyURI) {
|
||||
DatasetWrapper w = getDatasetWrapper();
|
||||
Dataset dataset = w.getDataset();
|
||||
dataset.getLock().enterCriticalSection(Lock.READ);
|
||||
try {
|
||||
String queryStr = "CONSTRUCT { ?ind <" +
|
||||
propertyURI + "> ?value } \n" +
|
||||
"WHERE { GRAPH ?g { ?ind <" +
|
||||
propertyURI + "> ?value } } \n";
|
||||
Query query = QueryFactory.create(queryStr);
|
||||
QueryExecution qe = QueryExecutionFactory.create(
|
||||
query, dataset);
|
||||
qe.execConstruct(ind.getModel());
|
||||
} finally {
|
||||
dataset.getLock().leaveCriticalSection();
|
||||
w.close();
|
||||
}
|
||||
}
|
||||
|
||||
public Float getSearchBoost(){
|
||||
if( this._searchBoostJena != null ){
|
||||
|
|
|
@ -142,7 +142,6 @@ public class JenaBaseDao extends JenaBaseDaoCon {
|
|||
protected void addPropertyStringValue(Resource res, Property dataprop, String value, Model model) {
|
||||
if (res != null && dataprop != null && value != null && value.length()>0) {
|
||||
model.add(res, dataprop, value, XSDDatatype.XSDstring);
|
||||
System.out.println("JenaBaseDao" + value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
|
|||
"PREFIX owl: <http://www.w3.org/2002/07/owl#> \n" +
|
||||
"PREFIX afn: <http://jena.hpl.hp.com/ARQ/function#>";
|
||||
|
||||
private DatasetWrapperFactory dwf;
|
||||
protected DatasetWrapperFactory dwf;
|
||||
|
||||
public PropertyDaoJena(DatasetWrapperFactory dwf,
|
||||
WebappDaoFactoryJena wadf) {
|
||||
|
|
|
@ -118,6 +118,7 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
|
|||
this.userURI = userURI;
|
||||
this.flag2ValueMap = base.flag2ValueMap;
|
||||
this.flag2ClassLabelMap = base.flag2ClassLabelMap;
|
||||
this.dwf = base.dwf;
|
||||
}
|
||||
|
||||
public WebappDaoFactoryJena(OntModelSelector ontModelSelector,
|
||||
|
|
|
@ -18,6 +18,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
|
|||
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyStatementDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
|
||||
public class WebappDaoFactorySDB extends WebappDaoFactoryJena {
|
||||
|
||||
|
@ -63,6 +64,18 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena {
|
|||
this.dwf = new ReconnectingDatasetFactory(bds, storeDesc);
|
||||
}
|
||||
|
||||
public WebappDaoFactorySDB(WebappDaoFactorySDB base, String userURI) {
|
||||
super(base.ontModelSelector);
|
||||
this.ontModelSelector = base.ontModelSelector;
|
||||
this.defaultNamespace = base.defaultNamespace;
|
||||
this.nonuserNamespaces = base.nonuserNamespaces;
|
||||
this.preferredLanguages = base.preferredLanguages;
|
||||
this.userURI = userURI;
|
||||
this.flag2ValueMap = base.flag2ValueMap;
|
||||
this.flag2ClassLabelMap = base.flag2ClassLabelMap;
|
||||
this.dwf = base.dwf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IndividualDao getIndividualDao() {
|
||||
if (entityWebappDao != null)
|
||||
|
@ -95,6 +108,11 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena {
|
|||
return vClassDao = new VClassDaoSDB(dwf, this);
|
||||
}
|
||||
|
||||
public WebappDaoFactory getUserAwareDaoFactory(String userURI) {
|
||||
// TODO: put the user-aware factories in a hashmap so we don't keep re-creating them
|
||||
return new WebappDaoFactorySDB(this, userURI);
|
||||
}
|
||||
|
||||
private class ReconnectingDatasetFactory implements DatasetWrapperFactory {
|
||||
|
||||
private BasicDataSource _bds;
|
||||
|
|
Loading…
Add table
Reference in a new issue