mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Script layer impl of form.get
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@12584 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
81
source/java/org/alfresco/repo/forms/script/ScriptForm.java
Normal file
81
source/java/org/alfresco/repo/forms/script/ScriptForm.java
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2008 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.repo.forms.script;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.repo.forms.FieldDefinition;
|
||||
import org.alfresco.repo.forms.FieldGroup;
|
||||
import org.alfresco.repo.forms.Form;
|
||||
import org.alfresco.repo.forms.FormData;
|
||||
|
||||
/**
|
||||
* Form JavaScript Object.
|
||||
*
|
||||
* @author Neil Mc Erlean
|
||||
*/
|
||||
public class ScriptForm implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 579853076546002023L;
|
||||
|
||||
private Form form;
|
||||
|
||||
/* default */ScriptForm(Form formObject)
|
||||
{
|
||||
this.form = formObject;
|
||||
}
|
||||
|
||||
public String getItem()
|
||||
{
|
||||
return form.getItem();
|
||||
}
|
||||
|
||||
public String getType()
|
||||
{
|
||||
return form.getType();
|
||||
}
|
||||
|
||||
public Collection<FieldGroup> getFieldGroups()
|
||||
{
|
||||
return form.getFieldGroups();
|
||||
}
|
||||
|
||||
public Collection<FieldDefinition> getFieldDefinitions()
|
||||
{
|
||||
return form.getFieldDefinitions();
|
||||
}
|
||||
|
||||
public List<String> getFieldDefinitionNames()
|
||||
{
|
||||
return form.getFieldDefinitionNames();
|
||||
}
|
||||
|
||||
public FormData getFormData()
|
||||
{
|
||||
return form.getFormData();
|
||||
}
|
||||
}
|
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2008 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.repo.forms.script;
|
||||
|
||||
import org.alfresco.repo.forms.Form;
|
||||
import org.alfresco.repo.forms.FormService;
|
||||
import org.alfresco.repo.jscript.BaseScopableProcessorExtension;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
|
||||
/**
|
||||
* Script object representing the form service.
|
||||
*
|
||||
* @author Neil McErlean
|
||||
*/
|
||||
public class ScriptFormService extends BaseScopableProcessorExtension
|
||||
{
|
||||
/** Service Registry */
|
||||
private ServiceRegistry serviceRegistry;
|
||||
|
||||
/** The site service */
|
||||
private FormService formService;
|
||||
|
||||
/**
|
||||
* Sets the Service Registry
|
||||
*
|
||||
* @param serviceRegistry
|
||||
*/
|
||||
public void setServiceRegistry(ServiceRegistry serviceRegistry)
|
||||
{
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the form service
|
||||
*
|
||||
* @param formService
|
||||
* the form service
|
||||
*/
|
||||
public void setFormService(FormService formService)
|
||||
{
|
||||
this.formService = formService;
|
||||
}
|
||||
|
||||
public ScriptForm getForm(String item)
|
||||
{
|
||||
Form result = formService.getForm(item);
|
||||
return new ScriptForm(result);
|
||||
}
|
||||
}
|
107
source/java/org/alfresco/repo/forms/script/test_formService.js
Normal file
107
source/java/org/alfresco/repo/forms/script/test_formService.js
Normal file
@@ -0,0 +1,107 @@
|
||||
function testGetFormForContentNode()
|
||||
{
|
||||
// Get a known form and check its various attributes/properties.
|
||||
var form = formService.getForm(testDoc);
|
||||
test.assertNotNull(form, "Form should have been found: " + testDoc);
|
||||
|
||||
test.assertEquals(testDoc, form.getItem());
|
||||
|
||||
test.assertEquals('cm:content', form.getType());
|
||||
|
||||
test.assertNull(form.getFieldGroups());
|
||||
|
||||
var fieldDefs = form.getFieldDefinitions();
|
||||
test.assertNotNull(fieldDefs);
|
||||
test.assertEquals(19, fieldDefs.size());
|
||||
|
||||
var mappedFields = new Array();
|
||||
for (var i = 0; i < fieldDefs.size(); i++)
|
||||
{
|
||||
mappedFields[fieldDefs.get(i).getName()] = fieldDefs.get(i);
|
||||
}
|
||||
var nameField = mappedFields['cm:name'];
|
||||
var titleField = mappedFields['cm:title'];
|
||||
var descField = mappedFields['cm:description'];
|
||||
var originatorField = mappedFields['cm:originator'];
|
||||
var addresseeField = mappedFields['cm:addressee'];
|
||||
var addresseesField = mappedFields['cm:addressees'];
|
||||
var subjectField = mappedFields['cm:subjectline'];
|
||||
var sentDateField = mappedFields['cm:sentdate'];
|
||||
var referencesField = mappedFields['cm:references'];
|
||||
|
||||
test.assertNotNull(nameField, "Expecting to find the cm:name field");
|
||||
test.assertNotNull(titleField, "Expecting to find the cm:title field");
|
||||
test.assertNotNull(descField, "Expecting to find the cm:description field");
|
||||
test.assertNotNull(originatorField, "Expecting to find the cm:originator field");
|
||||
test.assertNotNull(addresseeField, "Expecting to find the cm:addressee field");
|
||||
test.assertNotNull(addresseesField, "Expecting to find the cm:addressees field");
|
||||
test.assertNotNull(subjectField, "Expecting to find the cm:subjectline field");
|
||||
test.assertNotNull(sentDateField, "Expecting to find the cm:sentdate field");
|
||||
test.assertNotNull(referencesField, "Expecting to find the cm:references field");
|
||||
|
||||
// check the labels of all the fields
|
||||
test.assertEquals("Name", nameField.getLabel());
|
||||
test.assertEquals("Title", titleField.getLabel());
|
||||
test.assertEquals("Description", descField.getLabel());
|
||||
test.assertEquals("Originator", originatorField.getLabel());
|
||||
test.assertEquals("Addressee", addresseeField.getLabel());
|
||||
test.assertEquals("Addressees", addresseesField.getLabel());
|
||||
test.assertEquals("Subject", subjectField.getLabel());
|
||||
test.assertEquals("Sent Date", sentDateField.getLabel());
|
||||
test.assertEquals("References", referencesField.getLabel());
|
||||
|
||||
// check details of name field
|
||||
test.assertEquals("d:text", nameField.getDataType());
|
||||
test.assertTrue(nameField.isMandatory());
|
||||
// Expecting cm:name to be single-valued.
|
||||
test.assertFalse(nameField.isRepeating());
|
||||
|
||||
// get the constraint for the name field and check
|
||||
var constraints = nameField.getConstraints();
|
||||
test.assertEquals(1, constraints.size());
|
||||
var constraint = constraints.get(0);
|
||||
test.assertEquals("REGEX", constraint.getType());
|
||||
var params = constraint.getParams();
|
||||
test.assertNotNull(params);
|
||||
test.assertEquals(2, params.length);
|
||||
test.assertNotNull(params["expression"]);
|
||||
test.assertNotNull(params["requiresMatch"]);
|
||||
|
||||
// check details of the addressees field
|
||||
test.assertEquals("d:text", addresseesField.getDataType());
|
||||
test.assertFalse(addresseesField.isMandatory());
|
||||
// Expecting cm:addressees to be multi-valued.
|
||||
test.assertTrue(addresseesField.isRepeating());
|
||||
test.assertNull(addresseesField.getConstraints());
|
||||
|
||||
// check the details of the association field
|
||||
test.assertEquals("cm:content", referencesField.getEndpointType());
|
||||
//TODO Method name typo here "Enpoint"
|
||||
test.assertEquals("TARGET", referencesField.getEnpointDirection().toString());
|
||||
test.assertFalse(referencesField.isEndpointMandatory());
|
||||
test.assertTrue(referencesField.isEndpointMany());
|
||||
|
||||
// check the form data
|
||||
var formData = form.getFormData();
|
||||
test.assertNotNull(formData);
|
||||
var fieldData = formData.getData();
|
||||
test.assertEquals("This is the title for the test document", fieldData["cm:title"].getValue());
|
||||
test.assertEquals("This is the description for the test document", fieldData["cm:description"].getValue());
|
||||
test.assertEquals("fred@customer.com", fieldData["cm:originator"].getValue());
|
||||
test.assertEquals("bill@example.com", fieldData["cm:addressee"].getValue());
|
||||
test.assertEquals("harry@example.com", fieldData["cm:addressees_0"].getValue());
|
||||
test.assertEquals("jane@example.com", fieldData["cm:addressees_1"].getValue());
|
||||
test.assertEquals("The subject is...", fieldData["cm:subjectline"].getValue());
|
||||
|
||||
//TODO Might add the equivalent of the VALUE_SENT_DATE testing here.
|
||||
// In the meantime I'll use JavaScript's own Date object to assert that it is a valid date.
|
||||
var sentDate = fieldData["cm:sentdate"].getValue();
|
||||
test.assertFalse(isNaN(Date.parse(sentDate)));
|
||||
|
||||
var targets = fieldData["cm:references"].getValue();
|
||||
test.assertEquals(1, targets.size());
|
||||
test.assertEquals(testAssociatedDoc, targets.get(0));
|
||||
}
|
||||
|
||||
// Execute tests
|
||||
testGetFormForContentNode();
|
Reference in New Issue
Block a user