-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add search cappabilities for actions history
- Loading branch information
1 parent
ee123f2
commit 037f7d1
Showing
6 changed files
with
747 additions
and
1 deletion.
There are no files selected for viewing
141 changes: 141 additions & 0 deletions
141
hawkular-alerts-api/src/main/java/org/hawkular/alerts/api/model/paging/ActionComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/* | ||
* Copyright 2015 Red Hat, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.hawkular.alerts.api.model.paging; | ||
|
||
import java.util.Comparator; | ||
|
||
import org.hawkular.alerts.api.model.action.Action; | ||
|
||
/** | ||
* | ||
* @author Lucas Ponce | ||
*/ | ||
public class ActionComparator implements Comparator<Action> { | ||
|
||
public enum Field { | ||
ACTION_PLUGIN("actionPlugin"), | ||
ACTION_ID("actionId"), | ||
ALERT_ID("alertId"), | ||
CTIME("ctime"), | ||
RESULT("result"); | ||
|
||
private String text; | ||
|
||
Field(String text) { | ||
this.text = text; | ||
} | ||
|
||
public String getText() { | ||
return this.text; | ||
} | ||
|
||
public static Field getField(String text) { | ||
if (text == null || text.isEmpty()) { | ||
return ALERT_ID; | ||
} | ||
for (Field f : values()) { | ||
if (f.getText().compareToIgnoreCase(text) == 0) { | ||
return f; | ||
} | ||
} | ||
return ALERT_ID; | ||
} | ||
}; | ||
|
||
private Field field; | ||
private Order.Direction direction; | ||
|
||
public ActionComparator() { | ||
this(Field.ALERT_ID, Order.Direction.ASCENDING); | ||
} | ||
|
||
public ActionComparator(Field field, Order.Direction direction) { | ||
this.field = field; | ||
this.direction = direction; | ||
} | ||
@Override | ||
public int compare(Action o1, Action o2) { | ||
if (o1 == null && o2 == null) { | ||
return 0; | ||
} | ||
if (o1 == null && o2 != null) { | ||
return 1; | ||
} | ||
if (o1 != null && o2 == null) { | ||
return -1; | ||
} | ||
int iOrder = direction == Order.Direction.ASCENDING ? 1 : -1; | ||
switch (field) { | ||
case ALERT_ID: | ||
if (o1.getAlert() == null && o2.getAlert() == null) { | ||
return 0; | ||
} | ||
if (o1.getAlert() == null && o2.getAlert() != null) { | ||
return 1; | ||
} | ||
if (o1.getAlert() != null && o2.getAlert() == null) { | ||
return -1; | ||
} | ||
if (o1.getAlert().getAlertId() == null && o2.getAlert().getAlertId() == null) { | ||
return 0; | ||
} | ||
if (o1.getAlert().getAlertId() == null && o2.getAlert().getAlertId() != null) { | ||
return 1; | ||
} | ||
if (o1.getAlert().getAlertId() != null && o2.getAlert().getAlertId() == null) { | ||
return -1; | ||
} | ||
return o1.getAlert().getAlertId().compareTo(o2.getAlert().getAlertId()) * iOrder; | ||
case ACTION_PLUGIN: | ||
if (o1.getActionPlugin() == null && o2.getActionPlugin() == null) { | ||
return 0; | ||
} | ||
if (o1.getActionPlugin() == null && o2.getActionPlugin() != null) { | ||
return 1; | ||
} | ||
if (o1.getActionPlugin() != null && o2.getActionPlugin() == null) { | ||
return -1; | ||
} | ||
return o1.getActionPlugin().compareTo(o2.getActionPlugin()) * iOrder; | ||
case CTIME: | ||
return (int)((o1.getCtime() - o2.getCtime()) * iOrder); | ||
case ACTION_ID: | ||
if (o1.getActionId() == null && o2.getActionId() == null) { | ||
return 0; | ||
} | ||
if (o1.getActionId() == null && o2.getActionId() != null) { | ||
return 1; | ||
} | ||
if (o1.getActionId() != null && o2.getActionId() == null) { | ||
return -1; | ||
} | ||
return o1.getActionId().compareTo(o2.getActionId()) * iOrder; | ||
case RESULT: | ||
if (o1.getResult() == null && o2.getResult() == null) { | ||
return 0; | ||
} | ||
if (o1.getResult() == null && o2.getResult() != null) { | ||
return 1; | ||
} | ||
if (o1.getResult() != null && o2.getResult() == null) { | ||
return -1; | ||
} | ||
return o1.getResult().compareTo(o2.getResult()) * iOrder; | ||
} | ||
return 0; | ||
} | ||
} |
147 changes: 147 additions & 0 deletions
147
hawkular-alerts-api/src/main/java/org/hawkular/alerts/api/services/ActionsCriteria.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
/* | ||
* Copyright 2015 Red Hat, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.hawkular.alerts.api.services; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* Query criteria for fetching Actions from history backend. | ||
* | ||
* @author Jay Shaughnessy | ||
* @author Lucas Ponce | ||
*/ | ||
public class ActionsCriteria { | ||
Long startTime = null; | ||
Long endTime = null; | ||
String actionPlugin = null; | ||
Collection<String> actionPlugins = null; | ||
String actionId = null; | ||
Collection<String> actionIds = null; | ||
String alertId = null; | ||
Collection<String> alertIds = null; | ||
String result = null; | ||
Collection<String> results = null; | ||
|
||
public Long getStartTime() { | ||
return startTime; | ||
} | ||
|
||
public void setStartTime(Long startTime) { | ||
this.startTime = startTime; | ||
} | ||
|
||
public Long getEndTime() { | ||
return endTime; | ||
} | ||
|
||
public void setEndTime(Long endTime) { | ||
this.endTime = endTime; | ||
} | ||
|
||
public String getActionPlugin() { | ||
return actionPlugin; | ||
} | ||
|
||
public void setActionPlugin(String actionPlugin) { | ||
this.actionPlugin = actionPlugin; | ||
} | ||
|
||
public Collection<String> getActionPlugins() { | ||
return actionPlugins; | ||
} | ||
|
||
public void setActionPlugins(Collection<String> actionPlugins) { | ||
this.actionPlugins = actionPlugins; | ||
} | ||
|
||
public String getActionId() { | ||
return actionId; | ||
} | ||
|
||
public void setActionId(String actionId) { | ||
this.actionId = actionId; | ||
} | ||
|
||
public Collection<String> getActionIds() { | ||
return actionIds; | ||
} | ||
|
||
public void setActionIds(Collection<String> actionIds) { | ||
this.actionIds = actionIds; | ||
} | ||
|
||
public String getAlertId() { | ||
return alertId; | ||
} | ||
|
||
public void setAlertId(String alertId) { | ||
this.alertId = alertId; | ||
} | ||
|
||
public Collection<String> getAlertIds() { | ||
return alertIds; | ||
} | ||
|
||
public void setAlertIds(Collection<String> alertIds) { | ||
this.alertIds = alertIds; | ||
} | ||
|
||
public String getResult() { | ||
return result; | ||
} | ||
|
||
public void setResult(String result) { | ||
this.result = result; | ||
} | ||
|
||
public Collection<String> getResults() { | ||
return results; | ||
} | ||
|
||
public void setResults(Collection<String> results) { | ||
this.results = results; | ||
} | ||
|
||
public boolean hasCriteria() { | ||
return null != startTime | ||
|| null != endTime | ||
|| null != actionPlugin | ||
|| null != actionId | ||
|| null != alertId | ||
|| null != result | ||
|| (null != actionPlugins && !actionPlugins.isEmpty()) | ||
|| (null != actionIds && !actionIds.isEmpty()) | ||
|| (null != alertIds && !alertIds.isEmpty()) | ||
|| (null != results && !results.isEmpty()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ActionsCriteria{" + | ||
"startTime=" + startTime + | ||
", endTime=" + endTime + | ||
", actionPlugin='" + actionPlugin + '\'' + | ||
", actionPlugins=" + actionPlugins + | ||
", actionId='" + actionId + '\'' + | ||
", actionIds=" + actionIds + | ||
", alertId='" + alertId + '\'' + | ||
", alertIds=" + alertIds + | ||
", result='" + result + '\'' + | ||
", results=" + results + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.