@@ -18,7 +18,7 @@ public class CmdLineUI {
1818 public static final String KILL = "kill" ;
1919 public static final String SETWAITING = "setwaiting" ;
2020 public static final String CREATE_ASAP_ENGINE = "newengine" ;
21- public static final String CREATE_ASAP_STORAGE = "newstorage " ;
21+ public static final String CREATE_ASAP_APP = "newapp " ;
2222 public static final String CREATE_ASAP_CHANNEL = "newchannel" ;
2323 public static final String CREATE_ASAP_MESSAGE = "newmessage" ;
2424 public static final String RESET_ASAP_STORAGES = "resetstorage" ;
@@ -80,8 +80,8 @@ public void printUsage() {
8080 b .append (CREATE_ASAP_ENGINE );
8181 b .append (".. create new asap engine" );
8282 b .append ("\n " );
83- b .append (CREATE_ASAP_STORAGE );
84- b .append (".. create new asap storage" );
83+ b .append (CREATE_ASAP_APP );
84+ b .append (".. create new asap app (== storage) " );
8585 b .append ("\n " );
8686 b .append (CREATE_ASAP_CHANNEL );
8787 b .append (".. create new closed asap channel" );
@@ -143,9 +143,9 @@ public void printUsage(String cmdString, String comment) {
143143 out .println ("example: " + CREATE_ASAP_ENGINE + " Alice" );
144144 out .println ("create engine called Alice - data kept under a folder called tests/Alice" );
145145 break ;
146- case CREATE_ASAP_STORAGE :
147- out .println (CREATE_ASAP_STORAGE + " owner appName" );
148- out .println ("example: " + CREATE_ASAP_STORAGE + " Alice chat" );
146+ case CREATE_ASAP_APP :
147+ out .println (CREATE_ASAP_APP + " owner appName" );
148+ out .println ("example: " + CREATE_ASAP_APP + " Alice chat" );
149149 break ;
150150 case CREATE_ASAP_CHANNEL :
151151 out .println (CREATE_ASAP_CHANNEL + " owner appName uri (recipient)+" );
@@ -216,7 +216,8 @@ public void runCommandLoop() {
216216 this .doSetWaiting (parameterString ); break ;
217217 case CREATE_ASAP_ENGINE :
218218 this .doCreateASAPMultiEngine (parameterString ); break ;
219- case CREATE_ASAP_STORAGE : // same
219+ case CREATE_ASAP_APP : // same
220+ this .doCreateASAPApp (parameterString ); break ;
220221 case CREATE_ASAP_CHANNEL :
221222 this .doCreateASAPChannel (parameterString ); break ;
222223 case CREATE_ASAP_MESSAGE :
@@ -396,39 +397,57 @@ public void doCreateASAPMultiEngine(String parameterString) {
396397 }
397398 }
398399
399- public void doCreateASAPChannel (String parameterString ) {
400+ public void doCreateASAPApp (String parameterString ) {
400401 StringTokenizer st = new StringTokenizer (parameterString );
401402
402403 try {
403404 String owner = st .nextToken ();
404405 String appName = st .nextToken ();
405- String uri = st .nextToken ();
406406
407407 String appFolderName = TESTS_ROOT_FOLDER + "/" + owner + "/" + appName ;
408- String format = "sn2://" + appName ;
409-
410- List <CharSequence > recipients = new ArrayList <>();
411- while (st .hasMoreTokens ()) {
412- recipients .add (st .nextToken ());
413- }
414408
415- ASAPStorage storage = ASAPEngineFS .getASAPStorage (owner , appFolderName , format );
409+ ASAPStorage storage = ASAPEngineFS .getASAPStorage (owner , appFolderName , appName );
416410 if (!storage .isASAPManagementStorageSet ()) {
417411 storage .setASAPManagementStorage (ASAPEngineFS .getASAPStorage (owner ,
418412 TESTS_ROOT_FOLDER + "/" + owner + "/ASAPManagement" ,
419413 ASAP_1_0 .ASAP_MANAGEMENT_FORMAT ));
420414 }
421415
422- if (recipients .size () > 0 ) {
423- storage .createChannel (uri , recipients );
416+ this .storages .put (this .getStorageKey (owner , appName ), storage );
417+ }
418+ catch (RuntimeException e ) {
419+ this .printUsage (CREATE_ASAP_APP , e .getLocalizedMessage ());
420+ } catch (IOException | ASAPException e ) {
421+ this .printUsage (CREATE_ASAP_APP , e .getLocalizedMessage ());
422+ }
423+ }
424+
425+ public void doCreateASAPChannel (String parameterString ) {
426+ StringTokenizer st = new StringTokenizer (parameterString );
427+
428+ try {
429+ String owner = st .nextToken ();
430+ String appName = st .nextToken ();
431+ String uri = st .nextToken ();
432+
433+ ASAPStorage storage = this .storages .get (this .getStorageKey (owner , appName ));
434+
435+ List <CharSequence > recipients = new ArrayList <>();
436+
437+ // one recipient is mandatory - provoke an exception otherwise
438+ recipients .add (st .nextToken ());
439+
440+ // optional recipients
441+ while (st .hasMoreTokens ()) {
442+ recipients .add (st .nextToken ());
424443 }
425444
426- this . storages . put ( this . getStorageKey ( owner , appName ), storage );
445+ storage . createChannel ( uri , recipients );
427446 }
428447 catch (RuntimeException e ) {
429- this .printUsage (CREATE_ASAP_STORAGE , e .getLocalizedMessage ());
448+ this .printUsage (CREATE_ASAP_APP , e .getLocalizedMessage ());
430449 } catch (IOException | ASAPException e ) {
431- this .printUsage (CREATE_ASAP_STORAGE , e .getLocalizedMessage ());
450+ this .printUsage (CREATE_ASAP_APP , e .getLocalizedMessage ());
432451 }
433452 }
434453
0 commit comments