@Test public void countEventsAcceptsBlankFilters() { AuditEvent template = new AuditEvent(null, null, null, null, null, null); when(this.store.countEvents(template, null, null)).thenReturn(42L); when(this.auth.hasAccess(this.user, Right.ADMIN, this.xwikiPreferences)).thenReturn(true); long result = this.scriptService.countEvents(" ", " ", " ", " ", " ", " "); Mockito.verify(this.store).countEvents(template, null, null); Assert.assertEquals(42L, result); }
public long countEvents(String action, String userId, String ip, String entityId, String fromTime, String toTime) { if (this.auth.hasAccess(this.users.getCurrentUser(), Right.ADMIN, this.resolver.resolve(Constants.XWIKI_SPACE_REFERENCE))) { Calendar from = null; try { Date d = DATE_FORMAT.parse(fromTime); from = Calendar.getInstance(); from.setTime(d); } catch (Exception e) { } Calendar to = null; try { Date d = DATE_FORMAT.parse(toTime); to = Calendar.getInstance(); to.setTime(d); } catch (Exception e) { } DocumentReference entity = StringUtils.isNotBlank(entityId) ? this.resolverd.resolve(entityId) : null; User user = StringUtils.isNotBlank(userId) ? this.users.getUser(userId) : null; String actionId = StringUtils.isNotBlank(action) ? action : null; String ipValue = StringUtils.isNotBlank(ip) ? ip : null; AuditEvent eventTemplate = new AuditEvent(user, ipValue, actionId, null, entity, null); return this.store.countEvents(eventTemplate, from, to); } return -1; }
AuditScriptService implements ScriptService { public long countEvents(String action, String userId, String ip, String entityId, String fromTime, String toTime) { if (this.auth.hasAccess(this.users.getCurrentUser(), Right.ADMIN, this.resolver.resolve(Constants.XWIKI_SPACE_REFERENCE))) { Calendar from = null; try { Date d = DATE_FORMAT.parse(fromTime); from = Calendar.getInstance(); from.setTime(d); } catch (Exception e) { } Calendar to = null; try { Date d = DATE_FORMAT.parse(toTime); to = Calendar.getInstance(); to.setTime(d); } catch (Exception e) { } DocumentReference entity = StringUtils.isNotBlank(entityId) ? this.resolverd.resolve(entityId) : null; User user = StringUtils.isNotBlank(userId) ? this.users.getUser(userId) : null; String actionId = StringUtils.isNotBlank(action) ? action : null; String ipValue = StringUtils.isNotBlank(ip) ? ip : null; AuditEvent eventTemplate = new AuditEvent(user, ipValue, actionId, null, entity, null); return this.store.countEvents(eventTemplate, from, to); } return -1; } }
AuditScriptService implements ScriptService { public long countEvents(String action, String userId, String ip, String entityId, String fromTime, String toTime) { if (this.auth.hasAccess(this.users.getCurrentUser(), Right.ADMIN, this.resolver.resolve(Constants.XWIKI_SPACE_REFERENCE))) { Calendar from = null; try { Date d = DATE_FORMAT.parse(fromTime); from = Calendar.getInstance(); from.setTime(d); } catch (Exception e) { } Calendar to = null; try { Date d = DATE_FORMAT.parse(toTime); to = Calendar.getInstance(); to.setTime(d); } catch (Exception e) { } DocumentReference entity = StringUtils.isNotBlank(entityId) ? this.resolverd.resolve(entityId) : null; User user = StringUtils.isNotBlank(userId) ? this.users.getUser(userId) : null; String actionId = StringUtils.isNotBlank(action) ? action : null; String ipValue = StringUtils.isNotBlank(ip) ? ip : null; AuditEvent eventTemplate = new AuditEvent(user, ipValue, actionId, null, entity, null); return this.store.countEvents(eventTemplate, from, to); } return -1; }  }
AuditScriptService implements ScriptService { public long countEvents(String action, String userId, String ip, String entityId, String fromTime, String toTime) { if (this.auth.hasAccess(this.users.getCurrentUser(), Right.ADMIN, this.resolver.resolve(Constants.XWIKI_SPACE_REFERENCE))) { Calendar from = null; try { Date d = DATE_FORMAT.parse(fromTime); from = Calendar.getInstance(); from.setTime(d); } catch (Exception e) { } Calendar to = null; try { Date d = DATE_FORMAT.parse(toTime); to = Calendar.getInstance(); to.setTime(d); } catch (Exception e) { } DocumentReference entity = StringUtils.isNotBlank(entityId) ? this.resolverd.resolve(entityId) : null; User user = StringUtils.isNotBlank(userId) ? this.users.getUser(userId) : null; String actionId = StringUtils.isNotBlank(action) ? action : null; String ipValue = StringUtils.isNotBlank(ip) ? ip : null; AuditEvent eventTemplate = new AuditEvent(user, ipValue, actionId, null, entity, null); return this.store.countEvents(eventTemplate, from, to); } return -1; }  @Nonnull List<AuditEvent> getEventsForEntity(DocumentReference entity); @Nonnull List<AuditEvent> getEventsForUser(String userId); @Nonnull List<AuditEvent> getEventsForUser(String userId, String ip); @Nonnull @SuppressWarnings("checkstyle:ParameterNumber") List<AuditEvent> getEvents(int start, int number, String action, String userId, String ip, String entityId,
        String fromTime, String toTime); long countEvents(String action, String userId, String ip, String entityId, String fromTime, String toTime); }
AuditScriptService implements ScriptService { public long countEvents(String action, String userId, String ip, String entityId, String fromTime, String toTime) { if (this.auth.hasAccess(this.users.getCurrentUser(), Right.ADMIN, this.resolver.resolve(Constants.XWIKI_SPACE_REFERENCE))) { Calendar from = null; try { Date d = DATE_FORMAT.parse(fromTime); from = Calendar.getInstance(); from.setTime(d); } catch (Exception e) { } Calendar to = null; try { Date d = DATE_FORMAT.parse(toTime); to = Calendar.getInstance(); to.setTime(d); } catch (Exception e) { } DocumentReference entity = StringUtils.isNotBlank(entityId) ? this.resolverd.resolve(entityId) : null; User user = StringUtils.isNotBlank(userId) ? this.users.getUser(userId) : null; String actionId = StringUtils.isNotBlank(action) ? action : null; String ipValue = StringUtils.isNotBlank(ip) ? ip : null; AuditEvent eventTemplate = new AuditEvent(user, ipValue, actionId, null, entity, null); return this.store.countEvents(eventTemplate, from, to); } return -1; }  @Nonnull List<AuditEvent> getEventsForEntity(DocumentReference entity); @Nonnull List<AuditEvent> getEventsForUser(String userId); @Nonnull List<AuditEvent> getEventsForUser(String userId, String ip); @Nonnull @SuppressWarnings("checkstyle:ParameterNumber") List<AuditEvent> getEvents(int start, int number, String action, String userId, String ip, String entityId,
        String fromTime, String toTime); long countEvents(String action, String userId, String ip, String entityId, String fromTime, String toTime);  }