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.deployment.business;
35
36 import java.util.HashMap;
37 import java.util.Locale;
38
39 import net.sf.json.JSONObject;
40
41 import org.apache.commons.lang.StringUtils;
42
43 import fr.paris.lutece.plugins.deployment.service.IDatabaseService;
44 import fr.paris.lutece.plugins.deployment.util.ConstanteUtils;
45 import fr.paris.lutece.plugins.deployment.util.DeploymentUtils;
46 import fr.paris.lutece.portal.service.spring.SpringContextService;
47 import fr.paris.lutece.portal.service.template.AppTemplateService;
48 import fr.paris.lutece.portal.service.util.AppLogService;
49 import fr.paris.lutece.portal.service.util.AppPropertiesService;
50 import fr.paris.lutece.util.html.HtmlTemplate;
51
52
53
54
55
56
57 public class DumpAction extends DefaultAction
58 {
59 private IDatabaseService _databaseService = SpringContextService.getBean( "deployment.DatabaseService" );
60
61 @Override
62 public String run( Application application, ServerApplicationInstance serverApplicationInstance, CommandResult commandResult, ActionParameter... parameter )
63 {
64
65 String strResult = null;
66
67 String strDataBase = null;
68 for ( int i = 0; i < parameter.length; i++ )
69 {
70
71 if ( parameter [i].getName( ).equals( ConstanteUtils.PARAM_CODE_DATABASE ) )
72 {
73
74 strDataBase = parameter [i].getValue( );
75 }
76 }
77
78 if ( !StringUtils.isEmpty( strDataBase ) )
79 {
80 String strPlateformEnvironmentBaseUrl = AppPropertiesService.getProperty( ConstanteUtils.PROPERTY_ENVIRONMENT_PLATEFORM_BASE_URL );
81 String strWebserviceActionJsonPropery = AppPropertiesService.getProperty( ConstanteUtils.PROPERTY_WEBSERVICE_ACTION_RESULT_JSON_PROPERTY_RESULT );
82 String strJSONDump = null;
83
84 try
85 {
86 strJSONDump = DeploymentUtils.callPlateformEnvironmentWs( strPlateformEnvironmentBaseUrl + ConstanteUtils.CONSTANTE_SEPARATOR_SLASH
87 + DeploymentUtils.getPlateformUrlServerApplicationAction( application.getCode( ), serverApplicationInstance, this.getCode( ) )
88 + ConstanteUtils.CONSTANTE_SEPARATOR_SLASH + strDataBase + ConstanteUtils.CONSTANTE_SEPARATOR_SLASH + ConstanteUtils.CONSTANTE_STAR );
89 }
90 catch( Exception e )
91 {
92 DeploymentUtils.addTechnicalError( commandResult, "<h1>Erreur lors de l'exécution de la commande" + this.getCode( )
93 + " de cloudmgrws</h1> <br> " + e.getMessage( ), e );
94 AppLogService.error( e );
95
96 }
97
98 if ( strJSONDump != null )
99 {
100 JSONObject jo = DeploymentUtils.getJSONOBject( strJSONDump );
101
102 if ( jo != null )
103 {
104 strResult = jo.getString( strWebserviceActionJsonPropery );
105 if ( strResult != null && !new Boolean( strResult ) )
106 {
107
108 DeploymentUtils.addTechnicalError( commandResult, "<h1>Erreur lors de l'exécution de la commande" + this.getCode( )
109 + " de cloudmgrws</h1> <br> " + strJSONDump );
110
111 }
112 }
113 commandResult.getResultInformations( ).put(
114 ConstanteUtils.MARK_DUMP_FILE_URL,
115 "servlet/plugins/deployment/download?code_application=" + application.getIdApplication( ) + "&code_environment="
116 + serverApplicationInstance.getCodeEnvironment( ) + "&code_server_application_instance_sql="
117 + serverApplicationInstance.getCode( ) + "&code_database=" + strDataBase + "&plugin_name=deployment"
118 + "&server_application_type=" + serverApplicationInstance.getType( ) );
119
120 }
121 }
122
123 return strResult;
124 }
125
126 @Override
127 public boolean canRunAction( Application application, ServerApplicationInstance serverApplicationInstance, CommandResult commandResult,
128 ActionParameter... parameter )
129 {
130
131 String strDataBase = null;
132 for ( int i = 0; i < parameter.length; i++ )
133 {
134
135 if ( parameter [i].getName( ).equals( ConstanteUtils.PARAM_CODE_DATABASE ) )
136 {
137
138 strDataBase = parameter [i].getValue( );
139 }
140 }
141
142 return !StringUtils.isEmpty( strDataBase );
143 }
144
145 @Override
146 public String getTemplateFormAction( Application application, ServerApplicationInstance serverApplicationInstance, Locale locale )
147 {
148
149 HashMap model = new HashMap( );
150
151 model.put( ConstanteUtils.MARK_DATABASE_LIST,
152 DeploymentUtils.getSimpleReferenceList( _databaseService.getDatabases( application.getCode( ), serverApplicationInstance, locale ) ) );
153
154 HtmlTemplate template = AppTemplateService.getTemplate( ConstanteUtils.TEMPLATE_FORM_ACTION_DUMP, locale, model );
155
156 return template.getHtml( );
157 }
158 }