Merge branch 'develop' of github.com:vivo-project/Vitro into develop

This commit is contained in:
Brian Caruso 2013-10-15 16:08:49 -04:00
commit 08dab8e52f
27 changed files with 627 additions and 158 deletions

View file

@ -15,6 +15,7 @@ import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.display.DisplayObje
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction;
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel;
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.beans.Property;
@ -112,11 +113,12 @@ public class DisplayByRolePermission extends Permission {
*/
private boolean isAuthorized(DisplayObjectPropertyStatement action) {
ObjectPropertyStatement stmt = action.getObjectPropertyStatement();
String subjectUri = stmt.getSubjectURI();
String predicateUri = stmt.getPropertyURI();
String subjectUri = stmt.getSubjectURI();
String objectUri = stmt.getObjectURI();
Property op = (stmt.getProperty() != null)
? stmt.getProperty() : new Property(stmt.getPropertyURI());
return canDisplayResource(subjectUri)
&& canDisplayPredicate(new Property(predicateUri))
&& canDisplayPredicate(op)
&& canDisplayResource(objectUri);
}

View file

@ -0,0 +1,59 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller.json;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONObject;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupsForRequest;
import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache;
/**
*This class will get all the vclasses in the system.
*/
public class GetAllVClasses extends JsonObjectProducer {
private static final Log log = LogFactory
.getLog(GetAllVClasses.class);
public GetAllVClasses(VitroRequest vreq) {
super(vreq);
}
@Override
protected JSONObject process() throws Exception {
JSONObject map = new JSONObject();
//Get all VClassGroups
List<VClass> vclasses = new ArrayList<VClass>();
VClassGroupsForRequest vcgc = VClassGroupCache.getVClassGroups(vreq);
List<VClassGroup> groups = vcgc.getGroups();
for(VClassGroup vcg: groups) {
for( VClass vc : vcg){
vclasses.add(vc);
}
}
//Sort vclass by name
Collections.sort(vclasses);
ArrayList<JSONObject> classes = new ArrayList<JSONObject>(vclasses.size());
for(VClass vc: vclasses) {
JSONObject vcObj = new JSONObject();
vcObj.put("name", vc.getName());
vcObj.put("URI", vc.getURI());
classes.add(vcObj);
}
map.put("classes", classes);
return map;
}
}

View file

@ -83,6 +83,8 @@ public class JsonServlet extends VitroHttpServlet {
new GetRenderedSolrIndividualsByVClass(vreq).process(resp);
}else if( vreq.getParameter("getRandomSolrIndividualsByVClass") != null ){
new GetRandomSolrIndividualsByVClass(vreq).process(resp);
} else if( vreq.getParameter("getAllVClasses") != null ){
new GetAllVClasses(vreq).process(resp);
}
}

View file

@ -104,8 +104,10 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene
// funny business because it needs to be able to retrieve anonymous union
// classes by their "pseudo-bnode URIs".
// Someday we'll need to figure out a different way of doing this.
WebappDaoFactory ctxDaoFact = ModelAccess.on(
vreq.getSession().getServletContext()).getWebappDaoFactory();
//WebappDaoFactory ctxDaoFact = ModelAccess.on(
// vreq.getSession().getServletContext()).getWebappDaoFactory();
WebappDaoFactory ctxDaoFact = vreq.getLanguageNeutralWebappDaoFactory();
List<VClass> types = new ArrayList<VClass>();
Individual subject = EditConfigurationUtils.getSubjectIndividual(vreq);
String predicateUri = EditConfigurationUtils.getPredicateUri(vreq);

View file

@ -4,6 +4,7 @@ package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -30,10 +31,14 @@ import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.vocabulary.XSD;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupsForRequest;
import edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
@ -521,6 +526,8 @@ private String getExistingIsSelfContainedTemplateQuery() {
MenuManagementDataUtils.includeRequiredSystemData(vreq.getSession().getServletContext(), data);
data.put("classGroup", new ArrayList<String>());
data.put("classGroups", DataGetterUtils.getClassGroups(vreq));
//for solr individuals data get getter
data.put("classes", this.getAllVClasses(vreq));
data.put("availablePermissions", this.getAvailablePermissions(vreq));
data.put("availablePermissionOrderedList", this.getAvailablePermissonsOrderedURIs());
}
@ -664,4 +671,33 @@ private String getExistingIsSelfContainedTemplateQuery() {
return query;
}
//Get all vclasses for the list of vclasses for solr
//Originally considered using an ajax request to get the vclasses list which is fine for adding a new content type
//but for an existing solr content type, would need to make yet another ajax request which seems too much
private List<HashMap<String, String>> getAllVClasses(VitroRequest vreq) {
List<VClass> vclasses = new ArrayList<VClass>();
VClassGroupsForRequest vcgc = VClassGroupCache.getVClassGroups(vreq);
List<VClassGroup> groups = vcgc.getGroups();
for(VClassGroup vcg: groups) {
for( VClass vc : vcg){
vclasses.add(vc);
}
}
//Sort vclass by name
Collections.sort(vclasses);
ArrayList<HashMap<String, String>> classes = new ArrayList<HashMap<String, String>>(vclasses.size());
for(VClass vc: vclasses) {
HashMap<String, String> vcObj = new HashMap<String, String>();
vcObj.put("name", vc.getName());
vcObj.put("URI", vc.getURI());
classes.add(vcObj);
}
return classes;
}
}

View file

@ -18,6 +18,7 @@ public class ProcessDataGetterN3Map {
map.put("edu.cornell.mannlib.vitro.webapp.utils.dataGetter.ClassGroupPageData", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils.ProcessClassGroupDataGetterN3");
map.put("edu.cornell.mannlib.vitro.webapp.utils.dataGetter.IndividualsForClassesDataGetter", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils.ProcessIndividualsForClassesDataGetterN3");
map.put("edu.cornell.mannlib.vitro.webapp.utils.dataGetter.FixedHTMLDataGetter", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils.ProcessFixedHTMLN3");
map.put("edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SolrIndividualsDataGetter", "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils.ProcessSolrIndividualsDataGetterN3");
return map;
}

View file

@ -0,0 +1,179 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.utils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.servlet.ServletContext;
import net.sf.json.JSONObject;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.ontology.OntModel;
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;
import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Resource;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
//Returns the appropriate n3 based on data getter
public class ProcessSolrIndividualsDataGetterN3 extends ProcessDataGetterAbstract {
private static String classType = "java:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.SolrIndividualsDataGetter";
private Log log = LogFactory.getLog(ProcessFixedHTMLN3.class);
public ProcessSolrIndividualsDataGetterN3(){
}
//Pass in variable that represents the counter
//TODO: ensure correct model returned
//We shouldn't use the ACTUAL values here but generate the n3 required
//?dataGetter a FixedHTMLDataGetter ; display:saveToVar ?saveToVar; display:htmlValue ?htmlValue .
public List<String> retrieveN3Required(int counter) {
String dataGetterVar = getDataGetterVar(counter);
//UPDATE: Using variable for class type
String classTypeVar = getN3VarName(classTypeVarBase, counter);
String n3 = dataGetterVar + " a " + classTypeVar + "; \n" +
"display:saveToVar " + getN3VarName("saveToVar", counter) + "; \n" +
"display:hasVClassId " + getN3VarName("vclassUri", counter) + " .";
List<String> requiredList = new ArrayList<String>();
requiredList.add(getPrefixes() + n3);
return requiredList;
}
public List<String> retrieveN3Optional(int counter) {
return null;
}
public List<String> retrieveLiteralsOnForm(int counter) {
List<String> literalsOnForm = new ArrayList<String>();
literalsOnForm.add(getVarName("saveToVar",counter));
return literalsOnForm;
}
public List<String> retrieveUrisOnForm(int counter) {
List<String> urisOnForm = new ArrayList<String>();
//UPDATE: adding class type as uri on form
urisOnForm.add(getVarName("vclassUri", counter));
urisOnForm.add(getVarName(classTypeVarBase, counter));
return urisOnForm;
}
public List<FieldVTwo> retrieveFields(int counter) {
List<FieldVTwo> fields = new ArrayList<FieldVTwo>();
//fields.add(new FieldVTwo().setName(getVarName("dataGetter", counter)));
fields.add(new FieldVTwo().setName(getVarName("saveToVar", counter)));
fields.add(new FieldVTwo().setName(getVarName("vclassUri", counter)));
//UPDATE: adding class type to the uris on the form
fields.add(new FieldVTwo().setName(getVarName(classTypeVarBase, counter)));
return fields;
}
public List<String> getLiteralVarNamesBase() {
return Arrays.asList("saveToVar");
}
//these are for the fields ON the form
public List<String> getUriVarNamesBase() {
return Arrays.asList(classTypeVarBase, "vclassUri");
}
//For Existing Values in case of editing
//Execute populate before retrieval
public void populateExistingValues(String dataGetterURI, int counter, OntModel queryModel) {
//First, put dataGetterURI within scope as well
this.populateExistingDataGetterURI(dataGetterURI, counter);
//Put in type
this.populateExistingClassType(this.getClassType(), counter);
//Sparql queries for values to be executed
//And then placed in the correct place/literal or uri
String querystr = getExistingValuesSparqlQuery(dataGetterURI);
QueryExecution qe = null;
try{
Query query = QueryFactory.create(querystr);
qe = QueryExecutionFactory.create(query, queryModel);
ResultSet results = qe.execSelect();
while( results.hasNext()){
QuerySolution qs = results.nextSolution();
Literal saveToVarLiteral = qs.getLiteral("saveToVar");
Resource vclassUriResource = qs.getResource("vclassUri");
//Put both literals in existing literals
existingLiteralValues.put(this.getVarName("saveToVar", counter),
new ArrayList<Literal>(Arrays.asList(saveToVarLiteral)));
existingUriValues.put(this.getVarName("vclassUri", counter),
new ArrayList<String>(Arrays.asList(vclassUriResource.getURI())));
}
} catch(Exception ex) {
log.error("Exception occurred in retrieving existing values with query " + querystr, ex);
}
}
//?dataGetter a FixedHTMLDataGetter ; display:saveToVar ?saveToVar; display:htmlValue ?htmlValue .
protected String getExistingValuesSparqlQuery(String dataGetterURI) {
String query = this.getSparqlPrefix() + " SELECT ?saveToVar ?vclassUri WHERE {" +
"<" + dataGetterURI + "> display:saveToVar ?saveToVar . \n" +
"<" + dataGetterURI + "> display:hasVClassId ?vclassUri . \n" +
"}";
return query;
}
//Method to create a JSON object with existing values to return to form
//There may be a better way to do this without having to run the query twice
//TODO: Refactor code if required
public JSONObject getExistingValuesJSON(String dataGetterURI, OntModel queryModel, ServletContext context) {
JSONObject jObject = new JSONObject();
jObject.element("dataGetterClass", classType);
jObject.element(classTypeVarBase, classType);
String querystr = getExistingValuesSparqlQuery(dataGetterURI);
QueryExecution qe = null;
try{
Query query = QueryFactory.create(querystr);
qe = QueryExecutionFactory.create(query, queryModel);
ResultSet results = qe.execSelect();
while( results.hasNext()){
QuerySolution qs = results.nextSolution();
Literal saveToVarLiteral = qs.getLiteral("saveToVar");
Resource vclassUriResource = qs.getResource("vclassUri");
String vclassUriString = vclassUriResource.getURI();
jObject.element("saveToVar", saveToVarLiteral.getString());
//TODO: Handle single and double quotes within string and escape properlyu
jObject.element("vclassUri", vclassUriString);
}
} catch(Exception ex) {
log.error("Exception occurred in retrieving existing values with query " + querystr, ex);
}
return jObject;
}
//Escape single and double quotes for html string to be returned to form
public String replaceQuotes(String inputStr) {
return inputStr.replaceAll("\'", "&#39;").replaceAll("\"", "&quot;");
}
//This class can be extended so returning type here
public String getClassType() {
return classType;
}
}

View file

@ -64,7 +64,7 @@ public class KnowledgeBaseUpdater {
}
long startTime = System.currentTimeMillis();
log.info("Migrating the knowledge base");
log.info("Performing any necessary data migration");
logger.log("Started knowledge base migration");
try {
@ -93,24 +93,6 @@ public class KnowledgeBaseUpdater {
List<AtomicOntologyChange> rawChanges = getAtomicOntologyChanges();
AtomicOntologyChangeLists changes = new AtomicOntologyChangeLists(rawChanges,settings.getNewTBoxModel(),settings.getOldTBoxModel());
// Only modify the TBox and migration metadata the first time
if(updateRequired(servletContext)) {
//process the TBox before the ABox
try {
log.debug("\tupdating tbox annotations");
updateTBoxAnnotations();
} catch (Exception e) {
log.error(e,e);
}
try {
migrateMigrationMetadata(servletContext);
logger.log("Migrated migration metadata");
} catch (Exception e) {
log.error("unable to migrate migration metadata " + e.getMessage());
}
}
// update ABox data any time
log.info("performing SPARQL CONSTRUCT additions");
@ -130,6 +112,18 @@ public class KnowledgeBaseUpdater {
performSparqlConstructs(settings.getSparqlConstructDeletionsDir() + "/post/",
settings.getRDFService(), RETRACT);
// Only modify the TBox and migration metadata the first time
if(updateRequired(servletContext)) {
//process the TBox before the ABox
try {
log.debug("\tupdating tbox annotations");
updateTBoxAnnotations();
} catch (Exception e) {
log.error(e,e);
}
}
}
@ -264,39 +258,6 @@ public class KnowledgeBaseUpdater {
aboxUpdater.processClassChanges(changes.getAtomicClassChanges());
}
// special for 1.5 - temporary code
// migrate past migration indicators to not use blank nodes and move them to app metadata model
// changing structure for pre 1.5 ones in the process
private void migrateMigrationMetadata(ServletContext servletContext) throws Exception {
String baseResourceURI = "http://vitro.mannlib.cornell.edu/ns/vitro/metadata/migration/";
String queryFile = "MigrationData.sparql";
RDFService rdfService = RDFServiceUtils.getRDFServiceFactory(servletContext).getRDFService();
String fmQuery = FileUtils.readFileToString(new File(settings.getSparqlConstructDeletionsDir() + "/" + queryFile));
Model toRemove = ModelFactory.createDefaultModel();
toRemove.read(rdfService.sparqlConstructQuery(fmQuery, RDFService.ModelSerializationFormat.RDFXML), null);
String cmQuery = FileUtils.readFileToString(new File(settings.getSparqlConstructAdditionsDir() + "/" + queryFile));
Model toAdd = ModelFactory.createDefaultModel();
toAdd.read(rdfService.sparqlConstructQuery(cmQuery, RDFService.ModelSerializationFormat.RDFXML), null);
ByteArrayOutputStream outAdd = new ByteArrayOutputStream();
toAdd.write(outAdd);
InputStream inAdd = new ByteArrayInputStream(outAdd.toByteArray());
ChangeSet addChangeSet = rdfService.manufactureChangeSet();
addChangeSet.addAddition(inAdd, RDFService.ModelSerializationFormat.RDFXML, JenaDataSourceSetupBase.JENA_APPLICATION_METADATA_MODEL);
rdfService.changeSetUpdate(addChangeSet);
ByteArrayOutputStream outRemove = new ByteArrayOutputStream();
toRemove.write(outRemove);
InputStream inRemove = new ByteArrayInputStream(outRemove.toByteArray());
ChangeSet removeChangeSet = rdfService.manufactureChangeSet();
removeChangeSet.addRemoval(inRemove, RDFService.ModelSerializationFormat.RDFXML, JenaDataSourceSetupBase.JENA_DB_MODEL);
rdfService.changeSetUpdate(removeChangeSet);
}
private void updateTBoxAnnotations() {
TBoxUpdater tboxUpdater = new TBoxUpdater(settings, logger, record);
try {

View file

@ -88,10 +88,6 @@ public class TBoxUpdater {
public void modifyPropertyQualifications() throws IOException {
}
private Model mergeConfigurations(Model oldConfig, Model newConfig) {
return null;
}
public void updateDefaultAnnotationValues() throws IOException {
updateDefaultAnnotationValues(null);
@ -454,89 +450,69 @@ public class TBoxUpdater {
}
public void renameProperty(AtomicOntologyChange changeObj) throws IOException {
Dataset dataset = new RDFServiceDataset(settings.getRDFService());
Model userAnnotationsModel = dataset.getNamedModel(
JenaDataSourceSetupBase.JENA_TBOX_ASSERTIONS_MODEL);
if(changeObj.getNotes() != null && changeObj.getNotes().startsWith("cc:")) {
mergePropertyAnnotationsToPropertyConfig(changeObj, userAnnotationsModel);
mergePropertyAnnotationsToPropertyConfig(changeObj, siteModel);
}
Resource renamedProperty = userAnnotationsModel.getResource(changeObj.getSourceURI());
userAnnotationsModel.removeAll(renamedProperty, null, (RDFNode) null);
userAnnotationsModel.removeAll(null, null, renamedProperty);
Resource renamedProperty = siteModel.getResource(changeObj.getSourceURI());
siteModel.removeAll(renamedProperty, null, (RDFNode) null);
siteModel.removeAll(null, null, renamedProperty);
}
private void mergePropertyAnnotationsToPropertyConfig(AtomicOntologyChange changeObj,
Model userAnnotationsModel) throws IOException {
String contextURI = VitroVocabulary.PROPERTY_CONFIG_DATA + changeObj.getNotes().substring(3);
String oldPropertyURI = changeObj.getSourceURI();
Model oldAnnotationsModel = settings.getOldTBoxAnnotationsModel();
String propertyAnnotationsQuery =
"PREFIX config: <" + VitroVocabulary.configURI + "> \n" +
"PREFIX vitro: <" + VitroVocabulary.vitroURI + "> \n" +
"CONSTRUCT { \n" +
" <" + oldPropertyURI + "> vitro:inPropertyGroupAnnot ?group . \n" +
" <" + oldPropertyURI + "> <" + RDFS.label.getURI() + "> ?label . \n" +
" <" + oldPropertyURI + "> vitro:displayRankAnnot ?displayRank . \n" +
" <" + oldPropertyURI + "> vitro:customEntryFormAnnot ?customForm . \n" +
" <" + oldPropertyURI + "> vitro:hiddenFromDisplayBelowRoleLevelAnnot ?displayLevel . \n" +
" <" + oldPropertyURI + "> vitro:prohibitedFromUpdateBelowRoleLevelAnnot ?updateLevel . \n " +
" <" + oldPropertyURI + "> ?vitroProp ?vitroValue \n" +
"} WHERE { \n" +
" { <" + oldPropertyURI + "> vitro:inPropertyGroupAnnot ?group } \n" +
" UNION { <" + oldPropertyURI + "> <" + RDFS.label.getURI() + "> ?label } \n" +
" UNION { <" + oldPropertyURI + "> vitro:displayRankAnnot ?displayRank } \n" +
" UNION { <" + oldPropertyURI + "> vitro:customEntryFormAnnot ?customForm } \n" +
" UNION { <" + oldPropertyURI + "> vitro:hiddenFromDisplayBelowRoleLevelAnnot ?displayLevel } \n" +
" UNION { <" + oldPropertyURI + "> vitro:prohibitedFromUpdateBelowRoleLevelAnnot ?updateLevel } \n " +
" { <" + oldPropertyURI + "> <" + RDFS.label.getURI() + "> ?label } \n" +
" UNION { <" + oldPropertyURI + "> ?vitroProp ?vitroValue \n" +
" FILTER (regex(str(?vitroProp), \"" + VitroVocabulary.vitroURI + "\")) } \n" +
"} \n" ;
Model userChangesModel = construct(
propertyAnnotationsQuery, userAnnotationsModel).difference(
construct(propertyAnnotationsQuery, oldAnnotationsModel));
String addQuery = "PREFIX config: <" + VitroVocabulary.configURI + "> \n" +
"PREFIX vitro: <" + VitroVocabulary.vitroURI + "> \n" +
"CONSTRUCT { \n" +
" ?configuration config:propertyGroup ?group . \n" +
" ?configuration config:displayName ?label . \n" +
" ?configuration vitro:displayRankAnnot ?displayRank . \n" +
" ?configuration vitro:customEntryFormAnnot ?customForm . \n" +
" ?configuration vitro:hiddenFromDisplayBelowRoleLevelAnnot ?displayLevel . \n" +
" ?configuration vitro:prohibitedFromUpdateBelowRoleLevelAnnot ?updateLevel . \n " +
"} WHERE { \n" +
" <" + contextURI + "> config:hasConfiguration ?configuration . \n" +
" OPTIONAL { <" + oldPropertyURI + "> vitro:inPropertyGroupAnnot ?group } \n" +
" OPTIONAL { <" + oldPropertyURI + "> <" + RDFS.label.getURI() + "> ?label } \n" +
" OPTIONAL { <" + oldPropertyURI + "> vitro:displayRankAnnot ?displayRank } \n" +
" OPTIONAL { <" + oldPropertyURI + "> vitro:customEntryFormAnnot ?customForm } \n" +
" OPTIONAL { <" + oldPropertyURI + "> vitro:hiddenFromDisplayBelowRoleLevelAnnot ?displayLevel } \n" +
" OPTIONAL { <" + oldPropertyURI + "> vitro:prohibitedFromUpdateBelowRoleLevelAnnot ?updateLevel } \n " +
"} \n" ;
if(userChangesModel.size() == 0) {
return;
} else {
log.info("Updating PropertyConfig.n3 to include locally-changed " +
"settings from old property " + oldPropertyURI);
}
String retractQuery = "PREFIX config: <" + VitroVocabulary.configURI + "> \n" +
String newQuery = "PREFIX config: <" + VitroVocabulary.configURI + "> \n" +
"PREFIX vitro: <" + VitroVocabulary.vitroURI + "> \n" +
"CONSTRUCT { \n" +
" <" + oldPropertyURI + "> config:propertyGroup ?rgroup . \n" +
" ?configuration config:displayName ?rlabel . \n" +
" ?configuration vitro:displayRankAnnot ?rdisplayRank . \n" +
" ?configuration vitro:customEntryFormAnnot ?rcustomForm . \n" +
" ?configuration vitro:hiddenFromDisplayBelowRoleLevelAnnot ?rdisplayLevel . \n" +
" ?configuration vitro:prohibitedFromUpdateBelowRoleLevelAnnot ?rupdateLevel . \n " +
" ?configuration config:propertyGroup ?group . \n" +
" ?configuration config:displayName ?label . \n" +
" ?configuration ?vitroProp ?vitroValue . \n" +
"} WHERE { \n" +
" <" + contextURI + "> config:hasConfiguration ?configuration . \n" +
" OPTIONAL { <" + oldPropertyURI + "> vitro:inPropertyGroupAnnot ?group . \n" +
" ?configuration config:propertyGroup ?rgroup } \n" +
" OPTIONAL { <" + oldPropertyURI + "> <" + RDFS.label.getURI() + "> ?label . \n" +
" ?configuration config:displayName ?rlabel } \n " +
" OPTIONAL { <" + oldPropertyURI + "> vitro:displayRankAnnot ?displayRank . \n" +
" ?configuration vitro:displayRantAnnot ?rdisplayRank } \n " +
" OPTIONAL { <" + oldPropertyURI + "> vitro:customEntryFormAnnot ?customForm . \n" +
" ?configuration vitro:customEntryFormAnnot ?rcustomForm } \n" +
" OPTIONAL { <" + oldPropertyURI + "> vitro:hiddenFromDisplayBelowRoleLevelAnnot ?displayLevel . \n" +
" ?configuration vitro:hiddenFromDisplayBelowRoleLevelAnnot ?rdisplayLevel } \n" +
" OPTIONAL { <" + oldPropertyURI + "> vitro:prohibitedFromUpdateBelowRoleLevelAnnot ?updateLevel . \n " +
" ?configuration vitro:prohibitedFromUpdateBelowRoleLevelAnnot ?updateLevel } " +
" OPTIONAL { <" + oldPropertyURI + "> vitro:inPropertyGroupAnnot ?group } \n" +
" OPTIONAL { <" + oldPropertyURI + "> <" + RDFS.label.getURI() + "> ?label } \n" +
" OPTIONAL { <" + oldPropertyURI + "> ?vitroProp ?vitroValue \n" +
" FILTER (regex(str(?vitroProp), \"" + VitroVocabulary.vitroURI + "\")) } \n" +
"} \n" ;
String existingQuery = "PREFIX config: <" + VitroVocabulary.configURI + "> \n" +
"PREFIX vitro: <" + VitroVocabulary.vitroURI + "> \n" +
"CONSTRUCT { \n" +
" ?configuration config:propertyGroup ?group . \n" +
" ?configuration config:displayName ?label . \n" +
" ?configuration ?vitroProp ?vitroValue . \n" +
"} WHERE { \n" +
" <" + contextURI + "> config:hasConfiguration ?configuration . \n" +
" OPTIONAL { ?configuration config:propertyGroup ?group } \n" +
" OPTIONAL { ?configuration config:displayName ?label } \n" +
" OPTIONAL { ?configuration ?vitroProp ?vitroValue \n" +
" FILTER (regex(str(?vitroProp), \"" + VitroVocabulary.vitroURI + "\")) } \n" +
"} \n" ;
Model configModel = ModelFactory.createDefaultModel();
@ -545,17 +521,31 @@ public class TBoxUpdater {
FileInputStream fis = new FileInputStream(file);
configModel.read(fis, null, "N3");
Model union = ModelFactory.createUnion(configModel,
userChangesModel);
Model currentUnion = ModelFactory.createUnion(configModel,
userAnnotationsModel);
Model additions = construct(addQuery, union);
Model retractions = construct(retractQuery, union);
Model userAnnotationsAsConfig = construct(newQuery, currentUnion);
Model currentDefaultConfig = construct(existingQuery, currentUnion);
if (additions.size() > 0 || retractions.size() > 0) {
configModel.remove(retractions);
log.info("Removing " + retractions.size() + " statements from " + contextURI);
Model additions = userAnnotationsAsConfig.difference(currentDefaultConfig);
Model retractions = currentDefaultConfig.difference(userAnnotationsAsConfig);
// filter the retractions so we won't remove a value for a given predicate
// unless the additions model contains at least one value for the same predicate
Model filteredRetractions = ModelFactory.createDefaultModel();
StmtIterator retractIt = retractions.listStatements();
while(retractIt.hasNext()) {
Statement candidate = retractIt.nextStatement();
if(additions.contains(null, candidate.getPredicate(), (RDFNode) null)) {
filteredRetractions.add(candidate);
}
}
if (additions.size() > 0 || filteredRetractions.size() > 0) {
configModel.remove(filteredRetractions);
log.debug("Removing " + filteredRetractions.size() + " statements from " + contextURI);
configModel.add(additions);
log.info("Adding " + additions.size() + " statements from " + contextURI);
log.debug("Adding " + additions.size() + " statements from " + contextURI);
FileOutputStream fos = new FileOutputStream(file);
configModel.write(fos, "N3");
}

View file

@ -81,6 +81,8 @@ public class SimpleReasonerSetup implements ServletContextListener {
log.info("Pellet reasoner connected for the TBox");
waitForTBoxReasoning(sce);
// set up simple reasoning for the ABox
RDFService rdfService = RDFServiceUtils.getRDFServiceFactory(ctx).getRDFService();
@ -131,7 +133,7 @@ public class SimpleReasonerSetup implements ServletContextListener {
int sleeps = 0;
// sleep at least once to make sure the TBox reasoning gets started
while ((0 == sleeps) || ((sleeps < 1000) && pelletListener.isReasoning())) {
if ((sleeps % 10) == 0) { // print message at 10 second intervals
if (((sleeps - 1) % 10) == 0) { // print message at 10 second intervals
log.info("Waiting for initial TBox reasoning to complete");
}
Thread.sleep(1000);

View file

@ -141,7 +141,6 @@ public class UpdateKnowledgeBase implements ServletContextListener {
if(!JenaDataSourceSetupBase.isFirstStartup()) {
try {
ctx.setAttribute(KBM_REQURIED_AT_STARTUP, Boolean.TRUE);
log.info("Data migration required");
migrationChangesMade = ontologyUpdater.update(ctx);
if (tryMigrateDisplay) {
try {
@ -221,8 +220,8 @@ public class UpdateKnowledgeBase implements ServletContextListener {
StartupStatus.getBean(ctx).info(this, "Updating knowledge base: reports are in '" + dataDir + "'");
Path changedDir = createDirectory(dataDir, "changedData");
settings.setAddedDataFile(changedDir.resolve("addedData.n3").toString());
settings.setRemovedDataFile(changedDir.resolve("removedData.n3").toString());
settings.setAddedDataFile(changedDir.resolve(timestampedFileName("addedData", "n3")).toString());
settings.setRemovedDataFile(changedDir.resolve(timestampedFileName("removedData", "n3")).toString());
Path logDir = createDirectory(dataDir, "logs");
settings.setLogFile(logDir.resolve(timestampedFileName("knowledgeBaseUpdate", "log")).toString());

View file

@ -108,9 +108,9 @@ public class GroupedPropertyList extends BaseTemplateModel {
if (editing) {
mergeAllPossibleDataProperties(propertyList);
propertyList = correctLanguageForProperties(propertyList);
}
propertyList = correctLanguageForProperties(propertyList);
sort(propertyList);
// Put the list into groups