Author: tyrell
Date: Tue Feb 17 06:56:46 2009
New Revision: 31003
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=31003

Log:
Making typeahead more informative.

Added:
   
branches/mashup/java/1.5/java/modules/coreservices/servicemetadatalister/src/org/wso2/mashup/coreservices/servicemetadatalister/Suggestion.java
Modified:
   
branches/mashup/java/1.5/java/modules/coreservices/servicemetadatalister/src/org/wso2/mashup/coreservices/servicemetadatalister/ServiceMetaDataListerService.java

Modified: 
branches/mashup/java/1.5/java/modules/coreservices/servicemetadatalister/src/org/wso2/mashup/coreservices/servicemetadatalister/ServiceMetaDataListerService.java
URL: 
http://wso2.org/svn/browse/wso2/branches/mashup/java/1.5/java/modules/coreservices/servicemetadatalister/src/org/wso2/mashup/coreservices/servicemetadatalister/ServiceMetaDataListerService.java?rev=31003&r1=31002&r2=31003&view=diff
==============================================================================
--- 
branches/mashup/java/1.5/java/modules/coreservices/servicemetadatalister/src/org/wso2/mashup/coreservices/servicemetadatalister/ServiceMetaDataListerService.java
   (original)
+++ 
branches/mashup/java/1.5/java/modules/coreservices/servicemetadatalister/src/org/wso2/mashup/coreservices/servicemetadatalister/ServiceMetaDataListerService.java
   Tue Feb 17 06:56:46 2009
@@ -23,6 +23,9 @@
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.impl.llom.util.AXIOMUtil;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.wso2.mashup.MashupConstants;
 import org.wso2.mashup.MashupFault;
 import org.wso2.mashup.utils.MashupUtils;
@@ -37,11 +40,13 @@
 import org.wso2.registry.users.UserStoreReader;
 import org.wso2.wsas.ServerConstants;
 
+import javax.xml.stream.XMLStreamException;
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.HashMap;
+import java.io.FileInputStream;
 
 
 public class ServiceMetaDataListerService {
@@ -203,8 +208,8 @@
      * @param type
      * @return An array of suggestions depending on the prefix and type of 
query
      */
-    public String[] suggestSearchPhrases(String searchPrefix, int type) {
-        String[] resp = null;
+    public Suggestion[] suggestSearchPhrases(String searchPrefix, int type) {
+        Suggestion[] response = null;
 
         try {
             EmbeddedRegistry embeddedRegistry =
@@ -228,6 +233,7 @@
             String[] results = (String[]) resultsCollection.getContent();
 
             ArrayList tempSuggestions = new ArrayList();
+
             // Find out valid results
             if (type == 1) {
                 // Mashup names can be inferred from the path
@@ -237,23 +243,65 @@
                     String mashupName = tokens[tokens.length - 1];
 
                     if 
(mashupName.toLowerCase().indexOf(searchPrefix.toLowerCase()) != -1) {
-                        tempSuggestions.add(mashupName);
+                        // Get more information about the mashup from registry
+                        Resource resultArtifact = 
systemRegistry.get(currentResult);
+
+                        // Username of the mashup author
+                        String authorUserName = 
resultArtifact.getAuthorUserName();
+
+                        // Full name of the mashup author
+                        UserRealm realm = (UserRealm) 
MessageContext.getCurrentMessageContext()
+                                
.getConfigurationContext().getAxisConfiguration()
+                                
.getParameterValue(RegistryConstants.REGISTRY_REALM);
+                        UserStoreReader storeReader = 
realm.getUserStoreReader();
+                        String authorFullName =
+                                (String) 
storeReader.getUserProperties(authorUserName).get(
+                                        MashupConstants.FULL_NAME);
+
+                        Suggestion newSuggestion = new Suggestion(mashupName, 
authorUserName,
+                                                                  
authorFullName, currentResult,
+                                                                  "");
+                        tempSuggestions.add(newSuggestion);
                     }
                 }
             } else if (type == 2) {
                 // Need to get the comments
                 for (int x = 0; x < results.length; x++) {
                     Resource resultArtifact = systemRegistry.get(results[x]);
-                    tempSuggestions.add(resultArtifact.getContent());
+
+                    // Name of this mashup
+                    String[] tokens = results[x].split("/");
+                    String mashupName = tokens[tokens.length - 1];
+
+                    // Username of the mashup author
+                    String authorUserName = resultArtifact.getAuthorUserName();
+
+                    // Full name of the mashup author
+                    UserRealm realm = (UserRealm) 
MessageContext.getCurrentMessageContext()
+                            .getConfigurationContext().getAxisConfiguration()
+                            
.getParameterValue(RegistryConstants.REGISTRY_REALM);
+                    UserStoreReader storeReader = realm.getUserStoreReader();
+                    String authorFullName =
+                            (String) 
storeReader.getUserProperties(authorUserName).get(
+                                    MashupConstants.FULL_NAME);
+
+                    Suggestion newSuggestion =
+                            new Suggestion(mashupName, authorUserName, 
authorFullName, results[x],
+                                           (String) 
resultArtifact.getContent());
+                    tempSuggestions.add(newSuggestion);
                 }
             }
 
-            resp = new String[tempSuggestions.size()];
-            tempSuggestions.toArray(resp);
+            response = new Suggestion[tempSuggestions.size()];
+            tempSuggestions.toArray(response);
+
         } catch (RegistryException e) {
             log.error(e);
+        } catch (UserStoreException e) {
+            log.error(e);
         }
 
-        return resp;
+
+        return response;
     }
 }

Added: 
branches/mashup/java/1.5/java/modules/coreservices/servicemetadatalister/src/org/wso2/mashup/coreservices/servicemetadatalister/Suggestion.java
URL: 
http://wso2.org/svn/browse/wso2/branches/mashup/java/1.5/java/modules/coreservices/servicemetadatalister/src/org/wso2/mashup/coreservices/servicemetadatalister/Suggestion.java?pathrev=31003
==============================================================================
--- (empty file)
+++ 
branches/mashup/java/1.5/java/modules/coreservices/servicemetadatalister/src/org/wso2/mashup/coreservices/servicemetadatalister/Suggestion.java
     Tue Feb 17 06:56:46 2009
@@ -0,0 +1,61 @@
+package org.wso2.mashup.coreservices.servicemetadatalister;
+
+public class Suggestion {
+    private String mashupName;
+    private String authorUserName;
+    private String authorFullName;
+    private String mashupPath;
+    private String commentText;    
+
+    public Suggestion(String mashupName, String authorUserName, String 
authorFullName,
+                      String mashupPath,
+                      String commentText) {
+        this.mashupName = mashupName;
+        this.authorUserName = authorUserName;
+        this.authorFullName = authorFullName;
+        this.mashupPath = mashupPath;
+        this.commentText = commentText;
+    }
+
+    public String getAuthorFullName() {
+        return authorFullName;
+    }
+
+    public void setAuthorFullName(String authorFullName) {
+        this.authorFullName = authorFullName;
+    }
+
+    public String getMashupName() {
+        return mashupName;
+    }
+
+    public void setMashupName(String mashupName) {
+        this.mashupName = mashupName;
+    }
+
+    public String getAuthorUserName() {
+        return authorUserName;
+    }
+
+    public void setAuthorUserName(String authorUserName) {
+        this.authorUserName = authorUserName;
+    }
+
+    public String getMashupPath() {
+        return mashupPath;
+    }
+
+    public void setMashupPath(String mashupPath) {
+        this.mashupPath = mashupPath;
+    }
+
+    public String getCommentText() {
+        return commentText;
+    }
+
+    public void setCommentText(String commentText) {
+        this.commentText = commentText;
+    }
+
+
+}

_______________________________________________
Mashup-dev mailing list
[email protected]
https://wso2.org/cgi-bin/mailman/listinfo/mashup-dev

Reply via email to