models.internal.impl.DefaultAlertQuery Maven / Gradle / Ivy
/**
* Copyright 2015 Groupon.com
*
* 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.logback.annotations.Loggable;
import com.arpnetworking.metrics.portal.alerts.AlertRepository;
import com.google.common.base.MoreObjects;
import models.internal.Alert;
import models.internal.AlertQuery;
import models.internal.Context;
import models.internal.QueryResult;
import java.util.Optional;
/**
* Default internal model implementation for an alert query.
*
* @author Ville Koskela (vkoskela at groupon dot com)
*/
@Loggable
public final class DefaultAlertQuery implements AlertQuery {
/**
* Public constructor.
*
* @param repository The AlertRepository
*/
public DefaultAlertQuery(final AlertRepository repository) {
_repository = repository;
}
/**
* {@inheritDoc}
*/
@Override
public AlertQuery contains(final Optional contains) {
_contains = contains;
return this;
}
/**
* {@inheritDoc}
*/
@Override
public AlertQuery context(final Optional context) {
_context = context;
return this;
}
/**
* {@inheritDoc}
*/
@Override
public AlertQuery cluster(final Optional cluster) {
_cluster = cluster;
return this;
}
/**
* {@inheritDoc}
*/
@Override
public AlertQuery service(final Optional service) {
_service = service;
return this;
}
/**
* {@inheritDoc}
*/
@Override
public AlertQuery limit(final int limit) {
_limit = limit;
return this;
}
/**
* {@inheritDoc}
*/
@Override
public AlertQuery offset(final Optional offset) {
_offset = offset;
return this;
}
/**
* {@inheritDoc}
*/
@Override
public QueryResult execute() {
return _repository.query(this);
}
/**
* {@inheritDoc}
*/
@Override
public Optional getContains() {
return _contains;
}
/**
* {@inheritDoc}
*/
@Override
public Optional getContext() {
return _context;
}
/**
* {@inheritDoc}
*/
@Override
public Optional getCluster() {
return _cluster;
}
/**
* {@inheritDoc}
*/
@Override
public Optional getService() {
return _service;
}
/**
* {@inheritDoc}
*/
@Override
public int getLimit() {
return _limit;
}
/**
* {@inheritDoc}
*/
@Override
public Optional getOffset() {
return _offset;
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("id", Integer.toHexString(System.identityHashCode(this)))
.add("class", this.getClass())
.add("Repository", _repository)
.add("Contains", _contains)
.add("Context", _context)
.add("Cluster", _cluster)
.add("Service", _service)
.add("Limit", _limit)
.add("Offset", _offset)
.toString();
}
private final AlertRepository _repository;
private Optional _contains = Optional.empty();
private Optional _context = Optional.empty();
private Optional _cluster = Optional.empty();
private Optional _service = Optional.empty();
private int _limit = DEFAULT_LIMIT;
private Optional _offset = Optional.empty();
private static final int DEFAULT_LIMIT = 1000;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy