modules/core/dbutils/src/main/java/org/rhq/core/db/upgrade/CustomAlertSenderUpgradeTask.java | 29 +- modules/core/dbutils/src/main/scripts/dbsetup/alert-schema.xml | 1 modules/core/dbutils/src/main/scripts/dbsetup/search-data.xml | 8 modules/core/dbutils/src/main/scripts/dbsetup/search-schema.xml | 1 modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml | 1 modules/core/domain/src/main/java/org/rhq/core/domain/alert/AlertDefinition.java | 3 modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/AlertNotification.java | 52 +--- modules/core/domain/src/main/java/org/rhq/core/domain/plugin/AbstractPlugin.java | 3 modules/core/domain/src/main/java/org/rhq/core/domain/search/SavedSearch.java | 39 ++- modules/core/domain/src/main/java/org/rhq/core/domain/search/SearchSubsystem.java | 14 + modules/core/domain/src/main/java/org/rhq/core/domain/search/SearchSuggestion.java | 94 ++++++++ modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/alert/common/AlertNotificationStoreUIBean.java | 72 ------ modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/alert/common/AlertNotificationsUIBean.java | 26 -- modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/common/framework/UserPreferencesUIBean.java | 62 +++-- modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/inventory/browse/BrowseGroupsUIBean.java | 2 modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/inventory/browse/BrowseResourcesUIBean.java | 48 ++-- modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/legacy/action/resource/hub/ResourceHubPortalAction.java | 40 +-- modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/startup/StartupServlet.java | 11 modules/enterprise/gui/portal-war/src/main/webapp/rhq/common/alert/notification/details.xhtml | 24 -- modules/enterprise/gui/portal-war/src/main/webapp/rhq/common/menu/menu.xhtml | 15 + modules/enterprise/gui/portal-war/src/main/webapp/rhq/inventory/browseResources.xhtml | 34 ++ modules/enterprise/server/jar/src/main/antlr3/org/rhq/enterprise/server/search/RHQL.g | 1 modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerBean.java | 8 modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerLocal.java | 3 modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/scheduler/jobs/SavedSearchResultCountRecalculationJob.java | 98 ++++++++ modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/assist/AbstractSearchAssistant.java | 12 - modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/assist/ResourceSearchAssistant.java | 2 modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/assist/SearchAssistant.java | 10 modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/execution/SearchAssistManager.java | 115 +++++++++- modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/execution/SearchSuggestion.java | 52 ---- modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/execution/SearchTranslationManager.java | 26 +- modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/translation/SearchTranslatorFactory.java | 2 modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/util/CriteriaQueryGenerator.java | 2 modules/enterprise/server/jar/src/main/resources/single-line-rhql.txt | 10 modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/search/GenericSearchAssistTest.java | 5 modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/search/TestAutoCompletionManager.java | 8 36 files changed, 573 insertions(+), 360 deletions(-)
New commits: commit 91e1f5b3d76a7cbe48ecf46992ec74fbdd2ff5a1 Merge: 5250a8a... d362688... Author: Ian P. Springer <ips@jetengine.(none)> Date: Tue Apr 27 11:01:40 2010 -0400
Merge branch 'master' into gwt
commit d36268863a5e64e6a14de4d89c129f2ed0e89a2e Merge: 5f9cbe0... cc8f2db... Author: Ian P. Springer <ips@jetengine.(none)> Date: Tue Apr 27 09:52:39 2010 -0400
Merge branch 'master' of ssh://git.fedorahosted.org/git/rhq/rhq
commit cc8f2db67869ec32176c5160bc2adb195fdbb678 Author: Joseph Marques joseph@redhat.com Date: Tue Apr 27 09:46:42 2010 -0400
small fix to dbsetup script data
diff --git a/modules/core/dbutils/src/main/scripts/dbsetup/search-data.xml b/modules/core/dbutils/src/main/scripts/dbsetup/search-data.xml index da98622..380ef0f 100644 --- a/modules/core/dbutils/src/main/scripts/dbsetup/search-data.xml +++ b/modules/core/dbutils/src/main/scripts/dbsetup/search-data.xml @@ -5,18 +5,18 @@ <!-- overlord-created, global, default saved searches --> <table name="RHQ_SAVED_SEARCH"> <data ID="1" - CONTEXT="Resource" + CONTEXT="RESOURCE" NAME="Downed Platforms" DESCRIPTION="All downed machines across the entire enterprise" - PATTERN="down platform" + PATTERN="availability=down category=platform" LAST_COMPUTE_TIME="0" SUBJECT_ID="1" GLOBAL="TRUE" /> <data ID="2" - CONTEXT="Resource" + CONTEXT="RESOURCE" NAME="Downed Servers" DESCRIPTION="All downed servers across the entire enterprise" - PATTERN="down server" + PATTERN="availability=down category=server" LAST_COMPUTE_TIME="0" SUBJECT_ID="1" GLOBAL="TRUE" />
commit d2ce45f0122e499162151ef8e927d9d5086dc5ed Author: Joseph Marques joseph@redhat.com Date: Mon Apr 26 17:32:52 2010 -0400
remove name field from alert notifications
diff --git a/modules/core/dbutils/src/main/java/org/rhq/core/db/upgrade/CustomAlertSenderUpgradeTask.java b/modules/core/dbutils/src/main/java/org/rhq/core/db/upgrade/CustomAlertSenderUpgradeTask.java index 0fa4ee8..07c7590 100644 --- a/modules/core/dbutils/src/main/java/org/rhq/core/db/upgrade/CustomAlertSenderUpgradeTask.java +++ b/modules/core/dbutils/src/main/java/org/rhq/core/db/upgrade/CustomAlertSenderUpgradeTask.java @@ -75,9 +75,8 @@ public class CustomAlertSenderUpgradeTask implements DatabaseUpgradeTask {
String propertyName = "subjectId"; String senderName = "System Users"; - String name = "User Notifications";
- persist(data, propertyName, senderName, name); + persist(data, propertyName, senderName); }
private void upgradeRoleNotifications() throws SQLException { @@ -91,9 +90,8 @@ public class CustomAlertSenderUpgradeTask implements DatabaseUpgradeTask {
String propertyName = "roleId"; String senderName = "System Roles"; - String name = "Role Notifications";
- persist(data, propertyName, senderName, name); + persist(data, propertyName, senderName); }
private void upgradeEmailNotifications() throws SQLException { @@ -107,9 +105,8 @@ public class CustomAlertSenderUpgradeTask implements DatabaseUpgradeTask {
String propertyName = "emailAddress"; String senderName = "Direct Emails"; - String name = "Email Notifications";
- persist(data, propertyName, senderName, name); + persist(data, propertyName, senderName); }
private void upgradeSNMPNotifications() throws SQLException { @@ -129,7 +126,7 @@ public class CustomAlertSenderUpgradeTask implements DatabaseUpgradeTask {
// buffer will be 0 the very first time, since definitionId is initially -1 int configId = persistConfiguration("host", host, "port", port, "oid", oid); - persistNotification(alertDefinitionId, configId, "SNMP Traps", "SNMP Notifications"); + persistNotification(alertDefinitionId, configId, "SNMP Traps"); } }
@@ -147,11 +144,11 @@ public class CustomAlertSenderUpgradeTask implements DatabaseUpgradeTask { // buffer will be 0 the very first time, since definitionId is initially -1 int configId = persistConfiguration("operation-definition-id", operationDefinitionId, "selection-mode", "SELF"); - persistNotification(alertDefinitionId, configId, "Resource Operations", "Operation Invocation"); + persistNotification(alertDefinitionId, configId, "Resource Operations"); } }
- private void persist(List<Object[]> data, String propertyName, String sender, String name) throws SQLException { + private void persist(List<Object[]> data, String propertyName, String sender) throws SQLException { int definitionId = -1; StringBuilder buffer = new StringBuilder(); for (Object[] next : data) { @@ -162,7 +159,7 @@ public class CustomAlertSenderUpgradeTask implements DatabaseUpgradeTask { if (buffer.length() != 0) { // buffer will be 0 the very first time, since definitionId is initially -1 int configId = persistConfiguration(propertyName, buffer.toString()); - persistNotification(definitionId, configId, sender, name); + persistNotification(definitionId, configId, sender); } buffer = new StringBuilder(); // reset for the next definitionId } @@ -176,7 +173,7 @@ public class CustomAlertSenderUpgradeTask implements DatabaseUpgradeTask {
if (buffer.length() != 0) { int configId = persistConfiguration(propertyName, buffer.toString()); - persistNotification(definitionId, configId, sender, name); + persistNotification(definitionId, configId, sender); } }
@@ -197,9 +194,9 @@ public class CustomAlertSenderUpgradeTask implements DatabaseUpgradeTask { return configId; }
- private void persistNotification(int definitionId, int configId, String sender, String name) throws SQLException { + private void persistNotification(int definitionId, int configId, String sender) throws SQLException { int notificationId = databaseType.getNextSequenceValue(connection, "rhq_alert_notification", "id"); - String insertNotificationSQL = getInsertNotificationSQL(notificationId, definitionId, configId, sender, name); + String insertNotificationSQL = getInsertNotificationSQL(notificationId, definitionId, configId, sender);
databaseType.executeSql(connection, insertNotificationSQL); } @@ -214,9 +211,9 @@ public class CustomAlertSenderUpgradeTask implements DatabaseUpgradeTask { + " VALUES ( " + id + ", " + configId + ", '" + name + "', '" + value + "', 'property' ) "; }
- private String getInsertNotificationSQL(int id, int definitionId, int configId, String sender, String name) { - return "INSERT INTO rhq_alert_notification ( id, alert_definition_id, sender_config_id, sender_name, display_name )" // - + " VALUES ( " + id + ", " + definitionId + ", " + configId + ", '" + sender + "', '" + name + "' ) "; + private String getInsertNotificationSQL(int id, int definitionId, int configId, String sender) { + return "INSERT INTO rhq_alert_notification ( id, alert_definition_id, sender_config_id, sender_name )" // + + " VALUES ( " + id + ", " + definitionId + ", " + configId + ", '" + sender + "' ) "; }
} diff --git a/modules/core/dbutils/src/main/scripts/dbsetup/alert-schema.xml b/modules/core/dbutils/src/main/scripts/dbsetup/alert-schema.xml index 9617057..b2db5f0 100644 --- a/modules/core/dbutils/src/main/scripts/dbsetup/alert-schema.xml +++ b/modules/core/dbutils/src/main/scripts/dbsetup/alert-schema.xml @@ -137,7 +137,6 @@ <column name="TEMPLATE_ID" required="false" type="INTEGER" references="RHQ_ALERT_NOTIF_TEMPL(ID)"/> <column name="SENDER_CONFIG_ID" required="false" type="INTEGER" references="RHQ_CONFIG(ID)"/> <column name="SENDER_NAME" required="true" size="100" type="VARCHAR2" /> - <column name="DISPLAY_NAME" type="VARCHAR2" size="100" /> </table>
</dbsetup> diff --git a/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml b/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml index 6974780..d028a43 100644 --- a/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml +++ b/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml @@ -2060,7 +2060,6 @@ <schema-addColumn table="RHQ_ALERT" column="ACK_TIME" columnType="LONG" /> <!-- TODO: this needs to change to ack_subject_name --> <schema-addColumn table="RHQ_ALERT" column="ACK_SUBJECT" precision="100" columnType="VARCHAR2" /> - <schema-addColumn table="RHQ_ALERT_NOTIFICATION" column="DISPLAY_NAME" precision="100" columnType="VARCHAR2" /> <schema-addColumn table="RHQ_ALERT_NOTIFICATION" column="SENDER_NAME" precision="100" columnType="VARCHAR2" /> <schema-addColumn table="RHQ_ALERT_NOTIFICATION" column="SENDER_CONFIG_ID" columnType="INTEGER" /> <schema-directSQL> diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/AlertNotification.java b/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/AlertNotification.java index 1a7be46..b77d8b0 100644 --- a/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/AlertNotification.java +++ b/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/AlertNotification.java @@ -85,9 +85,6 @@ public class AlertNotification implements Serializable { @Column(name = "SENDER_NAME") private String senderName;
- @Column(name = "DISPLAY_NAME") - private String displayName; - protected AlertNotification() { } // JPA spec
@@ -115,7 +112,6 @@ public class AlertNotification implements Serializable { } else { this.configuration = source.configuration.deepCopy(false); } - this.displayName = source.displayName; this.senderName = source.senderName; }
@@ -129,8 +125,7 @@ public class AlertNotification implements Serializable { this.alertNotificationId = alertNotificationId; }
- public AlertNotification(String displayName, String sender) { - this.displayName = displayName; + public AlertNotification(String sender) { this.senderName = sender; }
@@ -147,22 +142,6 @@ public class AlertNotification implements Serializable { this.alertDefinition = alertDefinition; }
- public AlertNotification copyWithAlertDefintion(AlertDefinition alertDefinition, boolean copyIds) { - Configuration config; - if (copyIds) { - config = this.configuration; - } else { - config = this.configuration.deepCopy(false); - } - AlertNotification notification = new AlertNotification(alertDefinition, config); - if (copyIds) { - notification.id = this.id; - } - notification.setDisplayName(this.displayName); - notification.setSenderName(this.senderName); - return notification; - } - public void prepareForOrphanDelete() { this.alertDefinition = null; } @@ -183,14 +162,6 @@ public class AlertNotification implements Serializable { this.configuration = configuration; }
- public String getDisplayName() { - return displayName; - } - - public void setDisplayName(String displayName) { - this.displayName = displayName; - } - public AlertNotificationTemplate getAlertNotificationTemplate() { return alertNotificationTemplate; } @@ -216,7 +187,6 @@ public class AlertNotification implements Serializable { sb.append(", id=").append(id); sb.append(", notificationTemplate=").append(alertNotificationTemplate); sb.append(", senderName='").append(senderName).append('''); - sb.append(", displayName='").append(displayName).append('''); sb.append('}'); return sb.toString(); } diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/alert/common/AlertNotificationStoreUIBean.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/alert/common/AlertNotificationStoreUIBean.java deleted file mode 100644 index 05e254e..0000000 --- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/alert/common/AlertNotificationStoreUIBean.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * RHQ Management Platform - * Copyright (C) 2005-2009 Red Hat, Inc. - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ -package org.rhq.enterprise.gui.alert.common; - -import java.util.List; - -import org.jboss.seam.ScopeType; -import org.jboss.seam.annotations.Name; -import org.jboss.seam.annotations.Scope; -import org.jboss.seam.annotations.web.RequestParameter; - -import org.rhq.core.domain.alert.notification.AlertNotification; -import org.rhq.core.domain.auth.Subject; -import org.rhq.core.domain.configuration.Configuration; -import org.rhq.enterprise.server.alert.AlertNotificationManagerLocal; -import org.rhq.enterprise.server.util.LookupUtil; - -@Scope(ScopeType.EVENT) -@Name("alertNotificationStoreUIBean") -public class AlertNotificationStoreUIBean { - - @RequestParameter("context") - private String context; - - @RequestParameter("contextId") - private Integer contextId; - - private AlertNotificationManagerLocal alertNotificationManager = LookupUtil.getAlertNotificationManager(); - - public List<AlertNotification> lookupNotifications(Subject subject) { - if (context.equals("template")) { - return this.alertNotificationManager.getNotificationsForTemplate(subject, contextId); - } else { - return this.alertNotificationManager.getNotificationsForAlertDefinition(subject, contextId); - } - } - - public AlertNotification addNotification(Subject subject, String senderType, String notificationName, - Configuration configuration) { - if (context.equals("template")) { - return alertNotificationManager.addAlertNotificationToTemplate(subject, contextId, senderType, - notificationName, configuration); - } else { - return this.alertNotificationManager.addAlertNotification(subject, contextId, senderType, notificationName, - configuration); - } - } - - public void removeNotifications(Subject subject, Integer[] notificationIds) { - if (context.equals("template")) { - this.alertNotificationManager.removeNotificationsFromTemplate(subject, contextId, notificationIds); - } else { - this.alertNotificationManager.removeNotifications(subject, contextId, notificationIds); - } - } -} diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/alert/common/AlertNotificationsUIBean.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/alert/common/AlertNotificationsUIBean.java index f696c3c..80cc829 100644 --- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/alert/common/AlertNotificationsUIBean.java +++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/alert/common/AlertNotificationsUIBean.java @@ -49,14 +49,16 @@ public class AlertNotificationsUIBean extends EnterpriseFacesContextUIBean {
@RequestParameter("nid") private Integer notificationId; + @RequestParameter("context") + private String context; + @RequestParameter("contextId") + private Integer contextId; + @In private AlertNotificationManagerLocal alertNotificationManager; - @In(create = true) - private AlertNotificationStoreUIBean alertNotificationStoreUIBean;
private List<AlertNotification> alertNotifications; private Set<AlertNotification> selectedNotifications; - private String newAlertName; private String selectedNewSender; private AlertNotification activeNotification; private ConfigurationDefinition activeConfigDefinition; @@ -79,14 +81,6 @@ public class AlertNotificationsUIBean extends EnterpriseFacesContextUIBean { this.selectedNotifications = selectedNotifications; }
- public String getNewAlertName() { - return newAlertName; - } - - public void setNewAlertName(String newAlertName) { - this.newAlertName = newAlertName; - } - public String getSelectedNewSender() { return selectedNewSender; } @@ -136,7 +130,8 @@ public class AlertNotificationsUIBean extends EnterpriseFacesContextUIBean { }
public void reloadAlertNotifications() { - this.alertNotifications = this.alertNotificationStoreUIBean.lookupNotifications(getSubject()); + this.alertNotifications = this.alertNotificationManager.getNotificationsForAlertDefinition(getSubject(), + contextId); }
// Sets the initial state of the bean given the requrest parameters, this allows @@ -175,8 +170,9 @@ public class AlertNotificationsUIBean extends EnterpriseFacesContextUIBean { newSenderConfig = new Configuration(); }
- AlertNotification newlyCreated = this.alertNotificationStoreUIBean.addNotification(getSubject(), - this.selectedNewSender, this.newAlertName, newSenderConfig); + AlertNotification newlyCreated = this.alertNotificationManager.addAlertNotification(getSubject(), + this.contextId, this.selectedNewSender, newSenderConfig); + this.alertNotifications.add(newlyCreated); // only add if no errors this.activeNotification = newlyCreated; this.selectedNotifications.clear(); @@ -194,7 +190,7 @@ public class AlertNotificationsUIBean extends EnterpriseFacesContextUIBean { }
public String removeSelected() { - this.alertNotificationStoreUIBean.removeNotifications(getSubject(), getSelectedIds()); + this.alertNotificationManager.removeNotifications(getSubject(), contextId, getSelectedIds()); this.alertNotifications.removeAll(this.selectedNotifications); // only remove if no errors this.activeNotification = null;
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/common/alert/notification/details.xhtml b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/common/alert/notification/details.xhtml index fd83f96..74b978e 100644 --- a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/common/alert/notification/details.xhtml +++ b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/common/alert/notification/details.xhtml @@ -52,19 +52,13 @@ fastOrderControlsVisible="false" orderControlsVisible="false" id="sendersList"> - <rich:column width="20%"> - <f:facet name="header"> - <h:outputText value="Name" /> - </f:facet> - <h:outputText value="#{alertNotification.displayName}" /> - </rich:column> - <rich:column width="20%"> + <rich:column width="25%"> <f:facet name="header"> <h:outputText value="Type" /> </f:facet> <h:outputText value="#{alertNotification.senderName}" /> </rich:column> - <rich:column width="60%"> + <rich:column width="75%"> <f:facet name="header"> <h:outputText value="Configuration" /> </f:facet> @@ -170,20 +164,6 @@ <input type="hidden" name="contextSubId" value="#{param.contextSubId}"/>
<div style="height: 100px;"> - <h:outputLabel for="alertNameInput" value="Alert Notification Name:" /> - <br /> - <h:inputText id="alertNameInput" - value="#{alertNotificationsUIBean.newAlertName}" - maxlength="100" - required="true" /> - - <h:message for="alertNameInput" - infoClass="InfoBlock" - warnClass="WarnBlock" - errorClass="ErrorBlock" - fatalClass="FatalBlock" /> - <br /><br /> - <h:outputLabel for="senderList" value="Alert Sender Type:" /> <br /> <h:selectOneMenu id="senderList" value="#{alertNotificationsUIBean.selectedNewSender}"> diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerBean.java index 0e7682a..0897dc7 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerBean.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerBean.java @@ -296,7 +296,7 @@ public class AlertNotificationManagerBean implements AlertNotificationManagerLoc * {@inheritDoc} */ public AlertNotification addAlertNotification(Subject user, int alertDefinitionId, String senderName, - String alertName, Configuration configuration) { + Configuration configuration) {
AlertDefinition definition = alertDefinitionManager.getAlertDefinition(user, alertDefinitionId); if (definition == null) { @@ -307,7 +307,6 @@ public class AlertNotificationManagerBean implements AlertNotificationManagerLoc entityManager.persist(configuration); AlertNotification notif = new AlertNotification(definition); notif.setSenderName(senderName); - notif.setDisplayName(alertName); notif.setConfiguration(configuration); entityManager.persist(notif); definition.getAlertNotifications().add(notif); @@ -485,7 +484,7 @@ public class AlertNotificationManagerBean implements AlertNotificationManagerLoc AlertNotificationTemplate template = entityManager.find(AlertNotificationTemplate.class, templateId);
entityManager.persist(notificationConfiguration); - AlertNotification alertNotification = new AlertNotification(notificationName, sender); + AlertNotification alertNotification = new AlertNotification(sender); alertNotification.setConfiguration(notificationConfiguration); alertNotification.setAlertNotificationTemplate(template); entityManager.persist(alertNotification); diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerLocal.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerLocal.java index 56f1c20..9db80cc 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerLocal.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerLocal.java @@ -65,10 +65,9 @@ public interface AlertNotificationManagerLocal { * @param user subject of the caller * @param alertDefinitionId Id of the alert definition * @param senderName shortName of the {@link AlertSender} - * @param alertName name of the new {@link AlertNotification} * @param configuration Properties for this alert sender. */ - AlertNotification addAlertNotification(Subject user, int alertDefinitionId, String senderName, String alertName, + AlertNotification addAlertNotification(Subject user, int alertDefinitionId, String senderName, Configuration configuration);
/**
commit d3cc735b22ba4548e5eef68b1dae73bf51335649 Author: Joseph Marques joseph@redhat.com Date: Mon Apr 26 17:00:14 2010 -0400
BZ-562816: fix for stack trace when trying to edit general properties or conditions for an alert definition
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/alert/AlertDefinition.java b/modules/core/domain/src/main/java/org/rhq/core/domain/alert/AlertDefinition.java index afa5671..5a3aeba 100644 --- a/modules/core/domain/src/main/java/org/rhq/core/domain/alert/AlertDefinition.java +++ b/modules/core/domain/src/main/java/org/rhq/core/domain/alert/AlertDefinition.java @@ -448,8 +448,7 @@ public class AlertDefinition implements Serializable {
Set<AlertNotification> copiedNotifications = new HashSet<AlertNotification>(); for (AlertNotification oldNotification : new HashSet<AlertNotification>(alertDef.getAlertNotifications())) { - AlertNotification newNotification = oldNotification.copy(copyIds); - newNotification.setAlertDefinition(this); + AlertNotification newNotification = new AlertNotification(oldNotification, copyIds); copiedNotifications.add(newNotification); } this.removeAllAlertNotifications(); diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/AlertNotification.java b/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/AlertNotification.java index 1f14aad..1a7be46 100644 --- a/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/AlertNotification.java +++ b/modules/core/domain/src/main/java/org/rhq/core/domain/alert/notification/AlertNotification.java @@ -79,7 +79,7 @@ public class AlertNotification implements Serializable { private AlertNotificationTemplate alertNotificationTemplate;
@JoinColumn(name = "SENDER_CONFIG_ID", referencedColumnName = "ID") - @OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY) + @OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER) private Configuration configuration;
@Column(name = "SENDER_NAME") @@ -108,6 +108,17 @@ public class AlertNotification implements Serializable { this.configuration = config.deepCopy(); }
+ public AlertNotification(AlertNotification source, boolean copyIds) { + if (copyIds) { + this.id = source.id; + this.configuration = source.configuration; + } else { + this.configuration = source.configuration.deepCopy(false); + } + this.displayName = source.displayName; + this.senderName = source.senderName; + } + /** * Constructor only for transient usage * @param alertDefinitionId @@ -136,31 +147,22 @@ public class AlertNotification implements Serializable { this.alertDefinition = alertDefinition; }
- public AlertNotification copy(boolean copyIds) { - AlertNotification results = copy(); - if (copyIds) { - results.id = this.id; - } - return results; - } - - public AlertNotification copyWithAlertDefintion(AlertDefinition alertDefinition, boolean cloneConfiguration) { + public AlertNotification copyWithAlertDefintion(AlertDefinition alertDefinition, boolean copyIds) { Configuration config; - if (cloneConfiguration) { - config = this.configuration.deepCopy(false); - } else { + if (copyIds) { config = this.configuration; + } else { + config = this.configuration.deepCopy(false); } AlertNotification notification = new AlertNotification(alertDefinition, config); + if (copyIds) { + notification.id = this.id; + } notification.setDisplayName(this.displayName); notification.setSenderName(this.senderName); return notification; }
- protected AlertNotification copy() { - return new AlertNotification(this.alertDefinition, this.configuration); - } - public void prepareForOrphanDelete() { this.alertDefinition = null; } diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerBean.java index 8a4bb98..0e7682a 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerBean.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertNotificationManagerBean.java @@ -393,7 +393,8 @@ public class AlertNotificationManagerBean implements AlertNotificationManagerLoc def.getAlertNotifications().clear();
for (AlertNotification notif : template.getNotifications()) { - AlertNotification notification = notif.copyWithAlertDefintion(def, true); + AlertNotification notification = new AlertNotification(notif, true); + notification.setAlertDefinition(notif.getAlertDefinition()); entityManager.persist(notification.getConfiguration()); entityManager.persist(notification); def.addAlertNotification(notification); // Attach a copy, as the ones in the template should not be shared
commit deef32fd46d29fa6bf9145ac360c9b1d59b2826a Author: Joseph Marques joseph@redhat.com Date: Mon Apr 26 16:28:38 2010 -0400
only print statistics for saved search result count recalculation if updates were non-zero
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/scheduler/jobs/SavedSearchResultCountRecalculationJob.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/scheduler/jobs/SavedSearchResultCountRecalculationJob.java index a1e53b3..0e015e3 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/scheduler/jobs/SavedSearchResultCountRecalculationJob.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/scheduler/jobs/SavedSearchResultCountRecalculationJob.java @@ -80,7 +80,10 @@ public class SavedSearchResultCountRecalculationJob extends AbstractStatefulJob + next.getPattern() + "']"); } } - LOG.info("Statistics: updated " + updated + " in " + totalMillis + " ms (" + errors + " errors)"); + if (updated > 0) { + // only print non-zero stats + LOG.info("Statistics: updated " + updated + " in " + totalMillis + " ms (" + errors + " errors)"); + } }
private List<SavedSearch> getSavedSearchesNeedingRecomputation() {
commit 9937c0a8336afcf18245fe8614ad3fe413d178bc Author: Joseph Marques joseph@redhat.com Date: Mon Apr 26 15:52:28 2010 -0400
fix failure unit tests for saved searches subsystem
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/execution/SearchAssistManager.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/execution/SearchAssistManager.java index 2cb808c..97f44dd 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/execution/SearchAssistManager.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/execution/SearchAssistManager.java @@ -31,7 +31,7 @@ public class SearchAssistManager { private static List<String> booleanOperators = Arrays.asList("and", "or", "|");
private Subject subject; - private AbstractSearchAssistant completor; + private SearchSubsystem searchSubsystem;
/* * states: @@ -278,10 +278,11 @@ public class SearchAssistManager {
public SearchAssistManager(Subject subject, SearchSubsystem searchSubsystem) { this.subject = subject; - this.completor = getAutoCompletor(searchSubsystem); + this.searchSubsystem = searchSubsystem; + }
- protected AbstractSearchAssistant getAutoCompletor(SearchSubsystem searchSubsystem) { + protected AbstractSearchAssistant getSearchAssistant() { if (searchSubsystem == SearchSubsystem.RESOURCE) { return new ResourceSearchAssistant(); } else { @@ -290,8 +291,8 @@ public class SearchAssistManager { }
public List<String> getAllContexts() { - List<String> results = new ArrayList<String>(completor.getSimpleContexts()); - for (String parameterized : completor.getParameterizedContexts()) { + List<String> results = new ArrayList<String>(getSearchAssistant().getSimpleContexts()); + for (String parameterized : getSearchAssistant().getParameterizedContexts()) { results.add(parameterized + "["); } return results; @@ -299,7 +300,7 @@ public class SearchAssistManager {
public List<SearchSuggestion> getSuggestions(String expression, int caretPos) { //List<SearchSuggestion> simple = getSimpleSuggestions(expression, caretPos); - List<SearchSuggestion> advanced = getAdvancedSuggestions(expression, caretPos, SearchSuggestion.Kind.Advanced); + List<SearchSuggestion> advanced = getAdvancedSuggestions(expression, caretPos); List<SearchSuggestion> userSavedSearches = getUserSavedSearchSuggestions(expression); List<SearchSuggestion> globalSavedSearches = getGlobalSavedSearchSuggestions(expression);
@@ -313,11 +314,12 @@ public class SearchAssistManager { }
public List<SearchSuggestion> getSimpleSuggestions(String expression, int caretPos) { + AbstractSearchAssistant completor = getSearchAssistant(); + List<SearchSuggestion> results = new ArrayList<SearchSuggestion>(); for (String nextContext : completor.getSimpleContexts()) { String intermediateExpression = nextContext + "=" + expression; - List<SearchSuggestion> suggestions = getAdvancedSuggestions(intermediateExpression, caretPos, - SearchSuggestion.Kind.Simple); + List<SearchSuggestion> suggestions = getAdvancedSuggestions(intermediateExpression, caretPos); results.addAll(suggestions); } Collections.sort(results); @@ -328,8 +330,9 @@ public class SearchAssistManager { } }
- public List<SearchSuggestion> getAdvancedSuggestions(String expression, int caretPos, - SearchSuggestion.Kind targetKind) { + public List<SearchSuggestion> getAdvancedSuggestions(String expression, int caretPos) { + AbstractSearchAssistant completor = getSearchAssistant(); + debug("getAdvancedSuggestions: START"); long id = HibernatePerformanceMonitor.get().start(); SearchTermAssistant assistant = new SearchTermAssistant(expression, caretPos); @@ -339,7 +342,7 @@ public class SearchAssistManager {
if (tokens.length == 0) { debug("getAdvancedSuggestions: no terms"); - return convert(getAllContexts(), targetKind); // no terms yet defined + return convert(getAllContexts()); // no terms yet defined }
String beforeCaret = assistant.getFragmentBeforeCaret(); @@ -352,26 +355,26 @@ public class SearchAssistManager { if (parsed.context.equals("")) { if (tokens.length == 1) { debug("getAdvancedSuggestions: no terms yet, suggesting contexts"); - return convert(getAllContexts(), targetKind); + return convert(getAllContexts()); } else if (isBooleanTerm(assistant.getPreviousToken())) { debug("getAdvancedSuggestions: previous term was boolean, suggesting contexts"); - return convert(getAllContexts(), targetKind); + return convert(getAllContexts()); } else { debug("getAdvancedSuggestions: previous term was not boolean, suggesting boolean"); - return convert(booleanOperators, targetKind); + return convert(booleanOperators); } } else if (isBooleanTerm(parsed.context)) { debug("getAdvancedSuggestions: beforeCaret is whole boolean operator"); - return convert(getAllContexts(), targetKind); // TODO: should we tell user to type a space first? + return convert(getAllContexts()); // TODO: should we tell user to type a space first? } else { // check if this context is complete or not if (completor.getSimpleContexts().contains(parsed.context)) { debug("getAdvancedSuggestions: search term is simple context, wants operator"); - return convert(pad(parsed.context, comparisonOperators, ""), targetKind); + return convert(pad(parsed.context, comparisonOperators, "")); } if (completor.getParameterizedContexts().contains(parsed.context)) { debug("getAdvancedSuggestions: search term is parameterized context, wants open bracket"); - return convert(Arrays.asList(parsed.context + "["), targetKind); + return convert(Arrays.asList(parsed.context + "[")); }
debug("getAdvancedSuggestions: search term wants context completion"); @@ -386,12 +389,11 @@ public class SearchAssistManager { startsWithContexts.add(context + "["); } } - return convert(startsWithContexts, targetKind); + return convert(startsWithContexts); } case PARAM: debug("getAdvancedSuggestions: param state"); - return convert(pad(parsed.context + "[", completor.getParameters(parsed.context, parsed.param), "]"), - targetKind); + return convert(pad(parsed.context + "[", completor.getParameters(parsed.context, parsed.param), "]")); case OPERATOR: debug("getAdvancedSuggestions: operator state"); if (comparisonOperators.contains(parsed.operator)) { @@ -399,11 +401,11 @@ public class SearchAssistManager { List<String> valueSuggestions = pad(""", completor.getValues(parsed.context, parsed.param, ""), """); if (completor.getSimpleContexts().contains(parsed.context)) { debug("getAdvancedSuggestions: suggesting value completions for a simple context"); - return convert(pad(parsed.context + parsed.operator, valueSuggestions, ""), targetKind); + return convert(pad(parsed.context + parsed.operator, valueSuggestions, "")); } else { debug("getAdvancedSuggestions: suggesting value completions for a parameterized context"); return convert(pad(parsed.context + "[" + parsed.param + "]" + parsed.operator, valueSuggestions, - ""), targetKind); + "")); } }
@@ -416,9 +418,9 @@ public class SearchAssistManager {
debug("getAdvancedSuggestions: providing suggestions for comparison operators"); if (completor.getSimpleContexts().contains(parsed.context)) { - return convert(pad(parsed.context, operatorSuggestions, ""), targetKind); + return convert(pad(parsed.context, operatorSuggestions, "")); } else { - return convert(pad(parsed.context + "[" + parsed.param + "]", operatorSuggestions, ""), targetKind); + return convert(pad(parsed.context + "[" + parsed.param + "]", operatorSuggestions, "")); } case VALUE: debug("getAdvancedSuggestions: value state"); @@ -426,11 +428,10 @@ public class SearchAssistManager { """); if (completor.getSimpleContexts().contains(parsed.context)) { debug("getAdvancedSuggestions: suggesting value completions for a simple context"); - return convert(pad(parsed.context + parsed.operator, valueSuggestions, ""), targetKind); + return convert(pad(parsed.context + parsed.operator, valueSuggestions, "")); } else { debug("getAdvancedSuggestions: suggesting value completions for a parameterized context"); - return convert(pad(parsed.context + "[" + parsed.param + "]" + parsed.operator, valueSuggestions, ""), - targetKind); + return convert(pad(parsed.context + "[" + parsed.param + "]" + parsed.operator, valueSuggestions, "")); } default: return Collections.emptyList(); @@ -440,6 +441,7 @@ public class SearchAssistManager { public List<SearchSuggestion> getUserSavedSearchSuggestions(String expression) { SavedSearchCriteria criteria = new SavedSearchCriteria(); criteria.addFilterSubjectId(subject.getId()); + criteria.addFilterSearchContext(searchSubsystem); if (expression != null && expression.trim().equals("")) { criteria.addFilterName(expression); } @@ -494,10 +496,10 @@ public class SearchAssistManager { return false; }
- private List<SearchSuggestion> convert(List<String> suggestions, SearchSuggestion.Kind targetKind) { + private List<SearchSuggestion> convert(List<String> suggestions) { List<SearchSuggestion> results = new ArrayList<SearchSuggestion>(suggestions.size()); for (String suggestion : suggestions) { - results.add(new SearchSuggestion(targetKind, suggestion)); + results.add(new SearchSuggestion(Kind.Advanced, suggestion)); } return results; } diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/search/GenericSearchAssistTest.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/search/GenericSearchAssistTest.java index 5d51d10..0a28dee 100644 --- a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/search/GenericSearchAssistTest.java +++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/search/GenericSearchAssistTest.java @@ -36,7 +36,7 @@ public class GenericSearchAssistTest extends AbstractEJB3Test { }
count++; - List<SearchSuggestion> results = new TestAutoCompletionManager().getSuggestions(expression, + List<SearchSuggestion> results = new TestAutoCompletionManager().getAdvancedSuggestions(expression, expression.length()); List<String> expectedResults = Arrays.asList(expected.split(" "));
@@ -51,7 +51,8 @@ public class GenericSearchAssistTest extends AbstractEJB3Test { } System.out.println("Tested " + count + " expressions for assist"); } catch (Exception e) { - System.out.println("Error testing single line RHQL: " + e); + System.out.println("Error testing GenericSearchAssistTest: " + e); + e.printStackTrace(System.out); throw e; } finally { if (reader != null) { diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/search/TestAutoCompletionManager.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/search/TestAutoCompletionManager.java index 28a11a7..704146b 100644 --- a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/search/TestAutoCompletionManager.java +++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/search/TestAutoCompletionManager.java @@ -9,6 +9,7 @@ import java.util.Map; import org.rhq.core.domain.search.SearchSubsystem; import org.rhq.enterprise.server.search.assist.AbstractSearchAssistant; import org.rhq.enterprise.server.search.execution.SearchAssistManager; +import org.rhq.enterprise.server.util.LookupUtil;
public class TestAutoCompletionManager extends SearchAssistManager { public static class TestAutoCompletor extends AbstractSearchAssistant { @@ -61,10 +62,12 @@ public class TestAutoCompletionManager extends SearchAssistManager { }
public TestAutoCompletionManager() { - super(null, null); + super(LookupUtil.getSubjectManager().getOverlord(), null); }
- protected AbstractSearchAssistant getAutoCompletor(SearchSubsystem searchContext) { + @Override + protected AbstractSearchAssistant getSearchAssistant() { return new TestAutoCompletor(); + } }
commit 7064ea6ab73f1899567ed6bd6e48ee86aaf3f2cc Author: Joseph Marques joseph@redhat.com Date: Mon Apr 26 13:04:08 2010 -0400
BZ-562816: fix regression in custom alert sender UI
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/common/alert/notification/details.xhtml b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/common/alert/notification/details.xhtml index b8ae721..fd83f96 100644 --- a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/common/alert/notification/details.xhtml +++ b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/common/alert/notification/details.xhtml @@ -56,7 +56,7 @@ <f:facet name="header"> <h:outputText value="Name" /> </f:facet> - <h:outputText value="#{alertNotification.name}" /> + <h:outputText value="#{alertNotification.displayName}" /> </rich:column> <rich:column width="20%"> <f:facet name="header">
commit 8f4b79421c74e3d50abb3d8ab209168912e4c8fa Author: Joseph Marques joseph@redhat.com Date: Mon Apr 26 13:03:16 2010 -0400
continuing development on search subsystem:
add support for simple search terms (as opposed to context=value advanced expressions) fixed search portlet on the dashboard to point to the JSF-based inventory browser added display of global and user-specific saved searches to the resources menu support for loading saved searches from the menu bar, pre-populating the search textbox support for loading saved searches from the search suggestion, pre-populating the search textbox
diff --git a/modules/core/dbutils/src/main/scripts/dbsetup/search-schema.xml b/modules/core/dbutils/src/main/scripts/dbsetup/search-schema.xml index 14634b6..7910f84 100644 --- a/modules/core/dbutils/src/main/scripts/dbsetup/search-schema.xml +++ b/modules/core/dbutils/src/main/scripts/dbsetup/search-schema.xml @@ -12,7 +12,6 @@ <column name="DESCRIPTION" type="VARCHAR2" size="500" required="false"/> <column name="PATTERN" type="VARCHAR2" size="1000" required="true"/>
- <column name="JPQL_TRANSLATION" type="VARCHAR2" size="4000" required="false"/> <column name="LAST_COMPUTE_TIME" type="LONG" required="true"/> <column name="RESULT_COUNT" type="LONG" required="false"/>
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/AbstractPlugin.java b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/AbstractPlugin.java index d056fbb..e64c22b 100644 --- a/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/AbstractPlugin.java +++ b/modules/core/domain/src/main/java/org/rhq/core/domain/plugin/AbstractPlugin.java @@ -23,7 +23,6 @@
package org.rhq.core.domain.plugin;
-import java.io.ByteArrayInputStream; import java.io.Serializable;
import javax.persistence.Column; @@ -40,8 +39,6 @@ import javax.persistence.PrePersist; import javax.persistence.SequenceGenerator; import javax.persistence.Table;
-import org.rhq.core.util.MessageDigestGenerator; - /** * Base plugin implementation that agent and server plugin implementations extend. * diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/search/SavedSearch.java b/modules/core/domain/src/main/java/org/rhq/core/domain/search/SavedSearch.java index a9d4ff1..147942b 100644 --- a/modules/core/domain/src/main/java/org/rhq/core/domain/search/SavedSearch.java +++ b/modules/core/domain/src/main/java/org/rhq/core/domain/search/SavedSearch.java @@ -22,13 +22,18 @@ */ package org.rhq.core.domain.search;
+import java.io.Serializable; + import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; +import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; import javax.persistence.SequenceGenerator; import javax.persistence.Table;
@@ -55,7 +60,9 @@ import org.rhq.core.domain.auth.Subject; @Entity @SequenceGenerator(name = "id", sequenceName = "RHQ_SAVED_SEARCH_ID_SEQ") @Table(name = "RHQ_SAVED_SEARCH") -public class SavedSearch { +public class SavedSearch implements Serializable { + + private static final long serialVersionUID = 1L;
@Id @Column(name = "ID", nullable = false) @@ -75,16 +82,14 @@ public class SavedSearch { @Column(name = "PATTERN", nullable = false) private String pattern;
- @Column(name = "JPQL_TRANSLATION") - private String jpqlTranslation; - @Column(name = "LAST_COMPUTE_TIME", nullable = false) private long lastComputeTime;
@Column(name = "RESULT_COUNT") private Long resultCount;
- @Column(name = "SUBJECT_ID", nullable = false) + @JoinColumn(name = "SUBJECT_ID", nullable = false) + @ManyToOne(fetch = FetchType.LAZY) private Subject subject;
@Column(name = "SUBJECT_ID", insertable = false, updatable = false) @@ -105,7 +110,6 @@ public class SavedSearch { setName(name); // name can be null, to allow for saving searches quickly
this.description = null; - this.jpqlTranslation = null; // null value for pre-computed JPQL implies computation is needed this.lastComputeTime = 0; // further imply that computation needs to occur this.resultCount = null; // NULL resultCount implies either computation failed or hasn't begun yet this.global = false; // user must promote saved search to be a global after creation @@ -157,14 +161,6 @@ public class SavedSearch { this.pattern = pattern; }
- public String getJpqlTranslation() { - return jpqlTranslation; - } - - public void setJpqlTransation(String jpqlTranslation) { - this.jpqlTranslation = jpqlTranslation; - } - public long getLastComputeTime() { return lastComputeTime; } @@ -250,4 +246,19 @@ public class SavedSearch {
return true; } + + @Override + public String toString() { + return "SavedSearch [" // + + "id=" + id // + + ", context=" + context // + + ", description=" + description // + + ", global=" + global // + + ", lastComputeTime=" + lastComputeTime // + + ", name=" + name // + + ", pattern=" + pattern // + + ", resultCount=" + resultCount // + + ", subjectId=" + subjectId + "]"; + } + } diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/search/SearchSubsystem.java b/modules/core/domain/src/main/java/org/rhq/core/domain/search/SearchSubsystem.java index a834833..cc489f8 100644 --- a/modules/core/domain/src/main/java/org/rhq/core/domain/search/SearchSubsystem.java +++ b/modules/core/domain/src/main/java/org/rhq/core/domain/search/SearchSubsystem.java @@ -25,6 +25,7 @@ package org.rhq.core.domain.search; import java.util.HashMap; import java.util.Map;
+import org.rhq.core.domain.resource.Resource; import org.rhq.core.domain.resource.group.ResourceGroup;
/** @@ -40,8 +41,8 @@ import org.rhq.core.domain.resource.group.ResourceGroup; */ public enum SearchSubsystem {
- Resource(org.rhq.core.domain.resource.Resource.class), // - Group(ResourceGroup.class); + RESOURCE(Resource.class), // + GROUP(ResourceGroup.class);
private Class<?> entityClass; private static Map<Class<?>, SearchSubsystem> subsystems; @@ -63,4 +64,13 @@ public enum SearchSubsystem { public static SearchSubsystem get(Class<?> entityClass) { return SearchSubsystem.subsystems.get(entityClass); } + + /** + * A Java bean style getter to allow us to access the enum name from JSP or Facelets pages + * + * @return the enum name + */ + public String getName() { + return name(); + } } diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/search/SearchSuggestion.java b/modules/core/domain/src/main/java/org/rhq/core/domain/search/SearchSuggestion.java new file mode 100644 index 0000000..7e47275 --- /dev/null +++ b/modules/core/domain/src/main/java/org/rhq/core/domain/search/SearchSuggestion.java @@ -0,0 +1,94 @@ +package org.rhq.core.domain.search; + +import java.io.Serializable; + +public class SearchSuggestion implements Serializable, Comparable<SearchSuggestion> { + + private static final long serialVersionUID = 1L; + + public enum Kind { + Unknown(""), // + InstructionalTextComment(""), // + GlobalSavedSearch("GLOBAL"), // + UserSavedSearch("SAVED"), // + AdvancedOperator("SYNTAX"), // + Advanced("QUERY"), // + Simple("TEXT"); + + private String displayName; + + private Kind(String displayName) { + this.displayName = displayName; + } + + public String getDisplayName() { + return displayName; + } + + public String getName() { + return name(); + } + } + + private final Kind kind; + private final String value; + private final String label; + private final int startIndex; + private final int endIndex; + + public SearchSuggestion(Kind kind, String value) { + this(kind, value, 0, 0); + } + + public SearchSuggestion(Kind kind, String value, int startIndex, int length) { + this.kind = kind; + this.label = value; + this.value = value; + this.startIndex = startIndex; + this.endIndex = startIndex + length; + } + + public SearchSuggestion(Kind kind, String label, String value, int startIndex, int length) { + this.kind = kind; + this.label = label; + this.value = value; + this.startIndex = startIndex; + this.endIndex = startIndex + length; + } + + public Kind getKind() { + return kind; + } + + public String getLabel() { + return label; + } + + public String getValue() { + return value; + } + + public int getStartIndex() { + return startIndex; + } + + public int getEndIndex() { + return endIndex; + } + + @Override + public int compareTo(SearchSuggestion other) { + int kindComparision = (this.kind.ordinal() - other.kind.ordinal()); + if (kindComparision != 0) { + return kindComparision; + } + return label.compareTo(other.label); + } + + public String toString() { + String before = label.substring(0, startIndex); + String highlight = label.substring(startIndex, endIndex); + String after = label.substring(endIndex); + return before + "(" + highlight + ")" + after + "->" + value; + } +} diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/common/framework/UserPreferencesUIBean.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/common/framework/UserPreferencesUIBean.java index 0b87f7f..8fa9e9f 100644 --- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/common/framework/UserPreferencesUIBean.java +++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/common/framework/UserPreferencesUIBean.java @@ -19,15 +19,14 @@ package org.rhq.enterprise.gui.common.framework;
import java.util.List; -import java.util.Enumeration; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory;
import org.rhq.core.domain.auth.Subject; +import org.rhq.core.domain.criteria.SavedSearchCriteria; import org.rhq.core.domain.resource.Resource; import org.rhq.core.domain.resource.group.ResourceGroup; +import org.rhq.core.domain.search.SavedSearch; import org.rhq.core.domain.util.PageControl; +import org.rhq.core.domain.util.PageOrdering; import org.rhq.core.gui.util.FacesContextUtility; import org.rhq.enterprise.gui.legacy.ParamConstants; import org.rhq.enterprise.gui.legacy.WebUser; @@ -35,6 +34,7 @@ import org.rhq.enterprise.gui.legacy.WebUserPreferences; import org.rhq.enterprise.gui.util.EnterpriseFacesContextUtility; import org.rhq.enterprise.server.resource.ResourceManagerLocal; import org.rhq.enterprise.server.resource.group.ResourceGroupManagerLocal; +import org.rhq.enterprise.server.search.SavedSearchManagerLocal; import org.rhq.enterprise.server.util.LookupUtil;
/** @@ -42,23 +42,40 @@ import org.rhq.enterprise.server.util.LookupUtil; */ public class UserPreferencesUIBean {
- private final Log log = LogFactory.getLog(UserPreferencesUIBean.class); + //private final Log log = LogFactory.getLog(UserPreferencesUIBean.class);
public static final String LEFT_RESOURCE_NAV_SHOWING = "ui.leftResourceNavShowing"; public static final String SUMMARY_PANEL_DISPLAY_STATE = "ui.summaryPanelDisplayState";
private ResourceManagerLocal resourceManager = LookupUtil.getResourceManager(); private ResourceGroupManagerLocal groupManager = LookupUtil.getResourceGroupManager(); + private SavedSearchManagerLocal savedSearchManager = LookupUtil.getSavedSearchManager(); + private List<Resource> resourceFavorites; private List<ResourceGroup> groupFavorites; + private List<SavedSearch> savedSearches; private String refreshPath;
+ private WebUser webUser; + private Subject subject; + public Subject getSubject() { - return EnterpriseFacesContextUtility.getSubject(); + if (subject == null) { + loadUserInfo(); + } + return subject; }
public WebUser getWebUser() { - return EnterpriseFacesContextUtility.getWebUser(); + if (webUser == null) { + loadUserInfo(); + } + return webUser; + } + + private void loadUserInfo() { + webUser = EnterpriseFacesContextUtility.getWebUser(); + subject = webUser.getSubject(); }
public String getLeftResourceNavState() { @@ -68,8 +85,7 @@ public class UserPreferencesUIBean { }
public void setLeftResourceNavState(String state) { - WebUser webUser = EnterpriseFacesContextUtility.getWebUser(); - WebUserPreferences preferences = webUser.getWebPreferences(); + WebUserPreferences preferences = getWebUser().getWebPreferences(); preferences.setPreference(LEFT_RESOURCE_NAV_SHOWING, state); }
@@ -95,17 +111,13 @@ public class UserPreferencesUIBean { }
public void setPageRefresh(int refresh, String path) { - WebUser webUser = EnterpriseFacesContextUtility.getWebUser(); - WebUserPreferences preferences = webUser.getWebPreferences(); + WebUserPreferences preferences = getWebUser().getWebPreferences();
preferences.setPreference("PATH_REFRESH." + path, refresh); }
- - public int getPageRefresh() { - WebUser webUser = EnterpriseFacesContextUtility.getWebUser(); - WebUserPreferences preferences = webUser.getWebPreferences(); + WebUserPreferences preferences = getWebUser().getWebPreferences();
String path = (String) FacesContextUtility.getRequest().getAttribute("javax.servlet.forward.request_uri"); if (path == null) { @@ -124,13 +136,11 @@ public class UserPreferencesUIBean { }
public String getSummaryPanelDisplayState() { - return EnterpriseFacesContextUtility.getWebUser().getWebPreferences().getPreference( - SUMMARY_PANEL_DISPLAY_STATE, "true"); + return getWebUser().getWebPreferences().getPreference(SUMMARY_PANEL_DISPLAY_STATE, "true"); }
public void setSummaryPanelDisplayState(String state) { - WebUser webUser = EnterpriseFacesContextUtility.getWebUser(); - WebUserPreferences preferences = webUser.getWebPreferences(); + WebUserPreferences preferences = getWebUser().getWebPreferences(); preferences.setPreference(SUMMARY_PANEL_DISPLAY_STATE, state); }
@@ -146,6 +156,20 @@ public class UserPreferencesUIBean { return resourceFavorites; }
+ public List<SavedSearch> getSavedSearches() { + if (savedSearches == null) { + SavedSearchCriteria criteria = new SavedSearchCriteria(); + criteria.addFilterSubjectId(getSubject().getId()); + criteria.addFilterGlobal(true); + criteria.setFiltersOptional(true); // get this user's searches as well as global ones + criteria.addSortGlobal(PageOrdering.DESC); // globals, then user-specified + criteria.addSortName(PageOrdering.ASC); // each sublist is alphabetical + + savedSearches = savedSearchManager.findSavedSearchesByCriteria(getSubject(), criteria); + } + return savedSearches; + } + public List<ResourceGroup> getGroupFavorites() { if (groupFavorites == null) { WebUser user = EnterpriseFacesContextUtility.getWebUser(); diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/inventory/browse/BrowseGroupsUIBean.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/inventory/browse/BrowseGroupsUIBean.java index 37941e7..aad85f1 100644 --- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/inventory/browse/BrowseGroupsUIBean.java +++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/inventory/browse/BrowseGroupsUIBean.java @@ -13,6 +13,7 @@ import org.rhq.core.domain.auth.Subject; import org.rhq.core.domain.criteria.ResourceGroupCriteria; import org.rhq.core.domain.resource.group.GroupCategory; import org.rhq.core.domain.resource.group.composite.ResourceGroupComposite; +import org.rhq.core.domain.search.SearchSuggestion; import org.rhq.core.domain.util.PageControl; import org.rhq.core.domain.util.PageList; import org.rhq.core.gui.util.FacesContextUtility; @@ -21,7 +22,6 @@ import org.rhq.enterprise.gui.common.framework.PagedDataTableUIBean; import org.rhq.enterprise.gui.common.paging.PageControlView; import org.rhq.enterprise.gui.common.paging.PagedListDataModel; import org.rhq.enterprise.server.resource.group.ResourceGroupManagerLocal; -import org.rhq.enterprise.server.search.execution.SearchSuggestion; import org.rhq.enterprise.server.util.LookupUtil;
public class BrowseGroupsUIBean extends PagedDataTableUIBean { diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/inventory/browse/BrowseResourcesUIBean.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/inventory/browse/BrowseResourcesUIBean.java index 074cd3a..e01a8f2 100644 --- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/inventory/browse/BrowseResourcesUIBean.java +++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/inventory/browse/BrowseResourcesUIBean.java @@ -13,7 +13,9 @@ import org.rhq.core.domain.auth.Subject; import org.rhq.core.domain.criteria.ResourceCriteria; import org.rhq.core.domain.resource.ResourceCategory; import org.rhq.core.domain.resource.composite.ResourceComposite; +import org.rhq.core.domain.search.SavedSearch; import org.rhq.core.domain.search.SearchSubsystem; +import org.rhq.core.domain.search.SearchSuggestion; import org.rhq.core.domain.util.PageControl; import org.rhq.core.domain.util.PageList; import org.rhq.core.gui.util.FacesContextUtility; @@ -24,8 +26,8 @@ import org.rhq.enterprise.gui.common.paging.PageControlView; import org.rhq.enterprise.gui.common.paging.ResourceNameDisambiguatingPagedListDataModel; import org.rhq.enterprise.gui.util.EnterpriseFacesContextUtility; import org.rhq.enterprise.server.resource.ResourceManagerLocal; +import org.rhq.enterprise.server.search.SavedSearchManagerLocal; import org.rhq.enterprise.server.search.execution.SearchAssistManager; -import org.rhq.enterprise.server.search.execution.SearchSuggestion; import org.rhq.enterprise.server.util.HibernatePerformanceMonitor; import org.rhq.enterprise.server.util.LookupUtil;
@@ -34,10 +36,13 @@ public class BrowseResourcesUIBean extends PagedDataTableUIBean {
public static final String MANAGED_BEAN_NAME = "BrowseResourcesUIBean";
- private String filter; - private HtmlInputText filterInput; + private String search; + private HtmlInputText searchInput; private ResourceCategory category;
+ private ResourceManagerLocal resourceManager = LookupUtil.getResourceManager(); + private SavedSearchManagerLocal savedSearchManager = LookupUtil.getSavedSearchManager(); + private static final IntExtractor<ResourceComposite> RESOURCE_ID_EXTRATOR = new IntExtractor<ResourceComposite>() { public int extract(ResourceComposite object) { return object.getResource().getId(); @@ -54,15 +59,21 @@ public class BrowseResourcesUIBean extends PagedDataTableUIBean { category = ResourceCategory.SERVICE; }
- filter = FacesContextUtility.getOptionalRequestParameter("filter"); + String searchId = FacesContextUtility.getOptionalRequestParameter("searchId"); + if (searchId != null) { + SavedSearch savedSearch = savedSearchManager.getSavedSearchById(getSubject(), Integer.valueOf(searchId)); + search = savedSearch.getPattern(); + } else { + search = FacesContextUtility.getOptionalRequestParameter("search"); + } }
- public String getFilter() { - return this.filter; + public String getSearch() { + return this.search; }
- public void setFilter(String filter) { - this.filter = filter; + public void setSearch(String search) { + this.search = search; }
public ResourceCategory getCategory() { @@ -77,8 +88,6 @@ public class BrowseResourcesUIBean extends PagedDataTableUIBean { return dataModel; }
- private ResourceManagerLocal resourceManager = LookupUtil.getResourceManager(); - private class ResultsDataModel extends ResourceNameDisambiguatingPagedListDataModel<ResourceComposite> {
public ResultsDataModel(PageControlView view, String beanName) { @@ -86,14 +95,14 @@ public class BrowseResourcesUIBean extends PagedDataTableUIBean { }
public PageList<ResourceComposite> fetchDataForPage(PageControl pc) { - String filter = getFilter(); + String search = getSearch(); ResourceCategory category = getCategory();
ResourceCriteria criteria = new ResourceCriteria(); criteria.setPageControl(pc); criteria.addFilterResourceCategory(category); - if (filter != null && !filter.trim().equals("")) { - criteria.setSearchExpression(filter); + if (search != null && !search.trim().equals("")) { + criteria.setSearchExpression(search); } criteria.fetchParentResource(true);
@@ -127,25 +136,24 @@ public class BrowseResourcesUIBean extends PagedDataTableUIBean { return FacesContextUtility.getRequest().getParameterValues("selectedItems"); }
- SearchAssistManager searchAssist = new SearchAssistManager(SearchSubsystem.Resource); + SearchAssistManager searchAssist = new SearchAssistManager(getSubject(), SearchSubsystem.RESOURCE);
public List<SearchSuggestion> autocomplete(Object suggest) { String currentInputText = (String) suggest;
// assume caret at the end of the input long id = HibernatePerformanceMonitor.get().start(); - List<SearchSuggestion> suggestions = searchAssist.getAdvancedSuggestions(currentInputText, currentInputText - .length()); + List<SearchSuggestion> suggestions = searchAssist.getSuggestions(currentInputText, currentInputText.length()); HibernatePerformanceMonitor.get().stop(id, "ResourceSuggestions"); return suggestions; }
- public HtmlInputText getFilterInput() { - return filterInput; + public HtmlInputText getSearchInput() { + return searchInput; }
- public void setFilterInput(HtmlInputText filterInput) { - this.filterInput = filterInput; + public void setSearchInput(HtmlInputText searchInput) { + this.searchInput = searchInput; }
} diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/legacy/action/resource/hub/ResourceHubPortalAction.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/legacy/action/resource/hub/ResourceHubPortalAction.java index f3d14be..1c775c8 100644 --- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/legacy/action/resource/hub/ResourceHubPortalAction.java +++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/legacy/action/resource/hub/ResourceHubPortalAction.java @@ -36,6 +36,7 @@ import org.jetbrains.annotations.NotNull;
import org.rhq.core.domain.auth.Subject; import org.rhq.core.domain.plugin.Plugin; +import org.rhq.core.domain.resource.InventorySummary; import org.rhq.core.domain.resource.ResourceCategory; import org.rhq.core.domain.resource.composite.ResourceComposite; import org.rhq.core.domain.util.PageList; @@ -48,7 +49,6 @@ import org.rhq.enterprise.gui.legacy.util.HubUtils; import org.rhq.enterprise.gui.legacy.util.RequestUtils; import org.rhq.enterprise.gui.legacy.util.SessionUtils; import org.rhq.enterprise.gui.util.WebUtility; -import org.rhq.core.domain.resource.InventorySummary; import org.rhq.enterprise.server.resource.ResourceTypeManagerLocal; import org.rhq.enterprise.server.util.LookupUtil;
@@ -86,29 +86,23 @@ public class ResourceHubPortalAction extends BaseAction { messages = getResources(request); ResourceHubForm hubForm = (ResourceHubForm) form;
- /* - * once search functionality is complete, this will redirect to the new inventory manager; - * until then, keep it working against the old ResourceHub - */ - if (false) { - String filter = hubForm.getKeywords(); - if (filter.equals("Resource Name")) { - filter = null; // user didn't type a filter, just selected a category and clicked 'GO' - } - String category = hubForm.getResourceCategory(); - String subtab = "all"; - try { - ResourceCategory.valueOf(category.toUpperCase()); - subtab = category.toLowerCase(); - } catch (Exception e) { - subtab = "hub"; - } - String url = "/rhq/inventory/browseResources.xhtml?subtab=" + subtab; - if (filter != null && !filter.trim().equals("")) { - url += "&filter=" + filter; - } - response.sendRedirect(url); + String searchExpression = hubForm.getKeywords(); + if (searchExpression.equals("Resource Name")) { + searchExpression = null; // user didn't type a filter, just selected a category and clicked 'GO' + } + String category = hubForm.getResourceCategory(); + String subtab = "all"; + try { + ResourceCategory.valueOf(category.toUpperCase()); + subtab = category.toLowerCase(); + } catch (Exception e) { + subtab = "hub"; + } + String url = "/rhq/inventory/browseResources.xhtml?subtab=" + subtab; + if (searchExpression != null && !searchExpression.trim().equals("")) { + url += "&search=name=" + searchExpression; } + response.sendRedirect(url);
org.rhq.core.domain.util.PageControl pageControl = WebUtility.getPageControl(request); Subject subject = RequestUtils.getSubject(request); diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/startup/StartupServlet.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/startup/StartupServlet.java index d6cb267..51107b2 100644 --- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/startup/StartupServlet.java +++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/startup/StartupServlet.java @@ -59,6 +59,7 @@ import org.rhq.enterprise.server.plugin.pc.ServerPluginServiceManagement; import org.rhq.enterprise.server.resource.ResourceTypeManagerLocal; import org.rhq.enterprise.server.scheduler.SchedulerLocal; import org.rhq.enterprise.server.scheduler.jobs.AsyncResourceDeleteJob; +import org.rhq.enterprise.server.scheduler.jobs.SavedSearchResultCountRecalculationJob; import org.rhq.enterprise.server.scheduler.jobs.CheckForSuspectedAgentsJob; import org.rhq.enterprise.server.scheduler.jobs.CheckForTimedOutConfigUpdatesJob; import org.rhq.enterprise.server.scheduler.jobs.CheckForTimedOutContentRequestsJob; @@ -325,6 +326,16 @@ public class StartupServlet extends HttpServlet { LookupUtil.getSystemManager().scheduleConfigCacheReloader();
try { + // Do not check until we are up at least 1 min, and every minute thereafter. + final long initialDelay = 1000L * 60; + final long interval = 1000L * 60; + scheduler.scheduleSimpleRepeatingJob(SavedSearchResultCountRecalculationJob.class, true, false, initialDelay, + interval); + } catch (Exception e) { + log("Cannot schedule asynchronous resource deletion job: " + e.getMessage()); + } + + try { // Do not check until we are up at least 1 min, and every 5 minutes thereafter. final long initialDelay = 1000L * 60; final long interval = 1000L * 60 * 5; diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/common/menu/menu.xhtml b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/common/menu/menu.xhtml index 232974b..8e016de 100644 --- a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/common/menu/menu.xhtml +++ b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/common/menu/menu.xhtml @@ -124,6 +124,21 @@ </c:if> </c:forEach> </rich:menuGroup> + + ui:remove***** Resources > SAVED SEARCHES *****</ui:remove> + <rich:menuGroup value="Saved Searches" icon="/images/bookmark.png"> + <c:forEach var="savedSearch" items="#{UserPreferencesUIBean.savedSearches}"> + <c:if test="#{savedSearch.context.name == 'RESOURCE'}"> + <rich:menuItem submitMode="none" + icon="/images/icons/Flag_#{savedSearch.global ? 'yellow' : 'blue'}_16.png" + onclick="window.location = '/rhq/inventory/browseResources.xhtml?subtab=all&searchId=#{savedSearch.id}'"> + <h:outputText value="#{savedSearch.name}" /> + <h:outputText value=" (#{savedSearch.resultCount})" + rendered="#{not empty savedSearch.resultCount}" /> + </rich:menuItem> + </c:if> + </c:forEach> + </rich:menuGroup>
diff --git a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/inventory/browseResources.xhtml b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/inventory/browseResources.xhtml index ac11225..90d45c0 100644 --- a/modules/enterprise/gui/portal-war/src/main/webapp/rhq/inventory/browseResources.xhtml +++ b/modules/enterprise/gui/portal-war/src/main/webapp/rhq/inventory/browseResources.xhtml @@ -31,17 +31,23 @@ <a4j:keepAlive beanName="BrowseResourcesUIBean"/>
<h:form id="browseResourcesForm"> - <input type="hidden" name="subtab" value="${param.subtab}"/> + <input type="hidden" name="subtab" value="${param.subtab}" />
<p/> <h:panelGroup> - <h:outputLabel for="filter" value="Search: " /> - <h:inputText id="filter" - binding="#{BrowseResourcesUIBean.filterInput}" - value="#{BrowseResourcesUIBean.filter}" + <h:outputLabel for="search" value="Search: " /> + <h:inputText id="search" + binding="#{BrowseResourcesUIBean.searchInput}" + value="#{BrowseResourcesUIBean.search}" onkeypress="return ignoreEnterKey(event);" - style="width: 600px;" /> - <rich:suggestionbox id="suggest" for="filter" + style="width: 600px;"> + ui:remove + <a4j:support event="onfocus" reRender="suggest" + disableDefault="true" status="commonStatus" limitToList="true" + ajaxSingle="true" oncomplete="#{rich:component('suggest')}.show(event, {})"/> + </ui:remove> + </h:inputText> + <rich:suggestionbox id="suggest" for="search" width="600" height="400" border="1" cellpadding="1" cellspacing="1" minChars="0" @@ -56,7 +62,19 @@ eventsQueue="resourceSearchSuggestions" ignoreDupResponses="true" rendered="true"> <!-- disable until auto-completer is added --> - <h:column> + <h:column width="10%"> + <h:outputText value="#{suggestItem.kind.displayName}" style="font-variant: small-caps; color: gray;" + rendered="#{suggestItem.kind.name eq 'Simple'}" /> + <h:outputText value="#{suggestItem.kind.displayName}" style="font-variant: small-caps; " + rendered="#{suggestItem.kind.name eq 'Advanced'}" /> + <h:outputText value="#{suggestItem.kind.displayName}" style="font-variant: small-caps; color: yellow" + rendered="#{suggestItem.kind.name eq 'AdvancedOperator'}" /> + <h:outputText value="#{suggestItem.kind.displayName}" style="font-variant: small-caps; color: green;" + rendered="#{suggestItem.kind.name eq 'UserSavedSearch'}" /> + <h:outputText value="#{suggestItem.kind.displayName}" style="font-variant: small-caps; color: orange;" + rendered="#{suggestItem.kind.name eq 'GlobalSavedSearch'}" /> + </h:column> + <h:column width="90%"> <h:outputText value="#{suggestItem.label}" /> </h:column> </rich:suggestionbox> diff --git a/modules/enterprise/server/jar/src/main/antlr3/org/rhq/enterprise/server/search/RHQL.g b/modules/enterprise/server/jar/src/main/antlr3/org/rhq/enterprise/server/search/RHQL.g index b8ff97e..4fa879e 100644 --- a/modules/enterprise/server/jar/src/main/antlr3/org/rhq/enterprise/server/search/RHQL.g +++ b/modules/enterprise/server/jar/src/main/antlr3/org/rhq/enterprise/server/search/RHQL.g @@ -95,6 +95,7 @@ conditionalPrimary
simpleConditionalExpression : c=context WS* op=comparisonOperator WS* ident=identifier -> ^($op $c ^(VALUE $ident)) + | ident=identifier ; // rewrite tree output so operator is always the root -- ignore captured WS
context diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/scheduler/jobs/SavedSearchResultCountRecalculationJob.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/scheduler/jobs/SavedSearchResultCountRecalculationJob.java new file mode 100644 index 0000000..a1e53b3 --- /dev/null +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/scheduler/jobs/SavedSearchResultCountRecalculationJob.java @@ -0,0 +1,95 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2008 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +package org.rhq.enterprise.server.scheduler.jobs; + +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; + +import org.rhq.core.domain.auth.Subject; +import org.rhq.core.domain.criteria.ResourceCriteria; +import org.rhq.core.domain.criteria.SavedSearchCriteria; +import org.rhq.core.domain.resource.Resource; +import org.rhq.core.domain.search.SavedSearch; +import org.rhq.core.domain.search.SearchSubsystem; +import org.rhq.core.domain.util.PageList; +import org.rhq.enterprise.server.resource.ResourceManagerLocal; +import org.rhq.enterprise.server.search.SavedSearchManagerLocal; +import org.rhq.enterprise.server.util.LookupUtil; + +/** + * + * + * @author Joseph Marques + */ +public class SavedSearchResultCountRecalculationJob extends AbstractStatefulJob { + + private final static Log LOG = LogFactory.getLog(SavedSearchResultCountRecalculationJob.class); + + private SavedSearchManagerLocal savedSearchManager = LookupUtil.getSavedSearchManager(); + private ResourceManagerLocal resourceManager = LookupUtil.getResourceManager(); + + private Subject overlord = LookupUtil.getSubjectManager().getOverlord(); + + @Override + public void executeJobCode(JobExecutionContext context) throws JobExecutionException { + List<SavedSearch> staleSavedSearches = getSavedSearchesNeedingRecomputation(); + + int errors = 0; + int updated = 0; + long totalMillis = 0; + for (SavedSearch next : staleSavedSearches) { + try { + if (next.getContext() == SearchSubsystem.RESOURCE) { + ResourceCriteria criteria = new ResourceCriteria(); + criteria.setSearchExpression(next.getPattern()); + + totalMillis -= System.currentTimeMillis(); + PageList<Resource> results = resourceManager.findResourcesByCriteria(overlord, criteria); + totalMillis += System.currentTimeMillis(); + + if (results.getTotalSize() != next.getResultCount()) { + next.setResultCount((long) results.getTotalSize()); + savedSearchManager.updateSavedSearch(overlord, next); + updated++; + } + } + } catch (Throwable t) { + // TODO: mark this saved search as "broken" so that future computation is suppressed for it + errors++; + LOG.error("Could not calculate result count for SavedSearch[name=" + next.getName() + ", patter='" + + next.getPattern() + "']"); + } + } + LOG.info("Statistics: updated " + updated + " in " + totalMillis + " ms (" + errors + " errors)"); + } + + private List<SavedSearch> getSavedSearchesNeedingRecomputation() { + long fiveMinutesAgo = System.currentTimeMillis() - (5 * 60 * 1000); + + SavedSearchCriteria criteria = new SavedSearchCriteria(); + criteria.addFilterLastComputeTimeMax(fiveMinutesAgo); + + List<SavedSearch> results = savedSearchManager.findSavedSearchesByCriteria(overlord, criteria); + return results; + } +} diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/assist/AbstractSearchAssistant.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/assist/AbstractSearchAssistant.java index 90c790f..05b39e1 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/assist/AbstractSearchAssistant.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/assist/AbstractSearchAssistant.java @@ -12,6 +12,16 @@ import org.rhq.enterprise.server.util.LookupUtil;
public abstract class AbstractSearchAssistant implements SearchAssistant {
+ private int maxResultCount = 20; + + public int getMaxResultCount() { + return maxResultCount; + } + + public void setMaxResultCount(int maxResultCount) { + this.maxResultCount = maxResultCount; + } + @Override public List<String> getSimpleContexts() { return Collections.emptyList(); @@ -46,7 +56,7 @@ public abstract class AbstractSearchAssistant implements SearchAssistant { @SuppressWarnings("unchecked") protected final List<String> execute(String jpql) { Query query = LookupUtil.getEntityManager().createQuery(jpql); - query.setMaxResults(20); + query.setMaxResults(maxResultCount); List<String> results = query.getResultList(); return results; } diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/assist/ResourceSearchAssistant.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/assist/ResourceSearchAssistant.java index 94dcb7f..0e2b3df 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/assist/ResourceSearchAssistant.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/assist/ResourceSearchAssistant.java @@ -21,7 +21,7 @@ public class ResourceSearchAssistant extends AbstractSearchAssistant {
@Override public SearchSubsystem getSearchSubsystem() { - return SearchSubsystem.Resource; + return SearchSubsystem.RESOURCE; }
@Override diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/assist/SearchAssistant.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/assist/SearchAssistant.java index 804e0bb..4314e06 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/assist/SearchAssistant.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/assist/SearchAssistant.java @@ -6,14 +6,14 @@ import org.rhq.core.domain.search.SearchSubsystem;
public interface SearchAssistant {
- public SearchSubsystem getSearchSubsystem(); + SearchSubsystem getSearchSubsystem();
- public List<String> getSimpleContexts(); + List<String> getSimpleContexts();
- public List<String> getParameterizedContexts(); + List<String> getParameterizedContexts();
- public List<String> getParameters(String context, String filter); + List<String> getParameters(String context, String filter);
- public List<String> getValues(String context, String param, String filter); + List<String> getValues(String context, String param, String filter);
} diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/execution/SearchAssistManager.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/execution/SearchAssistManager.java index e500449..2cb808c 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/execution/SearchAssistManager.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/execution/SearchAssistManager.java @@ -9,19 +9,29 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory;
+import org.rhq.core.domain.auth.Subject; +import org.rhq.core.domain.criteria.SavedSearchCriteria; +import org.rhq.core.domain.search.SavedSearch; import org.rhq.core.domain.search.SearchSubsystem; +import org.rhq.core.domain.search.SearchSuggestion; +import org.rhq.core.domain.search.SearchSuggestion.Kind; +import org.rhq.core.domain.util.PageOrdering; +import org.rhq.enterprise.server.search.SavedSearchManagerLocal; +import org.rhq.enterprise.server.search.assist.AbstractSearchAssistant; import org.rhq.enterprise.server.search.assist.ResourceSearchAssistant; -import org.rhq.enterprise.server.search.assist.SearchAssistant; import org.rhq.enterprise.server.util.HibernatePerformanceMonitor; +import org.rhq.enterprise.server.util.LookupUtil;
public class SearchAssistManager {
private static final Log LOG = LogFactory.getLog(SearchAssistManager.class); + private SavedSearchManagerLocal savedSearchManager = LookupUtil.getSavedSearchManager();
private static List<String> comparisonOperators = Arrays.asList("!==", "!=", "==", "="); - private static List<String> booleanOperators = Arrays.asList("and", "or"); + private static List<String> booleanOperators = Arrays.asList("and", "or", "|");
- private SearchAssistant completor; + private Subject subject; + private AbstractSearchAssistant completor;
/* * states: @@ -266,12 +276,13 @@ public class SearchAssistManager { } }
- public SearchAssistManager(SearchSubsystem searchSubsystem) { + public SearchAssistManager(Subject subject, SearchSubsystem searchSubsystem) { + this.subject = subject; this.completor = getAutoCompletor(searchSubsystem); }
- protected SearchAssistant getAutoCompletor(SearchSubsystem searchSubsystem) { - if (searchSubsystem == SearchSubsystem.Resource) { + protected AbstractSearchAssistant getAutoCompletor(SearchSubsystem searchSubsystem) { + if (searchSubsystem == SearchSubsystem.RESOURCE) { return new ResourceSearchAssistant(); } else { throw new IllegalArgumentException("No SearchAssistant found for SearchSubsystem[" + searchSubsystem + "]"); @@ -286,7 +297,39 @@ public class SearchAssistManager { return results; }
- public List<SearchSuggestion> getAdvancedSuggestions(String expression, int caretPos) { + public List<SearchSuggestion> getSuggestions(String expression, int caretPos) { + //List<SearchSuggestion> simple = getSimpleSuggestions(expression, caretPos); + List<SearchSuggestion> advanced = getAdvancedSuggestions(expression, caretPos, SearchSuggestion.Kind.Advanced); + List<SearchSuggestion> userSavedSearches = getUserSavedSearchSuggestions(expression); + List<SearchSuggestion> globalSavedSearches = getGlobalSavedSearchSuggestions(expression); + + List<SearchSuggestion> results = new ArrayList<SearchSuggestion>(); + //results.addAll(simple); + results.addAll(advanced); + results.addAll(userSavedSearches); + results.addAll(globalSavedSearches); + Collections.sort(results); + return results; + } + + public List<SearchSuggestion> getSimpleSuggestions(String expression, int caretPos) { + List<SearchSuggestion> results = new ArrayList<SearchSuggestion>(); + for (String nextContext : completor.getSimpleContexts()) { + String intermediateExpression = nextContext + "=" + expression; + List<SearchSuggestion> suggestions = getAdvancedSuggestions(intermediateExpression, caretPos, + SearchSuggestion.Kind.Simple); + results.addAll(suggestions); + } + Collections.sort(results); + if (results.size() > completor.getMaxResultCount()) { + return results.subList(0, completor.getMaxResultCount()); + } else { + return results; + } + } + + public List<SearchSuggestion> getAdvancedSuggestions(String expression, int caretPos, + SearchSuggestion.Kind targetKind) { debug("getAdvancedSuggestions: START"); long id = HibernatePerformanceMonitor.get().start(); SearchTermAssistant assistant = new SearchTermAssistant(expression, caretPos); @@ -296,7 +339,7 @@ public class SearchAssistManager {
if (tokens.length == 0) { debug("getAdvancedSuggestions: no terms"); - return convert(getAllContexts()); // no terms yet defined + return convert(getAllContexts(), targetKind); // no terms yet defined }
String beforeCaret = assistant.getFragmentBeforeCaret(); @@ -309,26 +352,26 @@ public class SearchAssistManager { if (parsed.context.equals("")) { if (tokens.length == 1) { debug("getAdvancedSuggestions: no terms yet, suggesting contexts"); - return convert(getAllContexts()); + return convert(getAllContexts(), targetKind); } else if (isBooleanTerm(assistant.getPreviousToken())) { debug("getAdvancedSuggestions: previous term was boolean, suggesting contexts"); - return convert(getAllContexts()); + return convert(getAllContexts(), targetKind); } else { debug("getAdvancedSuggestions: previous term was not boolean, suggesting boolean"); - return convert(booleanOperators); + return convert(booleanOperators, targetKind); } } else if (isBooleanTerm(parsed.context)) { debug("getAdvancedSuggestions: beforeCaret is whole boolean operator"); - return convert(getAllContexts()); // TODO: should we tell user to type a space first? + return convert(getAllContexts(), targetKind); // TODO: should we tell user to type a space first? } else { // check if this context is complete or not if (completor.getSimpleContexts().contains(parsed.context)) { debug("getAdvancedSuggestions: search term is simple context, wants operator"); - return convert(pad(parsed.context, comparisonOperators, "")); + return convert(pad(parsed.context, comparisonOperators, ""), targetKind); } if (completor.getParameterizedContexts().contains(parsed.context)) { debug("getAdvancedSuggestions: search term is parameterized context, wants open bracket"); - return convert(Arrays.asList(parsed.context + "[")); + return convert(Arrays.asList(parsed.context + "["), targetKind); }
debug("getAdvancedSuggestions: search term wants context completion"); @@ -343,11 +386,12 @@ public class SearchAssistManager { startsWithContexts.add(context + "["); } } - return convert(startsWithContexts); + return convert(startsWithContexts, targetKind); } case PARAM: debug("getAdvancedSuggestions: param state"); - return convert(pad(parsed.context + "[", completor.getParameters(parsed.context, parsed.param), "]")); + return convert(pad(parsed.context + "[", completor.getParameters(parsed.context, parsed.param), "]"), + targetKind); case OPERATOR: debug("getAdvancedSuggestions: operator state"); if (comparisonOperators.contains(parsed.operator)) { @@ -355,11 +399,11 @@ public class SearchAssistManager { List<String> valueSuggestions = pad(""", completor.getValues(parsed.context, parsed.param, ""), """); if (completor.getSimpleContexts().contains(parsed.context)) { debug("getAdvancedSuggestions: suggesting value completions for a simple context"); - return convert(pad(parsed.context + parsed.operator, valueSuggestions, "")); + return convert(pad(parsed.context + parsed.operator, valueSuggestions, ""), targetKind); } else { debug("getAdvancedSuggestions: suggesting value completions for a parameterized context"); return convert(pad(parsed.context + "[" + parsed.param + "]" + parsed.operator, valueSuggestions, - "")); + ""), targetKind); } }
@@ -372,9 +416,9 @@ public class SearchAssistManager {
debug("getAdvancedSuggestions: providing suggestions for comparison operators"); if (completor.getSimpleContexts().contains(parsed.context)) { - return convert(pad(parsed.context, operatorSuggestions, "")); + return convert(pad(parsed.context, operatorSuggestions, ""), targetKind); } else { - return convert(pad(parsed.context + "[" + parsed.param + "]", operatorSuggestions, "")); + return convert(pad(parsed.context + "[" + parsed.param + "]", operatorSuggestions, ""), targetKind); } case VALUE: debug("getAdvancedSuggestions: value state"); @@ -382,16 +426,65 @@ public class SearchAssistManager { """); if (completor.getSimpleContexts().contains(parsed.context)) { debug("getAdvancedSuggestions: suggesting value completions for a simple context"); - return convert(pad(parsed.context + parsed.operator, valueSuggestions, "")); + return convert(pad(parsed.context + parsed.operator, valueSuggestions, ""), targetKind); } else { debug("getAdvancedSuggestions: suggesting value completions for a parameterized context"); - return convert(pad(parsed.context + "[" + parsed.param + "]" + parsed.operator, valueSuggestions, "")); + return convert(pad(parsed.context + "[" + parsed.param + "]" + parsed.operator, valueSuggestions, ""), + targetKind); } default: return Collections.emptyList(); } }
+ public List<SearchSuggestion> getUserSavedSearchSuggestions(String expression) { + SavedSearchCriteria criteria = new SavedSearchCriteria(); + criteria.addFilterSubjectId(subject.getId()); + if (expression != null && expression.trim().equals("")) { + criteria.addFilterName(expression); + } + + criteria.setCaseSensitive(false); + criteria.addSortName(PageOrdering.ASC); + + List<SavedSearch> savedSearchResults = savedSearchManager.findSavedSearchesByCriteria(subject, criteria); + + List<SearchSuggestion> results = new ArrayList<SearchSuggestion>(); + for (SavedSearch next : savedSearchResults) { + String label = next.getName(); + String value = next.getPattern(); + int index = next.getName().toLowerCase().indexOf(expression); + SearchSuggestion suggestion = new SearchSuggestion(Kind.UserSavedSearch, label, value, index, expression + .length()); + results.add(suggestion); + } + return results; + } + + public List<SearchSuggestion> getGlobalSavedSearchSuggestions(String expression) { + SavedSearchCriteria criteria = new SavedSearchCriteria(); + criteria.addFilterGlobal(true); + if (expression != null && expression.trim().equals("")) { + criteria.addFilterName(expression); + } + + criteria.setCaseSensitive(false); + criteria.addSortName(PageOrdering.ASC); + + List<SavedSearch> savedSearchResults = savedSearchManager.findSavedSearchesByCriteria(subject, criteria); + + List<SearchSuggestion> results = new ArrayList<SearchSuggestion>(); + for (SavedSearch next : savedSearchResults) { + String label = next.getName(); + String value = next.getPattern(); + int index = next.getName().toLowerCase().indexOf(expression); + SearchSuggestion suggestion = new SearchSuggestion(Kind.GlobalSavedSearch, label, value, index, expression + .length()); + results.add(suggestion); + } + return results; + } + private boolean isBooleanTerm(String term) { for (String op : booleanOperators) { if (op.equals(term)) { @@ -401,10 +494,10 @@ public class SearchAssistManager { return false; }
- private List<SearchSuggestion> convert(List<String> suggestions) { + private List<SearchSuggestion> convert(List<String> suggestions, SearchSuggestion.Kind targetKind) { List<SearchSuggestion> results = new ArrayList<SearchSuggestion>(suggestions.size()); for (String suggestion : suggestions) { - results.add(new SearchSuggestion(SearchSuggestion.SearchCategory.Advanced, suggestion)); + results.add(new SearchSuggestion(targetKind, suggestion)); } return results; } diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/execution/SearchSuggestion.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/execution/SearchSuggestion.java deleted file mode 100644 index e69090d..0000000 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/execution/SearchSuggestion.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.rhq.enterprise.server.search.execution; - -public class SearchSuggestion { - public enum SearchCategory { - Simple, Advanced, SavedSearch, InstructionalTextComment, Unknown; - } - - private final SearchCategory category; - private final String value; - private final String label; - private final int startIndex; - private final int endIndex; - - public SearchSuggestion(SearchCategory category, String value) { - this(category, value, 0, 0); - } - - public SearchSuggestion(SearchCategory category, String value, int startIndex, int length) { - this.category = category; - this.label = value; - this.value = value; - this.startIndex = startIndex; - this.endIndex = startIndex + length; - } - - public SearchCategory getCategory() { - return category; - } - - public String getLabel() { - return label; - } - - public String getValue() { - return value; - } - - public int getStartIndex() { - return startIndex; - } - - public int getEndIndex() { - return endIndex; - } - - public String toString() { - String before = label.substring(0, startIndex); - String highlight = label.substring(startIndex, endIndex); - String after = label.substring(endIndex); - return before + "(" + highlight + ")" + after + "->" + value; - } -} diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/execution/SearchTranslationManager.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/execution/SearchTranslationManager.java index 806987f..812bc57 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/execution/SearchTranslationManager.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/execution/SearchTranslationManager.java @@ -57,19 +57,19 @@ public class SearchTranslationManager {
public String getJPQLSelectStatement() throws Exception { String jpql = "SELECT " + alias + " FROM " + entity + " " + alias + " WHERE " + getJPQLWhereFragment(); - System.out.println("JPQL was:"); + //System.out.println("JPQL was:"); PrintUtils.printJPQL(jpql.split(" ")); - System.out.println(); + //System.out.println(); return jpql; }
public String getJPQLWhereFragment() throws Exception { RHQLParser.searchExpression_return searchAST = parser.searchExpression();
- System.out.println("Search was: " + expression); + //System.out.println("Search was: " + expression); CommonTree searchExpressionTree = (CommonTree) searchAST.getTree(); - System.out.println("Errors found: " + adaptor.getErrorMessages()); - System.out.println("Tree was:"); + //System.out.println("Errors found: " + adaptor.getErrorMessages()); + //System.out.println("Tree was:"); PrintUtils.print(searchExpressionTree, ""); String fragment = generateJPQL(searchExpressionTree); return fragment; @@ -193,12 +193,12 @@ public class SearchTranslationManager { }
if (lineBreakers.contains(next)) { - System.out.println(); - System.out.print(indent); + //System.out.println(); + //System.out.print(indent); }
- System.out.print(next); - System.out.print(" "); + //System.out.print(next); + //System.out.print(" ");
if (next.equals(")")) { indent = indent.substring(3); @@ -228,11 +228,11 @@ public class SearchTranslationManager { return; }
- System.out.print(indent + token.getText()); + //System.out.print(indent + token.getText()); if (isStringNode(token)) { - System.out.println(collapseStringChildren(tree)); + //System.out.println(collapseStringChildren(tree)); } else { - System.out.println(); + //System.out.println(); for (int childIndex = 0; childIndex < tree.getChildCount(); childIndex++) { CommonTree child = (CommonTree) tree.getChild(childIndex); print(child, indent + " "); @@ -261,7 +261,7 @@ public class SearchTranslationManager { }
public static void main(String[] args) throws Exception { - SearchTranslationManager manager = new SearchTranslationManager(SearchSubsystem.Resource); + SearchTranslationManager manager = new SearchTranslationManager(SearchSubsystem.RESOURCE); manager.setExpression("(name = rhq and category = server) or plugin = jbossas"); String jpql = manager.getJPQLSelectStatement(); } diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/translation/SearchTranslatorFactory.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/translation/SearchTranslatorFactory.java index fa8d626..ee8ecda 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/translation/SearchTranslatorFactory.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/search/translation/SearchTranslatorFactory.java @@ -8,7 +8,7 @@ public class SearchTranslatorFactory { }
public static SearchTranslator getTranslator(SearchSubsystem searchContext) { - if (searchContext == SearchSubsystem.Resource) { + if (searchContext == SearchSubsystem.RESOURCE) { return new ResourceSearchTranslator(); } throw new IllegalArgumentException("No SearchTranslator found for SearchContext[" + searchContext + "]"); diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/util/CriteriaQueryGenerator.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/util/CriteriaQueryGenerator.java index 0e1a789..ff71760 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/util/CriteriaQueryGenerator.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/util/CriteriaQueryGenerator.java @@ -398,7 +398,7 @@ public final class CriteriaQueryGenerator {
// translate first, if there was an error we won't add the dangling 'AND' to the where clause String translatedJPQL = searchManager.getJPQLWhereFragment(); - LOG.info("Translated JPQL Fragment was: " + translatedJPQL); + LOG.debug("Translated JPQL Fragment was: " + translatedJPQL); if (translatedJPQL != null) { searchExpressionWhereClause = translatedJPQL; } diff --git a/modules/enterprise/server/jar/src/main/resources/single-line-rhql.txt b/modules/enterprise/server/jar/src/main/resources/single-line-rhql.txt index 8793fb1..265071b 100644 --- a/modules/enterprise/server/jar/src/main/resources/single-line-rhql.txt +++ b/modules/enterprise/server/jar/src/main/resources/single-line-rhql.txt @@ -94,4 +94,12 @@ context = value1 | ((context = value2)) ((context = value1)) context = value2 (context = value1) (context = value2) (context = value1 (context = value2)) -context = value1 ((context = value2)) \ No newline at end of file +context = value1 ((context = value2)) + +# simple terms +hello +hello world +"hello world" 'foo bar' +'hello world' "foo bar" +hello | world +context=value | world \ No newline at end of file diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/search/GenericSearchAssistTest.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/search/GenericSearchAssistTest.java index 867ee78..5d51d10 100644 --- a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/search/GenericSearchAssistTest.java +++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/search/GenericSearchAssistTest.java @@ -10,7 +10,7 @@ import java.util.List;
import org.testng.annotations.Test;
-import org.rhq.enterprise.server.search.execution.SearchSuggestion; +import org.rhq.core.domain.search.SearchSuggestion; import org.rhq.enterprise.server.test.AbstractEJB3Test;
public class GenericSearchAssistTest extends AbstractEJB3Test { @@ -36,7 +36,7 @@ public class GenericSearchAssistTest extends AbstractEJB3Test { }
count++; - List<SearchSuggestion> results = new TestAutoCompletionManager().getAdvancedSuggestions(expression, + List<SearchSuggestion> results = new TestAutoCompletionManager().getSuggestions(expression, expression.length()); List<String> expectedResults = Arrays.asList(expected.split(" "));
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/search/TestAutoCompletionManager.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/search/TestAutoCompletionManager.java index 89cb5ff..28a11a7 100644 --- a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/search/TestAutoCompletionManager.java +++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/search/TestAutoCompletionManager.java @@ -8,7 +8,6 @@ import java.util.Map;
import org.rhq.core.domain.search.SearchSubsystem; import org.rhq.enterprise.server.search.assist.AbstractSearchAssistant; -import org.rhq.enterprise.server.search.assist.SearchAssistant; import org.rhq.enterprise.server.search.execution.SearchAssistManager;
public class TestAutoCompletionManager extends SearchAssistManager { @@ -62,10 +61,10 @@ public class TestAutoCompletionManager extends SearchAssistManager { }
public TestAutoCompletionManager() { - super(null); + super(null, null); }
- protected SearchAssistant getAutoCompletor(SearchSubsystem searchContext) { + protected AbstractSearchAssistant getAutoCompletor(SearchSubsystem searchContext) { return new TestAutoCompletor(); } }