diff --git a/configurationapp/src/main/java/com/att/ConfigurationApp.java b/configurationapp/src/main/java/com/att/ConfigurationApp.java index 1ea7d60..1d9a7dc 100644 --- a/configurationapp/src/main/java/com/att/ConfigurationApp.java +++ b/configurationapp/src/main/java/com/att/ConfigurationApp.java @@ -3,10 +3,16 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +/** + * The main class of ConfigurationApp + * + * @author gayathri + * + */ @SpringBootApplication public class ConfigurationApp { - public static void main(String[] args) { - SpringApplication.run(ConfigurationApp.class, args); - } + public static void main(String[] args) { + SpringApplication.run(ConfigurationApp.class, args); + } } 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..a4be137 100644 --- a/configurationapp/src/main/java/com/att/dao/configurations/ConfigurationDao.java +++ b/configurationapp/src/main/java/com/att/dao/configurations/ConfigurationDao.java @@ -1,48 +1,195 @@ 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 java.util.Optional; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import com.att.data.configurations.ConfigValue; +/** + * The ConfigurationDao class is used to manage the month year wise + * configurations. + * + * @author gayathri + * + */ @Service public class ConfigurationDao { - private class IdProvider { - private int currentId; - public IdProvider() { - currentId = 0; - } + /** + * Simple Class to provide sequence id to configurations. + * + * @author gayathri + * + */ + private class IdProvider { + private int currentId; + + /** + * Constructor initialization with sequence to zero. + */ + public IdProvider() { + currentId = 0; + } - public int getNextId() { - return this.currentId++; - } - } + /** + * To get next sequence id for the configuration. + * + * @return next sequence id + */ + public int getNextId() { + return this.currentId++; + } + } - /** - * No DB, so store the configs in a map. - */ - private Map> currentConfigurations; - private IdProvider idProvider; + /** + * No DB, so store the configs in a map. + */ + private Map> currentConfigurations; + private IdProvider idProvider; + private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurationDao.class); - public ConfigurationDao() { - idProvider = new IdProvider(); - currentConfigurations = new HashMap<>(); - } + /** + * Initializing default constructor. + */ + public ConfigurationDao() { + idProvider = new IdProvider(); + currentConfigurations = new HashMap<>(); + } - public List getConfigurationsForYearMonth(String yearMonth) { - return new ArrayList<>(); - } + /** + * To get the configurations of the given month. + * + * @param yearMonth year month like 0520119 for May 2019. + * @return List + */ + public List getConfigurationsForYearMonth(String yearMonth) { + try { + LOGGER.debug("START : getConfigurationsForYearMonth(String) of " + this.getClass().getSimpleName()); + if (currentConfigurations != null && yearMonth != null && yearMonth.trim().length() > 0) { + List configurations = currentConfigurations.get(yearMonth); + if (configurations == null) { + configurations = new ArrayList(); + } + LOGGER.debug("STOP : getConfigurationsForYearMonth(String) of " + this.getClass().getSimpleName()); + return configurations; + } + } catch (Exception e) { + LOGGER.error("EXCEPTION : getConfigurationsForYearMonth(String) of " + this.getClass().getSimpleName()); + } + return new ArrayList(); + } - public void addConfiguration(String yearMonth, ConfigValue value) { - int newId = idProvider.getNextId(); + /** + * To add the new configuration for the given month year. + * + * @param yearMonth year month like 0520119 for May 2019. + * @param value Config Value to be added. + * @return result + */ + public String addConfiguration(String yearMonth, ConfigValue value) { + String result = "Oops! Something went wrong while adding new configuration."; + try { + LOGGER.debug("START : addConfiguration(String, ConfigValue) of " + this.getClass().getSimpleName()); + if (currentConfigurations != null && yearMonth != null && yearMonth.trim().length() > 0 && value != null) { + int newId = idProvider.getNextId(); + value.setConfigId(newId); - } + List configurations = currentConfigurations.get(yearMonth); + if (configurations == null) { + configurations = new ArrayList(); + configurations.add(value); + currentConfigurations.put(yearMonth, configurations); + result = "Given configuration has been successfully added for the selected month."; + } else { + Optional configValueOpt = configurations.stream().filter(configValueData -> { + return configValueData.getConfigName().equals(value.getConfigName()); + }).findFirst(); + if (configValueOpt.isPresent()) { + result = "Configuration with given name already exists for the selected month."; + } else { + configurations.add(value); + currentConfigurations.put(yearMonth, configurations); + result = "Given configuration has been successfully added for the selected month."; + } + } + } + LOGGER.debug("STOP : addConfiguration(String, ConfigValue) of " + this.getClass().getSimpleName()); + } catch (Exception e) { + LOGGER.error("EXCEPTION : addConfiguration(String, ConfigValue) of " + this.getClass().getSimpleName()); + } + return result; + } - public void removeAllConfigurationsForYearMonth(String yearMonth) { + /** + * To remove all the configuration for the given month year. + * + * @param yearMonth year month like 0520119 for May 2019. + * @return result + */ + public String removeAllConfigurationsForYearMonth(String yearMonth) { + String result = "Oops! Something went wrong while deleting the configurations for the selected month."; + try { + LOGGER.debug("START : removeAllConfigurationsForYearMonth(String) of " + this.getClass().getSimpleName()); + if (currentConfigurations != null && yearMonth != null && yearMonth.trim().length() > 0) { + List configValues = currentConfigurations.remove(yearMonth); + if (configValues != null && configValues.size() > 0) { + result = "All the configurtions for the selected month got deleted successfully."; + } else { + result = "Selected month don't have any configurtions asscoiated with it."; + } + } + LOGGER.debug("STOP : removeAllConfigurationsForYearMonth(String) of " + this.getClass().getSimpleName()); + } catch (Exception e) { + LOGGER.error( + "EXCEPTION : removeAllConfigurationsForYearMonth(String) of " + this.getClass().getSimpleName()); + } + return result; + } - } + /** + * To remove given configuration for the given month year based on config id. + * + * @param yearMonth year month like 0520119 for May 2019. + * @param value Config Value to be added. + */ + public String removeOneConfigForYearMonth(String yearMonth, Integer configId) { + boolean result = false; + String response = "Oops! Something went wrong while deleting the selected configuration for the selected month."; + try { + LOGGER.debug( + "START : removeOneConfigForYearMonth(String, ConfigValue) of " + this.getClass().getSimpleName()); + if (currentConfigurations != null && yearMonth != null && yearMonth.trim().length() > 0 && configId != null + && configId >= 0) { + List configurations = currentConfigurations.get(yearMonth); + if (configurations != null) { + for (int i = 0; i < configurations.size(); i++) { + ConfigValue listConfigValue = configurations.get(i); + if (listConfigValue.getConfigId() == configId) { + configurations.remove(i); + result = true; + break; + } + } + if (result == true) { + response = "Successfully deleted the selected configuration for the selected month."; + } else { + response = "The selected configuration is not found for the selected month."; + } + } + } + LOGGER.debug( + "STOP : removeOneConfigForYearMonth(String, ConfigValue) of " + this.getClass().getSimpleName()); + } catch (Exception e) { + LOGGER.error("EXCEPTION : removeOneConfigForYearMonth(String, ConfigValue) of " + + this.getClass().getSimpleName()); + } + return response; + } } 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..b26e1ff 100644 --- a/configurationapp/src/main/java/com/att/data/configurations/ConfigValue.java +++ b/configurationapp/src/main/java/com/att/data/configurations/ConfigValue.java @@ -1,34 +1,63 @@ package com.att.data.configurations; /** - * Data Model + * Data Model - Configuration Value */ public class ConfigValue { - private String configName; - private int configId; - - public ConfigValue(String name, int id) { - this.configId = id; - this.configName = name; - } - - public ConfigValue() { - - } - - public void setConfigName(String name) { - this.configName = name; - } - - public String getConfigName() { - return this.configName; - } - - public void setConfigId(int id) { - this.configId = id; - } - - public int getConfigId() { - return this.configId; - } + private String configName; + private int configId; + + /** + * Constructor initialization with all properties. + * + * @param name Configuration name + * @param id Configuration id + */ + public ConfigValue(String name, int id) { + this.configId = id; + this.configName = name; + } + + /** + * Default constructor. + */ + public ConfigValue() { + + } + + /** + * To set configuration name + * + * @param name configuration name + */ + public void setConfigName(String name) { + this.configName = name; + } + + /** + * To get configuration name + * + * @return configuration name + */ + public String getConfigName() { + return this.configName; + } + + /** + * To set configuration id. + * + * @param name configuration id + */ + public void setConfigId(int id) { + this.configId = id; + } + + /** + * To get configuration id + * + * @return configuration id + */ + public int getConfigId() { + return this.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..7128094 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,131 @@ package com.att.web.configuarations; -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; +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; + +/** + * The ConfigurationController class is used to manage the month year wise + * configurations. + * + * @author gayathri + * + */ @RestController -@RequestMapping(value="/configuration") +@RequestMapping(value = "/configuration") public class ConfigurationController { - private ConfigurationDao dao; - - @Autowired - public ConfigurationController(ConfigurationDao dao) { - this.dao = dao; - } + private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurationController.class); - @RequestMapping(value="/{yearMonthNumber}", method=RequestMethod.GET) - @ResponseBody - public List getConfigurationsForYearMonth( - @PathVariable("yearMonthNumber") String yearMonth) { + private ConfigurationDao dao; - return new ArrayList<>(); - } + @Autowired + public ConfigurationController(ConfigurationDao dao) { + this.dao = dao; + } - @RequestMapping(value="/{yearMonthNumber}", method=RequestMethod.DELETE) - public void deleteConfigurationsForYearMonth(@PathVariable("yearMonthNumber") String yearMonth) { - try { + /** + * This request mapping is used to get all the configurations for the given + * month. + * + * @param yearMonth year month like 0520119 for May 2019. + * @return List + */ + @RequestMapping(value = "/{yearMonthNumber}", method = RequestMethod.GET) + @ResponseBody + public List getConfigurationsForYearMonth(@PathVariable("yearMonthNumber") String yearMonth) { + List response = new ArrayList(); + try { + LOGGER.debug("START : GET : PATH - /{yearMonthNumber} of " + this.getClass().getSimpleName()); + response = dao.getConfigurationsForYearMonth(yearMonth); + LOGGER.debug("STOP : GET : PATH - /{yearMonthNumber} of " + this.getClass().getSimpleName()); + } catch (Exception e) { + LOGGER.error("EXCEPTION : GET : PATH - /{yearMonthNumber} of " + this.getClass().getSimpleName()); + } + return response; + } - } catch (Exception ex) { + /** + * This request mapping is used to delete all the configurations for the given + * month. + * + * @param yearMonth year month like 0520119 for May 2019. + * @return String formated JSON object response with msg key for status message. + */ + @RequestMapping(value = "/{yearMonthNumber}", method = RequestMethod.DELETE) + @ResponseBody + public String deleteConfigurationsForYearMonth(@PathVariable("yearMonthNumber") String yearMonth) { + String result = "Oops! Something went wrong while deleting the configuration for the selected month."; + try { + LOGGER.debug("START : DELETE : PATH - /{yearMonthNumber} of " + this.getClass().getSimpleName()); + result = dao.removeAllConfigurationsForYearMonth(yearMonth); + LOGGER.debug("STOP : DELETE : PATH - /{yearMonthNumber} of " + this.getClass().getSimpleName()); + } catch (Exception ex) { + LOGGER.error("EXCEPTION : DELETE : PATH - /{yearMonthNumber} of " + this.getClass().getSimpleName()); + } + return "{\"msg\":\"" + result + "\"}"; + } - } - } + /** + * This request mapping is used to add the given configuration for the given + * month. + * + * @param yearMonth year month like 0520119 for May 2019. + * @param value ConfigValue object to be added + * @return String formated JSON object response with msg key for status message. + */ + @RequestMapping(value = "/{yearMonthNumber}", method = { RequestMethod.POST, RequestMethod.PUT }) + @ResponseBody + public String addConfigurationForYearMonth(@PathVariable("yearMonthNumber") String yearMonth, + @RequestBody ConfigValue value) { + String result = "Oops! Something went wrong while adding new configuration."; + try { + LOGGER.debug("START : POST/PUT : PATH - /{yearMonthNumber} with Request Body of " + + this.getClass().getSimpleName()); + result = dao.addConfiguration(yearMonth, value); + LOGGER.debug("STOP : POST/PUT : PATH - /{yearMonthNumber} with Request Body of " + + this.getClass().getSimpleName()); + } catch (Exception e) { + LOGGER.error("EXCEPTION : POST/PUT : PATH - /{yearMonthNumber} with Request Body of " + + this.getClass().getSimpleName()); + } + return "{\"msg\":\"" + result + "\"}"; + } - @RequestMapping(value="/{yearMonthNumber}", method={ RequestMethod.POST, RequestMethod.PUT }) - public void addConfigurationForYearMonth( - @PathVariable("yearMonthNumber") String yearMonth, - @RequestBody ConfigValue value) { + /** + * This request mapping is used to add the given configuration for the given + * month. + * + * @param yearMonth year month like 0520119 for May 2019. + * @param configId Configuration Id to be deleted + * @return String formated JSON object response with msg key for status message. + */ + @RequestMapping(value = "/{yearMonthNumber}/{congigid}", method = RequestMethod.DELETE) + @ResponseBody + public String deleteOneConfigForYearMonth(@PathVariable("yearMonthNumber") String yearMonth, + @PathVariable("congigid") Integer configId) { + String response = "Oops! Something went wrong while deleting the selected configuration for the selected month."; + try { + LOGGER.debug("START : DELETE : PATH - /{yearMonthNumber}/{congigid} of " + this.getClass().getSimpleName()); + response = dao.removeOneConfigForYearMonth(yearMonth, configId); + LOGGER.debug("STOP : DELETE : PATH - /{yearMonthNumber}/{congigid} of " + this.getClass().getSimpleName()); + } catch (Exception e) { + LOGGER.error( + "EXCEPTION : DELETE : PATH - /{yearMonthNumber}/{congigid} of " + this.getClass().getSimpleName()); + } + return "{\"msg\":\"" + response + "\"}"; + } - } } diff --git a/configurationapp/src/main/resources/static/index.html b/configurationapp/src/main/resources/static/index.html index 7cd14ba..7acca28 100644 --- a/configurationapp/src/main/resources/static/index.html +++ b/configurationapp/src/main/resources/static/index.html @@ -1,47 +1,204 @@ - Configuration App - - - - +Configuration App + + + + -

Welcome To The Configuration App

-
-
- -
-
- - - - - - - - - - -
Configuration IdConfiguration Name
-
-
- -
-
- +

Welcome To The Configuration App

+
+
+ + +
+
+ + +
+
+ + + + + + + + + + +
Configuration IdConfiguration Name
+
+
+ + +
+
+ \ 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" }, + ], }); };