diff --git a/productMods/templates/freemarker/edit/forms/addAssociatedConcept.ftl b/productMods/templates/freemarker/edit/forms/addAssociatedConcept.ftl index ee613943..fe1f81c6 100644 --- a/productMods/templates/freemarker/edit/forms/addAssociatedConcept.ftl +++ b/productMods/templates/freemarker/edit/forms/addAssociatedConcept.ftl @@ -66,6 +66,9 @@
<#if existingConcept.vocabURI?has_content && existingConcept.vocabLabel?has_content> ${existingConcept.vocabLabel} + <#else> +   + <#--We still want the column to be there even if no vocabulary source is present-->
diff --git a/productMods/templates/freemarker/edit/forms/addConceptThroughObjectPropertyAutoComplete.ftl b/productMods/templates/freemarker/edit/forms/addConceptThroughObjectPropertyAutoComplete.ftl new file mode 100644 index 00000000..9d92cefa --- /dev/null +++ b/productMods/templates/freemarker/edit/forms/addConceptThroughObjectPropertyAutoComplete.ftl @@ -0,0 +1,145 @@ +<#-- $This file is distributed under the terms of the license in /doc/license.txt$ --> +<#--Assign variables from editConfig--> +<#assign rangeOptions = editConfiguration.pageData.objectVar /> +<#-- +<#assign rangeOptionsExist = false /> +<#if (rangeOptions?keys?size > 0)> + <#assign rangeOptionsExist = true/> + + --> + +<#assign rangeOptionsExist = true /> + +<#assign objectTypes = editConfiguration.pageData.objectTypes /> +<#assign objectTypesSize = objectTypes?length /> +<#assign objectTypesExist = false /> +<#assign multipleTypes = false /> +<#if (objectTypesSize > 1)> + <#assign objectTypesExist = true /> + +<#if objectTypes?contains(",")> + <#assign multipleTypes = true/> + +<#assign sparqlForAcFilter = editConfiguration.pageData.sparqlForAcFilter /> +<#assign editMode = editConfiguration.pageData.editMode /> +<#assign propertyNameForDisplay = "" /> +<#if editConfiguration.objectPropertyNameForDisplay?has_content> + <#assign propertyNameForDisplay = editConfiguration.objectPropertyNameForDisplay /> + +<#if editMode = "edit" > + <#assign titleVerb = "${i18n().edit_capitalized}" /> + <#assign objectLabel = editConfiguration.pageData.objectLabel /> + <#assign selectedObjectUri = editConfiguration.objectUri /> + <#assign submitButtonText = "${i18n().save_button}" /> +<#else> + <#assign titleVerb = "${i18n().add_capitalized}" > + <#assign objectLabel = "" /> + <#assign selectedObjectUri = ""/> + <#assign submitButtonText = "${i18n().create_entry}" /> + + +<#if editConfiguration.formTitle?contains("collaborator") > + <#assign formTitle = "${i18n().select_existing_collaborator(editConfiguration.subjectName)}" /> +<#else> + <#assign formTitle = editConfiguration.formTitle /> + +<#--In order to fill out the subject--> +<#assign acFilterForIndividuals = "['" + editConfiguration.subjectUri + "']" /> + +

${formTitle}

+ +<#if editConfiguration.propertySelectFromExisting = true> + <#if rangeOptionsExist = true > +
+ + <#if editConfiguration.propertyPublicDescription?has_content> +

${editConfiguration.propertyPublicDescription}

+ + + <#---This section should become autocomplete instead--> +

+ + +

+ +
+

+ + + (${i18n().verify_this_match} ${i18n().or} + ${i18n().change_selection}) +

+ +
+ + <#--The above section should be autocomplete--> + +

+ + + or + ${i18n().cancel_link} +

+
+ <#else> +

${i18n().there_are_no_entries_for_selection}

+ + +

 

+<#if editConfiguration.propertyOfferCreateNewOption = true> +<#include "addConceptThroughObjectPropertyCreateNew.ftl"> + + + +<#if editConfiguration.propertySelectFromExisting = false && editConfiguration.propertyOfferCreateNewOption = false> +

${i18n().editing_prohibited}

+ + + +<#if editConfiguration.includeDeletionForm = true> +<#include "defaultDeletePropertyForm.ftl"> + + + +<#assign sparqlQueryUrl = "${urls.base}/ajax/sparqlQuery" > +<#--Passing in object types only if there are any types returned, otherwise +the parameter should not be passed at all to the solr search. +Also multiple types parameter set to true only if more than one type returned--> + +<#-- + edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.AutocompleteObjectPropertyFormGenerator + edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.AddAttendeeRoleToPersonGenerator +--> + +${stylesheets.add('')} + ${stylesheets.add('')} + ${stylesheets.add('')} + + + ${scripts.add('', + '', + '', + '')} diff --git a/productMods/templates/freemarker/edit/forms/addConceptThroughObjectPropertyCreateNew.ftl b/productMods/templates/freemarker/edit/forms/addConceptThroughObjectPropertyCreateNew.ftl new file mode 100644 index 00000000..9efc361b --- /dev/null +++ b/productMods/templates/freemarker/edit/forms/addConceptThroughObjectPropertyCreateNew.ftl @@ -0,0 +1,35 @@ +<#-- $This file is distributed under the terms of the license in /doc/license.txt$ --> +<#--Overriding default form here to allow just concepts to show in the list--> + + <#if rangeOptionsExist = true > +

${i18n().no_appropriate_entry}:

+ <#else> +

${i18n().create_new_entry}

+ + + <#if editConfiguration.objectUri?has_content> + <#assign objectUri = editConfiguration.objectUri> + <#else> + <#assign objectUri = ""/> + + + <#assign typesList = editConfiguration.pageData.createNewTypes/> +
+ + + + + + + + + <#if rangeOptionsExist = false > + ${i18n().or} + ${i18n().cancel_link} + +
\ No newline at end of file diff --git a/productMods/templates/freemarker/edit/forms/addConceptThroughObjectPropertyForm.ftl b/productMods/templates/freemarker/edit/forms/addConceptThroughObjectPropertyForm.ftl new file mode 100644 index 00000000..89b5ddc4 --- /dev/null +++ b/productMods/templates/freemarker/edit/forms/addConceptThroughObjectPropertyForm.ftl @@ -0,0 +1,49 @@ +<#-- $This file is distributed under the terms of the license in /doc/license.txt$ --> + +<#--Assign variables from editConfig--> +<#assign rangeOptions = editConfiguration.pageData.objectVar /> +<#assign rangeOptionsExist = false /> +<#if (rangeOptions?keys?size > 0)> + <#assign rangeOptionsExist = true/> + + +

${editConfiguration.formTitle}

+ +<#if editConfiguration.propertySelectFromExisting = true> + <#if rangeOptionsExist = true > + <#assign rangeOptionKeys = rangeOptions?keys /> +
+ + <#if editConfiguration.propertyPublicDescription?has_content> +

${editConfiguration.propertyPublicDescription}

+ + + +

+ + ${i18n().or} + ${i18n().cancel_link} +

+
+ <#else> +

${i18n().there_are_no_entries_for_selection}

+ + + +<#if editConfiguration.propertyOfferCreateNewOption = true> +<#include "addConceptThroughObjectPropertyCreateNew.ftl"> + + +<#if editConfiguration.propertySelectFromExisting = false && editConfiguration.propertyOfferCreateNewOption = false> +

${i18n().editing_prohibited}

+ + + +<#if editConfiguration.includeDeletionForm = true> +<#include "defaultDeletePropertyForm.ftl"> + + diff --git a/rdf/tbox/firsttime/initialTBoxAnnotations.n3 b/rdf/tbox/firsttime/initialTBoxAnnotations.n3 index 36af8a0a..d8e1fe18 100644 --- a/rdf/tbox/firsttime/initialTBoxAnnotations.n3 +++ b/rdf/tbox/firsttime/initialTBoxAnnotations.n3 @@ -329,6 +329,8 @@ vivo:GovernmentAgency skos:narrower rdfs:label "narrower term"@en-US ; + vitro:customEntryFormAnnot + "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.AddConceptThroughObjectPropertyGenerator"^^xsd:string ; vitro:displayLimitAnnot "5"^^xsd:int ; vitro:displayRankAnnot @@ -4744,6 +4746,8 @@ obo:ERO_0001245 skos:broader rdfs:label "broader term"@en-US ; + vitro:customEntryFormAnnot + "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.AddConceptThroughObjectPropertyGenerator"^^xsd:string ; vitro:displayLimitAnnot "5"^^xsd:int ; vitro:displayRankAnnot diff --git a/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddConceptThroughObjectPropertyGenerator.java b/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddConceptThroughObjectPropertyGenerator.java new file mode 100644 index 00000000..56fd11dd --- /dev/null +++ b/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddConceptThroughObjectPropertyGenerator.java @@ -0,0 +1,133 @@ +/* $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.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpSession; + +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.VClass; +import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; +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.EditConfigurationVTwo; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.ConstantFieldOptions; +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.VTwo.fields.IndividualsViaSolrQueryOptions; + +/** + * This generator is for the case where a new concept is being added for an object property other than research/subject areas where the + * default object property form generator would work instead of the generator for managing concepts. + * In this case, we don't want the dropdown list for types for "add a new item of this type" to show concept subclasses, so we are overriding + * the fields to just include the Concept class. + */ +public class AddConceptThroughObjectPropertyGenerator extends DefaultObjectPropertyFormGenerator implements EditConfigurationGenerator { + + private Log log = LogFactory.getLog(AddConceptThroughObjectPropertyGenerator.class); + + @Override + public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq, + HttpSession session) throws Exception { + EditConfigurationVTwo editConfig = super.getEditConfiguration(vreq, session); + //return rangetypes in form specific data + editConfig.addFormSpecificData("createNewTypes", getCreateNewTypesOptions(vreq)); + //override templates with ones that will override create new types portion + editConfig.setTemplate(getTemplate(vreq)); + return editConfig; + } + + private HashMap getCreateNewTypesOptions(VitroRequest vreq) { + HashMap options = new HashMap(); + List rangeTypes = getRangeTypes(vreq); + for(VClass v: rangeTypes) { + options.put(v.getURI(), v.getName()); + } + return options; + } + + //We will override range types as well so that autocomplete and other fields dependent on range + //will only consider the main concept type to be the range type + @Override + protected List getRangeTypes(VitroRequest vreq) { + // This first part needs a WebappDaoFactory with no filtering/RDFService + // funny business because it needs to be able to retrieve anonymous union + // classes by their "pseudo-bnode URIs". + // Someday we'll need to figure out a different way of doing this. + //WebappDaoFactory ctxDaoFact = ModelAccess.on( + // vreq.getSession().getServletContext()).getWebappDaoFactory(); + WebappDaoFactory ctxDaoFact = vreq.getLanguageNeutralWebappDaoFactory(); + + List types = new ArrayList(); + Individual subject = EditConfigurationUtils.getSubjectIndividual(vreq); + String predicateUri = EditConfigurationUtils.getPredicateUri(vreq); + String rangeUri = EditConfigurationUtils.getRangeUri(vreq); + if (rangeUri != null) { + VClass rangeVClass = ctxDaoFact.getVClassDao().getVClassByURI(rangeUri); + if (!rangeVClass.isUnion()) { + types.add(rangeVClass); + } else { + for (VClass unionComponent : rangeVClass.getUnionComponents()) { + types.add(unionComponent); + } + } + return types; + } else { + //This should never happen + log.warn("Range not found for this property so employing SKOS concept class"); + String vclassURI = "http://www.w3.org/2004/02/skos/core#Concept"; + VClass rangeVClass = ctxDaoFact.getVClassDao().getVClassByURI(vclassURI); + types.add(rangeVClass); + } + + return types; + } + + //Should override the method in default object property + private String getTemplate( + VitroRequest vreq) { + + String acObjectPropertyTemplate = "addConceptThroughObjectPropertyAutoComplete.ftl"; + String objectPropertyTemplate = "addConceptThroughObjectPropertyForm.ftl"; + String template = objectPropertyTemplate; + if( doAutoComplete ) + template = acObjectPropertyTemplate; + return template; + + } + + @Override + protected void setFields(EditConfigurationVTwo editConfiguration, VitroRequest vreq, String predicateUri, List rangeTypes) throws Exception { + FieldVTwo field = new FieldVTwo(); + field.setName("objectVar"); + + List validators = new ArrayList(); + validators.add("nonempty"); + field.setValidators(validators); + + if( ! doAutoComplete ){ + List types = new ArrayList(); + for(VClass v: rangeTypes) { + types.add(v.getURI()); + } + field.setOptions( new IndividualsViaSolrQueryOptions( + vreq.getSession().getServletContext(), + types.toArray(new String[types.size()]))); + }else{ + field.setOptions(null); + } + + Map fields = new HashMap(); + fields.put(field.getName(), field); + + editConfiguration.setFields(fields); + } + +} diff --git a/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/NewIndividualFormGenerator.java b/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/NewIndividualFormGenerator.java index 4ebe249a..9851b90e 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/NewIndividualFormGenerator.java +++ b/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/NewIndividualFormGenerator.java @@ -172,7 +172,9 @@ public class NewIndividualFormGenerator extends BaseEditConfigurationGenerator i WebappDaoFactory wdf = vreq.getWebappDaoFactory(); Boolean isPersonType = Boolean.FALSE; String foafPersonType = getFOAFPersonClassURI(); - List superTypes = wdf.getVClassDao().getAllSuperClassURIs(getTypeOfNew(vreq)); + List superTypes = wdf.getVClassDao().getAllSuperClassURIs(getTypeOfNew(vreq)); + //add foaf person type too so that can also get checked + superTypes.add(foafPersonType); if( superTypes != null ){ for( String typeUri : superTypes){ if( foafPersonType.equals(typeUri)) {