<commit_before>/*
 * Copyright 2011 <NAME> <<EMAIL>>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package pl.project13.janbanery.core.flow;

import pl.project13.janbanery.core.dao.Columns;
import pl.project13.janbanery.core.dao.Tasks;
import pl.project13.janbanery.exceptions.kanbanery.InternalServerErrorKanbaneryException;
import pl.project13.janbanery.exceptions.kanbanery.invalidentity.CanOnlyIceBoxTaskFromFirstColumnException;
import pl.project13.janbanery.exceptions.kanbanery.invalidentity.TaskAlreadyInLastColumnException;
import pl.project13.janbanery.resources.Column;
import pl.project13.janbanery.resources.Task;
import pl.project13.janbanery.resources.additions.TaskLocation;

import java.io.IOException;

/**
 * This flow enables the API to fluently move tasks around the Kanban board, making it as fun and powerful as possible.
 *
 * @author <NAME>
 */
public class TaskMoveFlowImpl implements TaskMoveFlow {

  private Columns columns;
  private Tasks   tasks;
  private Task    task;

  public TaskMoveFlowImpl(Tasks tasks, Columns columns, Task task) {
    this.columns = columns;
    this.tasks = tasks;
    this.task = task;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public TaskMoveFlow toIceBox() throws IOException, CanOnlyIceBoxTaskFromFirstColumnException {
    return to(TaskLocation.ICEBOX);
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public TaskMoveFlow toBoard() throws IOException {
    return to(TaskLocation.BOARD);
  }

  @Override
  public TaskMoveFlow toLastColumn() throws IOException {
    Column last = columns.last();
    return to(last);
  }

  @Override
  public TaskFlow asTaskFlow() {
    return new TaskFlowImpl(tasks, columns, task);
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public TaskMoveFlow toNextColumn() throws IOException {
    TaskMoveFlow moveFlow;
    try {
      moveFlow = to(TaskLocation.NEXT);
    } catch (InternalServerErrorKanbaneryException e) { // fixme this is a bug workaround
      // kanbanery does handle "ArrayIndexOutOfBounds" right for movement to the left,
      // but for movement to the right it fails and throws a 500 Internal Server Error...
      throw new TaskAlreadyInLastColumnException("{position: 'task is already in last column'}", e); // todo this is a kanbanery bug workaround
    }
    return moveFlow;
  }

  /**
   * {@inheritDoc}
   */<commit_msg>those are not todos<commit_after>/*
 * Copyright 2011 <NAME> <<EMAIL>>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package pl.project13.janbanery.core.flow;

import pl.project13.janbanery.core.dao.Columns;
import pl.project13.janbanery.core.dao.Tasks;
import pl.project13.janbanery.exceptions.kanbanery.InternalServerErrorKanbaneryException;
import pl.project13.janbanery.exceptions.kanbanery.invalidentity.CanOnlyIceBoxTaskFromFirstColumnException;
import pl.project13.janbanery.exceptions.kanbanery.invalidentity.TaskAlreadyInLastColumnException;
import pl.project13.janbanery.resources.Column;
import pl.project13.janbanery.resources.Task;
import pl.project13.janbanery.resources.additions.TaskLocation;

import java.io.IOException;

/**
 * This flow enables the API to fluently move tasks around the Kanban board, making it as fun and powerful as possible.
 *
 * @author <NAME>
 */
public class TaskMoveFlowImpl implements TaskMoveFlow {

  private Columns columns;
  private Tasks   tasks;
  private Task    task;

  public TaskMoveFlowImpl(Tasks tasks, Columns columns, Task task) {
    this.columns = columns;
    this.tasks = tasks;
    this.task = task;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public TaskMoveFlow toIceBox() throws IOException, CanOnlyIceBoxTaskFromFirstColumnException {
    return to(TaskLocation.ICEBOX);
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public TaskMoveFlow toBoard() throws IOException {
    return to(TaskLocation.BOARD);
  }

  @Override
  public TaskMoveFlow toLastColumn() throws IOException {
    Column last = columns.last();
    return to(last);
  }

  @Override
  public TaskFlow asTaskFlow() {
    return new TaskFlowImpl(tasks, columns, task);
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public TaskMoveFlow toNextColumn() throws IOException {
    TaskMoveFlow moveFlow;
    try {
      moveFlow = to(TaskLocation.NEXT);
    } catch (InternalServerErrorKanbaneryException e) { // this is a bug workaround
      // kanbanery does handle "ArrayIndexOutOfBounds" right for movement to the left,
      // but for movement to the right it fails and throws a 500 Internal Server Error...
      throw new TaskAlreadyInLastColumnException("{position: 'task is already in last column'}", e); // this is a kanbanery bug workaround
    }
    return moveFlow;
  }

  /**
   * {@inheritDoc}
   */
{'fraction_non_alphanumeric': 0.0900086880973067, 'fraction_numerical': 0.010078192875760209, 'mean_word_length': 3.8697123519458545, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4045338', 'n_tokens_mistral': 1694, 'n_tokens_neox': 1628, 'n_words': 517}