diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultDataPropertyFormGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultDataPropertyFormGenerator.java new file mode 100644 index 000000000..81019c099 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultDataPropertyFormGenerator.java @@ -0,0 +1,135 @@ +/* $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 javax.servlet.http.HttpSession; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +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.controller.VitroRequest; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration; +import edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils; + +public class DefaultDataPropertyFormGenerator implements EditConfigurationGenerator { + + private Log log = LogFactory.getLog(DefaultDataPropertyFormGenerator.class); + private static HashMap defaultsForXSDtypes; + + static { + defaultsForXSDtypes = new HashMap(); + //defaultsForXSDtypes.put("http://www.w3.org/2001/XMLSchema#dateTime","2001-01-01T12:00:00"); + defaultsForXSDtypes.put("http://www.w3.org/2001/XMLSchema#dateTime","#Unparseable datetime defaults to now"); + } + + @Override + public EditConfiguration getEditConfiguration(VitroRequest vreq, + HttpSession session) { + + String subjectUri = vreq.getParameter("subjectUri"); + String predicateUri = vreq.getParameter("predicateUri"); + String subjectUriJson = (String)vreq.getAttribute("subjectUriJson"); + String predicateUriJson = (String)vreq.getAttribute("predicateUriJson"); + String objectUriJson = (String)vreq.getAttribute("objectUriJson"); + + DataPropertyStatement dps = (DataPropertyStatement)vreq.getAttribute("dataprop"); + + String datapropKeyStr = vreq.getParameter("datapropKey"); + int dataHash=0; + + DataProperty prop = (DataProperty)vreq.getAttribute("predicate"); + if( prop == null ) return doHelp(vreq, "In DefaultDataPropertyFormGenerator, could not find predicate " + predicateUri); + vreq.setAttribute("propertyName",prop.getPublicName()); + + Individual subject = (Individual)vreq.getAttribute("subject"); + if( subject == null ) return doHelp(vreq,"In DefaultDataPropertyFormGenerator, could not find subject " + subjectUri); + vreq.setAttribute("subjectName",subject.getName()); + + String rangeDatatypeUri = vreq.getWebappDaoFactory().getDataPropertyDao().getRequiredDatatypeURI(subject, prop); + //String rangeDatatypeUri = prop.getRangeDatatypeURI(); + vreq.setAttribute("rangeDatatypeUriJson", MiscWebUtils.escape(rangeDatatypeUri)); + + + if( dps != null ){ + try { + dataHash = Integer.parseInt(datapropKeyStr); + log.debug("dataHash is " + dataHash); + } catch (NumberFormatException ex) { + log.debug("could not parse dataprop hash "+ + "but there was a dataproperty; hash: '"+datapropKeyStr+"'"); + } + + String rangeDatatype = dps.getDatatypeURI(); + if( rangeDatatype == null ){ + log.debug("no range datatype uri set on data property statement when property's range datatype is "+prop.getRangeDatatypeURI()+" in DefaultDataPropertyFormGenerator"); + vreq.setAttribute("rangeDatatypeUriJson",""); + } else { + log.debug("range datatype uri of ["+rangeDatatype+"] on data property statement in DefaultDataPropertyFormGenerator"); + vreq.setAttribute("rangeDatatypeUriJson",rangeDatatype); + } + String rangeLang = dps.getLanguage(); + if( rangeLang == null ) { + log.debug("no language attribute on data property statement in DefaultDataPropertyFormGenerator"); + vreq.setAttribute("rangeLangJson",""); + }else{ + log.debug("language attribute of ["+rangeLang+"] on data property statement in DefaultDataPropertyFormGenerator"); + vreq.setAttribute("rangeLangJson", rangeLang); + } + } else { + log.debug("No incoming dataproperty statement attribute for property "+prop.getPublicName()+"; adding a new statement"); + if(rangeDatatypeUri != null && rangeDatatypeUri.length() > 0) { + String defaultVal = defaultsForXSDtypes.get(rangeDatatypeUri); + if( defaultVal == null ) + vreq.setAttribute("rangeDefaultJson", ""); + else + vreq.setAttribute("rangeDefaultJson", '"' + MiscWebUtils.escape(defaultVal) + '"' ); + } + } + + + String localName = prop.getLocalName(); + String dataLiteral = localName + "Edited"; + String formUrl = (String)vreq.getAttribute("formUrl"); + String editKey = (String)vreq.getAttribute("editKey"); + + EditConfiguration editConfiguration = new EditConfiguration(); + + List n3ForEdit = new ArrayList(); + n3ForEdit.add("?subject"); + n3ForEdit.add("?predicate"); + n3ForEdit.add("?"+dataLiteral); + editConfiguration.setN3Required(n3ForEdit); + + editConfiguration.setFormUrl(formUrl); + editConfiguration.setEditKey(editKey); + + editConfiguration.setDatapropKey((datapropKeyStr==null)?"":datapropKeyStr); + editConfiguration.setUrlPatternToReturnTo("/individual"); + + editConfiguration.setVarNameForSubject("subject"); + editConfiguration.setSubjectUri(subjectUriJson); + + editConfiguration.setVarNameForPredicate("predicate"); + editConfiguration.setPredicateUri(predicateUriJson); + + + + + + + return null; + } + + private EditConfiguration doHelp(VitroRequest vreq, String string) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultObjectPropertyFormGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultObjectPropertyFormGenerator.java new file mode 100644 index 000000000..b172f7eb9 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultObjectPropertyFormGenerator.java @@ -0,0 +1,277 @@ +/* $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 com.hp.hpl.jena.ontology.OntModel; +import com.hp.hpl.jena.rdf.model.Literal; +import com.hp.hpl.jena.rdf.model.Model; + +import edu.cornell.mannlib.vitro.webapp.beans.Individual; +import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty; +import edu.cornell.mannlib.vitro.webapp.beans.VClass; +import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; +import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary; +import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; +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.SelectListGenerator; +import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch; + +/** + * Generates the edit configuration for a default property form. + * + */ +public class DefaultObjectPropertyFormGenerator implements EditConfigurationGenerator { + + private Log log = LogFactory.getLog(DefaultObjectPropertyFormGenerator.class); + + @Override + public EditConfiguration getEditConfiguration(VitroRequest vreq, + HttpSession session) { + // TODO Generate a edit conf for the default object property form and return it. + + + Individual subject = (Individual)vreq.getAttribute("subject"); + ObjectProperty prop = (ObjectProperty)vreq.getAttribute("predicate"); + + WebappDaoFactory wdf = vreq.getWebappDaoFactory(); + + String queryForInverse = "PREFIX owl: " + + " SELECT ?inverse_property " + + " WHERE { ?inverse_property owl:inverseOf ?predicate } "; + + + // retrieving attributes from the request object to build editjson string + String formUrl = (String)vreq.getAttribute("formUrl"); + String editKey = (String)vreq.getAttribute("editKey"); + + String subjectUriJson = (String)vreq.getAttribute("subjectUriJson"); + String predicateUriJson = (String)vreq.getAttribute("predicateUriJson"); + String objectUriJson = (String)vreq.getAttribute("objectUriJson"); + + //building the editjson object + //TODO: There has to be a better way of doing this. + // Tried building a java object with Google Gson and then + // deserialize it to json, but the values in the string + // are sometimes lists, maps, literals. +/* String editjson = "{" + + " formUrl : " + formUrl + " ," + + " editKey : " + editKey + " ," + + " urlPatternToReturnTo : " + "/individual ," + + + " subject : [ subject , " + subjectUriJson + " ] , " + + " predicate : [ predicate , " + predicateUriJson + " ] ," + + " object : [ objectVar , " + objectUriJson + ", URI ] , " + + + " n3required : [ " + n3ForEdit + "] ," + + " n3optional : [ " + n3Inverse + "] ," + + " newResources : { } ," + + + " urisInScope : { } ," + + " literalsInScope: { } ," + + + " urisOnForm : [objectVar] ," + + " literalsOnForm : [ ] ," + + " filesOnForm : [ ] ," + + + "sparqlForLiterals : { } ," + + "sparqlForUris : { inverseProp : " + queryForInverse + " } ," + + + "sparqlForExistingLiterals : { } ," + + "sparqlForExistingUris : { } ," + + + "fields : { objectVar : { " + + " newResource : false ," + + " queryForExisting : { }, " + + " validators : [ nonempty ] ," + + " optionsType : INDIVIDUALS_VIA_OBJECT_PROPERTY , " + + " subjectUri : " + subjectUriJson + " ," + + " subjectClassUri : ," + + " predicateUri : " + predicateUriJson + " ," + + " objectClassUri : ," + + " rangeDatatypeUri : ," + + " rangeLang : , " + + " literalOptions : [ ] , " + + " assertions : [ " + n3ForEdit + " ," + n3Inverse + " ] " + + " } " + + " } " + + " } "; + +*/ + + //set the editjson attribute in the request + // vreq.setAttribute("editjson", editjson); + // log.debug(vreq.getAttribute("editjson")); + + + EditConfiguration editConfiguration = new EditConfiguration(); + + editConfiguration.setFormUrl(formUrl); + editConfiguration.setEditKey(editKey); + + editConfiguration.setUrlPatternToReturnTo("/individual"); + + editConfiguration.setVarNameForSubject("subject"); + editConfiguration.setSubjectUri(subjectUriJson); + + editConfiguration.setVarNameForPredicate("predicate"); + editConfiguration.setPredicateUri(predicateUriJson); + + editConfiguration.setVarNameForObject("objectVar"); + editConfiguration.setObject(objectUriJson); + + List n3ForEdit = new ArrayList(); + n3ForEdit.add("?subject"); + n3ForEdit.add("?predicate"); + n3ForEdit.add("?objectVar"); + editConfiguration.setN3Required(n3ForEdit); + + List n3Inverse = new ArrayList(); + n3Inverse.add("?objectVar"); + n3Inverse.add("?inverseProp"); + n3Inverse.add("?subject"); + editConfiguration.setN3Optional(n3Inverse); + + editConfiguration.setNewResources(new HashMap()); + + editConfiguration.setUrisInScope(new HashMap()); + + editConfiguration.setLiteralsInScope(new HashMap()); + + List urisOnForm = new ArrayList(); + urisOnForm.add("objectVar"); + editConfiguration.setN3Optional(urisOnForm); + + editConfiguration.setLiteralsOnForm(new ArrayList()); + + editConfiguration.setFilesOnForm(new ArrayList()); + + editConfiguration.setSparqlForAdditionalLiteralsInScope(new HashMap()); + + Map urisInScope = new HashMap(); + urisInScope.put("inverseProp", queryForInverse); + editConfiguration.setSparqlForAdditionalUrisInScope(urisInScope); + + editConfiguration.setSparqlForExistingLiterals(new HashMap()); + editConfiguration.setSparqlForExistingUris(new HashMap()); + + Map fields = new HashMap(); + + Field field = new Field(); + field.setName("objectVar"); + field.setNewResource(false); + //queryForExisting is not being used anywhere in Field + + List validators = new ArrayList(); + validators.add("nonempty"); + field.setValidators(validators); + + //subjectUri and subjectClassUri are not being used in Field + + field.setOptionsType("INDIVIDUALS_VIA_OBJECT_PROPERTY"); + field.setPredicateUri(predicateUriJson); + + field.setObjectClassUri(null); + field.setRangeDatatypeUri(null); + + field.setRangeLang(null); + field.setLiteralOptions(new ArrayList>()); + + List assertions = new ArrayList(); + assertions.add("?subject"); + assertions.add("?predicate"); + assertions.add("?objectVar"); + assertions.add("?objectVar"); + assertions.add("?inverseProp"); + assertions.add("?subject"); + field.setAssertions(assertions); + + fields.put("objectVar", field); + + editConfiguration.setFields(fields); + + editConfiguration.putConfigInSession(editConfiguration, session); + + editConfiguration.setTemplate("defaultPropertyForm.ftl"); + + + String formTitle = " "; + String submitLabel = " "; + + Model model = (Model) session.getServletContext().getAttribute("jenaOntModel"); + + //this block is for an edit of an existing object property statement + if(vreq.getAttribute("object") != null) { + editConfiguration.prepareForObjPropUpdate(model); + formTitle = "Change entry for: " + prop.getDomainPublic() + " "; + submitLabel = "save change"; + } else { + editConfiguration.prepareForNonUpdate( model ); + if ( prop.getOfferCreateNewOption() ) { + //Try to get the name of the class to select from + VClass classOfObjectFillers = null; + + if( prop.getRangeVClassURI() == null ) { + // If property has no explicit range, try to get classes + List classes = wdf.getVClassDao().getVClassesForProperty(subject.getVClassURI(), prop.getURI()); + if( classes == null || classes.size() == 0 || classes.get(0) == null ){ + // If property has no explicit range, we will use e.g. owl:Thing. + // Typically an allValuesFrom restriction will come into play later. + classOfObjectFillers = wdf.getVClassDao().getTopConcept(); + } else { + if( classes.size() > 1 ) + log.debug("Found multiple classes when attempting to get range vclass."); + classOfObjectFillers = classes.get(0); + } + }else{ + classOfObjectFillers = wdf.getVClassDao().getVClassByURI(prop.getRangeVClassURI()); + if( classOfObjectFillers == null ) + classOfObjectFillers = wdf.getVClassDao().getTopConcept(); + } + + log.debug("property set to offer \"create new\" option; custom form: ["+prop.getCustomEntryForm()+"]"); + formTitle = "Select an existing "+classOfObjectFillers.getName()+" for "+subject.getName(); + submitLabel = "select existing"; + } else { + formTitle = "Add an entry to: "+prop.getDomainPublic()+""; + submitLabel = "save entry"; + } + } + + vreq.setAttribute("formTitle", formTitle); + +// if( prop.getSelectFromExisting() ){ +// // set ProhibitedFromSearch object so picklist doesn't show +// // individuals from classes that should be hidden from list views +// OntModel displayOntModel = +// (OntModel) session.getServletContext() +// .getAttribute("displayOntModel"); +// if (displayOntModel != null) { +// ProhibitedFromSearch pfs = new ProhibitedFromSearch( +// DisplayVocabulary.PRIMARY_LUCENE_INDEX_URI, displayOntModel); +// if( editConfiguration != null ) +// editConfiguration.setProhibitedFromSearch(pfs); +// } +// Map rangeOptions = SelectListGenerator.getOptions(editConfiguration, "objectVar" , wdf); +// if( rangeOptions != null && rangeOptions.size() > 0 ) { +// vreq.setAttribute("rangeOptionsExist", true); +// vreq.setAttribute("rangeOptions.objectVar", rangeOptions); +// } else { +// vreq.setAttribute("rangeOptionsExist",false); +// } +// } + + return editConfiguration; + } + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultPropertyFormGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultPropertyFormGenerator.java deleted file mode 100644 index d32a41506..000000000 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/DefaultPropertyFormGenerator.java +++ /dev/null @@ -1,23 +0,0 @@ -/* $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 javax.servlet.http.HttpSession; - -import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; -import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration; - -/** - * Generates the edit configuration for a default property form. - * - */ -public class DefaultPropertyFormGenerator implements EditConfigurationGenerator { - - @Override - public EditConfiguration getEditConfiguration(VitroRequest vreq, - HttpSession session) { - // TODO Generate a edit conf for the default object property form and return it. - return null; - } - -} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/EditDataPropStmtRequestDispatchController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/EditDataPropStmtRequestDispatchController.java new file mode 100644 index 000000000..92c7dca39 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/EditDataPropStmtRequestDispatchController.java @@ -0,0 +1,216 @@ +package edu.cornell.mannlib.vitro.webapp.edit.n3editing.controller; + +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.http.HttpSession; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import com.hp.hpl.jena.rdf.model.Model; + +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.controller.VitroRequest; +import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet; +import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues; +import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues; +import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; +import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.EditConfigurationGenerator; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.RdfLiteralHash; +import edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils; + +public class EditDataPropStmtRequestDispatchController extends FreemarkerHttpServlet { + + public static Log log = LogFactory.getLog(EditDataPropStmtRequestDispatchController.class); + + final String DEFAULT_DATA_FORM = "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.DefaultDataPropertyFormGenerator"; + final String DEFAULT_ERROR_FORM = "error.jsp"; + + @Override + protected ResponseValues processRequest(VitroRequest vreq) { + + HttpSession session = vreq.getSession(); + if( EditConfiguration.getEditKey( vreq ) == null ){ + vreq.setAttribute("editKey",EditConfiguration.newEditKey(session)); + }else{ + vreq.setAttribute("editKey", EditConfiguration.getEditKey( vreq )); + } + + //set title to Edit to maintain functionality from 1.1.1 and avoid updates to Selenium tests + vreq.setAttribute("title","Edit"); + + String subjectUri = vreq.getParameter("subjectUri"); + String predicateUri = vreq.getParameter("predicateUri"); + String formParam = vreq.getParameter("editForm"); + String command = vreq.getParameter("cmd"); + + + if( subjectUri == null || subjectUri.trim().length() == 0 ) { + log.error("required subjectUri parameter missing"); + return doHelp(vreq, "subjectUri was empty, it is required by EditDataPropStmtRequestDispatchController"); + } + if( predicateUri == null || predicateUri.trim().length() == 0) { + log.error("required subjectUri parameter missing"); + return doHelp(vreq, "predicateUri was empty, it is required by EditDataPropStmtRequestDispatchController"); + } + + // Since we have the URIs let's put the individual, data property, and optional data property statement in the request + vreq.setAttribute("subjectUri", subjectUri); + vreq.setAttribute("subjectUriJson", MiscWebUtils.escape(subjectUri)); + vreq.setAttribute("predicateUri", predicateUri); + vreq.setAttribute("predicateUriJson", MiscWebUtils.escape(predicateUri)); + + WebappDaoFactory wdf = vreq.getWebappDaoFactory(); + + Individual subject = wdf.getIndividualDao().getIndividualByURI(subjectUri); + if( subject == null ) { + log.error("Could not find subject Individual '"+subjectUri+"' in model"); + return doHelp(vreq, "EditDataPropStmtRequestDispatchController: Could not find subject Individual in model: '" + subjectUri + "'"); + } + vreq.setAttribute("subject", subject); + + DataProperty dataproperty = wdf.getDataPropertyDao().getDataPropertyByURI( predicateUri ); + if( dataproperty == null) { + // No dataproperty will be returned for rdfs:label, but we shouldn't throw an error. + // This is controlled by the Jena layer, so we can't change the behavior. + if (! predicateUri.equals(VitroVocabulary.LABEL)) { + log.error("Could not find data property '"+predicateUri+"' in model"); + return doHelp(vreq, "EditDataPropStmtRequestDispatchController: Could not find DataProperty in model: " + predicateUri); + } + } + else { + vreq.setAttribute("predicate", dataproperty); + } + + // Keep track of what form we are using so it can be returned to after a failed validation + // I'd like to get this from the request but sometimes that doesn't work well, internal forwards etc. + //TODO: this needs to be the same as the mapping in web.xml + vreq.setAttribute("formUrl", "/edit/editRequest?" + vreq.getQueryString()); + + String datapropKeyStr = vreq.getParameter("datapropKey"); + int dataHash = 0; + if( datapropKeyStr != null ){ + try { + dataHash = Integer.parseInt(datapropKeyStr); + vreq.setAttribute("datahash", dataHash); + log.debug("Found a datapropKey in parameters and parsed it to int: " + dataHash); + } catch (NumberFormatException ex) { + return doHelp(vreq, "Cannot decode incoming datapropKey value "+datapropKeyStr+" as an integer hash in EditDataPropStmtRequestDispatchController"); + } + } + + DataPropertyStatement dps = null; + if( dataHash != 0) { + Model model = (Model)session.getServletContext().getAttribute("jenaOntModel"); + dps = RdfLiteralHash.getPropertyStmtByHash(subject, predicateUri, dataHash, model); + + if (dps==null) { + log.error("No match to existing data property \""+predicateUri+"\" statement for subject \""+subjectUri+"\" via key "+datapropKeyStr); + //TODO: Needs to forward to dataPropMissingStatement.jsp + return null; + } + vreq.setAttribute("dataprop", dps ); + } + + if( log.isDebugEnabled() ){ + if (dataproperty != null) { + log.debug("predicate for DataProperty from request is " + dataproperty.getURI() + " with rangeDatatypeUri of '" + dataproperty.getRangeDatatypeURI() + "'"); + } + if( dps == null ) + log.debug("no existing DataPropertyStatement statement was found, making a new statemet"); + else{ + log.debug("Found an existing DataPropertyStatement"); + String msg = "existing datapropstmt: "; + msg += " subject uri: <"+dps.getIndividualURI() + ">\n"; + msg += " prop uri: <"+dps.getDatapropURI() + ">\n"; + msg += " prop data: \"" + dps.getData() + "\"\n"; + msg += " datatype: <" + dps.getDatatypeURI() + ">\n"; + msg += " hash of this stmt: " + RdfLiteralHash.makeRdfLiteralHash(dps); + log.debug(msg); + } + } + + +// vreq.setAttribute("preForm", "/edit/formPrefix.jsp"); +// vreq.setAttribute("postForm", "/edit/formSuffix.jsp"); + + if( "delete".equals(command) ){ + //TODO: Needs to forward to dataPropStmtDelete.jsp + return null; + } + + String form = null; + if (formParam != null) { + form = formParam; + } + else if (predicateUri.equals(VitroVocabulary.LABEL)) { // dataproperty is null here + form = "rdfsLabelForm.jsp"; + } + else { + form = dataproperty.getCustomEntryForm(); + if (form != null && form.length()>0) { + log.warn("have a custom form for this data property: "+form); + vreq.setAttribute("hasCustomForm","true"); + } else { + form = DEFAULT_DATA_FORM; + } + } + vreq.setAttribute("form", form); + + if( session.getAttribute("requestedFromEntity") == null ) { + session.setAttribute("requestedFromEntity", subjectUri ); + } + + /**** make the edit configuration ***/ + EditConfiguration editConfig = makeEditConfiguration( form, vreq, session); + + //what template? + String template = editConfig.getTemplate(); + + //what goes in the map for templates? + Map templateData = new HashMap(); + templateData.put("editConfiguration", editConfig); + + return new TemplateResponseValues(editConfig.getTemplate(), templateData); + + } + + + private EditConfiguration makeEditConfiguration( + String editConfGeneratorName, VitroRequest vreq, HttpSession session) { + + EditConfigurationGenerator editConfigurationGenerator = null; + + Object object = null; + try { + Class classDefinition = Class.forName(editConfGeneratorName); + object = classDefinition.newInstance(); + editConfigurationGenerator = (EditConfigurationGenerator) object; + } catch (InstantiationException e) { + System.out.println(e); + } catch (IllegalAccessException e) { + System.out.println(e); + } catch (ClassNotFoundException e) { + System.out.println(e); + } + + if(editConfigurationGenerator == null){ + log.error("could not find editConfigurationGenerator " + editConfGeneratorName); + return null; + } else { + return editConfigurationGenerator.getEditConfiguration(vreq, session); + } + + } + + private ResponseValues doHelp(VitroRequest vreq, String message){ + //output some sort of help message for the developers. + + return null; + } +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/EditRequestDispatchController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/EditRequestDispatchController.java index 40598fc83..ce79c6724 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/EditRequestDispatchController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/EditRequestDispatchController.java @@ -18,6 +18,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.Res import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.EditConfigurationGenerator; import edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils; /** @@ -34,11 +35,12 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet { private static final long serialVersionUID = 1L; public static Log log = LogFactory.getLog(EditRequestDispatchController.class); - final String DEFAULT_OBJ_FORM = "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.DefaultPropertyFormGenerator"; + final String DEFAULT_OBJ_FORM = "edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.DefaultObjectPropertyFormGenerator"; final String DEFAULT_ERROR_FORM = "error.jsp"; final String DEFAULT_ADD_INDIVIDUAL = "defaultAddMissingIndividualForm.jsp"; @Override protected ResponseValues processRequest(VitroRequest vreq) { + try{ WebappDaoFactory wdf = vreq.getWebappDaoFactory(); //get edit key. @@ -127,7 +129,9 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet { if ("delete".equals(command)) { //TODO: delete command is used with the defualt delete form //maybe it doesn't need to be in here? - return null; + HashMap map = new HashMap(); + map.put("errorMessage", "delete command is not yet implemented"); + return new TemplateResponseValues("error-message.ftl", map); } //Certain predicates may be annotated to change the behavior of the edit @@ -146,7 +150,10 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet { // // // <% - return null; + + HashMap map = new HashMap(); + map.put("errorMessage", "skip edit form for object properties is not yet implemented"); + return new TemplateResponseValues("error-message.ftl", map); } //use default object property form if nothing else works @@ -193,21 +200,49 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet { //what template? String template = editConfig.getTemplate(); + String formTitle = (String)vreq.getAttribute("formTitle"); //what goes in the map for templates? Map templateData = new HashMap(); templateData.put("editConfiguration", editConfig); + templateData.put("formTitle", formTitle); - return new TemplateResponseValues(editConfig.getTemplate(), templateData); + return new TemplateResponseValues(template, templateData); + }catch(Throwable th){ + + HashMap map = new HashMap(); + map.put("errorMessage", th.toString()); + log.error(th,th); + return new TemplateResponseValues("error-message.ftl", map); + + } } private EditConfiguration makeEditConfiguration( String editConfGeneratorName, VitroRequest vreq, HttpSession session) { - - //TODO: instianciate generator obj - //TODO: call getEditConfiguration() - - return null; + + EditConfigurationGenerator editConfigurationGenerator = null; + + Object object = null; + try { + Class classDefinition = Class.forName(editConfGeneratorName); + object = classDefinition.newInstance(); + editConfigurationGenerator = (EditConfigurationGenerator) object; + } catch (InstantiationException e) { + System.out.println(e); + } catch (IllegalAccessException e) { + System.out.println(e); + } catch (ClassNotFoundException e) { + System.out.println(e); + } + + if(editConfigurationGenerator == null){ + log.error("could not find editConfigurationGenerator " + editConfGeneratorName); + return null; + } else { + return editConfigurationGenerator.getEditConfiguration(vreq, session); + } + } /* @@ -263,12 +298,15 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet { } //forward to form? - return null; + HashMap map = new HashMap(); + map.put("errorMessage", "forweard to create new is not yet implemented"); + return new TemplateResponseValues("error-message.ftl", map); } private ResponseValues doHelp(VitroRequest vreq, String message){ //output some sort of help message for the developers. - return null; - } + HashMap map = new HashMap(); + map.put("errorMessage", "help is not yet implemented"); + return new TemplateResponseValues("error-message.ftl", map); } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/n3DeleteController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/n3DeleteController.java new file mode 100644 index 000000000..1b23549bc --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/controller/n3DeleteController.java @@ -0,0 +1,75 @@ +package edu.cornell.mannlib.vitro.webapp.edit.n3editing.controller; + +import java.util.ArrayList; +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 com.hp.hpl.jena.rdf.model.Model; + +import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; +import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet; +import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Generator; +import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission; + +/** + * N3 based deletion. + * + * Build up the n3 using the fields from an edit configuration and then remove + * all of those statements from the systems model. In general this should + * do the same thing as an update with processRdfForm2.jsp but it should just + * build the assertions graph and remove that from the system model. + * + */ + +public class n3DeleteController extends FreemarkerHttpServlet { + + private static final long serialVersionUID = 1L; + private static final Log log = LogFactory.getLog(n3DeleteController.class); + + @Override + protected ResponseValues processRequest(VitroRequest vreq){ + + /* the post parameters seem to get consumed by the parsing so + * we have to make a copy. */ + Map queryParameters = null; + queryParameters = vreq.getParameterMap(); + + List errorMessages = new ArrayList(); + + HttpSession session = vreq.getSession(); + EditConfiguration editConfiguration = EditConfiguration.getConfigFromSession(session, vreq); + if(editConfiguration == null){ + //TODO: previously forwarded to noEditConfigFound.jsp + //probably needs to forward to something else now + } + + EditN3Generator n3Subber = editConfiguration.getN3Generator(); + EditSubmission submission = new EditSubmission(queryParameters, editConfiguration); + + Map errors = submission.getValidationErrors(); + EditSubmission.putEditSubmissionInSession(session, submission); + + if(errors != null && !errors.isEmpty()){ + String form = editConfiguration.getFormUrl(); + vreq.setAttribute("formUrl", form); + //TODO: forwards to form. Needs to change + return null; + } + + List requiredAssertionsToDelete = new ArrayList(); + List optionalAssertionsToDelete = new ArrayList(); + + boolean requestIsAValidDelete = editConfiguration.getObject() != null && editConfiguration.getObject().trim().length() > 0; + + + + return null; + } +} diff --git a/webapp/web/templates/freemarker/edit/forms/defaultPropertyForm.ftl b/webapp/web/templates/freemarker/edit/forms/defaultPropertyForm.ftl new file mode 100644 index 000000000..259a8f512 --- /dev/null +++ b/webapp/web/templates/freemarker/edit/forms/defaultPropertyForm.ftl @@ -0,0 +1,19 @@ +

${formTitle}

+ +<#assign form ="/edit/processRdfForm2.jsp"> + +<#assign formUrl ="${form?url}"> + +<#if ${predicate.selectFromExisting} == true> + <#if ${rangeOptionsExist} == true > +
+ <#if predicate.publicDescription??> +

${predicate.publicDescription}

+ +
+ +
+ +
+ +