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..1c7f470 100644 --- a/configurationapp/src/main/java/com/att/dao/configurations/ConfigurationDao.java +++ b/configurationapp/src/main/java/com/att/dao/configurations/ConfigurationDao.java @@ -1,12 +1,16 @@ package com.att.dao.configurations; import com.att.data.configurations.ConfigValue; +//import java.awt.List; +import com.sun.org.apache.xpath.internal.operations.And; +import javax.print.attribute.HashAttributeSet; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Iterator; @Service public class ConfigurationDao { @@ -34,15 +38,53 @@ public ConfigurationDao() { } public List getConfigurationsForYearMonth(String yearMonth) { - return new ArrayList<>(); + List list = new ArrayList(); + + if(currentConfigurations.containsKey(yearMonth)) + { + return currentConfigurations.get(yearMonth); + } + return new ArrayList<>(); } - public void addConfiguration(String yearMonth, ConfigValue value) { + public int addConfiguration(String yearMonth, ConfigValue value) { int newId = idProvider.getNextId(); - + value.setConfigId(newId); + List list = new ArrayList(); + if (currentConfigurations.containsKey(yearMonth)) { + list = currentConfigurations.get(yearMonth); + list.add(value); + } else { + list.add(value); + } + currentConfigurations.put(yearMonth,list); + return newId; } public void removeAllConfigurationsForYearMonth(String yearMonth) { + currentConfigurations.remove(yearMonth); + } + public void removeConfigurationsForYearMonth(String yearMonth, ConfigValue value) { + List list = new ArrayList(); + if (currentConfigurations.containsKey(yearMonth)) { + list = currentConfigurations.get(yearMonth); + Iterator iterator = list.iterator(); + List listAfter = new ArrayList<>(); + while(iterator.hasNext()) { + ConfigValue next = iterator.next(); + if(next.getConfigId() == value.getConfigId() && + next.getConfigName().equals(value.getConfigName())) { + + } else { + listAfter.add(next); + } + } + + currentConfigurations.remove(yearMonth); + currentConfigurations.put(yearMonth,listAfter); + } } + + } 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..087c948 100644 --- a/configurationapp/src/main/java/com/att/web/configuarations/ConfigurationController.java +++ b/configurationapp/src/main/java/com/att/web/configuarations/ConfigurationController.java @@ -2,6 +2,7 @@ import com.att.dao.configurations.ConfigurationDao; import com.att.data.configurations.ConfigValue; +import java.io.Console; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -19,27 +20,36 @@ public ConfigurationController(ConfigurationDao dao) { this.dao = dao; } - @RequestMapping(value="/{yearMonthNumber}", method=RequestMethod.GET) - @ResponseBody - public List getConfigurationsForYearMonth( - @PathVariable("yearMonthNumber") String yearMonth) { + @RequestMapping(value="/getConfigurationsForYearMonth/{yearMonth}", method=RequestMethod.GET) + public List getConfigurationsForYearMonth( + @PathVariable("yearMonth") String yearMonth) { - return new ArrayList<>(); - } - - @RequestMapping(value="/{yearMonthNumber}", method=RequestMethod.DELETE) - public void deleteConfigurationsForYearMonth(@PathVariable("yearMonthNumber") String yearMonth) { - try { - - } catch (Exception ex) { + List getConfigValue = dao.getConfigurationsForYearMonth(yearMonth); + return getConfigValue; + } + + @RequestMapping(value="/deleteConfigurationsForYearMonth/{yearMonthNumber}/{deleteAll}", method=RequestMethod.DELETE) + public void deleteConfigurationsForYearMonth( + @PathVariable("deleteAll") Boolean deleteAll, + @PathVariable("yearMonthNumber") String yearMonth, + @RequestBody ConfigValue configValueIn) { + + if (deleteAll) { + try { + dao.removeAllConfigurationsForYearMonth(yearMonth); + } catch (Exception ex) { + + } + } else { + dao.removeConfigurationsForYearMonth(yearMonth,configValueIn); } } - @RequestMapping(value="/{yearMonthNumber}", method={ RequestMethod.POST, RequestMethod.PUT }) - public void addConfigurationForYearMonth( + @RequestMapping(value="/addConfigurationForYearMonth/{yearMonthNumber}", method={ RequestMethod.POST, RequestMethod.PUT }) + public int addConfigurationForYearMonth( @PathVariable("yearMonthNumber") String yearMonth, - @RequestBody ConfigValue value) { - + @RequestBody ConfigValue configValueIn) { + return(dao.addConfiguration(yearMonth, configValueIn)); } } diff --git a/configurationapp/src/main/resources/static/index.html b/configurationapp/src/main/resources/static/index.html index 7cd14ba..77d1c91 100644 --- a/configurationapp/src/main/resources/static/index.html +++ b/configurationapp/src/main/resources/static/index.html @@ -2,7 +2,8 @@ Configuration App - + > + @@ -27,15 +28,21 @@

Welcome To The Configuration App

Configuration Id Configuration Name + - +
+ +
+
+ +