def match_state( self, obj, state):
     wf_tool = getToolByName( obj, 'portal_workflow')
     try:
         wf_state = wf_tool.getInfoFor( obj, 'review_state')
     except WorkflowException:
         return False
     return wf_state== state
 def clearState( self, policy ):
     import incremental
     catalog = getToolByName( policy, 'portal_catalog' )
     pidx_id = incremental.getIncrementalIndexId( policy )
     for idx in catalog.index_objects():
         if idx.getId() == pidx_id:
             idx.clearState()
    def beginPolicyRemoval( self, policy ):
        """
        remove any non contained instance objects associated with policy.
        ie. policy incremental index
        """

        import incremental
        catalog = getToolByName( policy, 'portal_catalog' )
        pidx_id = incremental.getIncrementalIndexId( policy )
        if pidx_id in catalog.indexes():
            catalog.manage_delIndex( ids=[ pidx_id ] )

        policy.setResetDate( True )
    def finishPolicyConstruction( self, policy ):
        """
        add incremental policy index, deletion source, and dependency source
        """

        import incremental
        catalog = getToolByName( policy, 'portal_catalog' )
        pidx_id = incremental.getIncrementalIndexId( policy )

        if pidx_id not in catalog.indexes():
            catalog.manage_addIndex( pidx_id,
                                     incremental.PolicyIncrementalIndex.meta_type )

        import sources
        
        if DefaultConfiguration.DeletionSource not in policy.objectIds():
            sources.deletion.addDeletionSource( policy,
                                                DefaultConfiguration.DeletionSource )

        if DefaultConfiguration.DependencySource not in policy.objectIds():
            sources.dependency.addDependencySource( policy,
                                                    DefaultConfiguration.DependencySource )