use of org.ff4j.audit.Event in project ff4j by ff4j.
the class EventRepositoryElastic method getUserHitCount.
@Override
public Map<String, MutableHitCount> getUserHitCount(EventQueryDefinition query) {
JestResult result = getConnection().execute(getBuilder().queryGetEventQueryDefinition(query, EventConstants.ACTION_CHECK_OK));
List<Event> events = result.getSourceAsObjectList(Event.class);
Map<String, MutableHitCount> hitCount = new HashMap<String, MutableHitCount>();
for (Event event : events) {
String user = event.getUser();
if (hitCount.containsKey(user)) {
hitCount.get(user).inc();
} else {
hitCount.put(user, new MutableHitCount(1));
}
}
return hitCount;
}
use of org.ff4j.audit.Event in project ff4j by ff4j.
the class MongoEventMapper method fromStore.
/**
* {@inheritDoc}
*/
@SuppressWarnings({ "unchecked" })
@Override
public Event fromStore(Document bean) {
Event evt = new Event();
evt.setAction(bean.getString(ATTRIBUTE_ACTION));
evt.setDuration(bean.getInteger(ATTRIBUTE_DURATION));
evt.setHostName(bean.getString(ATTRIBUTE_HOST));
evt.setName(bean.getString(ATTRIBUTE_NAME));
evt.setSource(bean.getString(ATTRIBUTE_SOURCE));
evt.setTimestamp(bean.getLong(ATTRIBUTE_TIME));
evt.setType(bean.getString(ATTRIBUTE_TYPE));
evt.setUuid(bean.getString(ATTRIBUTE_ID));
evt.setUser(bean.getString(ATTRIBUTE_USER));
if (bean.containsKey(ATTRIBUTE_KEYS)) {
evt.setCustomKeys((Map<String, String>) JSON.parse(bean.getString(ATTRIBUTE_KEYS)));
}
return evt;
}
use of org.ff4j.audit.Event in project ff4j by ff4j.
the class DBObjectBuilderTest method testMongoEventMapper.
@Test
public void testMongoEventMapper() {
Event evt = new Event("JAVA", EventConstants.TARGET_FEATURE, "toto", EventConstants.ACTION_CHECK_OFF);
MongoEventMapper mem = new MongoEventMapper();
Event evt2 = mem.fromStore(mem.toStore(evt));
Assert.assertEquals(evt.getUuid(), evt2.getUuid());
}
use of org.ff4j.audit.Event in project ff4j by ff4j.
the class InMemoryEventRepository method getUserHitCount.
/**
* {@inheritDoc}
*/
@Override
public Map<String, MutableHitCount> getUserHitCount(EventQueryDefinition query) {
Map<String, MutableHitCount> hitRatio = new TreeMap<String, MutableHitCount>();
for (Event event : searchFeatureUsageEvents(query)) {
String user = Util.hasLength(event.getUser()) ? event.getUser() : "anonymous";
if (!hitRatio.containsKey(user)) {
hitRatio.put(user, new MutableHitCount());
}
hitRatio.get(user).inc();
}
return hitRatio;
}
use of org.ff4j.audit.Event in project ff4j by ff4j.
the class InMemoryEventRepository method getFeatureUsageHistory.
/**
* {@inheritDoc}
*/
@Override
public TimeSeriesChart getFeatureUsageHistory(EventQueryDefinition query, TimeUnit units) {
// Create the interval depending on units
TimeSeriesChart tsc = new TimeSeriesChart(query.getFrom(), query.getTo(), units);
for (String currentDay : getCandidateDays(query.getFrom(), query.getTo())) {
// There are some event this day
if (featureUsageEvents.containsKey(currentDay)) {
for (Map.Entry<String, EventSeries> entry : featureUsageEvents.get(currentDay).entrySet()) {
String currentFeatureName = entry.getKey();
// Filter feature names if required
Set<String> filteredFeatures = query.getNamesFilter();
if (filteredFeatures == null || filteredFeatures.isEmpty() || filteredFeatures.contains(currentFeatureName)) {
// Loop over events
for (Event evt : entry.getValue()) {
// Between bounds (keydate not enough)
if (isEventInInterval(evt, query.getFrom(), query.getTo())) {
// Create new serie if new feature Name
if (!tsc.getSeries().containsKey((currentFeatureName))) {
tsc.createNewSerie(currentFeatureName);
}
// Match FeatureName
Serie<Map<String, MutableHitCount>> serie = tsc.getSeries().get(currentFeatureName);
// Match SlotName
String slotName = tsc.getSdf().format(new Date(evt.getTimestamp()));
// Should be always 'true' as the tsc.getsdf().format() will get a slotName.
if (serie.getValue().containsKey(slotName)) {
// Fast Increment
serie.getValue().get(slotName).inc();
}
}
}
}
}
}
}
// Recolor series
List<String> colors = Util.generateHSVGradient("ee1100", "442299", tsc.getSeries().size());
int idxColor = 0;
for (Map.Entry<String, Serie<Map<String, MutableHitCount>>> serie : tsc.getSeries().entrySet()) {
serie.getValue().setColor(colors.get(idxColor));
idxColor++;
}
return tsc;
}
Aggregations