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 dialog.getFormField( Form.PARAMSTABLE ).setProperty( "component", paramsTable );
72
73 if( dialog.show() )
74 {
75 RestMethod method = resource.addNewMethod( dialog.getValue( Form.RESOURCENAME ) );
76 method.setMethod( RestRequestInterface.RequestMethod.valueOf( dialog.getValue( Form.METHOD ) ) );
77 paramsTable.extractParams( method.getParams(), ParamLocation.METHOD );
78
79 UISupport.select( method );
80
81 if( dialog.getBooleanValue( Form.CREATEREQUEST ) )
82 {
83 createRequest( method );
84 }
85 }
86 }
87
88 private class MethodInternalRestParamsTable extends InternalRestParamsTable
89 {
90 public MethodInternalRestParamsTable( RestParamsPropertyHolder params, ParamLocation defaultLocation )
91 {
92 super( params, defaultLocation );
93 }
94
95 protected RestParamsTableModel createTableModel( RestParamsPropertyHolder params )
96 {
97 return new InternalRestParamsTableModel( params )
98 {
99 public int getColumnCount()
100 {
101 return super.getColumnCount() - 1;
102 }
103 };
104 }
105 }
106
107 protected void createRequest( RestMethod method )
108 {
109 RestRequest request = method.addNewRequest( "Request " + ( method.getRequestCount() + 1 ) );
110 UISupport.showDesktopPanel( request );
111 }
112
113 @AForm( name = "Form.Title", description = "Form.Description", helpUrl = HelpUrls.NEWRESTSERVICE_HELP_URL, icon = UISupport.TOOL_ICON_PATH )
114 public interface Form
115 {
116 @AField( description = "Form.ResourceName.Description", type = AFieldType.STRING )
117 public final static String RESOURCENAME = messages.get( "Form.ResourceName.Label" );
118
119 @AField( description = "Form.Method.Description", type = AFieldType.ENUMERATION, values = { "GET", "POST", "PUT",
120 "DELETE", "HEAD" } )
121 public final static String METHOD = messages.get( "Form.Method.Label" );
122
123 @AField( description = "Form.ParamsTable.Description", type = AFieldType.COMPONENT )
124 public final static String PARAMSTABLE = messages.get( "Form.ParamsTable.Label" );
125
126 @AField( description = "Form.CreateRequest.Description", type = AFieldType.BOOLEAN )
127 public final static String CREATEREQUEST = messages.get( "Form.CreateRequest.Label" );
128 }
129 }