diff --git a/source/java/org/alfresco/repo/forms/FormServiceImplTest.java b/source/java/org/alfresco/repo/forms/FormServiceImplTest.java index 22c44741b4..749710a127 100644 --- a/source/java/org/alfresco/repo/forms/FormServiceImplTest.java +++ b/source/java/org/alfresco/repo/forms/FormServiceImplTest.java @@ -37,6 +37,7 @@ import org.alfresco.model.ContentModel; import org.alfresco.repo.content.MimetypeMap; import org.alfresco.repo.forms.AssociationFieldDefinition.Direction; import org.alfresco.repo.forms.PropertyFieldDefinition.FieldConstraint; +import org.alfresco.repo.forms.processor.node.TypeFormProcessor; import org.alfresco.repo.jscript.ClasspathScriptLocation; import org.alfresco.repo.security.authentication.AuthenticationComponent; import org.alfresco.service.cmr.repository.ContentData; @@ -921,7 +922,7 @@ public class FormServiceImplTest extends BaseAlfrescoSpringTest } // supply the destination - data.addFieldData("destination", this.folder.toString()); + data.addFieldData(TypeFormProcessor.DESTINATION, this.folder.toString()); // persist the data NodeRef newNode = (NodeRef)this.formService.saveForm(new Item(TYPE_FORM_ITEM_KIND, "cm:content"), data); @@ -936,6 +937,13 @@ public class FormServiceImplTest extends BaseAlfrescoSpringTest // check the titled aspect was automatically applied assertTrue("Expecting the cm:titled to have been applied", this.nodeService.hasAspect(this.document, ContentModel.ASPECT_TITLED)); + + // test different forms of itemId's + newNode = (NodeRef)this.formService.saveForm(new Item(TYPE_FORM_ITEM_KIND, "cm_content"), data); + assertNotNull("Expected new node to be created using itemId cm_content", newNode); + + newNode = (NodeRef)this.formService.saveForm(new Item(TYPE_FORM_ITEM_KIND, ContentModel.TYPE_CONTENT.toString()), data); + assertNotNull("Expected new node to be created using itemId " + ContentModel.TYPE_CONTENT.toString(), newNode); } public void testNoForm() throws Exception diff --git a/source/java/org/alfresco/repo/forms/processor/node/NodeFormProcessor.java b/source/java/org/alfresco/repo/forms/processor/node/NodeFormProcessor.java index c535ca964c..b3b69acf74 100644 --- a/source/java/org/alfresco/repo/forms/processor/node/NodeFormProcessor.java +++ b/source/java/org/alfresco/repo/forms/processor/node/NodeFormProcessor.java @@ -48,6 +48,7 @@ import org.alfresco.repo.forms.AssociationFieldDefinition.Direction; import org.alfresco.repo.forms.FormData.FieldData; import org.alfresco.repo.forms.PropertyFieldDefinition.FieldConstraint; import org.alfresco.repo.forms.processor.FilteredFormProcessor; +import org.alfresco.service.cmr.dictionary.AspectDefinition; import org.alfresco.service.cmr.dictionary.AssociationDefinition; import org.alfresco.service.cmr.dictionary.ChildAssociationDefinition; import org.alfresco.service.cmr.dictionary.Constraint; @@ -308,20 +309,39 @@ public class NodeFormProcessor extends FilteredFormProcessor // get data dictionary definition for node if it is provided QName type = null; Map propValues = Collections.emptyMap(); + Map propDefs = null; + Map assocDefs = null; if (nodeRef != null) { type = this.nodeService.getType(nodeRef); typeDef = this.dictionaryService.getAnonymousType(type, this.nodeService.getAspects(nodeRef)); + + // NOTE: the anonymous type returns all property and association defs + // for all aspects applied as well as the type + propDefs = typeDef.getProperties(); + assocDefs = typeDef.getAssociations(); propValues = this.nodeService.getProperties(nodeRef); } else { type = typeDef.getName(); - } - - Map propDefs = typeDef.getProperties(); - Map assocDefs = typeDef.getAssociations(); + + // we only get the properties and associations of the actual type so + // we also need to manually get properties and associations from any + // mandatory aspects + propDefs = new HashMap(16); + assocDefs = new HashMap(16); + propDefs.putAll(typeDef.getProperties()); + assocDefs.putAll(typeDef.getAssociations()); + + List aspects = typeDef.getDefaultAspects(true); + for (AspectDefinition aspect : aspects) + { + propDefs.putAll(aspect.getProperties()); + assocDefs.putAll(aspect.getAssociations()); + } + } for (String fieldName : fields) { diff --git a/source/java/org/alfresco/repo/forms/processor/node/TypeFormProcessor.java b/source/java/org/alfresco/repo/forms/processor/node/TypeFormProcessor.java index 5e5fda5e07..e52da7056a 100644 --- a/source/java/org/alfresco/repo/forms/processor/node/TypeFormProcessor.java +++ b/source/java/org/alfresco/repo/forms/processor/node/TypeFormProcessor.java @@ -59,9 +59,10 @@ public class TypeFormProcessor extends NodeFormProcessor /** Logger */ private static Log logger = LogFactory.getLog(TypeFormProcessor.class); - protected static final String DESTINATION = "destination"; protected static final String NAME_PROP_DATA = PROP + DATA_KEY_SEPARATOR + "cm" + DATA_KEY_SEPARATOR + "name"; + public static final String DESTINATION = "alf_destination"; + /* * @see org.alfresco.repo.forms.processor.node.NodeFormProcessor#getTypedItem(org.alfresco.repo.forms.Item) */ @@ -73,8 +74,29 @@ public class TypeFormProcessor extends NodeFormProcessor try { // convert the prefix type into full QName representation - // TODO: Also look for and deal with full QName as itemId - QName type = QName.createQName(item.getId(), this.namespaceService); + // the type name may be provided in the prefix form i.e. + // prefix:type, the : may be replaced with _ if the item id + // was passed on a URL or the full qname may be provided. + QName type = null; + String itemId = item.getId(); + if (itemId.startsWith("{")) + { + // item id looks like a full qname + type = QName.createQName(itemId); + } + else if (itemId.indexOf("_") != -1) + { + // if item id contains _ change the first occurrence to : + // as it's more than likely been converted for URL use + int idx = itemId.indexOf("_"); + String parsedItemId = itemId.substring(0, idx) + ":" + itemId.substring(idx+1); + type = QName.createQName(parsedItemId, this.namespaceService); + } + else + { + // try and create the QName using the item id as is + type = QName.createQName(itemId, this.namespaceService); + } // retrieve the type from the dictionary typeDef = this.dictionaryService.getType(type); @@ -246,7 +268,7 @@ public class TypeFormProcessor extends NodeFormProcessor { throw new FormException("Failed to persist form for '" + typeDef.getName().toPrefixString(this.namespaceService) + - "' as destination data was not present."); + "' as '" + DESTINATION + "' data was not provided."); } // create the parent NodeRef