diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/JSONServlet.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/JSONServlet.java index e38779a83..0378dc780 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/JSONServlet.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/JSONServlet.java @@ -22,11 +22,15 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import com.hp.hpl.jena.ontology.OntModel; + import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.SelectListGenerator; +import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch; +import edu.cornell.mannlib.vitro.webapp.web.DisplayVocabulary; /** * This servlet is for servicing requests for JSON objects/data. @@ -84,6 +88,17 @@ public class JSONServlet extends VitroHttpServlet { if( log.isDebugEnabled() ) log.debug(" attempting to get option list for field '" + field + "'"); + // set ProhibitedFromSearch object so picklist doesn't show + // individuals from classes that should be hidden from list views + OntModel displayOntModel = + (OntModel) getServletConfig().getServletContext() + .getAttribute("displayOntModel"); + if (displayOntModel != null) { + ProhibitedFromSearch pfs = new ProhibitedFromSearch( + DisplayVocabulary.PRIMARY_LUCENE_INDEX_URI, displayOntModel); + editConfig.setProhibitedFromSearch(pfs); + } + Map options = SelectListGenerator.getOptions(editConfig, field, (new VitroRequest(req)).getFullWebappDaoFactory()); resp.setContentType("application/json"); ServletOutputStream out = resp.getOutputStream(); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditConfiguration.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditConfiguration.java index f167aaa9c..d0a118928 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditConfiguration.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/EditConfiguration.java @@ -33,6 +33,7 @@ import edu.cornell.mannlib.vitro.webapp.auth.identifier.ServletIdentifierBundleF import edu.cornell.mannlib.vitro.webapp.auth.identifier.UserToIndIdentifierFactory; import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement; import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral; +import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch; /** * Represents a set of fields on a form and how parameters from a from @@ -92,6 +93,8 @@ public class EditConfiguration { private List modelChangePreprocessors; private List editSubmissionPreprocessors = null; + + private ProhibitedFromSearch prohibitedFromSearch; /** * If true, then any dependent resources that are unlinked should be @@ -833,6 +836,14 @@ public class EditConfiguration { this.modelChangePreprocessors.add( modelChangePreprocessor ); } + public void setProhibitedFromSearch( ProhibitedFromSearch prohibitedFromSearch) { + this.prohibitedFromSearch = prohibitedFromSearch; + } + + public ProhibitedFromSearch getProhibitedFromSearch() { + return this.prohibitedFromSearch; + } + private void debugScope(String msg){ if( log.isDebugEnabled()){ log.debug(msg); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/SelectListGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/SelectListGenerator.java index 76d06012e..876cef4af 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/SelectListGenerator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/SelectListGenerator.java @@ -11,6 +11,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.ListIterator; import java.util.Map; +import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -30,6 +31,10 @@ import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; +import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena; +import edu.cornell.mannlib.vitro.webapp.dao.jena.pellet.PelletListener; +import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch; + public class SelectListGenerator { static Log log = LogFactory.getLog(SelectListGenerator.class); @@ -180,11 +185,26 @@ public class SelectListGenerator { individuals = removeIndividualsAlreadyInRange(individuals,stmts,predicateUri,editConfig.getObject()); //Collections.sort(individuals,new compareIndividualsByName()); + ProhibitedFromSearch pfs = editConfig.getProhibitedFromSearch(); + for( Individual ind : individuals ){ String uri = ind.getURI(); - if( uri != null ){ - optionsMap.put(uri,ind.getName().trim()); - ++optionsCount; + if( uri != null ){ + boolean prohibited = false; + if (pfs != null) { + for (VClass vc : ind.getVClasses()) { + if (vc.getURI() != null) { + if (pfs.isClassProhibited(ind.getVClassURI())) { + prohibited = true; + break; + } + } + } + } + if (!prohibited) { + optionsMap.put(uri,ind.getName().trim()); + ++optionsCount; + } } } } @@ -203,21 +223,71 @@ public class SelectListGenerator { // now populate the options if( wDaoFact == null ) log.error("could not get WebappDaoFactory from request in SelectListGenerator.getOptions()."); + // if reasoning isn't available, we will also need to add + // individuals asserted in subclasses + boolean inferenceAvailable = false; + if (wDaoFact instanceof WebappDaoFactoryJena) { + PelletListener pl = ((WebappDaoFactoryJena) wDaoFact) + .getPelletListener(); + if (pl != null && pl.isConsistent() + && !pl.isInErrorState() + && !pl.isReasoning()) { + inferenceAvailable = true; + } + } + VClass vclass = wDaoFact.getVClassDao().getVClassByURI( vclassUri ); if( vclass == null ) { log.error("Cannot find owl:Class " + vclassUri + " in the model" ); optionsMap.put("", "Could not find class " + vclassUri); }else{ List individuals = wDaoFact.getIndividualDao().getIndividualsByVClassURI(vclass.getURI(),-1,-1); + Map individualMap = new HashMap(); + + for (Individual ind : wDaoFact.getIndividualDao().getIndividualsByVClassURI(vclass.getURI(),-1,-1)) { + if (ind.getURI() != null) { + individualMap.put(ind.getURI(), ind); + } + } + + if (!inferenceAvailable) { + for (String subclassURI : wDaoFact.getVClassDao().getAllSubClassURIs(vclass.getURI())) { + for (Individual ind : wDaoFact.getIndividualDao().getIndividualsByVClassURI(subclassURI,-1,-1)) { + if (ind.getURI() != null) { + individualMap.put(ind.getURI(), ind); + } + } + } + } + + List individuals = new ArrayList(); + individuals.addAll(individualMap.values()); + Collections.sort(individuals); + if (individuals.size()==0){ log.error("No individuals of type "+vclass.getName()+" to add to pick list in SelectListGenerator.getOptions(); check portal visibility"); optionsMap.put("", "No " + vclass.getName() + " found"); - }else{ + }else{ + ProhibitedFromSearch pfs = editConfig.getProhibitedFromSearch(); for( Individual ind : individuals ) { String uri = ind.getURI(); - if( uri != null ) { - optionsMap.put(uri,ind.getName().trim()); - ++optionsCount; + if( uri != null ) { + boolean prohibited = false; + if (pfs != null) { + for (VClass vc : ind.getVClasses()) { + if (vc.getURI() != null) { + if (pfs.isClassProhibited(ind.getVClassURI())) { + prohibited = true; + break; + } + + } + } + } + if(!prohibited) { + optionsMap.put(uri,ind.getName().trim()); + ++optionsCount; + } } } }