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.RestResource;
16 import com.eviware.soapui.impl.rest.actions.support.NewRestResourceActionBase;
17 import com.eviware.soapui.support.MessageSupport;
18 import com.eviware.soapui.support.UISupport;
19 import com.eviware.x.form.XFormDialog;
20
21 /***
22 * Actions for importing an existing soapUI project file into the current workspace
23 *
24 * @author Ole.Matzura
25 */
26
27 public class NewRestChildResourceAction extends NewRestResourceActionBase<RestResource>
28 {
29 public static final String SOAPUI_ACTION_ID = "NewRestChildResourceAction";
30 public static final MessageSupport messages = MessageSupport.getMessages( NewRestChildResourceAction.class );
31 private XFormDialog dialog;
32
33 public NewRestChildResourceAction()
34 {
35 super( messages.get( "title" ), messages.get( "description" ) );
36 }
37
38 protected RestResource createRestResource( RestResource parentResource, String path, XFormDialog dialog )
39 {
40 RestResource possibleParent = null;
41 String p = parentResource.getFullPath() + path;
42
43 for( RestResource resource : parentResource.getAllChildResources() )
44 {
45 if( p.startsWith( resource.getFullPath() ) )
46 {
47 int c = 0;
48 for( ; c < resource.getChildResourceCount(); c++ )
49 {
50 if( p.startsWith( resource.getChildResourceAt( c ).getFullPath() ) )
51 break;
52 }
53
54
55 if( c != resource.getChildResourceCount() )
56 continue;
57
58 possibleParent = resource;
59 break;
60 }
61 }
62
63 RestResource resource;
64
65 if( possibleParent != null && UISupport.confirm( "Create resource as child to [" + possibleParent.getName() + "]", "New Child Resource" ) )
66 {
67
68 path = path.substring( p.length() - possibleParent.getFullPath().length() - 1 );
69 resource = possibleParent.addNewChildResource( dialog.getValue( Form.RESOURCENAME ), path );
70 }
71 else
72 {
73 resource = parentResource.addNewChildResource( dialog.getValue( Form.RESOURCENAME ), path );
74 }
75
76 return resource;
77 }
78 }