forked from hygieia/hygieia-core
/
RelatedCollectorItemEventListener.java
42 lines (34 loc) · 1.85 KB
/
RelatedCollectorItemEventListener.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.capitalone.dashboard.event;
import com.capitalone.dashboard.event.constants.sync.Reason;
import com.capitalone.dashboard.event.sync.SyncDashboard;
import com.capitalone.dashboard.event.sync.SyncException;
import com.capitalone.dashboard.model.relation.RelatedCollectorItem;
import com.capitalone.dashboard.repository.CollectorItemRepository;
import com.capitalone.dashboard.repository.CollectorRepository;
import com.capitalone.dashboard.repository.PipelineRepository;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.mapping.event.AfterSaveEvent;
@org.springframework.stereotype.Component
public class RelatedCollectorItemEventListener extends HygieiaMongoEventListener<RelatedCollectorItem> {
private static final Log LOG = LogFactory.getLog(RelatedCollectorItemEventListener.class);
private final SyncDashboard syncDashboard;
@Autowired
public RelatedCollectorItemEventListener(
CollectorItemRepository collectorItemRepository,
PipelineRepository pipelineRepository,
CollectorRepository collectorRepository, SyncDashboard syncDashboard) {
super(collectorItemRepository, pipelineRepository, collectorRepository);
this.syncDashboard = syncDashboard;
}
@Override
public void onAfterSave(AfterSaveEvent<RelatedCollectorItem> event) {
RelatedCollectorItem relatedCollectorItem = event.getSource();
try {
syncDashboard.sync(relatedCollectorItem,!Reason.ARTIFACT_REASON.getAction().equalsIgnoreCase(relatedCollectorItem.getReason()));
} catch (SyncException e) {
LOG.error("Error processing related collector item. ID = " + relatedCollectorItem.getId() + ". Reason " + e.getMessage());
}
}
}