View Javadoc
1   /*
2    * Copyright (c) 2002-2022, City of Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.workflow.web.task;
35  
36  import fr.paris.lutece.plugins.workflowcore.service.task.ITask;
37  import fr.paris.lutece.plugins.workflowcore.web.task.ITaskComponent;
38  import fr.paris.lutece.plugins.workflowcore.web.task.ITaskComponentManager;
39  import fr.paris.lutece.portal.service.spring.SpringContextService;
40  
41  import java.util.List;
42  import java.util.Locale;
43  
44  import javax.servlet.http.HttpServletRequest;
45  
46  /**
47   *
48   * TaskComponentManager
49   *
50   */
51  public class TaskComponentManager implements ITaskComponentManager
52  {
53      /**
54       * The name of the bean of this service
55       */
56      public static final String BEAN_MANAGER = "workflow.taskComponentManager";
57  
58      /**
59       * {@inheritDoc}
60       */
61      @Override
62      public List<ITaskComponent> getTaskComponents( )
63      {
64          return SpringContextService.getBeansOfType( ITaskComponent.class );
65      }
66  
67      /**
68       * {@inheritDoc}
69       */
70      @Override
71      public ITaskComponent getTaskComponent( String strKey )
72      {
73          for ( ITaskComponent component : getTaskComponents( ) )
74          {
75              if ( component.isInvoked( strKey ) )
76              {
77                  return component;
78              }
79          }
80  
81          return null;
82      }
83  
84      /**
85       * {@inheritDoc}
86       */
87      @Override
88      public ITaskComponent getTaskComponent( ITask task )
89      {
90          if ( ( task != null ) && ( task.getTaskType( ) != null ) )
91          {
92              return getTaskComponent( task.getTaskType( ).getKey( ) );
93          }
94  
95          return null;
96      }
97  
98      /**
99       * {@inheritDoc}
100      */
101     @Override
102     public String getDisplayTaskForm( int nIdResource, String strResourceType, HttpServletRequest request, Locale locale, ITask task )
103     {
104         ITaskComponent component = getTaskComponent( task );
105 
106         if ( component != null )
107         {
108             return component.getDisplayTaskForm( nIdResource, strResourceType, request, locale, task );
109         }
110 
111         return null;
112     }
113 
114     /**
115      * {@inheritDoc}
116      */
117     @Override
118     public String getDisplayConfigForm( HttpServletRequest request, Locale locale, ITask task )
119     {
120         ITaskComponent component = getTaskComponent( task );
121 
122         if ( component != null )
123         {
124             return component.getDisplayConfigForm( request, locale, task );
125         }
126 
127         return null;
128     }
129 
130     /**
131      * {@inheritDoc}
132      */
133     @Override
134     public String getDisplayTaskInformation( int nIdHistory, HttpServletRequest request, Locale locale, ITask task )
135     {
136         ITaskComponent component = getTaskComponent( task );
137 
138         if ( component != null )
139         {
140             return component.getDisplayTaskInformation( nIdHistory, request, locale, task );
141         }
142 
143         return null;
144     }
145 
146     /**
147      * {@inheritDoc}
148      */
149     @Override
150     public String doValidateTask( int nIdResource, String strResourceType, HttpServletRequest request, Locale locale, ITask task )
151     {
152         ITaskComponent component = getTaskComponent( task );
153 
154         if ( component != null )
155         {
156             return component.doValidateTask( nIdResource, strResourceType, request, locale, task );
157         }
158 
159         return null;
160     }
161 
162     /**
163      * {@inheritDoc}
164      */
165     @Override
166     public String doSaveConfig( HttpServletRequest request, Locale locale, ITask task )
167     {
168         ITaskComponent component = getTaskComponent( task );
169 
170         if ( component != null )
171         {
172             return component.doSaveConfig( request, locale, task );
173         }
174 
175         return null;
176     }
177 }