1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.rest.actions.resource;
14
15 import com.eviware.soapui.config.RestParametersConfig;
16 import com.eviware.soapui.impl.rest.RestMethod;
17 import com.eviware.soapui.impl.rest.RestRequest;
18 import com.eviware.soapui.impl.rest.RestRequestInterface;
19 import com.eviware.soapui.impl.rest.RestResource;
20 import com.eviware.soapui.impl.rest.actions.support.NewRestResourceActionBase.InternalRestParamsTable;
21 import com.eviware.soapui.impl.rest.actions.support.NewRestResourceActionBase.ParamLocation;
22 import com.eviware.soapui.impl.rest.panels.resource.RestParamsTableModel;
23 import com.eviware.soapui.impl.rest.support.RestParamsPropertyHolder;
24 import com.eviware.soapui.impl.rest.support.XmlBeansRestParamsTestPropertyHolder;
25 import com.eviware.soapui.impl.wsdl.support.HelpUrls;
26 import com.eviware.soapui.support.MessageSupport;
27 import com.eviware.soapui.support.UISupport;
28 import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
29 import com.eviware.x.form.XFormDialog;
30 import com.eviware.x.form.support.ADialogBuilder;
31 import com.eviware.x.form.support.AField;
32 import com.eviware.x.form.support.AForm;
33 import com.eviware.x.form.support.AField.AFieldType;
34
35 /***
36 * Actions for importing an existing soapUI project file into the current
37 * workspace
38 *
39 * @author Ole.Matzura
40 */
41
42 public class NewRestMethodAction extends AbstractSoapUIAction<RestResource>
43 {
44 public static final String SOAPUI_ACTION_ID = "NewRestMethodAction";
45 public static final MessageSupport messages = MessageSupport.getMessages( NewRestMethodAction.class );
46 private XFormDialog dialog;
47 private XmlBeansRestParamsTestPropertyHolder params;
48 private InternalRestParamsTable paramsTable;
49
50 public NewRestMethodAction()
51 {
52 super( messages.get( "title" ), messages.get( "description" ) );
53 }
54
55 public void perform( RestResource resource, Object param )
56 {
57 if( dialog == null )
58 {
59 dialog = ADialogBuilder.buildDialog( Form.class );
60 dialog.setBooleanValue( Form.CREATEREQUEST, true );
61 }
62
63 dialog.setValue( Form.RESOURCENAME, "Method " + ( resource.getRestMethodCount() + 1 ) );
64
65 if( param instanceof XmlBeansRestParamsTestPropertyHolder )
66 params = ( XmlBeansRestParamsTestPropertyHolder )param;
67 else
68 params = new XmlBeansRestParamsTestPropertyHolder( null, RestParametersConfig.Factory.newInstance() );
69
70 paramsTable = new MethodInternalRestParamsTable( params, ParamLocation.METHOD )
71 {
72 public int getColumnCount()
73 {
74 return getColumnCount() - 1;
75 }
76 };
77 dialog.getFormField( Form.PARAMSTABLE ).setProperty( "component", paramsTable );
78
79 if( dialog.show() )
80 {
81 RestMethod method = resource.addNewMethod( dialog.getValue( Form.RESOURCENAME ) );
82 method.setMethod( RestRequestInterface.RequestMethod.valueOf( dialog.getValue( Form.METHOD ) ) );
83 paramsTable.extractParams( method.getParams(), ParamLocation.METHOD );
84
85 UISupport.select( method );
86
87 if( dialog.getBooleanValue( Form.CREATEREQUEST ) )
88 {
89 createRequest( method );
90 }
91 }
92 }
93
94 private class MethodInternalRestParamsTable extends InternalRestParamsTable
95 {
96
97 public MethodInternalRestParamsTable( RestParamsPropertyHolder params, ParamLocation defaultLocation )
98 {
99 super( params, defaultLocation );
100 }
101
102 protected RestParamsTableModel createTableModel( RestParamsPropertyHolder params )
103 {
104 return new InternalRestParamsTableModel( params )
105 {
106 public int getColumnCount()
107 {
108 return super.getColumnCount() - 1;
109 }
110 };
111 }
112 }
113
114 protected void createRequest( RestMethod method )
115 {
116 RestRequest request = method.addNewRequest( "Request " + ( method.getRequestCount() + 1 ) );
117 UISupport.showDesktopPanel( request );
118 }
119
120 @AForm( name = "Form.Title", description = "Form.Description", helpUrl = HelpUrls.NEWRESTSERVICE_HELP_URL, icon = UISupport.TOOL_ICON_PATH )
121 public interface Form
122 {
123 @AField( description = "Form.ResourceName.Description", type = AFieldType.STRING )
124 public final static String RESOURCENAME = messages.get( "Form.ResourceName.Label" );
125
126 @AField( description = "Form.Method.Description", type = AFieldType.ENUMERATION, values = { "GET", "POST", "PUT",
127 "DELETE", "HEAD" } )
128 public final static String METHOD = messages.get( "Form.Method.Label" );
129
130 @AField( description = "Form.ParamsTable.Description", type = AFieldType.COMPONENT )
131 public final static String PARAMSTABLE = messages.get( "Form.ParamsTable.Label" );
132
133 @AField( description = "Form.CreateRequest.Description", type = AFieldType.BOOLEAN )
134 public final static String CREATEREQUEST = messages.get( "Form.CreateRequest.Label" );
135 }
136 }