001/* 002 * Copyright 2013 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.plugins.thesaurus.workflow; 017 018import java.util.Collections; 019import java.util.List; 020import java.util.Map; 021import java.util.concurrent.Future; 022 023import org.ametys.cms.repository.Content; 024import org.ametys.cms.workflow.CreateContentFunction; 025import org.ametys.plugins.repository.ModifiableTraversableAmetysObject; 026 027import com.opensymphony.workflow.WorkflowException; 028 029/** 030 * OSWorkflow function for creating a term of thesaurus. 031 */ 032public class CreateTermFunction extends CreateContentFunction 033{ 034 /** Constant for storing the parent microthesaurus ID into the transient variables map. */ 035 public static final String PARENT_MT_ID_KEY = CreateTermFunction.class.getName() + "$parentMTId"; 036 037 /** Constant controlling if indexation should be avoided when creating the term (for use in imports or batch creations). */ 038 public static final String DISABLE_INDEXATION = CreateTermFunction.class.getName() + "$disableIndexation"; 039 040 @Override 041 protected ModifiableTraversableAmetysObject _getContentRoot(Map transientVars) throws WorkflowException 042 { 043 if (transientVars.containsKey(PARENT_MT_ID_KEY)) 044 { 045 return _resolver.resolveById((String) transientVars.get(PARENT_MT_ID_KEY)); 046 } 047 048 return super._getContentRoot(transientVars); 049 } 050 051 @Override 052 protected List<Future> _notifyContentAdded(Content content, Map transientVars) throws WorkflowException 053 { 054 Boolean disableIndexation = (Boolean) transientVars.get(DISABLE_INDEXATION); 055 if (disableIndexation == null || !disableIndexation.booleanValue()) 056 { 057 return super._notifyContentAdded(content, transientVars); 058 } 059 return Collections.EMPTY_LIST; 060 } 061}