T157 Added uuid as cookie
This commit is contained in:
		
							
								
								
									
										4
									
								
								.idea/workspace.xml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										4
									
								
								.idea/workspace.xml
									
									
									
										generated
									
									
									
								
							| @@ -20,7 +20,9 @@ | |||||||
|   </component> |   </component> | ||||||
|   <component name="ChangeListManager"> |   <component name="ChangeListManager"> | ||||||
|     <list default="true" id="458cde88-df3d-44bc-9d57-a33823e2f1a6" name="Default Changelist" comment=""> |     <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/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> |     </list> | ||||||
|     <option name="SHOW_DIALOG" value="false" /> |     <option name="SHOW_DIALOG" value="false" /> | ||||||
|     <option name="HIGHLIGHT_CONFLICTS" value="true" /> |     <option name="HIGHLIGHT_CONFLICTS" value="true" /> | ||||||
| @@ -309,7 +311,7 @@ | |||||||
|       <workItem from="1612259068808" duration="10440000" /> |       <workItem from="1612259068808" duration="10440000" /> | ||||||
|       <workItem from="1612279535476" duration="5692000" /> |       <workItem from="1612279535476" duration="5692000" /> | ||||||
|       <workItem from="1612442837870" duration="8318000" /> |       <workItem from="1612442837870" duration="8318000" /> | ||||||
|       <workItem from="1612609113694" duration="6024000" /> |       <workItem from="1612609113694" duration="7143000" /> | ||||||
|     </task> |     </task> | ||||||
|     <task id="LOCAL-00077" summary="testing jenkins docker"> |     <task id="LOCAL-00077" summary="testing jenkins docker"> | ||||||
|       <created>1601453886631</created> |       <created>1601453886631</created> | ||||||
|   | |||||||
| @@ -58,13 +58,13 @@ public class MockController { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     @ResponseBody |     @ResponseBody | ||||||
|     @GetMapping("/mock/json") |     @GetMapping({"/mock/json", "/mock/json/{uuid}"}) | ||||||
|     public List<MockedMessageDto> getJson(@RequestParam(required = false) UUID clientUUID){ |     public List<MockedMessageDto> getJson(@PathVariable(required = false) UUID uuid){ | ||||||
|         if(clientUUID == null) clientUUID = UUID.randomUUID(); |         if(uuid == null) uuid = UUID.randomUUID(); | ||||||
|         List<MockedMessageDto> messages = klausService.getAllMockedResponses(clientUUID); |         List<MockedMessageDto> messages = klausService.getAllMockedResponses(uuid); | ||||||
|         if(messages.size() == 0) { |         if(messages.size() == 0) { | ||||||
|             klausService.setMockedResponse(buildDefaultMessage(clientUUID)); |             klausService.setMockedResponse(buildDefaultMessage(uuid)); | ||||||
|             messages = klausService.getAllMockedResponses(clientUUID); |             messages = klausService.getAllMockedResponses(uuid); | ||||||
|         } |         } | ||||||
|         return messages; |         return messages; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -7,12 +7,16 @@ | |||||||
| //TODO: Add getData() recall after PUT, POST or DELETE | //TODO: Add getData() recall after PUT, POST or DELETE | ||||||
| //TODO: Add delete buttons for headers | //TODO: Add delete buttons for headers | ||||||
| //TODO: Add delete buttons for messages | //TODO: Add delete buttons for messages | ||||||
|  | var clientUUID; | ||||||
| var json; | var json; | ||||||
| var jsonIndex = 0; | var jsonIndex = 0; | ||||||
| function getData(uuid){ | const C_UUID = 'mock-uuid'; | ||||||
|     $.getJSON('http://localhost:8097/mock/json', function(data) { | function getData(){ | ||||||
|  |     loadCookies(); | ||||||
|  |     $.getJSON('http://localhost:8097/mock/json/'+clientUUID, function(data) { | ||||||
|         json = data; |         json = data; | ||||||
|  |         clientUUID = json[jsonIndex].clientUUID; | ||||||
|  |         setCookies(); | ||||||
|         console.log(JSON.stringify(json)); |         console.log(JSON.stringify(json)); | ||||||
|         console.log("Json received"); |         console.log("Json received"); | ||||||
|         fillMessageList(); |         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(){ | function updateData(){ | ||||||
|     var updatedJson = generateJson(); |     var updatedJson = generateJson(); | ||||||
|     $.ajax({ |     $.ajax({ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user