View Javadoc
1   /*
2    * Copyright (c) 2002-2020, City of 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.appcenter.modules.fastdeployapplication.service;
35  
36  import java.util.ArrayList;
37  import java.util.Comparator;
38  import java.util.HashMap;
39  import java.util.List;
40  import java.util.Locale;
41  import java.util.Map.Entry;
42  
43  import fr.paris.lutece.plugins.appcenter.modules.fastdeployapplication.business.CommandResult;
44  import fr.paris.lutece.plugins.appcenter.modules.fastdeployapplication.business.FastDeployApplicationData;
45  import fr.paris.lutece.plugins.appcenter.modules.fastdeployapplication.business.ServerApplicationInstance;
46  import fr.paris.lutece.plugins.appcenter.modules.fastdeployapplication.business.fastaction.ActionParameter;
47  import fr.paris.lutece.plugins.appcenter.modules.fastdeployapplication.business.fastaction.IAction;
48  import fr.paris.lutece.plugins.appcenter.modules.fastdeployapplication.util.DeploymentUtils;
49  import fr.paris.lutece.portal.service.i18n.I18nService;
50  import fr.paris.lutece.portal.service.spring.SpringContextService;
51  
52  public abstract class AbstractActionService implements IActionService
53  {
54      protected HashMap<String, IAction> _hashServerApplicationAction;
55  
56      public List<IAction> getListAction( Locale locale )
57      {
58          List<IAction> listActions = new ArrayList<IAction>( );
59          IAction action;
60  
61          for ( Entry<String, IAction> entry : _hashServerApplicationAction.entrySet( ) )
62          {
63              action = entry.getValue( );
64              action.setName( I18nService.getLocalizedString( action.getI18nKeyName( ), locale ) );
65              listActions.add( action );
66          }
67  
68          listActions.sort( Comparator.comparing( IAction::getName ) );
69          return listActions;
70      }
71  
72      @Override
73      public boolean executeAction( FastDeployApplicationData data, IAction action, ServerApplicationInstance serverApplicationInstance,
74              CommandResult commandResult, ActionParameter... parameter )
75      {
76          // TODO Auto-generated method stub
77          String strResult = action.run( data, serverApplicationInstance, commandResult, parameter );
78          boolean bResult = false;
79          // set status action
80          if ( strResult != null )
81          {
82              bResult = new Boolean( strResult );
83  
84          }
85  
86          if ( commandResult != null )
87          {
88              commandResult.setStatus( bResult ? CommandResult.STATUS_OK : CommandResult.STATUS_ERROR );
89          }
90          return bResult;
91      }
92  
93      @Override
94      public boolean canExecuteAction( FastDeployApplicationData data, IAction action, ServerApplicationInstance serverApplicationInstance,
95              CommandResult commandResult, ActionParameter... parameter )
96      {
97          // TODO Auto-generated method stub
98          return action.canRunAction( data, serverApplicationInstance, commandResult, parameter );
99      }
100 
101     @Override
102     public String getTemplateFormAction( FastDeployApplicationData data, IAction action, ServerApplicationInstance serverApplicationInstance, Locale locale )
103     {
104         // TODO Auto-generated method stub
105         return action.getTemplateFormAction( data, serverApplicationInstance, locale );
106     }
107 
108     @Override
109     public boolean isDisplayFormAction( FastDeployApplicationData data, IAction action, ServerApplicationInstance serverApplicationInstance )
110     {
111 
112         return action.isDisplayFormAction( data, serverApplicationInstance );
113     }
114 
115     public IAction getAction( String strKey, Locale locale )
116     {
117 
118         IAction serverApplicationAction = _hashServerApplicationAction.get( strKey );
119 
120         if ( serverApplicationAction != null )
121         {
122             serverApplicationAction.setName( I18nService.getLocalizedString( serverApplicationAction.getI18nKeyName( ), locale ) );
123         }
124 
125         return serverApplicationAction;
126     }
127 
128 }