diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bc476b1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ + +configurationapp/.project +configurationapp/.classpath +configurationapp/target/classes/application.properties +configurationapp/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst +configurationapp/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst 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..1832b1c 100644 --- a/configurationapp/src/main/java/com/att/dao/configurations/ConfigurationDao.java +++ b/configurationapp/src/main/java/com/att/dao/configurations/ConfigurationDao.java @@ -1,13 +1,14 @@ package com.att.dao.configurations; -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 org.springframework.stereotype.Service; + +import com.att.data.configurations.ConfigValue; + @Service public class ConfigurationDao { private class IdProvider { @@ -34,15 +35,44 @@ public ConfigurationDao() { } public List getConfigurationsForYearMonth(String yearMonth) { - return new ArrayList<>(); + List configForDate = currentConfigurations.get(yearMonth); + if (configForDate == null) { + configForDate = new ArrayList(); + } + + return configForDate; } public void addConfiguration(String yearMonth, ConfigValue value) { int newId = idProvider.getNextId(); - + value.setConfigId(newId); + + List configForDate = currentConfigurations.get(yearMonth); + if (configForDate == null) { + configForDate = new ArrayList(); + } + configForDate.add(value); + currentConfigurations.put(yearMonth, configForDate); } public void removeAllConfigurationsForYearMonth(String yearMonth) { - + currentConfigurations.remove(yearMonth); + } + + public boolean deleteOneConfigForYearMonth(String yearMonth, ConfigValue value) { + boolean result = false; + List allConfigs4Date = currentConfigurations.get(yearMonth); + if (allConfigs4Date != null) { + for (int i = 0; i < allConfigs4Date.size(); i++) { + ConfigValue listConfigValue = allConfigs4Date.get(i); + if (listConfigValue.getConfigId() == value.getConfigId()) { + allConfigs4Date.remove(i); + result = true; + break; + } + } + } + + return result; } } diff --git a/configurationapp/src/main/java/com/att/data/configurations/ConfigValue.java b/configurationapp/src/main/java/com/att/data/configurations/ConfigValue.java index 55339a3..0ede4ae 100644 --- a/configurationapp/src/main/java/com/att/data/configurations/ConfigValue.java +++ b/configurationapp/src/main/java/com/att/data/configurations/ConfigValue.java @@ -4,7 +4,7 @@ * Data Model */ public class ConfigValue { - private String configName; + private String configName; private int configId; public ConfigValue(String name, int id) { @@ -31,4 +31,10 @@ public void setConfigId(int id) { public int getConfigId() { return this.configId; } + + @Override + public String toString() { + return "ConfigValue [configName=" + configName + ", configId=" + configId + "]"; + } + } 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..40b7a06 100644 --- a/configurationapp/src/main/java/com/att/web/configuarations/ConfigurationController.java +++ b/configurationapp/src/main/java/com/att/web/configuarations/ConfigurationController.java @@ -1,45 +1,77 @@ package com.att.web.configuarations; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + import com.att.dao.configurations.ConfigurationDao; import com.att.data.configurations.ConfigValue; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; -import java.util.ArrayList; -import java.util.List; @RestController @RequestMapping(value="/configuration") public class ConfigurationController { + private static final Logger log = LoggerFactory.getLogger(ConfigurationController.class); + private ConfigurationDao dao; @Autowired public ConfigurationController(ConfigurationDao dao) { this.dao = dao; } - - @RequestMapping(value="/{yearMonthNumber}", method=RequestMethod.GET) + + @RequestMapping(value="/getConfigurationsForYearMonth/{yearMonthNumber}", method=RequestMethod.GET) @ResponseBody - public List getConfigurationsForYearMonth( - @PathVariable("yearMonthNumber") String yearMonth) { - - return new ArrayList<>(); + public List getConfigurationsForYearMonth(@PathVariable("yearMonthNumber") String yearMonth) { + + log.debug("In getConfigurationsForYearMonth with " + yearMonth); + + return dao.getConfigurationsForYearMonth(yearMonth); } - - @RequestMapping(value="/{yearMonthNumber}", method=RequestMethod.DELETE) - public void deleteConfigurationsForYearMonth(@PathVariable("yearMonthNumber") String yearMonth) { + + @RequestMapping(value="deleteConfigurationsForYearMonth/{yearMonthNumber}", method=RequestMethod.DELETE) + public boolean deleteConfigurationsForYearMonth(@PathVariable("yearMonthNumber") String yearMonth) { + //Not sure why you have exception block here, but minimally need to log an exception when it is caught try { - + log.debug("In deleteConfigurationsForYearMonth " + yearMonth); + dao.removeAllConfigurationsForYearMonth(yearMonth); + return true; } catch (Exception ex) { - + log.error("Exception while deleteConfigurationsForYearMonth for" + yearMonth); + return false; } } - - @RequestMapping(value="/{yearMonthNumber}", method={ RequestMethod.POST, RequestMethod.PUT }) - public void addConfigurationForYearMonth( + + @RequestMapping(value="/addConfigurationForYearMonth/{yearMonthNumber}", method={ RequestMethod.POST, RequestMethod.PUT }) + public boolean addConfigurationForYearMonth( @PathVariable("yearMonthNumber") String yearMonth, @RequestBody ConfigValue value) { + log.debug("In addConfigurationForYearMonth " + yearMonth); + log.debug(value.toString()); + + dao.addConfiguration(yearMonth, value); + + return true; + } + + @RequestMapping(value="deleteOneConfigForYearMonth/{yearMonthNumber}", method=RequestMethod.DELETE) + public boolean deleteOneConfigForYearMonth( + @PathVariable("yearMonthNumber") String yearMonth, + @RequestBody ConfigValue value) { + + log.debug("In deleteOneConfigForYearMonth " + yearMonth); + log.debug(value.toString()); + return dao.deleteOneConfigForYearMonth(yearMonth, value); } + } diff --git a/configurationapp/src/main/resources/application.properties b/configurationapp/src/main/resources/application.properties index 6c77a8e..104cc30 100644 --- a/configurationapp/src/main/resources/application.properties +++ b/configurationapp/src/main/resources/application.properties @@ -1,6 +1,6 @@ server.port=9000 spring.mvc.favicon.enabled=false -logging.level.root=WARN +logging.level.root=DEBUG logging.level.org.springframework.web=DEBUG logging.level.org.hibernate=ERROR \ No newline at end of file diff --git a/configurationapp/src/main/resources/static/index.html b/configurationapp/src/main/resources/static/index.html index 7cd14ba..7d8ae49 100644 --- a/configurationapp/src/main/resources/static/index.html +++ b/configurationapp/src/main/resources/static/index.html @@ -2,7 +2,7 @@ Configuration App - + @@ -21,6 +21,10 @@

Welcome To The Configuration App

+
+ + +
@@ -36,12 +40,140 @@

Welcome To The Configuration App

+ +
\ No newline at end of file diff --git a/configurationapp/src/main/resources/static/js/app.js b/configurationapp/src/main/resources/static/js/app.js index 2d4b945..eaeeda7 100644 --- a/configurationapp/src/main/resources/static/js/app.js +++ b/configurationapp/src/main/resources/static/js/app.js @@ -15,9 +15,15 @@ $('#configTable').DataTable({ scrollY: 300, paging: false, - sorting: false, + sorting: true, + ordering: true, + order: [], searching: false, - info: false + info: false, + columns: [ + { "data": "configId" }, + { "data": "configName" }, + ], }); }; diff --git a/configurationapp/target/classes/.gitignore b/configurationapp/target/classes/.gitignore new file mode 100644 index 0000000..2af1cab --- /dev/null +++ b/configurationapp/target/classes/.gitignore @@ -0,0 +1,2 @@ +/com/ +/static/