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.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.actions.support.NewRestResourceActionBase;
19 import com.eviware.soapui.support.MessageSupport;
20 import com.eviware.soapui.support.UISupport;
21 import com.eviware.x.form.XFormDialog;
22
23 /***
24 * Actions for importing an existing soapUI project file into the current
25 * workspace
26 *
27 * @author Ole.Matzura
28 */
29
30 public class NewRestChildResourceAction extends NewRestResourceActionBase<RestResource>
31 {
32 public static final String SOAPUI_ACTION_ID = "NewRestChildResourceAction";
33 public static final MessageSupport messages = MessageSupport.getMessages( NewRestChildResourceAction.class );
34 private XFormDialog dialog;
35
36 public NewRestChildResourceAction()
37 {
38 super( messages.get( "title" ), messages.get( "description" ) );
39 }
40
41 protected RestResource createRestResource( RestResource parentResource, String path, XFormDialog dialog )
42 {
43 RestResource possibleParent = null;
44 String p = parentResource.getFullPath() + path;
45
46 for( RestResource resource : parentResource.getAllChildResources() )
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 = parentResource.addNewChildResource( 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 }