Commit cc857e72 authored by Peter Harrison's avatar Peter Harrison

[#50] Ability to Link a List to a Board, Phase and Filter

parent 428b9d61
......@@ -22,7 +22,9 @@
package nz.net.orcon.kanban.controllers;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
......@@ -30,7 +32,9 @@ import javax.annotation.Resource;
import javax.jcr.Node;
import nz.net.orcon.kanban.automation.CacheInvalidationInterface;
import nz.net.orcon.kanban.model.Card;
import nz.net.orcon.kanban.model.ListResource;
import nz.net.orcon.kanban.model.ListResourceType;
import nz.net.orcon.kanban.model.Option;
import nz.net.orcon.kanban.tools.IdentifierTools;
import nz.net.orcon.kanban.tools.ListTools;
......@@ -68,6 +72,12 @@ public class ListController {
@Autowired
ListTools listTools;
@Autowired
PhaseController phaseController;
@Autowired
CardController cardController;
@PreAuthorize("hasPermission(#boardId, 'BOARD', 'ADMIN')")
@RequestMapping(value = "", method=RequestMethod.POST)
......@@ -90,13 +100,50 @@ public class ListController {
return list;
}
/**
* Get List.
* There are two sources for a list:
* - A List within the Board itself, used for small lists.
* - A List generated out of another Board.
*
* @param boardId
* @param listId
* @return
* @throws Exception
*/
@PreAuthorize("hasPermission(#boardId, 'BOARD', 'READ,WRITE,ADMIN')")
@RequestMapping(value = "/{listId}", method=RequestMethod.GET)
public @ResponseBody ListResource getList(
@PathVariable String boardId,
@PathVariable String listId) throws Exception {
return listCache.getItem(boardId, IdentifierTools.getIdFromName(listId));
String lid = IdentifierTools.getIdFromName(listId);
ListResource item = listCache.getItem(boardId, lid);
if( item.getListResourceType()==null || item.getListResourceType().equals(ListResourceType.INTERNAL)){
return item;
} else {
Map<String, String> cardList = cardController.getCardList(item.getBoard(), item.getPhase(), item.getFilter());
List<String> newList = new ArrayList<String>();
newList.addAll(cardList.keySet());
List<Card> cards = phaseController.getCards(item.getBoard(), item.getPhase(), item.getView(), newList);
Map<String,Option> optionList = new HashMap<String,Option>();
for( Card card : cards){
Option option = new Option();
option.setId(item.getBoard() + "-" + card.getId().toString());
option.setName( (String)card.getFields().get(item.getNameField()));
Map<String,String> newAttrs = new HashMap<String,String>();
Map<String, Object> fields = card.getFields();
for( Entry<String,Object> attr : fields.entrySet()){
newAttrs.put(attr.getKey(), attr.getValue().toString());
}
option.setAttributes(newAttrs);
optionList.put(option.getId(), option);
}
item.setItems(optionList);
return item;
}
}
public String getValue(
......
/**
* GRAVITY WORKFLOW AUTOMATION
* (C) Copyright 2015 Orcon Limited
* (C) Copyright 2016 Peter Harrison
*
* This file is part of Gravity Workflow Automation.
*
......@@ -24,17 +25,78 @@ package nz.net.orcon.kanban.model;
import java.io.Serializable;
import java.util.Map;
import org.apache.jackrabbit.ocm.manager.enumconverter.EnumTypeConverter;
import org.apache.jackrabbit.ocm.mapper.impl.annotation.Collection;
import org.apache.jackrabbit.ocm.mapper.impl.annotation.Node;
import org.apache.jackrabbit.ocm.mapper.impl.annotation.Field;
@Node
public class ListResource extends AbstractNamedModelClass implements Serializable{
private static final long serialVersionUID = -1199910314402814094L;
@Field(converter=EnumTypeConverter.class)
private ListResourceType listResourceType;
@Field
private String board;
@Field
private String phase;
@Field
private String view;
@Field
private String filter;
@Field
private String nameField;
@Collection(jcrMandatory=false)
private Map<String, Option> items;
public ListResourceType getListResourceType() {
return listResourceType;
}
public void setListResourceType(ListResourceType listResourceType) {
this.listResourceType = listResourceType;
}
public String getBoard() {
return board;
}
public void setBoard(String board) {
this.board = board;
}
public String getPhase() {
return phase;
}
public void setPhase(String phase) {
this.phase = phase;
}
public String getView() {
return view;
}
public void setView(String view) {
this.view = view;
}
public String getFilter() {
return filter;
}
public void setFilter(String filter) {
this.filter = filter;
}
public void setItems(Map<String, Option> items) {
this.items = items;
}
......@@ -43,4 +105,12 @@ public class ListResource extends AbstractNamedModelClass implements Serializabl
return items;
}
public String getNameField() {
return nameField;
}
public void setNameField(String nameField) {
this.nameField = nameField;
}
}
/**
* GRAVITY WORKFLOW AUTOMATION
* (C) Copyright 2016 Peter Harrison
*
* This file is part of Gravity Workflow Automation.
*
* Gravity Workflow Automation is free software: you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* Gravity Workflow Automation is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Gravity Workflow Automation.
* If not, see <http://www.gnu.org/licenses/>.
*/
package nz.net.orcon.kanban.model;
public enum ListResourceType {
INTERNAL,
BOARD;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment