Author: tyrell
Date: Mon Feb 16 01:00:23 2009
New Revision: 30854
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=30854

Log:
Adding a content suggest operation

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=30854&r1=30853&r2=30854&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
   Mon Feb 16 01:00:23 2009
@@ -28,6 +28,10 @@
 import org.wso2.mashup.utils.MashupUtils;
 import org.wso2.mashup.webapp.userprofile.UserInformation;
 import org.wso2.registry.RegistryConstants;
+import org.wso2.registry.Resource;
+import org.wso2.registry.exceptions.RegistryException;
+import org.wso2.registry.jdbc.EmbeddedRegistry;
+import org.wso2.registry.session.UserRegistry;
 import org.wso2.registry.users.UserRealm;
 import org.wso2.registry.users.UserStoreException;
 import org.wso2.registry.users.UserStoreReader;
@@ -37,6 +41,7 @@
 import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.Iterator;
+import java.util.HashMap;
 
 
 public class ServiceMetaDataListerService {
@@ -190,4 +195,65 @@
         filteredNames.toArray(userInfo);
         return userInfo;
     }
+
+    /**
+     * Accepts a search prefix and returns a set of available suggestions.
+     *
+     * @param searchPrefix
+     * @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;
+
+        try {
+            EmbeddedRegistry embeddedRegistry =
+                    (EmbeddedRegistry) 
MessageContext.getCurrentMessageContext()
+                            
.getConfigurationContext().getAxisConfiguration().getParameterValue(
+                            RegistryConstants.REGISTRY);
+            UserRegistry systemRegistry = embeddedRegistry.getSystemRegistry();
+
+            // Prepare the registry query
+            String queryPath = "";
+            HashMap paramsMap = new HashMap();
+            if (type == 1) {
+                queryPath = MashupConstants.ALL_MASHUPS_QUERY_PATH;
+            } else if (type == 2) {
+                queryPath = MashupConstants.COMMENTS_QUERY_PATH;
+                paramsMap.put("1", "%" + searchPrefix + "%");
+            }
+
+            Resource resultsCollection =
+                    systemRegistry.executeQuery(queryPath, paramsMap);
+            String[] results = (String[]) resultsCollection.getContent();
+
+            ArrayList tempSuggestions = new ArrayList();
+            // Find out valid results
+            if (type == 1) {
+                // Mashup names can be inferred from the path
+                for (int x = 0; x < results.length; x++) {
+                    String currentResult = results[x];
+                    String[] tokens = currentResult.split("/");
+                    String mashupName = tokens[tokens.length - 1];
+
+                    if (mashupName.indexOf(searchPrefix) != -1) {
+                        tempSuggestions.add(mashupName);
+                    }
+                }
+            } 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());
+                }
+            }
+
+            resp = new String[tempSuggestions.size()];
+            tempSuggestions.toArray(resp);
+        } catch (RegistryException e) {
+            log.error(e);
+        }
+
+        return resp;
+    }
 }

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

Reply via email to