View Javadoc
1   /*
2    * Copyright (c) 2002-2017, 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.provider;
35  
36  import java.util.ArrayList;
37  import java.util.Collection;
38  import java.util.List;
39  
40  import javax.inject.Inject;
41  import javax.servlet.http.HttpServletRequest;
42  
43  import fr.paris.lutece.plugins.workflow.service.taskinfo.ITaskInfoProvider;
44  import fr.paris.lutece.plugins.workflowcore.business.resource.ResourceHistory;
45  import fr.paris.lutece.plugins.workflowcore.service.provider.IMarkerProvider;
46  import fr.paris.lutece.plugins.workflowcore.service.provider.InfoMarker;
47  import fr.paris.lutece.plugins.workflowcore.service.task.ITask;
48  import fr.paris.lutece.plugins.workflowcore.service.task.ITaskService;
49  import javax.inject.Named;
50  import net.sf.json.JSONObject;
51  
52  /**
53   * This class represents a NotifyGru marker provider for the Edit record task
54   *
55   */
56  public class ReplyMarkerProvider implements IMarkerProvider
57  {
58      private static final String ID = "workflow-reply.taskReplyMarkerProvider";
59  
60      // Messages
61      private static final String MESSAGE_TITLE_KEY = "module.workflow.reply.marker.provider.taskreply.title";
62      private static final String MESSAGE_MARKER_MSG_DESCRIPTION_KEY = "module.workflow.reply.marker.provider.taskreply.msg.description";
63  
64      // Markers
65      private static final String MARK_REPLY_MESSAGE = "task_reply_message";
66      
67  
68      // Services
69      @Inject
70      private ITaskService _taskService;
71  
72      @Inject
73      @Named(value="workflow-reply.replyTaskInfoProvider")
74      private ITaskInfoProvider _replyTaskInfoProvider;
75  
76      
77      /**
78       * {@inheritDoc}
79       */
80      @Override
81      public String getId( )
82      {
83          return ID;
84      }
85  
86      /**
87       * {@inheritDoc}
88       */
89      @Override
90      public String getTitleI18nKey( )
91      {
92          return MESSAGE_TITLE_KEY ;
93      }
94  
95      /**
96       * {@inheritDoc}
97       */
98      @Override
99      public Collection<InfoMarker> provideMarkerDescriptions( )
100     {
101         List<InfoMarker> listMarkers = new ArrayList<>( );
102 
103         InfoMarker notifyGruMarkerMsg = new InfoMarker( MARK_REPLY_MESSAGE );
104         notifyGruMarkerMsg.setDescription( MESSAGE_MARKER_MSG_DESCRIPTION_KEY );
105         listMarkers.add( notifyGruMarkerMsg );
106 
107         return listMarkers;
108     }
109 
110     /**
111      * {@inheritDoc}
112      */
113     @Override
114     public Collection<InfoMarker> provideMarkerValues( ResourceHistory resourceHistory, ITask task, HttpServletRequest request )
115     {
116         List<InfoMarker> listMarkers = new ArrayList<>( );
117 
118         for ( ITask taskOther : _taskService.getListTaskByIdAction( resourceHistory.getAction( ).getId( ), request.getLocale( ) ) )
119         {
120             if ( taskOther.getTaskType( ).getKey( ).equals( _replyTaskInfoProvider.getTaskType( ).getKey( ) ) )
121             {
122                 String strJsonInfos = _replyTaskInfoProvider.getTaskResourceInfo( resourceHistory.getId( ), taskOther.getId( ), request ) ;
123 
124                 JSONObject jsonInfos = JSONObject.fromObject( strJsonInfos );
125                 String strMsg = jsonInfos.getString( MARK_REPLY_MESSAGE );
126 
127 
128                 InfoMarker notifyGruMarkerMsg = new InfoMarker( MARK_REPLY_MESSAGE );
129                 notifyGruMarkerMsg.setValue( strMsg );
130                 listMarkers.add( notifyGruMarkerMsg );
131 
132                 break;
133             }
134         }
135 
136         return listMarkers;
137     }
138 
139 }
140