Commit dac060dc authored by Peter Harrison's avatar Peter Harrison

Adding Findbugs to POM

Adding  try/catch to  ensure OCM connections are closed on error.
Addressing some findbugs bugs.
parent 549d8817
......@@ -439,4 +439,14 @@
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.3</version>
</plugin>
</plugins>
</reporting>
</project>
......@@ -100,17 +100,11 @@ public class AutomationEngine {
try {
card = cardController.getCard(cardHolder.getBoardId(),
null, cardHolder.getCardId(), "full");
board = boardsCache.getItem(cardHolder.getBoardId());
} catch (ResourceNotFoundException e) {
LOG.info("Resource no longer exists: " + cardHolder.toString());
return;
}
if (board == null) {
LOG.warn("Board Not Found: " + cardHolder.getBoardId());
return;
}
Map<String,Rule> rules = getRulesFromBoard(cardHolder.getBoardId());
LOG.info("Automation Examining :" + card.getPath());
......@@ -121,7 +115,7 @@ public class AutomationEngine {
Collection<CardEvent> alerts = cardController.getAlerts(card.getBoard(), card.getPhase(), card.getId().toString());
for( CardEvent alert : alerts){
if(alert==null){
LOG.equals("Alert NULL inside Loop");
LOG.error("Alert NULL inside Loop");
}
if("alert".equals(alert.getLevel())){
......@@ -698,10 +692,6 @@ public class AutomationEngine {
// Get Rule.
Rule rule = ruleCache.getItem(boardId, ruleId);
if(rule==null){
LOG.warn("Execute Actions: Rule Not Found: "+ boardId + "/" + ruleId);
return;
}
List<Action> sortedActionList = getSortedActions(rule.getActions());
......@@ -771,37 +761,42 @@ public class AutomationEngine {
private void raiseAlertOnError(Throwable e, Rule rule, Action action, Card card) throws Exception{
String causeMessage = "";
StringBuilder message = new StringBuilder();
message.append(rule.getName());
message.append(" ");
message.append(action.getName());
message.append(" calling: ");
message.append(action.getType());
message.append(".");
message.append(action.getResource());
message.append(".");
message.append(action.getMethod());
message.append(" caused ");
Throwable cause = e;
while(cause!=null){
if( cause.getMessage()!=null){
causeMessage = causeMessage + "(" + cause.getMessage() + ") ";
message.append("(");
message.append(cause.getMessage());
message.append(") ");
}
cause = cause.getCause();
}
String message = rule.getName()
+ " " + action.getName()
+ " calling: " + action.getType()
+ "." + action.getResource()
+ "." + action.getMethod()
+ " caused " + causeMessage;
if(card!=null){
if( cardController!=null){
cardController.saveAlert(
card.getBoard(),
card.getPhase(),
card.getId().toString(),
message,
message.toString(),
"alert");
}
LOG.warn( "Automation Exception - Card " + card.getId() + " " + message, e);
LOG.warn( "Automation Exception - Card " + card.getId() + " " + message.toString(), e);
} else {
LOG.warn( "Automation Exception " + message, e);
LOG.warn( "Automation Exception " + message.toString(), e);
}
}
private void outputContext( Map<String,Object> context){
......
......@@ -115,7 +115,7 @@ public class ClusterManager {
*/
@Scheduled( fixedDelay=30000l )
public void pollLeader() throws Exception{
if(!this.leader){
if(!isLeader()){
this.executeChallenge();
}
}
......@@ -137,28 +137,28 @@ public class ClusterManager {
Message coupMessage = coupSync.receiveMessage(10000l);
boolean newLeader = (coupMessage==null);
if( this.leader!=newLeader){
if( isLeader()!=newLeader){
if(newLeader){
LOG.warn("FAILOVER: Node promoted to MASTER.");
this.leader = true;
setLeader(true);
this.jcrObserver.start();
this.timerManager.startup();
} else {
LOG.warn("FAILOVER: Node demoted to worker.");
this.leader = false;
setLeader(false);
this.jcrObserver.stop();
this.timerManager.stopAll();
}
}
return this.leader;
return isLeader();
}
public void setLeader(boolean leader) {
public synchronized void setLeader(boolean leader) {
this.leader = leader;
}
public boolean isLeader() {
public synchronized boolean isLeader() {
return leader;
}
......
......@@ -105,10 +105,6 @@ public class TimerManager {
Map<String, String> rules;
try {
rules = ruleCache.list(boardId,"");
if( rules==null){
LOG.warn("Board Rules Not Found when Loading Timer: " + boardId);
return;
}
} catch (javax.jcr.PathNotFoundException e ){
LOG.info("No Rule for Board: "+ boardId);
return;
......
......@@ -62,6 +62,8 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.amazonaws.util.StringUtils;
/**
*
*/
......@@ -407,11 +409,11 @@ public class BoardController {
detailFilter = "(jcr:contains(@detail,'${detail}'))".replaceAll("\\$\\{detail\\}", detail);
}
if(categoryFilter!="" && detailFilter!=""){
if( !StringUtils.isNullOrEmpty(categoryFilter) && !StringUtils.isNullOrEmpty(detailFilter)){
qmFilter.addJCRExpression( categoryFilter + " or " + detailFilter);
} else if (categoryFilter!="" && detailFilter=="") {
} else if ( !StringUtils.isNullOrEmpty(categoryFilter) && StringUtils.isNullOrEmpty(detailFilter)) {
qmFilter.addJCRExpression( categoryFilter );
} else if (categoryFilter=="" && detailFilter!="") {
} else if (StringUtils.isNullOrEmpty(categoryFilter) && !StringUtils.isNullOrEmpty(detailFilter)) {
qmFilter.addJCRExpression( detailFilter );
}
......
......@@ -913,7 +913,6 @@ public class CardController {
Rule rule = ruleCache.getItem(boardId,taskId);
if(rule==null){
ocm.logout();
logger.warn("Rule Not Found: " + boardId + "." + taskId);
throw new ResourceNotFoundException();
}
......@@ -1030,15 +1029,12 @@ public class CardController {
String.format(URI.TASKS_URI, boardId, phaseId, cardId,
taskId));
if (node == null) {
ocm.logout();
throw new ResourceNotFoundException();
}
node.remove();
ocm.save();
} finally {
if (null != ocm) {
ocm.logout();
}
ocm.logout();
}
}
......
......@@ -77,13 +77,16 @@ public class FilterController {
}
ObjectContentManager ocm = ocmFactory.getOcm();
listTools.ensurePresence(String.format(URI.BOARD_URI, boardId), "filters", ocm.getSession());
String newId = IdentifierTools.getIdFromNamedModelClass(filter);
filter.setPath(String.format(URI.FILTER_URI, boardId, newId.toString()));
ocm.insert(filter);
ocm.save();
ocm.logout();
this.cacheInvalidationManager.invalidate(BoardController.BOARD, boardId);
try {
listTools.ensurePresence(String.format(URI.BOARD_URI, boardId), "filters", ocm.getSession());
String newId = IdentifierTools.getIdFromNamedModelClass(filter);
filter.setPath(String.format(URI.FILTER_URI, boardId, newId.toString()));
ocm.insert(filter);
ocm.save();
this.cacheInvalidationManager.invalidate(BoardController.BOARD, boardId);
} finally {
ocm.logout();
}
return filter;
}
......@@ -98,10 +101,14 @@ public class FilterController {
}
ObjectContentManager ocm = ocmFactory.getOcm();
ocm.update(filter);
ocm.save();
ocm.logout();
this.cacheInvalidationManager.invalidate(BoardController.BOARD, boardId);
try {
ocm.update(filter);
ocm.save();
this.cacheInvalidationManager.invalidate(BoardController.BOARD, boardId);
} finally {
ocm.logout();
}
return filter;
}
......@@ -110,12 +117,16 @@ public class FilterController {
public @ResponseBody Filter getFilter(@PathVariable String boardId,
@PathVariable String filterId) throws Exception {
ObjectContentManager ocm = ocmFactory.getOcm();
Filter filter = (Filter) ocm.getObject(Filter.class,String.format(URI.FILTER_URI, boardId, filterId));
ocm.logout();
if(filter==null){
throw new ResourceNotFoundException();
}
ObjectContentManager ocm = ocmFactory.getOcm();
Filter filter = null;
try {
filter = (Filter) ocm.getObject(Filter.class,String.format(URI.FILTER_URI, boardId, filterId));
if(filter==null){
throw new ResourceNotFoundException();
}
} finally {
ocm.logout();
}
return filter;
}
......@@ -125,13 +136,16 @@ public class FilterController {
@PathVariable String filterId,
@RequestBody Condition filterField) throws Exception {
ObjectContentManager ocm = ocmFactory.getOcm();
listTools.ensurePresence(String.format(URI.FILTER_URI, boardId, filterId), "conditions", ocm.getSession());
filterField.setPath(String.format(URI.FILTER_CONDITION_URI, boardId, filterId, filterField.getFieldName()));
ocm.insert(filterField);
ocm.save();
ocm.logout();
this.cacheInvalidationManager.invalidate(BoardController.BOARD, boardId);
ObjectContentManager ocm = ocmFactory.getOcm();
try {
listTools.ensurePresence(String.format(URI.FILTER_URI, boardId, filterId), "conditions", ocm.getSession());
filterField.setPath(String.format(URI.FILTER_CONDITION_URI, boardId, filterId, filterField.getFieldName()));
ocm.insert(filterField);
ocm.save();
this.cacheInvalidationManager.invalidate(BoardController.BOARD, boardId);
} finally {
ocm.logout();
}
return filterField;
}
......@@ -141,12 +155,15 @@ public class FilterController {
@PathVariable String filterId,
@PathVariable String fieldId) throws Exception {
ObjectContentManager ocm = ocmFactory.getOcm();
String path = String.format(URI.FILTER_CONDITION_URI, boardId, filterId, 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.FILTER_CONDITION_URI, boardId, filterId, fieldId);
ocm.getSession().removeItem(path);
ocm.save();
this.cacheInvalidationManager.invalidate(BoardController.BOARD, boardId);
} finally {
ocm.logout();
}
}
@PreAuthorize("hasPermission(#boardId, 'BOARD', 'READ,WRITE,ADMIN')")
......@@ -154,8 +171,12 @@ public class FilterController {
public @ResponseBody Map<String,String> listFilters(@PathVariable String boardId) throws Exception {
Session session = ocmFactory.getOcm().getSession();
Map<String,String> result = listTools.list(String.format(URI.FILTER_URI, boardId,""), "name", session);
session.logout();
Map<String,String> result = null;
try {
result = listTools.list(String.format(URI.FILTER_URI, boardId,""), "name", session);
} finally {
session.logout();
}
return result;
}
......@@ -166,9 +187,13 @@ public class FilterController {
throws Exception {
ObjectContentManager ocm = ocmFactory.getOcm();
Collection<Card> cards = null;
Collection<Card> cards = listTools.query(boardId, null, filterId, ocm);
ocm.logout();
try {
cards = listTools.query(boardId, null, filterId, ocm);
} finally {
ocm.logout();
}
return cards;
}
......@@ -182,16 +207,18 @@ public class FilterController {
}
ObjectContentManager ocm = ocmFactory.getOcm();
Node node = ocm.getSession().getNode(String.format(URI.FILTER_URI, boardId, filterId));
try {
Node node = ocm.getSession().getNode(String.format(URI.FILTER_URI, boardId, filterId));
if(node==null){
if(node==null){
throw new ResourceNotFoundException();
}
node.remove();
ocm.save();
this.cacheInvalidationManager.invalidate(BoardController.BOARD, boardId);
} finally {
ocm.logout();
throw new ResourceNotFoundException();
}
node.remove();
ocm.save();
ocm.logout();
this.cacheInvalidationManager.invalidate(BoardController.BOARD, boardId);
}
}
......@@ -76,14 +76,17 @@ public class ListController {
@RequestBody ListResource list ) throws Exception {
ObjectContentManager ocm = ocmFactory.getOcm();
try {
listTools.ensurePresence(String.format( URI.BOARD_URI, boardId), "lists", ocm.getSession());
String newId = IdentifierTools.getIdFromNamedModelClass(list);
list.setPath(String.format(URI.LIST_URI, boardId, newId.toString()));
ocm.insert(list);
ocm.save();
ocm.logout();
listTools.ensurePresence(String.format( URI.BOARD_URI, boardId), "lists", ocm.getSession());
String newId = IdentifierTools.getIdFromNamedModelClass(list);
list.setPath(String.format(URI.LIST_URI, boardId, newId.toString()));
ocm.insert(list);
ocm.save();
} finally {
ocm.logout();
}
return list;
}
......@@ -164,17 +167,18 @@ public class ListController {
}
ObjectContentManager ocm = ocmFactory.getOcm();
Node node = ocm.getSession().getNode(String.format(URI.LIST_URI, boardId, listId));
try {
Node node = ocm.getSession().getNode(String.format(URI.LIST_URI, boardId, listId));
if(node==null){
throw new ResourceNotFoundException();
}
if(node==null){
node.remove();
ocm.save();
this.cacheInvalidationManager.invalidate(LIST, listCache.getCacheId(boardId,listId));
} finally {
ocm.logout();
throw new ResourceNotFoundException();
}
node.remove();
ocm.save();
ocm.logout();
this.cacheInvalidationManager.invalidate(LIST, listCache.getCacheId(boardId,listId));
}
}
......@@ -92,14 +92,16 @@ public class PhaseController {
public @ResponseBody Phase getPhase(
@PathVariable String boardId, @PathVariable String phaseId) throws Exception {
ObjectContentManager ocm = ocmFactory.getOcm();
Phase phase = (Phase) ocm.getObject(Phase.class, String.format(URI.PHASES_URI, boardId, phaseId));
ocm.logout();
if(phase==null){
throw new ResourceNotFoundException();
ObjectContentManager ocm = ocmFactory.getOcm();
Phase phase = null;
try {
phase = (Phase) ocm.getObject(Phase.class, String.format(URI.PHASES_URI, boardId, phaseId));
if(phase==null){
throw new ResourceNotFoundException();
}
} finally {
ocm.logout();
}
return phase;
}
......@@ -124,8 +126,6 @@ public class PhaseController {
} finally {
ocm.logout();
}
return phase;
}
......@@ -221,9 +221,9 @@ public class PhaseController {
@PathVariable String phaseId) throws Exception {
Session session = ocmFactory.getOcm().getSession();
Node node = session.getNode(String.format(URI.PHASES_URI, boardId, phaseId));
try{
Node node = session.getNode(String.format(URI.PHASES_URI, boardId, phaseId));
Property property = node.getProperty("cards");
// If there is a property we need to kill it.
property.remove();
......@@ -298,6 +298,5 @@ public class PhaseController {
} finally {
ocm.logout();
}
}
}
}
......@@ -100,15 +100,19 @@ public class ResourceController {
ObjectContentManager ocm = ocmFactory.getOcm();
listTools.ensurePresence(String.format( URI.BOARD_URI, boardId), "resources", ocm.getSession());
try {
Node node = ocm.getSession().getNode(String.format(URI.RESOURCE_URI, boardId, ""));
Node addNode = node.addNode(resourceId);
addNode.setProperty("resource",value);
addNode.setProperty("name",resourceId);
ocm.getSession().save();
ocm.logout();
listTools.ensurePresence(String.format( URI.BOARD_URI, boardId), "resources", ocm.getSession());
Node node = ocm.getSession().getNode(String.format(URI.RESOURCE_URI, boardId, ""));
Node addNode = node.addNode(resourceId);
addNode.setProperty("resource",value);
addNode.setProperty("name",resourceId);
ocm.getSession().save();
} finally {
ocm.logout();
}
logger.info("Resource Saved " + resourceId);
}
......@@ -120,16 +124,18 @@ public class ResourceController {
logger.info("Deleting Resource " + resourceId);
ObjectContentManager ocm = ocmFactory.getOcm();
Node node = ocm.getSession().getNode(String.format(URI.RESOURCE_URI, boardId, resourceId));
if(node==null){
try {
Node node = ocm.getSession().getNode(String.format(URI.RESOURCE_URI, boardId, resourceId));
if(node==null){
ocm.logout();
throw new ResourceNotFoundException();
}
node.remove();
ocm.save();
this.cacheInvalidationManager.invalidate(RESOURCE, resourceCache.getCacheId(boardId,resourceId));
} finally {
ocm.logout();
throw new ResourceNotFoundException();
}
node.remove();
ocm.save();
ocm.logout();
this.cacheInvalidationManager.invalidate(RESOURCE, resourceCache.getCacheId(boardId,resourceId));
}
@PreAuthorize("hasPermission(#boardId, 'BOARD', 'READ,WRITE,ADMIN')")
......
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