Updates to help with debugging etc. and some new code in the reorder controller.
This commit is contained in:
parent
549bebf566
commit
899ad4a8c0
2 changed files with 82 additions and 7 deletions
|
@ -8,13 +8,27 @@ import org.apache.commons.httpclient.HttpStatus;
|
|||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.hp.hpl.jena.datatypes.TypeMapper;
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
import com.hp.hpl.jena.rdf.model.Resource;
|
||||
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
||||
import com.hp.hpl.jena.rdf.model.Property;
|
||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||
import com.hp.hpl.jena.rdf.model.Literal;
|
||||
import com.hp.hpl.jena.shared.Lock;
|
||||
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.UseBasicAjaxControllers;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.ajax.VitroAjaxController;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent;
|
||||
|
||||
/**
|
||||
* This controller receives Ajax requests for reordering a list of individuals.
|
||||
|
@ -85,7 +99,56 @@ public class ReorderController extends VitroAjaxController {
|
|||
|
||||
// This may not be the most efficient way. Should we instead build up a Model of retractions and additions, so
|
||||
// we only hit the database once?
|
||||
int counter = 1;
|
||||
reorderIndividuals(individualUris, vreq, rankPredicate);
|
||||
|
||||
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
|
||||
}
|
||||
|
||||
private void reorderIndividuals(String[] individualUris, VitroRequest vreq, String rankPredicate) {
|
||||
//Testing new mechanism
|
||||
OntModel writeModel = vreq.getJenaOntModel();
|
||||
Model additions = ModelFactory.createDefaultModel();
|
||||
Model retractions = ModelFactory.createDefaultModel();
|
||||
Property rankPredicateProperty = ResourceFactory.createProperty(rankPredicate);
|
||||
DataProperty dp = vreq.getWebappDaoFactory().getDataPropertyDao().getDataPropertyByURI(rankPredicate);
|
||||
String datapropURI = dp.getRangeDatatypeURI();
|
||||
int counter = 1;
|
||||
for (String individualUri : individualUris) {
|
||||
Resource individualResource = ResourceFactory.createResource(individualUri);
|
||||
//Deletions are all old statements with rank predicate
|
||||
retractions.add(writeModel.listStatements(individualResource, rankPredicateProperty, (RDFNode) null));
|
||||
//New statement is new literal with the data property from
|
||||
Literal dataLiteral = null;
|
||||
if(datapropURI != null && datapropURI.length() > 0) {
|
||||
dataLiteral = ResourceFactory.createTypedLiteral(String.valueOf(counter), TypeMapper.getInstance().getSafeTypeByName(datapropURI));
|
||||
} else {
|
||||
dataLiteral = ResourceFactory.createPlainLiteral(String.valueOf(counter));
|
||||
|
||||
}
|
||||
additions.add(individualResource, rankPredicateProperty, dataLiteral);
|
||||
counter++;
|
||||
}
|
||||
|
||||
Lock lock = null;
|
||||
try{
|
||||
lock = writeModel.getLock();
|
||||
lock.enterCriticalSection(Lock.WRITE);
|
||||
writeModel.getBaseModel().notifyEvent(new EditEvent(null,true));
|
||||
writeModel.add( additions );
|
||||
writeModel.remove( retractions );
|
||||
}catch(Throwable t){
|
||||
log.error("error adding edit change n3required model to in memory model \n"+ t.getMessage() );
|
||||
}finally{
|
||||
writeModel.getBaseModel().notifyEvent(new EditEvent(null,false));
|
||||
lock.leaveCriticalSection();
|
||||
}
|
||||
|
||||
|
||||
//old code that for some reason doesn't seem to actually commit the changes
|
||||
/*
|
||||
* int counter = 1;
|
||||
for (String individualUri : individualUris) {
|
||||
// Retract all existing rank statements for this individual
|
||||
dpsDao.deleteDataPropertyStatementsForIndividualByDataProperty(individualUri, rankPredicate);
|
||||
|
@ -97,11 +160,11 @@ public class ReorderController extends VitroAjaxController {
|
|||
counter++;
|
||||
}
|
||||
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
protected void doError(HttpServletResponse response, String errorMsg, int httpstatus) {
|
||||
|
||||
protected void doError(HttpServletResponse response, String errorMsg, int httpstatus) {
|
||||
super.doError(response, "Error: " + errorMsg, httpstatus);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,12 +34,18 @@ import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
|||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.edit.ReorderController;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.IndividualUpdateEvent;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
public class DataPropertyStatementDaoJena extends JenaBaseDao implements DataPropertyStatementDao
|
||||
{
|
||||
private static final Log log = LogFactory.getLog(DataPropertyStatementDaoJena.class);
|
||||
|
||||
|
||||
private DatasetWrapperFactory dwf;
|
||||
|
||||
|
@ -156,7 +162,11 @@ public class DataPropertyStatementDaoJena extends JenaBaseDao implements DataPro
|
|||
Property datatypeProperty = ResourceFactory.createProperty(
|
||||
dataPropertyURI);
|
||||
ontModel.removeAll(indRes, datatypeProperty, (Literal)null);
|
||||
} finally {
|
||||
} catch(Exception ex) {
|
||||
log.error("Error occurred in removal of data property " + dataPropertyURI + " for " + individualURI);
|
||||
}
|
||||
finally {
|
||||
|
||||
getOntModel().getBaseModel().notifyEvent(new IndividualUpdateEvent(
|
||||
getWebappDaoFactory().getUserURI(),
|
||||
false,
|
||||
|
@ -280,7 +290,9 @@ public class DataPropertyStatementDaoJena extends JenaBaseDao implements DataPro
|
|||
if (res != null && prop != null && literal != null && dataPropertyStmt.getData().length()>0) {
|
||||
res.addProperty(prop, literal);
|
||||
}
|
||||
} finally {
|
||||
} catch(Exception ex){
|
||||
log.error("Error occurred in adding a data property for " + dataPropertyStmt.toString());
|
||||
}finally {
|
||||
getOntModel().getBaseModel().notifyEvent(new IndividualUpdateEvent(getWebappDaoFactory().getUserURI(),false,dataPropertyStmt.getIndividualURI()));
|
||||
ontModel.leaveCriticalSection();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue