T157 Added uuid as cookie

This commit is contained in:
2021-02-06 13:58:04 +01:00
parent 5a38548ba9
commit 5bcfb571e2
3 changed files with 40 additions and 10 deletions

4
.idea/workspace.xml generated
View File

@@ -20,7 +20,9 @@
</component>
<component name="ChangeListManager">
<list default="true" id="458cde88-df3d-44bc-9d57-a33823e2f1a6" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/release11/klaus/controller/MockController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/release11/klaus/controller/MockController.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/resources/static/js/datatransfer.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/static/js/datatransfer.js" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -309,7 +311,7 @@
<workItem from="1612259068808" duration="10440000" />
<workItem from="1612279535476" duration="5692000" />
<workItem from="1612442837870" duration="8318000" />
<workItem from="1612609113694" duration="6024000" />
<workItem from="1612609113694" duration="7143000" />
</task>
<task id="LOCAL-00077" summary="testing jenkins docker">
<created>1601453886631</created>

View File

@@ -58,13 +58,13 @@ public class MockController {
}
@ResponseBody
@GetMapping("/mock/json")
public List<MockedMessageDto> getJson(@RequestParam(required = false) UUID clientUUID){
if(clientUUID == null) clientUUID = UUID.randomUUID();
List<MockedMessageDto> messages = klausService.getAllMockedResponses(clientUUID);
@GetMapping({"/mock/json", "/mock/json/{uuid}"})
public List<MockedMessageDto> getJson(@PathVariable(required = false) UUID uuid){
if(uuid == null) uuid = UUID.randomUUID();
List<MockedMessageDto> messages = klausService.getAllMockedResponses(uuid);
if(messages.size() == 0) {
klausService.setMockedResponse(buildDefaultMessage(clientUUID));
messages = klausService.getAllMockedResponses(clientUUID);
klausService.setMockedResponse(buildDefaultMessage(uuid));
messages = klausService.getAllMockedResponses(uuid);
}
return messages;
}

View File

@@ -7,12 +7,16 @@
//TODO: Add getData() recall after PUT, POST or DELETE
//TODO: Add delete buttons for headers
//TODO: Add delete buttons for messages
var clientUUID;
var json;
var jsonIndex = 0;
function getData(uuid){
$.getJSON('http://localhost:8097/mock/json', function(data) {
const C_UUID = 'mock-uuid';
function getData(){
loadCookies();
$.getJSON('http://localhost:8097/mock/json/'+clientUUID, function(data) {
json = data;
clientUUID = json[jsonIndex].clientUUID;
setCookies();
console.log(JSON.stringify(json));
console.log("Json received");
fillMessageList();
@@ -23,6 +27,30 @@ function getData(uuid){
});
}
function setCookies(){
document.cookie = C_UUID + '=' +clientUUID+';';
}
function loadCookies(){
clientUUID = getCookie(C_UUID);
}
function getCookie(cname) {
var name = cname + '=';
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return '';
}
function updateData(){
var updatedJson = generateJson();
$.ajax({