updates to jsps to use old publication to person generators etc.

This commit is contained in:
hjkhjk54 2011-11-22 21:55:53 +00:00
parent c5743ce2fa
commit 2278d1a365
7 changed files with 446 additions and 13 deletions

View file

@ -0,0 +1,59 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.edit.n3editing;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import com.hp.hpl.jena.rdf.model.Literal;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.N3Validator;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission;
public class PersonHasPublicationValidatorOld implements N3Validator {
private static String MISSING_PUB_TYPE_ERROR = "Must specify a publication type.";
private static String MISSING_PUB_TITLE_ERROR = "Must specify a publication title.";
@Override
public Map<String, String> validate(EditConfiguration editConfig,
EditSubmission editSub) {
Map<String,String> urisFromForm = editSub.getUrisFromForm();
Map<String,Literal> literalsFromForm = editSub.getLiteralsFromForm();
Map<String,String> errors = new HashMap<String,String>();
// If there's a pubUri, then we're done. The other fields are disabled and so don't get submitted.
String pubUri = urisFromForm.get("pubUri");
if (!StringUtils.isEmpty(pubUri)) {
return null;
}
String pubType = urisFromForm.get("pubType");
if ("".equals(pubType)) {
pubType = null;
}
Literal title = literalsFromForm.get("title");
if (title != null) {
String titleValue = title.getLexicalForm();
if (StringUtils.isEmpty(titleValue)) {
title = null;
}
}
if (pubType == null) {
errors.put("pubType", MISSING_PUB_TYPE_ERROR);
}
if (title == null) {
errors.put("title", MISSING_PUB_TITLE_ERROR);
}
return errors.size() != 0 ? errors : null;
}
}

View file

@ -0,0 +1,65 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.edit.n3editing;
import java.util.HashMap;
import java.util.Map;
import com.hp.hpl.jena.rdf.model.Literal;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.N3Validator;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission;
public class PublicationHasAuthorValidatorOld implements N3Validator {
private static String MISSING_FIRST_NAME_ERROR = "Must specify the author's first name.";
private static String MISSING_LAST_NAME_ERROR = "Must specify the author's last name.";
private static String MALFORMED_LAST_NAME_ERROR = "Last name may not contain a comma. Please enter first name in first name field.";
;
@Override
public Map<String, String> validate(EditConfiguration editConfig,
EditSubmission editSub) {
Map<String,String> urisFromForm = editSub.getUrisFromForm();
Map<String,Literal> literalsFromForm = editSub.getLiteralsFromForm();
Map<String,String> errors = new HashMap<String,String>();
String personUri = urisFromForm.get("personUri");
if ("".equals(personUri)) {
personUri = null;
}
// If there's a personUri, then we're done. The firstName and lastName fields are
// disabled and so don't get submitted.
if (personUri != null) {
return null;
}
Literal firstName = literalsFromForm.get("firstName");
if( firstName != null && firstName.getLexicalForm() != null && "".equals(firstName.getLexicalForm()) )
firstName = null;
Literal lastName = literalsFromForm.get("lastName");
String lastNameValue = "";
if (lastName != null) {
lastNameValue = lastName.getLexicalForm();
if( "".equals(lastNameValue) ) {
lastName = null;
}
}
if (lastName == null) {
errors.put("lastName", MISSING_LAST_NAME_ERROR);
// Don't reject space in the last name: de Vries, etc.
} else if (lastNameValue.contains(",")) {
errors.put("lastName", MALFORMED_LAST_NAME_ERROR);
}
if (firstName == null) {
errors.put("firstName", MISSING_FIRST_NAME_ERROR);
}
return errors.size() != 0 ? errors : null;
}
}

View file

@ -29,8 +29,6 @@ public class AddPublicationToPersonGenerator extends VivoBaseGenerator implement
initBasics(editConfiguration, vreq);
initPropertyParameters(vreq, session, editConfiguration);
initObjectPropForm(editConfiguration, vreq);
//Overriding url to return to
setUrlToReturnTo(editConfiguration, vreq);
setVarNames(editConfiguration);
@ -75,12 +73,7 @@ public class AddPublicationToPersonGenerator extends VivoBaseGenerator implement
}
private void setUrlToReturnTo(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
editConfiguration.setUrlPatternToReturnTo(EditConfigurationUtils.getFormUrlWithoutContext(vreq));
}
/***N3 strings both required and optional***/
private List<String> generateN3Optional() {

View file

@ -0,0 +1,316 @@
/* $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 java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.vivoweb.webapp.util.ModelUtils;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.DateTimeWithPrecisionVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.DateTimeIntervalValidationVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
import edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.vocabulary.RDFS;
import com.hp.hpl.jena.vocabulary.RDF;
import com.hp.hpl.jena.vocabulary.XSD;
import com.hp.hpl.jena.ontology.OntModel;
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.VClass;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
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.DisplayVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.RoleToActivityPredicatePreprocessor;
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.SelectListGeneratorVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.FieldVTwo;
import edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils;
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils;
import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils.EditMode;
import edu.cornell.mannlib.vitro.webapp.utils.generators.EditModeUtils;
/**
* Generates the edit configuration for importing concepts from external
* search services, e.g. UMLS etc.
*
* The N3 for this is set with the default settinf of
*
*/
public class AddUserDefinedConceptGenerator extends VivoBaseGenerator implements EditConfigurationGenerator {
private Log log = LogFactory.getLog(AddUserDefinedConceptGenerator.class);
private boolean isObjectPropForm = false;
private String subjectUri = null;
private String predicateUri = null;
private String objectUri = null;
private String datapropKeyStr= null;
private int dataHash = 0;
private DataPropertyStatement dps = null;
private String dataLiteral = null;
private String template = "addUserDefinedConcept.ftl";
private static HashMap<String,String> defaultsForXSDtypes ;
private static String SKOSConceptType = "http://www.w3.org/2004/02/skos/core#Concept";
@Override
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq, HttpSession session) {
EditConfigurationVTwo editConfiguration = new EditConfigurationVTwo();
initBasics(editConfiguration, vreq);
initPropertyParameters(vreq, session, editConfiguration);
initObjectPropForm(editConfiguration, vreq);
editConfiguration.setTemplate(template);
setVarNames(editConfiguration);
//Assumes this is a simple case of subject predicate var
editConfiguration.setN3Required(this.generateN3Required(vreq));
//n3 optional
editConfiguration.setN3Optional(this.generateN3Optional());
//Todo: what do new resources depend on here?
//In original form, these variables start off empty
editConfiguration.setNewResources(generateNewResources(vreq));
//In scope
this.setUrisAndLiteralsInScope(editConfiguration, vreq);
//on Form
this.setUrisAndLiteralsOnForm(editConfiguration, vreq);
editConfiguration.setFilesOnForm(new ArrayList<String>());
//Sparql queries
this.setSparqlQueries(editConfiguration, vreq);
//set fields
setFields(editConfiguration, vreq, EditConfigurationUtils.getPredicateUri(vreq));
setTemplate(editConfiguration, vreq);
//No validators required here
//Add preprocessors
addPreprocessors(editConfiguration, vreq.getWebappDaoFactory());
//Adding additional data, specifically edit mode
addFormSpecificData(editConfiguration, vreq);
//One override for basic functionality, changing url pattern
//and entity
//Adding term should return to this same page, not the subject
//Return takes the page back to the individual form
editConfiguration.setUrlPatternToReturnTo(EditConfigurationUtils.getFormUrlWithoutContext(vreq));
return editConfiguration;
}
private void setVarNames(EditConfigurationVTwo editConfiguration) {
editConfiguration.setVarNameForSubject("subject");
editConfiguration.setVarNameForPredicate("predicate");
editConfiguration.setVarNameForObject("conceptNode");
}
protected void setTemplate(EditConfigurationVTwo editConfiguration,
VitroRequest vreq) {
editConfiguration.setTemplate(template);
}
/*
* N3 Required and Optional Generators as well as supporting methods
*/
private String getPrefixesString() {
//TODO: Include dynamic way of including this
return "@prefix core: <http://vivoweb.org/ontology/core#> .";
}
//Here, the node is typed as a skos concept
private List<String> generateN3Required(VitroRequest vreq) {
return list(
getPrefixesString() + "\n" +
"?subject ?predicate ?conceptNode .\n"
);
}
//Optional b/c user may select an existing SKOS concept
private List<String> generateN3Optional() {
return list(
"?conceptNode <" + VitroVocabulary.RDF_TYPE + "> <" + SKOSConceptType + "> .\n" +
"?conceptNode <" + label + "> ?conceptLabel ."
);
}
/*
* Get new resources
*/
private Map<String, String> generateNewResources(VitroRequest vreq) {
HashMap<String, String> newResources = new HashMap<String, String>();
newResources.put("conceptNode", null);
//There are no new resources here, the concept node uri doesn't
//get created but already exists, and vocab uri should already exist as well
return newResources;
}
/*
* Set URIS and Literals In Scope and on form and supporting methods
*/
private void setUrisAndLiteralsInScope(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
HashMap<String, List<String>> urisInScope = new HashMap<String, List<String>>();
//note that at this point the subject, predicate, and object var parameters have already been processed
//these two were always set when instantiating an edit configuration object from json,
//although the json itself did not specify subject/predicate as part of uris in scope
urisInScope.put(editConfiguration.getVarNameForSubject(),
Arrays.asList(new String[]{editConfiguration.getSubjectUri()}));
urisInScope.put(editConfiguration.getVarNameForPredicate(),
Arrays.asList(new String[]{editConfiguration.getPredicateUri()}));
//Setting inverse role predicate
urisInScope.put("inverseRolePredicate", getInversePredicate(vreq));
editConfiguration.setUrisInScope(urisInScope);
//Uris in scope include subject, predicate, and object var
//literals in scope empty initially, usually populated by code in prepare for update
//with existing values for variables
editConfiguration.setLiteralsInScope(new HashMap<String, List<Literal>>());
}
private List<String> getInversePredicate(VitroRequest vreq) {
List<String> inversePredicateArray = new ArrayList<String>();
ObjectProperty op = EditConfigurationUtils.getObjectProperty(vreq);
if(op != null && op.getURIInverse() != null) {
inversePredicateArray.add(op.getURIInverse());
}
return inversePredicateArray;
}
//n3 should look as follows
//?subject ?predicate ?objectVar
private void setUrisAndLiteralsOnForm(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
List<String> urisOnForm = new ArrayList<String>();
List<String> literalsOnForm = new ArrayList<String>();
//The URI of the node that defines the concept
urisOnForm.add("conceptNode");
//In case the user defines a new concept, will add a concept label
literalsOnForm.add("conceptLabel");
editConfiguration.setLiteralsOnForm(literalsOnForm);
}
/**
* Set SPARQL Queries and supporting methods
*/
private void setSparqlQueries(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
//Sparql queries defining retrieval of literals etc.
editConfiguration.setSparqlForAdditionalLiteralsInScope(new HashMap<String, String>());
Map<String, String> urisInScope = new HashMap<String, String>();
editConfiguration.setSparqlForAdditionalUrisInScope(new HashMap<String, String>());
editConfiguration.setSparqlForExistingLiterals(new HashMap<String, String>());
editConfiguration.setSparqlForExistingUris(new HashMap<String, String>());
}
/**
*
* Set Fields and supporting methods
*/
private void setFields(EditConfigurationVTwo editConfiguration, VitroRequest vreq, String predicateUri) {
setConceptNodeField(editConfiguration, vreq);
setConceptLabelField(editConfiguration, vreq);
}
//this field will be hidden and include the concept node URI
private void setConceptNodeField(EditConfigurationVTwo editConfiguration,
VitroRequest vreq) {
editConfiguration.addField(new FieldVTwo().
setName("conceptNode").
setOptionsType("UNDEFINED"));
}
private void setConceptLabelField(EditConfigurationVTwo editConfiguration,
VitroRequest vreq) {
editConfiguration.addField(new FieldVTwo().
setName("conceptLabel").
setValidators(list("datatype:" + XSD.xstring.toString())).
setRangeDatatypeUri(XSD.xstring.toString())
);
}
//Add preprocessor
private void addPreprocessors(EditConfigurationVTwo editConfiguration, WebappDaoFactory wadf) {
//Will be a completely different type of preprocessor
/*
editConfiguration.addEditSubmissionPreprocessor(
new RoleToActivityPredicatePreprocessor(editConfiguration, wadf));
*/
}
//Form specific data
public void addFormSpecificData(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
HashMap<String, Object> formSpecificData = new HashMap<String, Object>();
formSpecificData.put("sparqlForAcFilter", getSparqlForAcFilter(vreq));
editConfiguration.setFormSpecificData(formSpecificData);
}
public String getSparqlForAcFilter(VitroRequest vreq) {
String subject = EditConfigurationUtils.getSubjectUri(vreq);
String query = "PREFIX core:<" + vivoCore + "> " +
"SELECT ?conceptNode WHERE { " +
"<" + subject + "> ?predicate ?conceptNode ." +
"?conceptNode <" + VitroVocabulary.RDF_TYPE + "> <" + SKOSConceptType + "> . }";
return query;
}
//skos concepts can be added for either research areas or subject areas
//IF coming in from a different form then can get the predicate here as it will be stored
public String getCurrentPredicate(VitroRequest vreq) {
return vreq.getParameter("conceptPredicate");
}
}