MOB-1209: Add ability to pass optional context when generating a form. Also added a sample template to demonstrate a custom set layout.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@15802 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gavin Cornwell
2009-08-18 22:00:23 +00:00
parent f18d83bd0b
commit a07a545df9
8 changed files with 117 additions and 26 deletions

View File

@@ -25,6 +25,7 @@
package org.alfresco.repo.forms;
import java.util.List;
import java.util.Map;
/**
@@ -45,6 +46,17 @@ public interface FormService
*/
public Form getForm(Item item);
/**
* Returns a form representation of the given item,
* all known fields for the item are included.
*
* @param item The item to get a form for
* @param context Map representing optional context that
* can be used during retrieval of the form
* @return The Form representation
*/
public Form getForm(Item item, Map<String, Object> context);
/**
* Returns a form representation of the given item consisting
* only of the given fields.
@@ -57,6 +69,20 @@ public interface FormService
*/
public Form getForm(Item item, List<String> fields);
/**
* Returns a form representation of the given item consisting
* only of the given fields.
*
* @param item The item to get a form for
* @param fields Restricted list of fields to include, null
* indicates all possible fields for the item
* should be included
* @param context Map representing optional context that
* can be used during retrieval of the form
* @return The Form representation
*/
public Form getForm(Item item, List<String> fields, Map<String, Object> context);
/**
* Returns a form representation of the given item consisting
* only of the given fields.
@@ -73,6 +99,24 @@ public interface FormService
*/
public Form getForm(Item item, List<String> fields, List<String> forcedFields);
/**
* Returns a form representation of the given item consisting
* only of the given fields.
*
* @param item The item to get a form for
* @param fields Restricted list of fields to include, null
* indicates all possible fields for the item
* should be included
* @param forcedFields List of field names from 'fields' list
* that should be forcibly included, it is
* up to the form processor implementation
* to determine how to enforce this
* @param context Map representing optional context that
* can be used during retrieval of the form
* @return The Form representation
*/
public Form getForm(Item item, List<String> fields, List<String> forcedFields, Map<String, Object> context);
/**
* Persists the given form representation for the given item.
*

View File

@@ -25,6 +25,7 @@
package org.alfresco.repo.forms;
import java.util.List;
import java.util.Map;
import org.alfresco.repo.forms.processor.FormProcessor;
import org.alfresco.repo.forms.processor.FormProcessorRegistry;
@@ -59,7 +60,15 @@ public class FormServiceImpl implements FormService
*/
public Form getForm(Item item)
{
return getForm(item, null, null);
return getForm(item, null, null, null);
}
/*
* @see org.alfresco.repo.forms.FormService#getForm(org.alfresco.repo.forms.Item, java.util.Map)
*/
public Form getForm(Item item, Map<String, Object> context)
{
return getForm(item, null, null, context);
}
/*
@@ -67,13 +76,29 @@ public class FormServiceImpl implements FormService
*/
public Form getForm(Item item, List<String> fields)
{
return getForm(item, fields, null);
return getForm(item, fields, null, null);
}
/*
* @see org.alfresco.repo.forms.FormService#getForm(org.alfresco.repo.forms.Item, java.util.List, java.util.Map)
*/
public Form getForm(Item item, List<String> fields, Map<String, Object> context)
{
return getForm(item, fields, null, context);
}
/*
* @see org.alfresco.repo.forms.FormService#getForm(org.alfresco.repo.forms.Item, java.util.List, java.util.List)
*/
public Form getForm(Item item, List<String> fields, List<String> forcedFields)
{
return getForm(item, fields, forcedFields, null);
}
/*
* @see org.alfresco.repo.forms.FormService#getForm(org.alfresco.repo.forms.Item, java.util.List, java.util.List, java.util.Map)
*/
public Form getForm(Item item, List<String> fields, List<String> forcedFields, Map<String, Object> context)
{
if (this.processorRegistry == null)
{
@@ -91,7 +116,7 @@ public class FormServiceImpl implements FormService
}
else
{
return processor.generate(item, fields, forcedFields);
return processor.generate(item, fields, forcedFields, context);
}
}

View File

@@ -1034,6 +1034,16 @@ public class FormServiceImplTest extends BaseAlfrescoSpringTest
assertEquals("Expecting 'overwritten' value to be 'three'", "three", value);
}
public void testFormContext() throws Exception
{
Map<String, Object> context = new HashMap<String, Object>(2);
context.put("nodeRef", this.folder);
context.put("name", "Gavin Cornwell");
Form form = this.formService.getForm(new Item(NODE_FORM_ITEM_KIND, this.document.toString()), context);
assertNotNull(form);
}
public void testJavascriptAPI() throws Exception
{
Map<String, Object> model = new HashMap<String, Object>();

View File

@@ -25,6 +25,7 @@
package org.alfresco.repo.forms.processor;
import java.util.List;
import java.util.Map;
import org.alfresco.repo.forms.Form;
import org.alfresco.repo.forms.FormData;
@@ -57,8 +58,11 @@ public interface Filter
* @param fields Restricted list of fields to include
* @param forcedFields List of fields to forcibly include
* @param form The Form object
* @param @param context Map representing optional context that
* can be used during retrieval of the form
*/
public void beforeGenerate(Object item, List<String> fields, List<String> forcedFields, Form form);
public void beforeGenerate(Object item, List<String> fields, List<String> forcedFields,
Form form, Map<String, Object> context);
/**
* Callback used to indicate that a form has just been generated for
@@ -73,8 +77,11 @@ public interface Filter
* @param fields Restricted list of fields to include
* @param forcedFields List of fields to forcibly include
* @param form The Form object
* @param context Map representing optional context that
* can be used during retrieval of the form
*/
public void afterGenerate(Object item, List<String> fields, List<String> forcedFields, Form form);
public void afterGenerate(Object item, List<String> fields, List<String> forcedFields,
Form form, Map<String, Object> context);
/**
* Callback used to indicate that the given form data is about to be

View File

@@ -25,6 +25,7 @@
package org.alfresco.repo.forms.processor;
import java.util.List;
import java.util.Map;
import org.alfresco.repo.forms.Form;
import org.alfresco.repo.forms.FormData;
@@ -56,17 +57,12 @@ public abstract class FilteredFormProcessor extends AbstractFormProcessor
if (logger.isDebugEnabled())
logger.debug("Set filter registry: " + this.filterRegistry + " for processor: " + this);
}
/**
* Generates a Form for the given item.
*
* @see org.alfresco.repo.forms.processor.FormProcessor#generate(org.alfresco.repo.forms.Item, java.util.List, java.util.List)
* @param item The item to generate a form for
* @param fields Restricted list of fields to include
* @param forcedFields List of fields to forcibly include
* @return The generated Form
/*
* @see org.alfresco.repo.forms.processor.FormProcessor#generate(org.alfresco.repo.forms.Item, java.util.List, java.util.List, java.util.Map)
*/
public Form generate(Item item, List<String> fields, List<String> forcedFields)
public Form generate(Item item, List<String> fields, List<String> forcedFields,
Map<String, Object> context)
{
// get the typed object representing the item
Object typedItem = getTypedItem(item);
@@ -79,19 +75,19 @@ public abstract class FilteredFormProcessor extends AbstractFormProcessor
{
for (Filter filter: this.filterRegistry.getFilters())
{
filter.beforeGenerate(typedItem, fields, forcedFields, form);
filter.beforeGenerate(typedItem, fields, forcedFields, form, context);
}
}
// perform the actual generation of the form
internalGenerate(typedItem, fields, forcedFields, form);
internalGenerate(typedItem, fields, forcedFields, form, context);
// inform all regsitered filters the form has been generated
if (this.filterRegistry != null)
{
for (Filter filter: this.filterRegistry.getFilters())
{
filter.afterGenerate(typedItem, fields, forcedFields, form);
filter.afterGenerate(typedItem, fields, forcedFields, form, context);
}
}
@@ -155,8 +151,11 @@ public abstract class FilteredFormProcessor extends AbstractFormProcessor
* @param fields Restricted list of fields to include
* @param forcedFields List of fields to forcibly include
* @param form The form object being generated
* @param context Map representing optional context that
* can be used during retrieval of the form
*/
protected abstract void internalGenerate(Object item, List<String> fields, List<String> forcedFields, Form form);
protected abstract void internalGenerate(Object item, List<String> fields, List<String> forcedFields,
Form form, Map<String, Object> context);
/**
* Persists the form data.

View File

@@ -25,6 +25,7 @@
package org.alfresco.repo.forms.processor;
import java.util.List;
import java.util.Map;
import org.alfresco.repo.forms.Form;
import org.alfresco.repo.forms.FormData;
@@ -67,9 +68,12 @@ public interface FormProcessor
* that should be forcibly included, it is
* up to the form processor implementation
* to determine how to enforce this
* @param context Map representing optional context that
* can be used during retrieval of the form
* @return The Form representation
*/
public Form generate(Item item, List<String> fields, List<String> forcedFields);
public Form generate(Item item, List<String> fields, List<String> forcedFields,
Map<String, Object> context);
/**
* Persists the given object representing the form data

View File

@@ -115,12 +115,13 @@ public class NodeFormProcessor extends ContentModelFormProcessor
return nodeRef;
}
}
/*
* @see org.alfresco.repo.forms.processor.FilteredFormProcessor#internalGenerate(java.lang.Object, java.util.List, java.util.List, org.alfresco.repo.forms.Form)
* @see org.alfresco.repo.forms.processor.FilteredFormProcessor#internalGenerate(java.lang.Object, java.util.List, java.util.List, org.alfresco.repo.forms.Form, java.util.Map)
*/
@Override
protected void internalGenerate(Object item, List<String> fields, List<String> forcedFields, Form form)
protected void internalGenerate(Object item, List<String> fields, List<String> forcedFields,
Form form, Map<String, Object> context)
{
if (logger.isDebugEnabled())
logger.debug("Generating form for: " + item);

View File

@@ -124,12 +124,13 @@ public class TypeFormProcessor extends ContentModelFormProcessor
// return the type definition object for the requested type
return typeDef;
}
/*
* @see org.alfresco.repo.forms.processor.node.NodeFormProcessor#internalGenerate(java.lang.Object, java.util.List, java.util.List, org.alfresco.repo.forms.Form)
* @see org.alfresco.repo.forms.processor.FilteredFormProcessor#internalGenerate(java.lang.Object, java.util.List, java.util.List, org.alfresco.repo.forms.Form, java.util.Map)
*/
@Override
protected void internalGenerate(Object item, List<String> fields, List<String> forcedFields, Form form)
protected void internalGenerate(Object item, List<String> fields, List<String> forcedFields,
Form form, Map<String, Object> context)
{
if (logger.isDebugEnabled())
logger.debug("Generating form for item: " + item);