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
Expand Up @@ -7,6 +7,7 @@
public class ConfigurationApp {

public static void main(String[] args) {

SpringApplication.run(ConfigurationApp.class, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -34,15 +31,24 @@ public ConfigurationDao() {
}

public List<ConfigValue> getConfigurationsForYearMonth(String yearMonth) {
return new ArrayList<>();
if(null == currentConfigurations.get(yearMonth)) {
return new ArrayList<>();
}
return currentConfigurations.get(yearMonth);
}

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

List<ConfigValue> adding = new ArrayList<>();
if(currentConfigurations.containsKey(yearMonth)) {
adding = currentConfigurations.get(yearMonth);
adding.add(new ConfigValue(value.getConfigName(),idProvider.getNextId()));
} else {
adding.add(new ConfigValue(value.getConfigName(),idProvider.getNextId()));
}
currentConfigurations.put(yearMonth, adding);
}

public void removeAllConfigurationsForYearMonth(String yearMonth) {

currentConfigurations = new HashMap<>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@RequestMapping(value="/configuration")
public class ConfigurationController {

@Autowired
private ConfigurationDao dao;

@Autowired
Expand All @@ -23,23 +24,21 @@ public ConfigurationController(ConfigurationDao dao) {
@ResponseBody
public List<ConfigValue> getConfigurationsForYearMonth(
@PathVariable("yearMonthNumber") String yearMonth) {

return new ArrayList<>();
;
return dao.getConfigurationsForYearMonth(yearMonth);
}

@RequestMapping(value="/{yearMonthNumber}", method=RequestMethod.DELETE)
public void deleteConfigurationsForYearMonth(@PathVariable("yearMonthNumber") String yearMonth) {
try {

} catch (Exception ex) {

}
public String deleteConfigurationsForYearMonth(@PathVariable("yearMonthNumber") String yearMonth) {
dao.removeAllConfigurationsForYearMonth(yearMonth);
return "{\"Status\":\"SUCCESS\"}";
}

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

dao.addConfiguration(yearMonth, value);
return "{\"Status\":\"SUCCESS\"}";
}
}
140 changes: 105 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,116 @@
<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" />
</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>

</tbody>
</table>
</div>
<div class="controls">
<button id="saveButton">Save Configurations</button>
</div>
</div>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css"/>
<script>
$(document).ready(function() {
$(document).ready(function () {
app.init();
getConfigurationsForYearMonth();
$("#saveButton").click(function () {
addDeleteConfiguration("POST", true);
});

$("#deleteAll").click(function () {
addDeleteConfiguration("DELETE", false);
});

$("#timePeriod").onchange(function () {
getConfigurationsForYearMonth();
});
})

function addDeleteConfiguration(method, add) {
var newConfig = $("#newConfig").val();

if (add) {
if (0 == newConfig.trim().length) {
alert("Config missing, unable to add empty config");
return;
}
}

var configValue = {}
configValue["configName"] = newConfig;

$.ajax({
url: "../configuration/" + $('#timePeriod option:selected').val(),
contentType: "application/json",
dataType: 'json',
type: method,
data: JSON.stringify(configValue),
success: function (data) {
getConfigurationsForYearMonth();
},
error: function (data) {
alert("Unable to add new configuration." + JSON.stringify(data));
console.log("Unable to add new configuration." + JSON.stringify(data));
}
});
}

function getConfigurationsForYearMonth() {
$.ajax({
url: "../configuration/" + $('#timePeriod option:selected').val(),
contentType: "application/json",
dataType: 'json',
type: "GET",
success: function (data) {
console.log("value : " + data);
var $configTempTable = $('#configTable').DataTable();
$configTempTable.clear();
$configTempTable.rows.add(data);
$configTempTable.draw();
},
error: function (data) {
console.log("Unable to display data." + JSON.stringify(data));
}
})
}
</script>
</head>
<body>
<h1>Welcome To The Configuration App</h1>
<div class="content">
<div class="controls">
<select id="timePeriod" onChange="getConfigurationsForYearMonth()">
<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">
<table>
<tr>
<td><label class="">New Configuration Name:</label></td>
<td><input value="" type="text" size="30" maxlength="30" id="newConfig"></td>
</tr>
<tr>
<td align="right"><button id="saveButton">Save Configurations</button></td>
<td><button id="deleteAll">Delete all Configurations</button></td>
</tr>
</table>

</div>
<div class="config-table-wrapper">
<table id="configTable">
<thead>
<tr>
<td>Configuration Id</td>
<td>Configuration Name</td>
</tr>
</thead>
<tbody>

</tbody>
</table>
</div>
</div>
</body>
</html>
6 changes: 5 additions & 1 deletion configurationapp/src/main/resources/static/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
paging: false,
sorting: false,
searching: false,
info: false
info: false,
columns: [
{ "data": "configId" },
{ "data": "configName" },
]
});
};

Expand Down