package pro.taskana.task.internal;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.ibatis.session.RowBounds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pro.taskana.common.api.TaskanaRole;
import pro.taskana.common.api.TimeInterval;
import pro.taskana.common.api.exceptions.NotAuthorizedException;
import pro.taskana.common.internal.InternalTaskanaEngine;
import pro.taskana.task.api.TaskCommentQuery;
import pro.taskana.task.api.TaskCommentQueryColumnName;
import pro.taskana.task.api.exceptions.TaskNotFoundException;
import pro.taskana.task.api.models.TaskComment;
import pro.taskana.workbasket.api.exceptions.NotAuthorizedToQueryWorkbasketException;
import pro.taskana.workbasket.internal.WorkbasketQueryImpl;

/**
 * TaskCommentQuery for generating dynamic sql.
 */
public class TaskCommentQueryImpl implements TaskCommentQuery {

    private static final Logger LOGGER = LoggerFactory.getLogger(TaskCommentQueryImpl.class);

    private static final String LINK_TO_MAPPER = "pro.taskana.task.internal.TaskCommentQueryMapper.queryTaskComments";

    private static final String LINK_TO_VALUE_MAPPER = "pro.taskana.task.internal.TaskCommentQueryMapper.queryTaskCommentColumnValues";

    private static final String LINK_TO_COUNTER = "pro.taskana.task.internal.TaskCommentQueryMapper.countQueryTaskComments";

    private final InternalTaskanaEngine taskanaEngine;

    private final TaskServiceImpl taskService;

    private final List<String> orderBy;

    private final List<String> orderColumns;

    private TaskCommentQueryColumnName queryColumnName;

    private String[] idIn;

    private String[] idNotIn;

    private String[] idLike;

    private String[] idNotLike;

    private String[] taskIdIn;

    private String[] creatorIn;

    private String[] creatorNotIn;

    private String[] creatorLike;

    private String[] creatorNotLike;

    private String[] textFieldLike;

    private String[] textFieldNotLike;

    private TimeInterval[] modifiedIn;

    private TimeInterval[] modifiedNotIn;

    private TimeInterval[] createdIn;

    private TimeInterval[] createdNotIn;

    private String[] accessIdIn;

    private boolean joinWithUserInfo;

    TaskCommentQueryImpl(InternalTaskanaEngine taskanaEngine) {
        this.taskanaEngine = taskanaEngine;
        this.taskService = (TaskServiceImpl) taskanaEngine.getEngine().getTaskService();
        this.orderBy = new ArrayList<>();
        this.orderColumns = new ArrayList<>();
        this.joinWithUserInfo = taskanaEngine.getEngine().getConfiguration().getAddAdditionalUserInfo();
    }

    @Override
    public TaskCommentQuery idIn(String... taskCommentIds) {
        this.idIn = taskCommentIds;
        return this;
    }

    @Override
    public TaskCommentQuery idNotIn(String... taskCommentIds) {
        this.idNotIn = taskCommentIds;
        return this;
    }

    @Override
    public TaskCommentQuery idLike(String... taskCommentIds) {
        this.idLike = toUpperCopy(taskCommentIds);
        return this;
    }

    @Override
    public TaskCommentQuery idNotLike(String... taskCommentIds) {
        this.idNotLike = toUpperCopy(taskCommentIds);
        return this;
    }

    @Override
    public TaskCommentQuery taskIdIn(String... taskIds) {
        this.taskIdIn = taskIds;
        return this;
    }

    @Override
    public TaskCommentQuery textFieldLike(String... texts) {
        this.textFieldLike = toUpperCopy(texts);
        return this;
    }

    @Override
    public TaskCommentQuery textFieldNotLike(String... texts) {
        this.textFieldNotLike = toUpperCopy(texts);
        return this;
    }

    @Override
    public TaskCommentQuery creatorIn(String... creators) {
        this.creatorIn = creators;
        return this;
    }

    @Override
    public TaskCommentQuery creatorNotIn(String... creators) {
        this.creatorNotIn = creators;
        return this;
    }

    @Override
    public TaskCommentQuery creatorLike(String... creators) {
        this.creatorLike = toUpperCopy(creators);
        return this;
    }

    @Override
    public TaskCommentQuery creatorNotLike(String... creators) {
        this.creatorNotLike = toUpperCopy(creators);
        return this;
    }

    @Override
    public TaskCommentQuery createdWithin(TimeInterval... intervals) {
        validateAllIntervals(intervals);
        this.createdIn = intervals;
        return this;
    }

    @Override
    public TaskCommentQuery createdNotWithin(TimeInterval... intervals) {
        this.createdNotIn = intervals;
        return this;
    }

    @Override
    public TaskCommentQuery modifiedWithin(TimeInterval... intervals) {
        validateAllIntervals(intervals);
        this.modifiedIn = intervals;
        return this;
    }

    @Override
    public TaskCommentQuery modifiedNotWithin(TimeInterval... intervals) {
        this.modifiedNotIn = intervals;
        return this;
    }

    @Override
    public List<TaskComment> list() {
        checkTaskPermission();
        setupAccessIds();
        return taskanaEngine.executeInDatabaseConnection(() -> taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this));
    }

    @Override
    public List<TaskComment> list(int offset, int limit) {
        checkTaskPermission();
        setupAccessIds();
        RowBounds rowBounds = new RowBounds(offset, limit);
        return taskanaEngine.executeInDatabaseConnection(() -> taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds));
    }

    @Override
    public List<String> listValues(TaskCommentQueryColumnName columnName, SortDirection sortDirection) {
        checkTaskPermission();
        setupAccessIds();
        queryColumnName = columnName;
        if (columnName == TaskCommentQueryColumnName.CREATOR_FULL_NAME) {
            joinWithUserInfo = true;
        }
        return taskanaEngine.executeInDatabaseConnection(() -> taskanaEngine.getSqlSession().selectList(LINK_TO_VALUE_MAPPER, this));
    }

    @Override
    public TaskComment single() {
        checkTaskPermission();
        setupAccessIds();
        return taskanaEngine.executeInDatabaseConnection(() -> taskanaEngine.getSqlSession().selectOne(LINK_TO_MAPPER, this));
    }

    @Override
    public long count() {
        checkTaskPermission();
        setupAccessIds();
        Long rowCount = taskanaEngine.executeInDatabaseConnection(() -> taskanaEngine.getSqlSession().selectOne(LINK_TO_COUNTER, this));
        return (rowCount == null) ? 0L : rowCount;
    }

    public TaskCommentQueryColumnName getQueryColumnName() {
        return queryColumnName;
    }

{
        return idIn;
    }

    public String[] getIdNotIn() {
        return idNotIn;
    }

    public String[] getIdLike() {
        return idLike;
    }

    public String[] getIdNotLike() {
        return idNotLike;
    }

    public String[] getTaskIdIn() {
        return taskIdIn;
    }

    public String[] getCreatorIn() {
        return creatorIn;
    }

    public String[] getCreatorNotIn() {
        return creatorNotIn;
    }

    public String[] getCreatorLike() {
        return creatorLike;
    }

    public String[] getCreatorNotLike() {
        return creatorNotLike;
    }

    public String[] getTextFieldLike() {
        return textFieldLike;
    }

    public String[] getTextFieldNotLike() {
        return textFieldNotLike;
    }

    public TimeInterval[] getModifiedIn() {
        return modifiedIn;
    }

    public TimeInterval[] getModifiedNotIn() {
        return modifiedNotIn;
    }

    public TimeInterval[] getCreatedIn() {
        return createdIn;
    }

    public TimeInterval[] getCreatedNotIn() {
        return createdNotIn;
    }

    public String[] getAccessIdIn() {
        return accessIdIn;
    }

    public boolean isIncludeLongName() {
        return joinWithUserInfo;
    }

    public void setIncludeLongName(boolean joinWithUserInfo) {
        this.joinWithUserInfo = joinWithUserInfo;
    }

    @Override
    public TaskCommentQuery orderByCreated(SortDirection sortDirection) {
        return addOrderCriteria("CREATED", sortDirection);
    }

    @Override
    public TaskCommentQuery orderByModified(SortDirection sortDirection) {
        return addOrderCriteria("MODIFIED", sortDirection);
    }

    private void checkTaskPermission() {
        if (taskIdIn != null) {
            if (taskanaEngine.getEngine().isUserInRole(TaskanaRole.ADMIN, TaskanaRole.TASK_ADMIN)) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Skipping permissions check since user is in role ADMIN or TASK_ADMIN.");
                }
                return;
            }
            Arrays.stream(taskIdIn).forEach(taskId -> {
                try {
                    taskService.getTask(taskId);
                } catch (NotAuthorizedException e) {
                    throw new NotAuthorizedToQueryWorkbasketException(e.getMessage(), e.getErrorCode(), e);
                } catch (TaskNotFoundException e) {
                    LOGGER.warn(String.format("The Task with the ID ' %s ' does not exist.", taskId), e);
                }
            });
        }
    }

    private TaskCommentQuery addOrderCriteria(String columnName, SortDirection sortDirection) {
        String orderByDirection = " " + (sortDirection == null ? SortDirection.ASCENDING : sortDirection);
        orderBy.add(columnName + orderByDirection);
        orderColumns.add(columnName);
        return this;
    }

    private void setupAccessIds() {
        if (taskanaEngine.getEngine().isUserInRole(TaskanaRole.ADMIN, TaskanaRole.TASK_ADMIN)) {
            this.accessIdIn = null;
        } else if (this.accessIdIn == null) {
            String[] accessIds = new String[0];
            List<String> ucAccessIds = taskanaEngine.getEngine().getCurrentUserContext().getAccessIds();
            if (!ucAccessIds.isEmpty()) {
                accessIds = new String[ucAccessIds.size()];
                accessIds = ucAccessIds.toArray(accessIds);
            }
            this.accessIdIn = accessIds;
            WorkbasketQueryImpl.lowercaseAccessIds(this.accessIdIn);
        }
    }

    private void validateAllIntervals(TimeInterval[] intervals) {
        for (TimeInterval ti : intervals) {
            if (!ti.isValid()) {
                throw new IllegalArgumentException("TimeInterval " + ti + " is invalid.");
            }
        }
    }

    @Override
    public String toString() {
        return "TaskCommentQueryImpl [taskanaEngine=" + taskanaEngine + ", taskService=" + taskService + ", queryColumnName=" + queryColumnName + ", idIn=" + Arrays.toString(idIn) + ", idNotIn=" + Arrays.toString(idNotIn) + ", idLike=" + Arrays.toString(idLike) + ", idNotLike=" + Arrays.toString(idNotLike) + ", taskIdIn=" + Arrays.toString(taskIdIn) + ", creatorIn=" + Arrays.toString(creatorIn) + ", creatorNotIn=" + Arrays.toString(creatorNotIn) + ", creatorLike=" + Arrays.toString(creatorLike) + ", creatorNotLike=" + Arrays.toString(creatorNotLike) + ", textFieldLike=" + Arrays.toString(textFieldLike) + ", textFieldNotLike=" + Arrays.toString(textFieldNotLike) + ", modifiedIn=" + Arrays.toString(modifiedIn) + ", modifiedNotIn=" + Arrays.toString(modifiedNotIn) + ", createdIn=" + Arrays.toString(createdIn) + ", createdNotIn=" + Arrays.toString(createdNotIn) + ", accessIdIn=" + Arrays.toString(accessIdIn) + ", joinWithUserInfo=" + joinWithUserInfo + "]";
    }
}


{
        validateAllIntervals(intervals);
        this.modifiedIn = intervals;
        return this;
    }

package pro.taskana.task.internal;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.ibatis.session.RowBounds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pro.taskana.common.api.TaskanaRole;
import pro.taskana.common.api.TimeInterval;
import pro.taskana.common.api.exceptions.NotAuthorizedException;
import pro.taskana.common.internal.InternalTaskanaEngine;
import pro.taskana.task.api.TaskCommentQuery;
import pro.taskana.task.api.TaskCommentQueryColumnName;
import pro.taskana.task.api.exceptions.TaskNotFoundException;
import pro.taskana.task.api.models.TaskComment;
import pro.taskana.workbasket.api.exceptions.NotAuthorizedToQueryWorkbasketException;
import pro.taskana.workbasket.internal.WorkbasketQueryImpl;

/**
 * TaskCommentQuery for generating dynamic sql.
 */
public class TaskCommentQueryImpl implements TaskCommentQuery {

    private static final Logger LOGGER = LoggerFactory.getLogger(TaskCommentQueryImpl.class);

    private static final String LINK_TO_MAPPER = "pro.taskana.task.internal.TaskCommentQueryMapper.queryTaskComments";

    private static final String LINK_TO_VALUE_MAPPER = "pro.taskana.task.internal.TaskCommentQueryMapper.queryTaskCommentColumnValues";

    private static final String LINK_TO_COUNTER = "pro.taskana.task.internal.TaskCommentQueryMapper.countQueryTaskComments";

    private final InternalTaskanaEngine taskanaEngine;

    private final TaskServiceImpl taskService;

    private final List<String> orderBy;

    private final List<String> orderColumns;

    private TaskCommentQueryColumnName queryColumnName;

    private String[] idIn;

    private String[] idNotIn;

    private String[] idLike;

    private String[] idNotLike;

    private String[] taskIdIn;

    private String[] creatorIn;

    private String[] creatorNotIn;

    private String[] creatorLike;

    private String[] creatorNotLike;

    private String[] textFieldLike;

    private String[] textFieldNotLike;

    private TimeInterval[] modifiedIn;

    private TimeInterval[] modifiedNotIn;

    private TimeInterval[] createdIn;

    private TimeInterval[] createdNotIn;

    private String[] accessIdIn;

    private boolean joinWithUserInfo;

    TaskCommentQueryImpl(InternalTaskanaEngine taskanaEngine) {
        this.taskanaEngine = taskanaEngine;
        this.taskService = (TaskServiceImpl) taskanaEngine.getEngine().getTaskService();
        this.orderBy = new ArrayList<>();
        this.orderColumns = new ArrayList<>();
        this.joinWithUserInfo = taskanaEngine.getEngine().getConfiguration().getAddAdditionalUserInfo();
    }

    @Override
    public TaskCommentQuery idIn(String... taskCommentIds) {
        this.idIn = taskCommentIds;
        return this;
    }

    @Override
    public TaskCommentQuery idNotIn(String... taskCommentIds) {
        this.idNotIn = taskCommentIds;
        return this;
    }

    @Override
    public TaskCommentQuery idLike(String... taskCommentIds) {
        this.idLike = toUpperCopy(taskCommentIds);
        return this;
    }

    @Override
    public TaskCommentQuery idNotLike(String... taskCommentIds) {
        this.idNotLike = toUpperCopy(taskCommentIds);
        return this;
    }

    @Override
    public TaskCommentQuery taskIdIn(String... taskIds) {
        this.taskIdIn = taskIds;
        return this;
    }

    @Override
    public TaskCommentQuery textFieldLike(String... texts) {
        this.textFieldLike = toUpperCopy(texts);
        return this;
    }

    @Override
    public TaskCommentQuery textFieldNotLike(String... texts) {
        this.textFieldNotLike = toUpperCopy(texts);
        return this;
    }

    @Override
    public TaskCommentQuery creatorIn(String... creators) {
        this.creatorIn = creators;
        return this;
    }

    @Override
    public TaskCommentQuery creatorNotIn(String... creators) {
        this.creatorNotIn = creators;
        return this;
    }

    @Override
    public TaskCommentQuery creatorLike(String... creators) {
        this.creatorLike = toUpperCopy(creators);
        return this;
    }

    @Override
    public TaskCommentQuery creatorNotLike(String... creators) {
        this.creatorNotLike = toUpperCopy(creators);
        return this;
    }

    @Override
    public TaskCommentQuery createdWithin(TimeInterval... intervals) {
        validateAllIntervals(intervals);
        this.createdIn = intervals;
        return this;
    }

    @Override
    public TaskCommentQuery createdNotWithin(TimeInterval... intervals) {
        this.createdNotIn = intervals;
        return this;
    }

    @Override
    public TaskCommentQuery modifiedWithin(TimeInterval... intervals)

    @Override
    public TaskCommentQuery modifiedNotWithin(TimeInterval... intervals) {
        this.modifiedNotIn = intervals;
        return this;
    }

    @Override
    public List<TaskComment> list() {
        checkTaskPermission();
        setupAccessIds();
        return taskanaEngine.executeInDatabaseConnection(() -> taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this));
    }

    @Override
    public List<TaskComment> list(int offset, int limit) {
        checkTaskPermission();
        setupAccessIds();
        RowBounds rowBounds = new RowBounds(offset, limit);
        return taskanaEngine.executeInDatabaseConnection(() -> taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds));
    }

    @Override
    public List<String> listValues(TaskCommentQueryColumnName columnName, SortDirection sortDirection) {
        checkTaskPermission();
        setupAccessIds();
        queryColumnName = columnName;
        if (columnName == TaskCommentQueryColumnName.CREATOR_FULL_NAME) {
            joinWithUserInfo = true;
        }
        return taskanaEngine.executeInDatabaseConnection(() -> taskanaEngine.getSqlSession().selectList(LINK_TO_VALUE_MAPPER, this));
    }

    @Override
    public TaskComment single() {
        checkTaskPermission();
        setupAccessIds();
        return taskanaEngine.executeInDatabaseConnection(() -> taskanaEngine.getSqlSession().selectOne(LINK_TO_MAPPER, this));
    }

    @Override
    public long count() {
        checkTaskPermission();
        setupAccessIds();
        Long rowCount = taskanaEngine.executeInDatabaseConnection(() -> taskanaEngine.getSqlSession().selectOne(LINK_TO_COUNTER, this));
        return (rowCount == null) ? 0L : rowCount;
    }

    public TaskCommentQueryColumnName getQueryColumnName() {
        return queryColumnName;
    }

    public String[] getIdIn() {
        return idIn;
    }

    public String[] getIdNotIn() {
        return idNotIn;
    }

    public String[] getIdLike() {
        return idLike;
    }

    public String[] getIdNotLike() {
        return idNotLike;
    }

    public String[] getTaskIdIn() {
        return taskIdIn;
    }

    public String[] getCreatorIn() {
        return creatorIn;
    }

    public String[] getCreatorNotIn() {
        return creatorNotIn;
    }

    public String[] getCreatorLike() {
        return creatorLike;
    }

    public String[] getCreatorNotLike() {
        return creatorNotLike;
    }

    public String[] getTextFieldLike() {
        return textFieldLike;
    }

    public String[] getTextFieldNotLike() {
        return textFieldNotLike;
    }

    public TimeInterval[] getModifiedIn() {
        return modifiedIn;
    }

    public TimeInterval[] getModifiedNotIn() {
        return modifiedNotIn;
    }

    public TimeInterval[] getCreatedIn() {
        return createdIn;
    }

    public TimeInterval[] getCreatedNotIn() {
        return createdNotIn;
    }

    public String[] getAccessIdIn() {
        return accessIdIn;
    }

    public boolean isIncludeLongName() {
        return joinWithUserInfo;
    }

    public void setIncludeLongName(boolean joinWithUserInfo) {
        this.joinWithUserInfo = joinWithUserInfo;
    }

    @Override
    public TaskCommentQuery orderByCreated(SortDirection sortDirection) {
        return addOrderCriteria("CREATED", sortDirection);
    }

    @Override
    public TaskCommentQuery orderByModified(SortDirection sortDirection) {
        return addOrderCriteria("MODIFIED", sortDirection);
    }

    private void checkTaskPermission() {
        if (taskIdIn != null) {
            if (taskanaEngine.getEngine().isUserInRole(TaskanaRole.ADMIN, TaskanaRole.TASK_ADMIN)) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Skipping permissions check since user is in role ADMIN or TASK_ADMIN.");
                }
                return;
            }
            Arrays.stream(taskIdIn).forEach(taskId -> {
                try {
                    taskService.getTask(taskId);
                } catch (NotAuthorizedException e) {
                    throw new NotAuthorizedToQueryWorkbasketException(e.getMessage(), e.getErrorCode(), e);
                } catch (TaskNotFoundException e) {
                    LOGGER.warn(String.format("The Task with the ID ' %s ' does not exist.", taskId), e);
                }
            });
        }
    }

    private TaskCommentQuery addOrderCriteria(String columnName, SortDirection sortDirection) {
        String orderByDirection = " " + (sortDirection == null ? SortDirection.ASCENDING : sortDirection);
        orderBy.add(columnName + orderByDirection);
        orderColumns.add(columnName);
        return this;
    }

    private void setupAccessIds() {
        if (taskanaEngine.getEngine().isUserInRole(TaskanaRole.ADMIN, TaskanaRole.TASK_ADMIN)) {
            this.accessIdIn = null;
        } else if (this.accessIdIn == null) {
            String[] accessIds = new String[0];
            List<String> ucAccessIds = taskanaEngine.getEngine().getCurrentUserContext().getAccessIds();
            if (!ucAccessIds.isEmpty()) {
                accessIds = new String[ucAccessIds.size()];
                accessIds = ucAccessIds.toArray(accessIds);
            }
            this.accessIdIn = accessIds;
            WorkbasketQueryImpl.lowercaseAccessIds(this.accessIdIn);
        }
    }

    private void validateAllIntervals(TimeInterval[] intervals) {
        for (TimeInterval ti : intervals) {
            if (!ti.isValid()) {
                throw new IllegalArgumentException("TimeInterval " + ti + " is invalid.");
            }
        }
    }

    @Override
    public String toString() {
        return "TaskCommentQueryImpl [taskanaEngine=" + taskanaEngine + ", taskService=" + taskService + ", queryColumnName=" + queryColumnName + ", idIn=" + Arrays.toString(idIn) + ", idNotIn=" + Arrays.toString(idNotIn) + ", idLike=" + Arrays.toString(idLike) + ", idNotLike=" + Arrays.toString(idNotLike) + ", taskIdIn=" + Arrays.toString(taskIdIn) + ", creatorIn=" + Arrays.toString(creatorIn) + ", creatorNotIn=" + Arrays.toString(creatorNotIn) + ", creatorLike=" + Arrays.toString(creatorLike) + ", creatorNotLike=" + Arrays.toString(creatorNotLike) + ", textFieldLike=" + Arrays.toString(textFieldLike) + ", textFieldNotLike=" + Arrays.toString(textFieldNotLike) + ", modifiedIn=" + Arrays.toString(modifiedIn) + ", modifiedNotIn=" + Arrays.toString(modifiedNotIn) + ", createdIn=" + Arrays.toString(createdIn) + ", createdNotIn=" + Arrays.toString(createdNotIn) + ", accessIdIn=" + Arrays.toString(accessIdIn) + ", joinWithUserInfo=" + joinWithUserInfo + "]";
    }
}


package pro.taskana.task.internal;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.ibatis.session.RowBounds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pro.taskana.common.api.TaskanaRole;
import pro.taskana.common.api.TimeInterval;
import pro.taskana.common.api.exceptions.NotAuthorizedException;
import pro.taskana.common.internal.InternalTaskanaEngine;
import pro.taskana.task.api.TaskCommentQuery;
import pro.taskana.task.api.TaskCommentQueryColumnName;
import pro.taskana.task.api.exceptions.TaskNotFoundException;
import pro.taskana.task.api.models.TaskComment;
import pro.taskana.workbasket.api.exceptions.NotAuthorizedToQueryWorkbasketException;
import pro.taskana.workbasket.internal.WorkbasketQueryImpl;

/**
 * TaskCommentQuery for generating dynamic sql.
 */
public class TaskCommentQueryImpl implements TaskCommentQuery {

    private static final Logger LOGGER = LoggerFactory.getLogger(TaskCommentQueryImpl.class);

    private static final String LINK_TO_MAPPER = "pro.taskana.task.internal.TaskCommentQueryMapper.queryTaskComments";

    private static final String LINK_TO_VALUE_MAPPER = "pro.taskana.task.internal.TaskCommentQueryMapper.queryTaskCommentColumnValues";

    private static final String LINK_TO_COUNTER = "pro.taskana.task.internal.TaskCommentQueryMapper.countQueryTaskComments";

    private final InternalTaskanaEngine taskanaEngine;

    private final TaskServiceImpl taskService;

    private final List<String> orderBy;

    private final List<String> orderColumns;

    private TaskCommentQueryColumnName queryColumnName;

    private String[] idIn;

    private String[] idNotIn;

    private String[] idLike;

    private String[] idNotLike;

    private String[] taskIdIn;

    private String[] creatorIn;

    private String[] creatorNotIn;

    private String[] creatorLike;

    private String[] creatorNotLike;

    private String[] textFieldLike;

    private String[] textFieldNotLike;

    private TimeInterval[] modifiedIn;

    private TimeInterval[] modifiedNotIn;

    private TimeInterval[] createdIn;

    private TimeInterval[] createdNotIn;

    private String[] accessIdIn;

    private boolean joinWithUserInfo;

    TaskCommentQueryImpl(InternalTaskanaEngine taskanaEngine) {
        this.taskanaEngine = taskanaEngine;
        this.taskService = (TaskServiceImpl) taskanaEngine.getEngine().getTaskService();
        this.orderBy = new ArrayList<>();
        this.orderColumns = new ArrayList<>();
        this.joinWithUserInfo = taskanaEngine.getEngine().getConfiguration().getAddAdditionalUserInfo();
    }

    @Override
    public TaskCommentQuery idIn(String... taskCommentIds) {
        this.idIn = taskCommentIds;
        return this;
    }

    @Override
    public TaskCommentQuery idNotIn(String... taskCommentIds) {
        this.idNotIn = taskCommentIds;
        return this;
    }

    @Override
    public TaskCommentQuery idLike(String... taskCommentIds) {
        this.idLike = toUpperCopy(taskCommentIds);
        return this;
    }

    @Override
    public TaskCommentQuery idNotLike(String... taskCommentIds) {
        this.idNotLike = toUpperCopy(taskCommentIds);
        return this;
    }

    @Override
    public TaskCommentQuery taskIdIn(String... taskIds) {
        this.taskIdIn = taskIds;
        return this;
    }

    @Override
    public TaskCommentQuery textFieldLike(String... texts) {
        this.textFieldLike = toUpperCopy(texts);
        return this;
    }

    @Override
    public TaskCommentQuery textFieldNotLike(String... texts) {
        this.textFieldNotLike = toUpperCopy(texts);
        return this;
    }

    @Override
    public TaskCommentQuery creatorIn(String... creators) {
        this.creatorIn = creators;
        return this;
    }

    @Override
    public TaskCommentQuery creatorNotIn(String... creators) {
        this.creatorNotIn = creators;
        return this;
    }

    @Override
    public TaskCommentQuery creatorLike(String... creators) {
        this.creatorLike = toUpperCopy(creators);
        return this;
    }

    @Override
    public TaskCommentQuery creatorNotLike(String... creators) {
        this.creatorNotLike = toUpperCopy(creators);
        return this;
    }

    @Override
    public TaskCommentQuery createdWithin(TimeInterval... intervals) {
        validateAllIntervals(intervals);
        this.createdIn = intervals;
        return this;
    }

    @Override
    public TaskCommentQuery createdNotWithin(TimeInterval... intervals) {
        this.createdNotIn = intervals;
        return this;
    }

    @Override
    public TaskCommentQuery modifiedWithin(TimeInterval... intervals) {
        validateAllIntervals(intervals);
        this.modifiedIn = intervals;
        return this;
    }

    @Override
    public TaskCommentQuery modifiedNotWithin(TimeInterval... intervals) {
        this.modifiedNotIn = intervals;
        return this;
    }

    @Override
    public List<TaskComment> list() {
        checkTaskPermission();
        setupAccessIds();
        return taskanaEngine.executeInDatabaseConnection(() -> taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this));
    }

    @Override
    public List<TaskComment> list(int offset, int limit) {
        checkTaskPermission();
        setupAccessIds();
        RowBounds rowBounds = new RowBounds(offset, limit);
        return taskanaEngine.executeInDatabaseConnection(() -> taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds));
    }

    @Override
    public List<String> listValues(TaskCommentQueryColumnName columnName, SortDirection sortDirection) {
        checkTaskPermission();
        setupAccessIds();
        queryColumnName = columnName;
        if (columnName == TaskCommentQueryColumnName.CREATOR_FULL_NAME) {
            joinWithUserInfo = true;
        }
        return taskanaEngine.executeInDatabaseConnection(() -> taskanaEngine.getSqlSession().selectList(LINK_TO_VALUE_MAPPER, this));
    }

    @Override
    public TaskComment single() {
        checkTaskPermission();
        setupAccessIds();
        return taskanaEngine.executeInDatabaseConnection(() -> taskanaEngine.getSqlSession().selectOne(LINK_TO_MAPPER, this));
    }

    @Override
    public long count() {
        checkTaskPermission();
        setupAccessIds();
        Long rowCount = taskanaEngine.executeInDatabaseConnection(() -> taskanaEngine.getSqlSession().selectOne(LINK_TO_COUNTER, this));
        return (rowCount == null) ? 0L : rowCount;
    }

    public TaskCommentQueryColumnName getQueryColumnName() {
        return queryColumnName;
    }

    public String[] getIdIn() {
        return idIn;
    }

    public String[] getIdNotIn() {
        return idNotIn;
    }

    public String[] getIdLike() {
        return idLike;
    }

    public String[] getIdNotLike() {
        return idNotLike;
    }

    public String[] getTaskIdIn() {
        return taskIdIn;
    }

    public String[] getCreatorIn() {
        return creatorIn;
    }

    public String[] getCreatorNotIn() {
        return creatorNotIn;
    }

    public String[] getCreatorLike() {
        return creatorLike;
    }

    public String[] getCreatorNotLike() {
        return creatorNotLike;
    }

    public String[] getTextFieldLike() {
        return textFieldLike;
    }

    public String[] getTextFieldNotLike() {
        return textFieldNotLike;
    }

    public TimeInterval[] getModifiedIn() {
        return modifiedIn;
    }

    public TimeInterval[] getModifiedNotIn() {
        return modifiedNotIn;
    }

    public TimeInterval[] getCreatedIn() {
        return createdIn;
    }

    public TimeInterval[] getCreatedNotIn() {
        return createdNotIn;
    }

    public String[] getAccessIdIn() {
        return accessIdIn;
    }

    public boolean isIncludeLongName() {
        return joinWithUserInfo;
    }

    public void setIncludeLongName(boolean joinWithUserInfo) {
        this.joinWithUserInfo = joinWithUserInfo;
    }

    @Override
    public TaskCommentQuery orderByCreated(SortDirection sortDirection) {
        return addOrderCriteria("CREATED", sortDirection);
    }

    @Override
    public TaskCommentQuery orderByModified(SortDirection sortDirection) {
        return addOrderCriteria("MODIFIED", sortDirection);
    }

    private void checkTaskPermission() {
        if (taskIdIn != null) {
            if (taskanaEngine.getEngine().isUserInRole(TaskanaRole.ADMIN, TaskanaRole.TASK_ADMIN)) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Skipping permissions check since user is in role ADMIN or TASK_ADMIN.");
                }
                return;
            }
            Arrays.stream(taskIdIn).forEach(taskId -> {
                try {
                    taskService.getTask(taskId);
                } catch (NotAuthorizedException e) {
                    throw new NotAuthorizedToQueryWorkbasketException(e.getMessage(), e.getErrorCode(), e);
                } catch (TaskNotFoundException e) {
                    LOGGER.warn(String.format("The Task with the ID ' %s ' does not exist.", taskId), e);
                }
            });
        }
    }

    private TaskCommentQuery addOrderCriteria(String columnName, SortDirection sortDirection) {
        String orderByDirection = " " + (sortDirection == null ? SortDirection.ASCENDING : sortDirection);
        orderBy.add(columnName + orderByDirection);
        orderColumns.add(columnName);
        return this;
    }

    private void setupAccessIds() {
        if (taskanaEngine.getEngine().isUserInRole(TaskanaRole.ADMIN, TaskanaRole.TASK_ADMIN)) {
            this.accessIdIn = null;
        } else if (this.accessIdIn == null) {
            String[] accessIds = new String[0];
            List<String> ucAccessIds = taskanaEngine.getEngine().getCurrentUserContext().getAccessIds();
            if (!ucAccessIds.isEmpty()) {
                accessIds = new String[ucAccessIds.size()];
                accessIds = ucAccessIds.toArray(accessIds);
            }
            this.accessIdIn = accessIds;
            WorkbasketQueryImpl.lowercaseAccessIds(this.accessIdIn);
        }
    }

    private void validateAllIntervals(TimeInterval[] intervals) {

        for (TimeInterval ti : intervals) {
            if (!ti.isValid()) {
                throw new IllegalArgumentException("TimeInterval " + ti + " is invalid.");
            }
        }
    }

    @Override
    public String toString() {
        return "TaskCommentQueryImpl [taskanaEngine=" + taskanaEngine + ", taskService=" + taskService + ", queryColumnName=" + queryColumnName + ", idIn=" + Arrays.toString(idIn) + ", idNotIn=" + Arrays.toString(idNotIn) + ", idLike=" + Arrays.toString(idLike) + ", idNotLike=" + Arrays.toString(idNotLike) + ", taskIdIn=" + Arrays.toString(taskIdIn) + ", creatorIn=" + Arrays.toString(creatorIn) + ", creatorNotIn=" + Arrays.toString(creatorNotIn) + ", creatorLike=" + Arrays.toString(creatorLike) + ", creatorNotLike=" + Arrays.toString(creatorNotLike) + ", textFieldLike=" + Arrays.toString(textFieldLike) + ", textFieldNotLike=" + Arrays.toString(textFieldNotLike) + ", modifiedIn=" + Arrays.toString(modifiedIn) + ", modifiedNotIn=" + Arrays.toString(modifiedNotIn) + ", createdIn=" + Arrays.toString(createdIn) + ", createdNotIn=" + Arrays.toString(createdNotIn) + ", accessIdIn=" + Arrays.toString(accessIdIn) + ", joinWithUserInfo=" + joinWithUserInfo + "]";
    }
}


for (TimeInterval ti : intervals) {
            if (!ti.isValid()) {
                throw new IllegalArgumentException("TimeInterval " + ti + " is invalid.");
            }
        }

    }

    @Override
    public String toString() {
        return "TaskCommentQueryImpl [taskanaEngine=" + taskanaEngine + ", taskService=" + taskService + ", queryColumnName=" + queryColumnName + ", idIn=" + Arrays.toString(idIn) + ", idNotIn=" + Arrays.toString(idNotIn) + ", idLike=" + Arrays.toString(idLike) + ", idNotLike=" + Arrays.toString(idNotLike) + ", taskIdIn=" + Arrays.toString(taskIdIn) + ", creatorIn=" + Arrays.toString(creatorIn) + ", creatorNotIn=" + Arrays.toString(creatorNotIn) + ", creatorLike=" + Arrays.toString(creatorLike) + ", creatorNotLike=" + Arrays.toString(creatorNotLike) + ", textFieldLike=" + Arrays.toString(textFieldLike) + ", textFieldNotLike=" + Arrays.toString(textFieldNotLike) + ", modifiedIn=" + Arrays.toString(modifiedIn) + ", modifiedNotIn=" + Arrays.toString(modifiedNotIn) + ", createdIn=" + Arrays.toString(createdIn) + ", createdNotIn=" + Arrays.toString(createdNotIn) + ", accessIdIn=" + Arrays.toString(accessIdIn) + ", joinWithUserInfo=" + joinWithUserInfo + "]";
    }
}


package pro.taskana.task.internal;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.ibatis.session.RowBounds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pro.taskana.common.api.TaskanaRole;
import pro.taskana.common.api.TimeInterval;
import pro.taskana.common.api.exceptions.NotAuthorizedException;
import pro.taskana.common.internal.InternalTaskanaEngine;
import pro.taskana.task.api.TaskCommentQuery;
import pro.taskana.task.api.TaskCommentQueryColumnName;
import pro.taskana.task.api.exceptions.TaskNotFoundException;
import pro.taskana.task.api.models.TaskComment;
import pro.taskana.workbasket.api.exceptions.NotAuthorizedToQueryWorkbasketException;
import pro.taskana.workbasket.internal.WorkbasketQueryImpl;

/**
 * TaskCommentQuery for generating dynamic sql.
 */
public class TaskCommentQueryImpl implements TaskCommentQuery {

    private static final Logger LOGGER = LoggerFactory.getLogger(TaskCommentQueryImpl.class);

    private static final String LINK_TO_MAPPER = "pro.taskana.task.internal.TaskCommentQueryMapper.queryTaskComments";

    private static final String LINK_TO_VALUE_MAPPER = "pro.taskana.task.internal.TaskCommentQueryMapper.queryTaskCommentColumnValues";

    private static final String LINK_TO_COUNTER = "pro.taskana.task.internal.TaskCommentQueryMapper.countQueryTaskComments";

    private final InternalTaskanaEngine taskanaEngine;

    private final TaskServiceImpl taskService;

    private final List<String> orderBy;

    private final List<String> orderColumns;

    private TaskCommentQueryColumnName queryColumnName;

    private String[] idIn;

    private String[] idNotIn;

    private String[] idLike;

    private String[] idNotLike;

    private String[] taskIdIn;

    private String[] creatorIn;

    private String[] creatorNotIn;

    private String[] creatorLike;

    private String[] creatorNotLike;

    private String[] textFieldLike;

    private String[] textFieldNotLike;

    private TimeInterval[] modifiedIn;

    private TimeInterval[] modifiedNotIn;

    private TimeInterval[] createdIn;

    private TimeInterval[] createdNotIn;

    private String[] accessIdIn;

    private boolean joinWithUserInfo;

    TaskCommentQueryImpl(InternalTaskanaEngine taskanaEngine) {
        this.taskanaEngine = taskanaEngine;
        this.taskService = (TaskServiceImpl) taskanaEngine.getEngine().getTaskService();
        this.orderBy = new ArrayList<>();
        this.orderColumns = new ArrayList<>();
        this.joinWithUserInfo = taskanaEngine.getEngine().getConfiguration().getAddAdditionalUserInfo();
    }

    @Override
    public TaskCommentQuery idIn(String... taskCommentIds) {
        this.idIn = taskCommentIds;
        return this;
    }

    @Override
    public TaskCommentQuery idNotIn(String... taskCommentIds) {
        this.idNotIn = taskCommentIds;
        return this;
    }

    @Override
    public TaskCommentQuery idLike(String... taskCommentIds) {
        this.idLike = toUpperCopy(taskCommentIds);
        return this;
    }

    @Override
    public TaskCommentQuery idNotLike(String... taskCommentIds) {
        this.idNotLike = toUpperCopy(taskCommentIds);
        return this;
    }

    @Override
    public TaskCommentQuery taskIdIn(String... taskIds) {
        this.taskIdIn = taskIds;
        return this;
    }

    @Override
    public TaskCommentQuery textFieldLike(String... texts) {
        this.textFieldLike = toUpperCopy(texts);
        return this;
    }

    @Override
    public TaskCommentQuery textFieldNotLike(String... texts) {
        this.textFieldNotLike = toUpperCopy(texts);
        return this;
    }

    @Override
    public TaskCommentQuery creatorIn(String... creators) {
        this.creatorIn = creators;
        return this;
    }

    @Override
    public TaskCommentQuery creatorNotIn(String... creators) {
        this.creatorNotIn = creators;
        return this;
    }

    @Override
    public TaskCommentQuery creatorLike(String... creators) {
        this.creatorLike = toUpperCopy(creators);
        return this;
    }

    @Override
    public TaskCommentQuery creatorNotLike(String... creators) {
        this.creatorNotLike = toUpperCopy(creators);
        return this;
    }

    @Override
    public TaskCommentQuery createdWithin(TimeInterval... intervals) {
        validateAllIntervals(intervals);
        this.createdIn = intervals;
        return this;
    }

    @Override
    public TaskCommentQuery createdNotWithin(TimeInterval... intervals) {
        this.createdNotIn = intervals;
        return this;
    }

    @Override
    public TaskCommentQuery modifiedWithin(TimeInterval... intervals) {
        validateAllIntervals(intervals);
        this.modifiedIn = intervals;
        return this;
    }

    @Override
    public TaskCommentQuery modifiedNotWithin(TimeInterval... intervals) {
        this.modifiedNotIn = intervals;
        return this;
    }

    @Override
    public List<TaskComment> list() {
        checkTaskPermission();
        setupAccessIds();
        return taskanaEngine.executeInDatabaseConnection(() -> taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this));
    }

    @Override
    public List<TaskComment> list(int offset, int limit) {
        checkTaskPermission();
        setupAccessIds();
        RowBounds rowBounds = new RowBounds(offset, limit);
        return taskanaEngine.executeInDatabaseConnection(() -> taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds));
    }

    @Override
    public List<String> listValues(TaskCommentQueryColumnName columnName, SortDirection sortDirection) {
        checkTaskPermission();
        setupAccessIds();
        queryColumnName = columnName;
        if (columnName == TaskCommentQueryColumnName.CREATOR_FULL_NAME) {
            joinWithUserInfo = true;
        }
        return taskanaEngine.executeInDatabaseConnection(() -> taskanaEngine.getSqlSession().selectList(LINK_TO_VALUE_MAPPER, this));
    }

    @Override
    public TaskComment single() {
        checkTaskPermission();
        setupAccessIds();
        return taskanaEngine.executeInDatabaseConnection(() -> taskanaEngine.getSqlSession().selectOne(LINK_TO_MAPPER, this));
    }

    @Override
    public long count() {
        checkTaskPermission();
        setupAccessIds();
        Long rowCount = taskanaEngine.executeInDatabaseConnection(() -> taskanaEngine.getSqlSession().selectOne(LINK_TO_COUNTER, this));
        return (rowCount == null) ? 0L : rowCount;
    }

    public TaskCommentQueryColumnName getQueryColumnName() {
        return queryColumnName;
    }

    public String[] getIdIn() {
        return idIn;
    }

    public String[] getIdNotIn() {
        return idNotIn;
    }

    public String[] getIdLike() {
        return idLike;
    }

    public String[] getIdNotLike() {
        return idNotLike;
    }

    public String[] getTaskIdIn() {
        return taskIdIn;
    }

    public String[] getCreatorIn() {
        return creatorIn;
    }

    public String[] getCreatorNotIn() {
        return creatorNotIn;
    }

    public String[] getCreatorLike() {
        return creatorLike;
    }

    public String[] getCreatorNotLike() {
        return creatorNotLike;
    }

    public String[] getTextFieldLike() {
        return textFieldLike;
    }

    public String[] getTextFieldNotLike() {
        return textFieldNotLike;
    }

    public TimeInterval[] getModifiedIn() {
        return modifiedIn;
    }

    public TimeInterval[] getModifiedNotIn() {
        return modifiedNotIn;
    }

    public TimeInterval[] getCreatedIn() {
        return createdIn;
    }

    public TimeInterval[] getCreatedNotIn() {
        return createdNotIn;
    }

    public String[] getAccessIdIn() {
        return accessIdIn;
    }

    public boolean isIncludeLongName() {
        return joinWithUserInfo;
    }

    public void setIncludeLongName(boolean joinWithUserInfo) {
        this.joinWithUserInfo = joinWithUserInfo;
    }

    @Override
    public TaskCommentQuery orderByCreated(SortDirection sortDirection) {
        return addOrderCriteria("CREATED", sortDirection);
    }

    @Override
    public TaskCommentQuery orderByModified(SortDirection sortDirection) {
        return addOrderCriteria("MODIFIED", sortDirection);
    }

    private void checkTaskPermission() {
        if (taskIdIn != null) {
            if (taskanaEngine.getEngine().isUserInRole(TaskanaRole.ADMIN, TaskanaRole.TASK_ADMIN)) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Skipping permissions check since user is in role ADMIN or TASK_ADMIN.");
                }
                return;
            }
            Arrays.stream(taskIdIn).forEach(taskId -> {
                try {
                    taskService.getTask(taskId);
                } catch (NotAuthorizedException e) {
                    throw new NotAuthorizedToQueryWorkbasketException(e.getMessage(), e.getErrorCode(), e);
                } catch (TaskNotFoundException e) {
                    LOGGER.warn(String.format("The Task with the ID ' %s ' does not exist.", taskId), e);
                }
            });
        }
    }

    private TaskCommentQuery addOrderCriteria(String columnName, SortDirection sortDirection) {
        String orderByDirection = " " + (sortDirection == null ? SortDirection.ASCENDING : sortDirection);
        orderBy.add(columnName + orderByDirection);
        orderColumns.add(columnName);
        return this;
    }

    private void setupAccessIds() {
        if (taskanaEngine.getEngine().isUserInRole(TaskanaRole.ADMIN, TaskanaRole.TASK_ADMIN)) {
            this.accessIdIn = null;
        } else if (this.accessIdIn == null) {
            String[] accessIds = new String[0];
            List<String> ucAccessIds = taskanaEngine.getEngine().getCurrentUserContext().getAccessIds();
            if (!ucAccessIds.isEmpty()) {
                accessIds = new String[ucAccessIds.size()];
                accessIds = ucAccessIds.toArray(accessIds);
            }
            this.accessIdIn = accessIds;
            WorkbasketQueryImpl.lowercaseAccessIds(this.accessIdIn);
        }
    }

    private void validateAllIntervals(TimeInterval[] intervals) {
        for (TimeInterval ti : intervals) {
            if (!ti.isValid()) {
                throw new IllegalArgumentException("TimeInterval " + ti + " is invalid.");
            }
        }

    @Override
    public String toString() {
        return "TaskCommentQueryImpl [taskanaEngine=" + taskanaEngine + ", taskService=" + taskService + ", queryColumnName=" + queryColumnName + ", idIn=" + Arrays.toString(idIn) + ", idNotIn=" + Arrays.toString(idNotIn) + ", idLike=" + Arrays.toString(idLike) + ", idNotLike=" + Arrays.toString(idNotLike) + ", taskIdIn=" + Arrays.toString(taskIdIn) + ", creatorIn=" + Arrays.toString(creatorIn) + ", creatorNotIn=" + Arrays.toString(creatorNotIn) + ", creatorLike=" + Arrays.toString(creatorLike) + ", creatorNotLike=" + Arrays.toString(creatorNotLike) + ", textFieldLike=" + Arrays.toString(textFieldLike) + ", textFieldNotLike=" + Arrays.toString(textFieldNotLike) + ", modifiedIn=" + Arrays.toString(modifiedIn) + ", modifiedNotIn=" + Arrays.toString(modifiedNotIn) + ", createdIn=" + Arrays.toString(createdIn) + ", createdNotIn=" + Arrays.toString(createdNotIn) + ", accessIdIn=" + Arrays.toString(accessIdIn) + ", joinWithUserInfo=" + joinWithUserInfo + "]";
    }
}


package pro.taskana.task.internal;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.ibatis.session.RowBounds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pro.taskana.common.api.TaskanaRole;
import pro.taskana.common.api.TimeInterval;
import pro.taskana.common.api.exceptions.NotAuthorizedException;
import pro.taskana.common.internal.InternalTaskanaEngine;
import pro.taskana.task.api.TaskCommentQuery;
import pro.taskana.task.api.TaskCommentQueryColumnName;
import pro.taskana.task.api.exceptions.TaskNotFoundException;
import pro.taskana.task.api.models.TaskComment;
import pro.taskana.workbasket.api.exceptions.NotAuthorizedToQueryWorkbasketException;
import pro.taskana.workbasket.internal.WorkbasketQueryImpl;

/**
 * TaskCommentQuery for generating dynamic sql.
 */
public class TaskCommentQueryImpl implements TaskCommentQuery {

    private static final Logger LOGGER = LoggerFactory.getLogger(TaskCommentQueryImpl.class);

    private static final String LINK_TO_MAPPER = "pro.taskana.task.internal.TaskCommentQueryMapper.queryTaskComments";

    private static final String LINK_TO_VALUE_MAPPER = "pro.taskana.task.internal.TaskCommentQueryMapper.queryTaskCommentColumnValues";

    private static final String LINK_TO_COUNTER = "pro.taskana.task.internal.TaskCommentQueryMapper.countQueryTaskComments";

    private final InternalTaskanaEngine taskanaEngine;

    private final TaskServiceImpl taskService;

    private final List<String> orderBy;

    private final List<String> orderColumns;

    private TaskCommentQueryColumnName queryColumnName;

    private String[] idIn;

    private String[] idNotIn;

    private String[] idLike;

    private String[] idNotLike;

    private String[] taskIdIn;

    private String[] creatorIn;

    private String[] creatorNotIn;

    private String[] creatorLike;

    private String[] creatorNotLike;

    private String[] textFieldLike;

    private String[] textFieldNotLike;

    private TimeInterval[] modifiedIn;

    private TimeInterval[] modifiedNotIn;

    private TimeInterval[] createdIn;

    private TimeInterval[] createdNotIn;

    private String[] accessIdIn;

    private boolean joinWithUserInfo;

    TaskCommentQueryImpl(InternalTaskanaEngine taskanaEngine) {
        this.taskanaEngine = taskanaEngine;
        this.taskService = (TaskServiceImpl) taskanaEngine.getEngine().getTaskService();
        this.orderBy = new ArrayList<>();
        this.orderColumns = new ArrayList<>();
        this.joinWithUserInfo = taskanaEngine.getEngine().getConfiguration().getAddAdditionalUserInfo();
    }

    @Override
    public TaskCommentQuery idIn(String... taskCommentIds) {
        this.idIn = taskCommentIds;
        return this;
    }

    @Override
    public TaskCommentQuery idNotIn(String... taskCommentIds) {
        this.idNotIn = taskCommentIds;
        return this;
    }

    @Override
    public TaskCommentQuery idLike(String... taskCommentIds) {
        this.idLike = toUpperCopy(taskCommentIds);
        return this;
    }

    @Override
    public TaskCommentQuery idNotLike(String... taskCommentIds) {
        this.idNotLike = toUpperCopy(taskCommentIds);
        return this;
    }

    @Override
    public TaskCommentQuery taskIdIn(String... taskIds) {
        this.taskIdIn = taskIds;
        return this;
    }

    @Override
    public TaskCommentQuery textFieldLike(String... texts) {
        this.textFieldLike = toUpperCopy(texts);
        return this;
    }

    @Override
    public TaskCommentQuery textFieldNotLike(String... texts) {
        this.textFieldNotLike = toUpperCopy(texts);
        return this;
    }

    @Override
    public TaskCommentQuery creatorIn(String... creators) {
        this.creatorIn = creators;
        return this;
    }

    @Override
    public TaskCommentQuery creatorNotIn(String... creators) {
        this.creatorNotIn = creators;
        return this;
    }

    @Override
    public TaskCommentQuery creatorLike(String... creators) {
        this.creatorLike = toUpperCopy(creators);
        return this;
    }

    @Override
    public TaskCommentQuery creatorNotLike(String... creators) {
        this.creatorNotLike = toUpperCopy(creators);
        return this;
    }

    @Override
    public TaskCommentQuery createdWithin(TimeInterval... intervals) {
        validateAllIntervals(intervals);
        this.createdIn = intervals;
        return this;
    }

    @Override
    public TaskCommentQuery createdNotWithin(TimeInterval... intervals) {
        this.createdNotIn = intervals;
        return this;
    }

    @Override
    public TaskCommentQuery modifiedWithin(TimeInterval... intervals) {
        validateAllIntervals(intervals);
        this.modifiedIn = intervals;
        return this;
    }

    @Override
    public TaskCommentQuery modifiedNotWithin(TimeInterval... intervals) {
        this.modifiedNotIn = intervals;
        return this;
    }

    @Override
    public List<TaskComment> list() {
        checkTaskPermission();
        setupAccessIds();
        return taskanaEngine.executeInDatabaseConnection(() -> taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this));
    }

    @Override
    public List<TaskComment> list(int offset, int limit) {
        checkTaskPermission();
        setupAccessIds();
        RowBounds rowBounds = new RowBounds(offset, limit);
        return taskanaEngine.executeInDatabaseConnection(() -> taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds));
    }

    @Override
    public List<String> listValues(TaskCommentQueryColumnName columnName, SortDirection sortDirection) {
        checkTaskPermission();
        setupAccessIds();
        queryColumnName = columnName;
        if (columnName == TaskCommentQueryColumnName.CREATOR_FULL_NAME) {
            joinWithUserInfo = true;
        }
        return taskanaEngine.executeInDatabaseConnection(() -> taskanaEngine.getSqlSession().selectList(LINK_TO_VALUE_MAPPER, this));
    }

    @Override
    public TaskComment single() {
        checkTaskPermission();
        setupAc

        return taskanaEngine.executeInDatabaseConnection(() -> taskanaEngine.getSqlSession().selectOne(LINK_TO_MAPPER, this));
    }

    @Override
    public long count() {
        checkTaskPermission();
        setupAccessIds();
        Long rowCount = taskanaEngine.executeInDatabaseConnection(() -> taskanaEngine.getSqlSession().selectOne(LINK_TO_COUNTER, this));
        return (rowCount == null) ? 0L : rowCount;
    }

    public TaskCommentQueryColumnName getQueryColumnName() {
        return queryColumnName;
    }

    public String[] getIdIn() {
        return idIn;
    }

    public String[] getIdNotIn() {
        return idNotIn;
    }

    public String[] getIdLike() {
        return idLike;
    }

    public String[] getIdNotLike() {
        return idNotLike;
    }

    public String[] getTaskIdIn() {
        return taskIdIn;
    }

    public String[] getCreatorIn() {
        return creatorIn;
    }

    public String[] getCreatorNotIn() {
        return creatorNotIn;
    }

    public String[] getCreatorLike() {
        return creatorLike;
    }

    public String[] getCreatorNotLike() {
        return creatorNotLike;
    }

    public String[] getTextFieldLike() {
        return textFieldLike;
    }

    public String[] getTextFieldNotLike() {
        return textFieldNotLike;
    }

    public TimeInterval[] getModifiedIn() {
        return modifiedIn;
    }

    public TimeInterval[] getModifiedNotIn() {
        return modifiedNotIn;
    }

    public TimeInterval[] getCreatedIn() {
        return createdIn;
    }

    public TimeInterval[] getCreatedNotIn() {
        return createdNotIn;
    }

    public String[] getAccessIdIn() {
        return accessIdIn;
    }

    public boolean isIncludeLongName() {
        return joinWithUserInfo;
    }

    public void setIncludeLongName(boolean joinWithUserInfo) {
        this.joinWithUserInfo = joinWithUserInfo;
    }

    @Override
    public TaskCommentQuery orderByCreated(SortDirection sortDirection) {
        return addOrderCriteria("CREATED", sortDirection);
    }

    @Override
    public TaskCommentQuery orderByModified(SortDirection sortDirection) {
        return addOrderCriteria("MODIFIED", sortDirection);
    }

    private void checkTaskPermission() {
        if (taskIdIn != null) {
            if (taskanaEngine.getEngine().isUserInRole(TaskanaRole.ADMIN, TaskanaRole.TASK_ADMIN)) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Skipping permissions check since user is in role ADMIN or TASK_ADMIN.");
                }
                return;
            }
            Arrays.stream(taskIdIn).forEach(taskId -> {
                try {
                    taskService.getTask(taskId);
                } catch (NotAuthorizedException e) {
                    throw new NotAuthorizedToQueryWorkbasketException(e.getMessage(), e.getErrorCode(), e);
                } catch (TaskNotFoundException e) {
                    LOGGER.warn(String.format("The Task with the ID ' %s ' does not exist.", taskId), e);
                }
            });
        }
    }

    private TaskCommentQuery addOrderCriteria(String columnName, SortDirection sortDirection) {
        String orderByDirection = " " + (sortDirection == null ? SortDirection.ASCENDING : sortDirection);
        orderBy.add(columnName + orderByDirection);
        orderColumns.add(columnName);
        return this;
    }

    private void setupAccessIds() {
        if (taskanaEngine.getEngine().isUserInRole(TaskanaRole.ADMIN, TaskanaRole.TASK_ADMIN)) {
            this.accessIdIn = null;
        } else if (this.accessIdIn == null) {
            String[] accessIds = new String[0];
            List<String> ucAccessIds = taskanaEngine.getEngine().getCurrentUserContext().getAccessIds();
            if (!ucAccessIds.isEmpty()) {
                accessIds = new String[ucAccessIds.size()];
                accessIds = ucAccessIds.toArray(accessIds);
            }
            this.accessIdIn = accessIds;
            WorkbasketQueryImpl.lowercaseAccessIds(this.accessIdIn);
        }
    }

    private void validateAllIntervals(TimeInterval[] intervals) {
        for (TimeInterval ti : intervals) {
            if (!ti.isValid()) {
                throw new IllegalArgumentException("TimeInterval " + ti + " is invalid.");
            }
        }
    }

    @Override
    public String toString() {
        return "TaskCommentQueryImpl [taskanaEngine=" + taskanaEngine + ", taskService=" + taskService + ", queryColumnName=" + queryColumnName + ", idIn=" + Arrays.toString(idIn) + ", idNotIn=" + Arrays.toString(idNotIn) + ", idLike=" + Arrays.toString(idLike) + ", idNotLike=" + Arrays.toString(idNotLike) + ", taskIdIn=" + Arrays.toString(taskIdIn) + ", creatorIn=" + Arrays.toString(creatorIn) + ", creatorNotIn=" + Arrays.toString(creatorNotIn) + ", creatorLike=" + Arrays.toString(creatorLike) + ", creatorNotLike=" + Arrays.toString(creatorNotLike) + ", textFieldLike=" + Arrays.toString(textFieldLike) + ", textFieldNotLike=" + Arrays.toString(textFieldNotLike) + ", modifiedIn=" + Arrays.toString(modifiedIn) + ", modifiedNotIn=" + Arrays.toString(modifiedNotIn) + ", createdIn=" + Arrays.toString(createdIn) + ", createdNotIn=" + Arrays.toString(createdNotIn) + ", accessIdIn=" + Arrays.toString(accessIdIn) + ", joinWithUserInfo=" + joinWithUserInfo + "]";
    }
}


if (!ti.isValid()) {
                throw new IllegalArgumentException("TimeInterval " + ti + " is invalid.");
            }

package pro.taskana.task.internal;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.ibatis.session.RowBounds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pro.taskana.common.api.TaskanaRole;
import pro.taskana.common.api.TimeInterval;
import pro.taskana.common.api.exceptions.NotAuthorizedException;
import pro.taskana.common.internal.InternalTaskanaEngine;
import pro.taskana.task.api.TaskCommentQuery;
import pro.taskana.task.api.TaskCommentQueryColumnName;
import pro.taskana.task.api.exceptions.TaskNotFoundException;
import pro.taskana.task.api.models.TaskComment;
import pro.taskana.workbasket.api.exceptions.NotAuthorizedToQueryWorkbasketException;
import pro.taskana.workbasket.internal.WorkbasketQueryImpl;

/**
 * TaskCommentQuery for generating dynamic sql.
 */
public class TaskCommentQueryImpl implements TaskCommentQuery {

    private static final Logger LOGGER = LoggerFactory.getLogger(TaskCommentQueryImpl.class);

    private static final String LINK_TO_MAPPER = "pro.taskana.task.internal.TaskCommentQueryMapper.queryTaskComments";

    private static final String LINK_TO_VALUE_MAPPER = "pro.taskana.task.internal.TaskCommentQueryMapper.queryTaskCommentColumnValues";

    private static final String LINK_TO_COUNTER = "pro.taskana.task.internal.TaskCommentQueryMapper.countQueryTaskComments";

    private final InternalTaskanaEngine taskanaEngine;

    private final TaskServiceImpl taskService;

    private final List<String> orderBy;

    private final List<String> orderColumns;

    private TaskCommentQueryColumnName queryColumnName;

    private String[] idIn;

    private String[] idNotIn;

    private String[] idLike;

    private String[] idNotLike;

    private String[] taskIdIn;

    private String[] creatorIn;

    private String[] creatorNotIn;

    private String[] creatorLike;

    private String[] creatorNotLike;

    private String[] textFieldLike;

    private String[] textFieldNotLike;

    private TimeInterval[] modifiedIn;

    private TimeInterval[] modifiedNotIn;

    private TimeInterval[] createdIn;

    private TimeInterval[] createdNotIn;

    private String[] accessIdIn;

    private boolean joinWithUserInfo;

    TaskCommentQueryImpl(InternalTaskanaEngine taskanaEngine) {
        this.taskanaEngine = taskanaEngine;
        this.taskService = (TaskServiceImpl) taskanaEngine.getEngine().getTaskService();
        this.orderBy = new ArrayList<>();
        this.orderColumns = new ArrayList<>();
        this.joinWithUserInfo = taskanaEngine.getEngine().getConfiguration().getAddAdditionalUserInfo();
    }

    @Override
    public TaskCommentQuery idIn(String... taskCommentIds) {
        this.idIn = taskCommentIds;
        return this;
    }

    @Override
    public TaskCommentQuery idNotIn(String... taskCommentIds) {
        this.idNotIn = taskCommentIds;
        return this;
    }

    @Override
    public TaskCommentQuery idLike(String... taskCommentIds) {
        this.idLike = toUpperCopy(taskCommentIds);
        return this;
    }

    @Override
    public TaskCommentQuery idNotLike(String... taskCommentIds) {
        this.idNotLike = toUpperCopy(taskCommentIds);
        return this;
    }

    @Override
    public TaskCommentQuery taskIdIn(String... taskIds) {
        this.taskIdIn = taskIds;
        return this;
    }

    @Override
    public TaskCommentQuery textFieldLike(String... texts) {
        this.textFieldLike = toUpperCopy(texts);
        return this;
    }

    @Override
    public TaskCommentQuery textFieldNotLike(String... texts) {
        this.textFieldNotLike = toUpperCopy(texts);
        return this;
    }

    @Override
    public TaskCommentQuery creatorIn(String... creators) {
        this.creatorIn = creators;
        return this;
    }

    @Override
    public TaskCommentQuery creatorNotIn(String... creators) {
        this.creatorNotIn = creators;
        return this;
    }

    @Override
    public TaskCommentQuery creatorLike(String... creators) {
        this.creatorLike = toUpperCopy(creators);
        return this;
    }

    @Override
    public TaskCommentQuery creatorNotLike(String... creators) {
        this.creatorNotLike = toUpperCopy(creators);
        return this;
    }

    @Override
    public TaskCommentQuery createdWithin(TimeInterval... intervals) {
        validateAllIntervals(intervals);
        this.createdIn = intervals;
        return this;
    }

    @Override
    public TaskCommentQuery createdNotWithin(TimeInterval... intervals) {
        this.createdNotIn = intervals;
        return this;
    }

    @Override
    public TaskCommentQuery modifiedWithin(TimeInterval... intervals) {
        validateAllIntervals(intervals);
        this.modifiedIn = intervals;
        return this;
    }

    @Override
    public TaskCommentQuery modifiedNotWithin(TimeInterval... intervals) {
        this.modifiedNotIn = intervals;
        return this;
    }

    @Override
    public List<TaskComment> list() {
        checkTaskPermission();
        setupAccessIds();
        return taskanaEngine.executeInDatabaseConnection(() -> taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this));
    }

    @Override
    public List<TaskComment> list(int offset, int limit) {
        checkTaskPermission();
        setupAccessIds();
        RowBounds rowBounds = new RowBounds(offset, limit);
        return taskanaEngine.executeInDatabaseConnection(() -> taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds));
    }

    @Override
    public List<String> listValues(TaskCommentQueryColumnName columnName, SortDirection sortDirection) {
        checkTaskPermission();
        setupAccessIds();
        queryColumnName = columnName;
        if (columnName == TaskCommentQueryColumnName.CREATOR_FULL_NAME) {
            joinWithUserInfo = true;
        }
        return taskanaEngine.executeInDatabaseConnection(() -> taskanaEngine.getSqlSession().selectList(LINK_TO_VALUE_MAPPER, this));
    }

    @Override
    public TaskComment single() {
        checkTaskPermission();
        setupAccessIds();
        return taskanaEngine.executeInDatabaseConnection(() -> taskanaEngine.getSqlSession().selectOne(LINK_TO_MAPPER, this));
    }

    @Override
    public long count() {
        checkTaskPermission();
        setupAccessIds();
        Long rowCount = taskanaEngine.executeInDatabaseConnection(() -> taskanaEngine.getSqlSession().selectOne(LINK_TO_COUNTER, this));
        return (rowCount == null) ? 0L : rowCount;
    }

    public TaskCommentQueryColumnName getQueryColumnName() {
        return queryColumnName;
    }

    public String[] getIdIn() {
        return idIn;
    }

    public String[] getIdNotIn() {
        return idNotIn;
    }

    public String[] getIdLike() {
        return idLike;
    }

    public String[] getIdNotLike() {
        return idNotLike;
    }

    public String[] getTaskIdIn() {
        return taskIdIn;
    }

    public String[] getCreatorIn() {
        return creatorIn;
    }

    public String[] getCreatorNotIn() {
        return creatorNotIn;
    }

    public String[] getCreatorLike() {
        return creatorLike;
    }

    public String[] getCreatorNotLike() {
        return creatorNotLike;
    }

    public String[] getTextFieldLike() {
        return textFieldLike;
    }

    public String[] getTextFieldNotLike() {
        return textFieldNotLike;
    }

    public TimeInterval[] getModifiedIn() {
        return modifiedIn;
    }

    public TimeInterval[] getModifiedNotIn() {
        return modifiedNotIn;
    }

    public TimeInterval[] getCreatedIn() {
        return createdIn;
    }

    public TimeInterval[] getCreatedNotIn() {
        return createdNotIn;
    }

    public String[] getAccessIdIn() {
        return accessIdIn;
    }

    public boolean isIncludeLongName() {
        return joinWithUserInfo;
    }

    public void setIncludeLongName(boolean joinWithUserInfo) {
        this.joinWithUserInfo = joinWithUserInfo;
    }

    @Override
    public TaskCommentQuery orderByCreated(SortDirection sortDirection) {
        return addOrderCriteria("CREATED", sortDirection);
    }

    @Override
    public TaskCommentQuery orderByModified(SortDirection sortDirection) {
        return addOrderCriteria("MODIFIED", sortDirection);
    }

    private void checkTaskPermission() {
        if (taskIdIn != null) {
            if (taskanaEngine.getEngine().isUserInRole(TaskanaRole.ADMIN, TaskanaRole.TASK_ADMIN)) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Skipping permissions check since user is in role ADMIN or TASK_ADMIN.");
                }
                return;
            }
            Arrays.stream(taskIdIn).forEach(taskId -> {
                try {
                    taskService.getTask(taskId);
                } catch (NotAuthorizedException e) {
                    throw new NotAuthorizedToQueryWorkbasketException(e.getMessage(), e.getErrorCode(), e);
                } catch (TaskNotFoundException e) {
                    LOGGER.warn(String.format("The Task with the ID ' %s ' does not exist.", taskId), e);
                }
            });
        }
    }

    private TaskCommentQuery addOrderCriteria(String columnName, SortDirection sortDirection) {
        String orderByDirection = " " + (sortDirection == null ? SortDirection.ASCENDING : sortDirection);
        orderBy.add(columnName + orderByDirection);
        orderColumns.add(columnName);
        return this;
    }

    private void setupAccessIds() {
        if (taskanaEngine.getEngine().isUserInRole(TaskanaRole.ADMIN, TaskanaRole.TASK_ADMIN)) {
            this.accessIdIn = null;
        } else if (this.accessIdIn == null) {
            String[] accessIds = new String[0];
            List<String> ucAccessIds = taskanaEngine.getEngine().getCurrentUserContext().getAccessIds();
            if (!ucAccessIds.isEmpty()) {
                accessIds = new String[ucAccessIds.size()];
                accessIds = ucAccessIds.toArray(accessIds);
            }
            this.accessIdIn = accessIds;
            WorkbasketQueryImpl.lowercaseAccessIds(this.accessIdIn);
        }
    }

    private void validateAllIntervals(TimeInterval[] intervals) {
        for (TimeInterval ti : intervals) {

        }
    }

    @Override
    public String toString() {
        return "TaskCommentQueryImpl [taskanaEngine=" + taskanaEngine + ", taskService=" + taskService + ", queryColumnName=" + queryColumnName + ", idIn=" + Arrays.toString(idIn) + ", idNotIn=" + Arrays.toString(idNotIn) + ", idLike=" + Arrays.toString(idLike) + ", idNotLike=" + Arrays.toString(idNotLike) + ", taskIdIn=" + Arrays.toString(taskIdIn) + ", creatorIn=" + Arrays.toString(creatorIn) + ", creatorNotIn=" + Arrays.toString(creatorNotIn) + ", creatorLike=" + Arrays.toString(creatorLike) + ", creatorNotLike=" + Arrays.toString(creatorNotLike) + ", textFieldLike=" + Arrays.toString(textFieldLike) + ", textFieldNotLike=" + Arrays.toString(textFieldNotLike) + ", modifiedIn=" + Arrays.toString(modifiedIn) + ", modifiedNotIn=" + Arrays.toString(modifiedNotIn) + ", createdIn=" + Arrays.toString(createdIn) + ", createdNotIn=" + Arrays.toString(createdNotIn) + ", accessIdIn=" + Arrays.toString(accessIdIn) + ", joinWithUserInfo=" + joinWithUserInfo + "]";
    }
}


try {
                    taskService.getTask(taskId);
                } catch (NotAuthorizedException e) {
                    throw new NotAuthorizedToQueryWorkbasketException(e.getMessage(), e.getErrorCode(), e);
                } catch (TaskNotFoundException e) {
                    LOGGER.warn(String.format("The Task with the ID ' %s ' does not exist.", taskId), e);
                }

package pro.taskana.task.internal;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.ibatis.session.RowBounds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pro.taskana.common.api.TaskanaRole;
import pro.taskana.common.api.TimeInterval;
import pro.taskana.common.api.exceptions.NotAuthorizedException;
import pro.taskana.common.internal.InternalTaskanaEngine;
import pro.taskana.task.api.TaskCommentQuery;
import pro.taskana.task.api.TaskCommentQueryColumnName;
import pro.taskana.task.api.exceptions.TaskNotFoundException;
import pro.taskana.task.api.models.TaskComment;
import pro.taskana.workbasket.api.exceptions.NotAuthorizedToQueryWorkbasketException;
import pro.taskana.workbasket.internal.WorkbasketQueryImpl;

/**
 * TaskCommentQuery for generating dynamic sql.
 */
public class TaskCommentQueryImpl implements TaskCommentQuery {

    private static final Logger LOGGER = LoggerFactory.getLogger(TaskCommentQueryImpl.class);

    private static final String LINK_TO_MAPPER = "pro.taskana.task.internal.TaskCommentQueryMapper.queryTaskComments";

    private static final String LINK_TO_VALUE_MAPPER = "pro.taskana.task.internal.TaskCommentQueryMapper.queryTaskCommentColumnValues";

    private static final String LINK_TO_COUNTER = "pro.taskana.task.internal.TaskCommentQueryMapper.countQueryTaskComments";

    private final InternalTaskanaEngine taskanaEngine;

    private final TaskServiceImpl taskService;

    private final List<String> orderBy;

    private final List<String> orderColumns;

    private TaskCommentQueryColumnName queryColumnName;

    private String[] idIn;

    private String[] idNotIn;

    private String[] idLike;

    private String[] idNotLike;

    private String[] taskIdIn;

    private String[] creatorIn;

    private String[] creatorNotIn;

    private String[] creatorLike;

    private String[] creatorNotLike;

    private String[] textFieldLike;

    private String[] textFieldNotLike;

    private TimeInterval[] modifiedIn;

    private TimeInterval[] modifiedNotIn;

    private TimeInterval[] createdIn;

    private TimeInterval[] createdNotIn;

    private String[] accessIdIn;

    private boolean joinWithUserInfo;

    TaskCommentQueryImpl(InternalTaskanaEngine taskanaEngine) {
        this.taskanaEngine = taskanaEngine;
        this.taskService = (TaskServiceImpl) taskanaEngine.getEngine().getTaskService();
        this.orderBy = new ArrayList<>();
        this.orderColumns = new ArrayList<>();
        this.joinWithUserInfo = taskanaEngine.getEngine().getConfiguration().getAddAdditionalUserInfo();
    }

    @Override
    public TaskCommentQuery idIn(String... taskCommentIds) {
        this.idIn = taskCommentIds;
        return this;
    }

    @Override
    public TaskCommentQuery idNotIn(String... taskCommentIds) {
        this.idNotIn = taskCommentIds;
        return this;
    }

    @Override
    public TaskCommentQuery idLike(String... taskCommentIds) {
        this.idLike = toUpperCopy(taskCommentIds);
        return this;
    }

    @Override
    public TaskCommentQuery idNotLike(String... taskCommentIds) {
        this.idNotLike = toUpperCopy(taskCommentIds);
        return this;
    }

    @Override
    public TaskCommentQuery taskIdIn(String... taskIds) {
        this.taskIdIn = taskIds;
        return this;
    }

    @Override
    public TaskCommentQuery textFieldLike(String... texts) {
        this.textFieldLike = toUpperCopy(texts);
        return this;
    }

    @Override
    public TaskCommentQuery textFieldNotLike(String... texts) {
        this.textFieldNotLike = toUpperCopy(texts);
        return this;
    }

    @Override
    public TaskCommentQuery creatorIn(String... creators) {
        this.creatorIn = creators;
        return this;
    }

    @Override
    public TaskCommentQuery creatorNotIn(String... creators) {
        this.creatorNotIn = creators;
        return this;
    }

    @Override
    public TaskCommentQuery creatorLike(String... creators) {
        this.creatorLike = toUpperCopy(creators);
        return this;
    }

    @Override
    public TaskCommentQuery creatorNotLike(String... creators) {
        this.creatorNotLike = toUpperCopy(creators);
        return this;
    }

    @Override
    public TaskCommentQuery createdWithin(TimeInterval... intervals) {
        validateAllIntervals(intervals);
        this.createdIn = intervals;
        return this;
    }

    @Override
    public TaskCommentQuery createdNotWithin(TimeInterval... intervals) {
        this.createdNotIn = intervals;
        return this;
    }

    @Override
    public TaskCommentQuery modifiedWithin(TimeInterval... intervals) {
        validateAllIntervals(intervals);
        this.modifiedIn = intervals;
        return this;
    }

    @Override
    public TaskCommentQuery modifiedNotWithin(TimeInterval... intervals) {
        this.modifiedNotIn = intervals;
        return this;
    }

    @Override
    public List<TaskComment> list() {
        checkTaskPermission();
        setupAccessIds();
        return taskanaEngine.executeInDatabaseConnection(() -> taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this));
    }

    @Override
    public List<TaskComment> list(int offset, int limit) {
        checkTaskPermission();
        setupAccessIds();
        RowBounds rowBounds = new RowBounds(offset, limit);
        return taskanaEngine.executeInDatabaseConnection(() -> taskanaEngine.getSqlSession().selectList(LINK_TO_MAPPER, this, rowBounds));
    }

    @Override
    public List<String> listValues(TaskCommentQueryColumnName columnName, SortDirection sortDirection) {
        checkTaskPermission();
        setupAccessIds();
        queryColumnName = columnName;
        if (columnName == TaskCommentQueryColumnName.CREATOR_FULL_NAME) {
            joinWithUserInfo = true;
        }
        return taskanaEngine.executeInDatabaseConnection(() -> taskanaEngine.getSqlSession().selectList(LINK_TO_VALUE_MAPPER, this));
    }

    @Override
    public TaskComment single() {
        checkTaskPermission();
        setupAccessIds();
        return taskanaEngine.executeInDatabaseConnection(() -> taskanaEngine.getSqlSession().selectOne(LINK_TO_MAPPER, this));
    }

    @Override
    public long count() {
        checkTaskPermission();
        setupAccessIds();
        Long rowCount = taskanaEngine.executeInDatabaseConnection(() -> taskanaEngine.getSqlSession().selectOne(LINK_TO_COUNTER, this));
        return (rowCount == null) ? 0L : rowCount;
    }

    public TaskCommentQueryColumnName getQueryColumnName() {
        return queryColumnName;
    }

    public String[] getIdIn() {
        return idIn;
    }

    public String[] getIdNotIn() {
        return idNotIn;
    }

    public String[] getIdLike() {
        return idLike;
    }

    public String[] getIdNotLike() {
        return idNotLike;
    }

    public String[] getTaskIdIn() {
        return taskIdIn;
    }

    public String[] getCreatorIn() {
        return creatorIn;
    }

    public String[] getCreatorNotIn() {
        return creatorNotIn;
    }

    public String[] getCreatorLike() {
        return creatorLike;
    }

    public String[] getCreatorNotLike() {
        return creatorNotLike;
    }

    public String[] getTextFieldLike() {
        return textFieldLike;
    }

    public String[] getTextFieldNotLike() {
        return textFieldNotLike;
    }

    public TimeInterval[] getModifiedIn() {
        return modifiedIn;
    }

    public TimeInterval[] getModifiedNotIn() {
        return modifiedNotIn;
    }

    public TimeInterval[] getCreatedIn() {
        return createdIn;
    }

    public TimeInterval[] getCreatedNotIn() {
        return createdNotIn;
    }

    public String[] getAccessIdIn() {
        return accessIdIn;
    }

    public boolean isIncludeLongName() {
        return joinWithUserInfo;
    }

    public void setIncludeLongName(boolean joinWithUserInfo) {
        this.joinWithUserInfo = joinWithUserInfo;
    }

    @Override
    public TaskCommentQuery orderByCreated(SortDirection sortDirection) {
        return addOrderCriteria("CREATED", sortDirection);
    }

    @Override
    public TaskCommentQuery orderByModified(SortDirection sortDirection) {
        return addOrderCriteria("MODIFIED", sortDirection);
    }

    private void checkTaskPermission() {
        if (taskIdIn != null) {
            if (taskanaEngine.getEngine().isUserInRole(TaskanaRole.ADMIN, TaskanaRole.TASK_ADMIN)) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Skipping permissions check since user is in role ADMIN or TASK_ADMIN.");
                }
                return;
            }
            Arrays.stream(taskIdIn).forEach(taskId -> {

            });
        }
    }

    private TaskCommentQuery addOrderCriteria(String columnName, SortDirection sortDirection) {
        String orderByDirection = " " + (sortDirection == null ? SortDirection.ASCENDING : sortDirection);
        orderBy.add(columnName + orderByDirection);
        orderColumns.add(columnName);
        return this;
    }

    private void setupAccessIds() {
        if (taskanaEngine.getEngine().isUserInRole(TaskanaRole.ADMIN, TaskanaRole.TASK_ADMIN)) {
            this.accessIdIn = null;
        } else if (this.accessIdIn == null) {
            String[] accessIds = new String[0];
            List<String> ucAccessIds = taskanaEngine.getEngine().getCurrentUserContext().getAccessIds();
            if (!ucAccessIds.isEmpty()) {
                accessIds = new String[ucAccessIds.size()];
                accessIds = ucAccessIds.toArray(accessIds);
            }
            this.accessIdIn = accessIds;
            WorkbasketQueryImpl.lowercaseAccessIds(this.accessIdIn);
        }
    }

    private void validateAllIntervals(TimeInterval[] intervals) {
        for (TimeInterval ti : intervals) {
            if (!ti.isValid()) {
                throw new IllegalArgumentException("TimeInterval " + ti + " is invalid.");
            }
        }
    }

    @Override
    public String toString() {
        return "TaskCommentQueryImpl [taskanaEngine=" + taskanaEngine + ", taskService=" + taskService + ", queryColumnName=" + queryColumnName + ", idIn=" + Arrays.toString(idIn) + ", idNotIn=" + Arrays.toString(idNotIn) + ", idLike=" + Arrays.toString(idLike) + ", idNotLike=" + Arrays.toString(idNotLike) + ", taskIdIn=" + Arrays.toString(taskIdIn) + ", creatorIn=" + Arrays.toString(creatorIn) + ", creatorNotIn=" + Arrays.toString(creatorNotIn) + ", creatorLike=" + Arrays.toString(creatorLike) + ", creatorNotLike=" + Arrays.toString(creatorNotLike) + ", textFieldLike=" + Arrays.toString(textFieldLike) + ", textFieldNotLike=" + Arrays.toString(textFieldNotLike) + ", modifiedIn=" + Arrays.toString(modifiedIn) + ", modifiedNotIn=" + Arrays.toString(modifiedNotIn) + ", createdIn=" + Arrays.toString(createdIn) + ", createdNotIn=" + Arrays.toString(createdNotIn) + ", accessIdIn=" + Arrays.toString(accessIdIn) + ", joinWithUserInfo=" + joinWithUserInfo + "]";
    }
}


@Override
    public RuntimeModuleDeploymentProperties propertiesForDescriptor(ModuleDescriptor moduleDescriptor)

package org.springframework.xd.dirt.server.admin.deployment;

import java.util.HashMap;
import java.util.Map;
import org.springframework.xd.module.ModuleDeploymentProperties;
import org.springframework.xd.module.ModuleDescriptor;
import org.springframework.xd.module.RuntimeModuleDeploymentProperties;

/**
 * Default implementation of {@link ModuleDeploymentPropertiesProvider}
 * for type {@link RuntimeModuleDeploymentProperties}.
 *
 * @author Ilayaperumal Gopinathan
 */
public class RuntimeModuleDeploymentPropertiesProvider implements ModuleDeploymentPropertiesProvider<RuntimeModuleDeploymentProperties> {

    /**
     * Map to keep track of how many instances of a module this provider
     * has generated properties for. This is used to generate a unique
     * id for each module deployment per container for stream partitioning.
     */
    private final Map<ModuleDescriptor.Key, Integer> mapModuleCount = new HashMap<ModuleDescriptor.Key, Integer>();

    /**
     * The {@link ModuleDeploymentProperties} provider for a {@link ModuleDescriptor}
     */
    protected final ModuleDeploymentPropertiesProvider<ModuleDeploymentProperties> deploymentPropertiesProvider;

    /**
     * Construct a {@code DefaultRuntimeModuleDeploymentPropertiesProvider}.
     *
     * @param propertiesProvider the module deployment properties provider
     */
    public RuntimeModuleDeploymentPropertiesProvider(ModuleDeploymentPropertiesProvider<ModuleDeploymentProperties> propertiesProvider) {
        this.deploymentPropertiesProvider = propertiesProvider;
    }

    /**
     * Return the runtime deployment properties for the given module descriptor.
     * Currently, this implementation assigns the module sequence for the given descriptor and add it to
     * the runtime deployment properties.
     */

{
        RuntimeModuleDeploymentProperties properties = new RuntimeModuleDeploymentProperties();
        properties.putAll(deploymentPropertiesProvider.propertiesForDescriptor(moduleDescriptor));
        ModuleDescriptor.Key moduleKey = moduleDescriptor.createKey();
        Integer index = mapModuleCount.get(moduleKey);
        if (index == null) {
            index = 0;
        }
        mapModuleCount.put(moduleKey, index + 1);
        // sequence number only applies if count > 0
        properties.setSequence((properties.getCount() == 0) ? 0 : mapModuleCount.get(moduleKey));
        return properties;
    }
}


        RuntimeModuleDeploymentProperties properties = new RuntimeModuleDeploymentProperties();
        properties.putAll(deploymentPropertiesProvider.propertiesForDescriptor(moduleDescriptor));
        ModuleDescriptor.Key moduleKey = moduleDescriptor.createKey();

package org.springframework.xd.dirt.server.admin.deployment;

import java.util.HashMap;
import java.util.Map;
import org.springframework.xd.module.ModuleDeploymentProperties;
import org.springframework.xd.module.ModuleDescriptor;
import org.springframework.xd.module.RuntimeModuleDeploymentProperties;

/**
 * Default implementation of {@link ModuleDeploymentPropertiesProvider}
 * for type {@link RuntimeModuleDeploymentProperties}.
 *
 * @author Ilayaperumal Gopinathan
 */
public class RuntimeModuleDeploymentPropertiesProvider implements ModuleDeploymentPropertiesProvider<RuntimeModuleDeploymentProperties> {

    /**
     * Map to keep track of how many instances of a module this provider
     * has generated properties for. This is used to generate a unique
     * id for each module deployment per container for stream partitioning.
     */
    private final Map<ModuleDescriptor.Key, Integer> mapModuleCount = new HashMap<ModuleDescriptor.Key, Integer>();

    /**
     * The {@link ModuleDeploymentProperties} provider for a {@link ModuleDescriptor}
     */
    protected final ModuleDeploymentPropertiesProvider<ModuleDeploymentProperties> deploymentPropertiesProvider;

    /**
     * Construct a {@code DefaultRuntimeModuleDeploymentPropertiesProvider}.
     *
     * @param propertiesProvider the module deployment properties provider
     */
    public RuntimeModuleDeploymentPropertiesProvider(ModuleDeploymentPropertiesProvider<ModuleDeploymentProperties> propertiesProvider) {
        this.deploymentPropertiesProvider = propertiesProvider;
    }

    /**
     * Return the runtime deployment properties for the given module descriptor.
     * Currently, this implementation assigns the module sequence for the given descriptor and add it to
     * the runtime deployment properties.
     */
    @Override
    public RuntimeModuleDeploymentProperties propertiesForDescriptor(ModuleDescriptor moduleDescriptor) {

        Integer index = mapModuleCount.get(moduleKey);
        if (index == null) {
            index = 0;
        }
        mapModuleCount.put(moduleKey, index + 1);
        // sequence number only applies if count > 0
        properties.setSequence((properties.getCount() == 0) ? 0 : mapModuleCount.get(moduleKey));
        return properties;
    }
}


Integer index = mapModuleCount.get(moduleKey);
        if (index == null) {
            index = 0;
        }
        mapModuleCount.put(moduleKey, index + 1);

package org.springframework.xd.dirt.server.admin.deployment;

import java.util.HashMap;
import java.util.Map;
import org.springframework.xd.module.ModuleDeploymentProperties;
import org.springframework.xd.module.ModuleDescriptor;
import org.springframework.xd.module.RuntimeModuleDeploymentProperties;

/**
 * Default implementation of {@link ModuleDeploymentPropertiesProvider}
 * for type {@link RuntimeModuleDeploymentProperties}.
 *
 * @author Ilayaperumal Gopinathan
 */
public class RuntimeModuleDeploymentPropertiesProvider implements ModuleDeploymentPropertiesProvider<RuntimeModuleDeploymentProperties> {

    /**
     * Map to keep track of how many instances of a module this provider
     * has generated properties for. This is used to generate a unique
     * id for each module deployment per container for stream partitioning.
     */
    private final Map<ModuleDescriptor.Key, Integer> mapModuleCount = new HashMap<ModuleDescriptor.Key, Integer>();

    /**
     * The {@link ModuleDeploymentProperties} provider for a {@link ModuleDescriptor}
     */
    protected final ModuleDeploymentPropertiesProvider<ModuleDeploymentProperties> deploymentPropertiesProvider;

    /**
     * Construct a {@code DefaultRuntimeModuleDeploymentPropertiesProvider}.
     *
     * @param propertiesProvider the module deployment properties provider
     */
    public RuntimeModuleDeploymentPropertiesProvider(ModuleDeploymentPropertiesProvider<ModuleDeploymentProperties> propertiesProvider) {
        this.deploymentPropertiesProvider = propertiesProvider;
    }

    /**
     * Return the runtime deployment properties for the given module descriptor.
     * Currently, this implementation assigns the module sequence for the given descriptor and add it to
     * the runtime deployment properties.
     */
    @Override
    public RuntimeModuleDeploymentProperties propertiesForDescriptor(ModuleDescriptor moduleDescriptor) {
        RuntimeModuleDeploymentProperties properties = new RuntimeModuleDeploymentProperties();
        properties.putAll(deploymentPropertiesProvider.propertiesForDescriptor(moduleDescriptor));
        ModuleDescriptor.Key moduleKey = moduleDescriptor.createKey();

        // sequence number only applies if count > 0
        properties.setSequence((properties.getCount() == 0) ? 0 : mapModuleCount.get(moduleKey));
        return properties;
    }
}


// sequence number only applies if count > 0
        properties.setSequence((properties.getCount() == 0) ? 0 : mapModuleCount.get(moduleKey));
        return properties;
    }

package org.springframework.xd.dirt.server.admin.deployment;

import java.util.HashMap;
import java.util.Map;
import org.springframework.xd.module.ModuleDeploymentProperties;
import org.springframework.xd.module.ModuleDescriptor;
import org.springframework.xd.module.RuntimeModuleDeploymentProperties;

/**
 * Default implementation of {@link ModuleDeploymentPropertiesProvider}
 * for type {@link RuntimeModuleDeploymentProperties}.
 *
 * @author Ilayaperumal Gopinathan
 */
public class RuntimeModuleDeploymentPropertiesProvider implements ModuleDeploymentPropertiesProvider<RuntimeModuleDeploymentProperties> {

    /**
     * Map to keep track of how many instances of a module this provider
     * has generated properties for. This is used to generate a unique
     * id for each module deployment per container for stream partitioning.
     */
    private final Map<ModuleDescriptor.Key, Integer> mapModuleCount = new HashMap<ModuleDescriptor.Key, Integer>();

    /**
     * The {@link ModuleDeploymentProperties} provider for a {@link ModuleDescriptor}
     */
    protected final ModuleDeploymentPropertiesProvider<ModuleDeploymentProperties> deploymentPropertiesProvider;

    /**
     * Construct a {@code DefaultRuntimeModuleDeploymentPropertiesProvider}.
     *
     * @param propertiesProvider the module deployment properties provider
     */
    public RuntimeModuleDeploymentPropertiesProvider(ModuleDeploymentPropertiesProvider<ModuleDeploymentProperties> propertiesProvider) {
        this.deploymentPropertiesProvider = propertiesProvider;
    }

    /**
     * Return the runtime deployment properties for the given module descriptor.
     * Currently, this implementation assigns the module sequence for the given descriptor and add it to
     * the runtime deployment properties.
     */
    @Override
    public RuntimeModuleDeploymentProperties propertiesForDescriptor(ModuleDescriptor moduleDescriptor) {
        RuntimeModuleDeploymentProperties properties = new RuntimeModuleDeploymentProperties();
        properties.putAll(deploymentPropertiesProvider.propertiesForDescriptor(moduleDescriptor));
        ModuleDescriptor.Key moduleKey = moduleDescriptor.createKey();
        Integer index = mapModuleCount.get(moduleKey);
        if (index == null) {
            index = 0;
        }
        mapModuleCount.put(moduleKey, index + 1);


package org.springframework.xd.dirt.server.admin.deployment;

import java.util.HashMap;
import java.util.Map;
import org.springframework.xd.module.ModuleDeploymentProperties;
import org.springframework.xd.module.ModuleDescriptor;
import org.springframework.xd.module.RuntimeModuleDeploymentProperties;

/**
 * Default implementation of {@link ModuleDeploymentPropertiesProvider}
 * for type {@link RuntimeModuleDeploymentProperties}.
 *
 * @author Ilayaperumal Gopinathan
 */
public class RuntimeModuleDeploymentPropertiesProvider implements ModuleDeploymentPropertiesProvider<RuntimeModuleDeploymentProperties> {

    /**
     * Map to keep track of how many instances of a module this provider
     * has generated properties for. This is used to generate a unique
     * id for each module deployment per container for stream partitioning.
     */
    private final Map<ModuleDescriptor.Key, Integer> mapModuleCount = new HashMap<ModuleDescriptor.Key, Integer>();

    /**
     * The {@link ModuleDeploymentProperties} provider for a {@link ModuleDescriptor}
     */
    protected final ModuleDeploymentPropertiesProvider<ModuleDeploymentProperties> deploymentPropertiesProvider;

    /**
     * Construct a {@code DefaultRuntimeModuleDeploymentPropertiesProvider}.
     *
     * @param propertiesProvider the module deployment properties provider
     */
    public RuntimeModuleDeploymentPropertiesProvider(ModuleDeploymentPropertiesProvider<ModuleDeploymentProperties> propertiesProvider) {
        this.deploymentPropertiesProvider = propertiesProvider;
    }

    /**
     * Return the runtime deployment properties for the given module descriptor.
     * Currently, this implementation assigns the module sequence for the given descriptor and add it to
     * the runtime deployment properties.
     */
    @Override
    public RuntimeModuleDeploymentProperties propertiesForDescriptor(ModuleDescriptor moduleDescriptor) {
        RuntimeModuleDeploymentProperties properties = new RuntimeModuleDeploymentProperties();
        properties.putAll(deploymentPropertiesProvider.propertiesForDescriptor(moduleDescriptor));
        ModuleDescriptor.Key moduleKey = moduleDescriptor.createKey();
        Integer index = mapModuleCount.get(moduleKey);
        if (index == null) {
            index = 0;
        }
        mapModuleCount.put(moduleKey, index + 1);
        // sequence number only applies if count > 0
        properties.setSequence((properties.getCount() == 0) ? 0 : mapModuleCount.get(moduleKey));
        return properti


if (index == null) {
            index = 0;
        }

package org.springframework.xd.dirt.server.admin.deployment;

import java.util.HashMap;
import java.util.Map;
import org.springframework.xd.module.ModuleDeploymentProperties;
import org.springframework.xd.module.ModuleDescriptor;
import org.springframework.xd.module.RuntimeModuleDeploymentProperties;

/**
 * Default implementation of {@link ModuleDeploymentPropertiesProvider}
 * for type {@link RuntimeModuleDeploymentProperties}.
 *
 * @author Ilayaperumal Gopinathan
 */
public class RuntimeModuleDeploymentPropertiesProvider implements ModuleDeploymentPropertiesProvider<RuntimeModuleDeploymentProperties> {

    /**
     * Map to keep track of how many instances of a module this provider
     * has generated properties for. This is used to generate a unique
     * id for each module deployment per container for stream partitioning.
     */
    private final Map<ModuleDescriptor.Key, Integer> mapModuleCount = new HashMap<ModuleDescriptor.Key, Integer>();

    /**
     * The {@link ModuleDeploymentProperties} provider for a {@link ModuleDescriptor}
     */
    protected final ModuleDeploymentPropertiesProvider<ModuleDeploymentProperties> deploymentPropertiesProvider;

    /**
     * Construct a {@code DefaultRuntimeModuleDeploymentPropertiesProvider}.
     *
     * @param propertiesProvider the module deployment properties provider
     */
    public RuntimeModuleDeploymentPropertiesProvider(ModuleDeploymentPropertiesProvider<ModuleDeploymentProperties> propertiesProvider) {
        this.deploymentPropertiesProvider = propertiesProvider;
    }

    /**
     * Return the runtime deployment properties for the given module descriptor.
     * Currently, this implementation assigns the module sequence for the given descriptor and add it to
     * the runtime deployment properties.
     */
    @Override
    public RuntimeModuleDeploymentProperties propertiesForDescriptor(ModuleDescriptor moduleDescriptor) {
        RuntimeModuleDeploymentProperties properties = new RuntimeModuleDeploymentProperties();
        properties.putAll(deploymentPropertiesProvider.propertiesForDescriptor(moduleDescriptor));
        ModuleDescriptor.Key moduleKey = moduleDescriptor.createKey();
        Integer index = mapModuleCount.get(moduleKey);

        mapModuleCount.put(moduleKey, index + 1);
        // sequence number only applies if count > 0
        properties.setSequence((properties.getCount() == 0) ? 0 : mapModuleCount.get(moduleKey));
        return properties;
    }
}


@Override
    public final void execute()

package com.archimatetool.script.commands;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.commands.Command;
import com.archimatetool.model.IArchimateModel;

/**
 * ScriptCommand
 *
 * @author Phillip Beauvoir
 */
public abstract class ScriptCommand extends Command {

    private IArchimateModel model;

    protected ScriptCommand(String name, IArchimateModel model) {
        super(name);
        this.model = model;
    }

    protected ScriptCommand(String name, EObject eObject) {
        super(name);
        setModel(eObject);
    }

    protected ScriptCommand(String name) {
        super(name);
    }

    protected void setModel(EObject eObject) {
        while (!(eObject instanceof IArchimateModel) && eObject != null) {
            eObject = eObject.eContainer();
        }
        model = (IArchimateModel) eObject;
    }

    public IArchimateModel getModel() {
        return model;
    }

    public abstract void perform();

{
        // Do nothing. Do not use! Use perform() instead.
    }

    @Override
    public void redo() {
        perform();
    }

    @Override
    public void dispose() {
        model = null;
    }
}


package com.archimatetool.script.commands;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.commands.Command;
import com.archimatetool.model.IArchimateModel;

/**
 * ScriptCommand
 *
 * @author Phillip Beauvoir
 */
public abstract class ScriptCommand extends Command {

    private IArchimateModel model;

    protected ScriptCommand(String name, IArchimateModel model) {
        super(name);
        this.model = model;
    }

    protected ScriptCommand(String name, EObject eObject) {
        super(name);
        setModel(eObject);
    }

    protected ScriptCommand(String name) {
        super(name);
    }

    protected void setModel(EObject eObject) {
        while (!(eObject instanceof IArchimateModel) && eObject != null) {
            eObject = eObject.eContainer();
        }
        model = (IArchimateModel) eObject;
    }

    public IArchimateModel getModel()

    public abstract void perform();

    @Override
    public final void execute() {
        // Do nothing. Do not use! Use perform() instead.
    }

    @Override
    public void redo() {
        perform();
    }

    @Override
    public void dispose() {
        model = null;
    }
}