View Javadoc
1   /*
2    * Copyright (c) 2002-2018, Mairie de 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.modules.tipi.web.task;
35  
36  import java.util.HashMap;
37  import java.util.Locale;
38  import java.util.Map;
39  
40  import javax.inject.Inject;
41  import javax.inject.Named;
42  import javax.servlet.http.HttpServletRequest;
43  
44  import org.apache.commons.lang3.StringUtils;
45  
46  import fr.paris.lutece.plugins.workflow.web.task.AbstractTaskComponent;
47  import fr.paris.lutece.plugins.workflowcore.business.config.ITaskConfig;
48  import fr.paris.lutece.plugins.workflowcore.service.config.ITaskConfigService;
49  import fr.paris.lutece.plugins.workflowcore.service.task.ITask;
50  import fr.paris.lutece.portal.service.template.AppTemplateService;
51  import fr.paris.lutece.util.html.HtmlTemplate;
52  import fr.paris.lutece.plugins.workflow.modules.tipi.business.Tipi;
53  import fr.paris.lutece.plugins.workflow.modules.tipi.business.TipiRefDetHistory;
54  import fr.paris.lutece.plugins.workflow.modules.tipi.service.ITipiRefDetHistoryService;
55  import fr.paris.lutece.plugins.workflow.modules.tipi.service.ITipiService;
56  import fr.paris.lutece.plugins.workflow.modules.tipi.service.ITipiWorkflowStateService;
57  
58  /**
59   * 
60   * Controller to expose the task tipi in the tipi task config HTML page
61   *
62   */
63  public class TipiTaskComponent extends AbstractTaskComponent
64  {
65      // MARKS
66      private static final String MARK_CONFIG = "config";
67      private static final String MARK_LIST_STATES = "list_states";
68      private static final String MARK_TIPI = "tipi";
69  
70      // BEAN
71      private static final String BEAN_CONFIG_SERVICE = "workflow-tipi.taskTipiConfigService";
72  
73      // TEMPLATE
74      private static final String TEMPLATE_TASK_CONFIG = "admin/plugins/workflow/modules/tipi/tipi_task_config.html";
75      private static final String TEMPLATE_TASK_INFORMATION = "admin/plugins/workflow/modules/tipi/tipi_task_information.html";
76  
77      // SERVICE
78      @Inject
79      private ITipiWorkflowStateService _tipiWorkFlowStateService;
80      @Inject
81      private ITipiRefDetHistoryService _tipiRefDetHistoryService;
82      @Inject
83      private ITipiService _tipiService;
84      @Inject
85      @Named( BEAN_CONFIG_SERVICE )
86      private ITaskConfigService _taskConfigService;
87  
88      /**
89       * {@inheritDoc}
90       */
91      @Override
92      public String doValidateTask( int arg0, String arg1, HttpServletRequest arg2, Locale arg3, ITask arg4 )
93      {
94          return null;
95      }
96  
97      /**
98       * {@inheritDoc}
99       */
100     @Override
101     public String getDisplayConfigForm( HttpServletRequest request, Locale locale, ITask task )
102     {
103 
104         Map<String, Object> model = new HashMap<String, Object>( );
105         model.put( MARK_CONFIG, _taskConfigService.findByPrimaryKey( task.getId( ) ) );
106         model.put( MARK_LIST_STATES, _tipiWorkFlowStateService.getListStates( task.getAction( ).getId( ) ) );
107 
108         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_TASK_CONFIG, locale, model );
109 
110         return template.getHtml( );
111     }
112 
113     /**
114      * {@inheritDoc}
115      */
116     @Override
117     public String getDisplayTaskForm( int nIdResource, String strResourceType, HttpServletRequest request, Locale locale, ITask task )
118     {
119         return null;
120     }
121 
122     /**
123      * {@inheritDoc}
124      */
125     @Override
126     public String getDisplayTaskInformation( int nIdResource, HttpServletRequest request, Locale locale, ITask task )
127     {
128         String strResult = StringUtils.EMPTY;
129 
130         TipiRefDetHistory tipiRefDetHistory = _tipiRefDetHistoryService.findByPrimaryKey( nIdResource );
131 
132         if ( tipiRefDetHistory != null )
133         {
134             Tipi tipi = _tipiService.findByPrimaryKey( tipiRefDetHistory.getRefDet( ) );
135 
136             Map<String, Object> model = new HashMap<String, Object>( );
137             model.put( MARK_TIPI, tipi );
138 
139             HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_TASK_INFORMATION, locale, model );
140 
141             strResult = template.getHtml( );
142         }
143 
144         return strResult;
145     }
146 
147     /**
148      * {@inheritDoc}
149      */
150     @Override
151     public String getTaskInformationXml( int arg0, HttpServletRequest arg1, Locale arg2, ITask arg3 )
152     {
153         return null;
154     }
155 
156     /**
157      * {@inheritDoc}
158      */
159     @Override
160     public String validateConfig( ITaskConfig arg0, HttpServletRequest arg1 )
161     {
162         return null;
163     }
164 }