Updates for n3 editing and two stage role person form

This commit is contained in:
hjkhjk54 2011-10-31 21:47:31 +00:00
parent d11c2cfe13
commit c93cecb63c
7 changed files with 93 additions and 48 deletions

View file

@ -212,10 +212,13 @@ public class EditConfigurationUtils {
Map<String, List<Literal>> literalsInScope = editConfig.getLiteralsInScope();
List<String> stringValues = new ArrayList<String>();
List<Literal> literalValues = literalsInScope.get(fieldName);
for(Literal l: literalValues) {
//Could do additional processing here if required, for example if date etc. if need be
stringValues.add(l.getValue().toString());
}
//TODO: Check whether it's correct that literal values would be null?
if(literalValues != null) {
for(Literal l: literalValues) {
//Could do additional processing here if required, for example if date etc. if need be
stringValues.add(l.getValue().toString());
}
}
return stringValues;
}
@ -229,7 +232,10 @@ public class EditConfigurationUtils {
Configuration fmConfig = FreemarkerConfigurationLoader.getConfig(vreq, vreq.getSession().getServletContext());
FieldVTwo field = editConfig == null ? null : editConfig.getField(fieldName);
MultiValueEditSubmission editSub = new MultiValueEditSubmission(vreq.getParameterMap(), editConfig);
MultiValueEditSubmission editSub = EditSubmissionUtils.getEditSubmissionFromSession(vreq.getSession(), editConfig);
//Should we create one if one doesn't exist?
//TODO: Check if one needs to be created if it doesn't exist?
//MultiValueEditSubmission editSub = new MultiValueEditSubmission(vreq.getParameterMap(), editConfig);
if( field != null && field.getEditElement() != null ){
html = field.getEditElement().draw(fieldName, editConfig, editSub, fmConfig);
}

View file

@ -153,7 +153,17 @@ public class EditN3GeneratorVTwo {
}
protected static String subInMultiLiterals(String var, List<Literal>values, String n3){
String tmp = n3;
if (n3==null ) {
log.error("subInMultiLiterals was passed a null n3 String");
return "blankBecauseTargetOrValueWasNull";
}else if( var == null ){
log.warn("subInMultiLiterals was passed a null var name");
return n3;
}else if( values == null ){
log.debug("subInMultiLiterals was passed a null value for var '"+var+"'; returning target: '"+n3+"'");
return n3;
}
String tmp = n3;
//make the multivalue literal string
List<String> n3Values = new ArrayList<String>(values.size());

View file

@ -903,7 +903,8 @@ public abstract class AddRoleToPersonTwoStageGenerator implements EditConfigurat
//Get edit mode
private EditMode getEditMode(VitroRequest vreq) {
String roleToActivityPredicate = getRoleToActivityPredicate(vreq);
EditMode mode = FrontEndEditingUtils.getEditMode(vreq, roleToActivityPredicate);
Individual object = EditConfigurationUtils.getObjectIndividual(vreq);
EditMode mode = FrontEndEditingUtils.getEditMode(vreq, object, roleToActivityPredicate);
return mode;
//(mode == EditMode.ADD || mode == EditMode.REPAIR) ? "\"nonempty\"
}
@ -969,7 +970,7 @@ public abstract class AddRoleToPersonTwoStageGenerator implements EditConfigurat
//Form specific data
public void addFormSpecificData(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
HashMap<String, Object> formSpecificData = new HashMap<String, Object>();
formSpecificData.put("editMode", getEditMode(vreq).name());
formSpecificData.put("editMode", getEditMode(vreq).name().toLowerCase());
//Fields that will need select lists generated
//Store field names
List<String> objectSelect = new ArrayList<String>();

View file

@ -73,7 +73,8 @@ public class PostEditCleanupController extends FreemarkerHttpServlet{
if(configuration == null)
throw new Error("No edit configuration found.");
//get the EditSubmission
//The submission for getting the entity to return to is not retrieved from the session but needs
//to be created - as it is in processRdfForm3.jsp
MultiValueEditSubmission submission = new MultiValueEditSubmission(vreq.getParameterMap(), configuration);
String entityToReturnTo = ProcessRdfForm.processEntityToReturnTo(configuration, submission, vreq);
return doPostEdit(vreq, entityToReturnTo);
@ -88,7 +89,7 @@ public class PostEditCleanupController extends FreemarkerHttpServlet{
EditConfigurationVTwo editConfig = EditConfigurationVTwo.getConfigFromSession(session,vreq);
//In order to support back button resubmissions, don't remove the editConfig from session.
//EditConfiguration.clearEditConfigurationInSession(session, editConfig);
//Here, edit submission is retrieved so it can be cleared out in case it exists
MultiValueEditSubmission editSub = EditSubmissionUtils.getEditSubmissionFromSession(session,editConfig);
EditSubmissionUtils.clearEditSubmissionInSession(session, editSub);

View file

@ -32,28 +32,34 @@ public class FrontEndEditingUtils {
/* Determine whether a property editing form is in add, edit, or repair mode. */
public static EditMode getEditMode(HttpServletRequest request, String relatedPropertyUri) {
EditMode mode = EditMode.ADD;
Individual obj = (Individual)request.getAttribute("object");
if( obj != null){
List<ObjectPropertyStatement> stmts = obj.getObjectPropertyStatements(relatedPropertyUri);
if( stmts != null){
if( stmts.size() > 1 ){
mode = EditMode.ERROR; // Multiple roleIn statements, yuck.
log.debug("Multiple statements found for property " + relatedPropertyUri + ". Setting edit mode to ERROR.");
}else if( stmts.size() == 0 ){
mode = EditMode.REPAIR; // need to repair the role node
log.debug("No statements found for property " + relatedPropertyUri + ". Setting edit mode to REPAIR.");
}else if(stmts.size() == 1 ){
mode = EditMode.EDIT; // editing single statement
log.debug("Single statement found for property " + relatedPropertyUri + ". Setting edit mode to EDIT.");
}
} else {
log.debug("Statements null for property " + relatedPropertyUri + " . Setting edit mode to ADD.");
}
} else {
log.debug("No object. Setting edit mode to ADD.");
}
return mode;
return getEditMode(request, obj, relatedPropertyUri);
}
public static EditMode getEditMode(HttpServletRequest request, Individual obj, String relatedPropertyUri) {
EditMode mode = EditMode.ADD;
if( obj != null){
List<ObjectPropertyStatement> stmts = obj.getObjectPropertyStatements(relatedPropertyUri);
if( stmts != null){
if( stmts.size() > 1 ){
mode = EditMode.ERROR; // Multiple roleIn statements, yuck.
log.debug("Multiple statements found for property " + relatedPropertyUri + ". Setting edit mode to ERROR.");
}else if( stmts.size() == 0 ){
mode = EditMode.REPAIR; // need to repair the role node
log.debug("No statements found for property " + relatedPropertyUri + ". Setting edit mode to REPAIR.");
}else if(stmts.size() == 1 ){
mode = EditMode.EDIT; // editing single statement
log.debug("Single statement found for property " + relatedPropertyUri + ". Setting edit mode to EDIT.");
}
} else {
log.debug("Statements null for property " + relatedPropertyUri + " . Setting edit mode to ADD.");
}
} else {
log.debug("No object. Setting edit mode to ADD.");
}
return mode;
}
}

View file

@ -1,7 +1,26 @@
<#--Assign property-specific variables here-->
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
<#--Two stage form for clinical role-->
<#--
Required Values to be set for each form that includes addRoleToPersonTwoStage.ftl are:
roleDescriptor.
The other required values (roleType, optionsType, objectClassUri, and literalOptions are
set in the JAVA class corresponding to the form, e.g. AddClinicalRoleToPersonGenerator.java.
Optional values can be set, but each of these has default values
set in addRoleToPersonTwoStage.ftl:
buttonText
typeSelectorLabel
numDateFields
showRoleLAbelField
roleExamples-->
<#--Variable assignments for Add Clinical Role To Person-->
<#assign roleDescriptor = "clinical activity" />
<#assign typeSelectorLabel = "clinical activity type" />
<#--Can Also set buttonText for a given form->
<#--Each of the two stage forms will include the form below-->
<#include "addRoleToPersonTwoStage.ftl">

View file

@ -6,7 +6,6 @@
<#assign uriValues = editConfiguration.existingUriValues />
<#assign htmlForElements = editConfiguration.pageData.htmlForElements />
Edit Mode is ${editMode}
<#--Freemarker variables with default values that can be overridden by specific forms-->
@ -40,7 +39,7 @@ Edit Mode is ${editMode}
<#assign titleVerb = "Create"/>
<#assign submitButtonText>${buttonText}</#assign>
<#assign disabledVal = ""/>
<#--The original jsp sets editMode to add, why?-->
<#assign editMode = "add" />
</#if>
<#--Get existing value for specific data literals and uris-->
@ -48,25 +47,23 @@ Edit Mode is ${editMode}
<#--Get selected activity type value if it exists, this is alternative to below-->
<#assign activityTypeValue = ""/>
<#if uriValues?keys?seq_contains("activityType") && uriValues.activityType?size > 0>
<#assign activityTypeValue = uriValues.activityType[0] />
<#if uriValues?keys?seq_contains("roleActivityType") && (uriValues.roleActivityType?size > 0)>
<#assign activityTypeValue = uriValues.roleActivityType[0] />
</#if>
<#--Get activity label value-->
<#assign activityLabelValue = "" />
<#if literalValues?keys?seq_contains("activityLabel") && literalValues.activityLabel?size > 0>
<#if literalValues?keys?seq_contains("activityLabel") && (literalValues.activityLabel?size > 0)>
<#assign activityLabelValue = literalValues.activityLabel[0] />
</#if>
<#--Get role label-->
<#assign roleLabel = "" />
<#if literalValues?keys?seq_contains("roleLabel") && literalValues.roleLabel?size > 0 >
<#if literalValues?keys?seq_contains("roleLabel") && (literalValues.roleLabel?size > 0) >
<#assign roleLabel = literalValues.roleLabel[0] />
</#if>
ActivityLabel:${activityLabelValue}
Activity type: ${activityTypeValue}
<h2>${titleVerb}&nbsp;${roleDescriptor} entry for ${editConfiguration.subjectName}</h2>
@ -94,15 +91,20 @@ Activity type: ${activityTypeValue}
<p class="inline"><label for="typeSelector">${roleDescriptor?capitalize} Type <span class='requiredHint'> *</span></label>
<select id="typeSelector" name="roleActivityType"
<#if disabledVal?has_content>
disabled = ${disabledVal}
disabled = "${disabledVal}"
</#if>
>
<#--Code below allows for selection of first 'select one' option if no activity type selected-->
<#if activityTypeValue?has_content>
<#assign selectedActivityType = activityTypeValue />
<#else>
<#assign selectedActivityType = "" />
</#if>
<#assign roleActivityTypeSelect = editConfiguration.pageData.roleActivityType />
<#assign roleActivityTypeKeys = roleActivityTypeSelect?keys />
<#list roleActivityTypeKeys as key>
<option value="${key}"
<#if activityTypeValue?has_content
&& activityTypeValue = key>selected</#if>
<#if selectedActivityType = key>selected</#if>
>
${roleActivityTypeSelect[key]}
</option>
@ -123,8 +125,8 @@ Activity type: ${activityTypeValue}
</p>
<#if editMode = "edit">
<input type="hidden" id="roleActivityType" name="roleActivityType" value/>
<input type="hidden" id="activityLabel" name="activityLabel"/>
<input type="hidden" id="roleActivityType" name="roleActivityType" value="${activityTypeValue}"/>
<input type="hidden" id="activityLabel" name="activityLabel" value="${activityLabelValue}}"/>
</#if>
<div class="acSelection">
@ -163,7 +165,7 @@ Activity type: ${activityTypeValue}
</div>
<input type="hidden" id="editKey" name="editKey" value="${editKey} />
<p class="submit">
<input type="submit" id="submit" value="submitButtonText"/><span class="or"> or <a class="cancel" href="${cancelUrl}">Cancel</a>
<input type="submit" id="submit" value="${submitButtonText}"/><span class="or"> or <a class="cancel" href="${cancelUrl}">Cancel</a>
</p>
<p id="requiredLegend" class="requiredHint">* required fields</p>
@ -182,7 +184,7 @@ Activity type: ${activityTypeValue}
${stylesheets.add('<link rel="stylesheet" href="${urls.base}/js/jquery-ui/css/smoothness/jquery-ui-1.8.9.custom.css" />')}
${stylesheets.add('<link rel="stylesheet" href="${urls.base}/edit/forms/css/customForm.css" />')}
${stylesheets.add('<link rel="stylesheet" href="${urls.base}/edit/forms/css/customFormWithAutocomplete.cs" />')}
${stylesheets.add('<link rel="stylesheet" href="${urls.base}/edit/forms/css/customFormWithAutocomplete.css" />')}
${scripts.add('<script type="text/javascript" src="${urls.base}/js/jquery-ui/js/jquery-ui-1.8.9.custom.min.js"></script>')}
${scripts.add('<script type="text/javascript" src="${urls.base}/js/customFormUtils.js"></script>')}