Commit 6b4709c4 authored by Peter Harrison's avatar Peter Harrison

Modify the Board object to access the actual templates list.

This will resolve an issue in production where the templates have
become out of sync.
parent 96328138
......@@ -87,7 +87,7 @@ public class SpawnPlugin implements Plugin {
throw new ResourceNotFoundException();
}
String targetTemplateName = targetBoard.getTemplates().get(targetTemplateId);
String targetTemplateName = targetBoard.getTemplates().get(targetTemplateId).getName();
if(targetTemplateName==null){
logger.warn("Template Not Found: " + targetTemplateId );
}
......
......@@ -30,6 +30,7 @@ import java.util.Map.Entry;
import nz.net.orcon.kanban.model.Board;
import nz.net.orcon.kanban.model.Phase;
import nz.net.orcon.kanban.model.SimpleTemplate;
import nz.net.orcon.kanban.model.Template;
import org.slf4j.Logger;
......@@ -68,10 +69,10 @@ public class UiController {
model.addAttribute("boardId", boardId);
Board board = boardsCache.getItem(boardId);
model.addAttribute("board", board);
Map<String, String> values = board.getTemplates();
Map<String, SimpleTemplate> values = board.getTemplates();
if( values!=null){
String templateId = values.values().iterator().next();
model.addAttribute("templateId", templateId );
SimpleTemplate templateId = values.values().iterator().next();
model.addAttribute("templateId", templateId.getId() );
}
List<Phase> phases = new ArrayList<Phase>(board.getPhases().values());
......@@ -94,9 +95,9 @@ public class UiController {
model.addAttribute("boardId", boardId);
Board board = boardsCache.getItem(boardId);
model.addAttribute("board", board);
Map<String, String> values = board.getTemplates();
Map<String, SimpleTemplate> values = board.getTemplates();
if( values!=null){
String templateId = values.values().iterator().next();
String templateId = values.values().iterator().next().getId();
model.addAttribute("templateId", templateId );
Template template = templateController.getTemplate(boardId,templateId);
model.addAttribute("template", template);
......@@ -111,9 +112,9 @@ public class UiController {
Model model) throws Exception {
log.info("Card UI - " + boardId);
Board board = boardsCache.getItem(boardId);
Map<String, String> templates = board.getTemplates();
Entry<String, String> next = templates.entrySet().iterator().next();
String templateId = next.getValue();
Map<String, SimpleTemplate> templates = board.getTemplates();
Entry<String, SimpleTemplate> next = templates.entrySet().iterator().next();
String templateId = next.getValue().getId();
Template template = templateController.getTemplate(boardId,templateId);
model.addAttribute("template", template);
model.addAttribute("phaseId", phaseId);
......@@ -128,9 +129,9 @@ public class UiController {
Model model) throws Exception {
Board board = boardsCache.getItem(boardId);
Map<String, String> templates = board.getTemplates();
Entry<String, String> next = templates.entrySet().iterator().next();
String templateId = next.getValue();
Map<String, SimpleTemplate> templates = board.getTemplates();
Entry<String, SimpleTemplate> next = templates.entrySet().iterator().next();
String templateId = next.getValue().getId();
model.addAttribute("template", templateId);
model.addAttribute("boardid", boardId);
model.addAttribute("phaseid", phaseId);
......
......@@ -36,8 +36,10 @@ public class Board extends AbstractNamedModelClass implements Serializable, Secu
@Collection(jcrMandatory=false,collectionConverter=StringCollectionConverterImpl.class)
private Map<String,String> roles;
@Collection(jcrMandatory=false,collectionConverter=StringCollectionConverterImpl.class)
private Map<String,String> templates;
//@Collection(jcrMandatory=false,collectionConverter=StringCollectionConverterImpl.class)
@Collection(jcrMandatory=false)
private Map<String,SimpleTemplate> templates;
@Collection(jcrMandatory=false)
private Map<String,Phase> phases;
......@@ -48,11 +50,11 @@ public class Board extends AbstractNamedModelClass implements Serializable, Secu
@Collection(jcrMandatory=false)
private Map<String,View> views;
public void setTemplates(Map<String,String> templates) {
public void setTemplates(Map<String,SimpleTemplate> templates) {
this.templates = templates;
}
public Map<String,String> getTemplates() {
public Map<String,SimpleTemplate> getTemplates() {
return templates;
}
......
/**
* GRAVITY WORKFLOW AUTOMATION
* (C) Copyright 2015 Orcon Limited
*
* 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;
import java.io.Serializable;
import org.apache.jackrabbit.ocm.mapper.impl.annotation.Node;
@Node(discriminator=false)
public class SimpleTemplate extends AbstractNamedModelClass implements Serializable {
public SimpleTemplate() {
super();
}
public SimpleTemplate(String path, String name) {
super();
setPath(path);
setName(name);
}
}
......@@ -40,6 +40,7 @@
<property name="classList">
<list>
<value>Template</value>
<value>SimpleTemplate</value>
<value>TemplateField</value>
<value>TemplateTask</value>
<value>TemplateGroup</value>
......
......@@ -3,15 +3,15 @@ var template = {
currenttemplate: false,
loadTemplates: function(templates) {
$.each(templates, function(k,t) {
if (!template.templates[t]) {
if (!template.templates[t.id]) {
$.ajax({
async: false,
url: ajaxUrl + '/template/' + t,
url: ajaxUrl + '/template/' + t.id,
success: function(data) {
template.templates[t] = data;
template.templates[t.id] = data;
$.each(data.fields, function(f, v) {
if (v.highlight) {
template.templates[t]['highlight'][f] = v.highlight;
template.templates[t.id]['highlight'][f] = v.highlight;
}
});
}
......
......@@ -45,7 +45,7 @@ var board = {
board.changeCurrentBoard(boardid);
jQuery.each(data.templates, function(i, t) {
template.loadTemplate(boardid,t);
template.loadTemplate(boardid,t.id);
});
phase.setPhases(data.phases);
......
......@@ -17,6 +17,7 @@ import nz.net.orcon.kanban.model.Filter;
import nz.net.orcon.kanban.model.Operation;
import nz.net.orcon.kanban.model.Phase;
import nz.net.orcon.kanban.model.Rule;
import nz.net.orcon.kanban.model.SimpleTemplate;
import nz.net.orcon.kanban.model.View;
import nz.net.orcon.kanban.model.ViewField;
......@@ -80,7 +81,7 @@ public class TestBoardTool {
ruleController.createRule(BOARD_ID, rule);
}
public Board getTestBoard( String name ){
public Board getTestBoard( String name ) throws Exception{
Map<String,Phase> phases = new HashMap<String,Phase>();
phases.put("test-phase", getTestPhase( "Test Phase", 1));
phases.put("next-phase", getTestPhase( "Next Phase", 2));
......@@ -88,8 +89,13 @@ public class TestBoardTool {
Map<String,View> views = new HashMap<String,View>();
views.put("testview", getTestView("Test View"));
Map<String, String> templates = new HashMap<String, String>();
templates.put("Test Template", TEMPLATE_ID);
SimpleTemplate template = new SimpleTemplate();
template.setId("test-template");
template.setName("Test Template");
Map<String, SimpleTemplate> templates = new HashMap<String, SimpleTemplate>();
templates.put("test-template", template);
Board board = new Board();
board.setName(name);
......
......@@ -41,6 +41,7 @@
<property name="classList">
<list>
<value>Template</value>
<value>SimpleTemplate</value>
<value>TemplateField</value>
<value>TemplateTask</value>
<value>TemplateGroup</value>
......
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