From d3a6eb447fd11d85f36a286e0a0fe064e62b9f29 Mon Sep 17 00:00:00 2001 From: Gavin Cornwell Date: Thu, 18 May 2006 21:02:07 +0000 Subject: [PATCH] - fixed issues with editing spaces - made topic pages consistent with 1.2 - added ability to force properties to render even if they are not present in the node - changed warnings about missing properties to debug but added a log label to turn it on easily git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2922 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../alfresco/web-client-config-properties.xml | 28 +++++++----- config/alfresco/web-client-config.xml | 2 - .../content/EditContentPropertiesDialog.java | 45 +++++++------------ .../web/bean/generator/LabelGenerator.java | 3 +- .../web/bean/spaces/EditSpaceDialog.java | 12 +++-- .../config/PropertySheetConfigElement.java | 38 +++++++++++----- .../config/PropertySheetElementReader.java | 6 ++- .../web/config/WebClientConfigTest.java | 4 +- .../component/property/PropertySheetItem.java | 37 ++++++++++++++- .../repo/component/property/UIProperty.java | 11 +++-- .../component/property/UIPropertySheet.java | 1 + .../test-resources/test-config-override.xml | 2 +- source/test-resources/test-config.xml | 3 +- source/web/jsp/forums/create-topic-dialog.jsp | 15 +------ 14 files changed, 127 insertions(+), 80 deletions(-) diff --git a/config/alfresco/web-client-config-properties.xml b/config/alfresco/web-client-config-properties.xml index ab99cb3aee..762489503e 100644 --- a/config/alfresco/web-client-config-properties.xml +++ b/config/alfresco/web-client-config-properties.xml @@ -5,21 +5,28 @@ - - + + + - - - + + + @@ -27,7 +34,7 @@ - @@ -36,16 +43,15 @@ - - - - + diff --git a/config/alfresco/web-client-config.xml b/config/alfresco/web-client-config.xml index d8c5757dc7..441149f6f9 100644 --- a/config/alfresco/web-client-config.xml +++ b/config/alfresco/web-client-config.xml @@ -175,7 +175,6 @@ - @@ -196,7 +195,6 @@ - diff --git a/source/java/org/alfresco/web/bean/content/EditContentPropertiesDialog.java b/source/java/org/alfresco/web/bean/content/EditContentPropertiesDialog.java index 297c371363..13f864b46c 100644 --- a/source/java/org/alfresco/web/bean/content/EditContentPropertiesDialog.java +++ b/source/java/org/alfresco/web/bean/content/EditContentPropertiesDialog.java @@ -2,7 +2,6 @@ package org.alfresco.web.bean.content; import java.io.Serializable; import java.text.MessageFormat; -import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -60,66 +59,54 @@ public class EditContentPropertiesDialog extends BaseDialogBean throws Exception { NodeRef nodeRef = this.browseBean.getDocument().getNodeRef(); - Map props = this.editableNode.getProperties(); + Map editedProps = this.editableNode.getProperties(); // get the name and move the node as necessary - String name = (String) props.get(ContentModel.PROP_NAME); + String name = (String) editedProps.get(ContentModel.PROP_NAME); if (name != null) { fileFolderService.rename(nodeRef, name); } - Map properties = this.nodeService.getProperties(nodeRef); + Map repoProps = this.nodeService.getProperties(nodeRef); // we need to put all the properties from the editable bag back into // the format expected by the repository // but first extract and deal with the special mimetype property for ContentData - String mimetype = (String)props.get(TEMP_PROP_MIMETYPE); + String mimetype = (String)editedProps.get(TEMP_PROP_MIMETYPE); if (mimetype != null) { // remove temporary prop from list so it isn't saved with the others - props.remove(TEMP_PROP_MIMETYPE); - ContentData contentData = (ContentData)props.get(ContentModel.PROP_CONTENT); + editedProps.remove(TEMP_PROP_MIMETYPE); + ContentData contentData = (ContentData)editedProps.get(ContentModel.PROP_CONTENT); if (contentData != null) { contentData = ContentData.setMimetype(contentData, mimetype); - props.put(ContentModel.PROP_CONTENT.toString(), contentData); + editedProps.put(ContentModel.PROP_CONTENT.toString(), contentData); } } - // extra and deal with the Author prop if the aspect has not been applied yet - String author = (String)props.get(ContentModel.PROP_AUTHOR); - if (author != null && author.length() != 0) + // add the "author" aspect if required, properties will get set below + if (this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_AUTHOR) == false) { - // add aspect if required - if (this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_AUTHOR) == false) - { - Map authorProps = new HashMap(1, 1.0f); - authorProps.put(ContentModel.PROP_AUTHOR, author); - this.nodeService.addAspect(nodeRef, ContentModel.ASPECT_AUTHOR, authorProps); - } - // else it will get updated in the later setProperties() call + this.nodeService.addAspect(nodeRef, ContentModel.ASPECT_AUTHOR, null); } - // deal with adding the "titled" aspect if required - String title = (String)props.get(ContentModel.PROP_TITLE); - String description = (String)props.get(ContentModel.PROP_DESCRIPTION); - if (title != null || description != null) + // add the "titled" aspect if required, properties will get set below + if (this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_TITLED) == false) { - // add the aspect to be sure it's present nodeService.addAspect(nodeRef, ContentModel.ASPECT_TITLED, null); - // props will get added later in setProperties() } // add the remaining properties - Iterator iterProps = props.keySet().iterator(); + 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)props.get(propName); + 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) && @@ -138,11 +125,11 @@ public class EditContentPropertiesDialog extends BaseDialogBean } } - properties.put(qname, propValue); + repoProps.put(qname, propValue); } // send the properties back to the repository - this.nodeService.setProperties(this.browseBean.getDocument().getNodeRef(), properties); + this.nodeService.setProperties(nodeRef, repoProps); // we also need to persist any association changes that may have been made diff --git a/source/java/org/alfresco/web/bean/generator/LabelGenerator.java b/source/java/org/alfresco/web/bean/generator/LabelGenerator.java index 69a3c3b50f..6cb4b7a716 100644 --- a/source/java/org/alfresco/web/bean/generator/LabelGenerator.java +++ b/source/java/org/alfresco/web/bean/generator/LabelGenerator.java @@ -28,8 +28,7 @@ public class LabelGenerator extends BaseComponentGenerator // add the component to the property sheet item item.getChildren().add(component); - // TODO: Turn the label red if the field is required - // setup the 'for' attribute to associate with it the control + // TODO: setup the 'for' attribute to associate with it the control return component; } diff --git a/source/java/org/alfresco/web/bean/spaces/EditSpaceDialog.java b/source/java/org/alfresco/web/bean/spaces/EditSpaceDialog.java index 49bb6dfd0d..048c132ba3 100644 --- a/source/java/org/alfresco/web/bean/spaces/EditSpaceDialog.java +++ b/source/java/org/alfresco/web/bean/spaces/EditSpaceDialog.java @@ -31,7 +31,7 @@ public class EditSpaceDialog extends CreateSpaceDialog super.init(parameters); // setup the space being edited - this.editableNode = this.browseBean.getActionSpace(); + this.editableNode = new Node(this.browseBean.getActionSpace().getNodeRef()); this.spaceType = this.editableNode.getType().toString(); } @@ -55,7 +55,7 @@ public class EditSpaceDialog extends CreateSpaceDialog protected String finishImpl(FacesContext context, String outcome) throws Exception { // update the existing node in the repository - NodeRef nodeRef = this.editableNode.getNodeRef(); + NodeRef nodeRef = this.browseBean.getActionSpace().getNodeRef(); Map editedProps = this.editableNode.getProperties(); // handle the name property separately, perform a rename in case it changed @@ -68,6 +68,12 @@ public class EditSpaceDialog extends CreateSpaceDialog // 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()) @@ -149,7 +155,7 @@ public class EditSpaceDialog extends CreateSpaceDialog @Override protected String doPostCommitProcessing(FacesContext context, String outcome) { - this.editableNode.reset(); + this.browseBean.getActionSpace().reset(); return outcome; } diff --git a/source/java/org/alfresco/web/config/PropertySheetConfigElement.java b/source/java/org/alfresco/web/config/PropertySheetConfigElement.java index 59a669b10d..5b556071fe 100644 --- a/source/java/org/alfresco/web/config/PropertySheetConfigElement.java +++ b/source/java/org/alfresco/web/config/PropertySheetConfigElement.java @@ -139,13 +139,16 @@ public class PropertySheetConfigElement extends ConfigElementAdapter * sheet is in view mode * @param inEdit Sets whether the property should be shown when the property * sheet is in edit mode - * @parm compGenerator The name of a bean that can be used as a component generator + * @param compGenerator The name of a bean that can be used as a component generator + * @param ignoreIfMissing Sets whether the property should be rendered if it is not + * found in the data dictionary or the node itself */ /*package*/ void addProperty(String name, String displayLabel, String displayLabelId, String readOnly, - String converter, String inView, String inEdit, String compGenerator) + String converter, String inView, String inEdit, String compGenerator, + String ignoreIfMissing) { addItem(new PropertyConfig(name, displayLabel, displayLabelId, Boolean.parseBoolean(readOnly), - converter, inView, inEdit, compGenerator)); + converter, inView, inEdit, compGenerator, ignoreIfMissing)); } /** @@ -160,7 +163,7 @@ public class PropertySheetConfigElement extends ConfigElementAdapter * sheet is in view mode * @param inEdit Sets whether the property should be shown when the property * sheet is in edit mode - * @parm compGenerator The name of a bean that can be used as a component generator + * @param compGenerator The name of a bean that can be used as a component generator */ /*package*/ void addAssociation(String name, String displayLabel, String displayLabelId, String readOnly, String converter, String inView, String inEdit, String compGenerator) @@ -181,7 +184,7 @@ public class PropertySheetConfigElement extends ConfigElementAdapter * sheet is in view mode * @param inEdit Sets whether the property should be shown when the property * sheet is in edit mode - * @parm compGenerator The name of a bean that can be used as a component generator + * @param compGenerator The name of a bean that can be used as a component generator */ /*package*/ void addChildAssociation(String name, String displayLabel, String displayLabelId, String readOnly, String converter, String inView, String inEdit, String compGenerator) @@ -257,10 +260,11 @@ public class PropertySheetConfigElement extends ConfigElementAdapter private boolean readOnly; private boolean showInViewMode = true; private boolean showInEditMode = true; + private boolean ignoreIfMissing = true; public ItemConfig(String name, String displayLabel, String displayLabelId, boolean readOnly, String converter, String inView, String inEdit, - String compGenerator) + String compGenerator, String ignoreIfMissing) { this.name = name; this.displayLabel = displayLabel; @@ -277,6 +281,10 @@ public class PropertySheetConfigElement extends ConfigElementAdapter { this.showInEditMode = Boolean.parseBoolean(inEdit); } + if (ignoreIfMissing != null) + { + this.ignoreIfMissing = Boolean.parseBoolean(ignoreIfMissing); + } } /** @@ -343,6 +351,15 @@ public class PropertySheetConfigElement extends ConfigElementAdapter return this.componentGenerator; } + /** + * @return Whether the property should be rendered if it is not found in the + * data dictionary or the node itself. + */ + public boolean getIgnoreIfMissing() + { + return this.ignoreIfMissing; + } + /** * @see java.lang.Object#toString() */ @@ -356,6 +373,7 @@ public class PropertySheetConfigElement extends ConfigElementAdapter buffer.append(" read-only=").append(this.readOnly); buffer.append(" show-in-view-mode=").append(this.showInViewMode); buffer.append(" show-in-edit-mode=").append(this.showInEditMode); + buffer.append(" ignore-if-missing=").append(this.ignoreIfMissing); buffer.append(" component-generator=").append(this.componentGenerator).append(")"); return buffer.toString(); } @@ -368,10 +386,10 @@ public class PropertySheetConfigElement extends ConfigElementAdapter { public PropertyConfig(String name, String displayLabel, String displayLabelId, boolean readOnly, String converter, String inView, String inEdit, - String compGenerator) + String compGenerator, String ignoreIfMissing) { super(name, displayLabel, displayLabelId, readOnly, converter, - inView, inEdit, compGenerator); + inView, inEdit, compGenerator, ignoreIfMissing); } } @@ -385,7 +403,7 @@ public class PropertySheetConfigElement extends ConfigElementAdapter String compGenerator) { super(name, displayLabel, displayLabelId, readOnly, converter, - inView, inEdit, compGenerator); + inView, inEdit, compGenerator, null); } } @@ -399,7 +417,7 @@ public class PropertySheetConfigElement extends ConfigElementAdapter String compGenerator) { super(name, displayLabel, displayLabelId, readOnly, converter, - inView, inEdit, compGenerator); + inView, inEdit, compGenerator, null); } } } diff --git a/source/java/org/alfresco/web/config/PropertySheetElementReader.java b/source/java/org/alfresco/web/config/PropertySheetElementReader.java index 5a29136fec..bdbf413ded 100644 --- a/source/java/org/alfresco/web/config/PropertySheetElementReader.java +++ b/source/java/org/alfresco/web/config/PropertySheetElementReader.java @@ -42,10 +42,12 @@ public class PropertySheetElementReader implements ConfigElementReader public static final String ATTR_SHOW_IN_EDIT_MODE = "show-in-edit-mode"; public static final String ATTR_SHOW_IN_VIEW_MODE = "show-in-view-mode"; public static final String ATTR_COMPONENT_GENERATOR = "component-generator"; + public static final String ATTR_IGNORE_IF_MISSING = "ignore-if-missing"; /** * @see org.alfresco.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element) */ + @SuppressWarnings("unchecked") public ConfigElement parse(Element element) { PropertySheetConfigElement configElement = null; @@ -78,9 +80,11 @@ public class PropertySheetElementReader implements ConfigElementReader if (ELEMENT_SHOW_PROPERTY.equals(item.getName())) { + String ignoreIfMissing = item.attributeValue(ATTR_IGNORE_IF_MISSING); + // add the property to show to the custom config element configElement.addProperty(propName, label, labelId, readOnly, converter, - inView, inEdit, compGenerator); + inView, inEdit, compGenerator, ignoreIfMissing); } else if (ELEMENT_SHOW_ASSOC.equals(item.getName())) { diff --git a/source/java/org/alfresco/web/config/WebClientConfigTest.java b/source/java/org/alfresco/web/config/WebClientConfigTest.java index cb375f0957..1093bf889b 100644 --- a/source/java/org/alfresco/web/config/WebClientConfigTest.java +++ b/source/java/org/alfresco/web/config/WebClientConfigTest.java @@ -18,7 +18,6 @@ package org.alfresco.web.config; import java.util.ArrayList; import java.util.Collection; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -99,12 +98,14 @@ public class WebClientConfigTest extends BaseTest assertNotNull("createddate property config should not be null", createdDataProp); assertEquals("display label for createddate should be null", null, createdDataProp.getDisplayLabel()); assertTrue("read only for createddate should be 'true'", createdDataProp.isReadOnly()); + assertTrue("ignoreIfMissing for createddate should be 'true'", createdDataProp.getIgnoreIfMissing()); ItemConfig iconProp = props.get("icon"); assertNotNull("icon property config should not be null", iconProp); assertEquals("display label for icon should be null", null, iconProp.getDisplayLabel()); assertEquals("component-generator", "SpaceIconPickerGenerator", iconProp.getComponentGenerator()); assertFalse("read only for icon should be 'false'", iconProp.isReadOnly()); + assertFalse("ignoreIfMissing for icon should be 'false'", iconProp.getIgnoreIfMissing()); // test that a call to the generic getChildren call throws an error try @@ -277,6 +278,7 @@ public class WebClientConfigTest extends BaseTest assertFalse("icon should not be read-only", iconCfg.isReadOnly()); assertTrue("icon should be shown in view mode", iconCfg.isShownInViewMode()); assertTrue("icon should be shown in edit mode", iconCfg.isShownInEditMode()); + assertFalse("ignoreIfMissing for icon should be 'false'", iconCfg.getIgnoreIfMissing()); } /** diff --git a/source/java/org/alfresco/web/ui/repo/component/property/PropertySheetItem.java b/source/java/org/alfresco/web/ui/repo/component/property/PropertySheetItem.java index a84bc4b3c6..aa8d17d6ba 100644 --- a/source/java/org/alfresco/web/ui/repo/component/property/PropertySheetItem.java +++ b/source/java/org/alfresco/web/ui/repo/component/property/PropertySheetItem.java @@ -42,6 +42,7 @@ public abstract class PropertySheetItem extends UIPanel implements NamingContain protected String displayLabel; protected String converter; protected Boolean readOnly; + protected Boolean ignoreIfMissing; protected String componentGenerator; protected String resolvedDisplayLabel; @@ -198,6 +199,38 @@ public abstract class PropertySheetItem extends UIPanel implements NamingContain this.readOnly = readOnly; } + /** + * @return Determines whether the item should be ignored (not rendered) + * if the item can not be found + */ + public boolean getIgnoreIfMissing() + { + if (this.ignoreIfMissing == null) + { + ValueBinding vb = getValueBinding("ignoreIfMissing"); + if (vb != null) + { + this.ignoreIfMissing = (Boolean)vb.getValue(getFacesContext()); + } + } + + if (this.ignoreIfMissing == null) + { + this.ignoreIfMissing = Boolean.TRUE; + } + + return this.ignoreIfMissing; + } + + /** + * @param ignoreIfMissing Sets the whether the item will be ignored + * if it can not be found + */ + public void setIgnoreIfMissing(boolean ignoreIfMissing) + { + this.ignoreIfMissing = ignoreIfMissing; + } + /** * @see javax.faces.component.StateHolder#restoreState(javax.faces.context.FacesContext, java.lang.Object) */ @@ -212,6 +245,7 @@ public abstract class PropertySheetItem extends UIPanel implements NamingContain this.converter = (String)values[4]; this.componentGenerator = (String)values[5]; this.resolvedDisplayLabel = (String)values[6]; + this.ignoreIfMissing = (Boolean)values[7]; } /** @@ -219,7 +253,7 @@ public abstract class PropertySheetItem extends UIPanel implements NamingContain */ public Object saveState(FacesContext context) { - Object values[] = new Object[7]; + Object values[] = new Object[8]; // standard component attributes are saved by the super class values[0] = super.saveState(context); values[1] = this.name; @@ -228,6 +262,7 @@ public abstract class PropertySheetItem extends UIPanel implements NamingContain values[4] = this.converter; values[5] = this.componentGenerator; values[6] = this.resolvedDisplayLabel; + values[7] = this.ignoreIfMissing; return (values); } diff --git a/source/java/org/alfresco/web/ui/repo/component/property/UIProperty.java b/source/java/org/alfresco/web/ui/repo/component/property/UIProperty.java index f844797c92..9dea96b0af 100644 --- a/source/java/org/alfresco/web/ui/repo/component/property/UIProperty.java +++ b/source/java/org/alfresco/web/ui/repo/component/property/UIProperty.java @@ -41,6 +41,7 @@ import org.springframework.web.jsf.FacesContextUtils; public class UIProperty extends PropertySheetItem { private static Log logger = LogFactory.getLog(UIProperty.class); + private static Log missingPropsLogger = LogFactory.getLog("alfresco.missingProperties"); /** * Default constructor @@ -76,8 +77,9 @@ public class UIProperty extends PropertySheetItem if (propDef == null) { // there is no definition for the node, so it may have been added to - // the node as an additional property, so look for it in the node itself - if (node.hasProperty(propertyName)) + // the node as an additional property, so look for it in the node itself. + // Or, if the ignoreIfMissing flag is set to false, show the property + if (node.hasProperty(propertyName) || getIgnoreIfMissing() == false) { String displayLabel = (String)getDisplayLabel(); if (displayLabel == null) @@ -91,8 +93,9 @@ public class UIProperty extends PropertySheetItem } else { - // warn the user that the property was not found anywhere! - logger.warn("Failed to find property definition for property '" + propertyName + "' for node: " + node.getNodeRef().toString()); + // warn the user that the property was not found anywhere + if (missingPropsLogger.isDebugEnabled()) + missingPropsLogger.debug("Failed to find property '" + propertyName + "' for node: " + node.getNodeRef().toString()); } } else diff --git a/source/java/org/alfresco/web/ui/repo/component/property/UIPropertySheet.java b/source/java/org/alfresco/web/ui/repo/component/property/UIPropertySheet.java index 033b42d454..cdd6cf3218 100644 --- a/source/java/org/alfresco/web/ui/repo/component/property/UIPropertySheet.java +++ b/source/java/org/alfresco/web/ui/repo/component/property/UIPropertySheet.java @@ -743,6 +743,7 @@ public class UIPropertySheet extends UIPanel implements NamingContainer propSheetItem.setName(item.getName()); propSheetItem.setConverter(item.getConverter()); propSheetItem.setComponentGenerator(item.getComponentGenerator()); + propSheetItem.setIgnoreIfMissing(item.getIgnoreIfMissing()); String displayLabel = item.getDisplayLabel(); if (item.getDisplayLabelId() != null) diff --git a/source/test-resources/test-config-override.xml b/source/test-resources/test-config-override.xml index 33c7c1ad71..10077982db 100644 --- a/source/test-resources/test-config-override.xml +++ b/source/test-resources/test-config-override.xml @@ -86,7 +86,7 @@ - + diff --git a/source/test-resources/test-config.xml b/source/test-resources/test-config.xml index 1b655ce234..aad877a482 100644 --- a/source/test-resources/test-config.xml +++ b/source/test-resources/test-config.xml @@ -161,7 +161,8 @@ - + diff --git a/source/web/jsp/forums/create-topic-dialog.jsp b/source/web/jsp/forums/create-topic-dialog.jsp index 2b2e52817a..54ed057922 100644 --- a/source/web/jsp/forums/create-topic-dialog.jsp +++ b/source/web/jsp/forums/create-topic-dialog.jsp @@ -81,7 +81,7 @@ - + @@ -91,19 +91,6 @@ - - - - - - - - - - - - -