1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.rest.actions.service;
14
15 import com.eviware.soapui.impl.rest.RestMethod;
16 import com.eviware.soapui.impl.rest.RestRequestInterface;
17 import com.eviware.soapui.impl.rest.RestResource;
18 import com.eviware.soapui.impl.rest.RestService;
19 import com.eviware.soapui.impl.rest.actions.support.NewRestResourceActionBase;
20 import com.eviware.soapui.support.MessageSupport;
21 import com.eviware.soapui.support.UISupport;
22 import com.eviware.x.form.XFormDialog;
23
24 /***
25 * Actions for importing an existing soapUI project file into the current
26 * workspace
27 *
28 * @author Ole.Matzura
29 */
30
31 public class NewRestResourceAction extends NewRestResourceActionBase<RestService>
32 {
33 public static final String SOAPUI_ACTION_ID = "NewRestResourceAction";
34 public static final MessageSupport messages = MessageSupport.getMessages( NewRestResourceAction.class );
35
36 public NewRestResourceAction()
37 {
38 super( messages.get( "title" ), messages.get( "description" ) );
39 }
40
41 protected RestResource createRestResource( RestService service, String path, XFormDialog dialog )
42 {
43 RestResource possibleParent = null;
44 String p = service.getBasePath() + path;
45
46 for( RestResource resource : service.getAllResources() )
47 {
48 if( p.startsWith( resource.getFullPath() ) )
49 {
50 int c = 0;
51 for( ; c < resource.getChildResourceCount(); c++ )
52 {
53 if( p.startsWith( resource.getChildResourceAt( c ).getFullPath() ) )
54 break;
55 }
56
57
58 if( c != resource.getChildResourceCount() )
59 continue;
60
61 possibleParent = resource;
62 break;
63 }
64 }
65
66 RestResource resource;
67
68 if( possibleParent != null
69 && UISupport.confirm( "Create resource as child to [" + possibleParent.getName() + "]",
70 "New Child Resource" ) )
71 {
72
73 path = path.substring( p.length() - possibleParent.getFullPath().length() - 1 );
74 resource = possibleParent.addNewChildResource( dialog.getValue( Form.RESOURCENAME ), path );
75 }
76 else
77 {
78 resource = service.addNewResource( dialog.getValue( Form.RESOURCENAME ), path );
79 }
80
81 return resource;
82 }
83
84 @Override
85 protected RestMethod createRestMethod( RestResource resource, XFormDialog dialog )
86 {
87 RestMethod method = resource.addNewMethod( dialog.getValue( Form.RESOURCENAME ) );
88 method.setMethod( RestRequestInterface.RequestMethod.GET );
89 return method;
90 }
91
92 }