org.javers.repository.api.QueryParams Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javers-core Show documentation
Show all versions of javers-core Show documentation
JaVers - object auditing and diff framework for Java
package org.javers.repository.api;
import org.javers.common.string.ToStringBuilder;
import org.javers.core.metamodel.object.SnapshotType;
import org.javers.repository.jql.QueryBuilder;
import java.util.*;
import org.javers.core.commit.CommitId;
import java.time.LocalDateTime;
/**
* Container for additional query parameters
* used for filtering Snapshots to be fetched from database.
*
* @see QueryParamsBuilder
* @author michal wesolowski
*/
public class QueryParams {
private final int limit;
private final int skip;
private final LocalDateTime from;
private final LocalDateTime to;
private final CommitId toCommitId;
private final Set commitIds;
private final Long version;
private final String author;
private final Map commitProperties;
private final boolean aggregate;
private final boolean newObjectChanges;
private final String changedProperty;
private final SnapshotType snapshotType;
private final boolean loadCommitProps;
QueryParams(int limit, int skip, LocalDateTime from, LocalDateTime to, Set commitIds, Long version, String author, Map commitProperties, boolean aggregate, boolean newObjectChanges, String changedProperty, CommitId toCommitId, SnapshotType snapshotType, boolean loadCommitProps) {
this.limit = limit;
this.skip = skip;
this.from = from;
this.to = to;
this.commitIds = commitIds;
this.version = version;
this.author = author;
this.commitProperties = commitProperties;
this.aggregate = aggregate;
this.newObjectChanges = newObjectChanges;
this.changedProperty = changedProperty;
this.toCommitId = toCommitId;
this.snapshotType = snapshotType;
this.loadCommitProps = loadCommitProps;
}
public QueryParams changeAggregate(boolean newAggregate) {
return new QueryParams(
limit, skip, from, to, commitIds, version, author, commitProperties,
newAggregate, newObjectChanges, changedProperty, toCommitId, snapshotType, loadCommitProps);
}
public QueryParams nextPage() {
return new QueryParams(
limit, skip+limit, from, to, commitIds, version, author, commitProperties,
aggregate, newObjectChanges, changedProperty, toCommitId, snapshotType, loadCommitProps);
}
/**
* @see QueryBuilder#limit(int)
*/
public int limit() {
return limit;
}
/**
* @see QueryBuilder#skip(int)
*/
public int skip() {
return skip;
}
/**
* @see QueryBuilder#from(LocalDateTime)
*/
public Optional from() {
return Optional.ofNullable(from);
}
/**
* @see QueryBuilder#to(LocalDateTime)
*/
public Optional to() {
return Optional.ofNullable(to);
}
/**
* @see QueryBuilder#toCommitId(CommitId)
*/
public Optional toCommitId() {
return Optional.ofNullable(toCommitId);
}
/**
* @see QueryBuilder#withCommitIds(Collection)
*/
public Set commitIds() {
return Collections.unmodifiableSet(commitIds);
}
/**
* @see QueryBuilder#withCommitProperty(String, String)
*/
public Map commitProperties() {
return commitProperties != null ?
commitProperties : Collections.emptyMap();
}
/**
* @see QueryBuilder#withChangedProperty(String)
*/
public Optional changedProperty(){
return Optional.ofNullable(changedProperty);
}
/**
* @see QueryBuilder#withVersion(long)
*/
public Optional version() {
return Optional.ofNullable(version);
}
/**
* @see QueryBuilder#byAuthor(String)
*/
public Optional author() {
return Optional.ofNullable(author);
}
/**
* @see QueryBuilder#withChildValueObjects()
*/
public boolean isAggregate() {
return aggregate;
}
public boolean isLoadCommitProps() {
return loadCommitProps;
}
/**
* @see QueryBuilder#withSnapshotType(SnapshotType)
*/
public Optional snapshotType() {
return Optional.ofNullable(snapshotType);
}
/**
* @see QueryBuilder#withNewObjectChanges(boolean)
*/
public boolean newObjectChanges() {
return newObjectChanges;
}
@Override
public String toString() {
return ToStringBuilder.toString(this,
"aggregate", aggregate,
"from", from,
"to", to,
"toCommitId", toCommitId,
"commitIds", commitIds,
"changedProperty", changedProperty,
"version", version,
"author", author,
"newObjectChanges", newObjectChanges,
"snapshotType", snapshotType,
"limit", limit,
"skip", skip);
}
public boolean hasDates() {
return from().isPresent() || to().isPresent();
}
public boolean isDateInRange(LocalDateTime date) {
if (from().isPresent() && from().get().isAfter(date)){
return false;
}
if (to().isPresent() && to().get().isBefore(date)){
return false;
}
return true;
}
}