Working on refactoring select option generation NIHVIVO-3657
This commit is contained in:
parent
41171a48f4
commit
f2707b0bb1
37 changed files with 1542 additions and 1042 deletions
|
@ -9,6 +9,7 @@ import java.util.Map;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
||||||
import freemarker.template.Configuration;
|
import freemarker.template.Configuration;
|
||||||
import freemarker.template.Template;
|
import freemarker.template.Template;
|
||||||
import freemarker.template.TemplateException;
|
import freemarker.template.TemplateException;
|
||||||
|
|
|
@ -24,6 +24,7 @@ import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Datatype;
|
import edu.cornell.mannlib.vitro.webapp.beans.Datatype;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.DatatypeDaoJena;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.DatatypeDaoJena;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission;
|
||||||
|
|
|
@ -135,7 +135,7 @@ public class DateTimeIntervalValidationVTwo implements N3ValidatorVTwo {
|
||||||
String precisionString = precisionStr.get(0);
|
String precisionString = precisionStr.get(0);
|
||||||
VitroVocabulary.Precision precision = DateTimeWithPrecision.toPrecision( precisionString );
|
VitroVocabulary.Precision precision = DateTimeWithPrecision.toPrecision( precisionString );
|
||||||
if( precision == null )
|
if( precision == null )
|
||||||
log.warn("cannot convert " + precisionStr + " to a precision");
|
log.debug("cannot convert " + precisionStr + " to a precision");
|
||||||
else
|
else
|
||||||
return precision;
|
return precision;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -20,6 +20,7 @@ import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerConfiguration;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerConfiguration;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission;
|
||||||
|
@ -133,8 +134,10 @@ public class DateTimeWithPrecisionVTwo extends BaseEditElementVTwo {
|
||||||
VitroVocabulary.Precision existingPrec = toPrecision(precisionUri);
|
VitroVocabulary.Precision existingPrec = toPrecision(precisionUri);
|
||||||
|
|
||||||
if( precisionUri != null && !"".equals(precisionUri) && existingPrec == null ){
|
if( precisionUri != null && !"".equals(precisionUri) && existingPrec == null ){
|
||||||
log.error("field " + getFieldName() + ": existing precision uri was " +
|
if( ! BLANK_SENTINEL.equals( precisionUri )){
|
||||||
|
log.warn("field " + getFieldName() + ": existing precision uri was " +
|
||||||
"'" + precisionUri + "' but could not convert to Precision object");
|
"'" + precisionUri + "' but could not convert to Precision object");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( precisionUri == null || precisionUri.isEmpty() || existingPrec == null){
|
if( precisionUri == null || precisionUri.isEmpty() || existingPrec == null){
|
||||||
|
|
|
@ -20,6 +20,7 @@ import com.hp.hpl.jena.vocabulary.XSD;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash;
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -29,6 +30,7 @@ import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.ModelSelector;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.ModelSelector;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.StandardModelSelector;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.StandardModelSelector;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.StandardWDFSelector;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.StandardWDFSelector;
|
||||||
|
@ -429,11 +431,14 @@ public class EditConfigurationVTwo {
|
||||||
return EditConfigurationUtils.copy(n3Required);
|
return EditConfigurationUtils.copy(n3Required);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: can we use varargs here?
|
|
||||||
public void setN3Required(List<String> n3Required) {
|
public void setN3Required(List<String> n3Required) {
|
||||||
this.n3Required = n3Required;
|
this.n3Required = n3Required;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setN3Required(String ... n3RequiredStrs){
|
||||||
|
this.n3Required = Arrays.asList( n3RequiredStrs );
|
||||||
|
}
|
||||||
|
|
||||||
/** return a copy of the value so that the configuration is not modified by external code.
|
/** return a copy of the value so that the configuration is not modified by external code.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@ -445,6 +450,11 @@ public class EditConfigurationVTwo {
|
||||||
this.n3Optional = n3Optional;
|
this.n3Optional = n3Optional;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setN3Optional(String ... n3Strs){
|
||||||
|
this.n3Optional = Arrays.asList( n3Strs );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public Map<String,String> getNewResources() {
|
public Map<String,String> getNewResources() {
|
||||||
return newResources;
|
return newResources;
|
||||||
}
|
}
|
||||||
|
@ -452,7 +462,21 @@ public class EditConfigurationVTwo {
|
||||||
public void setNewResources(Map<String,String> newResources) {
|
public void setNewResources(Map<String,String> newResources) {
|
||||||
this.newResources = newResources;
|
this.newResources = newResources;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setNewResources(String ... strs){
|
||||||
|
if( strs == null || strs.length % 2 != 0 ){
|
||||||
|
throw new Error(" setNewResources() must have pairs of varName, prefix ");
|
||||||
|
}
|
||||||
|
Map<String,String> map = new HashMap<String,String>();
|
||||||
|
|
||||||
|
for( int i=0;i<strs.length;i=i+2 ){
|
||||||
|
map.put(strs[i],strs[i+1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.newResources = map;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<String> getUrisOnform() {
|
public List<String> getUrisOnform() {
|
||||||
return urisOnform;
|
return urisOnform;
|
||||||
}
|
}
|
||||||
|
@ -461,6 +485,10 @@ public class EditConfigurationVTwo {
|
||||||
this.urisOnform = urisOnform;
|
this.urisOnform = urisOnform;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setUrisOnForm(String ... strs){
|
||||||
|
this.urisOnform = Arrays.asList( strs );
|
||||||
|
}
|
||||||
|
|
||||||
public void setFilesOnForm(List<String> filesOnForm){
|
public void setFilesOnForm(List<String> filesOnForm){
|
||||||
this.filesOnForm = filesOnForm;
|
this.filesOnForm = filesOnForm;
|
||||||
}
|
}
|
||||||
|
@ -477,6 +505,11 @@ public class EditConfigurationVTwo {
|
||||||
this.literalsOnForm = literalsOnForm;
|
this.literalsOnForm = literalsOnForm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setLiteralsOnForm(String ... strs){
|
||||||
|
this.literalsOnForm = Arrays.asList( strs );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public Map<String, List<String>> getUrisInScope() {
|
public Map<String, List<String>> getUrisInScope() {
|
||||||
return urisInScope;
|
return urisInScope;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,229 +0,0 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo;
|
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
|
||||||
import org.apache.commons.lang.builder.ToStringStyle;
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.MultiValueEditSubmission;
|
|
||||||
public class FieldVTwo {
|
|
||||||
|
|
||||||
public enum OptionsType {
|
|
||||||
LITERALS,
|
|
||||||
HARDCODED_LITERALS,
|
|
||||||
STRINGS_VIA_DATATYPE_PROPERTY,
|
|
||||||
INDIVIDUALS_VIA_OBJECT_PROPERTY,
|
|
||||||
INDIVIDUALS_VIA_VCLASS,
|
|
||||||
CHILD_VCLASSES,
|
|
||||||
CHILD_VCLASSES_WITH_PARENT,
|
|
||||||
VCLASSGROUP,
|
|
||||||
FILE,
|
|
||||||
UNDEFINED,
|
|
||||||
DATETIME,
|
|
||||||
DATE,
|
|
||||||
TIME
|
|
||||||
};
|
|
||||||
|
|
||||||
public static String RDF_XML_LITERAL_URI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral";
|
|
||||||
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* List of basic validators. See BaiscValidation.
|
|
||||||
*/
|
|
||||||
private List <String> validators = new ArrayList<String>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* What type of options is this?
|
|
||||||
*/
|
|
||||||
private OptionsType optionsType = OptionsType.UNDEFINED;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Special class to use for option type
|
|
||||||
*/
|
|
||||||
private Class customOptionType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used for building Options when OptionsType is INDIVIDUALS_VIA_OBJECT_PROPERTY
|
|
||||||
*/
|
|
||||||
private String predicateUri;
|
|
||||||
/**
|
|
||||||
* Used for building Options when OptionsType is INDIVIDUALS_VIA_VCLASS
|
|
||||||
*/
|
|
||||||
private String objectClassUri;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used for holding the expected/required datatype of the predicate when the predicate is a datatype propertyl.
|
|
||||||
* this can be a explicit URI or a qname.
|
|
||||||
* example:
|
|
||||||
* "this is the literal"^^<http://someuri.com/v1.2#type23>
|
|
||||||
* or
|
|
||||||
* "this is the literal"^^someprefix:type23
|
|
||||||
*/
|
|
||||||
private String rangeDatatypeUri;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used for holding the language of the literal when the predicate is a datatype property.
|
|
||||||
* This is the lang of the literal. lang strings must be: [a-z]+(-[a-z0-9]+)*
|
|
||||||
*/
|
|
||||||
private String rangeLang;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If this is a Select and it is of OptionsType LITERALS, these are the literals.
|
|
||||||
*/
|
|
||||||
private List<List<String>> literalOptions;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Property for special edit element.
|
|
||||||
*/
|
|
||||||
private EditElementVTwo editElement=null;;
|
|
||||||
|
|
||||||
/* *********************** Constructors ************************** */
|
|
||||||
|
|
||||||
public FieldVTwo() {}
|
|
||||||
|
|
||||||
private static String[] parameterNames = {"editElement","newResource","validators","optionsType","predicateUri","objectClassUri","rangeDatatypeUri","rangeLang","literalOptions","assertions"};
|
|
||||||
static{ Arrays.sort(parameterNames); }
|
|
||||||
|
|
||||||
public FieldVTwo setEditElement(EditElementVTwo editElement){
|
|
||||||
this.editElement = editElement;
|
|
||||||
|
|
||||||
if( editElement instanceof BaseEditElementVTwo)
|
|
||||||
((BaseEditElementVTwo) editElement).setField(this);
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ****************** Getters and Setters ******************************* */
|
|
||||||
|
|
||||||
public String getName(){
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List <String> getValidators() {
|
|
||||||
return validators;
|
|
||||||
}
|
|
||||||
public FieldVTwo setValidators(List <String> v) {
|
|
||||||
validators = v;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OptionsType getOptionsType() {
|
|
||||||
return optionsType;
|
|
||||||
}
|
|
||||||
public FieldVTwo setOptionsType(OptionsType ot) {
|
|
||||||
optionsType = ot;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
public FieldVTwo setOptionsType(String s) {
|
|
||||||
setOptionsType( getOptionForString(s));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static OptionsType getOptionForString(String s){
|
|
||||||
if( s== null || s.isEmpty() )
|
|
||||||
return OptionsType.UNDEFINED;
|
|
||||||
if ("LITERALS".equals(s)) {
|
|
||||||
return FieldVTwo.OptionsType.LITERALS;
|
|
||||||
} else if ("HARDCODED_LITERALS".equals(s)) {
|
|
||||||
return FieldVTwo.OptionsType.HARDCODED_LITERALS;
|
|
||||||
} else if ("STRINGS_VIA_DATATYPE_PROPERTY".equalsIgnoreCase(s)) {
|
|
||||||
return FieldVTwo.OptionsType.STRINGS_VIA_DATATYPE_PROPERTY;
|
|
||||||
} else if ("INDIVIDUALS_VIA_OBJECT_PROPERTY".equalsIgnoreCase(s)) {
|
|
||||||
return FieldVTwo.OptionsType.INDIVIDUALS_VIA_OBJECT_PROPERTY;
|
|
||||||
} else if ("INDIVIDUALS_VIA_VCLASS".equalsIgnoreCase(s)) {
|
|
||||||
return FieldVTwo.OptionsType.INDIVIDUALS_VIA_VCLASS;
|
|
||||||
} else if ("DATETIME".equalsIgnoreCase(s)) {
|
|
||||||
return FieldVTwo.OptionsType.DATETIME;
|
|
||||||
} else if ("CHILD_VCLASSES".equalsIgnoreCase(s)) {
|
|
||||||
return FieldVTwo.OptionsType.CHILD_VCLASSES;
|
|
||||||
} else if ("CHILD_VCLASSES_WITH_PARENT".equalsIgnoreCase(s)) {
|
|
||||||
return FieldVTwo.OptionsType.CHILD_VCLASSES_WITH_PARENT;
|
|
||||||
} else if ("VCLASSGROUP".equalsIgnoreCase(s)) {
|
|
||||||
return FieldVTwo.OptionsType.VCLASSGROUP;
|
|
||||||
} else if ("FILE".equalsIgnoreCase(s)) {
|
|
||||||
return FieldVTwo.OptionsType.FILE;
|
|
||||||
} else if ("DATE".equalsIgnoreCase(s)) {
|
|
||||||
return FieldVTwo.OptionsType.DATE;
|
|
||||||
} else if ("TIME".equalsIgnoreCase(s)) {
|
|
||||||
return FieldVTwo.OptionsType.TIME;
|
|
||||||
} else {
|
|
||||||
return FieldVTwo.OptionsType.UNDEFINED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPredicateUri() {
|
|
||||||
return predicateUri;
|
|
||||||
}
|
|
||||||
public FieldVTwo setPredicateUri(String s) {
|
|
||||||
predicateUri = s;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getObjectClassUri() {
|
|
||||||
return objectClassUri;
|
|
||||||
}
|
|
||||||
public FieldVTwo setObjectClassUri(String s) {
|
|
||||||
objectClassUri = s;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRangeDatatypeUri() {
|
|
||||||
return rangeDatatypeUri;
|
|
||||||
}
|
|
||||||
public FieldVTwo setRangeDatatypeUri(String r) {
|
|
||||||
if( rangeLang != null && rangeLang.trim().length() > 0 )
|
|
||||||
throw new IllegalArgumentException("A Field object may not have both rangeDatatypeUri and rangeLanguage set");
|
|
||||||
|
|
||||||
rangeDatatypeUri = r;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List <List<String>> getLiteralOptions() {
|
|
||||||
return literalOptions;
|
|
||||||
}
|
|
||||||
public FieldVTwo setLiteralOptions(List<List<String>> literalOptions) {
|
|
||||||
this.literalOptions = literalOptions;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRangeLang() {
|
|
||||||
return rangeLang;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FieldVTwo setRangeLang(String rangeLang) {
|
|
||||||
if( rangeDatatypeUri != null && rangeDatatypeUri.trim().length() > 0)
|
|
||||||
throw new IllegalArgumentException("A Field object may not have both rangeDatatypeUri and rangeLanguage set");
|
|
||||||
|
|
||||||
this.rangeLang = rangeLang;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EditElementVTwo getEditElement(){
|
|
||||||
return editElement;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FieldVTwo setName(String name){
|
|
||||||
this.name = name;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString(){
|
|
||||||
return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -33,7 +33,7 @@ import com.hp.hpl.jena.vocabulary.XSD;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral;
|
import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditElementVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditElementVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.FieldVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.BasicValidation;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.BasicValidation;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.N3Validator;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.N3Validator;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Utils;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Utils;
|
||||||
|
|
|
@ -1,504 +0,0 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo;
|
|
||||||
|
|
||||||
import java.text.Collator;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.ListIterator;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
|
|
||||||
import com.hp.hpl.jena.vocabulary.OWL;
|
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
|
|
||||||
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;
|
|
||||||
|
|
||||||
public class SelectListGeneratorVTwo {
|
|
||||||
|
|
||||||
static Log log = LogFactory.getLog(SelectListGeneratorVTwo.class);
|
|
||||||
|
|
||||||
public static Map<String,String> getOptions(
|
|
||||||
EditConfigurationVTwo editConfig,
|
|
||||||
String fieldName,
|
|
||||||
WebappDaoFactory wDaoFact){
|
|
||||||
if( editConfig == null ){
|
|
||||||
log.error( "fieldToSelectItemList() must be called with a non-null EditConfigurationVTwo ");
|
|
||||||
return Collections.EMPTY_MAP;
|
|
||||||
}
|
|
||||||
if( fieldName == null ){
|
|
||||||
log.error( "fieldToSelectItemList() must be called with a non-null fieldName");
|
|
||||||
return Collections.EMPTY_MAP;
|
|
||||||
}
|
|
||||||
|
|
||||||
FieldVTwo field = editConfig.getField(fieldName);
|
|
||||||
if (field==null) {
|
|
||||||
log.error("no field \""+fieldName+"\" found from editConfig in SelectListGenerator.getOptions()");
|
|
||||||
return Collections.EMPTY_MAP;
|
|
||||||
}
|
|
||||||
// now create an empty HashMap to populate and return
|
|
||||||
HashMap <String,String> optionsMap = new LinkedHashMap<String,String>();
|
|
||||||
// for debugging, keep a count of the number of options populated
|
|
||||||
int optionsCount=0;
|
|
||||||
|
|
||||||
FieldVTwo.OptionsType optionsType = field.getOptionsType();
|
|
||||||
String vclassUri = null;
|
|
||||||
switch (optionsType){
|
|
||||||
case HARDCODED_LITERALS: // originally not auto-sorted but sorted now, and empty values not removed or replaced
|
|
||||||
List<List<String>> hardcodedLiteralOptions = field.getLiteralOptions();
|
|
||||||
if (hardcodedLiteralOptions==null) {
|
|
||||||
log.error("no literalOptions List found for field \""+fieldName+"\" in SelectListGenerator.getOptions() when OptionsType HARDCODED_LITERALS specified");
|
|
||||||
return new HashMap <String,String>();
|
|
||||||
}
|
|
||||||
for(Object obj: ((Iterable)hardcodedLiteralOptions)){
|
|
||||||
List<String> literalPair = (List)obj;
|
|
||||||
String value=(String)literalPair.get(0);
|
|
||||||
if( value != null){ // allow empty string as a value
|
|
||||||
String label=(String)literalPair.get(1);
|
|
||||||
if (label!=null) {
|
|
||||||
optionsMap.put(value,label);
|
|
||||||
} else {
|
|
||||||
optionsMap.put(value, value);
|
|
||||||
}
|
|
||||||
++optionsCount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case LITERALS:
|
|
||||||
List<List<String>> literalOptions = field.getLiteralOptions();
|
|
||||||
if (literalOptions==null) {
|
|
||||||
log.error("no literalOptions List found for field \""+fieldName+"\" in SelectListGenerator.getOptions() when OptionsType LITERALS specified");
|
|
||||||
return new HashMap <String,String>();
|
|
||||||
}
|
|
||||||
for(Object obj: ((Iterable)literalOptions)){
|
|
||||||
List<String> literalPair = (List)obj;
|
|
||||||
String value=(String)literalPair.get(0);
|
|
||||||
if( value != null && value.trim().length() > 0){
|
|
||||||
String label=(String)literalPair.get(1);
|
|
||||||
if (label!=null && label.trim().length() > 0) {
|
|
||||||
optionsMap.put(value,label);
|
|
||||||
} else {
|
|
||||||
optionsMap.put(value, value);
|
|
||||||
}
|
|
||||||
++optionsCount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case STRINGS_VIA_DATATYPE_PROPERTY:
|
|
||||||
log.debug("processing Field \""+fieldName+"\" optionType as a datatype property predicateUri in SelectListGenerator.getOptions()");
|
|
||||||
String dataPropUri = field.getPredicateUri();
|
|
||||||
if (dataPropUri==null || dataPropUri.equals("")){
|
|
||||||
log.error("no predicate dataPropUri found for field \""+fieldName+"\" in SelectListGenerator.getOptions() when OptionsType STRINGS_VIA_DATATYPE_PROPERTY specified");
|
|
||||||
} else {
|
|
||||||
/* first test to see whether there's a default "leave blank" value specified with the literal options
|
|
||||||
String defaultOption=null;
|
|
||||||
if ((defaultOption=getDefaultOption(field))!=null) {
|
|
||||||
optionsMap.put(LEFT_BLANK, defaultOption);
|
|
||||||
} */
|
|
||||||
// now populate the options
|
|
||||||
log.debug("finding all choices for data property \""+dataPropUri+"\" in SelectListGenerator.getOptions()");
|
|
||||||
|
|
||||||
if( wDaoFact == null ) log.error("incoming WebappDaoFactory from request is null in SelectListGenerator.getOptions().");
|
|
||||||
|
|
||||||
DataPropertyStatementDao dpsDao = wDaoFact.getDataPropertyStatementDao();
|
|
||||||
DataPropertyDao dpDao = wDaoFact.getDataPropertyDao();
|
|
||||||
DataProperty dp = dpDao.getDataPropertyByURI(dataPropUri);
|
|
||||||
for (Iterator<DataPropertyStatement> i = dpsDao.getDataPropertyStatements(dp).iterator(); i.hasNext();) {
|
|
||||||
DataPropertyStatement dps = i.next();
|
|
||||||
if( dps != null ){
|
|
||||||
optionsMap.put(dps.getData().trim(),dps.getData().trim());
|
|
||||||
++optionsCount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case INDIVIDUALS_VIA_OBJECT_PROPERTY:
|
|
||||||
log.debug("processing Field \""+fieldName+"\" optionType as an object property predicateUri in SelectListGenerator.getOptions()");
|
|
||||||
String subjectUri = editConfig.getSubjectUri();
|
|
||||||
if (subjectUri==null || subjectUri.equals("")){
|
|
||||||
log.error("no subjectUri found for field \""+fieldName+"\" in SelectListGenerator.getOptions() when OptionsType INDIVIDUALS_VIA_OBJECTPROPERTY specified");
|
|
||||||
} else {
|
|
||||||
String predicateUri = field.getPredicateUri();
|
|
||||||
if (predicateUri==null || predicateUri.equals("")){
|
|
||||||
log.error("no predicateUri found for field \""+fieldName+"\" in SelectListGenerator.getOptions() when OptionsType INDIVIDUALS_VIA_OBJECTPROPERTY specified");
|
|
||||||
} else {
|
|
||||||
// first test to see whether there's a default "leave blank" value specified with the literal options
|
|
||||||
String defaultOption=null;
|
|
||||||
if ((defaultOption=getDefaultOption(field))!=null) {
|
|
||||||
optionsMap.put(LEFT_BLANK, defaultOption);
|
|
||||||
}
|
|
||||||
// now populate the options
|
|
||||||
log.debug("finding range individuals for subject \""+subjectUri+"\" and object property \""+predicateUri+"\" in SelectListGenerator.getOptions()");
|
|
||||||
|
|
||||||
if( wDaoFact == null ) log.error("could not get WebappDaoFactory from request in SelectListGenerator.getOptions().");
|
|
||||||
|
|
||||||
Individual subject = wDaoFact.getIndividualDao().getIndividualByURI(subjectUri);
|
|
||||||
if( subject == null ) log.error("could not get individual for subject uri "+subjectUri+" in SelectListGenerator.getOptions()");
|
|
||||||
|
|
||||||
ObjectProperty objProp = wDaoFact.getObjectPropertyDao().getObjectPropertyByURI(predicateUri);
|
|
||||||
if( objProp == null )
|
|
||||||
log.error("could not get object property for predicate "+predicateUri+" in SelectListGenerator.getOptions()");
|
|
||||||
|
|
||||||
List <VClass> vclasses = new ArrayList<VClass>();
|
|
||||||
vclasses = wDaoFact.getVClassDao().getVClassesForProperty(subject.getVClassURI(),predicateUri);
|
|
||||||
if( vclasses == null ){
|
|
||||||
log.error("no owl:Class found for predicate " + predicateUri );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if( vclasses.size() == 0 )
|
|
||||||
log.error("no owl:Class found for predicate " + predicateUri );
|
|
||||||
|
|
||||||
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( !uriSet.contains(ind.getURI())) {
|
|
||||||
uriSet.add(ind.getURI());
|
|
||||||
individuals.add(ind);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
List<ObjectPropertyStatement> stmts = subject.getObjectPropertyStatements();
|
|
||||||
if( stmts == null ) log.error("object properties for subject were null in SelectListGenerator.getOptions()");
|
|
||||||
|
|
||||||
individuals = removeIndividualsAlreadyInRange(individuals,stmts,predicateUri,editConfig.getObject());
|
|
||||||
//Collections.sort(individuals,new compareIndividualsByName());
|
|
||||||
|
|
||||||
for( Individual ind : individuals ){
|
|
||||||
String uri = ind.getURI();
|
|
||||||
if( uri != null ){
|
|
||||||
optionsMap.put(uri,ind.getName().trim());
|
|
||||||
++optionsCount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case INDIVIDUALS_VIA_VCLASS: //so we have a vclass URI
|
|
||||||
vclassUri = field.getObjectClassUri();
|
|
||||||
if (vclassUri==null || vclassUri.equals("")){
|
|
||||||
log.error("no vclassUri found for field \""+fieldName+"\" in SelectListGenerator.getOptions() when OptionsType INDIVIDUALS_VIA_VCLASS specified");
|
|
||||||
} else {
|
|
||||||
// first test to see whether there's a default "leave blank" value specified with the literal options
|
|
||||||
String defaultOption=null;
|
|
||||||
if ((defaultOption=getDefaultOption(field))!=null) {
|
|
||||||
optionsMap.put(LEFT_BLANK, defaultOption);
|
|
||||||
}
|
|
||||||
// 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{
|
|
||||||
Map<String, Individual> individualMap = new HashMap<String, Individual>();
|
|
||||||
|
|
||||||
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<Individual> individuals = new ArrayList<Individual>();
|
|
||||||
individuals.addAll(individualMap.values());
|
|
||||||
Collections.sort(individuals);
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
individuals.addAll(individualMap.values());
|
|
||||||
Collections.sort(individuals);
|
|
||||||
|
|
||||||
if (individuals.size()==0){
|
|
||||||
log.debug("No individuals of type "+vclass.getName()+" to add to pick list in SelectListGenerator.getOptions()");
|
|
||||||
optionsMap.put("", "No " + vclass.getName() + " found");
|
|
||||||
}else{
|
|
||||||
for( Individual ind : individuals ) {
|
|
||||||
String uri = ind.getURI();
|
|
||||||
if( uri != null ) {
|
|
||||||
optionsMap.put(uri,ind.getName().trim());
|
|
||||||
++optionsCount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case CHILD_VCLASSES: //so we have a vclass URI
|
|
||||||
vclassUri = field.getObjectClassUri();
|
|
||||||
if (vclassUri==null || vclassUri.equals("")){
|
|
||||||
log.error("no vclassUri found for field \""+fieldName+"\" in SelectListGenerator.getOptions() when OptionsType CHILD_VCLASSES specified");
|
|
||||||
} else {
|
|
||||||
// first test to see whether there's a default "leave blank" value specified with the literal options
|
|
||||||
String defaultOption=null;
|
|
||||||
if ((defaultOption=getDefaultOption(field))!=null) {
|
|
||||||
optionsMap.put(LEFT_BLANK, defaultOption);
|
|
||||||
}
|
|
||||||
// now populate the options
|
|
||||||
if( wDaoFact == null ) log.error("could not get WebappDaoFactory from request in SelectListGenerator.getOptions().");
|
|
||||||
|
|
||||||
VClassDao vclassDao = wDaoFact.getVClassDao();
|
|
||||||
List<String> subClassList = vclassDao.getAllSubClassURIs(vclassUri);
|
|
||||||
if( subClassList == null || subClassList.size()==0 ) {
|
|
||||||
log.debug("No subclasses of " + vclassUri + " found in the model so only default value from field's literalOptions will be used" );
|
|
||||||
} else {
|
|
||||||
for( String subClassUri : subClassList ) {
|
|
||||||
VClass subClass = vclassDao.getVClassByURI(subClassUri);
|
|
||||||
if( subClass != null && !OWL.Nothing.getURI().equals(subClassUri)) {
|
|
||||||
optionsMap.put(subClassUri,subClass.getName().trim());
|
|
||||||
++optionsCount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CHILD_VCLASSES_WITH_PARENT: //so we have a vclass URI
|
|
||||||
vclassUri = field.getObjectClassUri();
|
|
||||||
if (vclassUri==null || vclassUri.equals("")){
|
|
||||||
log.error("no vclassUri found for field \""+fieldName+"\" in SelectListGenerator.getOptions() when OptionsType CHILD_VCLASSES specified");
|
|
||||||
} else {
|
|
||||||
// first test to see whether there's a default "leave blank" value specified with the literal options
|
|
||||||
String defaultOption=null;
|
|
||||||
if ((defaultOption=getDefaultOption(field))!=null) {
|
|
||||||
optionsMap.put(LEFT_BLANK, defaultOption);
|
|
||||||
}
|
|
||||||
// now populate the options
|
|
||||||
if( wDaoFact == null ) log.error("could not get WebappDaoFactory from request in SelectListGenerator.getOptions().");
|
|
||||||
|
|
||||||
VClassDao vclassDao = wDaoFact.getVClassDao();
|
|
||||||
List<String> subClassList = vclassDao.getAllSubClassURIs(vclassUri);
|
|
||||||
if( subClassList == null || subClassList.size()==0 ) {
|
|
||||||
log.debug("No subclasses of " + vclassUri + " found in the model so only default value from field's literalOptions will be used" );
|
|
||||||
} else {
|
|
||||||
for( String subClassUri : subClassList ) {
|
|
||||||
VClass subClass = vclassDao.getVClassByURI(subClassUri);
|
|
||||||
if( subClass != null && !OWL.Nothing.getURI().equals(subClassUri)) {
|
|
||||||
optionsMap.put(subClassUri,subClass.getName().trim());
|
|
||||||
++optionsCount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
optionsMap.put(vclassUri, "Other");
|
|
||||||
++optionsCount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VCLASSGROUP:
|
|
||||||
|
|
||||||
String classGroupUri = field.getObjectClassUri(); // we're overloading this property to specify the classgroup
|
|
||||||
if (classGroupUri==null || classGroupUri.equals("")){
|
|
||||||
log.error("no classGroupUri found for field \""+fieldName+"\" in SelectListGenerator.getOptions() when OptionsType VCLASSGROUP specified");
|
|
||||||
} else {
|
|
||||||
// first test to see whether there's a default "leave blank" value specified with the literal options
|
|
||||||
String defaultOption=null;
|
|
||||||
if ((defaultOption=getDefaultOption(field))!=null) {
|
|
||||||
optionsMap.put(LEFT_BLANK, defaultOption);
|
|
||||||
}
|
|
||||||
// now populate the options
|
|
||||||
if( wDaoFact == null ) log.error("could not get WebappDaoFactory from request in SelectListGenerator.getOptions().");
|
|
||||||
|
|
||||||
VClassGroupDao vcgd = wDaoFact.getVClassGroupDao();
|
|
||||||
|
|
||||||
// Need to call this method to populate the classgroups - otherwise the classgroup class list is empty
|
|
||||||
List vClassGroups = vcgd.getPublicGroupsWithVClasses();
|
|
||||||
|
|
||||||
if (vClassGroups == null) {
|
|
||||||
log.error("No class groups found, so only default value from field's literalOptions will be used.");
|
|
||||||
} else {
|
|
||||||
VClassGroup vClassGroup = null;
|
|
||||||
for (Object o : vClassGroups) {
|
|
||||||
VClassGroup vcg = (VClassGroup) o;
|
|
||||||
if (vcg.getURI().equals(classGroupUri)) {
|
|
||||||
vClassGroup = vcg;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (vClassGroup == null) {
|
|
||||||
log.error("No class group with uri " + classGroupUri + "found, so only default value from field's literalOptions will be used.");
|
|
||||||
} else {
|
|
||||||
List<VClass> vClassList = vClassGroup.getVitroClassList();
|
|
||||||
|
|
||||||
if( vClassList == null || vClassList.size()==0 ) {
|
|
||||||
log.debug("No classes in class group " + classGroupUri + " found in the model, so only default value from field's literalOptions will be used" );
|
|
||||||
} else {
|
|
||||||
for( VClass vClass : vClassList ) {
|
|
||||||
String vClassUri = vClass.getURI();
|
|
||||||
if( vClass != null && !OWL.Nothing.getURI().equals(vClassUri)) {
|
|
||||||
optionsMap.put(vClassUri,vClass.getName().trim());
|
|
||||||
++optionsCount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case UNDEFINED :
|
|
||||||
log.error("optionsType \"UNDEFINED\" for Field \""+fieldName+"\" in SelectListGenerator.getOptions()");
|
|
||||||
break;
|
|
||||||
default: log.error("unknown optionsType "+optionsType.toString()+" for Field \""+fieldName+"\" in SelectListGenerator.getOptions()");
|
|
||||||
}
|
|
||||||
log.debug("added "+optionsCount+" options for field \""+fieldName+"\" in SelectListGenerator.getOptions()");
|
|
||||||
return optionsMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The default option is used when a option list is being auto
|
|
||||||
* generated from a VClass or an ObjectProperty. If there is an
|
|
||||||
* item in the literals item list then the name of it will be used
|
|
||||||
* as the text to display for an empty string value option.
|
|
||||||
*
|
|
||||||
* Having an option with an empty string for a Field that expects
|
|
||||||
* a URI will cause the form processing to assume that the field
|
|
||||||
* was left blank.
|
|
||||||
*
|
|
||||||
* @param field
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private static String getDefaultOption(FieldVTwo field) {
|
|
||||||
List <List<String>> defaultOptions = (List<List<String>>) field.getLiteralOptions();
|
|
||||||
if (defaultOptions!=null) {
|
|
||||||
for(Object obj: ((Iterable)defaultOptions)) {
|
|
||||||
List<String> pair = (List<String>)obj;
|
|
||||||
String value = pair.get(0);
|
|
||||||
String label = pair.get(1);
|
|
||||||
if( label != null && label.trim().length() > 0){
|
|
||||||
return label; // don't want to return a value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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){
|
|
||||||
log.debug("starting to check for duplicate range individuals in SelectListGenerator.removeIndividualsAlreadyInRange() ...");
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
log.debug("removed "+removeCount+" duplicate range individuals");
|
|
||||||
return individuals;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Methods to sort the options map
|
|
||||||
// from http://forum.java.sun.com/thread.jspa?threadID=639077&messageID=4250708
|
|
||||||
public static Map<String,String> getSortedMap(Map<String,String> hmap){
|
|
||||||
// first make temporary list of String arrays holding both the key and its corresponding value, so that the list can be sorted with a decent comparator
|
|
||||||
List<String[]> objectsToSort = new ArrayList<String[]>(hmap.size());
|
|
||||||
for (String key:hmap.keySet()) {
|
|
||||||
String[] x = new String[2];
|
|
||||||
x[0] = key;
|
|
||||||
x[1] = hmap.get(key);
|
|
||||||
objectsToSort.add(x);
|
|
||||||
}
|
|
||||||
Collections.sort(objectsToSort, new MapPairsComparator());
|
|
||||||
|
|
||||||
HashMap<String,String> map = new LinkedHashMap<String,String>(objectsToSort.size());
|
|
||||||
for (String[] pair:objectsToSort) {
|
|
||||||
map.put(pair[0],pair[1]);
|
|
||||||
}
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class MapPairsComparator implements Comparator<String[]> {
|
|
||||||
public int compare (String[] s1, String[] s2) {
|
|
||||||
Collator collator = Collator.getInstance();
|
|
||||||
if (s2 == null) {
|
|
||||||
return 1;
|
|
||||||
} else if (s1 == null) {
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
if ("".equals(s1[0])) {
|
|
||||||
return -1;
|
|
||||||
} else if ("".equals(s2[0])) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (s2[1]==null) {
|
|
||||||
return 1;
|
|
||||||
} else if (s1[1] == null){
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
return collator.compare(s1[1],s2[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final String LEFT_BLANK = "";
|
|
||||||
}
|
|
|
@ -0,0 +1,83 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.vocabulary.OWL;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||||
|
|
||||||
|
public class ChildVClassesOptions implements FieldOptions {
|
||||||
|
|
||||||
|
private static final String LEFT_BLANK = "";
|
||||||
|
private String vclassUri;
|
||||||
|
|
||||||
|
private String defaultOptionLabel;
|
||||||
|
|
||||||
|
static Log log = LogFactory.getLog(ChildVClassesOptions.class);
|
||||||
|
|
||||||
|
public ChildVClassesOptions(String vclassUri) {
|
||||||
|
super();
|
||||||
|
this.vclassUri = vclassUri;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChildVClassesOptions setDefaultOptionLabel(String label){
|
||||||
|
this.defaultOptionLabel = label;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, String> getOptions(
|
||||||
|
EditConfigurationVTwo editConfig,
|
||||||
|
String fieldName,
|
||||||
|
WebappDaoFactory wDaoFact) throws Exception{
|
||||||
|
// now create an empty HashMap to populate and return
|
||||||
|
HashMap <String,String> optionsMap = new LinkedHashMap<String,String>();
|
||||||
|
|
||||||
|
// for debugging, keep a count of the number of options populated
|
||||||
|
int optionsCount=0;
|
||||||
|
|
||||||
|
|
||||||
|
if (vclassUri==null || vclassUri.equals("")){
|
||||||
|
throw new Exception("no vclassUri found for field \""+fieldName+"\" in SelectListGenerator.getOptions() when OptionsType CHILD_VCLASSES specified");
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// first test to see whether there's a default "leave blank" value specified with the literal options
|
||||||
|
if (defaultOptionLabel!=null) {
|
||||||
|
optionsMap.put(LEFT_BLANK, defaultOptionLabel);
|
||||||
|
}
|
||||||
|
|
||||||
|
// now populate the options
|
||||||
|
VClassDao vclassDao = wDaoFact.getVClassDao();
|
||||||
|
List<String> subClassList = vclassDao.getAllSubClassURIs(vclassUri);
|
||||||
|
|
||||||
|
if( subClassList == null || subClassList.size()==0 ) {
|
||||||
|
log.debug("No subclasses of " + vclassUri + " found in the model so only default value from field's literalOptions will be used" );
|
||||||
|
} else {
|
||||||
|
for( String subClassUri : subClassList ) {
|
||||||
|
VClass subClass = vclassDao.getVClassByURI(subClassUri);
|
||||||
|
if( subClass != null && !OWL.Nothing.getURI().equals(subClassUri)) {
|
||||||
|
optionsMap.put(subClassUri,subClass.getName().trim());
|
||||||
|
++optionsCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.debug("added "+optionsCount+" options for field \""+fieldName+"\"");
|
||||||
|
return optionsMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getClassUri(){
|
||||||
|
return vclassUri;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,64 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.vocabulary.OWL;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||||
|
|
||||||
|
public class ChildVClassesWithParent implements FieldOptions {
|
||||||
|
|
||||||
|
private static final String LEFT_BLANK = "";
|
||||||
|
String fieldName;
|
||||||
|
String classUri;
|
||||||
|
String defaultOptionLabel = null;
|
||||||
|
|
||||||
|
public ChildVClassesWithParent(String classUri) throws Exception {
|
||||||
|
super();
|
||||||
|
|
||||||
|
if (classUri==null || classUri.equals(""))
|
||||||
|
throw new Exception ("vclassUri not set");
|
||||||
|
|
||||||
|
this.classUri = classUri;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChildVClassesWithParent setDefaultOption(String label){
|
||||||
|
this.defaultOptionLabel = label;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, String> getOptions(
|
||||||
|
EditConfigurationVTwo editConfig,
|
||||||
|
String fieldName,
|
||||||
|
WebappDaoFactory wDaoFact) throws Exception {
|
||||||
|
|
||||||
|
HashMap <String,String> optionsMap = new LinkedHashMap<String,String>();
|
||||||
|
// first test to see whether there's a default "leave blank" value specified with the literal options
|
||||||
|
if ( ! StringUtils.isEmpty( defaultOptionLabel ) ){
|
||||||
|
optionsMap.put(LEFT_BLANK, defaultOptionLabel);
|
||||||
|
}
|
||||||
|
|
||||||
|
VClassDao vclassDao = wDaoFact.getVClassDao();
|
||||||
|
List<String> subClassList = vclassDao.getAllSubClassURIs(classUri);
|
||||||
|
if (subClassList != null && subClassList.size() > 0) {
|
||||||
|
for (String subClassUri : subClassList) {
|
||||||
|
VClass subClass = vclassDao.getVClassByURI(subClassUri);
|
||||||
|
if (subClass != null && !OWL.Nothing.getURI().equals(subClassUri)) {
|
||||||
|
optionsMap.put(subClassUri, subClass.getName().trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return optionsMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,76 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||||
|
|
||||||
|
public class ConstantFieldOptions implements FieldOptions {
|
||||||
|
|
||||||
|
List<List<String>> options;
|
||||||
|
|
||||||
|
public ConstantFieldOptions(String ... optionPairs) throws Exception {
|
||||||
|
super();
|
||||||
|
|
||||||
|
if (optionPairs==null)
|
||||||
|
throw new Exception("Must specify option pairs in ConstantFieldOptions constructor");
|
||||||
|
|
||||||
|
if( optionPairs.length % 2 != 0)
|
||||||
|
throw new Exception("options must be in pairs of (value,lable)");
|
||||||
|
|
||||||
|
options = new ArrayList<List<String>>( optionPairs.length / 2 );
|
||||||
|
for(int i=0; i< optionPairs.length ; i=i+2){
|
||||||
|
List<String> pair = new ArrayList<String>(2);
|
||||||
|
pair.add(optionPairs[i]);
|
||||||
|
pair.add(optionPairs[i+1]);
|
||||||
|
options.add( pair );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ConstantFieldOptions(String fieldName2,
|
||||||
|
List<List<String>> optionPairs) throws Exception {
|
||||||
|
|
||||||
|
for(List<String> literalPair: optionPairs ){
|
||||||
|
if( literalPair == null)
|
||||||
|
throw new Exception("no items in optionPairs may be null.");
|
||||||
|
if( literalPair.size() == 0 )
|
||||||
|
throw new Exception("no items in optionPairs may be empty lists.");
|
||||||
|
if( literalPair.size() > 2)
|
||||||
|
throw new Exception("no items in optionPairs may be lists longer than 2 items.");
|
||||||
|
}
|
||||||
|
|
||||||
|
options = optionPairs;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, String> getOptions(
|
||||||
|
EditConfigurationVTwo editConfig,
|
||||||
|
String fieldName,
|
||||||
|
WebappDaoFactory wDaoFact) throws Exception {
|
||||||
|
// originally not auto-sorted but sorted now, and empty values not removed or replaced
|
||||||
|
HashMap <String,String> optionsMap = new LinkedHashMap<String,String>();
|
||||||
|
|
||||||
|
for(Object obj: ((Iterable)options)){
|
||||||
|
List<String> literalPair = (List)obj;
|
||||||
|
String value=(String)literalPair.get(0);
|
||||||
|
if( value != null){ // allow empty string as a value
|
||||||
|
String label=(String)literalPair.get(1);
|
||||||
|
if (label!=null) {
|
||||||
|
optionsMap.put(value,label);
|
||||||
|
} else {
|
||||||
|
optionsMap.put(value, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return optionsMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents an object that can return a list of options
|
||||||
|
* for an HTML select list.
|
||||||
|
*
|
||||||
|
* @author bdc34
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public interface FieldOptions {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Any object that are needed to get the options should
|
||||||
|
* be passed in the constructor of the implementation.
|
||||||
|
*
|
||||||
|
* @return return a map of value->label for the options.
|
||||||
|
* Should never return null.
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public Map<String,String> getOptions(
|
||||||
|
EditConfigurationVTwo editConfig,
|
||||||
|
String fieldName,
|
||||||
|
WebappDaoFactory wDaoFact) throws Exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* lic enum OptionsType {
|
||||||
|
LITERALS,x
|
||||||
|
|
||||||
|
HARDCODED_LITERALS,
|
||||||
|
STRINGS_VIA_DATATYPE_PROPERTY,
|
||||||
|
|
||||||
|
INDIVIDUALS_VIA_OBJECT_PROPERTY, x
|
||||||
|
|
||||||
|
INDIVIDUALS_VIA_VCLASS,
|
||||||
|
|
||||||
|
CHILD_VCLASSES, x
|
||||||
|
|
||||||
|
CHILD_VCLASSES_WITH_PARENT,
|
||||||
|
VCLASSGROUP,
|
||||||
|
FILE,
|
||||||
|
UNDEFINED, x
|
||||||
|
DATETIME,
|
||||||
|
DATE,
|
||||||
|
TIME
|
||||||
|
*/
|
|
@ -0,0 +1,141 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||||
|
import org.apache.commons.lang.builder.ToStringStyle;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.BaseEditElementVTwo;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditElementVTwo;
|
||||||
|
public class FieldVTwo {
|
||||||
|
|
||||||
|
// public enum OptionsType {
|
||||||
|
// LITERALS,
|
||||||
|
// HARDCODED_LITERALS,
|
||||||
|
// STRINGS_VIA_DATATYPE_PROPERTY,
|
||||||
|
// INDIVIDUALS_VIA_OBJECT_PROPERTY,
|
||||||
|
// INDIVIDUALS_VIA_VCLASS,
|
||||||
|
// CHILD_VCLASSES,
|
||||||
|
// CHILD_VCLASSES_WITH_PARENT,
|
||||||
|
// VCLASSGROUP,
|
||||||
|
// FILE,
|
||||||
|
// UNDEFINED,
|
||||||
|
// DATETIME,
|
||||||
|
// DATE,
|
||||||
|
// TIME
|
||||||
|
// };
|
||||||
|
|
||||||
|
public static String RDF_XML_LITERAL_URI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral";
|
||||||
|
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of basic validators. See BaiscValidation.
|
||||||
|
*/
|
||||||
|
private List <String> validators = new ArrayList<String>();
|
||||||
|
|
||||||
|
/** Object to get options from. */
|
||||||
|
private FieldOptions fieldOptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used for holding the expected/required datatype of the predicate when the predicate is a datatype propertyl.
|
||||||
|
* this can be a explicit URI or a qname.
|
||||||
|
* example:
|
||||||
|
* "this is the literal"^^<http://someuri.com/v1.2#type23>
|
||||||
|
* or
|
||||||
|
* "this is the literal"^^someprefix:type23
|
||||||
|
*/
|
||||||
|
private String rangeDatatypeUri;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used for holding the language of the literal when the predicate is a datatype property.
|
||||||
|
* This is the lang of the literal. lang strings must be: [a-z]+(-[a-z0-9]+)*
|
||||||
|
*/
|
||||||
|
private String rangeLang;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property for special edit element.
|
||||||
|
*/
|
||||||
|
private EditElementVTwo editElement=null;;
|
||||||
|
|
||||||
|
/* *********************** Constructors ************************** */
|
||||||
|
|
||||||
|
public FieldVTwo() {}
|
||||||
|
|
||||||
|
//private static String[] parameterNames = {"editElement","newResource","validators","optionsType","predicateUri","objectClassUri","rangeDatatypeUri","rangeLang","literalOptions","assertions"};
|
||||||
|
//static{ Arrays.sort(parameterNames); }
|
||||||
|
|
||||||
|
/* ****************** Getters and Setters ******************************* */
|
||||||
|
|
||||||
|
public FieldVTwo setEditElement(EditElementVTwo editElement){
|
||||||
|
this.editElement = editElement;
|
||||||
|
|
||||||
|
if( editElement instanceof BaseEditElementVTwo)
|
||||||
|
((BaseEditElementVTwo) editElement).setField(this);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getName(){
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List <String> getValidators() {
|
||||||
|
return validators;
|
||||||
|
}
|
||||||
|
public FieldVTwo setValidators(List <String> v) {
|
||||||
|
validators = v;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FieldVTwo setOptions( FieldOptions fopts){
|
||||||
|
this.fieldOptions = fopts;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FieldOptions getFieldOptions(){
|
||||||
|
return this.fieldOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRangeDatatypeUri() {
|
||||||
|
return rangeDatatypeUri;
|
||||||
|
}
|
||||||
|
public FieldVTwo setRangeDatatypeUri(String r) {
|
||||||
|
if( rangeLang != null && rangeLang.trim().length() > 0 )
|
||||||
|
throw new IllegalArgumentException("A Field object may not have both rangeDatatypeUri and rangeLanguage set");
|
||||||
|
|
||||||
|
rangeDatatypeUri = r;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRangeLang() {
|
||||||
|
return rangeLang;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FieldVTwo setRangeLang(String rangeLang) {
|
||||||
|
if( rangeDatatypeUri != null && rangeDatatypeUri.trim().length() > 0)
|
||||||
|
throw new IllegalArgumentException("A Field object may not have both rangeDatatypeUri and rangeLanguage set");
|
||||||
|
|
||||||
|
this.rangeLang = rangeLang;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EditElementVTwo getEditElement(){
|
||||||
|
return editElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FieldVTwo setName(String name){
|
||||||
|
this.name = name;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(){
|
||||||
|
return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||||
|
|
||||||
|
public class IndividualsViaClassGroupOptions implements FieldOptions {
|
||||||
|
|
||||||
|
String classGroupUri;
|
||||||
|
String defualtOptionLabel=null;
|
||||||
|
|
||||||
|
|
||||||
|
public IndividualsViaClassGroupOptions(String classGroupUri) {
|
||||||
|
super();
|
||||||
|
this.classGroupUri = classGroupUri;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IndividualsViaClassGroupOptions setDefaultOptionLabel(String label){
|
||||||
|
defualtOptionLabel = label;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, String> getOptions(
|
||||||
|
EditConfigurationVTwo editConfig,
|
||||||
|
String fieldName,
|
||||||
|
WebappDaoFactory wDaoFact) throws Exception {
|
||||||
|
throw new Error("not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getClassGroupUri(){
|
||||||
|
return classGroupUri;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,125 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ListIterator;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
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.ObjectProperty;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||||
|
|
||||||
|
public class IndividualsViaObjectPropetyOptions implements FieldOptions {
|
||||||
|
private static final String LEFT_BLANK = "";
|
||||||
|
private String subjectUri;
|
||||||
|
private String predicateUri;
|
||||||
|
private String objectUri;
|
||||||
|
|
||||||
|
private String defaultOptionLabel;
|
||||||
|
|
||||||
|
public IndividualsViaObjectPropetyOptions(String subjectUri,
|
||||||
|
String predicateUri, String objectUri) throws Exception {
|
||||||
|
super();
|
||||||
|
|
||||||
|
if (subjectUri == null || subjectUri.equals("")) {
|
||||||
|
throw new Exception("no subjectUri found for field ");
|
||||||
|
}
|
||||||
|
if (predicateUri == null || predicateUri.equals("")) {
|
||||||
|
throw new Exception("no predicateUri found for field ");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.subjectUri = subjectUri;
|
||||||
|
this.predicateUri = predicateUri;
|
||||||
|
this.objectUri = objectUri;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IndividualsViaObjectPropetyOptions setDefaultOptionLabel(String label){
|
||||||
|
this.defaultOptionLabel = label;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, String> getOptions(
|
||||||
|
EditConfigurationVTwo editConfig,
|
||||||
|
String fieldName,
|
||||||
|
WebappDaoFactory wDaoFact) {
|
||||||
|
HashMap<String, String> optionsMap = new LinkedHashMap<String, String>();
|
||||||
|
int optionsCount = 0;
|
||||||
|
|
||||||
|
// first test to see whether there's a default "leave blank"
|
||||||
|
// value specified with the literal options
|
||||||
|
if ((defaultOptionLabel ) != null) {
|
||||||
|
optionsMap.put(LEFT_BLANK, defaultOptionLabel);
|
||||||
|
}
|
||||||
|
|
||||||
|
Individual subject = wDaoFact.getIndividualDao().getIndividualByURI(subjectUri);
|
||||||
|
ObjectProperty objProp = wDaoFact.getObjectPropertyDao().getObjectPropertyByURI(predicateUri);
|
||||||
|
List<VClass> vclasses = wDaoFact.getVClassDao().getVClassesForProperty(subject.getVClassURI(), predicateUri);
|
||||||
|
|
||||||
|
if (vclasses == null || vclasses.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 (Individual ind : inds) {
|
||||||
|
if (!uriSet.contains(ind.getURI())) {
|
||||||
|
uriSet.add(ind.getURI());
|
||||||
|
individuals.add(ind);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<ObjectPropertyStatement> stmts = subject.getObjectPropertyStatements();
|
||||||
|
|
||||||
|
individuals = removeIndividualsAlreadyInRange(
|
||||||
|
individuals, stmts, predicateUri, objectUri);
|
||||||
|
// Collections.sort(individuals,new compareIndividualsByName());
|
||||||
|
|
||||||
|
for (Individual ind : individuals) {
|
||||||
|
String uri = ind.getURI();
|
||||||
|
if (uri != null) {
|
||||||
|
optionsMap.put(uri, ind.getName().trim());
|
||||||
|
++optionsCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return optionsMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,131 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
|
||||||
|
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.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||||
|
|
||||||
|
public class IndividualsViaVClassOptions implements FieldOptions {
|
||||||
|
|
||||||
|
public static final String LEFT_BLANK = "";
|
||||||
|
private List<String> vclassURIs;
|
||||||
|
private String defaultOptionLabel;
|
||||||
|
|
||||||
|
public IndividualsViaVClassOptions(String ... vclassURIs) throws Exception {
|
||||||
|
super();
|
||||||
|
|
||||||
|
if (vclassURIs==null )
|
||||||
|
throw new Exception("vclassURIs must not be null or empty ");
|
||||||
|
|
||||||
|
this.vclassURIs = new ArrayList<String>(vclassURIs.length);
|
||||||
|
for(int i=0;i<vclassURIs.length;i++){
|
||||||
|
if( vclassURIs[i] != null && !vclassURIs[i].trim().isEmpty() )
|
||||||
|
this.vclassURIs.add(vclassURIs[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public FieldOptions setDefaultOptionLabel(String label){
|
||||||
|
this.defaultOptionLabel = label;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, String> getOptions(
|
||||||
|
EditConfigurationVTwo editConfig,
|
||||||
|
String fieldName,
|
||||||
|
WebappDaoFactory wDaoFact) throws Exception {
|
||||||
|
|
||||||
|
Map<String, Individual> individualMap = new HashMap<String, Individual>();
|
||||||
|
|
||||||
|
for( String vclassURI : this.vclassURIs){
|
||||||
|
individualMap.putAll( getIndividualsForClass( vclassURI, wDaoFact) );
|
||||||
|
}
|
||||||
|
|
||||||
|
//sort the individuals
|
||||||
|
List<Individual> individuals = new ArrayList<Individual>();
|
||||||
|
individuals.addAll(individualMap.values());
|
||||||
|
Collections.sort(individuals);
|
||||||
|
|
||||||
|
Map<String, String> optionsMap = new HashMap<String,String>();
|
||||||
|
|
||||||
|
if (defaultOptionLabel != null) {
|
||||||
|
optionsMap.put(LEFT_BLANK, defaultOptionLabel);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (individuals.size() == 0) {
|
||||||
|
optionsMap.putAll( notFoundMsg() );
|
||||||
|
} else {
|
||||||
|
for (Individual ind : individuals) {
|
||||||
|
if (ind.getURI() != null) {
|
||||||
|
optionsMap.put(ind.getURI(), ind.getName().trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return optionsMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Map<? extends String, ? extends String> notFoundMsg() {
|
||||||
|
String msg = "No individuals found for "+ (vclassURIs.size() > 1?"types":"type");
|
||||||
|
for( String uri : vclassURIs ){
|
||||||
|
msg += " " + uri;
|
||||||
|
}
|
||||||
|
return Collections.singletonMap("", msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Map<String,Individual> getIndividualsForClass(String vclassURI, WebappDaoFactory wDaoFact ){
|
||||||
|
Map<String, Individual> individualMap = new HashMap<String, Individual>();
|
||||||
|
IndividualDao indDao = wDaoFact.getIndividualDao();
|
||||||
|
|
||||||
|
List<Individual> indsForClass= indDao.getIndividualsByVClassURI(vclassURI, -1, -1);
|
||||||
|
for (Individual ind : indsForClass) {
|
||||||
|
if (ind.getURI() != null) {
|
||||||
|
individualMap.put(ind.getURI(), ind);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if reasoning isn't available, we will also need to add
|
||||||
|
// individuals asserted in subclasses
|
||||||
|
individualMap.putAll( addWhenMissingInference(vclassURI, wDaoFact));
|
||||||
|
|
||||||
|
return individualMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean isReasoningAvailable( WebappDaoFactory wDaoFact){
|
||||||
|
boolean inferenceAvailable = false;
|
||||||
|
if (wDaoFact instanceof WebappDaoFactoryJena) {
|
||||||
|
PelletListener pl = ((WebappDaoFactoryJena) wDaoFact).getPelletListener();
|
||||||
|
if (pl != null && pl.isConsistent() && !pl.isInErrorState()
|
||||||
|
&& !pl.isReasoning()) {
|
||||||
|
inferenceAvailable = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return inferenceAvailable;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Map<String, Individual> addWhenMissingInference( String classUri , WebappDaoFactory wDaoFact ){
|
||||||
|
boolean inferenceAvailable = isReasoningAvailable(wDaoFact);
|
||||||
|
Map<String,Individual> individualMap = new HashMap<String,Individual>();
|
||||||
|
if ( !inferenceAvailable ) {
|
||||||
|
for (String subclassURI : wDaoFact.getVClassDao().getAllSubClassURIs(classUri)) {
|
||||||
|
for (Individual ind : wDaoFact.getIndividualDao().getIndividualsByVClassURI(subclassURI, -1, -1)) {
|
||||||
|
if (ind.getURI() != null) {
|
||||||
|
individualMap.put(ind.getURI(), ind);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return individualMap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||||
|
|
||||||
|
public class RdfTypeOptions implements FieldOptions {
|
||||||
|
|
||||||
|
String[] typeURIs;
|
||||||
|
|
||||||
|
public RdfTypeOptions(String ... superClassURIs)
|
||||||
|
throws Exception {
|
||||||
|
super();
|
||||||
|
if( superClassURIs == null )
|
||||||
|
throw new Exception("superClassURIs must be supplied "+
|
||||||
|
"to constructor.");
|
||||||
|
|
||||||
|
this.typeURIs = superClassURIs;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, String> getOptions(
|
||||||
|
EditConfigurationVTwo editConfig,
|
||||||
|
String fieldName,
|
||||||
|
WebappDaoFactory wdf) {
|
||||||
|
Map<String,String> uriToLabel = new HashMap<String,String>();
|
||||||
|
|
||||||
|
for(int i=0;i<typeURIs.length; i++){
|
||||||
|
String uri = typeURIs[i];
|
||||||
|
VClass vc = wdf.getVClassDao().getVClassByURI( uri );
|
||||||
|
if( vc == null ){
|
||||||
|
uriToLabel.put(uri,uri);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
uriToLabel.put(uri,vc.getPickListName());
|
||||||
|
List<String> subclassUris = wdf.getVClassDao().getAllSubClassURIs( uri );
|
||||||
|
if( subclassUris == null )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for( String subUri : subclassUris ){
|
||||||
|
VClass subVc = wdf.getVClassDao().getVClassByURI( subUri );
|
||||||
|
if( vc != null ){
|
||||||
|
uriToLabel.put(subUri,subVc.getPickListName());
|
||||||
|
}else{
|
||||||
|
uriToLabel.put(subUri,subUri);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return uriToLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,542 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields;
|
||||||
|
|
||||||
|
import java.text.Collator;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ListIterator;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.vocabulary.OWL;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
|
||||||
|
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.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||||
|
|
||||||
|
public class SelectListGeneratorVTwo {
|
||||||
|
|
||||||
|
static Log log = LogFactory.getLog(SelectListGeneratorVTwo.class);
|
||||||
|
|
||||||
|
public static Map<String,String> getOptions(
|
||||||
|
EditConfigurationVTwo editConfig,
|
||||||
|
String fieldName,
|
||||||
|
WebappDaoFactory wDaoFact){
|
||||||
|
|
||||||
|
|
||||||
|
if( editConfig == null ){
|
||||||
|
log.error( "fieldToSelectItemList() must be called with a non-null EditConfigurationVTwo ");
|
||||||
|
return Collections.EMPTY_MAP;
|
||||||
|
}
|
||||||
|
if( fieldName == null ){
|
||||||
|
log.error( "fieldToSelectItemList() must be called with a non-null fieldName");
|
||||||
|
return Collections.EMPTY_MAP;
|
||||||
|
}
|
||||||
|
|
||||||
|
FieldVTwo field = editConfig.getField(fieldName);
|
||||||
|
if (field==null) {
|
||||||
|
log.error("no field \""+fieldName+"\" found from editConfig.");
|
||||||
|
return Collections.EMPTY_MAP;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( field.getFieldOptions() == null ){
|
||||||
|
log.error("cannot get options for a field if it has no FieldOption set.");
|
||||||
|
return Collections.EMPTY_MAP;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return field.getFieldOptions().getOptions(editConfig,fieldName,wDaoFact);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error runing getFieldOptionis()",e);
|
||||||
|
return Collections.EMPTY_MAP;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// public static Map<String,String> getOptionsOldVersion(
|
||||||
|
// EditConfigurationVTwo editConfig,
|
||||||
|
// String fieldName,
|
||||||
|
// WebappDaoFactory wDaoFact){
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// if( editConfig == null ){
|
||||||
|
// log.error( "fieldToSelectItemList() must be called with a non-null EditConfigurationVTwo ");
|
||||||
|
// return Collections.EMPTY_MAP;
|
||||||
|
// }
|
||||||
|
// if( fieldName == null ){
|
||||||
|
// log.error( "fieldToSelectItemList() must be called with a non-null fieldName");
|
||||||
|
// return Collections.EMPTY_MAP;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// FieldVTwo field = editConfig.getField(fieldName);
|
||||||
|
// if (field==null) {
|
||||||
|
// log.error("no field \""+fieldName+"\" found from editConfig in SelectListGenerator.getOptions()");
|
||||||
|
// return Collections.EMPTY_MAP;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // now create an empty HashMap to populate and return
|
||||||
|
// HashMap <String,String> optionsMap = new LinkedHashMap<String,String>();
|
||||||
|
// // for debugging, keep a count of the number of options populated
|
||||||
|
// int optionsCount=0;
|
||||||
|
//
|
||||||
|
// FieldVTwo.OptionsType optionsType = field.getOptionsType();
|
||||||
|
// String vclassUri = null;
|
||||||
|
// switch (optionsType){
|
||||||
|
// case HARDCODED_LITERALS: // originally not auto-sorted but sorted now, and empty values not removed or replaced
|
||||||
|
// List<List<String>> hardcodedLiteralOptions = field.getLiteralOptions();
|
||||||
|
// if (hardcodedLiteralOptions==null) {
|
||||||
|
// log.error("no literalOptions List found for field \""+fieldName+"\" in SelectListGenerator.getOptions() when OptionsType HARDCODED_LITERALS specified");
|
||||||
|
// return new HashMap <String,String>();
|
||||||
|
// }
|
||||||
|
// for(Object obj: ((Iterable)hardcodedLiteralOptions)){
|
||||||
|
// List<String> literalPair = (List)obj;
|
||||||
|
// String value=(String)literalPair.get(0);
|
||||||
|
// if( value != null){ // allow empty string as a value
|
||||||
|
// String label=(String)literalPair.get(1);
|
||||||
|
// if (label!=null) {
|
||||||
|
// optionsMap.put(value,label);
|
||||||
|
// } else {
|
||||||
|
// optionsMap.put(value, value);
|
||||||
|
// }
|
||||||
|
// ++optionsCount;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// break;
|
||||||
|
// case LITERALS:
|
||||||
|
// List<List<String>> literalOptions = field.getLiteralOptions();
|
||||||
|
// if (literalOptions==null) {
|
||||||
|
// log.error("no literalOptions List found for field \""+fieldName+"\" in SelectListGenerator.getOptions() when OptionsType LITERALS specified");
|
||||||
|
// return new HashMap <String,String>();
|
||||||
|
// }
|
||||||
|
// for(Object obj: ((Iterable)literalOptions)){
|
||||||
|
// List<String> literalPair = (List)obj;
|
||||||
|
// String value=(String)literalPair.get(0);
|
||||||
|
// if( value != null && value.trim().length() > 0){
|
||||||
|
// String label=(String)literalPair.get(1);
|
||||||
|
// if (label!=null && label.trim().length() > 0) {
|
||||||
|
// optionsMap.put(value,label);
|
||||||
|
// } else {
|
||||||
|
// optionsMap.put(value, value);
|
||||||
|
// }
|
||||||
|
// ++optionsCount;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// break;
|
||||||
|
// case STRINGS_VIA_DATATYPE_PROPERTY:
|
||||||
|
// log.debug("processing Field \""+fieldName+"\" optionType as a datatype property predicateUri in SelectListGenerator.getOptions()");
|
||||||
|
// String dataPropUri = field.getPredicateUri();
|
||||||
|
// if (dataPropUri==null || dataPropUri.equals("")){
|
||||||
|
// log.error("no predicate dataPropUri found for field \""+fieldName+"\" in SelectListGenerator.getOptions() when OptionsType STRINGS_VIA_DATATYPE_PROPERTY specified");
|
||||||
|
// } else {
|
||||||
|
// /* first test to see whether there's a default "leave blank" value specified with the literal options
|
||||||
|
// String defaultOption=null;
|
||||||
|
// if ((defaultOption=getDefaultOption(field))!=null) {
|
||||||
|
// optionsMap.put(LEFT_BLANK, defaultOption);
|
||||||
|
// } */
|
||||||
|
// // now populate the options
|
||||||
|
// log.debug("finding all choices for data property \""+dataPropUri+"\" in SelectListGenerator.getOptions()");
|
||||||
|
//
|
||||||
|
// if( wDaoFact == null ) log.error("incoming WebappDaoFactory from request is null in SelectListGenerator.getOptions().");
|
||||||
|
//
|
||||||
|
// DataPropertyStatementDao dpsDao = wDaoFact.getDataPropertyStatementDao();
|
||||||
|
// DataPropertyDao dpDao = wDaoFact.getDataPropertyDao();
|
||||||
|
// DataProperty dp = dpDao.getDataPropertyByURI(dataPropUri);
|
||||||
|
// for (Iterator<DataPropertyStatement> i = dpsDao.getDataPropertyStatements(dp).iterator(); i.hasNext();) {
|
||||||
|
// DataPropertyStatement dps = i.next();
|
||||||
|
// if( dps != null ){
|
||||||
|
// optionsMap.put(dps.getData().trim(),dps.getData().trim());
|
||||||
|
// ++optionsCount;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// break;
|
||||||
|
// case INDIVIDUALS_VIA_OBJECT_PROPERTY:
|
||||||
|
// log.debug("processing Field \""+fieldName+"\" optionType as an object property predicateUri in SelectListGenerator.getOptions()");
|
||||||
|
// String subjectUri = editConfig.getSubjectUri();
|
||||||
|
// if (subjectUri==null || subjectUri.equals("")){
|
||||||
|
// log.error("no subjectUri found for field \""+fieldName+"\" in SelectListGenerator.getOptions() when OptionsType INDIVIDUALS_VIA_OBJECTPROPERTY specified");
|
||||||
|
// } else {
|
||||||
|
// String predicateUri = field.getPredicateUri();
|
||||||
|
// if (predicateUri==null || predicateUri.equals("")){
|
||||||
|
// log.error("no predicateUri found for field \""+fieldName+"\" in SelectListGenerator.getOptions() when OptionsType INDIVIDUALS_VIA_OBJECTPROPERTY specified");
|
||||||
|
// } else {
|
||||||
|
// // first test to see whether there's a default "leave blank" value specified with the literal options
|
||||||
|
// String defaultOption=null;
|
||||||
|
// if ((defaultOption=getDefaultOption(field))!=null) {
|
||||||
|
// optionsMap.put(LEFT_BLANK, defaultOption);
|
||||||
|
// }
|
||||||
|
// // now populate the options
|
||||||
|
// log.debug("finding range individuals for subject \""+subjectUri+"\" and object property \""+predicateUri+"\" in SelectListGenerator.getOptions()");
|
||||||
|
//
|
||||||
|
// if( wDaoFact == null ) log.error("could not get WebappDaoFactory from request in SelectListGenerator.getOptions().");
|
||||||
|
//
|
||||||
|
// Individual subject = wDaoFact.getIndividualDao().getIndividualByURI(subjectUri);
|
||||||
|
// if( subject == null ) log.error("could not get individual for subject uri "+subjectUri+" in SelectListGenerator.getOptions()");
|
||||||
|
//
|
||||||
|
// ObjectProperty objProp = wDaoFact.getObjectPropertyDao().getObjectPropertyByURI(predicateUri);
|
||||||
|
// if( objProp == null )
|
||||||
|
// log.error("could not get object property for predicate "+predicateUri+" in SelectListGenerator.getOptions()");
|
||||||
|
//
|
||||||
|
// List <VClass> vclasses = new ArrayList<VClass>();
|
||||||
|
// vclasses = wDaoFact.getVClassDao().getVClassesForProperty(subject.getVClassURI(),predicateUri);
|
||||||
|
// if( vclasses == null ){
|
||||||
|
// log.error("no owl:Class found for predicate " + predicateUri );
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// if( vclasses.size() == 0 )
|
||||||
|
// log.error("no owl:Class found for predicate " + predicateUri );
|
||||||
|
//
|
||||||
|
// 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( !uriSet.contains(ind.getURI())) {
|
||||||
|
// uriSet.add(ind.getURI());
|
||||||
|
// individuals.add(ind);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// List<ObjectPropertyStatement> stmts = subject.getObjectPropertyStatements();
|
||||||
|
// if( stmts == null ) log.error("object properties for subject were null in SelectListGenerator.getOptions()");
|
||||||
|
//
|
||||||
|
// individuals = removeIndividualsAlreadyInRange(individuals,stmts,predicateUri,editConfig.getObject());
|
||||||
|
// //Collections.sort(individuals,new compareIndividualsByName());
|
||||||
|
//
|
||||||
|
// for( Individual ind : individuals ){
|
||||||
|
// String uri = ind.getURI();
|
||||||
|
// if( uri != null ){
|
||||||
|
// optionsMap.put(uri,ind.getName().trim());
|
||||||
|
// ++optionsCount;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// break;
|
||||||
|
// case INDIVIDUALS_VIA_VCLASS: //so we have a vclass URI
|
||||||
|
// vclassUri = field.getObjectClassUri();
|
||||||
|
// if (vclassUri==null || vclassUri.equals("")){
|
||||||
|
// log.error("no vclassUri found for field \""+fieldName+"\" in SelectListGenerator.getOptions() when OptionsType INDIVIDUALS_VIA_VCLASS specified");
|
||||||
|
// } else {
|
||||||
|
// // first test to see whether there's a default "leave blank" value specified with the literal options
|
||||||
|
// String defaultOption=null;
|
||||||
|
// if ((defaultOption=getDefaultOption(field))!=null) {
|
||||||
|
// optionsMap.put(LEFT_BLANK, defaultOption);
|
||||||
|
// }
|
||||||
|
// // 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{
|
||||||
|
// Map<String, Individual> individualMap = new HashMap<String, Individual>();
|
||||||
|
//
|
||||||
|
// 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<Individual> individuals = new ArrayList<Individual>();
|
||||||
|
// individuals.addAll(individualMap.values());
|
||||||
|
// Collections.sort(individuals);
|
||||||
|
//
|
||||||
|
// 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);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// individuals.addAll(individualMap.values());
|
||||||
|
// Collections.sort(individuals);
|
||||||
|
//
|
||||||
|
// if (individuals.size()==0){
|
||||||
|
// log.debug("No individuals of type "+vclass.getName()+" to add to pick list in SelectListGenerator.getOptions()");
|
||||||
|
// optionsMap.put("", "No " + vclass.getName() + " found");
|
||||||
|
// }else{
|
||||||
|
// for( Individual ind : individuals ) {
|
||||||
|
// String uri = ind.getURI();
|
||||||
|
// if( uri != null ) {
|
||||||
|
// optionsMap.put(uri,ind.getName().trim());
|
||||||
|
// ++optionsCount;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// break;
|
||||||
|
// case CHILD_VCLASSES: //so we have a vclass URI
|
||||||
|
// vclassUri = field.getObjectClassUri();
|
||||||
|
// if (vclassUri==null || vclassUri.equals("")){
|
||||||
|
// log.error("no vclassUri found for field \""+fieldName+"\" in SelectListGenerator.getOptions() when OptionsType CHILD_VCLASSES specified");
|
||||||
|
// } else {
|
||||||
|
// // first test to see whether there's a default "leave blank" value specified with the literal options
|
||||||
|
// String defaultOption=null;
|
||||||
|
// if ((defaultOption=getDefaultOption(field))!=null) {
|
||||||
|
// optionsMap.put(LEFT_BLANK, defaultOption);
|
||||||
|
// }
|
||||||
|
// // now populate the options
|
||||||
|
// if( wDaoFact == null ) log.error("could not get WebappDaoFactory from request in SelectListGenerator.getOptions().");
|
||||||
|
//
|
||||||
|
// VClassDao vclassDao = wDaoFact.getVClassDao();
|
||||||
|
// List<String> subClassList = vclassDao.getAllSubClassURIs(vclassUri);
|
||||||
|
// if( subClassList == null || subClassList.size()==0 ) {
|
||||||
|
// log.debug("No subclasses of " + vclassUri + " found in the model so only default value from field's literalOptions will be used" );
|
||||||
|
// } else {
|
||||||
|
// for( String subClassUri : subClassList ) {
|
||||||
|
// VClass subClass = vclassDao.getVClassByURI(subClassUri);
|
||||||
|
// if( subClass != null && !OWL.Nothing.getURI().equals(subClassUri)) {
|
||||||
|
// optionsMap.put(subClassUri,subClass.getName().trim());
|
||||||
|
// ++optionsCount;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// break;
|
||||||
|
//
|
||||||
|
// case CHILD_VCLASSES_WITH_PARENT: //so we have a vclass URI
|
||||||
|
// vclassUri = field.getObjectClassUri();
|
||||||
|
// if (vclassUri==null || vclassUri.equals("")){
|
||||||
|
// log.error("no vclassUri found for field \""+fieldName+"\" in SelectListGenerator.getOptions() when OptionsType CHILD_VCLASSES specified");
|
||||||
|
// } else {
|
||||||
|
// // first test to see whether there's a default "leave blank" value specified with the literal options
|
||||||
|
// String defaultOption=null;
|
||||||
|
// if ((defaultOption=getDefaultOption(field))!=null) {
|
||||||
|
// optionsMap.put(LEFT_BLANK, defaultOption);
|
||||||
|
// }
|
||||||
|
// // now populate the options
|
||||||
|
// if( wDaoFact == null ) log.error("could not get WebappDaoFactory from request in SelectListGenerator.getOptions().");
|
||||||
|
//
|
||||||
|
// VClassDao vclassDao = wDaoFact.getVClassDao();
|
||||||
|
// List<String> subClassList = vclassDao.getAllSubClassURIs(vclassUri);
|
||||||
|
// if( subClassList == null || subClassList.size()==0 ) {
|
||||||
|
// log.debug("No subclasses of " + vclassUri + " found in the model so only default value from field's literalOptions will be used" );
|
||||||
|
// } else {
|
||||||
|
// for( String subClassUri : subClassList ) {
|
||||||
|
// VClass subClass = vclassDao.getVClassByURI(subClassUri);
|
||||||
|
// if( subClass != null && !OWL.Nothing.getURI().equals(subClassUri)) {
|
||||||
|
// optionsMap.put(subClassUri,subClass.getName().trim());
|
||||||
|
// ++optionsCount;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// optionsMap.put(vclassUri, "Other");
|
||||||
|
// ++optionsCount;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// break;
|
||||||
|
//
|
||||||
|
// case VCLASSGROUP:
|
||||||
|
//
|
||||||
|
// String classGroupUri = field.getObjectClassUri(); // we're overloading this property to specify the classgroup
|
||||||
|
// if (classGroupUri==null || classGroupUri.equals("")){
|
||||||
|
// log.error("no classGroupUri found for field \""+fieldName+"\" in SelectListGenerator.getOptions() when OptionsType VCLASSGROUP specified");
|
||||||
|
// } else {
|
||||||
|
// // first test to see whether there's a default "leave blank" value specified with the literal options
|
||||||
|
// String defaultOption=null;
|
||||||
|
// if ((defaultOption=getDefaultOption(field))!=null) {
|
||||||
|
// optionsMap.put(LEFT_BLANK, defaultOption);
|
||||||
|
// }
|
||||||
|
// // now populate the options
|
||||||
|
// if( wDaoFact == null ) log.error("could not get WebappDaoFactory from request in SelectListGenerator.getOptions().");
|
||||||
|
//
|
||||||
|
// VClassGroupDao vcgd = wDaoFact.getVClassGroupDao();
|
||||||
|
//
|
||||||
|
// // Need to call this method to populate the classgroups - otherwise the classgroup class list is empty
|
||||||
|
// List vClassGroups = vcgd.getPublicGroupsWithVClasses();
|
||||||
|
//
|
||||||
|
// if (vClassGroups == null) {
|
||||||
|
// log.error("No class groups found, so only default value from field's literalOptions will be used.");
|
||||||
|
// } else {
|
||||||
|
// VClassGroup vClassGroup = null;
|
||||||
|
// for (Object o : vClassGroups) {
|
||||||
|
// VClassGroup vcg = (VClassGroup) o;
|
||||||
|
// if (vcg.getURI().equals(classGroupUri)) {
|
||||||
|
// vClassGroup = vcg;
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if (vClassGroup == null) {
|
||||||
|
// log.error("No class group with uri " + classGroupUri + "found, so only default value from field's literalOptions will be used.");
|
||||||
|
// } else {
|
||||||
|
// List<VClass> vClassList = vClassGroup.getVitroClassList();
|
||||||
|
//
|
||||||
|
// if( vClassList == null || vClassList.size()==0 ) {
|
||||||
|
// log.debug("No classes in class group " + classGroupUri + " found in the model, so only default value from field's literalOptions will be used" );
|
||||||
|
// } else {
|
||||||
|
// for( VClass vClass : vClassList ) {
|
||||||
|
// String vClassUri = vClass.getURI();
|
||||||
|
// if( vClass != null && !OWL.Nothing.getURI().equals(vClassUri)) {
|
||||||
|
// optionsMap.put(vClassUri,vClass.getName().trim());
|
||||||
|
// ++optionsCount;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// break;
|
||||||
|
//
|
||||||
|
// case UNDEFINED :
|
||||||
|
// log.error("optionsType \"UNDEFINED\" for Field \""+fieldName+"\" in SelectListGenerator.getOptions()");
|
||||||
|
// break;
|
||||||
|
// default: log.error("unknown optionsType "+optionsType.toString()+" for Field \""+fieldName+"\" in SelectListGenerator.getOptions()");
|
||||||
|
// }
|
||||||
|
// log.debug("added "+optionsCount+" options for field \""+fieldName+"\" in SelectListGenerator.getOptions()");
|
||||||
|
// return optionsMap;
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The default option is used when a option list is being auto
|
||||||
|
* generated from a VClass or an ObjectProperty. If there is an
|
||||||
|
* item in the literals item list then the name of it will be used
|
||||||
|
* as the text to display for an empty string value option.
|
||||||
|
*
|
||||||
|
* Having an option with an empty string for a Field that expects
|
||||||
|
* a URI will cause the form processing to assume that the field
|
||||||
|
* was left blank.
|
||||||
|
*
|
||||||
|
* @param field
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
// private static String getDefaultOption(FieldVTwo field) {
|
||||||
|
// List <List<String>> defaultOptions = (List<List<String>>) field.getLiteralOptions();
|
||||||
|
// if (defaultOptions!=null) {
|
||||||
|
// for(Object obj: ((Iterable)defaultOptions)) {
|
||||||
|
// List<String> pair = (List<String>)obj;
|
||||||
|
// String value = pair.get(0);
|
||||||
|
// String label = pair.get(1);
|
||||||
|
// if( label != null && label.trim().length() > 0){
|
||||||
|
// return label; // don't want to return a value
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// 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){
|
||||||
|
log.debug("starting to check for duplicate range individuals in SelectListGenerator.removeIndividualsAlreadyInRange() ...");
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.debug("removed "+removeCount+" duplicate range individuals");
|
||||||
|
return individuals;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Methods to sort the options map
|
||||||
|
// from http://forum.java.sun.com/thread.jspa?threadID=639077&messageID=4250708
|
||||||
|
public static Map<String,String> getSortedMap(Map<String,String> hmap){
|
||||||
|
// first make temporary list of String arrays holding both the key and its corresponding value, so that the list can be sorted with a decent comparator
|
||||||
|
List<String[]> objectsToSort = new ArrayList<String[]>(hmap.size());
|
||||||
|
for (String key:hmap.keySet()) {
|
||||||
|
String[] x = new String[2];
|
||||||
|
x[0] = key;
|
||||||
|
x[1] = hmap.get(key);
|
||||||
|
objectsToSort.add(x);
|
||||||
|
}
|
||||||
|
Collections.sort(objectsToSort, new MapPairsComparator());
|
||||||
|
|
||||||
|
HashMap<String,String> map = new LinkedHashMap<String,String>(objectsToSort.size());
|
||||||
|
for (String[] pair:objectsToSort) {
|
||||||
|
map.put(pair[0],pair[1]);
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class MapPairsComparator implements Comparator<String[]> {
|
||||||
|
public int compare (String[] s1, String[] s2) {
|
||||||
|
Collator collator = Collator.getInstance();
|
||||||
|
if (s2 == null) {
|
||||||
|
return 1;
|
||||||
|
} else if (s1 == null) {
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
if ("".equals(s1[0])) {
|
||||||
|
return -1;
|
||||||
|
} else if ("".equals(s2[0])) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (s2[1]==null) {
|
||||||
|
return 1;
|
||||||
|
} else if (s1[1] == null){
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
return collator.compare(s1[1],s2[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final String LEFT_BLANK = "";
|
||||||
|
}
|
|
@ -18,7 +18,7 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.DateTimeIntervalVali
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.DateTimeWithPrecisionVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.DateTimeWithPrecisionVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.FieldVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils;
|
import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils.EditMode;
|
import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils.EditMode;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.generators.EditModeUtils;
|
import edu.cornell.mannlib.vitro.webapp.utils.generators.EditModeUtils;
|
||||||
|
|
|
@ -17,7 +17,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.DateTimeWithPrecisionVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.DateTimeWithPrecisionVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.FieldVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils;
|
import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils.EditMode;
|
import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils.EditMode;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.generators.EditModeUtils;
|
import edu.cornell.mannlib.vitro.webapp.utils.generators.EditModeUtils;
|
||||||
|
|
|
@ -34,8 +34,8 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTw
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditN3GeneratorVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditN3GeneratorVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.SelectListGeneratorVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.FieldVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.SelectListGeneratorVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils;
|
import edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.DefaultAddMissingIndividualFormModelPreprocessor;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.DefaultAddMissingIndividualFormModelPreprocessor;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.AntiXssValidation;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.AntiXssValidation;
|
||||||
|
@ -319,18 +319,23 @@ public class DefaultAddMissingIndividualFormGenerator implements EditConfigurati
|
||||||
private void setFields(EditConfigurationVTwo editConfiguration, VitroRequest vreq, String predicateUri) {
|
private void setFields(EditConfigurationVTwo editConfiguration, VitroRequest vreq, String predicateUri) {
|
||||||
Map<String, FieldVTwo> fields = new HashMap<String, FieldVTwo>();
|
Map<String, FieldVTwo> fields = new HashMap<String, FieldVTwo>();
|
||||||
if(EditConfigurationUtils.isObjectProperty(EditConfigurationUtils.getPredicateUri(vreq), vreq)) {
|
if(EditConfigurationUtils.isObjectProperty(EditConfigurationUtils.getPredicateUri(vreq), vreq)) {
|
||||||
fields = getObjectPropertyField(editConfiguration, vreq);
|
|
||||||
|
//make name field
|
||||||
|
FieldVTwo field = new FieldVTwo();
|
||||||
|
field.setName("name");
|
||||||
|
|
||||||
|
List<String> validators = new ArrayList<String>();
|
||||||
|
validators.add("nonempty");
|
||||||
|
field.setValidators(validators);
|
||||||
|
|
||||||
|
fields.put(field.getName(), field);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
log.error("Is not object property so fields not set");
|
log.error("Is not object property so fields not set");
|
||||||
}
|
}
|
||||||
|
|
||||||
editConfiguration.setFields(fields);
|
editConfiguration.setFields(fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private String getRangeClassUri(VitroRequest vreq) {
|
private String getRangeClassUri(VitroRequest vreq) {
|
||||||
Individual subject = EditConfigurationUtils.getSubjectIndividual(vreq);
|
Individual subject = EditConfigurationUtils.getSubjectIndividual(vreq);
|
||||||
|
@ -355,36 +360,6 @@ public class DefaultAddMissingIndividualFormGenerator implements EditConfigurati
|
||||||
return rangeClass.getURI();
|
return rangeClass.getURI();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, FieldVTwo> getObjectPropertyField(
|
|
||||||
EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
|
|
||||||
Map<String, FieldVTwo> fields = new HashMap<String, FieldVTwo>();
|
|
||||||
FieldVTwo field = new FieldVTwo();
|
|
||||||
field.setName("name");
|
|
||||||
//queryForExisting is not being used anywhere in Field
|
|
||||||
|
|
||||||
List<String> validators = new ArrayList<String>();
|
|
||||||
validators.add("nonempty");
|
|
||||||
field.setValidators(validators);
|
|
||||||
|
|
||||||
//subjectUri and subjectClassUri are not being used in Field
|
|
||||||
|
|
||||||
field.setOptionsType("UNDEFINED");
|
|
||||||
//TODO:check why predicate uri is empty on original jsp
|
|
||||||
field.setPredicateUri("");
|
|
||||||
|
|
||||||
field.setObjectClassUri("");
|
|
||||||
field.setRangeDatatypeUri(null);
|
|
||||||
|
|
||||||
field.setRangeLang(null);
|
|
||||||
field.setLiteralOptions(new ArrayList<List<String>>());
|
|
||||||
|
|
||||||
fields.put(field.getName(), field);
|
|
||||||
|
|
||||||
return fields;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void prepareForUpdate(VitroRequest vreq, HttpSession session, EditConfigurationVTwo editConfiguration) {
|
private void prepareForUpdate(VitroRequest vreq, HttpSession session, EditConfigurationVTwo editConfiguration) {
|
||||||
//Here, retrieve model from
|
//Here, retrieve model from
|
||||||
Model model = (Model) session.getServletContext().getAttribute("jenaOntModel");
|
Model model = (Model) session.getServletContext().getAttribute("jenaOntModel");
|
||||||
|
|
|
@ -21,7 +21,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral;
|
import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.FieldVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.DefaultDataPropEmptyField;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.DefaultDataPropEmptyField;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.AntiXssValidation;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.AntiXssValidation;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash;
|
||||||
|
@ -80,7 +80,6 @@ public class DefaultDataPropertyFormGenerator extends BaseEditConfigurationGener
|
||||||
|
|
||||||
FieldVTwo literalField = new FieldVTwo()
|
FieldVTwo literalField = new FieldVTwo()
|
||||||
.setName( literalVar )
|
.setName( literalVar )
|
||||||
.setPredicateUri(predicateUri)
|
|
||||||
.setRangeDatatypeUri(rangeDatatypeUri);
|
.setRangeDatatypeUri(rangeDatatypeUri);
|
||||||
|
|
||||||
editConfiguration.addField( literalField );
|
editConfiguration.addField( literalField );
|
||||||
|
|
|
@ -33,8 +33,8 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTw
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditN3GeneratorVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditN3GeneratorVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.SelectListGeneratorVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.FieldVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.SelectListGeneratorVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils;
|
import edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
||||||
|
|
||||||
|
|
|
@ -20,14 +20,15 @@ import com.hp.hpl.jena.rdf.model.Literal;
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
|
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.FieldVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldOptions;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.IndividualsViaObjectPropetyOptions;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.AntiXssValidation;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.AntiXssValidation;
|
||||||
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
||||||
|
|
||||||
|
@ -57,19 +58,23 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq,
|
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq,
|
||||||
HttpSession session) {
|
HttpSession session) throws Exception {
|
||||||
|
|
||||||
//Check if create new and return specific edit configuration from that generator.
|
//Check if create new and return specific edit configuration from that generator.
|
||||||
if(DefaultAddMissingIndividualFormGenerator.isCreateNewIndividual(vreq, session)) {
|
if(DefaultAddMissingIndividualFormGenerator.isCreateNewIndividual(vreq, session)) {
|
||||||
DefaultAddMissingIndividualFormGenerator generator = new DefaultAddMissingIndividualFormGenerator();
|
DefaultAddMissingIndividualFormGenerator generator = new DefaultAddMissingIndividualFormGenerator();
|
||||||
return generator.getEditConfiguration(vreq, session);
|
return generator.getEditConfiguration(vreq, session);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Add a generator for delete: based on command being delete - propDelete.jsp
|
//TODO: Add a generator for delete: based on command being delete - propDelete.jsp
|
||||||
//Generate a edit conf for the default object property form and return it.
|
//Generate a edit configuration for the default object property form and return it.
|
||||||
|
//if(DefaultDeleteGenerator.isDelete( vreq,session)){
|
||||||
|
// return (new DefaultDeleteGenerator()).getEditConfiguration(vreq,session);
|
||||||
|
|
||||||
return getDefaultObjectEditConfiguration(vreq, session);
|
return getDefaultObjectEditConfiguration(vreq, session);
|
||||||
}
|
}
|
||||||
|
|
||||||
private EditConfigurationVTwo getDefaultObjectEditConfiguration(VitroRequest vreq, HttpSession session) {
|
private EditConfigurationVTwo getDefaultObjectEditConfiguration(VitroRequest vreq, HttpSession session) throws Exception {
|
||||||
EditConfigurationVTwo editConfiguration = new EditConfigurationVTwo();
|
EditConfigurationVTwo editConfiguration = new EditConfigurationVTwo();
|
||||||
|
|
||||||
//process subject, predicate, object parameters
|
//process subject, predicate, object parameters
|
||||||
|
@ -295,112 +300,19 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void setFields(EditConfigurationVTwo editConfiguration, VitroRequest vreq, String predicateUri) {
|
private void setFields(EditConfigurationVTwo editConfiguration, VitroRequest vreq, String predicateUri) throws Exception {
|
||||||
Map<String, FieldVTwo> fields = new HashMap<String, FieldVTwo>();
|
Map<String, FieldVTwo> fields = new HashMap<String, FieldVTwo>();
|
||||||
if(EditConfigurationUtils.isObjectProperty(EditConfigurationUtils.getPredicateUri(vreq), vreq)) {
|
if(EditConfigurationUtils.isObjectProperty(EditConfigurationUtils.getPredicateUri(vreq), vreq)) {
|
||||||
fields = getObjectPropertyField(editConfiguration, vreq);
|
fields = getObjectPropertyField(editConfiguration, vreq);
|
||||||
} else {
|
} else {
|
||||||
fields = getDataPropertyField(editConfiguration, vreq);
|
throw new Exception("DefaultObjectPropertyFormGenerator does not handle data properties.");
|
||||||
}
|
}
|
||||||
|
|
||||||
editConfiguration.setFields(fields);
|
editConfiguration.setFields(fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, FieldVTwo> getDataPropertyField(
|
|
||||||
EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
|
|
||||||
Map<String, FieldVTwo> fields = new HashMap<String, FieldVTwo>();
|
|
||||||
FieldVTwo field = new FieldVTwo();
|
|
||||||
field.setName(dataLiteral);
|
|
||||||
//queryForExisting is not being used anywhere in Field
|
|
||||||
String rangeDatatypeUri = getRangeDatatypeUri(editConfiguration, vreq);
|
|
||||||
String rangeLang = getRangeLang(editConfiguration, vreq);
|
|
||||||
|
|
||||||
List<String> validators = new ArrayList<String>();
|
|
||||||
validators.add("datatype:" + rangeDatatypeUri);
|
|
||||||
field.setValidators(validators);
|
|
||||||
|
|
||||||
//subjectUri and subjectClassUri are not being used in Field
|
|
||||||
|
|
||||||
field.setOptionsType("LITERALS");
|
|
||||||
//why isn't predicate uri set for data properties?
|
|
||||||
field.setPredicateUri(null);
|
|
||||||
field.setObjectClassUri(null);
|
|
||||||
field.setRangeDatatypeUri(rangeDatatypeUri);
|
|
||||||
//have either range datatype uri or range lang
|
|
||||||
if(rangeDatatypeUri == null) {
|
|
||||||
field.setRangeLang(rangeLang);
|
|
||||||
}
|
|
||||||
field.setLiteralOptions(getLiteralOptions(editConfiguration, vreq));
|
|
||||||
|
|
||||||
fields.put(field.getName(), field);
|
|
||||||
return fields;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<List<String>> getLiteralOptions(
|
|
||||||
EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
|
|
||||||
DataPropertyStatement dps =EditConfigurationUtils.getDataPropertyStatement(vreq, vreq.getSession(), dataHash, predicateUri);
|
|
||||||
List<List<String>> literalOptions = new ArrayList<List<String>>();
|
|
||||||
if(dps == null) {
|
|
||||||
log.debug("No incoming dataproperty statement attribute for property ; adding a new statement");
|
|
||||||
String rangeDatatypeUri = getRangeDatatypeUri(editConfiguration, vreq);
|
|
||||||
if(rangeDatatypeUri != null && rangeDatatypeUri.length() > 0) {
|
|
||||||
String defaultVal = defaultsForXSDtypes.get(rangeDatatypeUri);
|
|
||||||
List<String> defaultArray = new ArrayList<String>();
|
|
||||||
defaultArray.add(defaultVal);
|
|
||||||
literalOptions.add(defaultArray);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return literalOptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRangeLang(EditConfigurationVTwo editConfiguration,
|
|
||||||
VitroRequest vreq) {
|
|
||||||
String rangeLang = null;
|
|
||||||
|
|
||||||
DataPropertyStatement dps =EditConfigurationUtils.getDataPropertyStatement(vreq, vreq.getSession(), dataHash, predicateUri);
|
|
||||||
if(dps != null) {
|
|
||||||
rangeLang = dps.getLanguage();
|
|
||||||
if( rangeLang == null ) {
|
|
||||||
log.debug("no language attribute on data property statement in DefaultDataPropertyFormGenerator");
|
|
||||||
}else{
|
|
||||||
log.debug("language attribute of ["+rangeLang+"] on data property statement in DefaultDataPropertyFormGenerator");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if( rangeLang != null && rangeLang.trim().length() == 0)
|
|
||||||
rangeLang = null;
|
|
||||||
return rangeLang;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRangeDatatypeUri(EditConfigurationVTwo editConfiguration,
|
|
||||||
VitroRequest vreq) {
|
|
||||||
Individual subject = EditConfigurationUtils.getSubjectIndividual(vreq);
|
|
||||||
DataProperty prop = EditConfigurationUtils.getDataProperty(vreq);
|
|
||||||
|
|
||||||
//rangeDefaultJson goes into literalk options
|
|
||||||
//validations include dataype:rangedatatypeurijson
|
|
||||||
//rangeDatatypeUri is rangeDAttypeUriJson
|
|
||||||
//rangeLang = rangeLanJson
|
|
||||||
DataPropertyStatement dps =EditConfigurationUtils.getDataPropertyStatement(vreq, vreq.getSession(), dataHash, predicateUri);
|
|
||||||
String rangeDatatypeUri = vreq.getWebappDaoFactory().getDataPropertyDao().getRequiredDatatypeURI(subject, prop);
|
|
||||||
|
|
||||||
if( dps != null ){
|
|
||||||
rangeDatatypeUri = dps.getDatatypeURI();
|
|
||||||
if( rangeDatatypeUri == null ){
|
|
||||||
log.debug("no range datatype uri set on data property statement when property's range datatype is "+prop.getRangeDatatypeURI()+" in DefaultDataPropertyFormGenerator");
|
|
||||||
} else {
|
|
||||||
log.debug("range datatype uri of ["+rangeDatatypeUri+"] on data property statement in DefaultDataPropertyFormGenerator");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.debug("No incoming dataproperty statement attribute for property "+prop.getPublicName()+"; adding a new statement");
|
|
||||||
}
|
|
||||||
if( rangeDatatypeUri != null && rangeDatatypeUri.trim().length() == 0)
|
|
||||||
rangeDatatypeUri = null;
|
|
||||||
|
|
||||||
return rangeDatatypeUri;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Map<String, FieldVTwo> getObjectPropertyField(
|
private Map<String, FieldVTwo> getObjectPropertyField(
|
||||||
EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
|
EditConfigurationVTwo editConfiguration, VitroRequest vreq) throws Exception {
|
||||||
Map<String, FieldVTwo> fields = new HashMap<String, FieldVTwo>();
|
Map<String, FieldVTwo> fields = new HashMap<String, FieldVTwo>();
|
||||||
FieldVTwo field = new FieldVTwo();
|
FieldVTwo field = new FieldVTwo();
|
||||||
field.setName("objectVar");
|
field.setName("objectVar");
|
||||||
|
@ -409,20 +321,13 @@ public class DefaultObjectPropertyFormGenerator implements EditConfigurationGene
|
||||||
List<String> validators = new ArrayList<String>();
|
List<String> validators = new ArrayList<String>();
|
||||||
validators.add("nonempty");
|
validators.add("nonempty");
|
||||||
field.setValidators(validators);
|
field.setValidators(validators);
|
||||||
|
|
||||||
//subjectUri and subjectClassUri are not being used in Field
|
|
||||||
|
|
||||||
field.setOptionsType("INDIVIDUALS_VIA_OBJECT_PROPERTY");
|
|
||||||
field.setPredicateUri(predicateUri);
|
|
||||||
|
|
||||||
field.setObjectClassUri(null);
|
|
||||||
field.setRangeDatatypeUri(null);
|
|
||||||
|
|
||||||
field.setRangeLang(null);
|
|
||||||
field.setLiteralOptions(new ArrayList<List<String>>());
|
|
||||||
|
|
||||||
fields.put(field.getName(), field);
|
field.setOptions( new IndividualsViaObjectPropetyOptions(
|
||||||
|
subjectUri,
|
||||||
|
predicateUri,
|
||||||
|
objectUri));
|
||||||
|
|
||||||
|
fields.put(field.getName(), field);
|
||||||
return fields;
|
return fields;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,5 +8,5 @@ import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||||
|
|
||||||
public interface EditConfigurationGenerator {
|
public interface EditConfigurationGenerator {
|
||||||
public EditConfigurationVTwo getEditConfiguration( VitroRequest vreq, HttpSession session );
|
public EditConfigurationVTwo getEditConfiguration( VitroRequest vreq, HttpSession session ) throws Exception;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,8 @@ import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.FieldVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.SelectListGeneratorVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.SelectListGeneratorVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils;
|
import edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils;
|
||||||
|
|
||||||
|
@ -371,9 +371,7 @@ public class MenuEditingFormGenerator implements EditConfigurationGenerator {
|
||||||
|
|
||||||
List<String> validators = new ArrayList<String>();
|
List<String> validators = new ArrayList<String>();
|
||||||
validators.add("nonempty");
|
validators.add("nonempty");
|
||||||
field.setValidators(validators);
|
field.setValidators(validators);
|
||||||
field.setOptionsType("LITERALS");
|
|
||||||
field.setPredicateUri(DisplayVocabulary.DISPLAY_NS + "title");
|
|
||||||
|
|
||||||
fields.put("title", field);
|
fields.put("title", field);
|
||||||
//Object Var Field
|
//Object Var Field
|
||||||
|
|
|
@ -37,8 +37,8 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.AntiXssValidation;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.AntiXssValidation;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditN3GeneratorVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditN3GeneratorVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.SelectListGeneratorVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.FieldVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.SelectListGeneratorVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils;
|
import edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
||||||
|
|
||||||
|
@ -243,24 +243,12 @@ public class NewIndividualFormGenerator implements EditConfigurationGenerator {
|
||||||
private void setLabelField(EditConfigurationVTwo editConfiguration,
|
private void setLabelField(EditConfigurationVTwo editConfiguration,
|
||||||
VitroRequest vreq, Map<String, FieldVTwo> fields) {
|
VitroRequest vreq, Map<String, FieldVTwo> fields) {
|
||||||
FieldVTwo field = new FieldVTwo();
|
FieldVTwo field = new FieldVTwo();
|
||||||
field.setName("label");
|
field.setName("label");
|
||||||
//queryForExisting is not being used anywhere in Field
|
field.setRangeDatatypeUri( XSD.xstring.toString() );
|
||||||
String stringDatatypeUri = XSD.xstring.toString();
|
|
||||||
|
|
||||||
|
|
||||||
List<String> validators = new ArrayList<String>();
|
List<String> validators = new ArrayList<String>();
|
||||||
validators.add("nonempty");
|
validators.add("nonempty");
|
||||||
field.setValidators(validators);
|
field.setValidators(validators);
|
||||||
|
|
||||||
//subjectUri and subjectClassUri are not being used in Field
|
|
||||||
|
|
||||||
field.setOptionsType("UNDEFINED");
|
|
||||||
//why isn't predicate uri set for data properties?
|
|
||||||
field.setPredicateUri(null);
|
|
||||||
field.setObjectClassUri(null);
|
|
||||||
field.setRangeDatatypeUri(stringDatatypeUri);
|
|
||||||
|
|
||||||
field.setLiteralOptions(new ArrayList<List<String>>());
|
|
||||||
|
|
||||||
fields.put(field.getName(), field);
|
fields.put(field.getName(), field);
|
||||||
editConfiguration.setFields(fields);
|
editConfiguration.setFields(fields);
|
||||||
|
|
|
@ -34,8 +34,8 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.AntiXssValidation;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.AntiXssValidation;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditN3GeneratorVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditN3GeneratorVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.SelectListGeneratorVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.FieldVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.SelectListGeneratorVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils;
|
import edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||||
|
@ -231,33 +231,19 @@ public class RDFSLabelGenerator implements EditConfigurationGenerator {
|
||||||
String rangeDatatypeUri = getRangeDatatypeUri(editConfiguration, vreq);
|
String rangeDatatypeUri = getRangeDatatypeUri(editConfiguration, vreq);
|
||||||
String rangeLang = getRangeLang(editConfiguration, vreq);
|
String rangeLang = getRangeLang(editConfiguration, vreq);
|
||||||
|
|
||||||
List<String> validators = getFieldValidators(editConfiguration, vreq);
|
List<String> validators = getFieldValidators(editConfiguration, vreq);
|
||||||
|
field.setValidators(validators);
|
||||||
field.setValidators(validators);
|
|
||||||
|
|
||||||
//subjectUri and subjectClassUri are not being used in Field
|
|
||||||
|
|
||||||
field.setOptionsType("UNDEFINED");
|
|
||||||
//why isn't predicate uri set for data properties?
|
|
||||||
field.setPredicateUri(null);
|
|
||||||
field.setObjectClassUri(null);
|
|
||||||
field.setRangeDatatypeUri(rangeDatatypeUri);
|
field.setRangeDatatypeUri(rangeDatatypeUri);
|
||||||
//have either range datatype uri or range lang, otherwise results in error
|
//have either range datatype uri or range lang, otherwise results in error
|
||||||
if(rangeDatatypeUri == null) {
|
if(rangeDatatypeUri == null) {
|
||||||
field.setRangeLang(rangeLang);
|
field.setRangeLang(rangeLang);
|
||||||
}
|
}
|
||||||
field.setLiteralOptions(getLiteralOptions(editConfiguration, vreq));
|
|
||||||
|
|
||||||
fields.put(field.getName(), field);
|
fields.put(field.getName(), field);
|
||||||
return fields;
|
return fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<List<String>> getLiteralOptions(
|
|
||||||
EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
|
|
||||||
DataPropertyStatement dps =EditConfigurationUtils.getDataPropertyStatement(vreq, vreq.getSession(), dataHash, predicateUri);
|
|
||||||
List<List<String>> literalOptions = new ArrayList<List<String>>();
|
|
||||||
return literalOptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRangeLang(EditConfigurationVTwo editConfiguration,
|
private String getRangeLang(EditConfigurationVTwo editConfiguration,
|
||||||
VitroRequest vreq) {
|
VitroRequest vreq) {
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.vocabulary.OWL;
|
||||||
|
import com.hp.hpl.jena.vocabulary.RDF;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.ChildVClassesOptions;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
||||||
|
|
||||||
|
public class RdfTypeGenerator extends BaseEditConfigurationGenerator implements EditConfigurationGenerator {
|
||||||
|
|
||||||
|
private Log log = LogFactory.getLog(RdfTypeGenerator.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EditConfigurationVTwo getEditConfiguration( VitroRequest vreq, HttpSession session) {
|
||||||
|
EditConfigurationVTwo editConfig = new EditConfigurationVTwo();
|
||||||
|
|
||||||
|
//get editkey and url of form
|
||||||
|
initBasics(editConfig, vreq);
|
||||||
|
initPropertyParameters(vreq, session, editConfig);
|
||||||
|
initObjectPropForm(editConfig, vreq);
|
||||||
|
|
||||||
|
editConfig.addUrisInScope("rdfTypeUri", Arrays.asList( RDF.type.getURI() ) );
|
||||||
|
|
||||||
|
editConfig.setN3Required( " ?subject ?rdfTypeUri ?object . ");
|
||||||
|
|
||||||
|
//set fields
|
||||||
|
editConfig.setUrisOnForm("object");
|
||||||
|
editConfig.addField( new FieldVTwo( )
|
||||||
|
.setName("object")
|
||||||
|
.setOptions(
|
||||||
|
new ChildVClassesOptions(OWL.Class.getURI()) )
|
||||||
|
);
|
||||||
|
|
||||||
|
editConfig.setTemplate("rdfTypeForm.ftl");
|
||||||
|
return editConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -153,7 +153,7 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet {
|
||||||
//TODO: should more of what happens in this method
|
//TODO: should more of what happens in this method
|
||||||
//happen in the generators?
|
//happen in the generators?
|
||||||
private EditConfigurationVTwo setupEditConfiguration(String editConfGeneratorName,
|
private EditConfigurationVTwo setupEditConfiguration(String editConfGeneratorName,
|
||||||
VitroRequest vreq) {
|
VitroRequest vreq) throws Exception {
|
||||||
HttpSession session = vreq.getSession();
|
HttpSession session = vreq.getSession();
|
||||||
EditConfigurationVTwo editConfig =
|
EditConfigurationVTwo editConfig =
|
||||||
makeEditConfigurationVTwo( editConfGeneratorName, vreq, session);
|
makeEditConfigurationVTwo( editConfGeneratorName, vreq, session);
|
||||||
|
@ -362,7 +362,7 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet {
|
||||||
|
|
||||||
|
|
||||||
private EditConfigurationVTwo makeEditConfigurationVTwo(
|
private EditConfigurationVTwo makeEditConfigurationVTwo(
|
||||||
String editConfGeneratorName, VitroRequest vreq, HttpSession session) {
|
String editConfGeneratorName, VitroRequest vreq, HttpSession session) throws Exception {
|
||||||
|
|
||||||
EditConfigurationGenerator EditConfigurationVTwoGenerator = null;
|
EditConfigurationGenerator EditConfigurationVTwoGenerator = null;
|
||||||
|
|
||||||
|
|
|
@ -33,8 +33,8 @@ import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditElementVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditElementVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.FieldVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.SelectListGeneratorVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.SelectListGeneratorVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.beanswrappers.ReadOnlyBeansWrapper;
|
import edu.cornell.mannlib.vitro.webapp.web.beanswrappers.ReadOnlyBeansWrapper;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.ObjectPropertyStatementTemplateModel;
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.ObjectPropertyStatementTemplateModel;
|
||||||
|
@ -48,7 +48,7 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel {
|
||||||
VitroRequest vreq;
|
VitroRequest vreq;
|
||||||
private Log log = LogFactory.getLog(EditConfigurationTemplateModel.class);
|
private Log log = LogFactory.getLog(EditConfigurationTemplateModel.class);
|
||||||
|
|
||||||
public EditConfigurationTemplateModel( EditConfigurationVTwo editConfig, VitroRequest vreq){
|
public EditConfigurationTemplateModel( EditConfigurationVTwo editConfig, VitroRequest vreq) throws Exception{
|
||||||
this.editConfig = editConfig;
|
this.editConfig = editConfig;
|
||||||
this.vreq = vreq;
|
this.vreq = vreq;
|
||||||
//get additional data that may be required to generate template
|
//get additional data that may be required to generate template
|
||||||
|
@ -72,7 +72,7 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel {
|
||||||
* Such as options for a drop-down etc.
|
* Such as options for a drop-down etc.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private void retrieveEditData() {
|
private void retrieveEditData() throws Exception {
|
||||||
//Get vitro request attributes for
|
//Get vitro request attributes for
|
||||||
setFormTitle();
|
setFormTitle();
|
||||||
setSubmitLabel();
|
setSubmitLabel();
|
||||||
|
@ -89,17 +89,16 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel {
|
||||||
|
|
||||||
//Based on certain pre-set fields/variables, look for what
|
//Based on certain pre-set fields/variables, look for what
|
||||||
//drop-downs need to be populated
|
//drop-downs need to be populated
|
||||||
private void populateDropdowns() {
|
private void populateDropdowns() throws Exception {
|
||||||
|
|
||||||
//For each field with an optionType defined, create the options
|
//For each field with an optionType defined, create the options
|
||||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
||||||
for(String fieldName: editConfig.getFields().keySet()){
|
for(String fieldName: editConfig.getFields().keySet()){
|
||||||
FieldVTwo field = editConfig.getField(fieldName);
|
FieldVTwo field = editConfig.getField(fieldName);
|
||||||
if( field.getOptionsType() == FieldVTwo.OptionsType.UNDEFINED
|
if( field.getFieldOptions() == null ){
|
||||||
|| field.getOptionsType() == null ){
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Map<String, String> optionsMap = SelectListGeneratorVTwo.getOptions(editConfig, fieldName, wdf);
|
Map<String, String> optionsMap = SelectListGeneratorVTwo.getOptions(editConfig, fieldName, wdf);
|
||||||
optionsMap = SelectListGeneratorVTwo.getSortedMap(optionsMap);
|
optionsMap = SelectListGeneratorVTwo.getSortedMap(optionsMap);
|
||||||
pageData.put(fieldName, optionsMap);
|
pageData.put(fieldName, optionsMap);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo;
|
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.hp.hpl.jena.rdf.model.Literal;
|
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||||
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
||||||
|
@ -18,6 +20,7 @@ import com.hp.hpl.jena.vocabulary.RDFS;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
|
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.InsertException;
|
import edu.cornell.mannlib.vitro.webapp.dao.InsertException;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfigurationConstants;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfigurationConstants;
|
||||||
|
|
||||||
public class ProcessRdfFormTest extends AbstractTestClass{
|
public class ProcessRdfFormTest extends AbstractTestClass{
|
||||||
|
|
|
@ -10,8 +10,8 @@ import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.FieldVTwo;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.MultiValueEditSubmission;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.MultiValueEditSubmission;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
||||||
|
|
||||||
public class AntiXssValidationTest {
|
public class AntiXssValidationTest {
|
||||||
|
|
||||||
|
|
|
@ -3,94 +3,15 @@
|
||||||
@prefix owl: <http://www.w3.org/2002/07/owl#> .
|
@prefix owl: <http://www.w3.org/2002/07/owl#> .
|
||||||
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
||||||
|
|
||||||
<http://vitro.mannlib.cornell.edu/ontologies/display/1.1#MenuText>
|
rdf:type
|
||||||
<http://vitro.mannlib.cornell.edu/ontologies/display/1.1#hasMenuText>
|
a owl:ObjectProperty ;
|
||||||
"""# $This file is distributed under the terms of the license in /doc/license.txt$
|
rdfs:label "RDF Type"@en-US ;
|
||||||
|
rdfs:range owl:Class;
|
||||||
@prefix owl: <http://www.w3.org/2002/07/owl#> .
|
<http://vitro.mannlib.cornell.edu/ns/vitro/0.7#customEntryFormAnnot>
|
||||||
@prefix display: <http://vitro.mannlib.cornell.edu/ontologies/display/1.1#> .
|
"edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.RdfTypeGenerator"^^xsd:string ;
|
||||||
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
<http://vitro.mannlib.cornell.edu/ns/vitro/0.7#offerCreateNewOptionAnnot>
|
||||||
@prefix core: <http://vivoweb.org/ontology/core#> .
|
"true"^^xsd:boolean ;
|
||||||
@prefix vivoweb: <http://vivoweb.org/ontology#> .
|
<http://vitro.mannlib.cornell.edu/ns/vitro/0.7#selectFromExistingAnnot>
|
||||||
|
"true"^^xsd:boolean ;
|
||||||
### This file defines the default menu for vivo. ###
|
|
||||||
|
|
||||||
#### Default Menu ####
|
|
||||||
|
|
||||||
display:DefaultMenu
|
|
||||||
a display:MainMenu ;
|
|
||||||
display:hasElement display:EventsMenuItem ;
|
|
||||||
display:hasElement display:HomeMenuItem ;
|
|
||||||
display:hasElement display:OrganizationsMenuItem ;
|
|
||||||
display:hasElement display:PeopleMenuItem ;
|
|
||||||
display:hasElement display:ResearchMenuItem .
|
|
||||||
|
|
||||||
#### Menu Items for Default Menu ####
|
|
||||||
|
|
||||||
display:HomeMenuItem
|
|
||||||
a display:NavigationElement ;
|
|
||||||
display:menuPosition 1;
|
|
||||||
display:linkText \"Home\";
|
|
||||||
display:toPage display:Home .
|
|
||||||
|
|
||||||
display:PeopleMenuItem
|
|
||||||
a display:NavigationElement ;
|
|
||||||
display:menuPosition 2;
|
|
||||||
display:linkText \"People\";
|
|
||||||
display:toPage display:People .
|
|
||||||
|
|
||||||
display:OrganizationsMenuItem
|
|
||||||
a display:NavigationElement ;
|
|
||||||
display:menuPosition 3;
|
|
||||||
display:linkText \"Organizations\";
|
|
||||||
display:toPage display:Organizations .
|
|
||||||
|
|
||||||
display:ResearchMenuItem
|
|
||||||
a display:NavigationElement ;
|
|
||||||
display:menuPosition 4;
|
|
||||||
display:linkText \"Research\";
|
|
||||||
display:toPage display:Research .
|
|
||||||
|
|
||||||
display:EventsMenuItem
|
|
||||||
a display:NavigationElement ;
|
|
||||||
display:menuPosition 5;
|
|
||||||
display:linkText \"Events\";
|
|
||||||
display:toPage display:Events .
|
|
||||||
|
|
||||||
########## Pages ############
|
|
||||||
|
|
||||||
display:Home
|
|
||||||
a display:HomePage ;
|
|
||||||
a display:Page ;
|
|
||||||
display:title \"Home\" ;
|
|
||||||
display:urlMapping \"/\" .
|
|
||||||
|
|
||||||
display:Events
|
|
||||||
a display:Page ;
|
|
||||||
a display:ClassGroupPage;
|
|
||||||
display:forClassGroup vivoweb:vitroClassGroupevents ;
|
|
||||||
display:title \"Events\" ;
|
|
||||||
display:urlMapping \"/events\" .
|
|
||||||
|
|
||||||
display:Organizations
|
|
||||||
a display:Page ;
|
|
||||||
a display:ClassGroupPage;
|
|
||||||
display:forClassGroup vivoweb:vitroClassGrouporganizations ;
|
|
||||||
display:title \"Organizations\" ;
|
|
||||||
display:urlMapping \"/organizations\" .
|
|
||||||
|
|
||||||
display:People
|
|
||||||
a display:Page ;
|
|
||||||
a display:ClassGroupPage;
|
|
||||||
display:forClassGroup vivoweb:vitroClassGrouppeople ;
|
|
||||||
display:requiresBodyTemplate \"menupage--classgroup-people.ftl\" ;
|
|
||||||
display:title \"People\" ;
|
|
||||||
display:urlMapping \"/people\" .
|
|
||||||
|
|
||||||
display:Research
|
|
||||||
a display:Page ;
|
|
||||||
a display:ClassGroupPage;
|
|
||||||
display:forClassGroup vivoweb:vitroClassGrouppublications ;
|
|
||||||
display:title \"Research\" ;
|
|
||||||
display:urlMapping \"/research\" .
|
|
||||||
""" .
|
|
|
@ -64,6 +64,7 @@ rdfs:comment
|
||||||
rdfs:label
|
rdfs:label
|
||||||
a owl:DatatypeProperty .
|
a owl:DatatypeProperty .
|
||||||
|
|
||||||
|
|
||||||
owl:versionInfo
|
owl:versionInfo
|
||||||
a owl:DatatypeProperty .
|
a owl:DatatypeProperty .
|
||||||
|
|
||||||
|
@ -145,6 +146,18 @@ owl:topObjectProperty
|
||||||
<http://vitro.mannlib.cornell.edu/ns/vitro/0.7#stubObjectPropertyAnnot>
|
<http://vitro.mannlib.cornell.edu/ns/vitro/0.7#stubObjectPropertyAnnot>
|
||||||
"true"^^xsd:boolean .
|
"true"^^xsd:boolean .
|
||||||
|
|
||||||
|
rdf:type
|
||||||
|
a owl:ObjectProperty ;
|
||||||
|
rdfs:label "RDF Type"@en-US ;
|
||||||
|
rdfs:range owl:Class ;
|
||||||
|
<http://vitro.mannlib.cornell.edu/ns/vitro/0.7#customEntryFormAnnot>
|
||||||
|
"edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.RdfTypeGenerator"^^xsd:string ;
|
||||||
|
<http://vitro.mannlib.cornell.edu/ns/vitro/0.7#offerCreateNewOptionAnnot>
|
||||||
|
"true"^^xsd:boolean ;
|
||||||
|
<http://vitro.mannlib.cornell.edu/ns/vitro/0.7#selectFromExistingAnnot>
|
||||||
|
"true"^^xsd:boolean .
|
||||||
|
|
||||||
|
|
||||||
<http://vitro.mannlib.cornell.edu/ns/vitro/0.7#additionalLink>
|
<http://vitro.mannlib.cornell.edu/ns/vitro/0.7#additionalLink>
|
||||||
a owl:ObjectProperty ;
|
a owl:ObjectProperty ;
|
||||||
rdfs:label "Additional Link"@en-US ;
|
rdfs:label "Additional Link"@en-US ;
|
||||||
|
|
45
webapp/web/templates/freemarker/edit/forms/rdfTypeForm.ftl
Normal file
45
webapp/web/templates/freemarker/edit/forms/rdfTypeForm.ftl
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||||
|
|
||||||
|
<#--Assign variables from editConfig-->
|
||||||
|
<#assign rangeOptions = editConfiguration.pageData.object />
|
||||||
|
<#assign rangeOptionsExist = false />
|
||||||
|
<#if (rangeOptions?keys?size > 0)>
|
||||||
|
<#assign rangeOptionsExist = true/>
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
<h2>${editConfiguration.formTitle}</h2>
|
||||||
|
|
||||||
|
|
||||||
|
<#if rangeOptionsExist = true >
|
||||||
|
<#assign rangeOptionKeys = rangeOptions?keys />
|
||||||
|
<form class="editForm" action = "${submitUrl}">
|
||||||
|
<input type="hidden" name="editKey" id="editKey" value="${editKey}" role="input" />
|
||||||
|
<select id="object" name="object" role="select">
|
||||||
|
<#list rangeOptionKeys as key>
|
||||||
|
<option value="${key}" <#if editConfiguration.objectUri?has_content && editConfiguration.objectUri = key>selected</#if> role="option">${rangeOptions[key]}</option>
|
||||||
|
</#list>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<input type="submit" id="submit" value="${editConfiguration.submitLabel}" role="button "/>
|
||||||
|
<span class="or"> or </span>
|
||||||
|
<a title="Cancel" class="cancel" href="${cancelUrl}">Cancel</a>
|
||||||
|
</p>
|
||||||
|
</form>
|
||||||
|
<#else>
|
||||||
|
<p> There are no Classes in the system from which to select. </p>
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
<#if editConfiguration.propertyOfferCreateNewOption = true>
|
||||||
|
<#include "defaultOfferCreateNewOptionForm.ftl">
|
||||||
|
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
<#if editConfiguration.propertySelectFromExisting = false && editConfiguration.propertyOfferCreateNewOption = false>
|
||||||
|
<p>This property is currently configured to prohibit editing. </p>
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
<#if editConfiguration.includeDeletionForm = true>
|
||||||
|
<#include "defaultDeletePropertyForm.ftl">
|
||||||
|
</#if>
|
||||||
|
|
Loading…
Add table
Reference in a new issue