1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.mydashboard.modules.grusupply.web;
35
36 import java.util.ArrayList;
37 import java.util.HashMap;
38 import java.util.List;
39 import java.util.Locale;
40 import java.util.Map;
41
42 import javax.inject.Inject;
43 import javax.inject.Named;
44 import javax.servlet.http.HttpServletRequest;
45
46 import org.apache.commons.collections.CollectionUtils;
47 import org.apache.commons.lang3.StringUtils;
48
49 import fr.paris.lutece.plugins.grubusiness.business.notification.EnumNotificationType;
50 import fr.paris.lutece.plugins.grubusiness.business.web.rs.DemandDisplay;
51 import fr.paris.lutece.plugins.grubusiness.business.web.rs.DemandResult;
52 import fr.paris.lutece.plugins.grubusiness.business.web.rs.NotificationResult;
53 import fr.paris.lutece.plugins.mydashboard.modules.grusupply.business.DemandDashboard;
54 import fr.paris.lutece.plugins.mydashboard.modules.grusupply.business.DemandDashboardHome;
55 import fr.paris.lutece.plugins.mydashboard.modules.grusupply.service.NotificationGruService;
56 import fr.paris.lutece.plugins.mydashboard.service.MyDashboardComponent;
57 import fr.paris.lutece.portal.service.i18n.I18nService;
58 import fr.paris.lutece.portal.service.security.LuteceUser;
59 import fr.paris.lutece.portal.service.security.SecurityService;
60 import fr.paris.lutece.portal.service.template.AppTemplateService;
61 import fr.paris.lutece.portal.service.util.AppPropertiesService;
62 import fr.paris.lutece.util.html.HtmlTemplate;
63
64
65
66
67
68
69 public class MyDashboardComponentLastNotificationGRU extends MyDashboardComponent
70 {
71
72
73
74
75 private static final long serialVersionUID = 8297192924908575568L;
76
77 private static final String TEMPLATE_LAST_NOTIFICATION_LIST = "skin/plugins/mydashboard/modules/grusupply/dashboard_last_demand.html";
78 private static final String DASHBOARD_COMPONENT_ID = "mydashboard-grusupply.componentLastNotification";
79 private static final String MESSAGE_COMPONENT_DESCRIPTION = "module.mydashboard.grusupply.myDashboardComponentLastNotification.description";
80 private static final String PROPERTY_LIMIT_RESULT = AppPropertiesService.getProperty( "mydashboard-grusupply.limit.result.lastnotification", "5" );
81
82 private static final String MARK_DEMAND_TYPE_LIST = "demand_types_list";
83 private static final String MARK_LIST_DEMAND = "list_demands";
84
85 @Inject
86 @Named( NotificationGruService.BEAN_NAME )
87 private NotificationGruService _notificationService;
88
89 @Override
90 public String getDashboardData( HttpServletRequest request )
91 {
92 LuteceUser user = SecurityService.getInstance( ).getRegisteredUser( request );
93
94 if ( user != null )
95 {
96 Map<String, Object> model = new HashMap<>( );
97
98 DemandResult demandResult = _notificationService.getListDemand( user.getName( ), "1", PROPERTY_LIMIT_RESULT, EnumNotificationType.MYDASHBOARD.toString( ) );
99 List<DemandDashboard> listDemandDashboards = new ArrayList<>( );
100
101 if ( demandResult != null && CollectionUtils.isNotEmpty( demandResult.getListDemandDisplay( ) ) )
102 {
103 for( DemandDisplay demand : demandResult.getListDemandDisplay( ) )
104 {
105 NotificationResult notificationList = _notificationService.getListNotification( demand.getDemand( ).getId( ), demand.getDemand( ).getTypeId( ), user.getName( ) );
106
107 DemandDashboardd/modules/grusupply/business/DemandDashboard.html#DemandDashboard">DemandDashboard demandDashboard = new DemandDashboard( demand.getDemand( ).getUID( ) , false );
108 demandDashboard.setDemand( demand.getDemand( ) );
109 demandDashboard.setStatus( demand.getStatus( ) );
110 if ( notificationList != null && notificationList.getNotifications( ) != null )
111 {
112 demandDashboard.setListNotification( notificationList.getNotifications( ) );
113 }
114 listDemandDashboards.add( demandDashboard );
115 }
116 listDemandDashboards = DemandDashboardHome.selectByDemandIds( listDemandDashboards );
117 }
118
119 model.put( MARK_DEMAND_TYPE_LIST, _notificationService.getListDemandType( ) );
120 model.put( MARK_LIST_DEMAND, listDemandDashboards );
121
122 HtmlTemplate htmTemplate = AppTemplateService.getTemplate( TEMPLATE_LAST_NOTIFICATION_LIST, request.getLocale( ), model );
123
124 return htmTemplate.getHtml( );
125 }
126
127 return StringUtils.EMPTY;
128 }
129
130 @Override
131 public String getComponentId( )
132 {
133 return DASHBOARD_COMPONENT_ID;
134 }
135
136 @Override
137 public String getComponentDescription( Locale locale )
138 {
139 return I18nService.getLocalizedString( MESSAGE_COMPONENT_DESCRIPTION, locale );
140 }
141
142 }