Skip to content

Commit

Permalink
TriggerRepositoryImpl class updated javadoc and removed some unused i…
Browse files Browse the repository at this point in the history
…mports
  • Loading branch information
mcicolella committed Jan 4, 2017
1 parent 86a9888 commit ce77fed
Showing 1 changed file with 25 additions and 23 deletions.
Expand Up @@ -31,11 +31,9 @@

import static com.freedomotic.util.FileOperations.writeSummaryFile;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -70,20 +68,20 @@ public TriggerRepositoryImpl(DataUpgradeService dataUpgradeService) {
@Override
public void saveTriggers(File folder) {
if (list.isEmpty()) {
LOG.warn("There are no triggers to persist, {} will not be altered", folder.getAbsolutePath());
LOG.warn("There are no triggers to persist, folder ''{}'' will not be altered", folder.getAbsolutePath());
return;
}

if (!folder.isDirectory()) {
LOG.warn("{} is not a valid trigger folder. Skipped", folder.getAbsoluteFile());
LOG.warn("''{}'' is not a valid trigger folder. Skipped", folder.getAbsoluteFile());
return;
}

XStream xstream = FreedomXStream.getXstream();
deleteTriggerFiles(folder);

try {
LOG.info("Saving triggers to file in {}", folder.getAbsolutePath());
LOG.info("Saving triggers to file into ''{}''", folder.getAbsolutePath());
StringBuffer summaryContent = new StringBuffer();
for (Trigger trigger : list) {
if (trigger.isToPersist()) {
Expand All @@ -97,13 +95,13 @@ public void saveTriggers(File folder) {
File file = new File(folder + "/" + fileName);
FreedomXStream.toXML(trigger, file);
}

summaryContent.append(trigger.getUUID()).append("\t\t").append(trigger.getName()).append("\t\t\t")
.append(trigger.getChannel()).append("\n");
.append(trigger.getChannel()).append("\n");
}

writeSummaryFile(new File(folder, "index.txt"), "#Filename \t\t #TriggerName \t\t\t #ListenedChannel\n", summaryContent.toString());

} catch (Exception e) {
LOG.error("Error while saving triggers ", e);
}
Expand Down Expand Up @@ -163,7 +161,6 @@ public boolean accept(File file) {
File[] files = folder.listFiles(objectFileFileter);

try {


if (files != null) {
for (File file : files) {
Expand All @@ -189,7 +186,7 @@ public boolean accept(File file) {
trigger = (Trigger) xstream.fromXML(xml);

} catch (DataUpgradeException dataUpgradeException) {
throw new RepositoryException("Cannot upgrade Trigger file " + file.getAbsolutePath(), dataUpgradeException);
throw new RepositoryException("Cannot upgrade trigger file " + file.getAbsolutePath(), dataUpgradeException);
} catch (XStreamException e) {
throw new RepositoryException("XML parsing error. Readed XML is \n" + xml, e);
}
Expand All @@ -208,11 +205,11 @@ public boolean accept(File file) {
list.add(trigger); //only in the list not registred. I will be registred only if used in mapping
}
} else {
LOG.warn("Trigger '{}' is already in the list", trigger.getName());
LOG.warn("Trigger ''{}'' is already in the list", trigger.getName());
}
}
} else {
LOG.info("No triggers to load from this folder {}", folder.toString());
LOG.info("No triggers to load from the folder ''{}''", folder.toString());
}
} catch (Exception e) {
LOG.error("Exception while loading this trigger ", e);
Expand All @@ -232,7 +229,7 @@ public static synchronized void addAndRegister(Trigger t) {
t.register();
int postSize = TriggerRepositoryImpl.size();
if (!(postSize == (preSize + 1))) {
LOG.error("Error while adding and registering trigger '{}'", t.getName());
LOG.error("Error while adding and registering trigger ''{}''", t.getName());
}
} else {
//this trigger is already in the list
Expand Down Expand Up @@ -265,7 +262,7 @@ public static synchronized void add(Trigger t) {
int postSize = TriggerRepositoryImpl.size();

if (!(postSize == (preSize + 1))) {
LOG.error("Error while adding trigger '{}'", t.getName());
LOG.error("Error while adding trigger ''{}''", t.getName());
}
}
}
Expand All @@ -284,10 +281,10 @@ public static synchronized void remove(Trigger t) {
int postSize = TriggerRepositoryImpl.size();

if (!(postSize == (preSize - 1))) {
LOG.error("Error while removing trigger '{}'", t.getName());
LOG.error("Error while removing trigger ''{}''", t.getName());
}
} catch (Exception e) {
LOG.error("Error while unregistering the trigger '{}'", t.getName(), e);
LOG.error("Error while unregistering trigger ''{}''", t.getName(), e);
}
}

Expand All @@ -308,7 +305,7 @@ public static Trigger getTrigger(String name) {
return trigger;
}
}
LOG.warn("Searching for a trigger named ''{}'' but it doesn''t exist", name);
LOG.warn("Searching for a trigger named ''{}'' but it doesn't exist", name);
return null;
}

Expand Down Expand Up @@ -367,8 +364,9 @@ public static Iterator<Trigger> iterator() {
}

/**
* Returns the triggers number.
*
* @return
* @return number of triggers
*/
public static int size() {
return list.size();
Expand Down Expand Up @@ -408,7 +406,7 @@ public boolean create(Trigger item) {
add(item);
return true;
} catch (Exception e) {
LOG.error("Cannot add trigger {} " + item.getName(), e);
LOG.error("Cannot add trigger ''{}''" + item.getName(), e);
return false;
}
}
Expand Down Expand Up @@ -446,12 +444,12 @@ public Trigger modify(String uuid, Trigger data) {
try {
data.register();
} catch (Exception f) {
LOG.warn("Cannot register trigger {} ", data.getName(), f);
LOG.warn("Cannot register trigger ''{}''", data.getName(), f);
}
return data;
}
} catch (Exception e) {
LOG.error("Error while modifying trigger {} " + data.getName(), e);
LOG.error("Error while modifying trigger ''{}''" + data.getName(), e);
return null;
}
}
Expand All @@ -465,7 +463,7 @@ public Trigger modify(String uuid, Trigger data) {
public Trigger copy(Trigger trg) {
try {
Trigger t = findOne(trg.getUUID()).clone();
t.setName("Copy of " + t.getName());
t.setName("Copy of trigger ''" + t.getName() + "''");
create(t);
return t;
} catch (Exception e) {
Expand All @@ -489,6 +487,10 @@ public void deleteAll() {
}
}

/**
* This class compares two triggers given their names.
*
*/
class TriggerNameComparator implements Comparator<Trigger> {

@Override
Expand Down

0 comments on commit ce77fed

Please sign in to comment.