Skip to content

Commit

Permalink
ConDec-71: Improve code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
kleebaum committed Jun 28, 2018
1 parent 4408c1b commit e7204bd
Showing 1 changed file with 18 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand All @@ -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());
Expand Down Expand Up @@ -84,11 +84,7 @@ public DecisionKnowledgeElementEntity doInTransaction() {
return null;
}
});
if (databaseEntry == null) {
return false;
} else {
return true;
}
return databaseEntry != null;
}

@Override
Expand Down Expand Up @@ -193,7 +189,8 @@ public DecisionKnowledgeElementEntity doInTransaction() {
}

@Override
public List<DecisionKnowledgeElement> getElementsLinkedWithInwardLinks(DecisionKnowledgeElement decisionKnowledgeElement) {
public List<DecisionKnowledgeElement> getElementsLinkedWithInwardLinks(
DecisionKnowledgeElement decisionKnowledgeElement) {
List<Link> inwardLinks = this.getInwardLinks(decisionKnowledgeElement);
List<DecisionKnowledgeElement> children = new ArrayList<DecisionKnowledgeElement>();
for (Link inwardLink : inwardLinks) {
Expand All @@ -216,7 +213,8 @@ public DecisionKnowledgeElementEntity doInTransaction() {
}

@Override
public List<DecisionKnowledgeElement> getElementsLinkedWithOutwardLinks(DecisionKnowledgeElement decisionKnowledgeElement) {
public List<DecisionKnowledgeElement> getElementsLinkedWithOutwardLinks(
DecisionKnowledgeElement decisionKnowledgeElement) {
List<Link> outwardLinks = this.getOutwardLinks(decisionKnowledgeElement);
List<DecisionKnowledgeElement> parents = new ArrayList<DecisionKnowledgeElement>();
for (Link outwardLink : outwardLinks) {
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -359,7 +354,7 @@ public List<Link> 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());
}
}

0 comments on commit e7204bd

Please sign in to comment.