updates to allow individuals with most specific type in dropdown to exclude subject and any objects for object property
This commit is contained in:
parent
90fc8f7ffa
commit
20278bde17
3 changed files with 82 additions and 28 deletions
|
@ -19,6 +19,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
|||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.fields.FieldUtils;
|
||||
|
||||
public class IndividualsViaObjectPropetyOptions implements FieldOptions {
|
||||
|
||||
|
@ -100,7 +101,7 @@ public class IndividualsViaObjectPropetyOptions implements FieldOptions {
|
|||
|
||||
List<ObjectPropertyStatement> stmts = subject.getObjectPropertyStatements();
|
||||
|
||||
individuals = removeIndividualsAlreadyInRange(
|
||||
individuals = FieldUtils.removeIndividualsAlreadyInRange(
|
||||
individuals, stmts, predicateUri, objectUri);
|
||||
// Collections.sort(individuals,new compareIndividualsByName());a
|
||||
|
||||
|
@ -162,28 +163,7 @@ public class IndividualsViaObjectPropetyOptions implements FieldOptions {
|
|||
return filteredVClassesURIs;
|
||||
}
|
||||
|
||||
// copied from OptionsForPropertyTag.java in the thought that class may be deprecated
|
||||
private static List<Individual> removeIndividualsAlreadyInRange(List<Individual> individuals,
|
||||
List<ObjectPropertyStatement> stmts, String predicateUri, String objectUriBeingEdited){
|
||||
HashSet<String> range = new HashSet<String>();
|
||||
|
||||
for(ObjectPropertyStatement ops : stmts){
|
||||
if( ops.getPropertyURI().equals(predicateUri))
|
||||
range.add( ops.getObjectURI() );
|
||||
}
|
||||
|
||||
int removeCount=0;
|
||||
ListIterator<Individual> it = individuals.listIterator();
|
||||
while(it.hasNext()){
|
||||
Individual ind = it.next();
|
||||
if( range.contains( ind.getURI()) && !(ind.getURI().equals(objectUriBeingEdited)) ) {
|
||||
it.remove();
|
||||
++removeCount;
|
||||
}
|
||||
}
|
||||
|
||||
return individuals;
|
||||
}
|
||||
|
||||
|
||||
public Comparator<String[]> getCustomComparator() {
|
||||
return null;
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
@ -18,11 +19,13 @@ import org.apache.solr.common.SolrDocument;
|
|||
import org.apache.solr.common.SolrDocumentList;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.fields.FieldUtils;
|
||||
|
||||
/*
|
||||
* This runs a solr query to get individuals of a certain class instead of relying on the dao classes.
|
||||
|
@ -32,9 +35,15 @@ public class IndividualsViaSolrQueryOptions extends IndividualsViaVClassOptions
|
|||
private Log log = LogFactory.getLog(IndividualsViaSolrQueryOptions.class);
|
||||
|
||||
private ServletContext servletContext;
|
||||
public IndividualsViaSolrQueryOptions(ServletContext context, String ... vclassURIs) throws Exception {
|
||||
private String subjectUri;
|
||||
private String predicateUri;
|
||||
private String objectUri;
|
||||
public IndividualsViaSolrQueryOptions(ServletContext context, String inputSubjectUri, String inputPredicateUri, String inputObjectUri, String ... vclassURIs) throws Exception {
|
||||
super(vclassURIs);
|
||||
this.servletContext = context;
|
||||
this.subjectUri = inputSubjectUri;
|
||||
this.predicateUri = inputPredicateUri;
|
||||
this.objectUri = inputObjectUri;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -96,8 +105,18 @@ public class IndividualsViaSolrQueryOptions extends IndividualsViaVClassOptions
|
|||
//sort the individuals
|
||||
List<Individual> individuals = new ArrayList<Individual>();
|
||||
individuals.addAll(individualMap.values());
|
||||
Collections.sort(individuals);
|
||||
|
||||
//Here we will remove individuals already in the range
|
||||
Individual subject = wDaoFact.getIndividualDao().getIndividualByURI(subjectUri);
|
||||
List<ObjectPropertyStatement> stmts = subject.getObjectPropertyStatements();
|
||||
|
||||
individuals = FieldUtils.removeIndividualsAlreadyInRange(
|
||||
individuals, stmts, predicateUri, objectUri);
|
||||
//Also remove subjectUri if it
|
||||
individuals = removeSubjectUri(individuals, subjectUri);
|
||||
//sort the list
|
||||
Collections.sort(individuals);
|
||||
//set up the options map
|
||||
Map<String, String> optionsMap = new HashMap<String,String>();
|
||||
|
||||
if (defaultOptionLabel != null) {
|
||||
|
@ -117,8 +136,19 @@ public class IndividualsViaSolrQueryOptions extends IndividualsViaVClassOptions
|
|||
return optionsMap;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//TODO: Check if this can be done simply by reference
|
||||
private List<Individual> removeSubjectUri(List<Individual> individuals,
|
||||
String subjectUri) {
|
||||
ListIterator<Individual> it = individuals.listIterator();
|
||||
while(it.hasNext()){
|
||||
Individual ind = it.next();
|
||||
if( ind.getURI().equals(subjectUri)) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
return individuals;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
package edu.cornell.mannlib.vitro.webapp.utils.fields;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||
|
||||
public class FieldUtils {
|
||||
|
||||
private static final Log log = LogFactory.getLog(FieldUtils.class);
|
||||
|
||||
|
||||
// copied from OptionsForPropertyTag.java in the thought that class may be deprecated
|
||||
public static List<Individual> removeIndividualsAlreadyInRange(List<Individual> individuals,
|
||||
List<ObjectPropertyStatement> stmts, String predicateUri, String objectUriBeingEdited){
|
||||
HashSet<String> range = new HashSet<String>();
|
||||
|
||||
for(ObjectPropertyStatement ops : stmts){
|
||||
if( ops.getPropertyURI().equals(predicateUri))
|
||||
range.add( ops.getObjectURI() );
|
||||
}
|
||||
|
||||
int removeCount=0;
|
||||
ListIterator<Individual> it = individuals.listIterator();
|
||||
while(it.hasNext()){
|
||||
Individual ind = it.next();
|
||||
if( range.contains( ind.getURI()) && !(ind.getURI().equals(objectUriBeingEdited)) ) {
|
||||
it.remove();
|
||||
++removeCount;
|
||||
}
|
||||
}
|
||||
|
||||
return individuals;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue