シナリオ:CRUD 操作のハンドラーの追加

要件に基づいて、アセットタイプの CRUD 操作に関連する前処理および後処理のハンドラーを追加できます。ActionHandler インターフェイスを使用して変更を実装します。

実装の概要

この例では、サンプルのテキスト作成ハンドラーを作成し、前処理手順のテキストモジュールの名前を更新します。
  1. ActionHandler インターフェイスを実装する TextCreateHandler クラスを CorrespondenceManagementSolutionTemplate/Services プロジェクトに作成します。このインターフェイスには、preProcess() および postProcess() メソッドが含まれます。preProcess() メソッドは作成メソッドの前に、postProcess() メソッドは作成メソッドの後に呼び出されます。
    package com.adobe.icc; 
     
    import java.util.Map; 
    import com.adobe.icc.dbforms.obj.TextModule; 
    import com.adobe.livecycle.content.repository.action.ActionHandler; 
    import com.adobe.livecycle.content.repository.action.ActionType; 
     
    /** 
     * TextCreateHandler is the handler associated with the Create operation of the Form. The preProcess() and postProcess() methods of 
     * this class are invoked just before and after the Create operation. 
     */ 
    public class TextCreateHandler implements ActionHandler { 
     
            private static final String PREFIX = "PREFIX"; 
        /** 
         * This method is invoked just prior to the Create operation of TextModule. The first parameter of this API is the form object that 
         * is being Created. 
         */ 
        public void preProcess(String nodeType, ActionType actionType, Object obj, Map<String, Object> arg1) 
        { 
            TextModule text = (TextModule) obj; 
                    text.setName(PREFIX + text.getName()); 
        } 
         
        /** 
         * This method is invoked just after to the Create operation of Text. The first parameter is the form object that has been 
         * Created. 
         */ 
        public void postProcess(String nodeType, ActionType actionType, Object arg0, Map<String, Object> arg1) { 
            // Do nothing 
        } 
    }
  2. 次のエントリを CorrespondenceManagementSolutionTemplate¥Services¥resources¥META-INF¥spring¥osgi-context.xml の <bp:blueprint> セクションに追加して、ハンドラーを設定します。
    <bp:reference interface="com.adobe.livecycle.content.repository.RepositoryService" />
  3. AssetDefinitionDeployer クラスを更新し、com.adobe.livecycle.content.repository.RepositoryService クラスのプライベート変数 repositoryService を追加します。
    @Autowired 
    private RepositoryService repositoryService;
  4. また、次のコードを afterPropertiesSet() メソッドに追加します。
    List<ActionHandler> handlers = new ArrayList<ActionHandler>(); 
    handlers = new ArrayList<ActionHandler>(); 
    handlers.add(new TextCreateHandler()); 
    repositoryService.addActionHandlers(ActionHandlerService.APP_ROOT_GLOBAL, TextModule.class.getName(), ActionType.CREATE, handlers);
  5. ソリューションテンプレートを再構築および再デプロイして変更を確認します。再構築および再デプロイについては、Solution Template の構築とデプロイを参照してください。