View Javadoc
1   /*
2    * Copyright (c) 2002-2019, 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.reply.service.task;
35  
36  import fr.paris.lutece.plugins.workflow.modules.reply.business.task.Reply;
37  import fr.paris.lutece.plugins.workflow.modules.reply.service.IReplyService;
38  import fr.paris.lutece.plugins.workflow.modules.reply.util.constants.ReplyConstants;
39  import java.util.Locale;
40  
41  import javax.servlet.http.HttpServletRequest;
42  
43  import org.apache.commons.lang.StringUtils;
44  
45  import fr.paris.lutece.plugins.workflowcore.service.config.ITaskConfigService;
46  import fr.paris.lutece.plugins.workflowcore.service.task.Task;
47  import fr.paris.lutece.portal.business.user.AdminUser;
48  import fr.paris.lutece.portal.service.i18n.I18nService;
49  import java.util.Map;
50  import javax.inject.Inject;
51  import javax.inject.Named;
52  
53  /**
54   * This class represents a task to reply to a ticket
55   *
56   */
57  public class TaskReply extends Task
58  {
59      private static final String MESSAGE_REPLY = "module.workflow.reply.task_reply.labelReply";
60  
61      // PARAMETERS
62      public static final String PARAMETER_USER_MESSAGE = "user_message";
63  
64      // Variables
65      private AdminUser _user;
66  
67      @Inject
68      private IReplyService _replyService;
69      @Inject
70      @Named( ReplyConstants.BEAN_REPLY_CONFIG_SERVICE )
71      private ITaskConfigService _taskReplyConfigService;
72  
73      /**
74       * {@inheritDoc}
75       */
76      @Override
77      public String getTitle( Locale locale )
78      {
79          return I18nService.getLocalizedString( MESSAGE_REPLY, locale );
80      }
81  
82      /**
83       * {@inheritDoc}
84       */
85      @Override
86      public void init( )
87      {
88      }
89  
90      /**
91       * {@inheritDoc}
92       */
93      @Override
94      public void processTask( int nIdResourceHistory, HttpServletRequest request, Locale locale )
95      {
96          String strMessage = request.getParameter( ReplyConstants.PARAMETER_REPLY_MESSAGE + ReplyConstants.UNDERSCORE + getId( ) );
97  
98          boolean bCreate = false;
99  
100         Reply reply = _replyService.find( nIdResourceHistory, getId( ) );
101 
102         if ( reply == null )
103         {
104             reply = new Reply( );
105             reply.setIdHistory( nIdResourceHistory );
106             reply.setIdTask( getId( ) );
107             bCreate = true;
108         }
109 
110         reply.setMessage( StringUtils.isNotBlank( strMessage ) ? strMessage : StringUtils.EMPTY );
111 
112         if ( bCreate )
113         {
114             _replyService.create( reply );
115         }
116         else
117         {
118             _replyService.update( reply );
119         }
120     }
121 
122     // GET
123 
124     /**
125      * {@inheritDoc}
126      */
127     @Override
128     public Map<String, String> getTaskFormEntries( Locale locale )
129     {
130         return null;
131     }
132 
133     /**
134      * {@inheritDoc}
135      */
136     @Override
137     public void doRemoveConfig( )
138     {
139         _replyService.removeByIdTask( getId( ) );
140         _taskReplyConfigService.remove( getId( ) );
141     }
142 
143     /**
144      * {@inheritDoc}
145      */
146     @Override
147     public void doRemoveTaskInformation( int nIdHistory )
148     {
149         _replyService.removeByIdHistory( nIdHistory, getId( ) );
150     }
151 }