Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package com.att.dao.configurations;

import com.att.data.configurations.ConfigValue;
import com.att.web.configuarations.ConfigurationController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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 {
private static final Logger logger = LoggerFactory.getLogger(ConfigurationDao.class);

private class IdProvider {
private int currentId;

Expand All @@ -33,16 +35,72 @@ public ConfigurationDao() {
currentConfigurations = new HashMap<>();
}

public void addConfigurationforYearMonth(String yearMonth, ConfigValue value) {
try {
if (value != null && !isNullOrEmpty(yearMonth)) {
value.setConfigId(idProvider.getNextId());

List<ConfigValue> configurationList = currentConfigurations.get(yearMonth);
if (isConfigExist(yearMonth)) {
Optional<ConfigValue> existingConfigValue = configurationList
.stream()
.filter(data -> data.getConfigName().equals(value.getConfigName()))
.findFirst();

if (!existingConfigValue.isPresent()) {
configurationList.add(value);
currentConfigurations.put(yearMonth, configurationList);
}
} else {
configurationList = new ArrayList<ConfigValue>();
configurationList.add(value);
currentConfigurations.put(yearMonth, configurationList);
}
}
} catch (Exception e) {
logger.error("Exception adding configuration for selected year and month. " + e.getMessage());
}
}


public List<ConfigValue> getConfigurationsForYearMonth(String yearMonth) {
try {
if (isConfigExist(yearMonth) && !isNullOrEmpty(yearMonth)) {
return currentConfigurations.get(yearMonth);
}
} catch (Exception e) {
logger.error("Error fetching configurations for selected year and month. " + e.getMessage());
}
return new ArrayList<>();
}

public void addConfiguration(String yearMonth, ConfigValue value) {
int newId = idProvider.getNextId();

public void deleteAllConfigurationsForYearMonth(String yearMonth) {

try {
if (!isNullOrEmpty(yearMonth)) {
currentConfigurations.remove(yearMonth);
}
} catch (Exception e) {
logger.error("Error deleting config for year and month " + e.getMessage());
}
}

public void removeAllConfigurationsForYearMonth(String yearMonth) {
public void deleteSelectedConfigForYearMonth(String yearMonth, int configId) {
try {
if (!isNullOrEmpty(yearMonth) && isConfigExist(yearMonth)) {
currentConfigurations.get(yearMonth).removeIf(it -> it.getConfigId() == configId);
}
} catch (Exception e) {
logger.error("Error deleting selected config for year and month. " + e.getMessage());
}
}

public static boolean isNullOrEmpty(String str) {
return !(str != null && !str.trim().isEmpty());
}

private boolean isConfigExist(String key) {
return currentConfigurations.containsKey(key);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,76 @@

import com.att.dao.configurations.ConfigurationDao;
import com.att.data.configurations.ConfigValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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")
@RequestMapping(value = "/configuration")
public class ConfigurationController {

private ConfigurationDao dao;
private static final Logger logger = LoggerFactory.getLogger(ConfigurationController.class);


@Autowired
public ConfigurationController(ConfigurationDao dao) {
this.dao = dao;
}

@RequestMapping(value="/{yearMonthNumber}", method=RequestMethod.GET)
@RequestMapping(value = "/{yearMonthNumber}", method = RequestMethod.GET)
@ResponseBody
public List<ConfigValue> getConfigurationsForYearMonth(
@PathVariable("yearMonthNumber") String yearMonth) {

return new ArrayList<>();
List<ConfigValue> response = new ArrayList<ConfigValue>();
try {
logger.debug("Fetching configuration for year month : ${yearMonth}");
response = dao.getConfigurationsForYearMonth(yearMonth);
} catch (Exception e) {
logger.error("Error fetching configuration for year month : ${yearMonth}. :: " + this.getClass().getName());
}
return response;
}

@RequestMapping(value="/{yearMonthNumber}", method=RequestMethod.DELETE)
@RequestMapping(value = "/{yearMonthNumber}", method = RequestMethod.DELETE)
public void deleteConfigurationsForYearMonth(@PathVariable("yearMonthNumber") String yearMonth) {
try {
logger.debug("Deleting configuration for year month : ${yearMonth}");

dao.deleteAllConfigurationsForYearMonth(yearMonth);
} catch (Exception ex) {
logger.error("Error deleting configurations for selected year and month. Class :: " + this.getClass().getName());
}
}

@RequestMapping(value = "/{yearMonthNumber}/{configId}", method = RequestMethod.DELETE)
public void deleteSelectedConfigForYearMonth(@PathVariable("yearMonthNumber") String yearMonth,
@PathVariable("configId") Integer configId) {
try {
logger.debug("Deleting selected configuration for year month : ${yearMonth}");
dao.deleteSelectedConfigForYearMonth(yearMonth, configId);
} catch (Exception e) {
logger.error("Error deleting selected config for year and month. :: " + this.getClass().getName());
}
}

@RequestMapping(value="/{yearMonthNumber}", method={ RequestMethod.POST, RequestMethod.PUT })
@RequestMapping(value = "/{yearMonthNumber}", method = {RequestMethod.POST})
public void addConfigurationForYearMonth(
@PathVariable("yearMonthNumber") String yearMonth,
@RequestBody ConfigValue value) {

try {
logger.debug("Adding configuration for selected year and month : ${yearMonth}");
dao.addConfigurationforYearMonth(yearMonth, value);
} catch (Exception e) {
logger.error("Error adding configuration for ${yearMonth}. :: " + this.getClass().getName());
}


}
}
16 changes: 15 additions & 1 deletion configurationapp/src/main/resources/static/css/main.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.controls {

padding-bottom: 10px;
}

.config-table-wrapper {
Expand All @@ -8,4 +8,18 @@

.content {

}

table, td, th {
border: 1px solid #ddd;
text-align: left;
}

table {
border-collapse: collapse;
width: 100%;
}

th, td {
padding: 15px;
}
91 changes: 56 additions & 35 deletions configurationapp/src/main/resources/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,67 @@
<html>
<head>
<title>Configuration App</title>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script src="js/app.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" />
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css"/>
<link rel="stylesheet" href="css/main.css"/>
</head>
<body>
<h1>Welcome To The Configuration App</h1>
<div class="content">
<div class="controls">
<select id="timePeriod">
<option value="012018">Jan 2018</option>
<option value="022018">Feb 2018</option>
<option value="032018">Mar 2018</option>
<option value="042018">Apr 2018</option>
<option value="052018">May 2018</option>
<option value="062018">Jun 2018</option>
<option value="072018">Jul 2018</option>
</select>
</div>
<div class="config-table-wrapper">
<table id="configTable">
<thead>
<tr>
<td>Configuration Id</td>
<td>Configuration Name</td>
</tr>
</thead>
<tbody>
<h1>Welcome To The Configuration App</h1>
<div class="content">
<div class="controls">
<select id="timePeriod">
<option value="012018">Jan 2018</option>
<option value="022018">Feb 2018</option>
<option value="032018">Mar 2018</option>
<option value="042018">Apr 2018</option>
<option value="052018">May 2018</option>
<option value="062018">Jun 2018</option>
<option value="072018">Jul 2018</option>
</select>
</div>
<div class="controls">
<label class="">Add Configuration:</label>
<input type="text" id="newConfigName">
<button id="saveButton">Save</button>
</div>
<div class="config-table-wrapper">
<table id="configTable">
<thead>
<tr>
<td>Configuration Id</td>
<td>Configuration Name</td>
<td>Action</td>
</tr>
</thead>
<tbody>

</tbody>
</table>
</div>
<div class="controls">
<button id="saveButton">Save Configurations</button>
</div>
</tbody>
</table>
</div>
<script>
$(document).ready(function() {
app.init();
})
</script>
<div class="controls">
<button id="deleteAllForMonthYearButton">Delete All Configurations </button>
</div>
</div>
<script>
$(document).ready(function () {
app.init();

$('#timePeriod').change(function () {
$('#newConfigName').val('');
getConfigMonthYear();
});

$('#saveButton').click(function () {
addNewConfigurationForYearMonth();
});

$('#deleteAllForMonthYearButton').click(function () {
deleteAllConfigForMonthYear();
});
});

</script>
</body>
</html>
Loading