@Test public void testAuditLogGetExperimentLabelThrowsException() { doThrow(new RuntimeException("runtimeexcep")).when(mockAuditLog).getExperimentLabel(); when(mockAuditLog.getTime()).thenReturn(new Date()); when(mockAuditLog.getAppName()).thenReturn("testApp"); ArrayList<AuditLog> entries = new ArrayList<>(); entries.add(mockAuditLog); List<AuditLogEntry> result = repository.makeAuditLogEntries(entries); assertEquals("Size should be eq", 1, result.size()); assertEquals("value shoudl be eq", null, result.get(0).getExperimentLabel()); }
protected List<AuditLogEntry> makeAuditLogEntries(List<AuditLog> entries) { List<AuditLogEntry> auditLogEntries = new ArrayList<>(entries.size()); for (AuditLog auditLog : entries) { Calendar calendar = Calendar.getInstance(); calendar.setTime(auditLog.getTime()); String userName = makeEmptyStringForNull(auditLog.getUsername()); String email = makeEmptyStringForNull(auditLog.getEmail()); String firstName = makeEmptyStringForNull(auditLog.getFirstName()); String lastName = makeEmptyStringForNull(auditLog.getLastName()); String userId = makeEmptyStringForNull(auditLog.getUserId()); UserInfo userInfo = UserInfo .newInstance(Username.valueOf(userName)).withEmail(email) .withFirstName(firstName).withLastName(lastName) .withUserId(userId).build(); AuditLogAction ala = null; String action = null; try { action = auditLog.getAction(); ala = AuditLogAction.valueOf(action); } catch (Exception e) { LOGGER.warn("Exception while creating audit log action: " + action, e); ala = AuditLogAction.UNSPECIFIED_ACTION; } Bucket.Label bucketLabel = null; String bucketLabelString = null; try { bucketLabelString = auditLog.getBucketLabel(); if (!StringUtils.isBlank(bucketLabelString)) bucketLabel = Bucket.Label.valueOf(bucketLabelString); } catch (Exception e) { LOGGER.warn("Exception while creating audit log bucket label: " + bucketLabelString, e); } Experiment.Label experimentLabel = null; String expLabelString = null; try { expLabelString = auditLog.getExperimentLabel(); if (!StringUtils.isBlank(expLabelString)) experimentLabel = Label.valueOf(expLabelString); } catch (Exception e) { LOGGER.warn("Exception while creating audit log experiment label: " + expLabelString, e); } Experiment.ID experimentId = null; UUID expId = null; try { expId = auditLog.getExperimentId(); if (expId != null) experimentId = Experiment.ID .valueOf(expId); } catch (Exception e) { LOGGER.warn("Exception while creating audit log experiment id: " + expId, e); } Application.Name appName = null; if (!AuditLogRepository.GLOBAL_ENTRY_APPLICATION.toString().equals( auditLog.getAppName())) appName = Application.Name.valueOf(auditLog.getAppName()); AuditLogEntry entry = new AuditLogEntry(calendar, userInfo, ala, appName, experimentLabel, experimentId, bucketLabel, auditLog.getProperty(), auditLog.getBefore(), auditLog.getAfter()); auditLogEntries.add(entry); } return auditLogEntries; }
CassandraAuditLogRepository implements AuditLogRepository { protected List<AuditLogEntry> makeAuditLogEntries(List<AuditLog> entries) { List<AuditLogEntry> auditLogEntries = new ArrayList<>(entries.size()); for (AuditLog auditLog : entries) { Calendar calendar = Calendar.getInstance(); calendar.setTime(auditLog.getTime()); String userName = makeEmptyStringForNull(auditLog.getUsername()); String email = makeEmptyStringForNull(auditLog.getEmail()); String firstName = makeEmptyStringForNull(auditLog.getFirstName()); String lastName = makeEmptyStringForNull(auditLog.getLastName()); String userId = makeEmptyStringForNull(auditLog.getUserId()); UserInfo userInfo = UserInfo .newInstance(Username.valueOf(userName)).withEmail(email) .withFirstName(firstName).withLastName(lastName) .withUserId(userId).build(); AuditLogAction ala = null; String action = null; try { action = auditLog.getAction(); ala = AuditLogAction.valueOf(action); } catch (Exception e) { LOGGER.warn("Exception while creating audit log action: " + action, e); ala = AuditLogAction.UNSPECIFIED_ACTION; } Bucket.Label bucketLabel = null; String bucketLabelString = null; try { bucketLabelString = auditLog.getBucketLabel(); if (!StringUtils.isBlank(bucketLabelString)) bucketLabel = Bucket.Label.valueOf(bucketLabelString); } catch (Exception e) { LOGGER.warn("Exception while creating audit log bucket label: " + bucketLabelString, e); } Experiment.Label experimentLabel = null; String expLabelString = null; try { expLabelString = auditLog.getExperimentLabel(); if (!StringUtils.isBlank(expLabelString)) experimentLabel = Label.valueOf(expLabelString); } catch (Exception e) { LOGGER.warn("Exception while creating audit log experiment label: " + expLabelString, e); } Experiment.ID experimentId = null; UUID expId = null; try { expId = auditLog.getExperimentId(); if (expId != null) experimentId = Experiment.ID .valueOf(expId); } catch (Exception e) { LOGGER.warn("Exception while creating audit log experiment id: " + expId, e); } Application.Name appName = null; if (!AuditLogRepository.GLOBAL_ENTRY_APPLICATION.toString().equals( auditLog.getAppName())) appName = Application.Name.valueOf(auditLog.getAppName()); AuditLogEntry entry = new AuditLogEntry(calendar, userInfo, ala, appName, experimentLabel, experimentId, bucketLabel, auditLog.getProperty(), auditLog.getBefore(), auditLog.getAfter()); auditLogEntries.add(entry); } return auditLogEntries; } }
CassandraAuditLogRepository implements AuditLogRepository { protected List<AuditLogEntry> makeAuditLogEntries(List<AuditLog> entries) { List<AuditLogEntry> auditLogEntries = new ArrayList<>(entries.size()); for (AuditLog auditLog : entries) { Calendar calendar = Calendar.getInstance(); calendar.setTime(auditLog.getTime()); String userName = makeEmptyStringForNull(auditLog.getUsername()); String email = makeEmptyStringForNull(auditLog.getEmail()); String firstName = makeEmptyStringForNull(auditLog.getFirstName()); String lastName = makeEmptyStringForNull(auditLog.getLastName()); String userId = makeEmptyStringForNull(auditLog.getUserId()); UserInfo userInfo = UserInfo .newInstance(Username.valueOf(userName)).withEmail(email) .withFirstName(firstName).withLastName(lastName) .withUserId(userId).build(); AuditLogAction ala = null; String action = null; try { action = auditLog.getAction(); ala = AuditLogAction.valueOf(action); } catch (Exception e) { LOGGER.warn("Exception while creating audit log action: " + action, e); ala = AuditLogAction.UNSPECIFIED_ACTION; } Bucket.Label bucketLabel = null; String bucketLabelString = null; try { bucketLabelString = auditLog.getBucketLabel(); if (!StringUtils.isBlank(bucketLabelString)) bucketLabel = Bucket.Label.valueOf(bucketLabelString); } catch (Exception e) { LOGGER.warn("Exception while creating audit log bucket label: " + bucketLabelString, e); } Experiment.Label experimentLabel = null; String expLabelString = null; try { expLabelString = auditLog.getExperimentLabel(); if (!StringUtils.isBlank(expLabelString)) experimentLabel = Label.valueOf(expLabelString); } catch (Exception e) { LOGGER.warn("Exception while creating audit log experiment label: " + expLabelString, e); } Experiment.ID experimentId = null; UUID expId = null; try { expId = auditLog.getExperimentId(); if (expId != null) experimentId = Experiment.ID .valueOf(expId); } catch (Exception e) { LOGGER.warn("Exception while creating audit log experiment id: " + expId, e); } Application.Name appName = null; if (!AuditLogRepository.GLOBAL_ENTRY_APPLICATION.toString().equals( auditLog.getAppName())) appName = Application.Name.valueOf(auditLog.getAppName()); AuditLogEntry entry = new AuditLogEntry(calendar, userInfo, ala, appName, experimentLabel, experimentId, bucketLabel, auditLog.getProperty(), auditLog.getBefore(), auditLog.getAfter()); auditLogEntries.add(entry); } return auditLogEntries; } @Inject  CassandraAuditLogRepository(AuditLogAccessor accessor); }
CassandraAuditLogRepository implements AuditLogRepository { protected List<AuditLogEntry> makeAuditLogEntries(List<AuditLog> entries) { List<AuditLogEntry> auditLogEntries = new ArrayList<>(entries.size()); for (AuditLog auditLog : entries) { Calendar calendar = Calendar.getInstance(); calendar.setTime(auditLog.getTime()); String userName = makeEmptyStringForNull(auditLog.getUsername()); String email = makeEmptyStringForNull(auditLog.getEmail()); String firstName = makeEmptyStringForNull(auditLog.getFirstName()); String lastName = makeEmptyStringForNull(auditLog.getLastName()); String userId = makeEmptyStringForNull(auditLog.getUserId()); UserInfo userInfo = UserInfo .newInstance(Username.valueOf(userName)).withEmail(email) .withFirstName(firstName).withLastName(lastName) .withUserId(userId).build(); AuditLogAction ala = null; String action = null; try { action = auditLog.getAction(); ala = AuditLogAction.valueOf(action); } catch (Exception e) { LOGGER.warn("Exception while creating audit log action: " + action, e); ala = AuditLogAction.UNSPECIFIED_ACTION; } Bucket.Label bucketLabel = null; String bucketLabelString = null; try { bucketLabelString = auditLog.getBucketLabel(); if (!StringUtils.isBlank(bucketLabelString)) bucketLabel = Bucket.Label.valueOf(bucketLabelString); } catch (Exception e) { LOGGER.warn("Exception while creating audit log bucket label: " + bucketLabelString, e); } Experiment.Label experimentLabel = null; String expLabelString = null; try { expLabelString = auditLog.getExperimentLabel(); if (!StringUtils.isBlank(expLabelString)) experimentLabel = Label.valueOf(expLabelString); } catch (Exception e) { LOGGER.warn("Exception while creating audit log experiment label: " + expLabelString, e); } Experiment.ID experimentId = null; UUID expId = null; try { expId = auditLog.getExperimentId(); if (expId != null) experimentId = Experiment.ID .valueOf(expId); } catch (Exception e) { LOGGER.warn("Exception while creating audit log experiment id: " + expId, e); } Application.Name appName = null; if (!AuditLogRepository.GLOBAL_ENTRY_APPLICATION.toString().equals( auditLog.getAppName())) appName = Application.Name.valueOf(auditLog.getAppName()); AuditLogEntry entry = new AuditLogEntry(calendar, userInfo, ala, appName, experimentLabel, experimentId, bucketLabel, auditLog.getProperty(), auditLog.getBefore(), auditLog.getAfter()); auditLogEntries.add(entry); } return auditLogEntries; } @Inject  CassandraAuditLogRepository(AuditLogAccessor accessor); @Override List<AuditLogEntry> getCompleteAuditLogEntryList(); @Override List<AuditLogEntry> getCompleteAuditLogEntryList(int limit); @Override List<AuditLogEntry> getAuditLogEntryList(
            Application.Name applicationName); @Override List<AuditLogEntry> getAuditLogEntryList(
            Application.Name applicationName, int limit); @Override List<AuditLogEntry> getGlobalAuditLogEntryList(); @Override List<AuditLogEntry> getGlobalAuditLogEntryList(int limit); @Override boolean storeEntry(AuditLogEntry entry); }
CassandraAuditLogRepository implements AuditLogRepository { protected List<AuditLogEntry> makeAuditLogEntries(List<AuditLog> entries) { List<AuditLogEntry> auditLogEntries = new ArrayList<>(entries.size()); for (AuditLog auditLog : entries) { Calendar calendar = Calendar.getInstance(); calendar.setTime(auditLog.getTime()); String userName = makeEmptyStringForNull(auditLog.getUsername()); String email = makeEmptyStringForNull(auditLog.getEmail()); String firstName = makeEmptyStringForNull(auditLog.getFirstName()); String lastName = makeEmptyStringForNull(auditLog.getLastName()); String userId = makeEmptyStringForNull(auditLog.getUserId()); UserInfo userInfo = UserInfo .newInstance(Username.valueOf(userName)).withEmail(email) .withFirstName(firstName).withLastName(lastName) .withUserId(userId).build(); AuditLogAction ala = null; String action = null; try { action = auditLog.getAction(); ala = AuditLogAction.valueOf(action); } catch (Exception e) { LOGGER.warn("Exception while creating audit log action: " + action, e); ala = AuditLogAction.UNSPECIFIED_ACTION; } Bucket.Label bucketLabel = null; String bucketLabelString = null; try { bucketLabelString = auditLog.getBucketLabel(); if (!StringUtils.isBlank(bucketLabelString)) bucketLabel = Bucket.Label.valueOf(bucketLabelString); } catch (Exception e) { LOGGER.warn("Exception while creating audit log bucket label: " + bucketLabelString, e); } Experiment.Label experimentLabel = null; String expLabelString = null; try { expLabelString = auditLog.getExperimentLabel(); if (!StringUtils.isBlank(expLabelString)) experimentLabel = Label.valueOf(expLabelString); } catch (Exception e) { LOGGER.warn("Exception while creating audit log experiment label: " + expLabelString, e); } Experiment.ID experimentId = null; UUID expId = null; try { expId = auditLog.getExperimentId(); if (expId != null) experimentId = Experiment.ID .valueOf(expId); } catch (Exception e) { LOGGER.warn("Exception while creating audit log experiment id: " + expId, e); } Application.Name appName = null; if (!AuditLogRepository.GLOBAL_ENTRY_APPLICATION.toString().equals( auditLog.getAppName())) appName = Application.Name.valueOf(auditLog.getAppName()); AuditLogEntry entry = new AuditLogEntry(calendar, userInfo, ala, appName, experimentLabel, experimentId, bucketLabel, auditLog.getProperty(), auditLog.getBefore(), auditLog.getAfter()); auditLogEntries.add(entry); } return auditLogEntries; } @Inject  CassandraAuditLogRepository(AuditLogAccessor accessor); @Override List<AuditLogEntry> getCompleteAuditLogEntryList(); @Override List<AuditLogEntry> getCompleteAuditLogEntryList(int limit); @Override List<AuditLogEntry> getAuditLogEntryList(
            Application.Name applicationName); @Override List<AuditLogEntry> getAuditLogEntryList(
            Application.Name applicationName, int limit); @Override List<AuditLogEntry> getGlobalAuditLogEntryList(); @Override List<AuditLogEntry> getGlobalAuditLogEntryList(int limit); @Override boolean storeEntry(AuditLogEntry entry);  }