merging picklist optimizations back into trunk
This commit is contained in:
parent
d5664d93ec
commit
7e46f1ed02
13 changed files with 116 additions and 92 deletions
|
@ -10,6 +10,8 @@ import java.util.Map;
|
|||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
||||
|
||||
/**
|
||||
* User: bdc34
|
||||
* Date: Oct 18, 2007
|
||||
|
@ -71,6 +73,8 @@ public interface Individual extends ResourceBean, VitroTimeWindowedResource, Com
|
|||
|
||||
/** Does the individual belong to this class? */
|
||||
boolean isVClass(String uri);
|
||||
|
||||
public boolean isMemberOfClassProhibitedFromSearch(ProhibitedFromSearch pfs);
|
||||
|
||||
void setObjectPropertyStatements(List<ObjectPropertyStatement> list);
|
||||
List<ObjectPropertyStatement> getObjectPropertyStatements();
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.json.JSONException;
|
|||
import org.json.JSONObject;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.filestorage.model.ImageInfo;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.sql.Timestamp;
|
||||
|
@ -195,6 +196,11 @@ public class IndividualImpl extends BaseResourceBean implements Individual, Comp
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isMemberOfClassProhibitedFromSearch(ProhibitedFromSearch pfs) {
|
||||
throw new UnsupportedOperationException(this.getClass().getName() +
|
||||
".isMemberOfClassProhibitedFromSearch must be overriden by a subclass");
|
||||
}
|
||||
|
||||
public List<VClass> getVClasses(boolean direct) {
|
||||
if (direct) {
|
||||
|
|
|
@ -13,6 +13,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
|||
import edu.cornell.mannlib.vitro.webapp.beans.Keyword;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.beans.ObjectSourceIface;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
||||
|
||||
public interface IndividualDao extends ObjectSourceIface {
|
||||
|
||||
|
@ -105,7 +106,7 @@ public interface IndividualDao extends ObjectSourceIface {
|
|||
|
||||
int getCountOfIndividualsInVClass(String vclassURI );
|
||||
|
||||
public boolean isIndividualOfClass(String vclassURI, String indURI);
|
||||
public boolean isIndividualOfClass(String vclassURI, String indURI);
|
||||
|
||||
/**
|
||||
* Returns a list of individuals with the given value for the given dataProperty. If
|
||||
|
|
|
@ -27,6 +27,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
|||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
||||
|
||||
/**
|
||||
* A Individual object that will delegate to an inner Individual
|
||||
|
@ -517,7 +518,11 @@ public class IndividualFiltering implements Individual {
|
|||
return _innerIndividual.isVClass(uri);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isMemberOfClassProhibitedFromSearch(ProhibitedFromSearch pfs) {
|
||||
return _innerIndividual.isMemberOfClassProhibitedFromSearch(pfs);
|
||||
}
|
||||
|
||||
public void setDataPropertyMap(Map<String, DataProperty> propertyMap) {
|
||||
_innerIndividual.setDataPropertyMap(propertyMap);
|
||||
}
|
||||
|
|
|
@ -114,17 +114,17 @@ public class VClassDaoFiltering extends BaseFiltering implements VClassDao{
|
|||
if(list == null )
|
||||
return null;
|
||||
filter(list,filters.getClassFilter());
|
||||
correctVClassCounts(list);
|
||||
//correctVClassCounts(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<VClass> getOntologyRootClasses(String ontologyURI) {
|
||||
return (List<VClass>)correctVClassCounts(innerVClassDao.getOntologyRootClasses(ontologyURI));
|
||||
return innerVClassDao.getOntologyRootClasses(ontologyURI);
|
||||
}
|
||||
|
||||
|
||||
public List <VClass>getRootClasses() {
|
||||
return correctVClassCounts(innerVClassDao.getRootClasses());
|
||||
return innerVClassDao.getRootClasses();
|
||||
}
|
||||
|
||||
|
||||
|
@ -142,13 +142,13 @@ public class VClassDaoFiltering extends BaseFiltering implements VClassDao{
|
|||
|
||||
|
||||
public List<VClass> getVClassesForProperty(String propertyURI, boolean domainSide) {
|
||||
List<VClass> list = innerVClassDao.getVClassesForProperty(propertyURI, domainSide);
|
||||
return correctVClassCounts(filter(list,filters.getClassFilter()));
|
||||
return innerVClassDao.getVClassesForProperty(propertyURI, domainSide);
|
||||
//return correctVClassCounts(filter(list,filters.getClassFilter()));
|
||||
}
|
||||
|
||||
public List<VClass> getVClassesForProperty(String vclassURI, String propertyURI) {
|
||||
List<VClass> list = innerVClassDao.getVClassesForProperty(vclassURI, propertyURI);
|
||||
return correctVClassCounts(filter(list,filters.getClassFilter()));
|
||||
return innerVClassDao.getVClassesForProperty(vclassURI, propertyURI);
|
||||
//return correctVClassCounts(filter(list,filters.getClassFilter()));
|
||||
}
|
||||
|
||||
public void insertNewVClass(VClass cls) throws InsertException {
|
||||
|
@ -167,7 +167,7 @@ public class VClassDaoFiltering extends BaseFiltering implements VClassDao{
|
|||
}
|
||||
|
||||
public void addVClassesToGroup(VClassGroup group, boolean includeUninstantiatedClasses) {
|
||||
this.addVClassesToGroup(group, includeUninstantiatedClasses, true);
|
||||
this.addVClassesToGroup(group, includeUninstantiatedClasses, false);
|
||||
}
|
||||
|
||||
public void addVClassesToGroup(VClassGroup group,
|
||||
|
|
|
@ -140,54 +140,36 @@ public class IndividualDaoJena extends JenaBaseDao implements IndividualDao {
|
|||
}
|
||||
|
||||
public List getIndividualsByVClassURI(String vclassURI, int offset, int quantity ) {
|
||||
if (vclassURI==null) {
|
||||
|
||||
if (vclassURI==null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List ents = new ArrayList();
|
||||
Resource theClass = null;
|
||||
|
||||
Resource theClass = (vclassURI.indexOf(PSEUDO_BNODE_NS) == 0)
|
||||
? getOntModel().createResource(new AnonId(vclassURI.split("#")[1]))
|
||||
: ResourceFactory.createResource(vclassURI);
|
||||
|
||||
getOntModel().enterCriticalSection(Lock.READ);
|
||||
try {
|
||||
if (vclassURI.indexOf(PSEUDO_BNODE_NS)==0) {
|
||||
ClosableIterator closeIt = getOntModel().listClasses();
|
||||
try {
|
||||
for (Iterator clsIt = closeIt ; clsIt.hasNext();) {
|
||||
OntClass cls = (OntClass) clsIt.next();
|
||||
if (cls.isAnon() && cls.getId().toString().equals(vclassURI.split("#")[1])) {
|
||||
theClass = cls;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
closeIt.close();
|
||||
}
|
||||
} else {
|
||||
theClass = getOntModel().getOntClass(vclassURI);
|
||||
}
|
||||
} finally {
|
||||
getOntModel().leaveCriticalSection();
|
||||
}
|
||||
|
||||
if (theClass == null) {
|
||||
theClass = ResourceFactory.createResource(vclassURI);
|
||||
}
|
||||
|
||||
getOntModel().enterCriticalSection(Lock.READ);
|
||||
try {
|
||||
ClosableIterator indIt = getOntModel().listIndividuals(theClass);
|
||||
StmtIterator stmtIt = getOntModel().listStatements((Resource) null, RDF.type, theClass);
|
||||
try {
|
||||
while (indIt.hasNext()) {
|
||||
com.hp.hpl.jena.ontology.Individual ind = (com.hp.hpl.jena.ontology.Individual) indIt.next();
|
||||
while (stmtIt.hasNext()) {
|
||||
Statement stmt = stmtIt.nextStatement();
|
||||
OntResource ind = (OntResource) stmt.getSubject().as(OntResource.class);
|
||||
ents.add(new IndividualJena(ind, (WebappDaoFactoryJena) getWebappDaoFactory()));
|
||||
}
|
||||
} finally {
|
||||
indIt.close();
|
||||
stmtIt.close();
|
||||
}
|
||||
} finally {
|
||||
getOntModel().leaveCriticalSection();
|
||||
}
|
||||
java.util.Collections.sort(ents);
|
||||
|
||||
return ents;
|
||||
java.util.Collections.sort(ents);
|
||||
|
||||
return ents;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ import com.hp.hpl.jena.rdf.model.Literal;
|
|||
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.StmtIterator;
|
||||
import com.hp.hpl.jena.shared.Lock;
|
||||
import com.hp.hpl.jena.util.iterator.ClosableIterator;
|
||||
import com.hp.hpl.jena.vocabulary.OWL;
|
||||
|
@ -42,6 +43,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
|||
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||
import edu.cornell.mannlib.vitro.webapp.filestorage.model.ImageInfo;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.FlagMathUtils;
|
||||
|
||||
public class IndividualJena extends IndividualImpl implements Individual {
|
||||
|
@ -820,6 +822,30 @@ public class IndividualJena extends IndividualImpl implements Individual {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMemberOfClassProhibitedFromSearch(ProhibitedFromSearch pfs) {
|
||||
ind.getModel().enterCriticalSection(Lock.READ);
|
||||
try {
|
||||
StmtIterator stmtIt = ind.listProperties(RDF.type);
|
||||
try {
|
||||
while(stmtIt.hasNext()) {
|
||||
Statement stmt = stmtIt.nextStatement();
|
||||
if (stmt.getObject().isURIResource()) {
|
||||
String typeURI = ((Resource)stmt.getObject()).getURI();
|
||||
if (pfs.isClassProhibited(typeURI)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
stmtIt.close();
|
||||
}
|
||||
return false;
|
||||
} finally {
|
||||
ind.getModel().leaveCriticalSection();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overriding the base method so that we can do the sorting by arbitrary property here. An
|
||||
|
|
|
@ -410,7 +410,7 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
|
|||
p.setInverseOf(inv);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("Couldn't set "+prop.getURIInverse()+" as inverse");
|
||||
log.debug("Couldn't set "+prop.getURIInverse()+" as inverse");
|
||||
// BJL: What we really want to do here is create a new property as inverse
|
||||
}
|
||||
}
|
||||
|
|
|
@ -768,7 +768,7 @@ public class VClassDaoJena extends JenaBaseDao implements VClassDao {
|
|||
|
||||
@Deprecated
|
||||
public void addVClassesToGroup(VClassGroup group, boolean includeUninstantiatedClasses) {
|
||||
addVClassesToGroup(group, includeUninstantiatedClasses, true);
|
||||
addVClassesToGroup(group, includeUninstantiatedClasses, false);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
|
|
|
@ -172,15 +172,17 @@ public class SelectListGenerator {
|
|||
if( vclasses.size() == 0 )
|
||||
log.error("no owl:Class found for predicate " + predicateUri );
|
||||
|
||||
HashMap<String,Individual> indMap = new HashMap<String,Individual>();
|
||||
List<Individual> individuals = new ArrayList<Individual>();
|
||||
HashSet<String> uriSet = new HashSet<String>();
|
||||
long startTime = System.currentTimeMillis();
|
||||
for ( VClass vclass : vclasses){
|
||||
for( Individual ind : wDaoFact.getIndividualDao().getIndividualsByVClassURI(vclass.getURI(),-1,-1)) {
|
||||
if( !indMap.containsKey(ind.getURI())) {
|
||||
indMap.put(ind.getURI(),ind);
|
||||
if( !uriSet.contains(ind.getURI())) {
|
||||
uriSet.add(ind.getURI());
|
||||
individuals.add(ind);
|
||||
}
|
||||
}
|
||||
}
|
||||
List<Individual> individuals = new ArrayList<Individual>(indMap.values());
|
||||
|
||||
List<ObjectPropertyStatement> stmts = subject.getObjectPropertyStatements();
|
||||
if( stmts == null ) log.error("object properties for subject were null in SelectListGenerator.getOptions()");
|
||||
|
@ -192,24 +194,12 @@ public class SelectListGenerator {
|
|||
|
||||
for( Individual ind : individuals ){
|
||||
String uri = ind.getURI();
|
||||
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;
|
||||
}
|
||||
if( uri != null && (pfs == null || !ind.isMemberOfClassProhibitedFromSearch(pfs)) ){
|
||||
optionsMap.put(uri,ind.getName().trim());
|
||||
++optionsCount;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -292,23 +282,9 @@ public class SelectListGenerator {
|
|||
ProhibitedFromSearch pfs = editConfig.getProhibitedFromSearch();
|
||||
for( Individual ind : individuals ) {
|
||||
String uri = ind.getURI();
|
||||
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;
|
||||
}
|
||||
if( uri != null && (pfs == null || !ind.isMemberOfClassProhibitedFromSearch(pfs)) ) {
|
||||
optionsMap.put(uri,ind.getName().trim());
|
||||
++optionsCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,8 +80,7 @@ public class MiscWebUtils {
|
|||
return (String) contentObj;
|
||||
}
|
||||
|
||||
public static String getCustomShortView(HttpServletRequest request) {
|
||||
|
||||
public static String getCustomShortView(HttpServletRequest request) {
|
||||
Individual object = ((ObjectPropertyStatement) request
|
||||
.getAttribute("opStmt")).getObject();
|
||||
return getCustomShortView(object, request);
|
||||
|
|
|
@ -481,7 +481,10 @@ public class InputElementFormattingTag extends TagSupport {
|
|||
} else if( getType().equalsIgnoreCase("select")) {
|
||||
String valueStr = doValue(editConfig, editSub);
|
||||
//String sizeStr = getSize(); //"style=\"width:"+getSize()+"%;\"";
|
||||
Map <String,String> optionsMap = SelectListGenerator.getOptions(editConfig,getName(), wdf);
|
||||
Map<String,String> optionsMap = (Map<String,String>) pageContext.getRequest().getAttribute("rangeOptions." + getId());
|
||||
if (optionsMap == null) {
|
||||
optionsMap = SelectListGenerator.getOptions(editConfig,getName(), wdf);
|
||||
}
|
||||
if (optionsMap==null){
|
||||
log.error("Error in InputElementFormattingTag.doStartTag(): null optionsMap returned from getOptions()");
|
||||
}
|
||||
|
@ -515,7 +518,10 @@ public class InputElementFormattingTag extends TagSupport {
|
|||
} else if( getType().equalsIgnoreCase("checkbox")) {
|
||||
String valueStr = doValue(editConfig, editSub);
|
||||
if (definitionTags) { out.print("<dd>"); }
|
||||
Map <String,String> optionsMap = SelectListGenerator.getOptions(editConfig,getName(),wdf);
|
||||
Map<String,String> optionsMap = (Map<String,String>) pageContext.getRequest().getAttribute("rangeOptions." + getId());
|
||||
if (optionsMap == null) {
|
||||
optionsMap = SelectListGenerator.getOptions(editConfig,getName(),wdf);
|
||||
}
|
||||
if (optionsMap==null){
|
||||
log.error("Error in InputElementFormattingTag.doStartTag(): null optionsMap returned from getOptions()");
|
||||
}
|
||||
|
@ -534,7 +540,10 @@ public class InputElementFormattingTag extends TagSupport {
|
|||
} else if( getType().equalsIgnoreCase("radio")) {
|
||||
String valueStr = doValue(editConfig, editSub);
|
||||
if (definitionTags) { out.print("<dd>"); }
|
||||
Map <String,String> optionsMap = SelectListGenerator.getOptions(editConfig,getName(),wdf);
|
||||
Map<String,String> optionsMap = (Map<String,String>) pageContext.getRequest().getAttribute("rangeOptions." + getId());
|
||||
if (optionsMap == null) {
|
||||
optionsMap = SelectListGenerator.getOptions(editConfig,getName(),wdf);
|
||||
}
|
||||
if (optionsMap==null){
|
||||
log.error("Error in InputElementFormattingTag.doStartTag(): null optionsMap returned from getOptions()");
|
||||
}
|
||||
|
|
|
@ -24,7 +24,10 @@
|
|||
%>
|
||||
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.SelectListGenerator"%>
|
||||
<%@page import="java.util.Map"%><v:jsonset var="queryForInverse" >
|
||||
<%@page import="java.util.Map"%>
|
||||
<%@page import="com.hp.hpl.jena.ontology.OntModel"%>
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch"%>
|
||||
<%@page import="edu.cornell.mannlib.vitro.webapp.web.DisplayVocabulary"%><v:jsonset var="queryForInverse" >
|
||||
PREFIX owl: <http://www.w3.org/2002/07/owl#>
|
||||
SELECT ?inverse_property
|
||||
WHERE {
|
||||
|
@ -131,11 +134,24 @@
|
|||
}
|
||||
|
||||
if( prop.getSelectFromExisting() ){
|
||||
// set ProhibitedFromSearch object so picklist doesn't show
|
||||
// individuals from classes that should be hidden from list views
|
||||
OntModel displayOntModel =
|
||||
(OntModel) pageContext.getServletContext()
|
||||
.getAttribute("displayOntModel");
|
||||
if (displayOntModel != null) {
|
||||
ProhibitedFromSearch pfs = new ProhibitedFromSearch(
|
||||
DisplayVocabulary.PRIMARY_LUCENE_INDEX_URI, displayOntModel);
|
||||
if( editConfig != null )
|
||||
editConfig.setProhibitedFromSearch(pfs);
|
||||
}
|
||||
Map<String,String> rangeOptions = SelectListGenerator.getOptions(editConfig, "objectVar" , wdf);
|
||||
if( rangeOptions != null && rangeOptions.size() > 0 )
|
||||
if( rangeOptions != null && rangeOptions.size() > 0 ) {
|
||||
request.setAttribute("rangeOptionsExist", true);
|
||||
else
|
||||
request.setAttribute("rangeOptions.objectVar", rangeOptions);
|
||||
} else {
|
||||
request.setAttribute("rangeOptionsExist",false);
|
||||
}
|
||||
}
|
||||
%>
|
||||
<jsp:include page="${preForm}"/>
|
||||
|
@ -150,7 +166,7 @@
|
|||
</c:if>
|
||||
<v:input type="select" id="objectVar" size="80" />
|
||||
<div style="margin-top: 1em">
|
||||
<v:input type="submit" id="submit" value="<%=submitLabel%>" cancel="true"/>
|
||||
<v:input type="submit" id="submit" value="<%=submitLabel%>" cancel="true"/>
|
||||
</div>
|
||||
</form>
|
||||
</c:if>
|
||||
|
|
Loading…
Add table
Reference in a new issue