mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Merged FORMS-TB3 to HEAD and fix for ALFCOM-2925 (The changes in document's metadata are not applied for 'Author' field)
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@14502 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -39,6 +39,7 @@ import org.alfresco.repo.forms.AssociationFieldDefinition.Direction;
|
||||
import org.alfresco.repo.forms.PropertyFieldDefinition.FieldConstraint;
|
||||
import org.alfresco.repo.jscript.ClasspathScriptLocation;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||
import org.alfresco.service.cmr.repository.AssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ContentData;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
@@ -729,6 +730,10 @@ public class FormServiceImplTest extends BaseAlfrescoSpringTest
|
||||
String newMimetype = MimetypeMap.MIMETYPE_HTML;
|
||||
data.addData("prop_mimetype", newMimetype);
|
||||
|
||||
// update the author property (this is on an aspect not applied)
|
||||
String newAuthor = "Gavin Cornwell";
|
||||
data.addData("prop_cm_author", newAuthor);
|
||||
|
||||
// update the originator
|
||||
String newOriginator = "jane@example.com";
|
||||
data.addData("prop_cm_originator", newOriginator);
|
||||
@@ -740,6 +745,9 @@ public class FormServiceImplTest extends BaseAlfrescoSpringTest
|
||||
// set the date to null (using an empty string)
|
||||
data.addData("prop_cm_sentdate", "");
|
||||
|
||||
// add an association to the child doc (as an attachment which is defined on an aspect not applied)
|
||||
//data.addData("assoc_cm_attachments_added", this.childDoc.toString());
|
||||
|
||||
// try and update non-existent properties (make sure there are no exceptions)
|
||||
data.addData("prop_cm_wrong", "This should not be persisted");
|
||||
data.addData("cm_wrong", "This should not be persisted");
|
||||
@@ -751,6 +759,7 @@ public class FormServiceImplTest extends BaseAlfrescoSpringTest
|
||||
Map<QName, Serializable> updatedProps = this.nodeService.getProperties(this.document);
|
||||
String updatedName = (String)updatedProps.get(ContentModel.PROP_NAME);
|
||||
String updatedTitle = (String)updatedProps.get(ContentModel.PROP_TITLE);
|
||||
String updatedAuthor = (String)updatedProps.get(ContentModel.PROP_AUTHOR);
|
||||
String updatedOriginator = (String)updatedProps.get(ContentModel.PROP_ORIGINATOR);
|
||||
List updatedAddressees = (List)updatedProps.get(ContentModel.PROP_ADDRESSEES);
|
||||
String wrong = (String)updatedProps.get(QName.createQName("cm", "wrong", this.namespaceService));
|
||||
@@ -758,6 +767,7 @@ public class FormServiceImplTest extends BaseAlfrescoSpringTest
|
||||
|
||||
assertEquals(newName, updatedName);
|
||||
assertEquals(newTitle, updatedTitle);
|
||||
assertEquals(newAuthor, updatedAuthor);
|
||||
assertEquals(newOriginator, updatedOriginator);
|
||||
assertNull("Expecting sentdate to be null", sentDate);
|
||||
assertNull("Expecting my:wrong to be null", wrong);
|
||||
@@ -767,6 +777,14 @@ public class FormServiceImplTest extends BaseAlfrescoSpringTest
|
||||
assertEquals(VALUE_ADDRESSEES2, updatedAddressees.get(1));
|
||||
assertEquals(VALUE_ADDRESSEES3, updatedAddressees.get(2));
|
||||
|
||||
// check the titled aspect was automatically applied
|
||||
assertTrue("Expecting the cm:titled to have been applied",
|
||||
this.nodeService.hasAspect(this.document, ContentModel.ASPECT_TITLED));
|
||||
|
||||
// check the author aspect was automatically applied
|
||||
assertTrue("Expecting the cm:author to have been applied",
|
||||
this.nodeService.hasAspect(this.document, ContentModel.ASPECT_AUTHOR));
|
||||
|
||||
// check mimetype was updated
|
||||
ContentData contentData = (ContentData)updatedProps.get(ContentModel.PROP_CONTENT);
|
||||
if (contentData != null)
|
||||
@@ -774,6 +792,16 @@ public class FormServiceImplTest extends BaseAlfrescoSpringTest
|
||||
String updatedMimetype = contentData.getMimetype();
|
||||
assertEquals(MimetypeMap.MIMETYPE_HTML, updatedMimetype);
|
||||
}
|
||||
|
||||
// check the association was added and the aspect it belongs to applied
|
||||
/*
|
||||
List<AssociationRef> assocs = this.nodeService.getTargetAssocs(this.document,
|
||||
ContentModel.ASSOC_ATTACHMENTS);
|
||||
assertEquals("Expecting 1 attachment association", 1, assocs.size());
|
||||
assertEquals(assocs.get(0).getTargetRef().toString(), this.childDoc.toString());
|
||||
assertTrue("Expecting the cm:attachable to have been applied",
|
||||
this.nodeService.hasAspect(this.document, ContentModel.ASPECT_ATTACHABLE));
|
||||
*/
|
||||
}
|
||||
|
||||
public void testNoForm() throws Exception
|
||||
|
@@ -861,6 +861,14 @@ public class NodeHandler extends AbstractHandler
|
||||
|
||||
// ensure that the property being persisted is defined in the model
|
||||
PropertyDefinition propDef = propDefs.get(fullQName);
|
||||
|
||||
// if the property is not defined on the node, check for the property in all models
|
||||
if (propDef == null)
|
||||
{
|
||||
propDef = this.dictionaryService.getProperty(fullQName);
|
||||
}
|
||||
|
||||
// if we have a property definition attempt the persist
|
||||
if (propDef != null)
|
||||
{
|
||||
// look for properties that have well known handling requirements
|
||||
@@ -868,18 +876,6 @@ public class NodeHandler extends AbstractHandler
|
||||
{
|
||||
processNamePropertyPersist(nodeRef, fieldData);
|
||||
}
|
||||
else if (fullQName.equals(ContentModel.PROP_TITLE))
|
||||
{
|
||||
processTitlePropertyPersist(nodeRef, fieldData, propsToPersist);
|
||||
}
|
||||
else if (fullQName.equals(ContentModel.PROP_DESCRIPTION))
|
||||
{
|
||||
processDescriptionPropertyPersist(nodeRef, fieldData, propsToPersist);
|
||||
}
|
||||
else if (fullQName.equals(ContentModel.PROP_AUTHOR))
|
||||
{
|
||||
processAuthorPropertyPersist(nodeRef, fieldData, propsToPersist);
|
||||
}
|
||||
else
|
||||
{
|
||||
Object value = fieldData.getValue();
|
||||
@@ -991,16 +987,23 @@ public class NodeHandler extends AbstractHandler
|
||||
String localName = m.group(2);
|
||||
String assocSuffix = m.group(3);
|
||||
|
||||
QName fullQNameFromJSON = QName.createQName(qNamePrefix, localName, namespaceService);
|
||||
QName fullQName = QName.createQName(qNamePrefix, localName, namespaceService);
|
||||
|
||||
// ensure that the association being persisted is defined in the model
|
||||
AssociationDefinition assocDef = assocDefs.get(fullQNameFromJSON);
|
||||
AssociationDefinition assocDef = assocDefs.get(fullQName);
|
||||
|
||||
// TODO: if the association is not defined on the node, check for the association
|
||||
// in all models, however, the source of an association can be critical so we
|
||||
// can't just look up the association in the model regardless. We need to
|
||||
// either check the source class of the node and the assoc def match or we
|
||||
// check that the association was defined as part of an aspect (where by it's
|
||||
// nature can have any source type)
|
||||
|
||||
if (assocDef == null)
|
||||
{
|
||||
if (logger.isWarnEnabled())
|
||||
{
|
||||
logger.warn("Definition for association " + fullQNameFromJSON + " not recognised and not persisted.");
|
||||
logger.warn("Definition for association " + fullQName + " not recognised and not persisted.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -1021,12 +1024,12 @@ public class NodeHandler extends AbstractHandler
|
||||
if (assocDef.isChild())
|
||||
{
|
||||
assocCommands.add(new AddChildAssocCommand(nodeRef, new NodeRef(nextTargetNode),
|
||||
fullQNameFromJSON));
|
||||
fullQName));
|
||||
}
|
||||
else
|
||||
{
|
||||
assocCommands.add(new AddAssocCommand(nodeRef, new NodeRef(nextTargetNode),
|
||||
fullQNameFromJSON));
|
||||
fullQName));
|
||||
}
|
||||
}
|
||||
else if (assocSuffix.equals(ASSOC_DATA_REMOVED_SUFFIX))
|
||||
@@ -1034,12 +1037,12 @@ public class NodeHandler extends AbstractHandler
|
||||
if (assocDef.isChild())
|
||||
{
|
||||
assocCommands.add(new RemoveChildAssocCommand(nodeRef, new NodeRef(nextTargetNode),
|
||||
fullQNameFromJSON));
|
||||
fullQName));
|
||||
}
|
||||
else
|
||||
{
|
||||
assocCommands.add(new RemoveAssocCommand(nodeRef, new NodeRef(nextTargetNode),
|
||||
fullQNameFromJSON));
|
||||
fullQName));
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1098,63 +1101,6 @@ public class NodeHandler extends AbstractHandler
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Persists the given field data as the title property
|
||||
*
|
||||
* @param nodeRef The NodeRef to update the title for
|
||||
* @param fieldData The data representing the new title value
|
||||
* @param propsToPersist Map of properties to be persisted
|
||||
*/
|
||||
protected void processTitlePropertyPersist(NodeRef nodeRef, FieldData fieldData,
|
||||
Map<QName, Serializable> propsToPersist)
|
||||
{
|
||||
// if a title property is present ensure the 'titled' aspect is applied
|
||||
if (this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_TITLED) == false)
|
||||
{
|
||||
this.nodeService.addAspect(nodeRef, ContentModel.ASPECT_TITLED, null);
|
||||
}
|
||||
|
||||
propsToPersist.put(ContentModel.PROP_TITLE, (String)fieldData.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Persists the given field data as the description property
|
||||
*
|
||||
* @param nodeRef The NodeRef to update the description for
|
||||
* @param fieldData The data representing the new description value
|
||||
* @param propsToPersist Map of properties to be persisted
|
||||
*/
|
||||
protected void processDescriptionPropertyPersist(NodeRef nodeRef, FieldData fieldData,
|
||||
Map<QName, Serializable> propsToPersist)
|
||||
{
|
||||
// if a description property is present ensure the 'titled' aspect is applied
|
||||
if (this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_TITLED) == false)
|
||||
{
|
||||
this.nodeService.addAspect(nodeRef, ContentModel.ASPECT_TITLED, null);
|
||||
}
|
||||
|
||||
propsToPersist.put(ContentModel.PROP_DESCRIPTION, (String)fieldData.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Persists the given field data as the author property
|
||||
*
|
||||
* @param nodeRef The NodeRef to update the author for
|
||||
* @param fieldData The data representing the new author value
|
||||
* @param propsToPersist Map of properties to be persisted
|
||||
*/
|
||||
protected void processAuthorPropertyPersist(NodeRef nodeRef, FieldData fieldData,
|
||||
Map<QName, Serializable> propsToPersist)
|
||||
{
|
||||
// if an author property is present ensure the 'author' aspect is applied
|
||||
if (this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_AUTHOR) == false)
|
||||
{
|
||||
this.nodeService.addAspect(nodeRef, ContentModel.ASPECT_AUTHOR, null);
|
||||
}
|
||||
|
||||
propsToPersist.put(ContentModel.PROP_AUTHOR, (String)fieldData.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Persists the given field data as the mimetype property
|
||||
*
|
||||
|
Reference in New Issue
Block a user