Search in sources :

Example 1 with DateConverter

use of org.camunda.bpm.engine.rest.dto.converter.DateConverter in project camunda-bpm-platform by camunda.

the class MetricsResourceImpl method applyQueryParams.

protected void applyQueryParams(MetricsQuery query, UriInfo uriInfo) {
    MultivaluedMap<String, String> queryParameters = uriInfo.getQueryParameters();
    DateConverter dateConverter = new DateConverter();
    dateConverter.setObjectMapper(objectMapper);
    if (queryParameters.getFirst("startDate") != null) {
        Date startDate = dateConverter.convertQueryParameterToType(queryParameters.getFirst("startDate"));
        query.startDate(startDate);
    }
    if (queryParameters.getFirst("endDate") != null) {
        Date endDate = dateConverter.convertQueryParameterToType(queryParameters.getFirst("endDate"));
        query.endDate(endDate);
    }
}
Also used : DateConverter(org.camunda.bpm.engine.rest.dto.converter.DateConverter) Date(java.util.Date)

Example 2 with DateConverter

use of org.camunda.bpm.engine.rest.dto.converter.DateConverter in project camunda-bpm-platform by camunda.

the class MetricsRestServiceImpl method applyQueryParams.

protected void applyQueryParams(MetricsQuery query, MultivaluedMap<String, String> queryParameters) {
    DateConverter dateConverter = new DateConverter();
    dateConverter.setObjectMapper(objectMapper);
    if (queryParameters.getFirst(QUERY_PARAM_START_DATE) != null) {
        Date startDate = dateConverter.convertQueryParameterToType(queryParameters.getFirst(QUERY_PARAM_START_DATE));
        query.startDate(startDate);
    }
    if (queryParameters.getFirst(QUERY_PARAM_END_DATE) != null) {
        Date endDate = dateConverter.convertQueryParameterToType(queryParameters.getFirst(QUERY_PARAM_END_DATE));
        query.endDate(endDate);
    }
    IntegerConverter intConverter = new IntegerConverter();
    intConverter.setObjectMapper(objectMapper);
    if (queryParameters.getFirst(QUERY_PARAM_FIRST_RESULT) != null) {
        int firstResult = intConverter.convertQueryParameterToType(queryParameters.getFirst(QUERY_PARAM_FIRST_RESULT));
        query.offset(firstResult);
    }
    if (queryParameters.getFirst(QUERY_PARAM_MAX_RESULTS) != null) {
        int maxResults = intConverter.convertQueryParameterToType(queryParameters.getFirst(QUERY_PARAM_MAX_RESULTS));
        query.limit(maxResults);
    }
}
Also used : IntegerConverter(org.camunda.bpm.engine.rest.dto.converter.IntegerConverter) DateConverter(org.camunda.bpm.engine.rest.dto.converter.DateConverter) Date(java.util.Date)

Example 3 with DateConverter

use of org.camunda.bpm.engine.rest.dto.converter.DateConverter in project camunda-bpm-platform by camunda.

the class HistoricProcessDefinitionRestServiceImpl method getHistoricActivityStatistics.

@Override
public List<HistoricActivityStatisticsDto> getHistoricActivityStatistics(UriInfo uriInfo, String processDefinitionId, Boolean includeCanceled, Boolean includeFinished, Boolean includeCompleteScope, String sortBy, String sortOrder) {
    HistoryService historyService = processEngine.getHistoryService();
    HistoricActivityStatisticsQuery query = historyService.createHistoricActivityStatisticsQuery(processDefinitionId);
    if (includeCanceled != null && includeCanceled) {
        query.includeCanceled();
    }
    if (includeFinished != null && includeFinished) {
        query.includeFinished();
    }
    if (includeCompleteScope != null && includeCompleteScope) {
        query.includeCompleteScope();
    }
    final MultivaluedMap<String, String> queryParameters = uriInfo.getQueryParameters();
    DateConverter dateConverter = new DateConverter();
    dateConverter.setObjectMapper(objectMapper);
    if (queryParameters.getFirst(QUERY_PARAM_STARTED_AFTER) != null) {
        Date startedAfter = dateConverter.convertQueryParameterToType(queryParameters.getFirst(QUERY_PARAM_STARTED_AFTER));
        query.startedAfter(startedAfter);
    }
    if (queryParameters.getFirst(QUERY_PARAM_STARTED_BEFORE) != null) {
        Date startedBefore = dateConverter.convertQueryParameterToType(queryParameters.getFirst(QUERY_PARAM_STARTED_BEFORE));
        query.startedBefore(startedBefore);
    }
    if (queryParameters.getFirst(QUERY_PARAM_FINISHED_AFTER) != null) {
        Date finishedAfter = dateConverter.convertQueryParameterToType(queryParameters.getFirst(QUERY_PARAM_FINISHED_AFTER));
        query.finishedAfter(finishedAfter);
    }
    if (queryParameters.getFirst(QUERY_PARAM_FINISHED_BEFORE) != null) {
        Date finishedBefore = dateConverter.convertQueryParameterToType(queryParameters.getFirst(QUERY_PARAM_FINISHED_BEFORE));
        query.finishedBefore(finishedBefore);
    }
    setSortOptions(query, sortOrder, sortBy);
    List<HistoricActivityStatisticsDto> result = new ArrayList<HistoricActivityStatisticsDto>();
    List<HistoricActivityStatistics> statistics = query.list();
    for (HistoricActivityStatistics currentStatistics : statistics) {
        result.add(HistoricActivityStatisticsDto.fromHistoricActivityStatistics(currentStatistics));
    }
    return result;
}
Also used : HistoricActivityStatisticsQuery(org.camunda.bpm.engine.history.HistoricActivityStatisticsQuery) DateConverter(org.camunda.bpm.engine.rest.dto.converter.DateConverter) HistoricActivityStatisticsDto(org.camunda.bpm.engine.rest.dto.history.HistoricActivityStatisticsDto) ArrayList(java.util.ArrayList) HistoryService(org.camunda.bpm.engine.HistoryService) HistoricActivityStatistics(org.camunda.bpm.engine.history.HistoricActivityStatistics) Date(java.util.Date)

Example 4 with DateConverter

use of org.camunda.bpm.engine.rest.dto.converter.DateConverter in project camunda-bpm-platform by camunda.

the class JobQueryDto method applyFilters.

@Override
protected void applyFilters(JobQuery query) {
    if (activityId != null) {
        query.activityId(activityId);
    }
    if (jobId != null) {
        query.jobId(jobId);
    }
    if (executionId != null) {
        query.executionId(executionId);
    }
    if (processInstanceId != null) {
        query.processInstanceId(processInstanceId);
    }
    if (processDefinitionId != null) {
        query.processDefinitionId(processDefinitionId);
    }
    if (processDefinitionKey != null) {
        query.processDefinitionKey(processDefinitionKey);
    }
    if (TRUE.equals(withRetriesLeft)) {
        query.withRetriesLeft();
    }
    if (TRUE.equals(executable)) {
        query.executable();
    }
    if (TRUE.equals(timers)) {
        if (messages != null && messages) {
            throw new InvalidRequestException(Status.BAD_REQUEST, "Parameter timers cannot be used together with parameter messages.");
        }
        query.timers();
    }
    if (TRUE.equals(messages)) {
        if (timers != null && timers) {
            throw new InvalidRequestException(Status.BAD_REQUEST, "Parameter messages cannot be used together with parameter timers.");
        }
        query.messages();
    }
    if (TRUE.equals(withException)) {
        query.withException();
    }
    if (exceptionMessage != null) {
        query.exceptionMessage(exceptionMessage);
    }
    if (TRUE.equals(noRetriesLeft)) {
        query.noRetriesLeft();
    }
    if (TRUE.equals(active)) {
        query.active();
    }
    if (TRUE.equals(suspended)) {
        query.suspended();
    }
    if (priorityHigherThanOrEquals != null) {
        query.priorityHigherThanOrEquals(priorityHigherThanOrEquals);
    }
    if (priorityLowerThanOrEquals != null) {
        query.priorityLowerThanOrEquals(priorityLowerThanOrEquals);
    }
    if (jobDefinitionId != null) {
        query.jobDefinitionId(jobDefinitionId);
    }
    if (dueDates != null) {
        DateConverter dateConverter = new DateConverter();
        dateConverter.setObjectMapper(objectMapper);
        for (ConditionQueryParameterDto conditionQueryParam : dueDates) {
            String op = conditionQueryParam.getOperator();
            Date dueDate = null;
            try {
                dueDate = dateConverter.convertQueryParameterToType((String) conditionQueryParam.getValue());
            } catch (RestException e) {
                throw new InvalidRequestException(e.getStatus(), e, "Invalid due date format: " + e.getMessage());
            }
            if (op.equals(ConditionQueryParameterDto.GREATER_THAN_OPERATOR_NAME)) {
                query.duedateHigherThan(dueDate);
            } else if (op.equals(ConditionQueryParameterDto.LESS_THAN_OPERATOR_NAME)) {
                query.duedateLowerThan(dueDate);
            } else {
                throw new InvalidRequestException(Status.BAD_REQUEST, "Invalid due date comparator specified: " + op);
            }
        }
    }
    if (tenantIds != null && !tenantIds.isEmpty()) {
        query.tenantIdIn(tenantIds.toArray(new String[tenantIds.size()]));
    }
    if (TRUE.equals(withoutTenantId)) {
        query.withoutTenantId();
    }
    if (TRUE.equals(includeJobsWithoutTenantId)) {
        query.includeJobsWithoutTenantId();
    }
}
Also used : DateConverter(org.camunda.bpm.engine.rest.dto.converter.DateConverter) RestException(org.camunda.bpm.engine.rest.exception.RestException) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) Date(java.util.Date) ConditionQueryParameterDto(org.camunda.bpm.engine.rest.dto.ConditionQueryParameterDto)

Aggregations

Date (java.util.Date)4 DateConverter (org.camunda.bpm.engine.rest.dto.converter.DateConverter)4 ArrayList (java.util.ArrayList)1 HistoryService (org.camunda.bpm.engine.HistoryService)1 HistoricActivityStatistics (org.camunda.bpm.engine.history.HistoricActivityStatistics)1 HistoricActivityStatisticsQuery (org.camunda.bpm.engine.history.HistoricActivityStatisticsQuery)1 ConditionQueryParameterDto (org.camunda.bpm.engine.rest.dto.ConditionQueryParameterDto)1 IntegerConverter (org.camunda.bpm.engine.rest.dto.converter.IntegerConverter)1 HistoricActivityStatisticsDto (org.camunda.bpm.engine.rest.dto.history.HistoricActivityStatisticsDto)1 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)1 RestException (org.camunda.bpm.engine.rest.exception.RestException)1