View Javadoc
1   package fr.paris.lutece.plugins.appcenter.modules.support.web;
2   
3   import java.util.HashMap;
4   import java.util.Locale;
5   import java.util.Map;
6   import java.util.Set;
7   
8   import javax.inject.Inject;
9   import javax.servlet.http.HttpServletRequest;
10  import javax.validation.ConstraintViolation;
11  
12  
13  import fr.paris.lutece.plugins.appcenter.business.Application;
14  import fr.paris.lutece.plugins.appcenter.business.ApplicationHome;
15  import fr.paris.lutece.plugins.appcenter.business.Demand;
16  import fr.paris.lutece.plugins.appcenter.business.DemandHome;
17  import fr.paris.lutece.plugins.appcenter.modules.support.business.SupportData;
18  import fr.paris.lutece.plugins.appcenter.modules.support.business.SupportDemand;
19  import fr.paris.lutece.plugins.appcenter.web.Constants;
20  import fr.paris.lutece.plugins.workflow.web.task.NoConfigTaskComponent;
21  import fr.paris.lutece.plugins.workflowcore.business.resource.ResourceHistory;
22  import fr.paris.lutece.plugins.workflowcore.service.resource.IResourceHistoryService;
23  import fr.paris.lutece.plugins.workflowcore.service.task.ITask;
24  import fr.paris.lutece.portal.service.template.AppTemplateService;
25  import fr.paris.lutece.util.bean.BeanUtil;
26  import fr.paris.lutece.util.beanvalidation.BeanValidationUtil;
27  import fr.paris.lutece.util.html.HtmlTemplate;
28  
29  public class SupportTaskComponent extends NoConfigTaskComponent
30  {
31      // TEMPLATES
32      private static final String TEMPLATE_SUPPORT_TASK_FORM = "admin/plugins/appcenter/modules/support/support_task_form.html";
33      private static final String TEMPLATE_SUPPORT_DISPLAY_HISTORY = "admin/plugins/appcenter/modules/support/support_task_history.html";
34  
35      // MESSAGES
36      private static final String MESSAGE_MANDATORY_FIELD = "portal.util.message.mandatoryFields";
37  
38  
39      @Inject
40      private IResourceHistoryService _resourceHistoryService;
41  
42      /**
43       * {@inheritDoc}
44       */
45      @Override
46      public String getDisplayTaskForm( int nIdResource, String strResourceType, HttpServletRequest request, Locale locale, ITask task )
47      {
48          Map<String, Object> model = new HashMap<>( );
49  
50          SupportDemand demand = DemandHome.findByPrimaryKey( nIdResource, SupportDemand.class );
51          if ( demand != null )
52          {
53              model.put( Constants.MARK_DEMAND, demand );
54              Application application = ApplicationHome.findByPrimaryKey( demand.getIdApplication( ) );
55              model.put( Constants.MARK_APPLICATION, application );
56  
57          }
58  
59          HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_SUPPORT_TASK_FORM, locale, model );
60  
61          return template.getHtml( );
62      }
63  
64      /**
65       * {@inheritDoc}
66       */
67      @Override
68      public String doValidateTask( int nIdResource, String strResourceType, HttpServletRequest request, Locale locale, ITask task )
69      {
70          SupportDatapcenter/modules/support/business/SupportData.html#SupportData">SupportData supportData = new SupportData( );
71          BeanUtil.populate( supportData, request );
72  
73  
74          //FIXME return real error message here
75          
76          Set<ConstraintViolation<SupportData>> errors = BeanValidationUtil.validate( supportData );
77          if ( !errors.isEmpty() )
78          {
79              for ( ConstraintViolation<SupportData> constraint : errors )
80              {
81          		return constraint.getMessage();
82              }
83          }
84  
85          return null;
86      }
87  
88      /**
89       * {@inheritDoc}
90       */
91      @Override
92      public String getDisplayTaskInformation( int nIdHistory, HttpServletRequest request, Locale locale, ITask task )
93      {
94          ResourceHistory resourceHistory = _resourceHistoryService.findByPrimaryKey( nIdHistory );
95          Demand demand = DemandHome.findByPrimaryKey( resourceHistory.getIdResource( ) );
96          // FIXME Load datasubset associated with this demand
97  
98          Map<String, Object> model = new HashMap<>( );
99          // model.put( MARK_HISTORY_LIST, listHistory );
100         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_SUPPORT_DISPLAY_HISTORY, locale, model );
101         return template.getHtml( );
102     }
103 
104     /**
105      * {@inheritDoc}
106      */
107     @Override
108     public String getTaskInformationXml( int nIdHistory, HttpServletRequest request, Locale locale, ITask task )
109     {
110         return null;
111     }
112 }