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,12 +1,16 @@
package com.att.dao.configurations;

import com.att.data.configurations.ConfigValue;
//import java.awt.List;
import com.sun.org.apache.xpath.internal.operations.And;
import javax.print.attribute.HashAttributeSet;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Iterator;

@Service
public class ConfigurationDao {
Expand Down Expand Up @@ -34,15 +38,53 @@ public ConfigurationDao() {
}

public List<ConfigValue> getConfigurationsForYearMonth(String yearMonth) {
return new ArrayList<>();
List<ConfigValue> list = new ArrayList<ConfigValue>();

if(currentConfigurations.containsKey(yearMonth))
{
return currentConfigurations.get(yearMonth);
}
return new ArrayList<>();
}

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

value.setConfigId(newId);
List<ConfigValue> list = new ArrayList<ConfigValue>();
if (currentConfigurations.containsKey(yearMonth)) {
list = currentConfigurations.get(yearMonth);
list.add(value);
} else {
list.add(value);
}
currentConfigurations.put(yearMonth,list);
return newId;
}

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

public void removeConfigurationsForYearMonth(String yearMonth, ConfigValue value) {
List<ConfigValue> list = new ArrayList<ConfigValue>();
if (currentConfigurations.containsKey(yearMonth)) {
list = currentConfigurations.get(yearMonth);
Iterator<ConfigValue> iterator = list.iterator();
List<ConfigValue> listAfter = new ArrayList<>();
while(iterator.hasNext()) {
ConfigValue next = iterator.next();
if(next.getConfigId() == value.getConfigId() &&
next.getConfigName().equals(value.getConfigName())) {

} else {
listAfter.add(next);
}
}

currentConfigurations.remove(yearMonth);
currentConfigurations.put(yearMonth,listAfter);
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.att.dao.configurations.ConfigurationDao;
import com.att.data.configurations.ConfigValue;
import java.io.Console;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

Expand All @@ -19,27 +20,36 @@ public ConfigurationController(ConfigurationDao dao) {
this.dao = dao;
}

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

return new ArrayList<>();
}

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

} catch (Exception ex) {
List<ConfigValue> getConfigValue = dao.getConfigurationsForYearMonth(yearMonth);

return getConfigValue;
}

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

if (deleteAll) {
try {
dao.removeAllConfigurationsForYearMonth(yearMonth);
} catch (Exception ex) {

}
} else {
dao.removeConfigurationsForYearMonth(yearMonth,configValueIn);
}
}

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

@RequestBody ConfigValue configValueIn) {
return(dao.addConfiguration(yearMonth, configValueIn));
}
}
11 changes: 9 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,8 @@
<html>
<head>
<title>Configuration App</title>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>>
<!-- <script src="https://code.jquery.com/jquery-3.3.1.slim.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 @@ -27,15 +28,21 @@ <h1>Welcome To The Configuration App</h1>
<tr>
<td>Configuration Id</td>
<td>Configuration Name</td>
<td></td>
</tr>
</thead>
<tbody>

</tbody>
</table>
</div>
</div>
<div class="controls">
<button id="saveButton">Save Configurations</button>
<button id="deleteButton">Delete Configurations</button>
</div>
<div class="controls">
<button id="newButton">New Configurations</button>
<input id="configName" placeholder="Config Name" type="text" />
</div>
</div>
<script>
Expand Down
93 changes: 90 additions & 3 deletions configurationapp/src/main/resources/static/js/app.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,112 @@
(function() {
function App() {

window.onload = function() {

$('#timePeriod').change(function(){
var yearMonth = document.getElementById("timePeriod").value;
app.getData(yearMonth);
});

document.getElementById('newButton').onclick = function() {
var yearMonth = document.getElementById("timePeriod").value;
var configName = document.getElementById("configName").value;
document.getElementById("configName").value= "";
app.putData(yearMonth, configName);
};

document.getElementById('deleteButton').onclick = function() {
var yearMonth = document.getElementById("timePeriod").value;
app.deleteData(true, yearMonth, null, null);
};
}

function App() {
}

App.prototype.getData = function() {
$.ajax('',{
App.prototype.putData = function(yearMonth, configName) {
var dTable = $('#configTable').DataTable();
var JSONObject= {
'configId': 0,
'configName': configName
};

$.ajax({
type: 'PUT',
url: "/configuration/addConfigurationForYearMonth/"+yearMonth,
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(JSONObject),
async: true,
// success: function(result) {
// alert('Result: ' + result);
// },
// error: function(jqXHR, textStatus, errorThrown) {
// alert("error"+jqXHR.status + ' ' + jqXHR.responseText);
// }
}).then(function(configId) {
dTable.row.add([
configId,
configName
]).draw();
})
}

App.prototype.deleteData = function(deleteAll,yearMonth, configId, configName) {
var dTable = $('#configTable').DataTable();
var JSONObject= {
'configId': configId,
'configName': configName
};
$.ajax({
type: "DELETE",
url: "/configuration/deleteConfigurationsForYearMonth/"+yearMonth+"/"+deleteAll,
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(JSONObject),
async: true,
}).then(function(data) {
if (deleteAll) dTable.clear().draw();
})
};

App.prototype.getData = function(yearMonth) {
var dTable = $('#configTable').DataTable();
dTable.clear().draw();
$.ajax({
type: "GET",
url: "configuration/getConfigurationsForYearMonth/"+yearMonth,
}).then(function(data) {
console.log("data: "+data);
$.each(data, function( index, configValue ) {
dTable.row.add([
configValue.configId,
configValue.configName
]).draw();
});
})
};

App.prototype.init = function() {
$('#configTable').DataTable({
"columnDefs": [ {
"targets": 2,
"data": null,
"defaultContent": "<button>Delete</button>"
} ],
scrollY: 300,
paging: false,
sorting: false,
searching: false,
info: false
});
var dTable = $('#configTable').DataTable();
$('#configTable tbody').on( 'click', 'button', function () {
var data = dTable.row( $(this).parents('tr') ).data();
dTable.row( $(this).parents('tr') )
.remove()
.draw();
app.deleteData(false, document.getElementById("timePeriod").value, data[0], data[1]);
} );
};


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