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

configurationapp/.project
configurationapp/.classpath
configurationapp/target/classes/application.properties
configurationapp/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
configurationapp/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
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 org.springframework.stereotype.Service;

import com.att.data.configurations.ConfigValue;

@Service
public class ConfigurationDao {
private class IdProvider {
Expand All @@ -34,15 +35,44 @@ public ConfigurationDao() {
}

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

return configForDate;
}

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

value.setConfigId(newId);

List<ConfigValue> configForDate = currentConfigurations.get(yearMonth);
if (configForDate == null) {
configForDate = new ArrayList<ConfigValue>();
}
configForDate.add(value);
currentConfigurations.put(yearMonth, configForDate);
}

public void removeAllConfigurationsForYearMonth(String yearMonth) {

currentConfigurations.remove(yearMonth);
}

public boolean deleteOneConfigForYearMonth(String yearMonth, ConfigValue value) {
boolean result = false;
List<ConfigValue> allConfigs4Date = currentConfigurations.get(yearMonth);
if (allConfigs4Date != null) {
for (int i = 0; i < allConfigs4Date.size(); i++) {
ConfigValue listConfigValue = allConfigs4Date.get(i);
if (listConfigValue.getConfigId() == value.getConfigId()) {
allConfigs4Date.remove(i);
result = true;
break;
}
}
}

return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Data Model
*/
public class ConfigValue {
private String configName;
private String configName;
private int configId;

public ConfigValue(String name, int id) {
Expand All @@ -31,4 +31,10 @@ public void setConfigId(int id) {
public int getConfigId() {
return this.configId;
}

@Override
public String toString() {
return "ConfigValue [configName=" + configName + ", configId=" + configId + "]";
}

}
Original file line number Diff line number Diff line change
@@ -1,45 +1,77 @@
package com.att.web.configuarations;

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;
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")
public class ConfigurationController {

private static final Logger log = LoggerFactory.getLogger(ConfigurationController.class);

private ConfigurationDao dao;

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

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

return new ArrayList<>();
public List<ConfigValue> getConfigurationsForYearMonth(@PathVariable("yearMonthNumber") String yearMonth) {

log.debug("In getConfigurationsForYearMonth with " + yearMonth);

return dao.getConfigurationsForYearMonth(yearMonth);
}

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

@RequestMapping(value="deleteConfigurationsForYearMonth/{yearMonthNumber}", method=RequestMethod.DELETE)
public boolean deleteConfigurationsForYearMonth(@PathVariable("yearMonthNumber") String yearMonth) {
//Not sure why you have exception block here, but minimally need to log an exception when it is caught
try {

log.debug("In deleteConfigurationsForYearMonth " + yearMonth);
dao.removeAllConfigurationsForYearMonth(yearMonth);
return true;
} catch (Exception ex) {

log.error("Exception while deleteConfigurationsForYearMonth for" + yearMonth);
return false;
}
}

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

log.debug("In addConfigurationForYearMonth " + yearMonth);
log.debug(value.toString());

dao.addConfiguration(yearMonth, value);

return true;
}

@RequestMapping(value="deleteOneConfigForYearMonth/{yearMonthNumber}", method=RequestMethod.DELETE)
public boolean deleteOneConfigForYearMonth(
@PathVariable("yearMonthNumber") String yearMonth,
@RequestBody ConfigValue value) {

log.debug("In deleteOneConfigForYearMonth " + yearMonth);
log.debug(value.toString());
return dao.deleteOneConfigForYearMonth(yearMonth, value);
}

}
2 changes: 1 addition & 1 deletion configurationapp/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
server.port=9000
spring.mvc.favicon.enabled=false

logging.level.root=WARN
logging.level.root=DEBUG
logging.level.org.springframework.web=DEBUG
logging.level.org.hibernate=ERROR
134 changes: 133 additions & 1 deletion 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 All @@ -21,6 +21,10 @@ <h1>Welcome To The Configuration App</h1>
<option value="072018">Jul 2018</option>
</select>
</div>
<div class="controls">
<label class="">* New Configuration:</label>
<input value="" type="text" size="30" maxlength="30" id="NewConfigName">
</div>
<div class="config-table-wrapper">
<table id="configTable">
<thead>
Expand All @@ -36,12 +40,140 @@ <h1>Welcome To The Configuration App</h1>
</div>
<div class="controls">
<button id="saveButton">Save Configurations</button>
<button id="delete4MonthYearButton">Delete Config. For Month Year</button>
<button id="deleteOneConfigButton">Delete Single Config</button>
</div>
</div>
<script>
$(document).ready(function() {
app.init();

$("#saveButton").click(function(){
addNewConfiguration();
});

$("#delete4MonthYearButton").click(function(){
deleteConfig4MonthYear();
});

$("#deleteOneConfigButton").click(function(){
deleteOneConfig();
});

$timePeriod = $("#timePeriod");
$timePeriod.change (function() {
getConfig4MonthYear();
});

//For selection de-selection
let table = $('#configTable').DataTable();
$('#configTable tbody').on( 'click', 'tr', function () {
if ( $(this).hasClass('selected') ) {
$(this).removeClass('selected');
} else {
table.$('tr.selected').removeClass('selected');
$(this).addClass('selected');
}
} );
})

function addNewConfiguration() {

let configName = $("#NewConfigName").val();
if (configName.trim().length == 0) {
alert("Please enter a Configuration and then click Save button");
return;
}

let aConfig4Date = {}
aConfig4Date["configName"] = configName;

$.ajax({
type: "POST",
contentType: "application/json",
url: "configuration/addConfigurationForYearMonth/" + $timePeriod.val(),
data: JSON.stringify(aConfig4Date),
dataType: 'json',
cache: false,
timeout: 600000,
success: function (data) {
console.log("SUCCESS in addNewConfiguration " + data);
getConfig4MonthYear();
},
error: function (data) {
console.log("HIT error on addNewConfiguration" + JSON.stringify(data));
}
});

}

function deleteConfig4MonthYear() {

$.ajax({
type: "DELETE",
contentType: "application/json",
url: "configuration/deleteConfigurationsForYearMonth/" + $timePeriod.val(),
dataType: 'json',
cache: false,
timeout: 600000,
success: function (data) {
console.log("SUCCESS in deleteConfig4MonthYear", data);
getConfig4MonthYear();
},
error: function (e) {
console.log("HIT error on deleteConfig4MonthYear");
}
});

}

function getConfig4MonthYear() {
$.ajax({
type: "GET",
contentType: "application/json",
url: "configuration/getConfigurationsForYearMonth/" + $timePeriod.val(),
dataType: 'json',
cache: false,
timeout: 600000,
success: function (data) {
console.log("SUCCESS in getConfig4MonthYear : ", data);
$elementTable = $('#configTable').DataTable();
$elementTable.clear();
$elementTable.rows.add(data);
$elementTable.draw();
},
error: function (e) {
console.log("HIT error on getConfig4MonthYear");
}
});
}

function deleteOneConfig() {
let selectedRow = $('#configTable').DataTable().row('.selected');

if (selectedRow.data()) {
$.ajax({
type: "DELETE",
contentType: "application/json",
url: "configuration/deleteOneConfigForYearMonth/" + $timePeriod.val(),
data: JSON.stringify(selectedRow.data()),
dataType: 'json',
cache: false,
timeout: 600000,
success: function (data) {
console.log("SUCCESS in deleteOneConfig", data);
getConfig4MonthYear();
},
error: function (e) {
console.log("HIT error on deleteOneConfig");
}
});
} else {
alert("Please select a Configuration Row and then click Delete Single Config.");
}
}


</script>
</body>
</html>
10 changes: 8 additions & 2 deletions configurationapp/src/main/resources/static/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
],
});
};

Expand Down
2 changes: 2 additions & 0 deletions configurationapp/target/classes/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/com/
/static/