<commit_before>/**
 * Copyright (c) 2015-2018 Linagora
 * 
 * This program/library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 2.1 of the License, or (at your
 * option) any later version.
 * 
 * This program/library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
 * for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program/library; If not, see http://www.gnu.org/licenses/
 * for the GNU Lesser General Public License version 2.1.
 */
package org.ow2.petals.flowable.incoming.integration;

import static org.ow2.petals.flowable.FlowableSEConstants.IntegrationOperation.ITG_OP_GETTASKS;

import java.net.URI;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.logging.Logger;

import javax.xml.datatype.DatatypeFactory;

import org.flowable.engine.RepositoryService;
import org.flowable.engine.TaskService;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.engine.repository.ProcessDefinitionQuery;
import org.flowable.task.api.Task;
import org.flowable.task.api.TaskQuery;
import org.ow2.petals.components.flowable.generic._1.GetTasks;
import org.ow2.petals.components.flowable.generic._1.GetTasksResponse;
import org.ow2.petals.components.flowable.generic._1.InvalidRequest;
import org.ow2.petals.components.flowable.generic._1.Tasks;
import org.ow2.petals.flowable.incoming.integration.exception.OperationInitializationException;

/**
 * The integration operation to search tasks
 * 
 * @author <NAME> - Linagora
 * 
 */
public class GetTasksOperation extends AbstractOperation<GetTasks, GetTasksResponse> {

    public static final URI FAULT_ACTOR = URI.create("http://petals.ow2.org/components/flowable/generic/1.0/GetTasks");

    /**
     * The Flowable task service
     */
    private final TaskService taskService;

    /**
     * The Flowable repository service
     */
    private final RepositoryService repositoryService;

    public GetTasksOperation(final TaskService taskService, final RepositoryService repositoryService, final Logger log)
            throws OperationInitializationException {
        super(ITG_OP_GETTASKS, FAULT_ACTOR,
                new Class[] { GetTasks.class, GetTasksResponse.class, InvalidRequest.class }, log);
        this.taskService = taskService;
        this.repositoryService = repositoryService;
    }

    @Override
    public GetTasksResponse doExecute(final GetTasks incomingObject) throws Exception {

        final TaskQuery taskQuery = this.taskService.createTaskQuery();

        // By default, we search active tasks
        final Boolean isActive = incomingObject.isActive();
        if (isActive != null && !isActive.booleanValue()) {
            taskQuery.suspended();
        } else {
            taskQuery.active();
        }

        final String assignee = incomingObject.getAssignee();
        if (assignee != null && !assignee.isEmpty()) {
            taskQuery.taskCandidateUser(assignee);
        }

        final String processInstanceId = incomingObject.getProcessInstanceIdentifier();
        if (processInstanceId != null && !processInstanceId.isEmpty()) {
            taskQuery.processInstanceId(processInstanceId);
        }
        
        final String processDefinitionId = incomingObject.getProcessDefinitionIdentifier();
        if (processDefinitionId != null && !processDefinitionId.isEmpty()) {<commit_msg>PETALSSEFLOWABLE-56: Unable to retrieve task assigned directly to a user<commit_after>/**
 * Copyright (c) 2015-2018 Linagora
 * 
 * This program/library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 2.1 of the License, or (at your
 * option) any later version.
 * 
 * This program/library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
 * for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program/library; If not, see http://www.gnu.org/licenses/
 * for the GNU Lesser General Public License version 2.1.
 */
package org.ow2.petals.flowable.incoming.integration;

import static org.ow2.petals.flowable.FlowableSEConstants.IntegrationOperation.ITG_OP_GETTASKS;

import java.net.URI;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.logging.Logger;

import javax.xml.datatype.DatatypeFactory;

import org.flowable.engine.RepositoryService;
import org.flowable.engine.TaskService;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.engine.repository.ProcessDefinitionQuery;
import org.flowable.task.api.Task;
import org.flowable.task.api.TaskQuery;
import org.ow2.petals.components.flowable.generic._1.GetTasks;
import org.ow2.petals.components.flowable.generic._1.GetTasksResponse;
import org.ow2.petals.components.flowable.generic._1.InvalidRequest;
import org.ow2.petals.components.flowable.generic._1.Tasks;
import org.ow2.petals.flowable.incoming.integration.exception.OperationInitializationException;

/**
 * The integration operation to search tasks
 * 
 * @author <NAME> - Linagora
 * 
 */
public class GetTasksOperation extends AbstractOperation<GetTasks, GetTasksResponse> {

    public static final URI FAULT_ACTOR = URI.create("http://petals.ow2.org/components/flowable/generic/1.0/GetTasks");

    /**
     * The Flowable task service
     */
    private final TaskService taskService;

    /**
     * The Flowable repository service
     */
    private final RepositoryService repositoryService;

    public GetTasksOperation(final TaskService taskService, final RepositoryService repositoryService, final Logger log)
            throws OperationInitializationException {
        super(ITG_OP_GETTASKS, FAULT_ACTOR,
                new Class[] { GetTasks.class, GetTasksResponse.class, InvalidRequest.class }, log);
        this.taskService = taskService;
        this.repositoryService = repositoryService;
    }

    @Override
    public GetTasksResponse doExecute(final GetTasks incomingObject) throws Exception {

        final TaskQuery taskQuery = this.taskService.createTaskQuery();

        // By default, we search active tasks
        final Boolean isActive = incomingObject.isActive();
        if (isActive != null && !isActive.booleanValue()) {
            taskQuery.suspended();
        } else {
            taskQuery.active();
        }

        final String assignee = incomingObject.getAssignee();
        if (assignee != null && !assignee.isEmpty()) {
            taskQuery.taskCandidateOrAssigned(assignee);
        }

        final String processInstanceId = incomingObject.getProcessInstanceIdentifier();
        if (processInstanceId != null && !processInstanceId.isEmpty()) {
            taskQuery.processInstanceId(processInstanceId);
        }
        
        final String processDefinitionId = incomingObject.getProcessDefinitionIdentifier();
        if (processDefinitionId != null && !processDefinitionId.isEmpty()) {
{'fraction_non_alphanumeric': 0.08692195574400424, 'fraction_numerical': 0.0071551609911223, 'mean_word_length': 3.7561436672967865, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3960155', 'n_tokens_mistral': 2024, 'n_tokens_neox': 1953, 'n_words': 551}