Clean up JenaAdminActions to remove compiler warnings.
Remove commented code and unused methods. Add generics to Iterators or use for-each loops to avoid iterators entirely.
This commit is contained in:
parent
77d7f1e184
commit
ee6141adc2
1 changed files with 25 additions and 47 deletions
|
@ -18,12 +18,10 @@ import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import com.hp.hpl.jena.iri.IRI;
|
import com.hp.hpl.jena.iri.IRI;
|
||||||
import com.hp.hpl.jena.iri.IRIFactory;
|
import com.hp.hpl.jena.iri.IRIFactory;
|
||||||
import com.hp.hpl.jena.iri.Violation;
|
|
||||||
import com.hp.hpl.jena.ontology.AllValuesFromRestriction;
|
import com.hp.hpl.jena.ontology.AllValuesFromRestriction;
|
||||||
import com.hp.hpl.jena.ontology.OntClass;
|
import com.hp.hpl.jena.ontology.OntClass;
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||||
import com.hp.hpl.jena.ontology.OntResource;
|
|
||||||
import com.hp.hpl.jena.ontology.Restriction;
|
import com.hp.hpl.jena.ontology.Restriction;
|
||||||
import com.hp.hpl.jena.query.Query;
|
import com.hp.hpl.jena.query.Query;
|
||||||
import com.hp.hpl.jena.query.QueryExecution;
|
import com.hp.hpl.jena.query.QueryExecution;
|
||||||
|
@ -35,11 +33,9 @@ import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||||
import com.hp.hpl.jena.rdf.model.Property;
|
import com.hp.hpl.jena.rdf.model.Property;
|
||||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||||
import com.hp.hpl.jena.rdf.model.Resource;
|
import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
|
||||||
import com.hp.hpl.jena.rdf.model.Statement;
|
import com.hp.hpl.jena.rdf.model.Statement;
|
||||||
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
||||||
import com.hp.hpl.jena.shared.Lock;
|
import com.hp.hpl.jena.shared.Lock;
|
||||||
import com.hp.hpl.jena.util.iterator.ClosableIterator;
|
|
||||||
import com.hp.hpl.jena.vocabulary.OWL;
|
import com.hp.hpl.jena.vocabulary.OWL;
|
||||||
import com.hp.hpl.jena.vocabulary.RDF;
|
import com.hp.hpl.jena.vocabulary.RDF;
|
||||||
import com.hp.hpl.jena.vocabulary.RDFS;
|
import com.hp.hpl.jena.vocabulary.RDFS;
|
||||||
|
@ -60,7 +56,7 @@ public class JenaAdminActions extends BaseEditController {
|
||||||
if (iri.hasViolation(false) ) {
|
if (iri.hasViolation(false) ) {
|
||||||
log.error("Bad URI: "+uri);
|
log.error("Bad URI: "+uri);
|
||||||
log.error( "Only well-formed absolute URIrefs can be included in RDF/XML output: "
|
log.error( "Only well-formed absolute URIrefs can be included in RDF/XML output: "
|
||||||
+ ((Violation)iri.violations(false).next()).getShortMessage());
|
+ iri.violations(false).next().getShortMessage());
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -72,8 +68,7 @@ public class JenaAdminActions extends BaseEditController {
|
||||||
private static final String AKT_PORTAL = "http://www.aktors.org/ontology/portal#";
|
private static final String AKT_PORTAL = "http://www.aktors.org/ontology/portal#";
|
||||||
|
|
||||||
private void copyStatements(Model src, Model dest, Resource subj, Property pred, RDFNode obj) {
|
private void copyStatements(Model src, Model dest, Resource subj, Property pred, RDFNode obj) {
|
||||||
for (Iterator i = src.listStatements(subj,pred,obj); i.hasNext();) {
|
for (Statement stmt : src.listStatements(subj,pred,obj).toList()) {
|
||||||
Statement stmt = (Statement) i.next();
|
|
||||||
String subjNs = stmt.getSubject().getNameSpace();
|
String subjNs = stmt.getSubject().getNameSpace();
|
||||||
if (subjNs == null || (! (subjNs.equals(VITRO) || subjNs.equals(AKT_SUPPORT) || subjNs.equals(AKT_PORTAL) ) ) ) {
|
if (subjNs == null || (! (subjNs.equals(VITRO) || subjNs.equals(AKT_SUPPORT) || subjNs.equals(AKT_PORTAL) ) ) ) {
|
||||||
if (stmt.getObject().isLiteral()) {
|
if (stmt.getObject().isLiteral()) {
|
||||||
|
@ -91,14 +86,11 @@ public class JenaAdminActions extends BaseEditController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This doesn't really print just the TBox. It takes a copy of the model, removes all the individuals, and writes the result.
|
* This doesn't really print just the TBox. It takes a copy of the model, removes all the individuals, and writes the result.
|
||||||
* @param response
|
|
||||||
*/
|
*/
|
||||||
private void outputTbox(HttpServletResponse response) {
|
private void outputTbox(HttpServletResponse response) {
|
||||||
OntModel memoryModel = ModelAccess.on(getServletContext()).getBaseOntModel();
|
OntModel memoryModel = ModelAccess.on(getServletContext()).getBaseOntModel();
|
||||||
try {
|
try {
|
||||||
OntModel tempOntModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);
|
OntModel tempOntModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);
|
||||||
Property DescriptionProp = ResourceFactory.createProperty(VitroVocabulary.DESCRIPTION_ANNOT);
|
|
||||||
Property ExampleProp = ResourceFactory.createProperty(VitroVocabulary.EXAMPLE_ANNOT);
|
|
||||||
memoryModel.enterCriticalSection(Lock.READ);
|
memoryModel.enterCriticalSection(Lock.READ);
|
||||||
try {
|
try {
|
||||||
copyStatements(memoryModel,tempOntModel,null,RDF.type,OWL.Class);
|
copyStatements(memoryModel,tempOntModel,null,RDF.type,OWL.Class);
|
||||||
|
@ -110,8 +102,6 @@ public class JenaAdminActions extends BaseEditController {
|
||||||
copyStatements(memoryModel,tempOntModel,null,RDFS.domain,null);
|
copyStatements(memoryModel,tempOntModel,null,RDFS.domain,null);
|
||||||
copyStatements(memoryModel,tempOntModel,null,RDFS.range,null);
|
copyStatements(memoryModel,tempOntModel,null,RDFS.range,null);
|
||||||
copyStatements(memoryModel,tempOntModel,null,OWL.inverseOf,null);
|
copyStatements(memoryModel,tempOntModel,null,OWL.inverseOf,null);
|
||||||
//copyStatements(memoryModel,tempOntModel,null,DescriptionProp,null);
|
|
||||||
//copyStatements(memoryModel,tempOntModel,null,ExampleProp,null);
|
|
||||||
} finally {
|
} finally {
|
||||||
memoryModel.leaveCriticalSection();
|
memoryModel.leaveCriticalSection();
|
||||||
}
|
}
|
||||||
|
@ -131,28 +121,24 @@ public class JenaAdminActions extends BaseEditController {
|
||||||
Model taxonomyModel = ModelFactory.createDefaultModel();
|
Model taxonomyModel = ModelFactory.createDefaultModel();
|
||||||
try {
|
try {
|
||||||
HashSet<Resource> typeSet = new HashSet<Resource>();
|
HashSet<Resource> typeSet = new HashSet<Resource>();
|
||||||
for (Iterator classIt = ontModel.listStatements((Resource)null,RDF.type,(RDFNode)null); classIt.hasNext();) {
|
for (Statement stmt : ontModel.listStatements((Resource)null,RDF.type,(RDFNode)null).toList()) {
|
||||||
Statement stmt = (Statement) classIt.next();
|
|
||||||
if (stmt.getObject().isResource()) {
|
if (stmt.getObject().isResource()) {
|
||||||
Resource ontClass = (Resource) stmt.getObject();
|
typeSet.add((Resource) stmt.getObject());
|
||||||
typeSet.add(ontClass);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Iterator classIt = ontModel.listClasses(); classIt.hasNext();) {
|
for (Resource classRes : ontModel.listClasses().toList()) {
|
||||||
Resource classRes = (Resource) classIt.next();
|
|
||||||
typeSet.add(classRes);
|
typeSet.add(classRes);
|
||||||
}
|
}
|
||||||
for (Iterator<Resource> typeIt = typeSet.iterator(); typeIt.hasNext();) {
|
for (Resource ontClass : typeSet) {
|
||||||
Resource ontClass = typeIt.next();
|
if (!ontClass.isAnon()) { // Only query for named classes
|
||||||
if (!ontClass.isAnon()) { // Only query for named classes
|
System.out.println("Describing "+ontClass.getURI());
|
||||||
System.out.println("Describing "+ontClass.getURI());
|
// We want a subgraph describing this class, including related BNodes
|
||||||
// We want a subgraph describing this class, including related BNodes
|
String queryStr = "DESCRIBE <"+ontClass.getURI()+">";
|
||||||
String queryStr = "DESCRIBE <"+ontClass.getURI()+">";
|
Query describeQuery = QueryFactory.create(queryStr);
|
||||||
Query describeQuery = QueryFactory.create(queryStr);
|
QueryExecution qe = QueryExecutionFactory.create(describeQuery,ontModel);
|
||||||
QueryExecution qe = QueryExecutionFactory.create(describeQuery,ontModel);
|
qe.execDescribe(taxonomyModel);
|
||||||
qe.execDescribe(taxonomyModel);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
ontModel.leaveCriticalSection();
|
ontModel.leaveCriticalSection();
|
||||||
}
|
}
|
||||||
|
@ -175,7 +161,7 @@ public class JenaAdminActions extends BaseEditController {
|
||||||
OntModel model = ModelAccess.on(getServletContext()).getJenaOntModel();
|
OntModel model = ModelAccess.on(getServletContext()).getJenaOntModel();
|
||||||
Model tmp = ModelFactory.createDefaultModel();
|
Model tmp = ModelFactory.createDefaultModel();
|
||||||
boolean valid = true;
|
boolean valid = true;
|
||||||
for (Statement stmt : ((List<Statement>)model.listStatements().toList()) ) {
|
for (Statement stmt : model.listStatements().toList() ) {
|
||||||
tmp.add(stmt);
|
tmp.add(stmt);
|
||||||
StringWriter writer = new StringWriter();
|
StringWriter writer = new StringWriter();
|
||||||
try {
|
try {
|
||||||
|
@ -202,17 +188,15 @@ public class JenaAdminActions extends BaseEditController {
|
||||||
|
|
||||||
private void printRestrictions() {
|
private void printRestrictions() {
|
||||||
OntModel memoryModel = (OntModel) getServletContext().getAttribute("pelletOntModel");
|
OntModel memoryModel = (OntModel) getServletContext().getAttribute("pelletOntModel");
|
||||||
for (Iterator i = memoryModel.listRestrictions(); i.hasNext(); ) {
|
for (Restriction rest : memoryModel.listRestrictions().toList() ) {
|
||||||
Restriction rest = (Restriction) i.next();
|
|
||||||
//System.out.println();
|
//System.out.println();
|
||||||
if (rest.isAllValuesFromRestriction()) {
|
if (rest.isAllValuesFromRestriction()) {
|
||||||
log.trace("All values from: ");
|
log.trace("All values from: ");
|
||||||
AllValuesFromRestriction avfr = rest.asAllValuesFromRestriction();
|
AllValuesFromRestriction avfr = rest.asAllValuesFromRestriction();
|
||||||
Resource res = avfr.getAllValuesFrom();
|
Resource res = avfr.getAllValuesFrom();
|
||||||
if (res.canAs(OntClass.class)) {
|
if (res.canAs(OntClass.class)) {
|
||||||
OntClass resClass = (OntClass) res.as(OntClass.class);
|
OntClass resClass = res.as(OntClass.class);
|
||||||
for (Iterator resInstIt = resClass.listInstances(); resInstIt.hasNext(); ) {
|
for (Resource inst : resClass.listInstances().toList() ) {
|
||||||
Resource inst = (Resource) resInstIt.next();
|
|
||||||
log.trace(" -"+inst.getURI());
|
log.trace(" -"+inst.getURI());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -222,8 +206,7 @@ public class JenaAdminActions extends BaseEditController {
|
||||||
log.trace("Has value: ");
|
log.trace("Has value: ");
|
||||||
}
|
}
|
||||||
log.trace("On property "+rest.getOnProperty().getURI());
|
log.trace("On property "+rest.getOnProperty().getURI());
|
||||||
for (Iterator indIt = rest.listInstances(); indIt.hasNext(); ) {
|
for (Resource inst : rest.listInstances().toList() ) {
|
||||||
Resource inst = (Resource) indIt.next();
|
|
||||||
log.trace(" "+inst.getURI());
|
log.trace(" "+inst.getURI());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,8 +218,7 @@ public class JenaAdminActions extends BaseEditController {
|
||||||
memoryModel.enterCriticalSection(Lock.WRITE);
|
memoryModel.enterCriticalSection(Lock.WRITE);
|
||||||
try {
|
try {
|
||||||
List<Statement> statementsToRemove = new LinkedList<Statement>();
|
List<Statement> statementsToRemove = new LinkedList<Statement>();
|
||||||
for (Iterator i = memoryModel.listStatements(null,null,(Literal)null); i.hasNext(); ) {
|
for (Statement stmt : memoryModel.listStatements(null,null,(Literal)null).toList() ) {
|
||||||
Statement stmt = (Statement) i.next();
|
|
||||||
if (stmt.getObject().isLiteral()) {
|
if (stmt.getObject().isLiteral()) {
|
||||||
Literal lit = (Literal) stmt.getObject();
|
Literal lit = (Literal) stmt.getObject();
|
||||||
if ( lit.getString().length() > 24) {
|
if ( lit.getString().length() > 24) {
|
||||||
|
@ -253,7 +235,8 @@ public class JenaAdminActions extends BaseEditController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doGet(HttpServletRequest req, HttpServletResponse response) {
|
@Override
|
||||||
|
public void doGet(HttpServletRequest req, HttpServletResponse response) {
|
||||||
if (!isAuthorizedToDisplayPage(req, response, SimplePermission.USE_MISCELLANEOUS_ADMIN_PAGES.ACTIONS)) {
|
if (!isAuthorizedToDisplayPage(req, response, SimplePermission.USE_MISCELLANEOUS_ADMIN_PAGES.ACTIONS)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -275,16 +258,15 @@ public class JenaAdminActions extends BaseEditController {
|
||||||
|
|
||||||
if (actionStr.equals("checkURIs")) {
|
if (actionStr.equals("checkURIs")) {
|
||||||
OntModel memoryModel = ModelAccess.on(getServletContext()).getJenaOntModel();
|
OntModel memoryModel = ModelAccess.on(getServletContext()).getJenaOntModel();
|
||||||
ClosableIterator stmtIt = memoryModel.listStatements();
|
StmtIterator stmtIt = memoryModel.listStatements();
|
||||||
try {
|
try {
|
||||||
for (Iterator i = stmtIt; i.hasNext(); ) {
|
for (Statement stmt : stmtIt.toList() ) {
|
||||||
boolean sFailed = false;
|
boolean sFailed = false;
|
||||||
boolean pFailed = false;
|
boolean pFailed = false;
|
||||||
boolean oFailed = false;
|
boolean oFailed = false;
|
||||||
String sURI = "<bNode>";
|
String sURI = "<bNode>";
|
||||||
String pURI = "???";
|
String pURI = "???";
|
||||||
String oURI = "<bNode>";
|
String oURI = "<bNode>";
|
||||||
Statement stmt = (Statement) i.next();
|
|
||||||
if (stmt.getSubject().getURI() != null) {
|
if (stmt.getSubject().getURI() != null) {
|
||||||
sFailed = checkURI(sURI = stmt.getSubject().getURI());
|
sFailed = checkURI(sURI = stmt.getSubject().getURI());
|
||||||
}
|
}
|
||||||
|
@ -318,11 +300,7 @@ public class JenaAdminActions extends BaseEditController {
|
||||||
memoryModel = ModelAccess.on(getServletContext()).getJenaOntModel();
|
memoryModel = ModelAccess.on(getServletContext()).getJenaOntModel();
|
||||||
System.out.println("jenaOntModel");
|
System.out.println("jenaOntModel");
|
||||||
}
|
}
|
||||||
int subModelCount = 0;
|
int subModelCount = memoryModel.listSubModels().toList().size();
|
||||||
for (Iterator subIt = memoryModel.listSubModels(); subIt.hasNext();) {
|
|
||||||
subIt.next();
|
|
||||||
++subModelCount;
|
|
||||||
}
|
|
||||||
System.out.println("Submodels: "+subModelCount);
|
System.out.println("Submodels: "+subModelCount);
|
||||||
try {
|
try {
|
||||||
//response.setContentType("application/rdf+xml");
|
//response.setContentType("application/rdf+xml");
|
||||||
|
|
Loading…
Add table
Reference in a new issue