From: <cl...@fe...> - 2008-08-11 19:38:01
|
Author: clasohm Date: 2008-08-11 19:37:47 +0000 (Mon, 11 Aug 2008) New Revision: 1737 Modified: contrib/camden/ccm-ldn-camden-decisiontree/trunk/application.xml contrib/camden/ccm-ldn-camden-decisiontree/trunk/pdl/com/arsdigita/camden/cms/contenttypes/DecisionTree.pdl contrib/camden/ccm-ldn-camden-decisiontree/trunk/src/com/arsdigita/camden/cms/contenttypes/DecisionTree.java contrib/camden/ccm-ldn-camden-decisiontree/trunk/src/com/arsdigita/camden/cms/contenttypes/OptionTarget.java Log: second try fixing the DecisionTree publication problem Modified: contrib/camden/ccm-ldn-camden-decisiontree/trunk/application.xml =================================================================== --- contrib/camden/ccm-ldn-camden-decisiontree/trunk/application.xml 2008-08-08 15:53:08 UTC (rev 1736) +++ contrib/camden/ccm-ldn-camden-decisiontree/trunk/application.xml 2008-08-11 19:37:47 UTC (rev 1737) @@ -2,7 +2,7 @@ <ccm:application xmlns:ccm="http://ccm.redhat.com/ccm-project" name="ccm-ldn-camden-decisiontree" prettyName="Red Hat CCM Content Types" - version="1.0.1" + version="1.0.2" release="1" webapp="ROOT"> <ccm:dependencies> Modified: contrib/camden/ccm-ldn-camden-decisiontree/trunk/pdl/com/arsdigita/camden/cms/contenttypes/DecisionTree.pdl =================================================================== --- contrib/camden/ccm-ldn-camden-decisiontree/trunk/pdl/com/arsdigita/camden/cms/contenttypes/DecisionTree.pdl 2008-08-08 15:53:08 UTC (rev 1736) +++ contrib/camden/ccm-ldn-camden-decisiontree/trunk/pdl/com/arsdigita/camden/cms/contenttypes/DecisionTree.pdl 2008-08-11 19:37:47 UTC (rev 1737) @@ -24,7 +24,7 @@ object type DecisionTree extends ContentPage { String[0..1] cancelURL = cam_decision_trees.cancel_url; - component TreeSection[0..1] firstSection = + TreeSection[0..1] firstSection = join cam_decision_trees.first_section to cam_tree_sections.section_id; reference key (cam_decision_trees.tree_id); @@ -74,7 +74,7 @@ object type OptionTarget extends ContentItem { String[0..1] targetURL = cam_option_targets.target_url; - component TreeSection[0..1] targetSection = + TreeSection[0..1] targetSection = join cam_option_targets.target_section to cam_tree_sections.section_id; reference key (cam_option_targets.target_id); Modified: contrib/camden/ccm-ldn-camden-decisiontree/trunk/src/com/arsdigita/camden/cms/contenttypes/DecisionTree.java =================================================================== --- contrib/camden/ccm-ldn-camden-decisiontree/trunk/src/com/arsdigita/camden/cms/contenttypes/DecisionTree.java 2008-08-08 15:53:08 UTC (rev 1736) +++ contrib/camden/ccm-ldn-camden-decisiontree/trunk/src/com/arsdigita/camden/cms/contenttypes/DecisionTree.java 2008-08-11 19:37:47 UTC (rev 1737) @@ -29,6 +29,8 @@ import com.arsdigita.cms.CMS; import com.arsdigita.cms.ContentItem; import com.arsdigita.cms.ContentPage; +import com.arsdigita.cms.CustomCopy; +import com.arsdigita.cms.ItemCopier; import com.arsdigita.cms.dispatcher.SimpleXMLGenerator; import com.arsdigita.cms.dispatcher.XMLGenerator; import com.arsdigita.domain.DataObjectNotFoundException; @@ -38,6 +40,7 @@ import com.arsdigita.persistence.OID; import com.arsdigita.persistence.Session; import com.arsdigita.persistence.SessionManager; +import com.arsdigita.persistence.metadata.Property; import com.arsdigita.web.BaseApplicationServlet; import com.arsdigita.xml.Element; @@ -224,4 +227,51 @@ parent.addContent(content); } + + /** + * Override ContentItem.copyProperty so that firstSection is handled + * like a component. + */ + public boolean copyProperty(CustomCopy source, Property property, + ItemCopier copier) { + String attribute = property.getName(); + if (FIRST_SECTION.equals(attribute)) { + // We don't copy the FIRST_SECTION property here, because it's not marked + // as a component, and would cause a PublishedLink to be created, which + // results in performance problems during publication. Instead, we will + // set the FIRST_SECTION property as part of the copying of the SECTIONS + // property, see below. + return true; + } + + boolean result = super.copyProperty(source, property, copier); + + if (SECTIONS.equals(attribute)) { + DecisionTree srcTree = (DecisionTree)source; + TreeSection srcFirstSection = srcTree.getFirstSection(); + if (srcFirstSection != null) { + // At this point, all associated TreeSections have been copied, + // so we can be sure that ItemCopier.getCopy() will return the + // copied TreeSection object. + setFirstSection((TreeSection)copier.getCopy(srcFirstSection.getOID())); + } + + // Next, we go through all OptionTargets in the source object + // and set the TARGET_SECTION property of the corresponding + // destination OptionTarget. Like FIRST_SECTION, the TARGET_SECTION + // property was skipped when the OptionTargets were copied. + OptionTargetCollection srcTargets = srcTree.getTargets(); + while (srcTargets.next()) { + OptionTarget srcTarget = srcTargets.getTarget(); + TreeSection srcSection = srcTarget.getTargetSection(); + + if (srcSection == null) continue; + + OptionTarget dstTarget = (OptionTarget)copier.getCopy(srcTarget.getOID()); + dstTarget.setTargetSection((TreeSection)copier.getCopy(srcSection.getOID())); + } + } + + return result; + } } Modified: contrib/camden/ccm-ldn-camden-decisiontree/trunk/src/com/arsdigita/camden/cms/contenttypes/OptionTarget.java =================================================================== --- contrib/camden/ccm-ldn-camden-decisiontree/trunk/src/com/arsdigita/camden/cms/contenttypes/OptionTarget.java 2008-08-08 15:53:08 UTC (rev 1736) +++ contrib/camden/ccm-ldn-camden-decisiontree/trunk/src/com/arsdigita/camden/cms/contenttypes/OptionTarget.java 2008-08-11 19:37:47 UTC (rev 1737) @@ -21,9 +21,12 @@ import java.math.BigDecimal; import com.arsdigita.cms.ContentItem; +import com.arsdigita.cms.CustomCopy; +import com.arsdigita.cms.ItemCopier; import com.arsdigita.domain.DataObjectNotFoundException; import com.arsdigita.persistence.DataObject; import com.arsdigita.persistence.OID; +import com.arsdigita.persistence.metadata.Property; /** * A section target of the Camden Decision Tree content type. @@ -97,5 +100,20 @@ public void setTargetSection(TreeSection value) { set(TARGET_SECTION, value); } + + public boolean copyProperty(CustomCopy source, Property property, + ItemCopier copier) { + String attribute = property.getName(); + if (TARGET_SECTION.equals(attribute)) { + // We don't copy the TARGET_SECTION property here, because it's not marked + // as a component, and would cause a PublishedLink to be created, which + // results in performance problems during publication. Instead, we will + // set the TARGET_SECTION property as part of the copying of the SECTIONS + // property in DecisionTree.copyProperty(). + return true; + } + + return super.copyProperty(source, property, copier); + } } \ No newline at end of file |