Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add barebones internal models for reports #146

Merged
merged 7 commits into from
Jan 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
210 changes: 210 additions & 0 deletions app/models/internal/impl/ChromeScreenshotReportSource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
/*
* Copyright 2019 Dropbox, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package models.internal.impl;

import com.arpnetworking.commons.builder.OvalBuilder;
import com.arpnetworking.logback.annotations.Loggable;
import com.google.common.base.MoreObjects;
import models.internal.reports.ReportSource;
import net.sf.oval.constraint.AssertURL;
import net.sf.oval.constraint.AssertURLCheck;
import net.sf.oval.constraint.NotEmpty;
import net.sf.oval.constraint.NotNull;

import java.net.URI;
import java.util.Objects;
import java.util.UUID;

/**
* Internal model for a report source that pulls screenshots from a Chrome web browser.
*
* @author Christian Briones (cbriones at dropbox dot com)
*/
@Loggable
public final class ChromeScreenshotReportSource implements ReportSource {
cwbriones marked this conversation as resolved.
Show resolved Hide resolved
private final UUID _id;
private final URI _uri;
private final String _title;
private final boolean _ignoreCertificateErrors;
private final String _triggeringEventName;

private ChromeScreenshotReportSource(final Builder builder) {
_id = builder._id;
_uri = builder._uri;
_title = builder._title;
_ignoreCertificateErrors = builder._ignoreCertificateErrors;
_triggeringEventName = builder._triggeringEventName;
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("id", _id)
.add("url", _uri)
.add("title", _title)
.add("ignoreCertificateErrors", _ignoreCertificateErrors)
.add("triggeringEventName", _triggeringEventName)
.toString();
}

@Override
public UUID getId() {
return _id;
}

/**
* Get the URI for this report source.
*
* @return the URI for this report source.
*/
public URI getUri() {
return _uri;
}

/**
* Get the title for this report source.
*
* @return the title for this report source.
*/
public String getTitle() {
return _title;
}

/**
* Returns {@code true} if this source ignores certificate errors.
*
* @return {@code true} if this source ignores certificate errors, otherwise {@code false}.
*/
public boolean ignoresCertificateErrors() {
return _ignoreCertificateErrors;
}

/**
* Get the browser event name used to trigger this report source.
*
* The report will be considered generated once an event with this name is registered
* with the browser.
*
* @return the name of the triggering event.
*/
public String getTriggeringEventName() {
return _triggeringEventName;
}

@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final ChromeScreenshotReportSource that = (ChromeScreenshotReportSource) o;
return _ignoreCertificateErrors == that._ignoreCertificateErrors
&& Objects.equals(_id, that._id)
&& Objects.equals(_uri, that._uri)
&& Objects.equals(_title, that._title)
&& Objects.equals(_triggeringEventName, that._triggeringEventName);
}

@Override
public int hashCode() {
return Objects.hash(_id, _uri, _title, _ignoreCertificateErrors, _triggeringEventName);
}

/**
* Builder implementation that constructs {@link ChromeScreenshotReportSource}.
*/
public static final class Builder extends OvalBuilder<ChromeScreenshotReportSource> {
/**
* Public constructor.
*/
public Builder() {
super(ChromeScreenshotReportSource::new);
}

/**
* The source id. Required. Cannot be null or empty.
*
* @param id The id.
cwbriones marked this conversation as resolved.
Show resolved Hide resolved
* @return This instance of {@code Builder}
*/
public Builder setId(final UUID id) {
_id = id;
return this;
}

/**
* The source URL. Required. Cannot be null or empty.
*
* @param uri The URL.
* @return This instance of {@code Builder}
*/
public Builder setUri(final URI uri) {
_uri = uri;
return this;
}

/**
* The source title. Required. Cannot be null or empty.
*
* @param title The title.
* @return This instance of {@code Builder}
*/
public Builder setTitle(final String title) {
_title = title;
return this;
}

/**
* The triggering event name for the source. Required. Cannot be null or empty.
*
* @param triggeringEventName The event name.
* @return This instance of {@code Builder}
*/
public Builder setTriggeringEventName(final String triggeringEventName) {
_triggeringEventName = triggeringEventName;
return this;
}

/**
* Determine if the source should ignore certificate errors. Cannot be null. Defaults to false.
*
* @param ignoreCertificateErrors Whether this source should ignore certificate errors.
* @return This instance of {@code Builder}
*/
public Builder setIgnoreCertificateErrors(final Boolean ignoreCertificateErrors) {
_ignoreCertificateErrors = ignoreCertificateErrors;
return this;
}

@NotNull
private UUID _id;
@NotNull
@AssertURL(permittedURISchemes = {AssertURLCheck.URIScheme.HTTP, AssertURLCheck.URIScheme.HTTPS})
private URI _uri;
@NotNull
@NotEmpty
private String _title;
@NotNull
@NotEmpty
private String _triggeringEventName;
@NotNull
private Boolean _ignoreCertificateErrors = false;

}
}
169 changes: 169 additions & 0 deletions app/models/internal/impl/DefaultReport.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
/*
* Copyright 2019 Dropbox, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package models.internal.impl;

import akka.actor.ActorRef;
import com.arpnetworking.commons.builder.OvalBuilder;
import com.arpnetworking.logback.annotations.Loggable;
import com.arpnetworking.metrics.portal.scheduling.Schedule;
import com.google.common.collect.ImmutableSet;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import models.internal.reports.RecipientGroup;
import models.internal.reports.Report;
import models.internal.reports.ReportSource;
import net.sf.oval.constraint.NotEmpty;
import net.sf.oval.constraint.NotNull;

import java.time.Instant;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;

/**
* Default implementation of {@link Report}.
*
* @author Christian Briones (cbriones at dropbox dot com)
*/
@Loggable
public final class DefaultReport implements Report {
cwbriones marked this conversation as resolved.
Show resolved Hide resolved
private DefaultReport(final Builder builder) {
_id = builder._id;
_name = builder._name;
_schedule = builder._schedule;
_source = builder._source;
_groups = builder._groups;
}

@Override
public UUID getId() {
return _id;
}

@Override
public String getName() {
return _name;
}

@Override
public Schedule getSchedule() {
return _schedule;
}

@Override
public ReportSource getSource() {
return _source;
}

@Override
public ImmutableSet<RecipientGroup> getRecipientGroups() {
return _groups;
}

@Override
@SuppressFBWarnings(
value = "NP_NONNULL_PARAM_VIOLATION",
justification = "Known problem with FindBugs. See https://github.com/findbugsproject/findbugs/issues/79."
)
public CompletionStage<Result> execute(final ActorRef scheduler, final Instant scheduled) {
return CompletableFuture.completedFuture(null);
}

private final UUID _id;
private final String _name;
private final Schedule _schedule;
private final ReportSource _source;
private final ImmutableSet<RecipientGroup> _groups;

/**
* Builder implementation that constructs {@code DefaultReport}.
*/
public static final class Builder extends OvalBuilder<DefaultReport> {
/**
* Public Constructor.
*/
public Builder() {
super(DefaultReport::new);
}

/**
* Set the report id. Required. Cannot be null.
*
* @param id The report id.
cwbriones marked this conversation as resolved.
Show resolved Hide resolved
* @return This instance of {@code Builder}.
*/
public Builder setId(final UUID id) {
_id = id;
return this;
}

/**
* Set the report name. Required. Cannot be null or empty.
*
* @param name The report name.
* @return This instance of {@code Builder}.
*/
public Builder setName(final String name) {
_name = name;
return this;
}

/**
* Set the report schedule. Required. Cannot be null.
*
* @param schedule The report schedule.
* @return This instance of {@code Builder}.
*/
public Builder setSchedule(final Schedule schedule) {
_schedule = schedule;
return this;
}

/**
* Set the report source. Required. Cannot be null.
*
* @param source The report source.
* @return This instance of {@code Builder}.
*/
public Builder setReportSource(final ReportSource source) {
_source = source;
return this;
}

/**
* Set the report recipients. Required. Cannot be null.
*
* @param groups The report recipient groups.
* @return This instance of {@code Builder}.
*/
public Builder setRecipientGroups(final ImmutableSet<RecipientGroup> groups) {
_groups = groups;
return this;
}

@NotNull
private UUID _id;
@NotNull
@NotEmpty
private String _name;
@NotNull
private ReportSource _source;
@NotNull
private ImmutableSet<RecipientGroup> _groups;
@NotNull
private Schedule _schedule;
}
}
Loading