diff options
author | Kevin Smokowski <ks6305@att.com> | 2018-02-23 18:09:55 +0000 |
---|---|---|
committer | Timoney, Dan (dt5972) <dt5972@att.com> | 2018-03-02 15:19:35 -0500 |
commit | 7d82b39d7007df02bdd050ed1d46111d29fa6ade (patch) | |
tree | 77239c3d9f90f04af2fc4773f6e81d9dc36f3a60 /sli/common | |
parent | d873c2251b596c5dc15c0899b22ea0b7fdd6a286 (diff) |
Favor interfaces
Favor using interfaces over concrete implementations
Change-Id: Ie7541eeefa69671cc7ed39fba37fdd2e24380770
Issue-ID: CCSDK-189
Signed-off-by: Kevin Smokowski <ks6305@att.com>
Favor interfaces
Favor using interfaces over concrete implementations
Change-Id: Ie3b71833c0f31f67288430c25ca31ca07c0449e0
Issue-ID: CCSDK-189
Signed-off-by: Kevin Smokowski <ks6305@att.com>
Diffstat (limited to 'sli/common')
-rwxr-xr-x | sli/common/src/main/antlr4/org/onap/ccsdk/sli/core/sli/ExprGrammar.g4 | 2 | ||||
-rw-r--r-- | sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicLoader.java | 212 |
2 files changed, 105 insertions, 109 deletions
diff --git a/sli/common/src/main/antlr4/org/onap/ccsdk/sli/core/sli/ExprGrammar.g4 b/sli/common/src/main/antlr4/org/onap/ccsdk/sli/core/sli/ExprGrammar.g4 index 1b026bb1..42563168 100755 --- a/sli/common/src/main/antlr4/org/onap/ccsdk/sli/core/sli/ExprGrammar.g4 +++ b/sli/common/src/main/antlr4/org/onap/ccsdk/sli/core/sli/ExprGrammar.g4 @@ -16,7 +16,7 @@ MULTOP : '/' | '*'; NUMBER : ('0'..'9')+; -STRING : '\'' ~[\']* '\''; +STRING : '\'' ~[']* '\''; IDENTIFIER : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_'|'-')*; diff --git a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicLoader.java b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicLoader.java index bc8c1bdf..95f73f96 100644 --- a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicLoader.java +++ b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicLoader.java @@ -32,137 +32,133 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedList; import java.util.List; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class SvcLogicLoader { - private static final Logger LOGGER = LoggerFactory.getLogger(SvcLogicLoader.class); - SvcLogicStore store; - String directoryRoot; - String propFile; - - public SvcLogicLoader(String directoryRoot, String propFile) { - store = SvcLogicParser.getStore(propFile); - this.directoryRoot = directoryRoot; - this.propFile = propFile; - } - - public void loadAndActivate() throws IOException { - SvcLogicCrawler slc = new SvcLogicCrawler(); - Files.walkFileTree(Paths.get(this.directoryRoot), slc); - - loadGraphs(slc.getGraphPaths(), directoryRoot); - - List<ActivationEntry> activationEntries = processActivationFiles(slc.getActivationPaths()); - activateGraphs(activationEntries); - } - - private List<ActivationEntry> processActivationFiles(List<Path> activationPaths) { - List<ActivationEntry> activationEntries = new ArrayList<ActivationEntry>(); - for (Path activationFile : activationPaths) { - activationEntries.addAll(getActivationEntries(activationFile)); + private static final Logger LOGGER = LoggerFactory.getLogger(SvcLogicLoader.class); + protected SvcLogicStore store; + protected String directoryRoot; + + public SvcLogicLoader(String directoryRoot, SvcLogicStore store) { + this.store = store; + this.directoryRoot = directoryRoot; } - return activationEntries; - } + public SvcLogicLoader(String directoryRoot, String propFile) { + this.store = SvcLogicParser.getStore(propFile); + this.directoryRoot = directoryRoot; + } - private void activateGraphs(List<ActivationEntry> activationEntries) { - for (ActivationEntry entry : activationEntries) { - try { - if (store.hasGraph(entry.module, entry.rpc, entry.version, entry.mode)) { - store.activate(entry.module, entry.rpc, entry.version, entry.mode); - } else { - LOGGER.error("hasGraph returned false for " + entry.toString()); - } - } catch (SvcLogicException e) { - LOGGER.error("Failed to call hasGraph for " + entry.toString(), e); - } + public void loadAndActivate() throws IOException { + SvcLogicCrawler slc = new SvcLogicCrawler(); + Files.walkFileTree(Paths.get(directoryRoot), slc); + loadGraphs(slc.getGraphPaths(), directoryRoot); + List<ActivationEntry> activationEntries = processActivationFiles(slc.getActivationPaths()); + activateGraphs(activationEntries); } - } - - protected List<ActivationEntry> getActivationEntries(Path activationFilePath) { - List<ActivationEntry> activationEntries = new ArrayList<>(); - int lineNumber = 1; - try (BufferedReader br = Files.newBufferedReader(activationFilePath, StandardCharsets.US_ASCII)) { - String fileRead = br.readLine(); - while (fileRead != null) { - String[] fields = fileRead.split("\\s"); - if (fields.length == 4) { - activationEntries.add(parseActivationEntry(fields)); - } else { - LOGGER.error("Activation entry [" + fileRead + "] is declared at line number " + lineNumber + " in the file " + activationFilePath + " and is invalid."); + + private List<ActivationEntry> processActivationFiles(List<Path> activationPaths) { + List<ActivationEntry> activationEntries = new ArrayList<ActivationEntry>(); + for (Path activationFile : activationPaths) { + activationEntries.addAll(getActivationEntries(activationFile)); } - fileRead = br.readLine(); - lineNumber++; - } - return activationEntries; - } catch (IOException ioe) { - LOGGER.error("Couldn't read the activation file at " + activationFilePath, ioe); - return null; - } - } - - protected void loadGraphs(List<Path> graphPaths, String directoryRoot) { - for (Path graphPath : graphPaths) { - try { - saveGraph(graphPath.toString()); - } catch (Exception e) { - LOGGER.error("Couldn't load graph at " + graphPath, e); - } + return activationEntries; } - } - private void saveGraph(String xmlFile) throws SvcLogicException { - File f = new File(xmlFile); - if (!f.canRead()) { - throw new ConfigurationException("Cannot read xml file (" + xmlFile + ")"); + private void activateGraphs(List<ActivationEntry> activationEntries) { + for (ActivationEntry entry : activationEntries) { + try { + if (store.hasGraph(entry.module, entry.rpc, entry.version, entry.mode)) { + store.activate(entry.module, entry.rpc, entry.version, entry.mode); + } else { + LOGGER.error("hasGraph returned false for " + entry.toString()); + } + } catch (SvcLogicException e) { + LOGGER.error("Failed to call hasGraph for " + entry.toString(), e); + } + } } - SvcLogicParser parser = new SvcLogicParser(); - LinkedList<SvcLogicGraph> graphs = null; - - try { - graphs = parser.parse(xmlFile); - } catch (Exception e) { - throw new SvcLogicException(e.getMessage(), e); + protected List<ActivationEntry> getActivationEntries(Path activationFilePath) { + List<ActivationEntry> activationEntries = new ArrayList<>(); + int lineNumber = 1; + try (BufferedReader br = Files.newBufferedReader(activationFilePath, StandardCharsets.US_ASCII)) { + String fileRead = br.readLine(); + while (fileRead != null) { + String[] fields = fileRead.split("\\s"); + if (fields.length == 4) { + activationEntries.add(parseActivationEntry(fields)); + } else { + LOGGER.error("Activation entry [" + fileRead + "] is declared at line number " + lineNumber + + " in the file " + activationFilePath + " and is invalid."); + } + fileRead = br.readLine(); + lineNumber++; + } + return activationEntries; + } catch (IOException ioe) { + LOGGER.error("Couldn't read the activation file at " + activationFilePath, ioe); + return null; + } } - if (graphs == null) { - throw new SvcLogicException("Could not parse " + xmlFile); + protected void loadGraphs(List<Path> graphPaths, String directoryRoot) { + for (Path graphPath : graphPaths) { + try { + saveGraph(graphPath.toString()); + } catch (Exception e) { + LOGGER.error("Couldn't load graph at " + graphPath, e); + } + } } - for (Iterator<SvcLogicGraph> iter = graphs.iterator(); iter.hasNext();) { - - SvcLogicGraph graph = iter.next(); + private void saveGraph(String xmlFile) throws SvcLogicException { + File f = new File(xmlFile); + if (!f.canRead()) { + throw new ConfigurationException("Cannot read xml file (" + xmlFile + ")"); + } - try { - LOGGER.info("Saving " + graph.toString() + " to database"); - store.store(graph); - } catch (Exception e) { - throw new SvcLogicException(e.getMessage(), e); - } + SvcLogicParser parser = new SvcLogicParser(); + LinkedList<SvcLogicGraph> graphs = null; - } - } + try { + graphs = parser.parse(xmlFile); + } catch (Exception e) { + throw new SvcLogicException(e.getMessage(), e); + } - protected ActivationEntry parseActivationEntry(String[] fileInput) { - return new ActivationEntry(fileInput[0], fileInput[1], fileInput[2], fileInput[3]); - } + if (graphs == null) { + throw new SvcLogicException("Could not parse " + xmlFile); + } - protected String getValue(String raw, String attributeName) { - raw = raw.substring(attributeName.length() + 1); - if (raw.contains(">")) { - raw = raw.substring(0, raw.lastIndexOf('>')); - } - if (raw.endsWith("'")) { - raw = raw.substring(0, raw.lastIndexOf('\'')); + for (Iterator<SvcLogicGraph> iter = graphs.iterator(); iter.hasNext();) { + SvcLogicGraph graph = iter.next(); + try { + LOGGER.info("Saving " + graph.toString() + " to database"); + store.store(graph); + } catch (Exception e) { + throw new SvcLogicException(e.getMessage(), e); + } + } } - if (raw.endsWith("\"")) { - raw = raw.substring(0, raw.lastIndexOf('"')); + + protected ActivationEntry parseActivationEntry(String[] fileInput) { + return new ActivationEntry(fileInput[0], fileInput[1], fileInput[2], fileInput[3]); } - return raw; - } + protected String getValue(String raw, String attributeName) { + raw = raw.substring(attributeName.length() + 1); + if (raw.contains(">")) { + raw = raw.substring(0, raw.lastIndexOf('>')); + } + if (raw.endsWith("'")) { + raw = raw.substring(0, raw.lastIndexOf('\'')); + } + if (raw.endsWith("\"")) { + raw = raw.substring(0, raw.lastIndexOf('"')); + } + return raw; + } } |