Commit 549d8817 authored by Peter Harrison's avatar Peter Harrison

Fix for TemplateController to check for presence of templates under a

board before adding template.
Modified methods to add a try around OCM operations to ensure connection
is properly closed.
parent 29be6115
...@@ -111,18 +111,21 @@ public class PhaseController { ...@@ -111,18 +111,21 @@ public class PhaseController {
logger.warn("Attempt to update phase using POST"); logger.warn("Attempt to update phase using POST");
throw new Exception("Attempt to Update Phase using POST. Use PUT instead"); throw new Exception("Attempt to Update Phase using POST. Use PUT instead");
} }
ObjectContentManager ocm = ocmFactory.getOcm(); ObjectContentManager ocm = ocmFactory.getOcm();
listTools.ensurePresence(String.format(URI.BOARD_URI, boardId), "phases", ocm.getSession()); try{
listTools.ensurePresence(String.format(URI.BOARD_URI, boardId), "phases", ocm.getSession());
// Save the new Phase
String newName = IdentifierTools.getIdFromNamedModelClass(phase);
phase.setPath(String.format(URI.PHASES_URI, boardId, newName));
ocm.insert(phase);
ocm.save();
this.cacheInvalidationManager.invalidate(BoardController.BOARD, boardId);
} finally {
ocm.logout();
}
// Save the new Phase
String newName = IdentifierTools.getIdFromNamedModelClass(phase);
phase.setPath(String.format(URI.PHASES_URI, boardId, newName));
ocm.insert(phase);
ocm.save();
ocm.logout();
this.cacheInvalidationManager.invalidate(BoardController.BOARD, boardId);
return phase; return phase;
} }
...@@ -136,10 +139,14 @@ public class PhaseController { ...@@ -136,10 +139,14 @@ public class PhaseController {
phase.setPath(String.format(URI.PHASES_URI, boardId, phaseId)); phase.setPath(String.format(URI.PHASES_URI, boardId, phaseId));
} }
ObjectContentManager ocm = ocmFactory.getOcm(); ObjectContentManager ocm = ocmFactory.getOcm();
ocm.update(phase); try {
ocm.save(); ocm.update(phase);
ocm.logout(); ocm.save();
this.cacheInvalidationManager.invalidate(BoardController.BOARD, boardId); this.cacheInvalidationManager.invalidate(BoardController.BOARD, boardId);
} finally {
ocm.logout();
}
return phase; return phase;
} }
...@@ -147,8 +154,12 @@ public class PhaseController { ...@@ -147,8 +154,12 @@ public class PhaseController {
@RequestMapping(value = "", method=RequestMethod.GET) @RequestMapping(value = "", method=RequestMethod.GET)
public @ResponseBody Collection<Phase> getPhaseList(@PathVariable String boardId) throws Exception { public @ResponseBody Collection<Phase> getPhaseList(@PathVariable String boardId) throws Exception {
ObjectContentManager ocm = ocmFactory.getOcm(); ObjectContentManager ocm = ocmFactory.getOcm();
Collection<Phase> objects = ocm.getChildObjects(Phase.class, String.format(URI.PHASES_URI, boardId, "")); Collection<Phase> objects = null;
ocm.logout(); try {
objects = ocm.getChildObjects(Phase.class, String.format(URI.PHASES_URI, boardId, ""));
} finally {
ocm.logout();
}
return objects; return objects;
} }
...@@ -181,15 +192,17 @@ public class PhaseController { ...@@ -181,15 +192,17 @@ public class PhaseController {
@PathVariable String phaseId) throws Exception { @PathVariable String phaseId) throws Exception {
Session session = ocmFactory.getOcm().getSession(); Session session = ocmFactory.getOcm().getSession();
Map<String,String> result = listTools.list(String.format(URI.CARDS_URI, boardId, phaseId, ""), "id", session); try {
session.logout(); Map<String,String> result = listTools.list(String.format(URI.CARDS_URI, boardId, phaseId, ""), "id", session);
for( Entry<String,String> entry : result.entrySet()){
for( Entry<String,String> entry : result.entrySet()){ CardHolder cardHolder = new CardHolder();
CardHolder cardHolder = new CardHolder(); cardHolder.setBoardId(boardId);
cardHolder.setBoardId(boardId); cardHolder.setCardId(entry.getKey());
cardHolder.setCardId(entry.getKey()); cardListener.addCardHolder(cardHolder);
cardListener.addCardHolder(cardHolder); Thread.sleep(3500);
Thread.sleep(3500); }
} finally {
session.logout();
} }
return true; return true;
} }
...@@ -217,10 +230,12 @@ public class PhaseController { ...@@ -217,10 +230,12 @@ public class PhaseController {
session.save(); session.save();
} catch (PathNotFoundException e){ } catch (PathNotFoundException e){
// This is expected - there should be no property. // This is expected - there should be no property.
} finally {
session.logout();
} }
session.logout();
this.cacheInvalidationManager.invalidate(BoardController.BOARD, boardId); this.cacheInvalidationManager.invalidate(BoardController.BOARD, boardId);
return true; return true;
} }
...@@ -268,8 +283,7 @@ public class PhaseController { ...@@ -268,8 +283,7 @@ public class PhaseController {
ObjectContentManager ocm = ocmFactory.getOcm(); ObjectContentManager ocm = ocmFactory.getOcm();
try{ try{
Node node = ocm.getSession().getNode(String.format(URI.TASKS_URI, card.getBoard(), card.getPhase(), card.getId().toString(),"")); Node node = ocm.getSession().getNode(String.format(URI.TASKS_URI, card.getBoard(), card.getPhase(), card.getId().toString(),""));
int complete = 0; int complete = 0;
NodeIterator nodes = node.getNodes(); NodeIterator nodes = node.getNodes();
while(nodes.hasNext()){ while(nodes.hasNext()){
...@@ -279,7 +293,6 @@ public class PhaseController { ...@@ -279,7 +293,6 @@ public class PhaseController {
complete++; complete++;
} }
} }
card.setCompleteTasks(new Long(complete)); card.setCompleteTasks(new Long(complete));
} finally { } finally {
......
...@@ -96,6 +96,9 @@ public class TemplateController { ...@@ -96,6 +96,9 @@ public class TemplateController {
} }
ObjectContentManager ocm = ocmFactory.getOcm(); ObjectContentManager ocm = ocmFactory.getOcm();
try{ try{
listTools.ensurePresence(String.format(URI.BOARD_URI, boardId), "templates", ocm.getSession());
String templateId = template.getId(); String templateId = template.getId();
if( templateId==null){ if( templateId==null){
templateId=IdentifierTools.getIdFromNamedModelClass(template); templateId=IdentifierTools.getIdFromNamedModelClass(template);
......
package nz.net.orcon.kanban.automation.actions; package nz.net.orcon.kanban.automation.actions;
import static org.junit.Assert.*;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.FileInputStream; import java.io.FileInputStream;
...@@ -18,9 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -18,9 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.amazonaws.services.identitymanagement.model.ListSigningCertificatesResult;
import com.amazonaws.services.identitymanagement.model.ServerCertificateMetadata; import com.amazonaws.services.identitymanagement.model.ServerCertificateMetadata;
import com.amazonaws.services.identitymanagement.model.SigningCertificate;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/test-aws.xml" }) @ContextConfiguration(locations = { "/test-aws.xml" })
...@@ -61,6 +57,7 @@ public class AwsAutomationActionTest { ...@@ -61,6 +57,7 @@ public class AwsAutomationActionTest {
} }
@Test @Test
@Ignore
public void testCreateCloudFrontDistribution(){ public void testCreateCloudFrontDistribution(){
Collection<String> loadBalancerList = automationAction.getLoadBalancerList(); Collection<String> loadBalancerList = automationAction.getLoadBalancerList();
......
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