package com.modesteam.urutau.service;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import com.modesteam.urutau.dao.LayerDAO;
import com.modesteam.urutau.model.system.Layer;

public class KanbanService {

	private static final Long FIRST_DEFAULT_LAYER_ID = 1L;

	private static final Long LAST_DEFAULT_LAYER_ID = 4L;

	private final LayerDAO layerDAO;
		
	public KanbanService() {
		this(null);
	}
	
	@Inject
	public KanbanService(LayerDAO layerDAO) {
		this.layerDAO = layerDAO;
	}
	
	/**
	 * Get Default layers of all project: 
	 * Backlog, In Progress, Do, Done.
	 * 
	 * @return {@link List} of default layers above
	 */
	public List<Layer> getDefaultLayers() {
		List<Layer> defaultLayers = new ArrayList<Layer>();
		
		for(Long id = FIRST_DEFAULT_LAYER_ID; id <= LAST_DEFAULT_LAYER_ID; id++) {
			Layer found = layerDAO.find(id);
			defaultLayers.add(found);
		}
		
		return defaultLayers;
	}
	
	/**
	 * Returns first layer, that is backlog
	 */
	public Layer getBackLogLayer() {
		return layerDAO.find(FIRST_DEFAULT_LAYER_ID);
	}
	
}

@@ -155,16 +155,76 @@
 yerDAO;%0A
+import com.modesteam.urutau.exception.SystemBreakException;%0A
 import c
@@ -1077,22 +1077,36 @@
 r() %7B%0A%09%09
-return
+Layer backLogLayer =
  layerDA
@@ -1136,16 +1136,146 @@
 YER_ID);
+;%0A%09%09%0A%09%09if(backLogLayer == null) %7B%0A%09%09%09throw new SystemBreakException(%22The backlog layer is invalid%22);%0A%09%09%7D%0A%09%09%0A%09%09return backLogLayer;
 %0A%09%7D%0A%09%0A%7D%0A

Throw exception if backlog layer are null