org.camunda.bpm.engine.impl.HistoricProcessInstanceQueryImpl Maven / Gradle / Ivy
/* 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 org.camunda.bpm.engine.impl;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Set;
import org.camunda.bpm.engine.history.HistoricProcessInstance;
import org.camunda.bpm.engine.history.HistoricProcessInstanceQuery;
import org.camunda.bpm.engine.impl.interceptor.CommandContext;
import org.camunda.bpm.engine.impl.interceptor.CommandExecutor;
import static org.camunda.bpm.engine.impl.util.EnsureUtil.ensureNotEmpty;
/**
* @author Tom Baeyens
* @author Falko Menge
* @author Bernd Ruecker
*/
public class HistoricProcessInstanceQueryImpl extends AbstractVariableQueryImpl implements HistoricProcessInstanceQuery {
private static final long serialVersionUID = 1L;
protected String processInstanceId;
protected String processDefinitionId;
protected String processDefinitionName;
protected String processDefinitionNameLike;
protected String businessKey;
protected String businessKeyLike;
protected boolean finished = false;
protected boolean unfinished = false;
protected String startedBy;
protected String superProcessInstanceId;
protected List processKeyNotIn;
protected Date startedBefore;
protected Date startedAfter;
protected Date finishedBefore;
protected Date finishedAfter;
protected String processDefinitionKey;
protected Set processInstanceIds;
public HistoricProcessInstanceQueryImpl() {
}
public HistoricProcessInstanceQueryImpl(CommandContext commandContext) {
super(commandContext);
}
public HistoricProcessInstanceQueryImpl(CommandExecutor commandExecutor) {
super(commandExecutor);
}
public HistoricProcessInstanceQueryImpl processInstanceId(String processInstanceId) {
this.processInstanceId = processInstanceId;
return this;
}
public HistoricProcessInstanceQuery processInstanceIds(Set processInstanceIds) {
ensureNotEmpty("Set of process instance ids", processInstanceIds);
this.processInstanceIds = processInstanceIds;
return this;
}
public HistoricProcessInstanceQueryImpl processDefinitionId(String processDefinitionId) {
this.processDefinitionId = processDefinitionId;
return this;
}
public HistoricProcessInstanceQuery processDefinitionKey(String processDefinitionKey) {
this.processDefinitionKey = processDefinitionKey;
return this;
}
public HistoricProcessInstanceQuery processDefinitionName(String processDefinitionName) {
this.processDefinitionName = processDefinitionName;
return this;
}
public HistoricProcessInstanceQuery processDefinitionNameLike(String nameLike) {
this.processDefinitionNameLike = nameLike;
return this;
}
public HistoricProcessInstanceQuery processInstanceBusinessKey(String businessKey) {
this.businessKey = businessKey;
return this;
}
public HistoricProcessInstanceQuery processInstanceBusinessKeyLike(String businessKeyLike) {
this.businessKeyLike = businessKeyLike;
return this;
}
public HistoricProcessInstanceQuery finished() {
this.finished = true;
return this;
}
public HistoricProcessInstanceQuery unfinished() {
this.unfinished = true;
return this;
}
public HistoricProcessInstanceQuery startedBy(String userId) {
this.startedBy = userId;
return this;
}
public HistoricProcessInstanceQuery processDefinitionKeyNotIn(List processDefinitionKeys) {
this.processKeyNotIn = processDefinitionKeys;
return this;
}
public HistoricProcessInstanceQuery startedAfter(Date date) {
startedAfter = date;
return this;
}
public HistoricProcessInstanceQuery startedBefore(Date date) {
startedBefore = date;
return this;
}
public HistoricProcessInstanceQuery finishedAfter(Date date) {
finishedAfter = date;
finished = true;
return this;
}
public HistoricProcessInstanceQuery finishedBefore(Date date) {
finishedBefore = date;
finished = true;
return this;
}
public HistoricProcessInstanceQuery superProcessInstanceId(String superProcessInstanceId) {
this.superProcessInstanceId = superProcessInstanceId;
return this;
}
public HistoricProcessInstanceQuery orderByProcessInstanceBusinessKey() {
return orderBy(HistoricProcessInstanceQueryProperty.BUSINESS_KEY);
}
public HistoricProcessInstanceQuery orderByProcessInstanceDuration() {
return orderBy(HistoricProcessInstanceQueryProperty.DURATION);
}
public HistoricProcessInstanceQuery orderByProcessInstanceStartTime() {
return orderBy(HistoricProcessInstanceQueryProperty.START_TIME);
}
public HistoricProcessInstanceQuery orderByProcessInstanceEndTime() {
return orderBy(HistoricProcessInstanceQueryProperty.END_TIME);
}
public HistoricProcessInstanceQuery orderByProcessDefinitionId() {
return orderBy(HistoricProcessInstanceQueryProperty.PROCESS_DEFINITION_ID);
}
public HistoricProcessInstanceQuery orderByProcessInstanceId() {
return orderBy(HistoricProcessInstanceQueryProperty.PROCESS_INSTANCE_ID_);
}
public long executeCount(CommandContext commandContext) {
checkQueryOk();
ensureVariablesInitialized();
return commandContext
.getHistoricProcessInstanceManager()
.findHistoricProcessInstanceCountByQueryCriteria(this);
}
public List executeList(CommandContext commandContext, Page page) {
checkQueryOk();
ensureVariablesInitialized();
return commandContext
.getHistoricProcessInstanceManager()
.findHistoricProcessInstancesByQueryCriteria(this, page);
}
public String getBusinessKey() {
return businessKey;
}
public String getBusinessKeyLike() {
return businessKeyLike;
}
public boolean isOpen() {
return unfinished;
}
public String getProcessDefinitionId() {
return processDefinitionId;
}
public String getProcessDefinitionKey() {
return processDefinitionKey;
}
public String getProcessDefinitionIdLike() {
return processDefinitionKey + ":%:%";
}
public String getProcessDefinitionName() {
return processDefinitionName;
}
public String getProcessDefinitionNameLike() {
return processDefinitionNameLike;
}
public String getProcessInstanceId() {
return processInstanceId;
}
public Set getProcessInstanceIds() {
return processInstanceIds;
}
public String getStartedBy() {
return startedBy;
}
public String getSuperProcessInstanceId() {
return superProcessInstanceId;
}
public void setSuperProcessInstanceId(String superProcessInstanceId) {
this.superProcessInstanceId = superProcessInstanceId;
}
public List getProcessKeyNotIn() {
return processKeyNotIn;
}
public Date getStartedAfter() {
return startedAfter;
}
public Date getStartedBefore() {
return startedBefore;
}
public Date getFinishedAfter() {
return finishedAfter;
}
public Date getFinishedBefore() {
return finishedBefore;
}
// below is deprecated and to be removed in 5.12
protected Date startDateBy;
protected Date startDateOn;
protected Date finishDateBy;
protected Date finishDateOn;
protected Date startDateOnBegin;
protected Date startDateOnEnd;
protected Date finishDateOnBegin;
protected Date finishDateOnEnd;
@Deprecated
public HistoricProcessInstanceQuery startDateBy(Date date) {
this.startDateBy = this.calculateMidnight(date);;
return this;
}
@Deprecated
public HistoricProcessInstanceQuery startDateOn(Date date) {
this.startDateOn = date;
this.startDateOnBegin = this.calculateMidnight(date);
this.startDateOnEnd = this.calculateBeforeMidnight(date);
return this;
}
@Deprecated
public HistoricProcessInstanceQuery finishDateBy(Date date) {
this.finishDateBy = this.calculateBeforeMidnight(date);
return this;
}
@Deprecated
public HistoricProcessInstanceQuery finishDateOn(Date date) {
this.finishDateOn = date;
this.finishDateOnBegin = this.calculateMidnight(date);
this.finishDateOnEnd = this.calculateBeforeMidnight(date);
return this;
}
@Deprecated
private Date calculateBeforeMidnight(Date date){
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.DAY_OF_MONTH, 1);
cal.add(Calendar.SECOND, -1);
return cal.getTime();
}
@Deprecated
private Date calculateMidnight(Date date){
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.MILLISECOND, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.HOUR, 0);
return cal.getTime();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy