From e7204bd5f1964ff6c81f0bd83a376ea0d46cede5 Mon Sep 17 00:00:00 2001 From: Anja Kleebaum Date: Thu, 28 Jun 2018 13:22:56 +0200 Subject: [PATCH] ConDec-71: Improve code quality --- .../persistence/ActiveObjectStrategy.java | 41 ++++++++----------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/src/main/java/de/uhd/ifi/se/decision/documentation/jira/persistence/ActiveObjectStrategy.java b/src/main/java/de/uhd/ifi/se/decision/documentation/jira/persistence/ActiveObjectStrategy.java index 3bbbf51b0d..fc980dd509 100644 --- a/src/main/java/de/uhd/ifi/se/decision/documentation/jira/persistence/ActiveObjectStrategy.java +++ b/src/main/java/de/uhd/ifi/se/decision/documentation/jira/persistence/ActiveObjectStrategy.java @@ -21,8 +21,8 @@ import net.java.ao.Query; /** - * @description Extends the abstract class AbstractPersistenceStrategy. Uses the active - * object framework to store decision knowledge. + * @description Extends the abstract class AbstractPersistenceStrategy. Uses the + * active object framework to store decision knowledge. */ @JsonAutoDetect public class ActiveObjectStrategy extends AbstractPersistenceStrategy { @@ -31,7 +31,7 @@ public class ActiveObjectStrategy extends AbstractPersistenceStrategy { @Override public DecisionKnowledgeElement insertDecisionKnowledgeElement(DecisionKnowledgeElement decisionKnowledgeElement, - ApplicationUser user) { + ApplicationUser user) { if (decisionKnowledgeElement == null) { LOGGER.error("AOStrategy insertDecisionKnowledgeElement the DecisionRepresentation is null"); return null; @@ -46,8 +46,8 @@ public DecisionKnowledgeElement insertDecisionKnowledgeElement(DecisionKnowledge public DecisionKnowledgeElementEntity doInTransaction() { DecisionKnowledgeElementEntity databaseEntry = ACTIVE_OBJECTS .create(DecisionKnowledgeElementEntity.class); - databaseEntry.setKey( - decisionKnowledgeElement.getProjectKey().toUpperCase(Locale.ENGLISH) + "-" + databaseEntry.getId()); + databaseEntry.setKey(decisionKnowledgeElement.getProjectKey().toUpperCase(Locale.ENGLISH) + "-" + + databaseEntry.getId()); databaseEntry.setSummary(decisionKnowledgeElement.getSummary()); databaseEntry.setDescription(decisionKnowledgeElement.getDescription()); databaseEntry.setType(decisionKnowledgeElement.getType().toString()); @@ -84,11 +84,7 @@ public DecisionKnowledgeElementEntity doInTransaction() { return null; } }); - if (databaseEntry == null) { - return false; - } else { - return true; - } + return databaseEntry != null; } @Override @@ -193,7 +189,8 @@ public DecisionKnowledgeElementEntity doInTransaction() { } @Override - public List getElementsLinkedWithInwardLinks(DecisionKnowledgeElement decisionKnowledgeElement) { + public List getElementsLinkedWithInwardLinks( + DecisionKnowledgeElement decisionKnowledgeElement) { List inwardLinks = this.getInwardLinks(decisionKnowledgeElement); List children = new ArrayList(); for (Link inwardLink : inwardLinks) { @@ -216,7 +213,8 @@ public DecisionKnowledgeElementEntity doInTransaction() { } @Override - public List getElementsLinkedWithOutwardLinks(DecisionKnowledgeElement decisionKnowledgeElement) { + public List getElementsLinkedWithOutwardLinks( + DecisionKnowledgeElement decisionKnowledgeElement) { List outwardLinks = this.getOutwardLinks(decisionKnowledgeElement); List parents = new ArrayList(); for (Link outwardLink : outwardLinks) { @@ -299,13 +297,8 @@ public Long doInTransaction() { } @Override - public boolean editLink(Link link, ApplicationUser user){ - if(deleteLink(link,user)){ - if(insertLink(link,user)!=0){ - return true; - } - } - return false; + public boolean editLink(Link link, ApplicationUser user) { + return deleteLink(link, user) && insertLink(link, user) != 0; } @Override @@ -314,8 +307,10 @@ public boolean deleteLink(Link link, ApplicationUser user) { @Override public Boolean doInTransaction() { for (LinkEntity linkEntity : ACTIVE_OBJECTS.find(LinkEntity.class)) { - if (link.getIngoingId() == linkEntity.getIngoingId() && link.getOutgoingId() == linkEntity.getOutgoingId() - ||link.getOutgoingId() == linkEntity.getIngoingId() && link.getIngoingId() == linkEntity.getOutgoingId()) { + if (link.getIngoingId() == linkEntity.getIngoingId() + && link.getOutgoingId() == linkEntity.getOutgoingId() + || link.getOutgoingId() == linkEntity.getIngoingId() + && link.getIngoingId() == linkEntity.getOutgoingId()) { try { linkEntity.getEntityManager().delete(linkEntity); return true; @@ -359,7 +354,7 @@ public List getOutwardLinks(DecisionKnowledgeElement decisionKnowledgeElem // Converting the Entity to a DecisionKnowledgeElementImpl for future use private DecisionKnowledgeElement castToDecisionKnowledgeElement(DecisionKnowledgeElementEntity entity) { - return new DecisionKnowledgeElementImpl(entity.getId(), entity.getSummary(), - entity.getDescription(), entity.getType(), entity.getProjectKey(), entity.getKey()); + return new DecisionKnowledgeElementImpl(entity.getId(), entity.getSummary(), entity.getDescription(), + entity.getType(), entity.getProjectKey(), entity.getKey()); } } \ No newline at end of file