enable default object property form to calculate range options based on all vclasses for subject
This commit is contained in:
parent
cd7fe20cac
commit
1d880ea29d
3 changed files with 63 additions and 14 deletions
|
@ -66,16 +66,29 @@ public class IndividualsViaObjectPropetyOptions implements FieldOptions {
|
|||
|
||||
Individual subject = wDaoFact.getIndividualDao().getIndividualByURI(subjectUri);
|
||||
ObjectProperty objProp = wDaoFact.getObjectPropertyDao().getObjectPropertyByURI(predicateUri);
|
||||
List<VClass> vclasses = wDaoFact.getVClassDao().getVClassesForProperty(subject.getVClassURI(), predicateUri);
|
||||
//get all vclasses applicable to the individual subject
|
||||
List<VClass> subjectVClasses = subject.getVClasses();
|
||||
//using hashset to prevent duplicates
|
||||
HashSet<String> vclassesURIs = new HashSet<String>();
|
||||
//Get the range vclasses applicable for the property and each vclass for the subject
|
||||
for(VClass subjectVClass: subjectVClasses) {
|
||||
List<VClass> vclasses = wDaoFact.getVClassDao().getVClassesForProperty(subjectVClass.getURI(), predicateUri);
|
||||
//add range vclass to hash
|
||||
if(vclasses != null) {
|
||||
for(VClass v: vclasses) {
|
||||
vclassesURIs.add(v.getURI());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (vclasses == null || vclasses.size() == 0) {
|
||||
if (vclassesURIs.size() == 0) {
|
||||
return optionsMap;
|
||||
}
|
||||
|
||||
List<Individual> individuals = new ArrayList<Individual>();
|
||||
HashSet<String> uriSet = new HashSet<String>();
|
||||
for (VClass vclass : vclasses) {
|
||||
List<Individual> inds = wDaoFact.getIndividualDao().getIndividualsByVClassURI(vclass.getURI(), -1, -1);
|
||||
for (String vclassURI: vclassesURIs) {
|
||||
List<Individual> inds = wDaoFact.getIndividualDao().getIndividualsByVClassURI(vclassURI, -1, -1);
|
||||
for (Individual ind : inds) {
|
||||
if (!uriSet.contains(ind.getURI())) {
|
||||
uriSet.add(ind.getURI());
|
||||
|
@ -88,7 +101,7 @@ public class IndividualsViaObjectPropetyOptions implements FieldOptions {
|
|||
|
||||
individuals = removeIndividualsAlreadyInRange(
|
||||
individuals, stmts, predicateUri, objectUri);
|
||||
// Collections.sort(individuals,new compareIndividualsByName());
|
||||
// Collections.sort(individuals,new compareIndividualsByName());a
|
||||
|
||||
for (Individual ind : individuals) {
|
||||
String uri = ind.getURI();
|
||||
|
|
|
@ -7,6 +7,7 @@ import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.*;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -105,11 +106,19 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene
|
|||
String predicateUri = EditConfigurationUtils.getPredicateUri(vreq);
|
||||
WebappDaoFactory wDaoFact = vreq.getWebappDaoFactory();
|
||||
List<String> types = new ArrayList<String>();
|
||||
List <VClass> vclasses = new ArrayList<VClass>();
|
||||
vclasses = wDaoFact.getVClassDao().getVClassesForProperty(subject.getVClassURI(),predicateUri);
|
||||
for(VClass v: vclasses) {
|
||||
types.add(v.getURI());
|
||||
//Get all vclasses applicable to subject
|
||||
List<VClass> vClasses = subject.getVClasses();
|
||||
HashSet<String> typesHash = new HashSet<String>();
|
||||
for(VClass vclass: vClasses) {
|
||||
List<VClass> rangeVclasses = wDaoFact.getVClassDao().getVClassesForProperty(vclass.getURI(),predicateUri);
|
||||
if(rangeVclasses != null) {
|
||||
for(VClass range: rangeVclasses) {
|
||||
//a hash will keep a unique list of types and so prevent duplicates
|
||||
typesHash.add(range.getURI());
|
||||
}
|
||||
}
|
||||
}
|
||||
types.addAll(typesHash);
|
||||
return types;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -504,6 +505,7 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel {
|
|||
|
||||
|
||||
//TODO:Check where this logic should actually go, copied from input element formatting tag
|
||||
//Updating to enable multiple vclasses applicable to subject to be analyzed to understand possible range of types
|
||||
public Map<String, String> getOfferTypesCreateNew() {
|
||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
||||
ObjectProperty op =
|
||||
|
@ -513,9 +515,34 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel {
|
|||
wdf.getIndividualDao().getIndividualByURI(editConfig.getSubjectUri());
|
||||
|
||||
List<VClass> vclasses = null;
|
||||
vclasses = wdf.getVClassDao().getVClassesForProperty(sub.getVClassURI(), op.getURI());
|
||||
if( vclasses == null )
|
||||
List<VClass> subjectVClasses = sub.getVClasses();
|
||||
if( subjectVClasses == null ) {
|
||||
vclasses = wdf.getVClassDao().getAllVclasses();
|
||||
}
|
||||
else {
|
||||
//this hash is used to make sure there are no duplicates in the vclasses
|
||||
//a more elegant method may look at overriding equals/hashcode to enable a single hashset of VClass objects
|
||||
HashSet<String> vclassesURIs = new HashSet<String>();
|
||||
vclasses = new ArrayList<VClass>();
|
||||
//Get the range vclasses applicable for the property and each vclass for the subject
|
||||
for(VClass subjectVClass: subjectVClasses) {
|
||||
List<VClass> rangeVclasses = wdf.getVClassDao().getVClassesForProperty(subjectVClass.getURI(), op.getURI());
|
||||
//add range vclass to hash
|
||||
if(rangeVclasses != null) {
|
||||
for(VClass v: rangeVclasses) {
|
||||
if(!vclassesURIs.contains(v.getURI())) {
|
||||
vclassesURIs.add(v.getURI());
|
||||
vclasses.add(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//if each subject vclass resulted in null being returned for range vclasses, then size of vclasses would be zero
|
||||
if(vclasses.size() == 0) {
|
||||
vclasses = wdf.getVClassDao().getAllVclasses();
|
||||
}
|
||||
|
||||
|
||||
HashMap<String,String> types = new HashMap<String, String>();
|
||||
for( VClass vclass : vclasses ){
|
||||
|
|
Loading…
Add table
Reference in a new issue