Commit 2754b553 authored by Peter Harrison's avatar Peter Harrison

Properly ending OCM connections.

parent 609124ab
...@@ -90,13 +90,16 @@ public class RuleController { ...@@ -90,13 +90,16 @@ public class RuleController {
} }
ObjectContentManager ocm = ocmFactory.getOcm(); ObjectContentManager ocm = ocmFactory.getOcm();
listTools.ensurePresence(String.format(URI.BOARD_URI, boardId), "rules", ocm.getSession()); try{
rule.setPath(String.format(URI.RULE_URI, boardId, IdentifierTools.getIdFromNamedModelClass(rule)));
ocm.insert(rule);
ocm.save(); listTools.ensurePresence(String.format(URI.BOARD_URI, boardId), "rules", ocm.getSession());
ocm.logout();
rule.setPath(String.format(URI.RULE_URI, boardId, IdentifierTools.getIdFromNamedModelClass(rule)));
ocm.insert(rule);
ocm.save();
} finally {
ocm.logout();
}
return rule; return rule;
} }
...@@ -132,17 +135,19 @@ public class RuleController { ...@@ -132,17 +135,19 @@ public class RuleController {
} }
ObjectContentManager ocm = ocmFactory.getOcm(); ObjectContentManager ocm = ocmFactory.getOcm();
Node node = ocm.getSession().getNode(String.format(URI.RULE_URI, boardId, ruleId)); try {
Node node = ocm.getSession().getNode(String.format(URI.RULE_URI, boardId, ruleId));
if(node==null){ if(node==null){
throw new ResourceNotFoundException();
}
node.remove();
ocm.save();
this.cacheInvalidationManager.invalidate(RULE, ruleCache.getCacheId(boardId,ruleId));
} finally {
ocm.logout(); ocm.logout();
throw new ResourceNotFoundException();
} }
node.remove();
ocm.save();
ocm.logout();
this.cacheInvalidationManager.invalidate(RULE, ruleCache.getCacheId(boardId,ruleId));
} }
public void setJmsTemplate(JmsTemplate jmsTemplate) { public void setJmsTemplate(JmsTemplate jmsTemplate) {
......
/** /**
* GRAVITY WORKFLOW AUTOMATION * GRAVITY WORKFLOW AUTOMATION
* (C) Copyright 2015 Orcon Limited * (C) Copyright 2015 Orcon Limited
* (C) Copyright 2016 Peter Harrison
* *
* This file is part of Gravity Workflow Automation. * This file is part of Gravity Workflow Automation.
* *
...@@ -76,5 +77,4 @@ public class TeamCache extends CacheImpl<Team> { ...@@ -76,5 +77,4 @@ public class TeamCache extends CacheImpl<Team> {
} }
return result; return result;
} }
} }
/** /**
* GRAVITY WORKFLOW AUTOMATION * GRAVITY WORKFLOW AUTOMATION
* (C) Copyright 2015 Orcon Limited * (C) Copyright 2015 Orcon Limited
* (C) Copyright 2016 Peter Harrison
* *
* This file is part of Gravity Workflow Automation. * This file is part of Gravity Workflow Automation.
* *
...@@ -76,9 +77,8 @@ public class TeamController { ...@@ -76,9 +77,8 @@ public class TeamController {
throw new Exception("Attempt to Update team using POST. Use PUT instead"); throw new Exception("Attempt to Update team using POST. Use PUT instead");
} }
ObjectContentManager ocm = null; ObjectContentManager ocm = ocmFactory.getOcm();
try { try {
ocm = ocmFactory.getOcm();
String newId = IdentifierTools.getIdFromNamedModelClass(team); String newId = IdentifierTools.getIdFromNamedModelClass(team);
team.setPath(String.format(URI.TEAM_URI, newId.toString())); team.setPath(String.format(URI.TEAM_URI, newId.toString()));
...@@ -90,9 +90,7 @@ public class TeamController { ...@@ -90,9 +90,7 @@ public class TeamController {
ocm.save(); ocm.save();
this.cacheInvalidationManager.invalidate(TEAM, newId); this.cacheInvalidationManager.invalidate(TEAM, newId);
} finally { } finally {
if(ocm!=null){ ocm.logout();
ocm.logout();
}
} }
return team; return team;
} }
...@@ -106,16 +104,13 @@ public class TeamController { ...@@ -106,16 +104,13 @@ public class TeamController {
@PreAuthorize("hasPermission(#teamId, 'TEAM', 'ADMIN')") @PreAuthorize("hasPermission(#teamId, 'TEAM', 'ADMIN')")
@RequestMapping(value = "/{teamId}", method=RequestMethod.DELETE) @RequestMapping(value = "/{teamId}", method=RequestMethod.DELETE)
public @ResponseBody void deleteTeam(@PathVariable String teamId) throws Exception { public @ResponseBody void deleteTeam(@PathVariable String teamId) throws Exception {
ObjectContentManager ocm = null; ObjectContentManager ocm = ocmFactory.getOcm();
try{ try{
ocm = ocmFactory.getOcm();
ocm.getSession().removeItem(String.format(URI.TEAM_URI, teamId)); ocm.getSession().removeItem(String.format(URI.TEAM_URI, teamId));
ocm.save(); ocm.save();
this.cacheInvalidationManager.invalidate(TEAM, teamId); this.cacheInvalidationManager.invalidate(TEAM, teamId);
} finally { } finally {
if(ocm!=null){ ocm.logout();
ocm.logout();
}
} }
} }
...@@ -129,7 +124,6 @@ public class TeamController { ...@@ -129,7 +124,6 @@ public class TeamController {
ObjectContentManager ocm = ocmFactory.getOcm(); ObjectContentManager ocm = ocmFactory.getOcm();
try{ try{
listTools.ensurePresence(String.format( URI.TEAM_URI, teamId), "owners", ocm.getSession()); listTools.ensurePresence(String.format( URI.TEAM_URI, teamId), "owners", ocm.getSession());
Node node = ocm.getSession().getNode(String.format(URI.TEAM_OWNERS, teamId,"")); Node node = ocm.getSession().getNode(String.format(URI.TEAM_OWNERS, teamId,""));
...@@ -192,6 +186,4 @@ public class TeamController { ...@@ -192,6 +186,4 @@ public class TeamController {
ocm.logout(); ocm.logout();
} }
} }
} }
/** /**
* GRAVITY WORKFLOW AUTOMATION * GRAVITY WORKFLOW AUTOMATION
* (C) Copyright 2015 Orcon Limited * (C) Copyright 2015 Orcon Limited
* (C) Copyright 2016 Peter Harrison
* *
* This file is part of Gravity Workflow Automation. * This file is part of Gravity Workflow Automation.
* *
...@@ -70,9 +71,7 @@ public class UserController { ...@@ -70,9 +71,7 @@ public class UserController {
ocm.insert(user); ocm.insert(user);
ocm.save(); ocm.save();
} finally { } finally {
if(ocm!=null){ ocm.logout();
ocm.logout();
}
} }
return user; return user;
} }
...@@ -92,9 +91,7 @@ public class UserController { ...@@ -92,9 +91,7 @@ public class UserController {
user.setPasswordhash(null); user.setPasswordhash(null);
} finally { } finally {
if(ocm!=null){ ocm.logout();
ocm.logout();
}
} }
return user; return user;
} }
...@@ -106,9 +103,7 @@ public class UserController { ...@@ -106,9 +103,7 @@ public class UserController {
session.removeItem(String.format(URI.USER_URI, userId)); session.removeItem(String.format(URI.USER_URI, userId));
session.save(); session.save();
} finally { } finally {
if(session!=null){ session.logout();
session.logout();
}
} }
} }
...@@ -147,8 +142,6 @@ public class UserController { ...@@ -147,8 +142,6 @@ public class UserController {
} else { } else {
logger.warn("Wrong user credentials while changing password."); logger.warn("Wrong user credentials while changing password.");
} }
} catch( Exception e){
logger.error("Exception changing password.", e);
} finally { } finally {
if(ocm!=null){ if(ocm!=null){
ocm.logout(); ocm.logout();
......
/** /**
* GRAVITY WORKFLOW AUTOMATION * GRAVITY WORKFLOW AUTOMATION
* (C) Copyright 2015 Orcon Limited * (C) Copyright 2015 Orcon Limited
* (C) Copyright 2016 Peter Harrison
* *
* This file is part of Gravity Workflow Automation. * This file is part of Gravity Workflow Automation.
* *
...@@ -81,13 +82,16 @@ public class ViewController { ...@@ -81,13 +82,16 @@ public class ViewController {
throw new Exception("Attempt to Update Template using POST. Use PUT instead"); throw new Exception("Attempt to Update Template using POST. Use PUT instead");
} }
ObjectContentManager ocm = ocmFactory.getOcm(); ObjectContentManager ocm = ocmFactory.getOcm();
listTools.ensurePresence(String.format(URI.BOARD_URI, boardId), "views", ocm.getSession()); try {
String newId = IdentifierTools.getIdFromNamedModelClass(view); listTools.ensurePresence(String.format(URI.BOARD_URI, boardId), "views", ocm.getSession());
view.setPath(String.format(URI.VIEW_URI, boardId, newId.toString())); String newId = IdentifierTools.getIdFromNamedModelClass(view);
ocm.insert(view); view.setPath(String.format(URI.VIEW_URI, boardId, newId.toString()));
ocm.save(); ocm.insert(view);
ocm.logout(); ocm.save();
this.cacheInvalidationManager.invalidate(BoardController.BOARD, boardId); this.cacheInvalidationManager.invalidate(BoardController.BOARD, boardId);
} finally {
ocm.logout();
}
return view; return view;
} }
...@@ -117,15 +121,17 @@ public class ViewController { ...@@ -117,15 +121,17 @@ public class ViewController {
public @ResponseBody View getView(@PathVariable String boardId, public @ResponseBody View getView(@PathVariable String boardId,
@PathVariable String viewId) throws Exception { @PathVariable String viewId) throws Exception {
ObjectContentManager ocm = ocmFactory.getOcm(); ObjectContentManager ocm = ocmFactory.getOcm();
View view = (View) ocm.getObject(View.class,String.format(URI.VIEW_URI, boardId, viewId)); View view;
ocm.logout(); try {
view = (View) ocm.getObject(View.class,String.format(URI.VIEW_URI, boardId, viewId));
if(view==null){ if(view==null){
throw new ResourceNotFoundException();
}
} finally {
ocm.logout(); ocm.logout();
throw new ResourceNotFoundException();
} }
return view; return view;
} }
...@@ -133,12 +139,15 @@ public class ViewController { ...@@ -133,12 +139,15 @@ public class ViewController {
public @ResponseBody void deleteView(@PathVariable String boardId, public @ResponseBody void deleteView(@PathVariable String boardId,
@PathVariable String viewId) throws Exception { @PathVariable String viewId) throws Exception {
ObjectContentManager ocm = ocmFactory.getOcm(); ObjectContentManager ocm = ocmFactory.getOcm();
String path = String.format(URI.VIEW_URI, boardId, viewId); try {
ocm.getSession().removeItem(path); String path = String.format(URI.VIEW_URI, boardId, viewId);
ocm.save(); ocm.getSession().removeItem(path);
ocm.logout(); ocm.save();
this.cacheInvalidationManager.invalidate(BoardController.BOARD, boardId); this.cacheInvalidationManager.invalidate(BoardController.BOARD, boardId);
} finally {
ocm.logout();
}
} }
@RequestMapping(value = "/{viewId}/fields/{fieldId}", method=RequestMethod.GET) @RequestMapping(value = "/{viewId}/fields/{fieldId}", method=RequestMethod.GET)
...@@ -146,14 +155,16 @@ public class ViewController { ...@@ -146,14 +155,16 @@ public class ViewController {
@PathVariable String viewId, @PathVariable String viewId,
@PathVariable String fieldId) throws Exception { @PathVariable String fieldId) throws Exception {
ObjectContentManager ocm = ocmFactory.getOcm(); ObjectContentManager ocm = ocmFactory.getOcm();
ViewField viewField = (ViewField) ocm.getObject(ViewField.class,String.format(URI.VIEW_FIELD_URI, boardId, viewId, fieldId)); ViewField viewField;
ocm.logout(); try {
viewField = (ViewField) ocm.getObject(ViewField.class,String.format(URI.VIEW_FIELD_URI, boardId, viewId, fieldId));
if(viewField==null){ if(viewField==null){
throw new ResourceNotFoundException(); throw new ResourceNotFoundException();
}
} finally {
ocm.logout();
} }
return viewField; return viewField;
} }
...@@ -162,11 +173,14 @@ public class ViewController { ...@@ -162,11 +173,14 @@ public class ViewController {
@PathVariable String viewId, @PathVariable String viewId,
@RequestBody ViewField viewField) throws Exception { @RequestBody ViewField viewField) throws Exception {
ObjectContentManager ocm = ocmFactory.getOcm(); ObjectContentManager ocm = ocmFactory.getOcm();
viewField.setPath(String.format(URI.VIEW_FIELD_URI, boardId, viewId, viewField.getName())); try {
ocm.insert(viewField); viewField.setPath(String.format(URI.VIEW_FIELD_URI, boardId, viewId, viewField.getName()));
ocm.save(); ocm.insert(viewField);
ocm.logout(); ocm.save();
} finally {
ocm.logout();
}
this.cacheInvalidationManager.invalidate(BoardController.BOARD, boardId); this.cacheInvalidationManager.invalidate(BoardController.BOARD, boardId);
return viewField; return viewField;
} }
...@@ -176,20 +190,27 @@ public class ViewController { ...@@ -176,20 +190,27 @@ public class ViewController {
@PathVariable String viewId, @PathVariable String viewId,
@PathVariable String fieldId) throws Exception { @PathVariable String fieldId) throws Exception {
ObjectContentManager ocm = ocmFactory.getOcm(); ObjectContentManager ocm = ocmFactory.getOcm();
String path = String.format(URI.VIEW_FIELD_URI, boardId, viewId, fieldId); try {
ocm.getSession().removeItem(path); String path = String.format(URI.VIEW_FIELD_URI, boardId, viewId, fieldId);
ocm.save(); ocm.getSession().removeItem(path);
ocm.logout(); ocm.save();
this.cacheInvalidationManager.invalidate(BoardController.BOARD, boardId); this.cacheInvalidationManager.invalidate(BoardController.BOARD, boardId);
} finally {
ocm.logout();
}
} }
@RequestMapping(value = "", method=RequestMethod.GET) @RequestMapping(value = "", method=RequestMethod.GET)
public @ResponseBody Map<String,String> listViews(@PathVariable String boardId) throws Exception { public @ResponseBody Map<String,String> listViews(@PathVariable String boardId) throws Exception {
Session session = ocmFactory.getOcm().getSession(); Session session = ocmFactory.getOcm().getSession();
Map<String,String> result = listTools.list(String.format(URI.VIEW_URI, boardId,""), "name", session); Map<String,String> result;
session.logout(); try {
result = listTools.list(String.format(URI.VIEW_URI, boardId,""), "name", session);
} finally {
session.logout();
}
return result; return result;
} }
} }
...@@ -82,7 +82,7 @@ public class XmlFileController { ...@@ -82,7 +82,7 @@ public class XmlFileController {
try{ try{
ocm = ocmFactory.getOcm(); ocm = ocmFactory.getOcm();
cardList = cardTools.getCardList(boardId,includeArchive, ocm); cardList = cardTools.getCardList(boardId,includeArchive, ocm);
}finally{ } finally {
ocm.logout(); ocm.logout();
} }
......
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