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
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties

# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored)
!/.mvn/wrapper/maven-wrapper.jar

# Ignore all IntelliJ Idea files
.idea/
out/
*.iws
*.iml
*.ipr

untracked/
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 All @@ -25,24 +22,65 @@ public int getNextId() {
/**
* No DB, so store the configs in a map.
*/
private Map<String, List<ConfigValue>> currentConfigurations;
private IdProvider idProvider;
private final Map<String, List<ConfigValue>> currentConfigurations;
private final Map<Integer, ConfigValue> allConfigValues;
private final IdProvider idProvider;

public ConfigurationDao() {
idProvider = new IdProvider();
// Acknowledging that configurations are different subsets over the same universe of config values
allConfigValues = new HashMap<>();
createConfigValue("A");
createConfigValue("B");
createConfigValue("C");
createConfigValue("D");
createConfigValue("E");
createConfigValue("F");
createConfigValue("G");
createConfigValue("H");
currentConfigurations = new HashMap<>();
ArrayList<ConfigValue> configValues = new ArrayList<>();
configValues.add(allConfigValues.get(0));
configValues.add(allConfigValues.get(1));
configValues.add(allConfigValues.get(2));
configValues.add(allConfigValues.get(3));
currentConfigurations.put("012018", configValues);
configValues = new ArrayList<>();
configValues.add(allConfigValues.get(0));
configValues.add(allConfigValues.get(2));
configValues.add(allConfigValues.get(5));
configValues.add(allConfigValues.get(6));
configValues.add(allConfigValues.get(7));
currentConfigurations.put("022018", configValues);
}

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

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

public void addConfiguration(String yearMonth, ConfigValue prototype) {
ConfigValue newValue = createConfigValue(prototype.getConfigName());
List<ConfigValue> values = currentConfigurations.get(yearMonth);
if (values == null) {
values = new ArrayList<>();
currentConfigurations.put(yearMonth, values);
}
values.add(newValue);
}

public void removeAllConfigurationsForYearMonth(String yearMonth) {
currentConfigurations.remove(yearMonth);
}

private ConfigValue createConfigValue(String name) {
int id = idProvider.getNextId();
ConfigValue cv = new ConfigValue(name, id);
allConfigValues.put(id, cv);
return cv;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,21 @@ public ConfigurationController(ConfigurationDao dao) {
@RequestMapping(value="/{yearMonthNumber}", method=RequestMethod.GET)
@ResponseBody
public List<ConfigValue> getConfigurationsForYearMonth(
@PathVariable("yearMonthNumber") String yearMonth) {

return new ArrayList<>();
@PathVariable("yearMonthNumber") String yearMonth)
{
return dao.getConfigurationsForYearMonth(yearMonth);
}

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

} catch (Exception ex) {

}
dao.removeAllConfigurationsForYearMonth(yearMonth);
}

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

@RequestBody ConfigValue value)
{
dao.addConfiguration(yearMonth, value);
}
}
6 changes: 4 additions & 2 deletions configurationapp/src/main/resources/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<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" />
Expand Down Expand Up @@ -35,7 +35,9 @@ <h1>Welcome To The Configuration App</h1>
</table>
</div>
<div class="controls">
<button id="saveButton">Save Configurations</button>
<button id="addButton">Add Configuration</button>
<button id="deleteButton">Delete Configurations</button>
<button id="refreshButton">Refresh Configurations</button>
</div>
</div>
<script>
Expand Down
80 changes: 65 additions & 15 deletions configurationapp/src/main/resources/static/js/app.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,75 @@
(function() {
function App() {

}
this.selectedResourcePath = function () {
return '/configuration/' + this.selectedTimePeriod();
}

this.selectedTimePeriod = function () {
return $('#timePeriod').val();
}

this.init = function() {

App.prototype.getData = function() {
$.ajax('',{
$('#configTable').DataTable({
serverSide: true,
ajax: {
url: this.selectedResourcePath(),
type: 'GET',
// Necessary because root is not an object with a "data" key
dataSrc: ''
},
columns: [
{ data: 'configId'},
{ data: 'configName'}
],
scrollY: 300,
paging: false,
sorting: false,
searching: false,
info: false
});

}).then(function(data) {
$('#addButton').click(function() {
let name = prompt("Enter a name for the new configuration:");
$.ajax({
type: "POST",
url: app.selectedResourcePath(),
data: JSON.stringify({
configId: -1,
configName: name
}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success:function (successResponse,textStatus,jqXHR) {
$('#configTable').DataTable().ajax.reload();
},
error: function (errorResponse1) {
$('#configTable').DataTable().ajax.reload();
}
});
});

})
};
$('#deleteButton').click(function() {
$.ajax({
url: app.selectedResourcePath(),
type: 'DELETE',
success: function() {
$('#configTable').DataTable().ajax.reload();
}
});
});

App.prototype.init = function() {
$('#configTable').DataTable({
scrollY: 300,
paging: false,
sorting: false,
searching: false,
info: false
});
};
$('#refreshButton').click(function() {
$('#configTable').DataTable().ajax.reload();
});

$('#timePeriod').change(function() {
$('#configTable').DataTable().ajax.url(app.selectedResourcePath()).load();
});
}

}

window.app = new App;
})($);