NIHVIVO-238 - Updating custom reports and site configuration sections of vitro site admin to remove datastar-specific changes. Preventing past expected publication date (datastar-215), Autopopulating dataset originator with person info (datastar-304), Updates to Model preprocess related to dataset-304

This commit is contained in:
hjk54 2010-03-26 19:00:48 +00:00
parent 5b6ee59e77
commit 61a64faf40
12 changed files with 116 additions and 36 deletions

View file

@ -151,6 +151,8 @@ public class FedoraDatastreamController extends VitroHttpServlet implements Cons
IndividualDao iwDao = vreq.getWebappDaoFactory().getIndividualDao();
Individual entity = iwDao.getIndividualByURI(fileUri);
if( entity == null )
throw new FdcException( "No entity found in system for file uri " + fileUri);
//System.out.println("Entity == null:" + (entity == null));

View file

@ -74,11 +74,15 @@ public class BasicValidation {
if( validations != null ){
// NB this is case-sensitive
boolean isRequiredField = validations.contains("nonempty");
for( String validationType : validations){
String value = null;
try{
if( literal != null )
if( literal != null ){
value = literal.getString();
System.out.println("get data type uri " + literal.asNode().getLiteralDatatype().getURI());
}
}catch(Throwable th){
log.debug("could not convert literal to string" , th);
}
@ -92,6 +96,7 @@ public class BasicValidation {
}
break;
}
String validateMsg = validate(validationType, value);
if( validateMsg != null) {
errors.put(name,validateMsg);
@ -149,7 +154,8 @@ public class BasicValidation {
return SUCCESS;
else
return "must be in valid date format mm/dd/yyyy.";
}else if( validationType.indexOf("datatype:") == 0 ) {
}
else if( validationType.indexOf("datatype:") == 0 ) {
String datatypeURI = validationType.substring(9);
String errorMsg = validateAgainstDatatype( value, datatypeURI );
if ( errorMsg == null ) {
@ -157,6 +163,34 @@ public class BasicValidation {
} else {
return errorMsg;
}
}
//Date not past validation
if( "dateNotPast".equalsIgnoreCase(validationType)){
System.out.println("date not past - Value " + value);
//if( ! past (value) )
// return "date must not be in the past";
//Current date
Calendar c = Calendar.getInstance();
//Input
Calendar inputC = Calendar.getInstance();
String yearParamStr, monthParamStr, dayParamStr;
int yearDash = value.indexOf("-");
int monthDash = value.lastIndexOf("-");
if(yearDash != -1 && yearDash != monthDash) {
yearParamStr = value.substring(0, yearDash);
monthParamStr = value.substring(yearDash + 1, monthDash);
dayParamStr = value.substring(monthDash + 1, value.length());
System.out.println("Year param str " + yearParamStr + " - MonthPAram:" + monthParamStr + " - day:" + dayParamStr);
inputC.set(Integer.parseInt(yearParamStr), Integer.parseInt(monthParamStr) - 1, Integer.parseInt(dayParamStr));
if(inputC.before(c)) {
return this.DATE_NOT_PAST_MSG;
//Returning null makes the error message "field is empty" display instead
//return null;
} else {
return SUCCESS;
}
}
}
return null; //
}
@ -214,7 +248,7 @@ public class BasicValidation {
/** we use null to indicate success */
public final static String SUCCESS = null;
public final static String REQUIRED_FIELD_EMPTY_MSG = "This field must not be empty.";
public final static String DATE_NOT_PAST_MSG = "Please enter a future target date for publication (past dates are invalid).";
/** regex for strings like "12/31/2004" */
private final String dateRegex = "((1[012])|([1-9]))/((3[10])|([12][0-9])|([1-9]))/[\\d]{4}";
private final Pattern datePattern = Pattern.compile(dateRegex);
@ -222,7 +256,7 @@ public class BasicValidation {
static final List<String> basicValidations;
static{
basicValidations = Arrays.asList(
"nonempty","isDate" );
"nonempty","isDate","dateNotPast" );
}
private Log log = LogFactory.getLog(BasicValidation.class);

View file

@ -4,6 +4,7 @@ package edu.cornell.mannlib.vitro.webapp.edit.n3editing;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
import javax.servlet.http.HttpServletRequest;
/**
* This will remove old relation triple for an edit.
@ -22,7 +23,7 @@ public class DefaultAddMissingIndividualFormModelPreprocessor implements
this.objectUri = objectUri;
}
public void preprocess( Model retractionsModel, Model additionsModel) {
public void preprocess( Model retractionsModel, Model additionsModel, HttpServletRequest r) {
if( retractionsModel == null || additionsModel == null)
return;

View file

@ -251,12 +251,15 @@ public class EditConfiguration {
UserToIndIdentifierFactory.getIndividualsForUser(ids);
if( userUris == null || userUris.size() == 0 ){
System.out.println("Cound not find user ur for edit request");
log.error("Could not find a userUri for edit request, make " +
"sure that there is an IdentifierBundleFactory that " +
"produces userUri identifiers in the context.");
} else if( userUris.size() > 1 ){
log.error("Found multiple userUris, using the first in list.");
System.out.println("Found multiple user uris");
}else {
System.out.println("EditConfiguration.java - checking system value for User URI " + userUris.get(0));
getUrisInScope().put("editingUser",userUris.get(0));
}
}

View file

@ -8,6 +8,7 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Calendar;
import javax.servlet.http.HttpSession;
@ -46,7 +47,6 @@ public class EditSubmission {
}
public EditSubmission(Map<String,String[]> queryParameters, EditConfiguration editConfig){
if( editConfig == null )
throw new Error("EditSubmission needs an EditConfiguration");
this.editKey = editConfig.getEditKey();
@ -70,7 +70,6 @@ public class EditSubmission {
log.debug("No value found for query parameter " + var);
}
}
this.literalsFromForm =new HashMap<String,Literal>();
for(String var: editConfig.getLiteralsOnForm() ){
Field field = editConfig.getField(var);
@ -126,6 +125,8 @@ public class EditSubmission {
if( errors != null ) {
validationErrors.putAll( errors);
}
}
public EditSubmission(Map<String, String[]> queryParameters, EditConfiguration editConfig,
@ -156,7 +157,7 @@ public class EditSubmission {
* "2008-03-14T00:00:00"^^<http://www.w3.org/2001/XMLSchema#dateTime>
*/
public Literal getDateTime(Map<String,String[]> queryParameters,String fieldName){
DateTime dt = null;
DateTime dt = null;
List<String> year = Arrays.asList(queryParameters.get("year"+ fieldName));
List<String> month = Arrays.asList(queryParameters.get("month" + fieldName));
List<String> day = Arrays.asList(queryParameters.get("day" + fieldName));
@ -301,9 +302,36 @@ public class EditSubmission {
return null;
}
//Removing this
/*
boolean compareCurrentDate = false;
String[] dateNotPastArgs = queryParameters.get("validDateParam");
if(dateNotPastArgs != null && dateNotPastArgs.length > 0) {
compareCurrentDate = (dateNotPastArgs[0].equals("dateNotPast"));
}*/
try{
dt = dateFormater.parseDateTime(year.get(0) +'-'+ month.get(0) +'-'+ day.get(0));
String dateStr = dateFormater.print(dt);
/*if(compareCurrentDate) {
Calendar c = Calendar.getInstance();
//Set to last year
int currentYear = c.get(Calendar.YEAR);
//?Set to time starting at 00 this morning?
Calendar inputC = Calendar.getInstance();
inputC.set(Integer.parseInt(yearParamStr), Integer.parseInt(monthParamStr) - 1, Integer.parseInt(dayParamStr));
//if input time is more than a year ago
if(inputC.before(c)) {
errors += "Please enter a future target date for publication (past dates are invalid).";
validationErrors.put( fieldName, errors);
//Returning null makes the error message "field is empty" display instead
//return null;
}
}*/
return new EditLiteral(dateStr,DATE_URI, null );
}catch(IllegalFieldValueException ifve){
validationErrors.put( fieldName, ifve.getLocalizedMessage() );

View file

@ -4,8 +4,10 @@ package edu.cornell.mannlib.vitro.webapp.edit.n3editing;
import com.hp.hpl.jena.rdf.model.Model;
import javax.servlet.http.HttpServletRequest;
public interface ModelChangePreprocessor {
public abstract void preprocess ( Model retractionsModel, Model additionsModel );
public abstract void preprocess ( Model retractionsModel, Model additionsModel, HttpServletRequest request );
}

View file

@ -305,6 +305,7 @@ public class InputElementFormattingTag extends TagSupport {
Map<String,String> errors = editSub.getValidationErrors();
if( errors == null || errors.isEmpty())
return "";
String val = errors.get(getId());
if( val != null){
return val;
@ -340,7 +341,6 @@ public class InputElementFormattingTag extends TagSupport {
/* populate the pieces */
String classStr = doClass();
String errorStr = getValidationErrors(editSub);
JspWriter out = pageContext.getOut();
boolean definitionTags = false; // current default
@ -355,12 +355,15 @@ public class InputElementFormattingTag extends TagSupport {
}
Field field = editConfig == null ? null : editConfig.getField(getId());
if( getType().equalsIgnoreCase("date") ||
(field != null && field.getRangeDatatypeUri() != null && field.getRangeDatatypeUri().equals(XSD.date.getURI())) ){
//if its a dataprop that should be a string override type and use date picker
if (definitionTags) { out.print("<dg>"); }
out.print( generateHtmlForDate(getId(),editConfig,editSub) );
if (definitionTags) { out.print("</dg>"); }
} else if ( getType().equalsIgnoreCase("time") ||
(field != null && field.getRangeDatatypeUri() != null && field.getRangeDatatypeUri().equals(XSD.time.getURI())) ) {
if (definitionTags) { out.print("<dd>"); }
@ -636,14 +639,14 @@ public class InputElementFormattingTag extends TagSupport {
}
}else{
//try to get default value
System.out.println("Trying to get the default value");
Field field = editConfig.getField(fieldName);
List<List<String>> options = field.getLiteralOptions();
if( options.size() >=1 && options.get(0) != null &&
options.get(0).size() >= 1 && options.get(0).get(0) != null){
dateStrFromLit = options.get(0).get(0);
}else{
System.out.println("No default value found for field " + fieldName);
log.debug("no default found for field " + fieldName);
}
}
@ -680,7 +683,7 @@ public class InputElementFormattingTag extends TagSupport {
}
String sb = "";
sb += " <div class=\"inlineForm\" id=\"textdate"+fieldName+"\"> \n";
sb += " <label for=\"year"+fieldName+"\">year</label> \n";
sb += " <input type=\"text\" size=\"4\" id=\"year"+fieldName+"\" "+ "name=\"year"+fieldName+"\" maxlength=\"4\" value=\"" + ((year != 0) ? year : "") + "\"/>\n";
@ -737,6 +740,10 @@ public class InputElementFormattingTag extends TagSupport {
sb += " <option value=\"31\" "+(day == 31?SELECTED:"")+">31</option> \n";
sb += " </select> \n";
sb += "</div> \n";
if(fieldName.equals("expectedPublicationDateEdited")) {
sb += "<input type='hidden' id='validDateParam' name='validDateParam' value='dateNotPast'/>";
}
return sb;
}
@ -744,7 +751,7 @@ public class InputElementFormattingTag extends TagSupport {
public String generateHtmlForTime(String fieldName,
EditConfiguration editConfig, EditSubmission editSub ) {
DateTime dt = null;
int hour = -1;
int minute = -1;
@ -933,7 +940,7 @@ public class InputElementFormattingTag extends TagSupport {
public String generateHtmlForDateTime(String fieldName,
EditConfiguration editConfig, EditSubmission editSub ){
DateTime dt = null;
DateTime dt = null;
if( editSub != null && editSub.getLiteralsFromForm() != null &&
editSub.getLiteralsFromForm().get(fieldName) != null ){
//found the field on the EditSubmission
@ -1028,7 +1035,7 @@ public class InputElementFormattingTag extends TagSupport {
hour = dt.getHourOfDay();
minute = dt.getMinuteOfHour();
}
String sb = "";
sb += " <div class=\"inlineForm\" id=\"textdate"+fieldName+"\"> \n";
@ -1087,9 +1094,9 @@ public class InputElementFormattingTag extends TagSupport {
sb += " <option value=\"31\" "+(day == 31?SELECTED:"")+">31</option> \n";
sb += " </select> \n";
sb += " \n";
sb += generateMarkupForTime(fieldName, hour, minute);
sb += "</div> \n";
return sb;