Github user nickwallen commented on a diff in the pull request:
https://github.com/apache/metron/pull/1190#discussion_r216735553
--- Diff:
metron-platform/metron-indexing/src/main/java/org/apache/metron/indexing/dao/metaalert/lucene/AbstractLuceneMetaAlertUpdateDao.java
---
@@ -170,21 +169,51 @@ protected Document
buildCreateDocument(Iterable<Document> alerts, List<String> g
return updates;
}
+ /**
+ * Adds alerts to a metaalert, based on a list of GetRequests provided
for retrieval.
+ * @param metaAlertGuid The GUID of the metaalert to be given new
children.
+ * @param alertRequests GetRequests for the appropriate alerts to add.
+ * @return The updated metaalert with alerts added.
+ */
+ @Override
+ public Document addAlertsToMetaAlert(String metaAlertGuid,
List<GetRequest> alertRequests)
+ throws IOException {
+
+ Document metaAlert = retrieveLatestDao
+ .getLatest(metaAlertGuid, MetaAlertConstants.METAALERT_TYPE);
+ if (MetaAlertStatus.ACTIVE.getStatusString()
+
.equals(metaAlert.getDocument().get(MetaAlertConstants.STATUS_FIELD))) {
+ Iterable<Document> alerts =
retrieveLatestDao.getAllLatest(alertRequests);
+ Map<Document, Optional<String>> updates =
buildAddAlertToMetaAlertUpdates(metaAlert, alerts);
+ update(updates);
+ return metaAlert;
+ } else {
+ throw new IllegalStateException("Adding alerts to an INACTIVE meta
alert is not allowed");
+ }
+ }
+
+ /**
+ * Removes alerts from a metaalert, based on a list of GetRequests
provided for retrieval.
+ * @param metaAlertGuid The GUID of the metaalert to remove children
from.
+ * @param alertRequests A list of GetReqests that will provide the
alerts to remove
+ * @return The updated metaalert with alerts removed.
+ * @throws IllegalStateException If the metaalert is inactive.
+ */
@Override
@SuppressWarnings("unchecked")
- public boolean removeAlertsFromMetaAlert(String metaAlertGuid,
List<GetRequest> alertRequests)
- throws IOException {
+ public Document removeAlertsFromMetaAlert(String metaAlertGuid,
List<GetRequest> alertRequests)
+ throws IOException, IllegalStateException {
Document metaAlert = retrieveLatestDao
.getLatest(metaAlertGuid, MetaAlertConstants.METAALERT_TYPE);
if (metaAlert == null) {
- return false;
+ return null;
--- End diff --
Should we also treat this as an exceptional condition?
---