[Title] Fixed tempalte create and search logic
authorgyeongseok.seo <gyeongseok.seo@samsung.com>
Tue, 21 May 2013 10:25:46 +0000 (19:25 +0900)
committergyeongseok.seo <gyeongseok.seo@samsung.com>
Wed, 22 May 2013 04:49:01 +0000 (13:49 +0900)
[Desc.] search result sorting print
[Issue]

Change-Id: I6bed3dc991fa08097707647dba23b25bd510c6fd

org.tizen.cli/src/org/tizen/cli/command/CreateTemplate.java
org.tizen.cli/src/org/tizen/cli/command/SearchTemplate.java
org.tizen.cli/src/org/tizen/cli/exec/AbstractLauncher.java

index 43887e4..cefa283 100755 (executable)
@@ -34,7 +34,7 @@ import org.tizen.common.verrari.Storage;
 import org.tizen.common.verrari.Template;
 import org.tizen.common.verrari.TemplateContext;
 import org.tizen.common.verrari.TemplateException;
-import org.tizen.common.verrari.realm.StandardRealm;
+import org.tizen.common.verrari.realm.CommonRealm;
 import org.tizen.common.verrari.storage.FileStorage;
 import org.tizen.common.verrari.template.TemplateConstants;
 
@@ -111,7 +111,7 @@ implements CommandWithParameter
             }
             cache.put( name, template );
             template.template( models, storage );
-            final String[] dependencies = StandardRealm.separate( template.getAttribute( TemplateConstants.ATTR_DEPENDENCY ) );
+            final String[] dependencies = CommonRealm.separate( template.getAttribute( TemplateConstants.ATTR_DEPENDENCY ) );
             if ( null == dependencies )
             {
                 continue;
index a29564a..97749e5 100755 (executable)
@@ -29,6 +29,8 @@ import static org.tizen.common.util.StringUtil.isEmpty;
 
 import java.io.IOException;
 import java.util.Collection;
+import java.util.Iterator;
+import java.util.TreeSet;
 
 import org.tizen.common.core.command.ExecutionContext;
 import org.tizen.common.verrari.AttributeContainer;
@@ -43,19 +45,13 @@ extends AbstractCommand
 implements CommandWithParameter
 {
 
-    @Override
-    public void process(
+    protected void
+    search(
+        final Realm realm,
         final ExecutionContext context,
         final String[] args
     ) throws IOException
     {
-        if ( null == args || 0 == args.length )
-        {
-            context.getPrompter().error( "A keyword required." );
-            return ;
-        }
-        final Realm realm = (Realm) context.getValue( PluginConstants.REALM );
-        
         if ( !( realm instanceof SearchableRealm ) )
         {
             context.getPrompter().error( "Search unsupported realm." );
@@ -73,12 +69,23 @@ implements CommandWithParameter
             context.getPrompter().notify( "No template with '" + keyword  + "'." );
             return ;
         }
+
+        TreeSet<String> sortTree = new TreeSet<String>();
         for ( final AttributeContainer template : templates )
         {
             final StringBuilder buffer = new StringBuilder();
             final String name = template.getAttribute( TemplateConstants.ATTR_NAME );
             final String desc = template.getAttribute( TemplateConstants.ATTR_DESCRIPTION );
+            final String version = template.getAttribute( TemplateConstants.ATTR_VERSION );
+
             buffer.append( name );
+            if ( !isEmpty( version ) )
+            {
+                buffer.append( " ( " );
+                buffer.append( version );
+                buffer.append( " ) " );
+            }
+            
             buffer.append( " - " );
             if ( isEmpty( desc ) )
             {
@@ -88,9 +95,32 @@ implements CommandWithParameter
             {
                 buffer.append( desc );
             }
-            
-            context.getPrompter().notify( buffer.toString() + "." );
+
+            sortTree.add( buffer.toString() );
+        }
+
+        // search result notify
+        Iterator<String> iter = sortTree.iterator();
+        while ( iter.hasNext() ) {
+            context.getPrompter().notify( iter.next() + "." );
         }
     }
 
+    /* (non-Javadoc)
+     * @see org.tizen.cli.command.CommandWithParameter#process(org.tizen.common.core.command.ExecutionContext, java.lang.String[])
+     */
+    @Override
+    public void process(
+        final ExecutionContext context,
+        final String[] args
+    ) throws IOException
+    {
+        if ( null == args || 0 == args.length )
+        {
+            context.getPrompter().error( "A keyword required." );
+            return ;
+        }
+        final Realm realm = (Realm) context.getValue( PluginConstants.REALM );
+        search( realm, context, args );
+    }
 }
index 505b37e..32b4d5f 100755 (executable)
@@ -470,6 +470,7 @@ AbstractLauncher
        {
                getPrompter().error( e.getMessage() );
                logger.error( "Command stop because of exception", e );
+
                Throwable iter = e;
                while ( null != iter )
                {