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
35 public NewRestChildResourceAction()
36 {
37 super( messages.get( "title" ), messages.get( "description" ) );
38 }
39
40 protected RestResource createRestResource( RestResource parentResource, String path, XFormDialog dialog )
41 {
42 RestResource possibleParent = null;
43 String p = parentResource.getFullPath() + path;
44
45 for( RestResource resource : parentResource.getAllChildResources() )
46 {
47 if( p.startsWith( resource.getFullPath() ) )
48 {
49 int c = 0;
50 for( ; c < resource.getChildResourceCount(); c++ )
51 {
52 if( p.startsWith( resource.getChildResourceAt( c ).getFullPath() ) )
53 break;
54 }
55
56
57 if( c != resource.getChildResourceCount() )
58 continue;
59
60 possibleParent = resource;
61 break;
62 }
63 }
64
65 RestResource resource;
66
67 if( possibleParent != null
68 && UISupport.confirm( "Create resource as child to [" + possibleParent.getName() + "]",
69 "New Child Resource" ) )
70 {
71
72 path = path.substring( p.length() - possibleParent.getFullPath().length() - 1 );
73 resource = possibleParent.addNewChildResource( dialog.getValue( Form.RESOURCENAME ), path );
74 }
75 else
76 {
77 resource = parentResource.addNewChildResource( dialog.getValue( Form.RESOURCENAME ), path );
78 }
79
80 return resource;
81 }
82
83 @Override
84 protected RestMethod createRestMethod( RestResource resource, XFormDialog dialog )
85 {
86 RestMethod method = resource.addNewMethod( dialog.getValue( Form.RESOURCENAME ) );
87 method.setMethod( RestRequestInterface.RequestMethod.GET );
88 return method;
89 }
90 }