View Javadoc
1   package fr.paris.lutece.plugins.appcenter.modules.openam.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  import org.apache.poi.ss.formula.functions.T;
13  
14  import fr.paris.lutece.plugins.appcenter.business.Application;
15  import fr.paris.lutece.plugins.appcenter.business.ApplicationHome;
16  import fr.paris.lutece.plugins.appcenter.business.Demand;
17  import fr.paris.lutece.plugins.appcenter.business.DemandHome;
18  import fr.paris.lutece.plugins.appcenter.modules.openam.business.OpenamAgentData;
19  import fr.paris.lutece.plugins.appcenter.modules.openam.business.OpenamDemand;
20  import fr.paris.lutece.plugins.appcenter.web.Constants;
21  import fr.paris.lutece.plugins.workflow.web.task.NoConfigTaskComponent;
22  import fr.paris.lutece.plugins.workflowcore.business.resource.ResourceHistory;
23  import fr.paris.lutece.plugins.workflowcore.service.resource.IResourceHistoryService;
24  import fr.paris.lutece.plugins.workflowcore.service.task.ITask;
25  import fr.paris.lutece.portal.service.message.AdminMessage;
26  import fr.paris.lutece.portal.service.message.AdminMessageService;
27  import fr.paris.lutece.portal.service.template.AppTemplateService;
28  import fr.paris.lutece.util.bean.BeanUtil;
29  import fr.paris.lutece.util.beanvalidation.BeanValidationUtil;
30  import fr.paris.lutece.util.html.HtmlTemplate;
31  
32  public class OpenamTaskComponent extends NoConfigTaskComponent
33  {
34      // TEMPLATES
35      private static final String TEMPLATE_OPENAM_TASK_FORM = "admin/plugins/appcenter/modules/openam/openam_task_form.html";
36      private static final String TEMPLATE_OPENAM_DISPLAY_HISTORY = "admin/plugins/appcenter/modules/openam/openam_task_history.html";
37  
38      // MESSAGES
39      private static final String MESSAGE_MANDATORY_FIELD = "portal.util.message.mandatoryFields";
40  
41      // MARKS
42  
43      @Inject
44      private IResourceHistoryService _resourceHistoryService;
45  
46      /**
47       * {@inheritDoc}
48       */
49      @Override
50      public String getDisplayTaskForm( int nIdResource, String strResourceType, HttpServletRequest request, Locale locale, ITask task )
51      {
52          Map<String, Object> model = new HashMap<String, Object>( );
53  
54          OpenamDemand demand = DemandHome.findByPrimaryKey( nIdResource, OpenamDemand.class );
55          if ( demand != null )
56          {
57              model.put( Constants.MARK_DEMAND, demand );
58              Application application = ApplicationHome.findByPrimaryKey( demand.getIdApplication( ) );
59              model.put( Constants.MARK_APPLICATION, application );
60  
61          }
62  
63          HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_OPENAM_TASK_FORM, locale, model );
64  
65          return template.getHtml( );
66      }
67  
68      /**
69       * {@inheritDoc}
70       */
71      @Override
72      public String doValidateTask( int nIdResource, String strResourceType, HttpServletRequest request, Locale locale, ITask task )
73      {
74          OpenamAgentDatamodules/openam/business/OpenamAgentData.html#OpenamAgentData">OpenamAgentData openamAgentData = new OpenamAgentData( );
75          BeanUtil.populate( openamAgentData, request );
76  
77  
78          //FIXME return real error message here
79          
80          Set<ConstraintViolation<OpenamAgentData>> errors = BeanValidationUtil.validate( openamAgentData );
81          if ( !errors.isEmpty() )
82          {
83          
84          	for ( ConstraintViolation<OpenamAgentData> constraint : errors )
85              {
86          	
87          		
88          		return constraint.getMessage();
89              }
90          	
91             
92          }
93  
94          return null;
95      }
96  
97      /**
98       * {@inheritDoc}
99       */
100     @Override
101     public String getDisplayTaskInformation( int nIdHistory, HttpServletRequest request, Locale locale, ITask task )
102     {
103         ResourceHistory resourceHistory = _resourceHistoryService.findByPrimaryKey( nIdHistory );
104         Demand demand = DemandHome.findByPrimaryKey( resourceHistory.getIdResource( ) );
105         // FIXME Load datasubset associated with this demand
106 
107         Map<String, Object> model = new HashMap<String, Object>( );
108         // model.put( MARK_HISTORY_LIST, listHistory );
109         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_OPENAM_DISPLAY_HISTORY, locale, model );
110         return template.getHtml( );
111     }
112 
113     /**
114      * {@inheritDoc}
115      */
116     @Override
117     public String getTaskInformationXml( int nIdHistory, HttpServletRequest request, Locale locale, ITask task )
118     {
119         return null;
120     }
121 }