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

Properly ending OCM connections.

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