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 package com.eviware.soapui.impl.wsdl.actions.project;
26
27 import java.io.File;
28
29 import com.eviware.soapui.impl.rest.RestService;
30 import com.eviware.soapui.impl.rest.RestServiceFactory;
31 import com.eviware.soapui.impl.rest.support.WadlImporter;
32 import com.eviware.soapui.impl.wsdl.WsdlProject;
33 import com.eviware.soapui.impl.wsdl.support.HelpUrls;
34 import com.eviware.soapui.impl.wsdl.support.PathUtils;
35 import com.eviware.soapui.model.propertyexpansion.DefaultPropertyExpansionContext;
36 import com.eviware.soapui.model.propertyexpansion.PropertyExpansionContext;
37 import com.eviware.soapui.support.MessageSupport;
38 import com.eviware.soapui.support.StringUtils;
39 import com.eviware.soapui.support.UISupport;
40 import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
41 import com.eviware.x.form.XFormDialog;
42 import com.eviware.x.form.XFormField;
43 import com.eviware.x.form.XFormFieldListener;
44 import com.eviware.x.form.support.ADialogBuilder;
45 import com.eviware.x.form.support.AField;
46 import com.eviware.x.form.support.AForm;
47 import com.eviware.x.form.support.AField.AFieldType;
48
49 /***
50 * Action for creating a new WSDL project
51 *
52 * @author Ole.Matzura
53 */
54
55 public class AddWadlAction extends AbstractSoapUIAction<WsdlProject>
56 {
57 public static final String SOAPUI_ACTION_ID = "NewWsdlProjectAction";
58 private XFormDialog dialog;
59
60 public static final MessageSupport messages = MessageSupport.getMessages( AddWadlAction.class );
61
62 public AddWadlAction()
63 {
64 super( messages.get( "Title" ), messages.get( "Description" ) );
65 }
66
67 public void perform( WsdlProject project, Object param )
68 {
69 PropertyExpansionContext context = new DefaultPropertyExpansionContext( project.getModelItem() );
70 if( dialog == null )
71 {
72 dialog = ADialogBuilder.buildDialog( Form.class );
73 dialog.getFormField( Form.INITIALWSDL ).addFormFieldListener( new XFormFieldListener()
74 {
75 public void valueChanged( XFormField sourceField, String newValue, String oldValue )
76 {
77 String value = newValue.toLowerCase().trim();
78
79 dialog.getFormField( Form.GENERATETESTSUITE ).setEnabled( newValue.trim().length() > 0 );
80 }
81 } );
82 }
83 else
84 {
85 dialog.setValue( Form.INITIALWSDL, "" );
86 dialog.getFormField( Form.GENERATETESTSUITE ).setEnabled( false );
87 }
88
89 while( dialog.show() )
90 {
91 try
92 {
93 String url = dialog.getValue( Form.INITIALWSDL ).trim();
94 if( StringUtils.hasContent( url ) )
95 {
96 String expUrl = PathUtils.expandPath( url, project );
97
98 if( new File( expUrl ).exists() )
99 expUrl = new File( expUrl ).toURI().toURL().toString();
100
101 RestService result = importWadl( project, expUrl );
102 if( !url.equals( expUrl ) && result != null )
103 {
104 result.setWadlUrl( url );
105 }
106 break;
107 }
108 }
109 catch( Exception ex )
110 {
111 UISupport.showErrorMessage( ex );
112 }
113 }
114 }
115
116 private RestService importWadl( WsdlProject project, String url )
117 {
118 RestService restService = ( RestService )project
119 .addNewInterface( project.getName(), RestServiceFactory.REST_TYPE );
120 UISupport.select( restService );
121 try
122 {
123 new WadlImporter( restService ).initFromWadl( url );
124 }
125 catch( Exception e )
126 {
127 UISupport.showErrorMessage( e );
128 }
129
130 return restService;
131 }
132
133 @AForm( name = "Form.Title", description = "Form.Description", helpUrl = HelpUrls.NEWPROJECT_HELP_URL, icon = UISupport.TOOL_ICON_PATH )
134 public interface Form
135 {
136 @AField( description = "Form.InitialWadl.Description", type = AFieldType.FILE )
137 public final static String INITIALWSDL = messages.get( "Form.InitialWadl.Label" );
138
139 @AField( description = "Form.GenerateTestSuite.Description", type = AFieldType.BOOLEAN, enabled = false )
140 public final static String GENERATETESTSUITE = messages.get( "Form.GenerateTestSuite.Label" );
141 }
142 }