/** * Creates an AuditLogEntry. * * @param time the event time (required) * @param user the event user (required) * @param action the event action (required) * @param experiment the experiment (if applicable) * @param bucketLabel the bucket label (if applicable) * @param changedProperty the changed property (if applicable) * @param before the property before (if applicable) * @param after the property after (if applicable) */ public AuditLogEntry(Calendar time, UserInfo user, AuditLogAction action, ExperimentBase experiment, Bucket.Label bucketLabel, String changedProperty, String before, String after) { this(time, user, action, experiment == null ? null : experiment.getApplicationName(), experiment == null ? null : experiment.getLabel(), experiment == null ? null : experiment.getID(), bucketLabel, changedProperty, before, after); }
/** * This method finds the right attributes to set. The set fields can be found * in the {@link TextTemplates}. * * @param buckEvent an {@link BucketCreateEvent} that represents the changes * @return the message for the email */ private String getBucketCreatedMessage(BucketCreateEvent buckEvent) { ST template = new ST(BUCKET_CREATED); Map<String, String> variables = new HashMap<>(); Bucket buck = buckEvent.getBucket(); ExperimentBase exp = buckEvent.getExperiment(); put(variables, EXPERIMENT_LABEL, exp.getLabel()); put(variables, BUCKET_NAME, buck.getLabel().toString()); put(variables, APPLICATION_NAME, String.valueOf(exp.getApplicationName())); put(variables, USER_NAME, getUserRepresentation(buckEvent.getUser())); return replaceVariablesInTemplate(variables, template); }
/** * The addressors for a given experiment are the administrators of the application the * experiment belongs to. * * @param event the {@link ExperimentEvent} to be processed * @return a list of the email-addresses of the addressors */ private Collection<? extends String> getExperimentAddressor(ExperimentEvent event) { Set<String> adressors; ExperimentBase exp = event.getExperiment(); if (exp != null) { adressors = getAdminEmails(exp.getApplicationName()); } else { throw new EventLogException("An ExperimentEvent was recorded without having an Experiment!"); } return adressors; }
/** * This method finds the right attributes to set. The set fields can be found * in the {@link TextTemplates}. * * @param buckEvent an {@link BucketChangeEvent} that represents the changes * @return the message for the email */ private String getBucketChangedMessage(BucketChangeEvent buckEvent) { ST template = new ST(BUCKET_CHANGE); Map<String, String> variables = new HashMap<>(); Bucket buck = buckEvent.getBucket(); ExperimentBase exp = buckEvent.getExperiment(); put(variables, EXPERIMENT_LABEL, exp.getLabel()); put(variables, BUCKET_NAME, buck.getLabel().toString()); put(variables, APPLICATION_NAME, String.valueOf(exp.getApplicationName())); put(variables, USER_NAME, getUserRepresentation(buckEvent.getUser())); put(variables, FIELD_NAME, buckEvent.getPropertyName()); if (buckEvent.getPropertyName() != null && "allocation".equalsIgnoreCase(buckEvent.getPropertyName())) { put(variables, FIELD_BEFORE, String.valueOf(((double) Math.round(Double.parseDouble(buckEvent.getBefore()) * 10000d) / 10000d) * 100).concat("%")); put(variables, FIELD_AFTER, String.valueOf(((double) Math.round(Double.parseDouble(buckEvent.getAfter()) * 10000d) / 10000d) * 100).concat("%")); } else { put(variables, FIELD_BEFORE, buckEvent.getBefore()); put(variables, FIELD_AFTER, buckEvent.getAfter()); } return replaceVariablesInTemplate(variables, template); }
/** * This method finds the right attributes to set. The set fields can be found * in the {@link TextTemplates}. * * @param expEvent an {@link ExperimentCreateEvent} that represents the created experiment * @return the message for the email */ private String getExperimentCreatedMessage(ExperimentCreateEvent expEvent) { ST template = new ST(EXPERIMENT_CREATED); Map<String, String> variables = new HashMap<>(); ExperimentBase exp = expEvent.getExperiment(); put(variables, EXPERIMENT_LABEL, exp.getLabel()); put(variables, EXPERIMENT_ID, String.valueOf(exp.getID())); put(variables, APPLICATION_NAME, String.valueOf(exp.getApplicationName())); put(variables, USER_NAME, getUserRepresentation(expEvent.getUser())); return replaceVariablesInTemplate(variables, template); }
/** * This method finds the right attributes to set. The set fields can be found * in the {@link TextTemplates}. * * @param expEvent an {@link ExperimentChangeEvent} that represents the changes * @return the message for the email */ private String getExperimentChangedMessage(ExperimentChangeEvent expEvent) { ST template = new ST(EXPERIMENT_CHANGED); Map<String, String> variables = new HashMap<>(); ExperimentBase exp = expEvent.getExperiment(); put(variables, EXPERIMENT_LABEL, exp.getLabel()); put(variables, EXPERIMENT_ID, String.valueOf(exp.getID())); put(variables, APPLICATION_NAME, String.valueOf(exp.getApplicationName())); put(variables, USER_NAME, getUserRepresentation(expEvent.getUser())); put(variables, FIELD_NAME, expEvent.getPropertyName()); if (expEvent.getPropertyName() != null && "sampling_percent".equalsIgnoreCase(expEvent.getPropertyName())) { put(variables, FIELD_BEFORE, String.valueOf(((double) Math.round(Double.parseDouble(expEvent.getBefore()) * 10000d) / 10000d) * 100).concat("%")); put(variables, FIELD_AFTER, String.valueOf(((double) Math.round(Double.parseDouble(expEvent.getAfter()) * 10000d) / 10000d) * 100).concat("%")); } else { put(variables, FIELD_BEFORE, expEvent.getBefore()); put(variables, FIELD_AFTER, expEvent.getAfter()); } return replaceVariablesInTemplate(variables, template); }