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.identitystore.v3.web.rs.dto.common.IdentityDto;
54 import fr.paris.lutece.plugins.mydashboard.modules.grusupply.business.DemandDashboard;
55 import fr.paris.lutece.plugins.mydashboard.modules.grusupply.business.DemandDashboardHome;
56 import fr.paris.lutece.plugins.mydashboard.modules.grusupply.service.IdentityStoreService;
57 import fr.paris.lutece.plugins.mydashboard.modules.grusupply.service.NotificationGruService;
58 import fr.paris.lutece.plugins.mydashboard.service.MyDashboardComponent;
59 import fr.paris.lutece.portal.service.i18n.I18nService;
60 import fr.paris.lutece.portal.service.security.LuteceUser;
61 import fr.paris.lutece.portal.service.security.SecurityService;
62 import fr.paris.lutece.portal.service.template.AppTemplateService;
63 import fr.paris.lutece.portal.service.util.AppPropertiesService;
64 import fr.paris.lutece.util.html.HtmlTemplate;
65
66
67
68
69
70
71 public class MyDashboardComponentLastNotificationGRU extends MyDashboardComponent
72 {
73
74
75
76
77 private static final long serialVersionUID = 8297192924908575568L;
78
79 private static final String TEMPLATE_LAST_NOTIFICATION_LIST = "skin/plugins/mydashboard/modules/grusupply/dashboard_last_demand.html";
80 private static final String DASHBOARD_COMPONENT_ID = "mydashboard-grusupply.componentLastNotification";
81 private static final String MESSAGE_COMPONENT_DESCRIPTION = "module.mydashboard.grusupply.myDashboardComponentLastNotification.description";
82 private static final String PROPERTY_LIMIT_RESULT = AppPropertiesService.getProperty( "mydashboard-grusupply.limit.result.lastnotification", "5" );
83
84 private static final String MARK_DEMAND_TYPE_LIST = "demand_types_list";
85 private static final String MARK_LIST_DEMAND = "list_demands";
86
87 @Inject
88 @Named( NotificationGruService.BEAN_NAME )
89 private NotificationGruService _notificationService;
90
91 @Override
92 public String getDashboardData( HttpServletRequest request )
93 {
94 LuteceUser user = SecurityService.getInstance( ).getRegisteredUser( request );
95
96 if ( user != null )
97 {
98 Map<String, Object> model = new HashMap<>( );
99
100 IdentityDto identity = IdentityStoreService.getIdentityByGuid( user.getName( ) );
101
102 DemandResult demandResult = _notificationService.getListDemand( identity.getCustomerId( ), "1", PROPERTY_LIMIT_RESULT, EnumNotificationType.MYDASHBOARD.toString( ) );
103 List<DemandDashboard> listDemandDashboards = new ArrayList<>( );
104
105 if ( demandResult != null && CollectionUtils.isNotEmpty( demandResult.getListDemandDisplay( ) ) )
106 {
107 for( DemandDisplay demand : demandResult.getListDemandDisplay( ) )
108 {
109 NotificationResult notificationList = _notificationService.getListNotification( demand.getDemand( ).getId( ), demand.getDemand( ).getTypeId( ), identity.getCustomerId( ), EnumNotificationType.MYDASHBOARD.name( ) );
110
111 DemandDashboardd/modules/grusupply/business/DemandDashboard.html#DemandDashboard">DemandDashboard demandDashboard = new DemandDashboard( demand.getDemand( ).getUID( ) , false );
112 demandDashboard.setDemand( demand.getDemand( ) );
113 demandDashboard.setStatus( demand.getStatus( ) );
114 if ( notificationList != null && notificationList.getNotifications( ) != null )
115 {
116 demandDashboard.setListNotification( notificationList.getNotifications( ) );
117 }
118 listDemandDashboards.add( demandDashboard );
119 }
120 listDemandDashboards = DemandDashboardHome.selectByDemandIds( listDemandDashboards );
121 }
122
123 model.put( MARK_DEMAND_TYPE_LIST, _notificationService.getListDemandType( ) );
124 model.put( MARK_LIST_DEMAND, listDemandDashboards );
125
126 HtmlTemplate htmTemplate = AppTemplateService.getTemplate( TEMPLATE_LAST_NOTIFICATION_LIST, request.getLocale( ), model );
127
128 return htmTemplate.getHtml( );
129 }
130
131 return StringUtils.EMPTY;
132 }
133
134 @Override
135 public String getComponentId( )
136 {
137 return DASHBOARD_COMPONENT_ID;
138 }
139
140 @Override
141 public String getComponentDescription( Locale locale )
142 {
143 return I18nService.getLocalizedString( MESSAGE_COMPONENT_DESCRIPTION, locale );
144 }
145
146 }