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);
|
Individual subject = wDaoFact.getIndividualDao().getIndividualByURI(subjectUri);
|
||||||
ObjectProperty objProp = wDaoFact.getObjectPropertyDao().getObjectPropertyByURI(predicateUri);
|
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;
|
return optionsMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Individual> individuals = new ArrayList<Individual>();
|
List<Individual> individuals = new ArrayList<Individual>();
|
||||||
HashSet<String> uriSet = new HashSet<String>();
|
HashSet<String> uriSet = new HashSet<String>();
|
||||||
for (VClass vclass : vclasses) {
|
for (String vclassURI: vclassesURIs) {
|
||||||
List<Individual> inds = wDaoFact.getIndividualDao().getIndividualsByVClassURI(vclass.getURI(), -1, -1);
|
List<Individual> inds = wDaoFact.getIndividualDao().getIndividualsByVClassURI(vclassURI, -1, -1);
|
||||||
for (Individual ind : inds) {
|
for (Individual ind : inds) {
|
||||||
if (!uriSet.contains(ind.getURI())) {
|
if (!uriSet.contains(ind.getURI())) {
|
||||||
uriSet.add(ind.getURI());
|
uriSet.add(ind.getURI());
|
||||||
|
@ -88,7 +101,7 @@ public class IndividualsViaObjectPropetyOptions implements FieldOptions {
|
||||||
|
|
||||||
individuals = removeIndividualsAlreadyInRange(
|
individuals = removeIndividualsAlreadyInRange(
|
||||||
individuals, stmts, predicateUri, objectUri);
|
individuals, stmts, predicateUri, objectUri);
|
||||||
// Collections.sort(individuals,new compareIndividualsByName());
|
// Collections.sort(individuals,new compareIndividualsByName());a
|
||||||
|
|
||||||
for (Individual ind : individuals) {
|
for (Individual ind : individuals) {
|
||||||
String uri = ind.getURI();
|
String uri = ind.getURI();
|
||||||
|
|
|
@ -7,6 +7,7 @@ import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -101,15 +102,23 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<String> getRangeTypes(VitroRequest vreq) {
|
protected List<String> getRangeTypes(VitroRequest vreq) {
|
||||||
Individual subject = EditConfigurationUtils.getSubjectIndividual(vreq);
|
Individual subject = EditConfigurationUtils.getSubjectIndividual(vreq);
|
||||||
String predicateUri = EditConfigurationUtils.getPredicateUri(vreq);
|
String predicateUri = EditConfigurationUtils.getPredicateUri(vreq);
|
||||||
WebappDaoFactory wDaoFact = vreq.getWebappDaoFactory();
|
WebappDaoFactory wDaoFact = vreq.getWebappDaoFactory();
|
||||||
List<String> types = new ArrayList<String>();
|
List<String> types = new ArrayList<String>();
|
||||||
List <VClass> vclasses = new ArrayList<VClass>();
|
//Get all vclasses applicable to subject
|
||||||
vclasses = wDaoFact.getVClassDao().getVClassesForProperty(subject.getVClassURI(),predicateUri);
|
List<VClass> vClasses = subject.getVClasses();
|
||||||
for(VClass v: vclasses) {
|
HashSet<String> typesHash = new HashSet<String>();
|
||||||
types.add(v.getURI());
|
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;
|
return types;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
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
|
//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() {
|
public Map<String, String> getOfferTypesCreateNew() {
|
||||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
||||||
ObjectProperty op =
|
ObjectProperty op =
|
||||||
|
@ -513,9 +515,34 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel {
|
||||||
wdf.getIndividualDao().getIndividualByURI(editConfig.getSubjectUri());
|
wdf.getIndividualDao().getIndividualByURI(editConfig.getSubjectUri());
|
||||||
|
|
||||||
List<VClass> vclasses = null;
|
List<VClass> vclasses = null;
|
||||||
vclasses = wdf.getVClassDao().getVClassesForProperty(sub.getVClassURI(), op.getURI());
|
List<VClass> subjectVClasses = sub.getVClasses();
|
||||||
if( vclasses == null )
|
if( subjectVClasses == null ) {
|
||||||
vclasses = wdf.getVClassDao().getAllVclasses();
|
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>();
|
HashMap<String,String> types = new HashMap<String, String>();
|
||||||
for( VClass vclass : vclasses ){
|
for( VClass vclass : vclasses ){
|
||||||
|
|
Loading…
Add table
Reference in a new issue