diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3dc211b --- /dev/null +++ b/.gitignore @@ -0,0 +1,22 @@ + +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties + +# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored) +!/.mvn/wrapper/maven-wrapper.jar + +# Ignore all IntelliJ Idea files +.idea/ +out/ +*.iws +*.iml +*.ipr + +untracked/ diff --git a/configurationapp/src/main/java/com/att/dao/configurations/ConfigurationDao.java b/configurationapp/src/main/java/com/att/dao/configurations/ConfigurationDao.java index f889558..2545753 100644 --- a/configurationapp/src/main/java/com/att/dao/configurations/ConfigurationDao.java +++ b/configurationapp/src/main/java/com/att/dao/configurations/ConfigurationDao.java @@ -3,10 +3,7 @@ import com.att.data.configurations.ConfigValue; import org.springframework.stereotype.Service; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; @Service public class ConfigurationDao { @@ -25,24 +22,65 @@ public int getNextId() { /** * No DB, so store the configs in a map. */ - private Map> currentConfigurations; - private IdProvider idProvider; + private final Map> currentConfigurations; + private final Map allConfigValues; + private final IdProvider idProvider; public ConfigurationDao() { idProvider = new IdProvider(); + // Acknowledging that configurations are different subsets over the same universe of config values + allConfigValues = new HashMap<>(); + createConfigValue("A"); + createConfigValue("B"); + createConfigValue("C"); + createConfigValue("D"); + createConfigValue("E"); + createConfigValue("F"); + createConfigValue("G"); + createConfigValue("H"); currentConfigurations = new HashMap<>(); + ArrayList configValues = new ArrayList<>(); + configValues.add(allConfigValues.get(0)); + configValues.add(allConfigValues.get(1)); + configValues.add(allConfigValues.get(2)); + configValues.add(allConfigValues.get(3)); + currentConfigurations.put("012018", configValues); + configValues = new ArrayList<>(); + configValues.add(allConfigValues.get(0)); + configValues.add(allConfigValues.get(2)); + configValues.add(allConfigValues.get(5)); + configValues.add(allConfigValues.get(6)); + configValues.add(allConfigValues.get(7)); + currentConfigurations.put("022018", configValues); } public List getConfigurationsForYearMonth(String yearMonth) { - return new ArrayList<>(); + List result = currentConfigurations.get(yearMonth); + if (result == null) { + return new ArrayList<>(); + } + return result; } - public void addConfiguration(String yearMonth, ConfigValue value) { - int newId = idProvider.getNextId(); - + public void addConfiguration(String yearMonth, ConfigValue prototype) { + ConfigValue newValue = createConfigValue(prototype.getConfigName()); + List values = currentConfigurations.get(yearMonth); + if (values == null) { + values = new ArrayList<>(); + currentConfigurations.put(yearMonth, values); + } + values.add(newValue); } public void removeAllConfigurationsForYearMonth(String yearMonth) { + currentConfigurations.remove(yearMonth); + } + private ConfigValue createConfigValue(String name) { + int id = idProvider.getNextId(); + ConfigValue cv = new ConfigValue(name, id); + allConfigValues.put(id, cv); + return cv; } + } diff --git a/configurationapp/src/main/java/com/att/web/configuarations/ConfigurationController.java b/configurationapp/src/main/java/com/att/web/configuarations/ConfigurationController.java index 995402a..ec95937 100644 --- a/configurationapp/src/main/java/com/att/web/configuarations/ConfigurationController.java +++ b/configurationapp/src/main/java/com/att/web/configuarations/ConfigurationController.java @@ -22,24 +22,21 @@ public ConfigurationController(ConfigurationDao dao) { @RequestMapping(value="/{yearMonthNumber}", method=RequestMethod.GET) @ResponseBody public List getConfigurationsForYearMonth( - @PathVariable("yearMonthNumber") String yearMonth) { - - return new ArrayList<>(); + @PathVariable("yearMonthNumber") String yearMonth) + { + return dao.getConfigurationsForYearMonth(yearMonth); } @RequestMapping(value="/{yearMonthNumber}", method=RequestMethod.DELETE) public void deleteConfigurationsForYearMonth(@PathVariable("yearMonthNumber") String yearMonth) { - try { - - } catch (Exception ex) { - - } + dao.removeAllConfigurationsForYearMonth(yearMonth); } @RequestMapping(value="/{yearMonthNumber}", method={ RequestMethod.POST, RequestMethod.PUT }) public void addConfigurationForYearMonth( @PathVariable("yearMonthNumber") String yearMonth, - @RequestBody ConfigValue value) { - + @RequestBody ConfigValue value) + { + dao.addConfiguration(yearMonth, value); } } diff --git a/configurationapp/src/main/resources/static/index.html b/configurationapp/src/main/resources/static/index.html index 7cd14ba..81fcdb6 100644 --- a/configurationapp/src/main/resources/static/index.html +++ b/configurationapp/src/main/resources/static/index.html @@ -2,7 +2,7 @@ Configuration App - + @@ -35,7 +35,9 @@

Welcome To The Configuration App

- + + +