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.RestResource;
16 import com.eviware.soapui.impl.rest.RestService;
17 import com.eviware.soapui.impl.rest.actions.support.NewRestResourceActionBase;
18 import com.eviware.soapui.support.MessageSupport;
19 import com.eviware.soapui.support.UISupport;
20 import com.eviware.x.form.XFormDialog;
21
22 /***
23 * Actions for importing an existing soapUI project file into the current workspace
24 *
25 * @author Ole.Matzura
26 */
27
28 public class NewRestResourceAction extends NewRestResourceActionBase<RestService>
29 {
30 public static final String SOAPUI_ACTION_ID = "NewRestResourceAction";
31 public static final MessageSupport messages = MessageSupport.getMessages( NewRestResourceAction.class );
32
33 public NewRestResourceAction()
34 {
35 super( messages.get( "title" ), messages.get( "description" ) );
36 }
37
38 protected RestResource createRestResource( RestService service, String path, XFormDialog dialog )
39 {
40 RestResource possibleParent = null;
41 String p = service.getBasePath() + path;
42
43 for( RestResource resource : service.getAllResources() )
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 = service.addNewResource( dialog.getValue( Form.RESOURCENAME ), path );
74 }
75
76 return resource;
77 }
78
79 }