Merged widlam/refactor/issue#201 to master
This commit is contained in:
@@ -51,106 +51,35 @@ public class MockController {
|
||||
* Returns the full list of messages. It's used by javascript on the client side to initialize homepage
|
||||
* with data from the database.
|
||||
* @param uuidValue the key-uuid of given set of messages
|
||||
* @return responds with 200 OK and list of {@link MockedMessageDto}
|
||||
* @return responds with 200 OK and {@link MockedMessageDto}
|
||||
*/
|
||||
@GetMapping({"/", "/{uuidValue}"})
|
||||
public List<MockedMessageDto> getListOfMessages(@PathVariable(required = false) String uuidValue){
|
||||
public MockedMessageDto getMessage(@PathVariable(required = false) String uuidValue){
|
||||
UUID clientUUID;
|
||||
MockedMessageDto message ;
|
||||
if(uuidValue == null || uuidValue.equals("")) clientUUID = UUID.randomUUID();
|
||||
else clientUUID = UUID.fromString(uuidValue);
|
||||
List<MockedMessageDto> messages = klausService.getAllMockedResponses(clientUUID);
|
||||
if(messages.size() == 0) {
|
||||
klausService.setMockedResponse(buildDefaultMessage(clientUUID));
|
||||
messages = klausService.getAllMockedResponses(clientUUID);
|
||||
}
|
||||
Collections.sort(messages);
|
||||
return messages;
|
||||
}
|
||||
message = klausService
|
||||
.getMockedMessageByClientUUID(clientUUID)
|
||||
.orElse( buildDefaultMessage(clientUUID) );
|
||||
|
||||
/**
|
||||
* If provided UUID does not exist in database returns ResponseEntity with new generated UUID(if previous UUID is not provided),
|
||||
* or old UUID(if previous UUID is provided). If provided UUID exists function returns provided UUID.
|
||||
* @param givenUUIDValue the UUID client wants to check exsitance in database
|
||||
* @param previousUUIDValue the previous UUID used by client(optional variable)
|
||||
* @return ResponseEntity with UUID
|
||||
*/
|
||||
@RequestMapping(
|
||||
method = RequestMethod.GET ,
|
||||
path = {"/check/{givenUUIDValue}/{previousUUIDValue}",
|
||||
"/check/{givenUUIDValue}"})
|
||||
public ResponseEntity<String> checkUUID(
|
||||
@PathVariable String givenUUIDValue
|
||||
,@PathVariable(required = false) String previousUUIDValue ){
|
||||
try{
|
||||
UUID.fromString(givenUUIDValue);
|
||||
} catch (IllegalArgumentException ex){
|
||||
log.error("Wrong UUID value!");
|
||||
if (previousUUIDValue == null || previousUUIDValue.equals("")){
|
||||
UUID newUUID = UUID.randomUUID();
|
||||
log.info("New UUID generated.");
|
||||
return ResponseEntity.ok(newUUID.toString());
|
||||
}
|
||||
log.info("Previous UUID value restored.");
|
||||
return ResponseEntity.ok(previousUUIDValue);
|
||||
}
|
||||
return ResponseEntity.ok(givenUUIDValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts empty post request and creates new message in given set. The new message has default set of data,
|
||||
* which is constructed in {@link #buildDefaultMessage(UUID, int)} method.
|
||||
* @param uuidValue the key-uuid of given set of messages
|
||||
* @return confirmation response with 200 OK
|
||||
*/
|
||||
@PostMapping("/{uuidValue}")
|
||||
public ResponseEntity<String> addNewMessage(@PathVariable String uuidValue){
|
||||
UUID clientUUID = UUID.fromString(uuidValue);
|
||||
List<MockedMessageDto> messages = klausService.getAllMockedResponses(clientUUID);
|
||||
MockedMessageDto nextMessage = buildDefaultMessage(clientUUID, findNextId(messages));
|
||||
return klausService.setMockedResponse(nextMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes message of given id via client request
|
||||
* @param uuidValue the key-uuid of given set of messages
|
||||
* @param idValue unique id of given message
|
||||
* @return after deletion the confirmation is send with status 200 OK
|
||||
*/
|
||||
@DeleteMapping("/{uuidValue}/{idValue}")
|
||||
public ResponseEntity<String> removeMessage(@PathVariable String uuidValue,
|
||||
@PathVariable String idValue){
|
||||
UUID clientUUID = UUID.fromString(uuidValue);
|
||||
int id = Integer.parseInt(idValue);
|
||||
return klausService.deleteMockedResponse(clientUUID, id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Recalls {@link #buildDefaultMessage(UUID)} for message construction and sets id of message
|
||||
* @param uuid the key-uuid of given set of messages
|
||||
* @param id unique id of given message
|
||||
* @return message with default dataset and set id
|
||||
*/
|
||||
private static MockedMessageDto buildDefaultMessage(UUID uuid, int id){
|
||||
MockedMessageDto message = buildDefaultMessage(uuid);
|
||||
message.setMockedResponseId(id);
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructs message with default set of data
|
||||
* @param uuid the key-uuid of given set of messages
|
||||
* @return message with default dataset
|
||||
*/
|
||||
private static MockedMessageDto buildDefaultMessage(UUID uuid){
|
||||
private MockedMessageDto buildDefaultMessage(UUID uuid){
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
headers.put("Keep-Alive", "timeout=60");
|
||||
headers.put("Connection", "keep-alive");
|
||||
headers.put("Date", LocalDateTime.now().toString());
|
||||
return MockedMessageDto.builder()
|
||||
MockedMessageDto mockedMessageDto = MockedMessageDto.builder()
|
||||
.clientUUID(uuid)
|
||||
.mockedResponseId(1)
|
||||
.mediaType(MediaType.APPLICATION_XML_VALUE)
|
||||
.contentType(MediaType.APPLICATION_XML_VALUE)
|
||||
.messageBody("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
||||
"<note>\n" +
|
||||
" <to>Tove</to>\n" +
|
||||
@@ -161,38 +90,24 @@ public class MockController {
|
||||
.httpHeaders(headers)
|
||||
.httpStatus(200)
|
||||
.build();
|
||||
klausService.setMockedResponse(mockedMessageDto);
|
||||
return mockedMessageDto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the highest id in the list and returns it incremented by 1
|
||||
* @param messages list of messages
|
||||
* @return highest id incremented by 1
|
||||
*/
|
||||
public static int findNextId(List<MockedMessageDto> messages) {
|
||||
int highestId = 0;
|
||||
for (MockedMessageDto m : messages)
|
||||
highestId = highestId > m.getMockedResponseId() ? highestId : m.getMockedResponseId();
|
||||
return ++highestId;
|
||||
}
|
||||
|
||||
/**
|
||||
* It's one of the most important features - the bread and butter of the Mocked Service. It's link that allows
|
||||
* to receive mocked response from the server and use it to mock!
|
||||
* @param clientUUID the key-uuid of given set of messages
|
||||
* @param mockedResponseId unique id of given message
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/r/{clientUUID}/{mockedResponseId}")
|
||||
@RequestMapping(value = "/r/{clientUUID}")
|
||||
public ResponseEntity getMockedResponse(
|
||||
@PathVariable UUID clientUUID,
|
||||
@PathVariable int mockedResponseId) {
|
||||
MockedMessageDto mockedMessageDto = klausService.getMockedResponse(clientUUID, mockedResponseId);
|
||||
@PathVariable UUID clientUUID) {
|
||||
MockedMessageDto mockedMessageDto = klausService.getMockedResponse(clientUUID);
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
if (mockedMessageDto.getHttpHeaders() != null) mockedMessageDto.getHttpHeaders().forEach(httpHeaders::set);
|
||||
httpHeaders.add("Content-Type", mockedMessageDto.getMediaType());
|
||||
httpHeaders.add("Content-Type", mockedMessageDto.getContentType());
|
||||
return new ResponseEntity<>(mockedMessageDto.getMessageBody(), httpHeaders,
|
||||
Objects.requireNonNull(HttpStatus.valueOf(mockedMessageDto.getHttpStatus())));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.r11.tools.controller;
|
||||
|
||||
import com.r11.tools.mappers.RequestHistoryMapper;
|
||||
import com.r11.tools.model.HistoryRequestModel;
|
||||
import com.r11.tools.model.RequestHistory;
|
||||
import com.r11.tools.model.RequestHistoryDTO;
|
||||
import com.r11.tools.service.RequestHistoryService;
|
||||
@@ -9,9 +8,7 @@ import lombok.AllArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -28,40 +25,14 @@ public class RequestHistoryController {
|
||||
private final RequestHistoryMapper mapper;
|
||||
|
||||
/**
|
||||
* Returns the list of Events in given time bracket.
|
||||
* The list of objects is received via {@link RequestHistoryDTO}, which contains time brackets,
|
||||
* as well as the key - uuid.
|
||||
* @param historyRequestModel EventRequestDto object that contains data needed to query the database
|
||||
* @return list of {@link RequestHistory}
|
||||
*/
|
||||
@PostMapping
|
||||
public ResponseEntity<List<RequestHistoryDTO>> filterHistory(@RequestBody HistoryRequestModel historyRequestModel){
|
||||
return ResponseEntity.ok(
|
||||
service.getHistoryRecordsBetweenDatesAndByUUIDAndMessageId(historyRequestModel)
|
||||
.stream()
|
||||
.map(mapper::requestHistoryToRequestHistoryDTO)
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of Events of last 24h from given date.
|
||||
* Returns the list of Events.
|
||||
* @param uuid unique id of message list
|
||||
* @param messageId unique id of message in message list
|
||||
* @return list of {@link RequestHistory}
|
||||
*/
|
||||
@GetMapping(path = "/{uuid}/{messageId}")
|
||||
public ResponseEntity<List<RequestHistoryDTO>> getLastDay(@PathVariable UUID uuid,
|
||||
@PathVariable Integer messageId){
|
||||
LocalDateTime requestTime = LocalDateTime.now();
|
||||
LocalDateTime dayBeforeRequest = requestTime.minusDays(1L);
|
||||
List<RequestHistoryDTO> requestHistory = service.getHistoryRecordsBetweenDatesAndByUUIDAndMessageId(
|
||||
HistoryRequestModel.builder()
|
||||
.localDateTimeFrom(dayBeforeRequest)
|
||||
.localDateTimeTo(requestTime)
|
||||
.clientUUID(uuid)
|
||||
.mockedResponseId(messageId)
|
||||
.build()
|
||||
@GetMapping(path = "/{uuid}")
|
||||
public ResponseEntity<List<RequestHistoryDTO>> getLastDay(@PathVariable String uuid){
|
||||
List<RequestHistoryDTO> requestHistory = service.getHistoryRecordsByUUID(
|
||||
uuid
|
||||
).stream()
|
||||
.map(mapper::requestHistoryToRequestHistoryDTO)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@@ -39,7 +39,6 @@ public class IncomingMockRequestInterceptor implements HandlerInterceptor {
|
||||
RequestHistoryDTO historyDTO = RequestHistoryDTO.builder()
|
||||
.httpMethod(HttpMethod.valueOf(httpRequest.getMethod()))
|
||||
.headers( headers )
|
||||
.messageID(Integer.valueOf(pathVariable.get("mockedResponseId")))
|
||||
.clientUUID(UUID.fromString(pathVariable.get("clientUUID")))
|
||||
.dateTimeStamp(LocalDateTime.now())
|
||||
.requestBody(requestBody)
|
||||
|
||||
@@ -4,15 +4,23 @@ import com.r11.tools.model.MockedMessage;
|
||||
import com.r11.tools.model.MockedMessageDto;
|
||||
import org.mapstruct.*;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Creates key value for redis entry
|
||||
* @author Rafał Źukowicz
|
||||
*/
|
||||
@Mapper
|
||||
public interface MockedMessageMapper {
|
||||
@Mapping( target = "compositePrimaryKey", expression = "java(mockedMessageDto.getClientUUID() + \"_\"" +
|
||||
" + mockedMessageDto.getMockedResponseId())")
|
||||
@Mapping( target = "createdAt" , expression = "java(java.time.LocalDateTime.now())")
|
||||
MockedMessage mockedMessageDtoToMockedMessage(MockedMessageDto mockedMessageDto);
|
||||
MockedMessageDto mockedMessageToMockedMessageDto(MockedMessage mockedMessage);
|
||||
|
||||
default Optional<MockedMessageDto> optionalMockedMessageToOptionalMockedMessageDTO(Optional<MockedMessage> optionalMockedMessage){
|
||||
return optionalMockedMessage.map(this::mockedMessageToMockedMessageDto);
|
||||
}
|
||||
|
||||
default Optional<MockedMessage> optionalMockedMessageDTOToOptionalMockedMessage(Optional<MockedMessageDto> optionalMockedMessageDto){
|
||||
return optionalMockedMessageDto.map(this::mockedMessageDtoToMockedMessage);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ import org.mapstruct.Mapping;
|
||||
@Mapper
|
||||
public interface RequestHistoryMapper {
|
||||
|
||||
@Mapping(target = "id", expression = "java(null)")
|
||||
@Mapping(target = "clientUUID", expression = "java(requestHistoryDTO.getClientUUID().toString())")
|
||||
RequestHistory requestHistoryDTOToRequestHistory(RequestHistoryDTO requestHistoryDTO);
|
||||
@Mapping(target = "clientUUID", expression = "java(java.util.UUID.fromString(requestHistory.getClientUUID()))")
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
package com.r11.tools.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Represents all data needed to get HistoryRecord from database
|
||||
* @author Mikołaj Widła
|
||||
*/
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class HistoryRequestModel {
|
||||
|
||||
private UUID clientUUID;
|
||||
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
|
||||
private LocalDateTime localDateTimeFrom;
|
||||
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
|
||||
private LocalDateTime localDateTimeTo;
|
||||
private Integer mockedResponseId;
|
||||
|
||||
}
|
||||
@@ -1,11 +1,6 @@
|
||||
package com.r11.tools.model;
|
||||
|
||||
import com.r11.tools.model.constraints.HttpCode;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import javax.validation.constraints.Positive;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -14,6 +9,11 @@ import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.redis.core.RedisHash;
|
||||
import org.springframework.data.redis.core.index.Indexed;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* MockedMessage redis entity pojo
|
||||
* @author Rafał Żukowicz
|
||||
@@ -24,13 +24,10 @@ import org.springframework.data.redis.core.index.Indexed;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class MockedMessage implements Serializable {
|
||||
@Id
|
||||
private String compositePrimaryKey;
|
||||
@Indexed
|
||||
@Id
|
||||
private UUID clientUUID;
|
||||
@Positive
|
||||
private Integer mockedResponseId;
|
||||
private String mediaType;
|
||||
private String contentType;
|
||||
private String messageBody;
|
||||
private Map<String, String> httpHeaders;
|
||||
@HttpCode
|
||||
@@ -38,5 +35,3 @@ public class MockedMessage implements Serializable {
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package com.r11.tools.model;
|
||||
|
||||
import com.r11.tools.model.constraints.HttpCode;
|
||||
import lombok.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Positive;
|
||||
import lombok.*;
|
||||
|
||||
/**
|
||||
* Alternative version of {@link MockedMessage} used in http body
|
||||
@@ -18,19 +17,12 @@ import lombok.*;
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class MockedMessageDto implements Serializable, Comparable<MockedMessageDto> {
|
||||
public class MockedMessageDto implements Serializable{
|
||||
private UUID clientUUID;
|
||||
@NotNull
|
||||
@Positive
|
||||
private Integer mockedResponseId;
|
||||
private String mediaType;
|
||||
private String contentType;
|
||||
private String messageBody;
|
||||
private Map<String, String> httpHeaders;
|
||||
@HttpCode
|
||||
private Integer httpStatus;
|
||||
|
||||
@Override
|
||||
public int compareTo(MockedMessageDto message) {
|
||||
return this.mockedResponseId > message.getMockedResponseId() ? 1 : -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,15 +25,12 @@ import java.util.Map;
|
||||
@AllArgsConstructor
|
||||
@RedisHash("mockHistory")
|
||||
public class RequestHistory implements Comparable<RequestHistory>, Serializable {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
@DateTimeFormat(pattern = "yyyy-MM-ddTHH:mm:ss")
|
||||
private LocalDateTime dateTimeStamp;
|
||||
@Indexed
|
||||
private String clientUUID;
|
||||
@Indexed
|
||||
private Integer messageID;
|
||||
private Map<String,String> headers;
|
||||
private HttpMethod httpMethod;
|
||||
private String requestBody;
|
||||
|
||||
@@ -25,7 +25,6 @@ public class RequestHistoryDTO {
|
||||
private UUID clientUUID;
|
||||
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
|
||||
private LocalDateTime dateTimeStamp;
|
||||
private Integer messageID;
|
||||
private Map<String,String> headers;
|
||||
private HttpMethod httpMethod;
|
||||
private String requestBody;
|
||||
|
||||
@@ -14,11 +14,11 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
*/
|
||||
@Repository
|
||||
@Transactional
|
||||
public interface MockedResponseRepository extends CrudRepository<MockedMessage, String> {
|
||||
public interface MockedResponseRepository extends CrudRepository<MockedMessage, UUID> {
|
||||
/**
|
||||
* Finds all messages by their uuid
|
||||
* @param clientUUID the key-uuid of given set of messages
|
||||
* @return Optional of list of {@link com.r11.tools.model.MockedMessage}
|
||||
*/
|
||||
Optional<List<MockedMessage>> findAllByClientUUID(UUID clientUUID);
|
||||
Optional<MockedMessage> findAllByClientUUID(UUID clientUUID);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,5 @@ import java.util.List;
|
||||
@Repository
|
||||
@Transactional
|
||||
public interface RequestHistoryRepository extends CrudRepository<RequestHistory,String> {
|
||||
List<RequestHistory> findAllByClientUUIDAndMessageID(
|
||||
String clientUUID,
|
||||
Integer messageID);
|
||||
List<RequestHistory> findAllByClientUUID(String clientUUID);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package com.r11.tools.service;
|
||||
|
||||
import com.r11.tools.model.MockedMessageDto;
|
||||
import java.util.List;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -12,8 +13,7 @@ import org.springframework.stereotype.Service;
|
||||
*/
|
||||
@Service
|
||||
public interface KlausService {
|
||||
ResponseEntity<String> deleteMockedResponse(UUID clientUUID, int mockedResponseId);
|
||||
List<MockedMessageDto> getAllMockedResponses(UUID clientUUID);
|
||||
MockedMessageDto getMockedResponse(UUID clientUUID, int mockedResponseId);
|
||||
Optional<MockedMessageDto> getMockedMessageByClientUUID(UUID clientUUID);
|
||||
MockedMessageDto getMockedResponse(UUID clientUUID);
|
||||
ResponseEntity<String> setMockedResponse(MockedMessageDto mockedMessageDto);
|
||||
}
|
||||
|
||||
@@ -13,16 +13,15 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Service for {@link com.r11.tools.controller.MockController} and {@link com.r11.tools.controller.MockController}
|
||||
* Allows for performing CRUD operations on {@link MockedMessageDto}
|
||||
* @author Rafał Żukowicz
|
||||
* @author Gabriel Modzelewski
|
||||
* @author Mikołaj Widła
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
@@ -31,20 +30,6 @@ public class KlausServiceImpl implements KlausService {
|
||||
private final Logger log = LogManager.getRootLogger();
|
||||
private final MockedResponseRepository mockedResponseRepository;
|
||||
|
||||
/**
|
||||
* Removes message of given id in given key-uuid set
|
||||
* @param clientUUID the key-uuid of given set of messages
|
||||
* @param mockedResponseId unique id of given message
|
||||
* @return confirmation and status 200 OK
|
||||
*/
|
||||
@Override
|
||||
public ResponseEntity<String> deleteMockedResponse(UUID clientUUID, int mockedResponseId) {
|
||||
String key = clientUUID.toString() + "_" + mockedResponseId;
|
||||
mockedResponseRepository.deleteById(key);
|
||||
log.info("Message: "+mockedResponseId+" has been removed.");
|
||||
return new ResponseEntity<>("MockedResponse has been removed successfully",
|
||||
new HttpHeaders(), HttpStatus.ACCEPTED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all messages of given key-uuid
|
||||
@@ -52,28 +37,23 @@ public class KlausServiceImpl implements KlausService {
|
||||
* @return List of {@link MockedMessageDto}
|
||||
*/
|
||||
@Override
|
||||
public List<MockedMessageDto> getAllMockedResponses(UUID clientUUID){
|
||||
Optional<List<MockedMessage>> listOptional = mockedResponseRepository.findAllByClientUUID(clientUUID);
|
||||
log.info("Messages for UUID: "+clientUUID+" has been fetched from DB.");
|
||||
return listOptional.map(mockedMessages -> mockedMessages.stream()
|
||||
.map(mockedMessageMapper::mockedMessageToMockedMessageDto)
|
||||
.collect(Collectors.toList())).orElse(List.of());
|
||||
public Optional<MockedMessageDto> getMockedMessageByClientUUID(UUID clientUUID){
|
||||
Optional<MockedMessage> mockedMessageOptional = mockedResponseRepository.findAllByClientUUID(clientUUID);
|
||||
log.info("Message for UUID: "+clientUUID+" has been fetched from DB.");
|
||||
return mockedMessageMapper.optionalMockedMessageToOptionalMockedMessageDTO(mockedMessageOptional);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@link MockedMessageDto} of given id and key-uuid. If message doesn't then empty message is returned
|
||||
* @param clientUUID the key-uuid of given set of messages
|
||||
* @param mockedResponseId unique id of given message
|
||||
* @return {@link MockedMessageDto} object
|
||||
*/
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public MockedMessageDto getMockedResponse(UUID clientUUID, int mockedResponseId){
|
||||
String key = clientUUID.toString() + "_" + mockedResponseId;
|
||||
Optional<MockedMessage> optionalMockedMessage = mockedResponseRepository.findById(key);
|
||||
public MockedMessageDto getMockedResponse(UUID clientUUID){
|
||||
Optional<MockedMessage> optionalMockedMessage = mockedResponseRepository.findById(clientUUID);
|
||||
MockedMessageDto mockedMessageDto = MockedMessageDto.builder()
|
||||
.clientUUID(clientUUID)
|
||||
.mockedResponseId(mockedResponseId)
|
||||
.build();
|
||||
if (optionalMockedMessage.isPresent()) {
|
||||
mockedMessageDto = mockedMessageMapper.mockedMessageToMockedMessageDto(optionalMockedMessage.get());
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package com.r11.tools.service;
|
||||
|
||||
import com.r11.tools.controller.RequestHistoryController;
|
||||
import com.r11.tools.model.HistoryRequestModel;
|
||||
import com.r11.tools.model.RequestHistory;
|
||||
import com.r11.tools.model.RequestHistoryDTO;
|
||||
import java.util.List;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Spring service interface for {@link RequestHistoryController}
|
||||
* @author Rafał Żukowicz
|
||||
@@ -15,9 +15,9 @@ import org.springframework.stereotype.Service;
|
||||
public interface RequestHistoryService {
|
||||
/**
|
||||
* Searches for {@link RequestHistory} objects between date brackets
|
||||
* @param historyRequestModel object containing required data for request
|
||||
* @param uuid user uuid
|
||||
* @return list of {@link RequestHistory}
|
||||
*/
|
||||
List<RequestHistory> getHistoryRecordsBetweenDatesAndByUUIDAndMessageId(HistoryRequestModel historyRequestModel);
|
||||
List<RequestHistory> getHistoryRecordsByUUID(String uuid);
|
||||
void saveRequest(RequestHistoryDTO requestDTO);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.r11.tools.service;
|
||||
|
||||
import com.r11.tools.controller.RequestHistoryController;
|
||||
import com.r11.tools.mappers.RequestHistoryMapper;
|
||||
import com.r11.tools.model.HistoryRequestModel;
|
||||
import com.r11.tools.model.RequestHistory;
|
||||
import com.r11.tools.model.RequestHistoryDTO;
|
||||
import com.r11.tools.repository.RequestHistoryRepository;
|
||||
@@ -11,7 +10,6 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Spring Service for {@link RequestHistoryController}. Contains logic required for quering
|
||||
@@ -26,29 +24,11 @@ public class RequestHistoryServiceImpl implements RequestHistoryService {
|
||||
private final RequestHistoryRepository repository;
|
||||
private final RequestHistoryMapper requestMapper;
|
||||
|
||||
/**
|
||||
* in order to create query via{@link com.r11.tools.repository.RequestHistoryRepository}
|
||||
* @param historyRequestModel object containing required data for request
|
||||
* @return list of {@link RequestHistory}
|
||||
*/
|
||||
@Override
|
||||
public List<RequestHistory> getHistoryRecordsBetweenDatesAndByUUIDAndMessageId(HistoryRequestModel historyRequestModel) {
|
||||
List<RequestHistory> history = repository.findAllByClientUUIDAndMessageID(
|
||||
historyRequestModel.getClientUUID().toString(),
|
||||
historyRequestModel.getMockedResponseId()
|
||||
);
|
||||
public List<RequestHistory> getHistoryRecordsByUUID(String uuid) {
|
||||
List<RequestHistory> history = repository.findAllByClientUUID(uuid);
|
||||
Collections.sort(history);
|
||||
|
||||
return history.stream()
|
||||
.filter( historyRecord -> historyRecord
|
||||
.getDateTimeStamp()
|
||||
.isAfter(historyRequestModel.getLocalDateTimeFrom())
|
||||
).filter(
|
||||
historyRecord-> historyRecord
|
||||
.getDateTimeStamp()
|
||||
.isBefore(historyRequestModel.getLocalDateTimeTo())
|
||||
)
|
||||
.collect(Collectors.toList());
|
||||
return history;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -63,10 +63,6 @@ body {
|
||||
width: 90%;
|
||||
}
|
||||
|
||||
.tool.extended .tool-context {
|
||||
width: 75%;
|
||||
}
|
||||
|
||||
.tool.extended .tool-extention {
|
||||
width: 20%;
|
||||
padding-top: 2%;
|
||||
|
||||
@@ -83,12 +83,21 @@ function changeActiveTools(activeCategoryButton) {
|
||||
* @returns {void}
|
||||
*/
|
||||
function changeTool(tool) {
|
||||
if (tools.has(tool)) {
|
||||
const url = tools.get(tool);
|
||||
document.location.search = tool + "/";
|
||||
localStorage.setItem("lastPage", tool);
|
||||
document.getElementById("iframe").src = url;
|
||||
if (! tools.has(tool)) return;
|
||||
const url = tools.get(tool);
|
||||
localStorage.setItem("lastPage", tool);
|
||||
|
||||
switch (tool) { // XML category is default.
|
||||
case "jsonform":
|
||||
changeActiveTools('JSON');
|
||||
break;
|
||||
case "mock":
|
||||
changeActiveTools('REST');
|
||||
break;
|
||||
|
||||
}
|
||||
document.location.search = tool;
|
||||
document.getElementById("iframe").src = url;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,15 +113,5 @@ function loadLastPage() {
|
||||
if (lastPage == null) {
|
||||
lastPage = "xpath";
|
||||
}
|
||||
|
||||
switch (lastPage) { // XML category is default.
|
||||
case "jsonform":
|
||||
changeActiveTools('JSON');
|
||||
break;
|
||||
case "mock":
|
||||
changeActiveTools('REST');
|
||||
break;
|
||||
|
||||
}
|
||||
document.getElementById("iframe").src = tools.get(lastPage);
|
||||
changeTool(lastPage);
|
||||
}
|
||||
@@ -2,16 +2,9 @@ var clientUUID = '';
|
||||
var advancedDisplayed = false;
|
||||
var json = {};
|
||||
var jsonIndex = 0;
|
||||
var lastId = 1;
|
||||
var htable_row = 0;
|
||||
var host = window.location.protocol + "//" + window.location.hostname + "/mock";
|
||||
var dataModified = false;
|
||||
const addMessageName = 'addMessage';
|
||||
const loadMessageName = 'changeMessage';
|
||||
const removeMessageName = 'removeMessage';
|
||||
|
||||
const C_UUID = 'mock-uuid';
|
||||
const C_ID = 'last-displayed-id';
|
||||
const C_ADV = 'advanced-mode';
|
||||
|
||||
const color_red = "#ff8f8f";
|
||||
@@ -20,9 +13,6 @@ const color_grey = "#6b6b6b";
|
||||
const setModified = function(){
|
||||
setDataModified();
|
||||
}
|
||||
const setOrigin = function(){
|
||||
setDataOrigin();
|
||||
}
|
||||
|
||||
const getUpdate = function(){
|
||||
updateData();
|
||||
@@ -30,33 +20,69 @@ const getUpdate = function(){
|
||||
const dataRefresh = function(){
|
||||
getData();
|
||||
}
|
||||
$('#btn-newtile').click(function(){callAddMessage()});
|
||||
// $('#btn-addRow').click(function(){addRow()});
|
||||
// $('#btn-save').click(getUpdate);
|
||||
|
||||
/*
|
||||
Listeners segment
|
||||
*/
|
||||
|
||||
$(document).on('change', '.data-field', setModified);
|
||||
|
||||
$('#btn-save').click(
|
||||
() => {
|
||||
disableSaveButton();
|
||||
}
|
||||
);
|
||||
|
||||
$('#btn-newRow').click(
|
||||
()=> {
|
||||
newRowInput();
|
||||
setDataModified();
|
||||
}
|
||||
);
|
||||
|
||||
/*
|
||||
Functions segment
|
||||
*/
|
||||
|
||||
function disableSaveButton(){
|
||||
$('#btn-save').removeClass('active');
|
||||
$('#btn-save').off();
|
||||
}
|
||||
|
||||
function createLink(uuid){
|
||||
var link = host + '/api/mock/r/'+uuid;
|
||||
return link;
|
||||
}
|
||||
|
||||
|
||||
function onLoad(){
|
||||
loadCookies();
|
||||
getData();
|
||||
}
|
||||
|
||||
function getData(){
|
||||
$.getJSON(host + '/api/mock/'+clientUUID, function(data) {
|
||||
json = data;
|
||||
checkUuid();
|
||||
|
||||
|
||||
refreshData();
|
||||
loadFetchedMessage();
|
||||
initializeUUID();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function checkUuid(){
|
||||
if(clientUUID == null || clientUUID == undefined || clientUUID == ''){
|
||||
clientUUID = json[0].clientUUID;
|
||||
setCookie();
|
||||
}
|
||||
function loadCookies(){
|
||||
clientUUID = getCookie(C_UUID);
|
||||
advancedDisplayed = getCookie(C_ADV) == 'true';
|
||||
}
|
||||
|
||||
function getDomain(){
|
||||
var url = window.location.href;
|
||||
var arr = url.split("/");
|
||||
var result = arr[0] + "//" + arr[2];
|
||||
return result;
|
||||
function setCookie(){
|
||||
document.cookie = C_UUID + '=' +clientUUID;
|
||||
document.cookie = C_ADV + '=' + advancedVisibility;
|
||||
}
|
||||
|
||||
function initializeUUID(){
|
||||
if(clientUUID == null || clientUUID == undefined || clientUUID == ''){
|
||||
clientUUID = json.clientUUID;
|
||||
setCookie();
|
||||
}
|
||||
}
|
||||
|
||||
function httpStatusInvalid(){
|
||||
@@ -71,56 +97,9 @@ function setDataModified(){
|
||||
document.getElementById("httpStatus").style.backgroundColor = color_red;
|
||||
return;
|
||||
}
|
||||
dataModified = true;
|
||||
$('#btn-save').addClass('active');
|
||||
$('#btn-save').click(getUpdate);
|
||||
document.getElementById("httpStatus").style.backgroundColor = null;
|
||||
}
|
||||
|
||||
//Adding change listener to fields
|
||||
$('.data-field').change(setModified);
|
||||
|
||||
function setDataOrigin(){
|
||||
dataModified = false;
|
||||
$('#btn-save').removeClass('active');
|
||||
$('#btn-save').off();
|
||||
}
|
||||
|
||||
const idToDisplay = function(){
|
||||
let defaultId = json[0].mockedResponseId;
|
||||
if(lastId == undefined || lastId == null) return defaultId;
|
||||
for(let i=0; i<json.length; i++){
|
||||
if(json[i].mockedResponseId == lastId){
|
||||
return lastId;
|
||||
}
|
||||
}
|
||||
if(jsonIndex <= json.length && jsonIndex > 0){
|
||||
jsonIndex -= 1;
|
||||
return json[jsonIndex].mockedResponseId;
|
||||
}
|
||||
return defaultId;
|
||||
}
|
||||
|
||||
function refreshData(){
|
||||
$("#uuid-input").val(clientUUID);
|
||||
fillMessageList();
|
||||
|
||||
let id = idToDisplay();
|
||||
|
||||
loadMessage(id);
|
||||
|
||||
}
|
||||
|
||||
function setCookie(){
|
||||
document.cookie = C_UUID + '=' +clientUUID;
|
||||
document.cookie = C_ID + '=' + lastId;
|
||||
document.cookie = C_ADV + '=' + advancedVisibility;
|
||||
}
|
||||
|
||||
function loadCookies(){
|
||||
clientUUID = getCookie(C_UUID);
|
||||
lastId = getCookie(C_ID);
|
||||
advancedDisplayed = getCookie(C_ADV) == 'true';
|
||||
$('#btn-save').addClass('active');
|
||||
$('#btn-save').click(getUpdate);
|
||||
document.getElementById("httpStatus").style.backgroundColor = null;
|
||||
}
|
||||
|
||||
function getCookie(cname) {
|
||||
@@ -139,28 +118,10 @@ function getCookie(cname) {
|
||||
return '';
|
||||
}
|
||||
|
||||
function callMethodByName(methodObject){
|
||||
let name = methodObject.name;
|
||||
let id = methodObject.id;
|
||||
switch(name){
|
||||
case addMessageName:
|
||||
addMessage();
|
||||
break;
|
||||
case loadMessageName:
|
||||
loadMessage(id);
|
||||
break;
|
||||
case removeMessageName:
|
||||
removeMessage(id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function updateData(){
|
||||
var updatedJson = generateJson();
|
||||
var updatedJson = createRequestBody();
|
||||
const dataSaved = function () {
|
||||
setDataOrigin();
|
||||
refreshData();
|
||||
loadFetchedMessage();
|
||||
savedModalDisplay();
|
||||
}
|
||||
$.ajax({
|
||||
@@ -169,159 +130,27 @@ function updateData(){
|
||||
data: JSON.stringify(updatedJson, null, 2),
|
||||
contentType: "application/json",
|
||||
}).done(dataSaved);
|
||||
disableSaveButton();
|
||||
}
|
||||
|
||||
function callAddMessage(){
|
||||
if(dataModified){
|
||||
setMethodToCall(addMessageName, null);
|
||||
dataLossModalDisplay();
|
||||
}
|
||||
else {
|
||||
addMessage();
|
||||
}
|
||||
function loadFetchedMessage(){
|
||||
fillStaticFields(
|
||||
json.clientUUID,
|
||||
json.contentType,
|
||||
json.messageBody,
|
||||
json.httpStatus);
|
||||
fillHeaderTable(json.httpHeaders);
|
||||
initializeHistory();
|
||||
refreshHeaderTable(document.innerHTML);
|
||||
}
|
||||
|
||||
function addMessage(){
|
||||
$.ajax({
|
||||
url: host + '/api/mock/'+clientUUID,
|
||||
type: 'POST',
|
||||
}).done(dataRefresh);
|
||||
}
|
||||
|
||||
function callRemoveMessage(id){
|
||||
if(dataModified){
|
||||
setMethodToCall(removeMessageName, id);
|
||||
dataLossModalDisplay();
|
||||
}
|
||||
else {
|
||||
removeMessage(id);
|
||||
}
|
||||
}
|
||||
|
||||
function removeMessage(id){
|
||||
var jsonObject = findJsonById(id);
|
||||
$.ajax({
|
||||
url: host + '/api/mock/'+clientUUID + '/' + id,
|
||||
type: 'DELETE',
|
||||
}).done(dataRefresh);
|
||||
}
|
||||
|
||||
|
||||
function clearMock(){
|
||||
fillStaticFields('','','','');
|
||||
htable_row = 0;
|
||||
$('#httpStatusValues').html('');
|
||||
}
|
||||
|
||||
function initializeMock(index){
|
||||
clearMock();
|
||||
fillStaticFields(json[index].clientUUID
|
||||
, json[index].mockedResponseId
|
||||
, json[index].mediaType
|
||||
, json[index].messageBody
|
||||
, json[index].httpStatus);
|
||||
fillHeaderTable(json[index].httpHeaders);
|
||||
}
|
||||
|
||||
function fillStaticFields(uuid, id, mediaType, body, httpStatus){
|
||||
let link = createLink(uuid,id);
|
||||
function fillStaticFields(uuid, contentType, body, httpStatus){
|
||||
let link = createLink(uuid);
|
||||
let linkHtml = '<a class="hyperlink" target="_blank" href="'+link+'">'+link+'</a>';
|
||||
$('#messageLink').html(linkHtml);
|
||||
$('#httpStatus').val(httpStatus);
|
||||
$('#uuid-input').val(uuid);
|
||||
$('#typeSelector').val(mediaType);
|
||||
$('#typeSelector').val(contentType);
|
||||
$('#bodyEditor').val(body);
|
||||
$('#mockedMessageId').html(id);
|
||||
|
||||
}
|
||||
|
||||
function changeEditionOfUUID(element){
|
||||
|
||||
var inputFieldId= "#uuid-input"
|
||||
var inputFieldDiv = "#uuid-edit-field"
|
||||
if(element.checked){
|
||||
$(inputFieldId).removeAttr('disabled');
|
||||
$(inputFieldDiv).removeClass('disabled');
|
||||
} else{
|
||||
$(inputFieldId).attr('disabled', true);
|
||||
$(inputFieldDiv).addClass('disabled');
|
||||
}
|
||||
}
|
||||
|
||||
function copyUUIDToClipboard(){
|
||||
navigator.clipboard.writeText( document.getElementById('uuid-input').value );
|
||||
}
|
||||
|
||||
|
||||
async function fetchUUIDCheck(givenUUID , strategy){
|
||||
var newUUID = "UUID" ;
|
||||
url = host + "/api/mock/check/";
|
||||
|
||||
switch(strategy){
|
||||
case "new":{
|
||||
await fetch(url + givenUUID+ "/", { method : "GET" })
|
||||
.then ( response => response.text() )
|
||||
.then ( data => {
|
||||
newUUID = data;
|
||||
|
||||
} )
|
||||
break;
|
||||
}
|
||||
case "restore":{
|
||||
await fetch(url + givenUUID + "/" + clientUUID + "/" , { method: "GET" })
|
||||
.then (response => response.text() )
|
||||
.then (data => {
|
||||
newUUID = data;
|
||||
|
||||
} )
|
||||
break;
|
||||
}
|
||||
}
|
||||
return newUUID ;
|
||||
}
|
||||
|
||||
function checkUUIDChars(uuid) {
|
||||
uuid.replace(/ /g,'')
|
||||
const regex = new RegExp("^[A-z0-9-]+$");
|
||||
|
||||
if(regex.test(uuid) && uuid != ""){
|
||||
return uuid ;
|
||||
}
|
||||
return "invalid";
|
||||
}
|
||||
|
||||
function changeUUID(element){
|
||||
|
||||
const uuidStrategy = $('input[name="uuid-validation-type"]:checked').val();
|
||||
const givenUUID = checkUUIDChars(element.value);
|
||||
|
||||
if( givenUUID == clientUUID ){
|
||||
$("#uuid-input").attr("disabled", true);
|
||||
uuidChangeModalDisplay("noChg");
|
||||
return;
|
||||
}
|
||||
|
||||
var newUUID = fetchUUIDCheck(givenUUID , uuidStrategy);
|
||||
var changeMessage = uuidStrategy;
|
||||
newUUID
|
||||
.then( data => {
|
||||
if (givenUUID == data) {
|
||||
changeMessage = "success";
|
||||
}
|
||||
clientUUID = data;
|
||||
$("#editable").attr("checked", false);
|
||||
|
||||
uuidChangeModalDisplay(changeMessage);
|
||||
document.cookie = C_UUID + '=' + data ;
|
||||
} )
|
||||
loadCookies();
|
||||
refreshData();
|
||||
}
|
||||
|
||||
|
||||
function createLink(uuid, id){
|
||||
var link = host + '/api/mock/r/'+uuid+'/'+id;
|
||||
return link;
|
||||
}
|
||||
|
||||
function fillHeaderTable(headers){
|
||||
@@ -331,10 +160,9 @@ function fillHeaderTable(headers){
|
||||
|
||||
function refreshHeaderTable(html){
|
||||
$('#headerMapTable').html(html);
|
||||
$('.table-map').change(function(){setDataModified()});
|
||||
$('.btn-hashmap').click(function(){
|
||||
$(this).closest('tr').remove();
|
||||
setDataModified();
|
||||
$(this).closest('tr').remove();
|
||||
})
|
||||
}
|
||||
|
||||
@@ -353,19 +181,16 @@ function addRow(key, value){
|
||||
refreshHeaderTable(headersMapHtml);
|
||||
}
|
||||
|
||||
const newRowInput = function(){
|
||||
function newRowInput(){
|
||||
const hName = $('#headerKeyInput');
|
||||
const hValue = $('#headerValueInput');
|
||||
if(checkIfInputValid(hName.val()) && checkIfInputValid(hValue.val())){
|
||||
addRow(hName.val(), hValue.val());
|
||||
hName.val(null);
|
||||
hValue.val(null);
|
||||
setDataModified();
|
||||
}
|
||||
}
|
||||
|
||||
$('#btn-newRow').click(newRowInput);
|
||||
|
||||
function checkIfInputValid(input){
|
||||
return !(input == '' || input == null || input == undefined);
|
||||
}
|
||||
@@ -396,134 +221,22 @@ function buildRowHtml(key, value){
|
||||
'</tr>';
|
||||
}
|
||||
|
||||
|
||||
function fillMessageList(){
|
||||
$("#listItems").html('');
|
||||
var innerHTML = '';
|
||||
for(let i=0; i<json.length; i++){
|
||||
innerHTML += generateMessageTileHtml(json[i].mockedResponseId, json[i].httpStatus, json[i].mediaType);
|
||||
}
|
||||
$("#listItems").append(innerHTML);
|
||||
$('.tile').click(function(e) {
|
||||
var element = $(this);
|
||||
var button = element.find('.btn-tile').children().get(0);
|
||||
|
||||
if(!(button == e.target)){
|
||||
|
||||
callLoadMessage(parseInt($(this).attr('tileid')));
|
||||
}
|
||||
});
|
||||
$('.btn-tile').click(function(){
|
||||
//
|
||||
callRemoveMessage($(this).closest('.tile').attr('tileId'));
|
||||
})
|
||||
}
|
||||
|
||||
function findJsonById(id){
|
||||
return json[findJsonIndexById(id)];
|
||||
}
|
||||
|
||||
function findJsonIndexById(id){
|
||||
for(let i=0; i<json.length; i++)
|
||||
if(id == json[i].mockedResponseId) return i;
|
||||
}
|
||||
|
||||
function callLoadMessage(id){
|
||||
if(dataModified) {
|
||||
setMethodToCall(loadMessageName, id);
|
||||
dataLossModalDisplay();
|
||||
}
|
||||
else {
|
||||
loadMessage(id);
|
||||
}
|
||||
}
|
||||
|
||||
function loadMessage(id){
|
||||
if(id == null || id == undefined){
|
||||
|
||||
return;
|
||||
}
|
||||
lastId = id;
|
||||
setCookie();
|
||||
setDataOrigin();
|
||||
for(let i=0; i<json.length; i++){
|
||||
|
||||
if(id == json[i].mockedResponseId){
|
||||
jsonIndex = i;
|
||||
|
||||
initializeMock(jsonIndex);
|
||||
|
||||
selectMessage(id);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function selectMessage(id){
|
||||
const tiles = $('.tile');
|
||||
|
||||
tiles.removeClass("active");
|
||||
|
||||
$('.tile[tileid="'+id+'"]').addClass("active");
|
||||
|
||||
initializeHistory();
|
||||
refreshHeaderTable(document.innerHTML);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function generateMessageTileHtml(id, httpStatus, mediaType){
|
||||
var innerHTML = '' +
|
||||
'<div tileid="' + id + '" class="tile">' +
|
||||
'<div class="content">' +
|
||||
'<div class="display-space-between">' +
|
||||
'<div class="centered-vertically">' +
|
||||
'<p>Id: ' + id + '</p>' +
|
||||
'<p>Status: ' + httpStatus + '</p>' +
|
||||
'</div>' +
|
||||
'<div>' +
|
||||
'<button class="modification-button btn-tile"><i class="icon-cancel"></i></button>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'</div>';
|
||||
return innerHTML;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const onbuild = function(){
|
||||
loadCookies();
|
||||
getData();
|
||||
if(advancedDisplayed) {
|
||||
changeAdvancedVisibility();
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ready(onbuild);
|
||||
|
||||
function sleep(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
|
||||
|
||||
function generateJson(){
|
||||
function createRequestBody(){
|
||||
var newJson =
|
||||
{
|
||||
clientUUID: json[jsonIndex].clientUUID,
|
||||
mockedResponseId: json[jsonIndex].mockedResponseId,
|
||||
mediaType: $('#typeSelector').val(),
|
||||
clientUUID: json.clientUUID,
|
||||
contentType: $('#typeSelector').val(),
|
||||
messageBody: $('#bodyEditor').val(),
|
||||
httpStatus: $('#httpStatus').val(),
|
||||
httpHeaders: {},
|
||||
};
|
||||
newJson['httpHeaders'] = convertTableToJson();
|
||||
|
||||
json[jsonIndex] = newJson;
|
||||
json = newJson;
|
||||
return newJson;
|
||||
}
|
||||
|
||||
@@ -538,4 +251,4 @@ function convertTableToJson(){
|
||||
obj[key] = rows.eq(i).children().eq(1).children().eq(0).val();
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,40 +1,8 @@
|
||||
var historyJson = {};
|
||||
const maxIterations = 200;
|
||||
|
||||
function filterHistory(){
|
||||
var dateFrom = new Date($('#historyFrom').val() + 'T' + $('#historyTimeFrom').val());
|
||||
|
||||
var dateTo = new Date($('#historyTo').val() + 'T' + $('#historyTimeTo').val());
|
||||
|
||||
loadHistory(dateFrom, dateTo);
|
||||
}
|
||||
|
||||
const startSearch = function(){
|
||||
filterHistory();
|
||||
}
|
||||
$('#btn-searchHistory').click(startSearch);
|
||||
|
||||
function loadHistory(dateFrom, dateTo){
|
||||
|
||||
var eventRequest = {
|
||||
clientUUID : json[jsonIndex].clientUUID,
|
||||
localDateTimeFrom : dateFrom,
|
||||
localDateTimeTo : dateTo,
|
||||
mockedResponseId : json[jsonIndex].mockedResponseId
|
||||
};
|
||||
$.ajax({
|
||||
url: host + '/api/event',
|
||||
type: 'POST',
|
||||
data: JSON.stringify(eventRequest, null, 2),
|
||||
contentType: "application/json"
|
||||
}).done(function(data){
|
||||
historyJson = data;
|
||||
displayHistory();
|
||||
});
|
||||
}
|
||||
|
||||
function getLast24hHistoryData(){
|
||||
$.getJSON(host + '/api/event/' + clientUUID + '/' + lastId, function(data){
|
||||
function getHistoryData(){
|
||||
$.getJSON(host + '/api/event/' + clientUUID, function(data){
|
||||
historyJson = data;
|
||||
displayHistory();
|
||||
});
|
||||
|
||||
@@ -48,7 +48,7 @@ function showHistory(){
|
||||
|
||||
function initializeHistory(){
|
||||
historyFilter.removeClass('active');
|
||||
getLast24hHistoryData();
|
||||
getHistoryData();
|
||||
}
|
||||
|
||||
function showHeaders(){
|
||||
@@ -60,9 +60,9 @@ function showHeaders(){
|
||||
$('#headersTab').off('click');
|
||||
}
|
||||
|
||||
function showHeadersHistory(element){
|
||||
function showHeadersHistory(record){
|
||||
historyTable = '';
|
||||
headers = parseHeaders(element.id)
|
||||
headers = parseHeaders(record.id)
|
||||
headers.forEach(
|
||||
(value,key) => {
|
||||
historyTable +=
|
||||
@@ -176,7 +176,7 @@ function focusOutTip(element){
|
||||
}
|
||||
|
||||
function refreshHistoryRecords(){
|
||||
getLast24hHistoryData();
|
||||
getHistoryData();
|
||||
}
|
||||
|
||||
function hidTip(element){
|
||||
@@ -229,19 +229,5 @@ $('#btnSave').focusin(function(){focusInTip('btnSaveTip')});
|
||||
$('#btnSave').mouseleave(function(){hidTip('btnSaveTip')});
|
||||
$('#btnSave').focusout(function(){focusOutTip('btnSaveTip')});
|
||||
|
||||
$('#new-tile').mouseover(function(){showTip('btn-newTileTip');});
|
||||
$('#new-tile').mouseleave(function(){hidTip('btn-newTileTip')});
|
||||
$('#new-tile').focusout(function(){focusOutTip('btn-newTileTip')});
|
||||
|
||||
$('#listItems').mouseover(function(){showTip('messagesTip');});
|
||||
$('#listItems').mouseleave(function(){hidTip('messagesTip')});
|
||||
|
||||
|
||||
$('#uuid-edit-field').mouseover(function(){ showTip('UUIDFieldTip') });
|
||||
$('#uuid-edit-field').mouseleave(function(){ hidTip('UUIDFieldTip') });
|
||||
|
||||
$('#uuid-validation-strategy').mouseover(function(){ showTip('UUIDValidationStrategyTip') });
|
||||
$('#uuid-validation-strategy').mouseleave(function(){ hidTip('UUIDValidationStrategyTip') });
|
||||
|
||||
$('#editableBlock').mouseover( function(){ showTip('UUIDEditionTip') } );
|
||||
$('#editableBlock').mouseleave(function(){ hidTip('UUIDEditionTip') });
|
||||
$('#listItems').mouseleave(function(){hidTip('messagesTip')});
|
||||
@@ -8,7 +8,7 @@
|
||||
<link rel="stylesheet" href="../assets/css/tools/mock/common.css" type="text/css">
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<body onload="onLoad()">
|
||||
<div class="popup-flex hiddable-container">
|
||||
<div class="popup-body" id="popup-body">
|
||||
<div class="popup-button-close-container">
|
||||
@@ -43,36 +43,9 @@
|
||||
<div>
|
||||
<h1>MockedServices</h1>
|
||||
</div>
|
||||
<div>
|
||||
<label for="uuid-input" class="block-display">UUID</label>
|
||||
<div id="uuid-edit">
|
||||
<div id="uuid-edit-field" class="bordered-field disabled">
|
||||
<input id="uuid-input" disabled onfocusout="changeUUID(this);" value="UUID" />
|
||||
<button onclick="copyUUIDToClipboard();" class="uuid-inputField-icon modification-button flex-item btn-copy action-button">
|
||||
<span class="material-icons uuid-inputField-icon-span ">content_copy</span>
|
||||
</button>
|
||||
</div>
|
||||
<div id="editableBlock">
|
||||
<input type="checkbox" onchange="changeEditionOfUUID(this)" name="editable" id="editable" value="false"/>
|
||||
<label for="editable">Editable</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="hiddable" id="uuid-validation-strategy">
|
||||
<label><b>UUID generation strategy:</b></label>
|
||||
|
||||
<input type="radio" checked name="uuid-validation-type" value="new" id="generateNew"/>
|
||||
<label for="generateNew">Generate new UUID</label>
|
||||
|
||||
<input type="radio" name="uuid-validation-type" value="restore" id="restore"/>
|
||||
<label for="restore">Restore previous UUID</label>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div>
|
||||
<!-- h2 -->
|
||||
<div id="basicItemData" class="hiddable active"><h2>Your Message</h2></div>
|
||||
<div id="advancedItemData" class="hiddable"><h2>Messaged id: <span id="mockedMessageId">1</span></h2></div>
|
||||
<div><h2>Your Message</h2></div>
|
||||
|
||||
<!-- link -->
|
||||
<div>
|
||||
@@ -95,7 +68,6 @@
|
||||
<option value="404">
|
||||
<option value="500">
|
||||
</datalist>
|
||||
|
||||
</div>
|
||||
<!-- content type -->
|
||||
<div class="max-width small-vertical-margin">
|
||||
@@ -155,25 +127,7 @@
|
||||
<!-- history -->
|
||||
<div id="history" class="medium-vertical-margin tabcontent">
|
||||
<div class="block-display max-width">
|
||||
<button id="btn-history-filter" class="clickable-text highlight switch">
|
||||
<span class="toggleIndicator"></span> filter
|
||||
<button type="button" class="refresh-button" onclick="refreshHistoryRecords();" >↻</button>
|
||||
</button>
|
||||
<div id ="history-filter" class="display-space-between max-width small-vertical-margin hiddable">
|
||||
<div class="three-fourth-width display-space-evenly">
|
||||
<div class="block-display half-width with-padding">
|
||||
<label for="historyFrom" class="block-label">From</label>
|
||||
<input id="historyFrom" type="date" class="bordered-field max-width with-padding">
|
||||
<input id="historyTimeFrom" type="time" class="small-vertical-margin bordered-field max-width with-padding">
|
||||
</div>
|
||||
<div class="block-display half-width with-padding">
|
||||
<label for="historyTo" class="block-label">To</label>
|
||||
<input id="historyTo" type="date" class="bordered-field max-width with-padding">
|
||||
<input id="historyTimeTo" type="time" class="small-vertical-margin bordered-field max-width with-padding">
|
||||
</div>
|
||||
</div>
|
||||
<button id="btn-searchHistory" class="quater-width action-button active small-margins">Search</button>
|
||||
</div>
|
||||
<button type="button" class="refresh-button" onclick="refreshHistoryRecords();" >↻</button>
|
||||
|
||||
<div class="max-width centered-content large-vertical-margin overflowedTableContent">
|
||||
<table id="historyTable" class="table-default">
|
||||
@@ -195,18 +149,6 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="selectMenuContent" class="tool-extention">
|
||||
<!-- header -->
|
||||
<div>
|
||||
<h2>Message List</h2>
|
||||
</div>
|
||||
<!-- tile list -->
|
||||
<div id="listItems">
|
||||
</div>
|
||||
<div id="new-tile" class="max-width centered-content small-vertical-margin">
|
||||
<button id="btn-newtile" class="modification-button btn-addtile"><i class="icon-plus"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tooltip-window lite">
|
||||
<div>
|
||||
@@ -226,30 +168,6 @@
|
||||
<p>To save message, the message must be changed!</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="large-vertical-margin">
|
||||
<div id="btn-newTileTip" class="tip">
|
||||
<h3>Add new message</h3>
|
||||
<p>This button adds new message.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="large-vertical-margin">
|
||||
<div id="UUIDFieldTip" class="tip">
|
||||
<h3>UUID</h3>
|
||||
<p>UUID is an Unique ID that represents you in API. By UUID your messages is saved in database. You can change it to access your previous configuration of mocked messages</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="large-vertical-margin">
|
||||
<div id="UUIDValidationStrategyTip" class="tip">
|
||||
<h3>UUID Checking Strategy</h3>
|
||||
<p>When you provide invalid UUID you can choose what do with it. You can generate new UUID or restore previous.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="large-vertical-margin">
|
||||
<div id="UUIDEditionTip" class="tip">
|
||||
<h3>UUID Edition</h3>
|
||||
<p>Unlocks you ability to edit UUID</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="large-vertical-margin">
|
||||
<div id="messagesTip" class="tip">
|
||||
@@ -297,16 +215,6 @@
|
||||
</div>
|
||||
</div>
|
||||
<div id="overlay"></div>
|
||||
<div id="modal-uuidChanged" class="modal">
|
||||
<div class="header">
|
||||
<div>Change UUID info<i class="r-exclamation"></i></div>
|
||||
<button onclick="window.location.reload();">×</button>
|
||||
</div>
|
||||
<div id="changeUUIDSuccess" class="body hiddable uuid-modal-body">Your message UUID has been changed successfully.</div>
|
||||
<div id="newUUID" class="body hiddable uuid-modal-body">You provided wrong UUID! <br> New UUID has been generated!</div>
|
||||
<div id="restoredUUID" class="body hiddable uuid-modal-body">You provided wrong UUID! <br> Old UUID has been restored!</div>
|
||||
<div id="noChgUUID" class="body hiddable uuid-modal-body">You doesn't provide any change to UUID!</div>
|
||||
</div>
|
||||
<div id="modal-confirm" class="modal">
|
||||
<div class="header">
|
||||
<div>Message saved<i class="r-exclamation"></i></div>
|
||||
@@ -321,9 +229,7 @@
|
||||
</div>
|
||||
<div class="body">You haven't saved your message!<br> Do you want to save it?</div>
|
||||
<div class="function">
|
||||
|
||||
<button type = "button" onclick = "updateData()" value = "Display">Save</button>
|
||||
|
||||
<button>No</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user