diff --git a/source/java/org/alfresco/web/bean/content/EditContentPropertiesDialog.java b/source/java/org/alfresco/web/bean/content/EditContentPropertiesDialog.java index 4b65439662..af6e8ae556 100644 --- a/source/java/org/alfresco/web/bean/content/EditContentPropertiesDialog.java +++ b/source/java/org/alfresco/web/bean/content/EditContentPropertiesDialog.java @@ -69,17 +69,16 @@ public class EditContentPropertiesDialog extends BaseDialogBean NodeRef nodeRef = this.editableNode.getNodeRef(); Map editedProps = this.editableNode.getProperties(); - // we deal with 'name' as a rename/move operation later - String name = (String)editedProps.get(ContentModel.PROP_NAME); + // get the name and move the node as necessary + String name = (String) editedProps.get(ContentModel.PROP_NAME); if (name != null) { - editedProps.remove(ContentModel.PROP_NAME); + fileFolderService.rename(nodeRef, name); } // we need to put all the properties from the editable bag back into // the format expected by the repository Map repoProps = this.nodeService.getProperties(nodeRef); - repoProps.remove(ContentModel.PROP_NAME); // but first extract and deal with the special mimetype property for ContentData String mimetype = (String)editedProps.get(TEMP_PROP_MIMETYPE); @@ -182,13 +181,6 @@ public class EditContentPropertiesDialog extends BaseDialogBean } } - // get the name and move the node as necessary - if (name != null) - { - this.fileFolderService.rename(nodeRef, name); - this.editableNode.getProperties().put(ContentModel.PROP_NAME.toString(), name); - } - return outcome; } diff --git a/source/java/org/alfresco/web/bean/spaces/EditSpaceDialog.java b/source/java/org/alfresco/web/bean/spaces/EditSpaceDialog.java index e522a090e9..e4bfa8a3b3 100644 --- a/source/java/org/alfresco/web/bean/spaces/EditSpaceDialog.java +++ b/source/java/org/alfresco/web/bean/spaces/EditSpaceDialog.java @@ -72,16 +72,15 @@ public class EditSpaceDialog extends CreateSpaceDialog NodeRef nodeRef = this.editableNode.getNodeRef(); Map editedProps = this.editableNode.getProperties(); - // we deal with 'name' as a rename/move operation later + // handle the name property separately, perform a rename in case it changed String name = (String)editedProps.get(ContentModel.PROP_NAME); if (name != null) { - editedProps.remove(ContentModel.PROP_NAME); + this.fileFolderService.rename(nodeRef, name); } // get the current set of properties from the repository Map repoProps = this.nodeService.getProperties(nodeRef); - repoProps.remove(ContentModel.PROP_NAME); // add the "uifacets" aspect if required, properties will get set below if (this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_UIFACETS) == false) @@ -164,13 +163,6 @@ public class EditSpaceDialog extends CreateSpaceDialog } } - // get the name and move the node as necessary - if (name != null) - { - this.fileFolderService.rename(nodeRef, name); - this.editableNode.getProperties().put(ContentModel.PROP_NAME.toString(), name); - } - return outcome; } diff --git a/source/java/org/alfresco/web/bean/wcm/EditFilePropertiesDialog.java b/source/java/org/alfresco/web/bean/wcm/EditFilePropertiesDialog.java index a049d8c2cf..3250a13e8e 100644 --- a/source/java/org/alfresco/web/bean/wcm/EditFilePropertiesDialog.java +++ b/source/java/org/alfresco/web/bean/wcm/EditFilePropertiesDialog.java @@ -16,14 +16,23 @@ */ package org.alfresco.web.bean.wcm; +import java.io.Serializable; import java.text.MessageFormat; +import java.util.Iterator; +import java.util.Map; import javax.faces.context.FacesContext; +import org.alfresco.model.ContentModel; import org.alfresco.repo.avm.AVMNodeConverter; import org.alfresco.service.cmr.avm.AVMService; +import org.alfresco.service.cmr.dictionary.DataTypeDefinition; +import org.alfresco.service.cmr.dictionary.PropertyDefinition; import org.alfresco.service.cmr.model.FileExistsException; +import org.alfresco.service.cmr.repository.ContentData; import org.alfresco.service.cmr.repository.InvalidNodeRefException; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.namespace.QName; import org.alfresco.web.app.Application; import org.alfresco.web.bean.content.EditContentPropertiesDialog; import org.alfresco.web.bean.repository.Node; @@ -72,6 +81,87 @@ public class EditFilePropertiesDialog extends EditContentPropertiesDialog return new Node(this.avmBrowseBean.getAvmNode().getNodeRef()); } +@Override + protected String finishImpl(FacesContext context, String outcome) + throws Exception + { + NodeRef nodeRef = this.editableNode.getNodeRef(); + Map editedProps = this.editableNode.getProperties(); + + // handle the name property separately, it is a special case for AVM nodes + String name = (String)editedProps.get(ContentModel.PROP_NAME); + if (name != null) + { + editedProps.remove(ContentModel.PROP_NAME); + } + + // we need to put all the properties from the editable bag back into + // the format expected by the repository + Map repoProps = this.nodeService.getProperties(nodeRef); + + // but first extract and deal with the special mimetype property for ContentData + String mimetype = (String)editedProps.get(TEMP_PROP_MIMETYPE); + if (mimetype != null) + { + // remove temporary prop from list so it isn't saved with the others + editedProps.remove(TEMP_PROP_MIMETYPE); + ContentData contentData = (ContentData)editedProps.get(ContentModel.PROP_CONTENT); + if (contentData != null) + { + contentData = ContentData.setMimetype(contentData, mimetype); + editedProps.put(ContentModel.PROP_CONTENT.toString(), contentData); + } + } + + // add the "titled" aspect if required, properties will get set below + if (this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_TITLED) == false) + { + nodeService.addAspect(nodeRef, ContentModel.ASPECT_TITLED, null); + } + + // add the remaining properties + Iterator iterProps = editedProps.keySet().iterator(); + while (iterProps.hasNext()) + { + String propName = iterProps.next(); + QName qname = QName.createQName(propName); + + // make sure the property is represented correctly + Serializable propValue = (Serializable)editedProps.get(propName); + + // check for empty strings when using number types, set to null in this case + if ((propValue != null) && (propValue instanceof String) && + (propValue.toString().length() == 0)) + { + PropertyDefinition propDef = this.dictionaryService.getProperty(qname); + if (propDef != null) + { + if (propDef.getDataType().getName().equals(DataTypeDefinition.DOUBLE) || + propDef.getDataType().getName().equals(DataTypeDefinition.FLOAT) || + propDef.getDataType().getName().equals(DataTypeDefinition.INT) || + propDef.getDataType().getName().equals(DataTypeDefinition.LONG)) + { + propValue = null; + } + } + } + + repoProps.put(qname, propValue); + } + + // send the properties back to the repository + this.nodeService.setProperties(nodeRef, repoProps); + + // perform the rename last as for an AVM it changes the NodeRef + if (name != null) + { + this.fileFolderService.rename(nodeRef, name); + editedProps.put(ContentModel.PROP_NAME.toString(), name); + } + + return outcome; + } + @Override protected String doPostCommitProcessing(FacesContext context, String outcome) { diff --git a/source/java/org/alfresco/web/bean/wcm/EditFolderPropertiesDialog.java b/source/java/org/alfresco/web/bean/wcm/EditFolderPropertiesDialog.java index c57abfa674..77f4690543 100644 --- a/source/java/org/alfresco/web/bean/wcm/EditFolderPropertiesDialog.java +++ b/source/java/org/alfresco/web/bean/wcm/EditFolderPropertiesDialog.java @@ -16,15 +16,23 @@ */ package org.alfresco.web.bean.wcm; +import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Iterator; import java.util.List; +import java.util.Map; import javax.faces.context.FacesContext; +import org.alfresco.model.ContentModel; import org.alfresco.repo.avm.AVMNodeConverter; import org.alfresco.service.cmr.avm.AVMService; +import org.alfresco.service.cmr.dictionary.DataTypeDefinition; +import org.alfresco.service.cmr.dictionary.PropertyDefinition; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.namespace.QName; import org.alfresco.web.bean.repository.Node; import org.alfresco.web.bean.spaces.EditSpaceDialog; import org.alfresco.web.ui.common.component.UIListItem; @@ -72,6 +80,72 @@ public class EditFolderPropertiesDialog extends EditSpaceDialog return new Node(this.avmBrowseBean.getAvmNode().getNodeRef()); } + @Override + protected String finishImpl(FacesContext context, String outcome) throws Exception + { + // update the existing node in the repository + NodeRef nodeRef = this.editableNode.getNodeRef(); + Map editedProps = this.editableNode.getProperties(); + + // handle the name property separately, it is a special case for AVM nodes + String name = (String)editedProps.get(ContentModel.PROP_NAME); + if (name != null) + { + editedProps.remove(ContentModel.PROP_NAME); + } + + // get the current set of properties from the repository + Map repoProps = this.nodeService.getProperties(nodeRef); + + // add the "uifacets" aspect if required, properties will get set below + if (this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_UIFACETS) == false) + { + this.nodeService.addAspect(nodeRef, ContentModel.ASPECT_UIFACETS, null); + } + + // overwrite the current properties with the edited ones + Iterator iterProps = editedProps.keySet().iterator(); + while (iterProps.hasNext()) + { + String propName = iterProps.next(); + QName qname = QName.createQName(propName); + + // make sure the property is represented correctly + Serializable propValue = (Serializable)editedProps.get(propName); + + // check for empty strings when using number types, set to null in this case + if ((propValue != null) && (propValue instanceof String) && + (propValue.toString().length() == 0)) + { + PropertyDefinition propDef = this.dictionaryService.getProperty(qname); + if (propDef != null) + { + if (propDef.getDataType().getName().equals(DataTypeDefinition.DOUBLE) || + propDef.getDataType().getName().equals(DataTypeDefinition.FLOAT) || + propDef.getDataType().getName().equals(DataTypeDefinition.INT) || + propDef.getDataType().getName().equals(DataTypeDefinition.LONG)) + { + propValue = null; + } + } + } + + repoProps.put(qname, propValue); + } + + // send the properties back to the repository + this.nodeService.setProperties(nodeRef, repoProps); + + // perform the rename last as for an AVM it changes the NodeRef + if (name != null) + { + this.fileFolderService.rename(nodeRef, name); + editedProps.put(ContentModel.PROP_NAME.toString(), name); + } + + return outcome; + } + @Override protected String doPostCommitProcessing(FacesContext context, String outcome) {