diff --git a/ApiTestManager/src/APIClient.js b/ApiTestManager/src/APIClient.js
index 99cc6bd..9abaed1 100644
--- a/ApiTestManager/src/APIClient.js
+++ b/ApiTestManager/src/APIClient.js
@@ -28,35 +28,6 @@ class APIClient {
return this.contextPath + this.CLIENT_URL;
}
- async sendAPIRequest(model, preProcessCallback, consoleOutput) {
- try {
- let variables = {};
- const updatedModel = await this.executePreRequestScript(model, variables, consoleOutput);
- let processedRequest = this.replacePlaceholdersWithVariables(updatedModel, variables);
-
- if (preProcessCallback) {
- preProcessCallback(processedRequest);
- }
- const response = await this.makeAjaxRequest(processedRequest, model, consoleOutput);
- const responseData = await response.json(); // Parse the JSON response
-
- if (!response.ok) {
- const errorMessage = responseData.error || 'Unknown error';
- throw new Error(`API 호출 중 오류가 발생했습니다. 사유[${errorMessage}]`);
- }
-
- const finalResponse = this.formatResponse(responseData);
- return this.executePostRequestScript(model.postRequestScript, variables, processedRequest, finalResponse, consoleOutput).catch(error => {
- $('.toast-body').text(error);
- $('.toast').toast('show');
- return finalResponse; // Return the original response even if there's an error in the post-request script
- });
-
- } catch (error) {
- throw error;
- }
- }
-
formatResponse(data) {
// Format response as needed before post-request script
let response = {};
@@ -99,6 +70,61 @@ class APIClient {
}
}
+ async processPreScriptAndVariables(model, value, consoleOutput){
+ let variables = {};
+ const updatedModel = await this.executePreRequestScript(model, variables, consoleOutput);
+ return this.replacePlaceholderValueWithVariables(updatedModel, value, variables);
+ }
+
+ replacePlaceholderValueWithVariables(model, originalValue, variables) {
+ let mergedVariables = {};
+ _.forEach(window.globals, (value, key) => {
+ mergedVariables[key] = value;
+ });
+
+ if (variables) {
+ _.forEach(variables, (value, key) => {
+ mergedVariables[key] = value;
+ });
+ }
+
+ _.forEach(mergedVariables, (value, key) => {
+ const placeholder = `{{${key}}}`;
+ // Replace in path
+ originalValue = originalValue.replace(new RegExp(placeholder, 'g'), value);
+ });
+ return originalValue;
+ }
+
+ async sendAPIRequest(model, preProcessCallback, consoleOutput) {
+ try {
+ let variables = {};
+ const updatedModel = await this.executePreRequestScript(model, variables, consoleOutput);
+ let processedRequest = this.replacePlaceholdersWithVariables(updatedModel, variables);
+
+ if (preProcessCallback) {
+ preProcessCallback(processedRequest);
+ }
+ const response = await this.makeAjaxRequest(processedRequest, model, consoleOutput);
+ const responseData = await response.json(); // Parse the JSON response
+
+ if (!response.ok) {
+ const errorMessage = responseData.error || 'Unknown error';
+ throw new Error(`API 호출 중 오류가 발생했습니다. 사유[${errorMessage}]`);
+ }
+
+ const finalResponse = this.formatResponse(responseData);
+ return this.executePostRequestScript(model.postRequestScript, variables, processedRequest, finalResponse, consoleOutput).catch(error => {
+ $('.toast-body').text(error);
+ $('.toast').toast('show');
+ return finalResponse; // Return the original response even if there's an error in the post-request script
+ });
+
+ } catch (error) {
+ throw error;
+ }
+ }
+
replacePlaceholdersWithVariables(original, variables) {
let request = JSON.parse(JSON.stringify(original));
diff --git a/ApiTestManager/src/APITester.js b/ApiTestManager/src/APITester.js
index 763ec9a..682c06b 100644
--- a/ApiTestManager/src/APITester.js
+++ b/ApiTestManager/src/APITester.js
@@ -1,9 +1,10 @@
import * as monaco from 'monaco-editor';
import APIClient from './APIClient';
-import EditableInput from './components/EditableInput';
import {createPopper} from '@popperjs/core/lib/popper-lite';
-import PropertyTable from './components/PropertyTable';
import VariableSnippet from './components/VariableSnippet';
+import HTTPClientView from './components/HTTPClientView';
+import TCPClientView from './components/TCPClientView';
+import ServerManager from './components/ServerManager';
class APITester {
@@ -25,6 +26,7 @@ class APITester {
this.popperContent = document.getElementById('popperContent');
this.popperInstance = null;
this.contextPath = contextPath || '/';
+
}
getCollectionListURL() {
@@ -51,281 +53,6 @@ class APITester {
return this.contextPath + `mgmt/collections/${collectionId}/apis/delete.do`;
}
- renderServers(selectedServer) {
- const optionsHtml = this.servers.map(server => ``).join('');
-
- return ``;
- }
-
- basePath(serverId) {
- if (serverId === undefined || serverId === null || serverId === '') {
- return '';
- }
- return this.servers.filter(server => server.id == serverId)[0].basePath; // == : 타입 비교 없이 값만 비교
- }
-
- httpApiRequestTemplate(apiRequest, index) {
- return `
-
-
${apiRequest.collectionName} > ${apiRequest.name}
-
-
-
-
-
-
- ${this.renderServers(apiRequest.server)}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Response
-
-
-
-
-
- -
-
-
- -
-
-
- -
-
-
-
-
-
-
-
-
- `;
- }
-
- tcpApiRequestTemplate(apiRequest, index) {
- return `
-
-
${apiRequest.collectionName} > ${apiRequest.name}
-
-
- ${this.renderServers(apiRequest.server)}
-
-
-
-
-
-
-
-
- -
-
-
- -
-
-
- -
-
-
-
-
-
-
-
- Response
-
-
-
-
-
- -
-
-
- -
-
-
-
-
-
-
-
-
- `;
- }
-
headerTemplate(header, index) {
return `
@@ -402,6 +129,7 @@ class APITester {
$('.toast').toast('show');
}
}
+ this.serverManager = new ServerManager(this.servers);
this.bindEvents();
this.loadCollections();
}
@@ -424,8 +152,7 @@ class APITester {
{selector: '.delete_api_request', action: this.showDeleteApiRequestModal.bind(this)},
{selector: '.open_api_request', action: this.openApiRequest.bind(this)},
{selector: '.confirm_delete_api', action: this.deleteApiRequest.bind(this)},
- {selector: '.close_tab', action: this.closeTab.bind(this)}
- ];
+ {selector: '.close_tab', action: this.closeTab.bind(this)}];
for (let event of events) {
$(document).on('click', event.selector, event.action);
@@ -601,7 +328,7 @@ class APITester {
const tabIndex = $('#apiRequestTabContent').children().index($(event.currentTarget).closest('.api_request'));
let model = this.apiRequests[tabIndex];
let target = $('#api_request_' + model.id);
- target.find('input[name="basePath"]').val(this.basePath(model.server));
+ target.find('input[name="basePath"]').val(this.serverManager.basePath(model.server));
}
renderHeaders(headers) {
@@ -633,12 +360,10 @@ class APITester {
placement: 'bottom', // Popper below the element
modifiers: [
{
- name: 'offset',
- options: {
+ name: 'offset', options: {
offset: [0, 8] // Adjust the position if needed
}
- }
- ]
+ }]
});
}
@@ -655,87 +380,36 @@ class APITester {
let apiRequestTabContent = $(this.apiTabContentTarget);
let model = this.apiRequests[index];
- if (model.type ==='HTTP'){
- apiRequestTabContent.append(this.httpApiRequestTemplate(model, index));
- let editableInput = new EditableInput({
- name: 'path',
- value: model.path
- });
-
- let queryParamTable = new PropertyTable({
- propertyName: 'queryParams',
- properties: model.queryParams
- });
-
- let headerTable = new PropertyTable({
- propertyName: 'headers',
- properties: model.headers
- });
-
- apiRequestTabContent.find(`#api_request_${model.id}`).find('.api_request_info').find('.path').each(function() {
- editableInput.init(this, (value) => {
- model.path = value;
- model.queryParams = me.parseParam(model.path);
- queryParamTable.setProperties(model.queryParams);
- $('span.variable').off('mouseover');
- $('span.variable').off('mouseout');
- document.querySelectorAll('span.variable').forEach(element => {
- let text = element.innerText;
- element.addEventListener('mouseover', () => me.showPopper(element, text));
- element.addEventListener('mouseout', () => me.hidePopper(element));
- });
- });
-
- $(this).append(``);
-
- $('span.variable').off('mouseover');
- $('span.variable').off('mouseout');
- });
- queryParamTable.init(apiRequestTabContent.find(`#api_request_${model.id}`).find('.query_params')[0], (properties) => {
- model.queryParams = properties;
- console.log(model.queryParams);
- this.buildPath(model);
- editableInput.setValue(model.path);
- $('span.variable').off('mouseover');
- $('span.variable').off('mouseout');
- document.querySelectorAll('span.variable').forEach(element => {
- let text = element.innerText;
- element.addEventListener('mouseover', () => me.showPopper(element, text));
- element.addEventListener('mouseout', () => me.hidePopper(element));
- });
- });
-
- headerTable.init(apiRequestTabContent.find(`#api_request_${model.id}`).find('.request_headers')[0], (properties) => {
- model.headers = properties;
- $('span.variable').off('mouseover');
- $('span.variable').off('mouseout');
- document.querySelectorAll('span.variable').forEach(element => {
- let text = element.innerText;
- element.addEventListener('mouseover', () => me.showPopper(element, text));
- element.addEventListener('mouseout', () => me.hidePopper(element));
- });
- });
- }
-
- if (model.type ==='TCP'){
- apiRequestTabContent.append(this.tcpApiRequestTemplate(model, index));
- }
-
document.querySelectorAll('.variable').forEach(element => {
let text = element.innerText;
element.addEventListener('mouseover', () => me.showPopper(element, text));
element.addEventListener('mouseout', () => me.hidePopper(element));
});
+ let language = model.type === 'HTTP' ? 'json' : 'text';
- this.openTab(model.id);
- let target = $('#api_request_' + model.id);
- let language = model.type ==='TCP'? 'text': 'json';
+ let target = null;
+ let requestBodyEditor = null;
- let requestBodyEditor = monaco.editor.create(target.find('.request_body')[0], {
- value: model.requestBody,
- language: language,
- automaticLayout: true
- });
+ if (model.type === 'HTTP') {
+ let httpClientView = new HTTPClientView(me, this.serverManager, apiRequestTabContent, model);
+ httpClientView.init();
+ this.openTab(model.id);
+ target = $('#api_request_' + model.id);
+ requestBodyEditor = monaco.editor.create(target.find('.request_body')[0], {
+ value: model.requestBody, language: 'json', automaticLayout: true
+ });
+ }
+
+ if (model.type === 'TCP') {
+ const tcpClientView = new TCPClientView(me, this.serverManager, apiRequestTabContent, model);
+ tcpClientView.init();
+ this.openTab(model.id);
+ target = $('#api_request_' + model.id);
+ requestBodyEditor = monaco.editor.create(target.find('.request_body')[0], {
+ value: model.requestBody, language: 'text', automaticLayout: false
+ });
+ tcpClientView.setRequestBodyEditor(requestBodyEditor);
+ }
requestBodyEditor.onMouseMove((e) => {
let position = e.target.position;
@@ -768,27 +442,19 @@ class APITester {
});
let responseBodyEditor = monaco.editor.create(target.find('.response_body')[0], {
- value: '',
- language: language,
- automaticLayout: true,
- quickSuggestions: false
+ value: '', language: language, automaticLayout: true, quickSuggestions: false
});
me.responseEditors.push(responseBodyEditor);
let consoleEditor = monaco.editor.create(target.find('.console')[0], {
- value: '',
- automaticLayout: true,
- quickSuggestions: false
+ value: '', automaticLayout: true, quickSuggestions: false
});
me.consoleEditors.push(consoleEditor);
let preRequestEditor = monaco.editor.create(target.find('.pre-request')[0], {
- value: model.preRequestScript,
- language: 'javascript',
- automaticLayout: true,
- quickSuggestions: false
+ value: model.preRequestScript, language: 'javascript', automaticLayout: true, quickSuggestions: false
});
const snippet1 = new VariableSnippet();
@@ -804,10 +470,7 @@ class APITester {
});
let postRequestEditor = monaco.editor.create(target.find('.post-request')[0], {
- value: model.postRequestScript,
- language: 'javascript',
- automaticLayout: true,
- quickSuggestions: false
+ value: model.postRequestScript, language: 'javascript', automaticLayout: true, quickSuggestions: false
});
const snippet2 = new VariableSnippet();
@@ -874,12 +537,10 @@ class APITester {
}
$('li .api_request_sortable').draggable({
- helper: this.customHelper,
- start: function(event, ui) {
+ helper: this.customHelper, start: function(event, ui) {
// You can add any additional data or styles you want when dragging starts
$(this).addClass('dragging');
- },
- stop: function(event, ui) {
+ }, stop: function(event, ui) {
// Clean up, e.g., remove styles or data
$(this).removeClass('dragging');
}
@@ -907,9 +568,7 @@ class APITester {
const tabIndex = $('#apiRequestTabContent').children().index($(event.currentTarget).closest('.api_request'));
let model = this.apiRequests[tabIndex];
model.headers.push({
- enabled: true,
- key: '',
- value: ''
+ enabled: true, key: '', value: ''
});
this.renderHeaderView(tabIndex);
}
@@ -938,32 +597,14 @@ class APITester {
let queryParam = queryParamArray[i].split('=');
queryParams.push({
- enabled: true,
- key: queryParam[0],
- value: (queryParam[1] === undefined ? '' : queryParam[1])
+ enabled: true, key: queryParam[0], value: (queryParam[1] === undefined ? '' : queryParam[1])
});
}
}
+ console.log(queryParams);
return queryParams;
}
- buildPath(model) {
- let queryString = model.path.split('?')[0];
- if (model.queryParams.length > 0) {
- queryString += '?';
- }
- for (let i = 0; i < model.queryParams.length; i++) {
- if (!model.queryParams[i].enabled) {
- continue;
- }
- queryString += model.queryParams[i].key + '=' + model.queryParams[i].value;
- if (i < model.queryParams.length - 1) {
- queryString += '&';
- }
- }
- model.path = queryString;
- }
-
showLoadingOverlay() {
$('#loading-overlay').show();
}
@@ -998,11 +639,7 @@ class APITester {
model.responseModel.time = endTime - startTime;
} else {
model.responseModel = {
- status: 0,
- time: 0,
- size: 0,
- headers: [],
- body: ''
+ status: 0, time: 0, size: 0, headers: [], body: ''
};
}
@@ -1022,10 +659,7 @@ class APITester {
message = JSON.stringify(message, null, 2);
}
var op = {
- identifier: id,
- range: range,
- text: message + '\n',
- forceMoveMarkers: true
+ identifier: id, range: range, text: message + '\n', forceMoveMarkers: true
};
console.executeEdits('my-source', [op]);
}
@@ -1033,23 +667,18 @@ class APITester {
loadCollections() {
const me = this;
this.currentAjaxRequest = $.ajax({
- url: this.getCollectionListURL(),
- type: 'GET',
- contentType: 'application/json',
- success: function(data) {
+ url: this.getCollectionListURL(), type: 'GET', contentType: 'application/json', success: function(data) {
me.collections = data.map(collection => {
if (collection.apis) {
collection.apis = collection.apis.map(api => ({...api, collectionId: collection.id}));
}
return collection;
});
- },
- error: function(response, textStatus, errorThrown) {
+ }, error: function(response, textStatus, errorThrown) {
me.hideLoadingOverlay();
$('.toast-body').text(response.responseJSON.error);
$('.toast').toast('show');
- },
- complete: function() {
+ }, complete: function() {
me.renderCollections();
me.hideLoadingOverlay();
}
@@ -1061,16 +690,11 @@ class APITester {
const me = this;
me.showLoadingOverlay();
this.currentAjaxRequest = $.ajax({
- url: this.getCollectionCreateURL(),
- type: 'POST',
- contentType: 'application/json',
- data: JSON.stringify({name: name}),
- error: function(response, textStatus, errorThrown) {
+ url: this.getCollectionCreateURL(), type: 'POST', contentType: 'application/json', data: JSON.stringify({name: name}), error: function(response, textStatus, errorThrown) {
me.hideLoadingOverlay();
$('.toast-body').text(response.responseJSON.error);
$('.toast').toast('show');
- },
- complete: function() {
+ }, complete: function() {
me.loadCollections();
me.hideLoadingOverlay();
$('#new_collection_modal').modal('hide');
@@ -1082,16 +706,11 @@ class APITester {
const me = this;
me.showLoadingOverlay();
this.currentAjaxRequest = $.ajax({
- url: this.getCollectionUpdateURL(),
- type: 'POST',
- contentType: 'application/json',
- data: JSON.stringify({id: id, name: name}),
- error: function(response, textStatus, errorThrown) {
+ url: this.getCollectionUpdateURL(), type: 'POST', contentType: 'application/json', data: JSON.stringify({id: id, name: name}), error: function(response, textStatus, errorThrown) {
me.hideLoadingOverlay();
$('.toast-body').text(response.responseJSON.error);
$('.toast').toast('show');
- },
- complete: function() {
+ }, complete: function() {
me.loadCollections();
me.hideLoadingOverlay();
$('#new_collection_modal').modal('hide');
@@ -1104,18 +723,12 @@ class APITester {
const me = this;
me.showLoadingOverlay();
this.currentAjaxRequest = $.ajax({
- url: this.getCollectionDeleteURL(),
- type: 'POST',
- contentType: 'application/json',
- data: JSON.stringify({id: collectionId}),
- success: function() {
- },
- error: function(response, textStatus, errorThrown) {
+ url: this.getCollectionDeleteURL(), type: 'POST', contentType: 'application/json', data: JSON.stringify({id: collectionId}), success: function() {
+ }, error: function(response, textStatus, errorThrown) {
me.hideLoadingOverlay();
$('.toast-body').text(response.responseJSON.error);
$('.toast').toast('show');
- },
- complete: function() {
+ }, complete: function() {
me.loadCollections();
me.hideLoadingOverlay();
$('#confirm_delete_modal').modal('hide');
@@ -1127,21 +740,15 @@ class APITester {
const me = this;
me.showLoadingOverlay();
this.currentAjaxRequest = $.ajax({
- url: this.getAPISaveURL(model.collectionId),
- type: 'POST',
- contentType: 'application/json',
- data: JSON.stringify(model),
- success: function(data) {
+ url: this.getAPISaveURL(model.collectionId), type: 'POST', contentType: 'application/json', data: JSON.stringify(model), success: function(data) {
let message = '저장되었습니다.';
$('.toast-body').text(message);
$('.toast').toast('show');
- },
- error: function(response, textStatus, errorThrown) {
+ }, error: function(response, textStatus, errorThrown) {
me.hideLoadingOverlay();
$('.toast-body').text(response.responseJSON.error);
$('.toast').toast('show');
- },
- complete: function() {
+ }, complete: function() {
me.hideLoadingOverlay();
}
});
@@ -1154,21 +761,15 @@ class APITester {
me.showLoadingOverlay();
this.currentAjaxRequest = $.ajax({
- url: this.getAPISaveURL(model.collectionId),
- type: 'POST',
- contentType: 'application/json',
- data: JSON.stringify(model),
- success: function(data) {
+ url: this.getAPISaveURL(model.collectionId), type: 'POST', contentType: 'application/json', data: JSON.stringify(model), success: function(data) {
let message = '저장되었습니다.';
$('.toast-body').text(message);
$('.toast').toast('show');
- },
- error: function(response, textStatus, errorThrown) {
+ }, error: function(response, textStatus, errorThrown) {
me.hideLoadingOverlay();
$('.toast-body').text(response.responseJSON.error);
$('.toast').toast('show');
- },
- complete: function() {
+ }, complete: function() {
me.hideLoadingOverlay();
}
});
@@ -1190,42 +791,26 @@ class APITester {
})[0];
let me = this;
let newApi = {
- id: '',
- server: null,
- method: 'GET',
- name: newApiName,
- path: '',
- type : newApiType,
- headers: [],
- queryParams: [],
- requestBody: '',
- preRequestScript: '',
- postRequestScript: '',
- collectionId: collectionId,
- responseModel: {
- status: 0,
- time: 0,
- size: 0,
- headers: [],
- ody: ''
+ id: '', server: null, method: 'GET', name: newApiName, path: '', type: newApiType, headers: [], queryParams: [], requestBody: '', preRequestScript: '', postRequestScript: '', collectionId: collectionId, responseModel: {
+ status: 0, time: 0, size: 0, headers: [], ody: ''
}
};
newApi.collectionName = collection.name;
+ if (newApiType === 'TCP') {
+ newApi.layout = [];
+ newApi.layout.push({layoutItems: []});
+ }
+
+
this.currentAjaxRequest = $.ajax({
- url: this.getAPISaveURL(collectionId),
- type: 'POST',
- contentType: 'application/json',
- data: JSON.stringify(newApi),
- success: function(data) {
+ url: this.getAPISaveURL(collectionId), type: 'POST', contentType: 'application/json', data: JSON.stringify(newApi), success: function(data) {
newApi.id = data;
- },
- error: function(response, textStatus, errorThrown) {
+ }, error: function(response, textStatus, errorThrown) {
me.hideLoadingOverlay();
$('.toast-body').text(response.responseJSON.error);
$('.toast').toast('show');
- },
- complete: function() {
+ }, complete: function() {
me.loadCollections();
me.apiRequests.push(newApi);
me.currentIndex = me.apiRequests.length - 1;
@@ -1271,11 +856,7 @@ class APITester {
if (!selectedApi.responseModel) {
selectedApi.responseModel = {
- status: 0,
- time: 0,
- size: 0,
- headers: [],
- body: ''
+ status: 0, time: 0, size: 0, headers: [], body: ''
};
}
@@ -1305,17 +886,11 @@ class APITester {
}
const me = this;
this.currentAjaxRequest = $.ajax({
- url: this.getAPIDeleteURL(collectionId),
- type: 'POST',
- contentType: 'application/json',
- data: JSON.stringify({id: apiId}),
- success: function(data) {
- },
- error: function(response, textStatus, errorThrown) {
+ url: this.getAPIDeleteURL(collectionId), type: 'POST', contentType: 'application/json', data: JSON.stringify({id: apiId}), success: function(data) {
+ }, error: function(response, textStatus, errorThrown) {
$('.toast-body').text(response.responseJSON.error);
me.hideLoadingOverlay();
- },
- complete: function() {
+ }, complete: function() {
me.hideLoadingOverlay();
me.loadCollections();
$('#confirm_delete_api_modal').modal('hide');
diff --git a/ApiTestManager/src/components/HTTPClientView.js b/ApiTestManager/src/components/HTTPClientView.js
new file mode 100644
index 0000000..86501de
--- /dev/null
+++ b/ApiTestManager/src/components/HTTPClientView.js
@@ -0,0 +1,255 @@
+import EditableInput from './EditableInput';
+import PropertyTable from './PropertyTable';
+
+class HTTPClientView {
+ constructor(parent, serverManager, apiRequestTabContent, model, index) {
+ this.parent = parent;
+ this.serverManager = serverManager;
+ this.apiRequestTabContent = apiRequestTabContent;
+ this.model = model;
+ this.index = index;
+ }
+
+ init() {
+ let me = this;
+ this.apiRequestTabContent.append(this.httpApiRequestTemplate(this.model, this.index));
+ let editableInput = new EditableInput({
+ name: 'path',
+ value: this.model.path
+ });
+ let queryParamTable = new PropertyTable({
+ propertyName: 'queryParams',
+ properties: this.model.queryParams
+ });
+
+ let headerTable = new PropertyTable({
+ propertyName: 'headers',
+ properties: this.model.headers
+ });
+
+ this.apiRequestTabContent.find(`#api_request_${this.model.id}`).find('.api_request_info').find('.path').each(function() {
+ editableInput.init(this, (value) => {
+ me.model.path = value;
+ me.model.queryParams = me.parent.parseParam(me.model.path);
+ queryParamTable.setProperties(me.model.queryParams);
+ $('span.variable').off('mouseover');
+ $('span.variable').off('mouseout');
+ document.querySelectorAll('span.variable').forEach(element => {
+ let text = element.innerText;
+ element.addEventListener('mouseover', () => this.parent.showPopper(element, text));
+ element.addEventListener('mouseout', () => this.parent.hidePopper(element));
+ });
+ });
+
+ $(this).append(``);
+
+ $('span.variable').off('mouseover');
+ $('span.variable').off('mouseout');
+ });
+
+ queryParamTable.init(this.apiRequestTabContent.find(`#api_request_${this.model.id}`).find('.query_params')[0], (properties) => {
+ this.model.queryParams = properties;
+ console.log(this.model.queryParams);
+ this.buildPath(this.model);
+ editableInput.setValue(this.model.path);
+ $('span.variable').off('mouseover');
+ $('span.variable').off('mouseout');
+ document.querySelectorAll('span.variable').forEach(element => {
+ let text = element.innerText;
+ element.addEventListener('mouseover', () => this.parent.showPopper(element, text));
+ element.addEventListener('mouseout', () => this.parent.hidePopper(element));
+ });
+ });
+
+ headerTable.init(this.apiRequestTabContent.find(`#api_request_${this.model.id}`).find('.request_headers')[0], (properties) => {
+ this.model.headers = properties;
+ $('span.variable').off('mouseover');
+ $('span.variable').off('mouseout');
+ document.querySelectorAll('span.variable').forEach(element => {
+ let text = element.innerText;
+ element.addEventListener('mouseover', () => this.parent.showPopper(element, text));
+ element.addEventListener('mouseout', () => this.parent.hidePopper(element));
+ });
+ });
+
+ }
+
+ buildPath(model) {
+ let queryString = model.path.split('?')[0];
+ if (model.queryParams.length > 0) {
+ queryString += '?';
+ }
+ for (let i = 0; i < model.queryParams.length; i++) {
+ if (!model.queryParams[i].enabled) {
+ continue;
+ }
+ queryString += model.queryParams[i].key + '=' + model.queryParams[i].value;
+ if (i < model.queryParams.length - 1) {
+ queryString += '&';
+ }
+ }
+ model.path = queryString;
+ }
+
+ httpApiRequestTemplate(apiRequest, index) {
+ return `
+
+
${apiRequest.collectionName} > ${apiRequest.name}
+
+
+
+
+
+
+ ${this.serverManager.renderHttpServers(apiRequest.server)}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Response
+
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+
+
+
+ `;
+ }
+}
+
+export default HTTPClientView;
diff --git a/ApiTestManager/src/components/ServerManager.js b/ApiTestManager/src/components/ServerManager.js
new file mode 100644
index 0000000..6836d1a
--- /dev/null
+++ b/ApiTestManager/src/components/ServerManager.js
@@ -0,0 +1,44 @@
+class ServerManager {
+ constructor(servers) {
+ this.servers = servers ||[];
+ }
+
+ basePath(serverId) {
+ if (serverId === undefined || serverId === null || serverId === '') {
+ return '';
+ }
+ return this.servers.filter(server => server.id == serverId)[0].basePath; // == : 타입 비교 없이 값만 비교
+ }
+
+ getServer(serverId) {
+ return this.servers.filter(server => server.id == serverId)[0];
+ }
+
+ renderServers(selectedServer) {
+ const optionsHtml = this.servers.map(server => ``).join('');
+
+ return ``;
+ }
+
+ renderTcpServers(selectedServer) {
+ const optionsHtml = this.servers.filter( server => server.scheme === 'tcp')
+ .map(server => ``).join('');
+
+ return ``;
+ }
+
+ renderHttpServers(selectedServer) {
+ const optionsHtml = this.servers.filter( server => server.scheme !== 'tcp')
+ .map(server => ``).join('');
+
+ return ``;
+ }
+}
+
+export default ServerManager;
diff --git a/ApiTestManager/src/components/TCPClientView.js b/ApiTestManager/src/components/TCPClientView.js
new file mode 100644
index 0000000..ffc0dd9
--- /dev/null
+++ b/ApiTestManager/src/components/TCPClientView.js
@@ -0,0 +1,386 @@
+import EditableInput from './EditableInput';
+import APIClient from '../APIClient';
+
+
+class TCPClientView {
+
+ constructor(parent, serverManager, apiRequestTabContent, model, index) {
+ this.parent = parent;
+ this.serverManager = serverManager;
+ this.apiRequestTabContent = apiRequestTabContent;
+ this.model = model;
+ this.index = index;
+ this.server = this.serverManager.getServer(this.model.server);
+ this.apiClient = new APIClient();
+ }
+
+ init() {
+ this.apiRequestTabContent.append(this.tcpApiRequestTemplate(this.model, this.index));
+ this.renderApiLayout(this.model.layout);
+ }
+
+ setRequestBodyEditor(editor) {
+ this.requestBodyEditor = editor;
+ }
+
+ renderApiLayout(layout) {
+ const requestContainer = this.apiRequestTabContent.find('.request_layout');
+ requestContainer.empty();
+
+ const headerHtml = `
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ | # |
+ 항목명(영문) |
+ 항목설명 |
+ 깊이 |
+ 아이템 유형 |
+ 반복 횟수 |
+ 반복 참조 필드 |
+ 데이터 타입 |
+ 데이터 길이 |
+ 값 |
+ 비고 |
+
+
+
+ `;
+
+ const footerHtml = `
+
+
+ `;
+
+ const fieldsHtml = layout.layoutItems ? layout.layoutItems.map((item, index) => {
+ return this.renderApiLayoutItem(item, index);
+ }).join('') : '';
+
+ requestContainer.append(headerHtml + fieldsHtml + footerHtml);
+
+ requestContainer.find('.editable').each((index, editableElement) => {
+ const editableInput = new EditableInput({
+ name: editableElement.dataset.name,
+ value: editableElement.dataset.value
+ });
+
+ editableInput.init(editableElement, (value) => {
+ _.set(this.model.layout, editableElement.dataset.name, value);
+ this.buildMessage();
+ $('span.variable').off('mouseover');
+ $('span.variable').off('mouseover');
+ document.querySelectorAll('span.variable').forEach(element => {
+ let text = element.innerText;
+ element.addEventListener('mouseover', () => this.parent.showPopper(element, text));
+ element.addEventListener('mouseout', () => this.parent.hidePopper(element));
+ });
+ });
+ });
+
+ let totalLength = 0;
+ this.model.layout.layoutItems.forEach(item => {
+ totalLength += parseInt(item.loutItemLength);
+ });
+ this.apiRequestTabContent.find('.total_message_length').text(totalLength);
+ this.setupListeners();
+ }
+
+
+ handleUIUpdate(event) {
+ if (event) {
+ event.preventDefault();
+ const element = event.currentTarget;
+ const fieldName = $(element).attr('name');
+ const newValue = this.getFieldValue(element);
+ if (fieldName !== '') {
+ _.set(this.model.layout, fieldName, newValue);
+ this.buildMessage();
+ }
+ }
+ let totalLength = 0;
+ this.model.layout.layoutItems.forEach(item => {
+ totalLength += parseInt(item.loutItemLength);
+ });
+ this.apiRequestTabContent.find('.total_message_length').text(totalLength);
+ }
+
+ getFieldValue(element) {
+ if ($(element).is('select') || $(element).is('input[type="text"]') || $(element).is('input[type="number"]')) {
+ return $(element).val();
+ }
+ if ($(element).is('input[type="checkbox"]')) {
+ return $(element).is(':checked');
+ }
+ }
+
+ renderApiLayoutItem(item, index) {
+ if (item.value === null)
+ item.value = '';
+
+ return `
+
+ | ${item.loutItemSerno} |
+ |
+ |
+ |
+
+
+ |
+ |
+ |
+
+
+ |
+ |
+
+
+ |
+
+
+
+
+
+
+
+ |
+
+ `;
+
+ }
+
+ recalculateSerno() {
+ // Reassign loutItemSerno sequentially based on the current order
+ this.model.layout.layoutItems.forEach((item, index) => {
+ item.loutItemSerno = index + 1; // Assuming you want to start numbering from 1
+ });
+ }
+
+ setupListeners() {
+ const table = this.apiRequestTabContent.find('.layout_table');
+ table.on('change', 'select.field, input.field', this.handleUIUpdate.bind(this));
+
+ table.on('click', '.add-layout-item', event => {
+ let item = {
+ 'parent': 0,
+ 'level': 1,
+ 'loutName': '',
+ 'loutItemName': '',
+ 'loutItemDesc': '',
+ 'loutItemDepth': 1,
+ 'loutItemType': 'Field',
+ 'loutItemOccCnt': '',
+ 'loutItemOccRef': '',
+ 'loutItemDataType': 'String',
+ 'loutItemLength': 1,
+ 'loutItemDecimal': 0,
+ 'loutItemDefault': '',
+ 'loutItemMaskYn': 'N',
+ 'loutItemMaskOffset': 0,
+ 'loutItemMaskLength': 0,
+ 'parentLoutItemIndex': 0,
+ 'expanded': true,
+ 'isLeaf': true,
+ 'LOUTITEMPATH': '',
+ 'value' : ''
+ };
+ this.model.layout.layoutItems.push(item);
+ this.recalculateSerno();
+ this.renderApiLayout(this.model.layout);
+ });
+
+ table.on('click', '.move-up', event => {
+ const index = $(event.currentTarget).data('index');
+ if (index > 0) {
+ const temp = this.model.layout.layoutItems[index];
+ this.model.layout.layoutItems[index] = this.model.layout.layoutItems[index - 1];
+ this.model.layout.layoutItems[index - 1] = temp;
+ this.recalculateSerno();
+ this.renderApiLayout(this.model.layout);
+ }
+ });
+
+ table.on('click', '.move-down', event => {
+ const index = $(event.currentTarget).data('index');
+ if (index < this.model.layout.layoutItems.length - 1) {
+ const temp = this.model.layout.layoutItems[index];
+ this.model.layout.layoutItems[index] = this.model.layout.layoutItems[index + 1];
+ this.model.layout.layoutItems[index + 1] = temp;
+ this.recalculateSerno();
+ this.renderApiLayout(this.model.layout);
+ }
+ });
+
+ table.on('click', '.delete', event => {
+ const index = $(event.currentTarget).data('index');
+ this.model.layout.layoutItems.splice(index, 1);
+ this.recalculateSerno();
+ this.renderApiLayout(this.model.layout);
+ });
+ }
+
+ async buildMessage() {
+ let message = '';
+ this.requestBodyEditor.setValue(message);
+
+ for (const item of this.model.layout.layoutItems) {
+ let duplicated = item.value;
+ const value = await this.apiClient.processPreScriptAndVariables(this.model, duplicated, null);
+ message += this.fillPadding(item.loutItemLength, value);
+ }
+
+ this.requestBodyEditor.setValue(message);
+ }
+
+ fillPadding(dataLength, value) {
+ value = String(value);
+ return value.padStart(dataLength, ' ');
+ }
+
+ tcpApiRequestTemplate(apiRequest, index) {
+ return `
+
+
${apiRequest.collectionName} > ${apiRequest.name}
+
+
+ ${this.serverManager.renderTcpServers(apiRequest.server)}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+
+ 전체 메시지 길이:
+
+
+
+
+
+
+ Response
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
+
+
+
+ `;
+ }
+}
+
+export default TCPClientView;
diff --git a/src/main/java/com/eactive/testmaster/client/controller/ApiRequestMgmtController.java b/src/main/java/com/eactive/testmaster/client/controller/ApiRequestMgmtController.java
index 8127381..98f424e 100644
--- a/src/main/java/com/eactive/testmaster/client/controller/ApiRequestMgmtController.java
+++ b/src/main/java/com/eactive/testmaster/client/controller/ApiRequestMgmtController.java
@@ -3,12 +3,17 @@ package com.eactive.testmaster.client.controller;
import com.eactive.testmaster.client.dto.ApiCollectionDTO;
import com.eactive.testmaster.client.dto.ApiRequestDTO;
import com.eactive.testmaster.client.entity.ApiCollection;
+import com.eactive.testmaster.client.entity.ApiLayout;
import com.eactive.testmaster.client.entity.ApiRequestInfo;
+import com.eactive.testmaster.client.mapper.ApiLayoutMapper;
import com.eactive.testmaster.client.mapper.ApiRequestMapper;
+import com.eactive.testmaster.client.service.ApiLayoutMgmtService;
import com.eactive.testmaster.client.service.ApiRequestMgmtService;
import com.eactive.testmaster.common.util.SecurityUtil;
import com.eactive.testmaster.user.entity.StaffUser;
import com.eactive.testmaster.user.service.UserService;
+import javax.transaction.Transactional;
+import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@@ -20,13 +25,19 @@ public class ApiRequestMgmtController {
private static final String SUCCESS = "success";
private final ApiRequestMgmtService apiRequestMgmtService;
+ private final ApiLayoutMgmtService apiLayoutMgmtService;
+
private final ApiRequestMapper apiRequestMapper;
+ private final ApiLayoutMapper apiLayoutMapper;
+
private final UserService userService;
- public ApiRequestMgmtController(ApiRequestMgmtService apiRequestMgmtService, ApiRequestMapper apiRequestMapper, UserService userService) {
+ public ApiRequestMgmtController(ApiRequestMgmtService apiRequestMgmtService, ApiLayoutMgmtService apiLayoutMgmtService, ApiRequestMapper apiRequestMapper, ApiLayoutMapper apiLayoutMapper, UserService userService) {
this.apiRequestMgmtService = apiRequestMgmtService;
+ this.apiLayoutMgmtService = apiLayoutMgmtService;
this.apiRequestMapper = apiRequestMapper;
+ this.apiLayoutMapper = apiLayoutMapper;
this.userService = userService;
}
@@ -39,7 +50,7 @@ public class ApiRequestMgmtController {
@PostMapping("/mgmt/collections/create.do")
public ResponseEntity createApiCollection(
- @RequestBody ApiCollectionDTO dto) {
+ @RequestBody ApiCollectionDTO dto) {
ApiCollection collection = apiRequestMapper.map(dto);
StaffUser user = userService.findByEsntlId(SecurityUtil.getCurrentUserEsntlId());
@@ -64,18 +75,28 @@ public class ApiRequestMgmtController {
}
@PostMapping("/mgmt/collections/{id}/apis/save.do")
- public ResponseEntity addApiToCollection(@PathVariable(name = "id") String id,
- @RequestBody ApiRequestDTO dto) {
+ @Transactional
+ public ResponseEntity addApiToCollection(@PathVariable(name = "id") String id, @RequestBody ApiRequestDTO dto) {
ApiRequestInfo apiRequestInfo = apiRequestMapper.map(dto);
StaffUser user = userService.findByEsntlId(SecurityUtil.getCurrentUserEsntlId());
apiRequestInfo.setOwner(user);
String apiId = apiRequestMgmtService.saveApiToCollection(id, apiRequestInfo);
+
+ if (dto.getLayout() != null) {
+ dto.getLayout().setApiRequestId(apiId);
+ apiLayoutMgmtService.saveLayout(apiLayoutMapper.map(dto.getLayout()));
+ }
return ResponseEntity.ok(apiId);
+
}
@PostMapping("/mgmt/collections/{id}/apis/delete.do")
- public ResponseEntity removeApiFromCollection(@PathVariable(name = "id") String id,
- @RequestBody ApiRequestDTO dto) {
+ @Transactional
+ public ResponseEntity removeApiFromCollection(@PathVariable(name = "id") String id, @RequestBody ApiRequestDTO dto) {
+ ApiLayout layout = apiLayoutMgmtService.findLayoutByApiRequest(dto.getId());
+ if (layout != null) {
+ apiLayoutMgmtService.deleteLayout(layout.getId());
+ }
apiRequestMgmtService.removeApiFromCollection(id, dto.getId());
return ResponseEntity.ok(SUCCESS);
}
diff --git a/src/main/java/com/eactive/testmaster/client/dto/ApiLayoutDTO.java b/src/main/java/com/eactive/testmaster/client/dto/ApiLayoutDTO.java
new file mode 100644
index 0000000..206d0ee
--- /dev/null
+++ b/src/main/java/com/eactive/testmaster/client/dto/ApiLayoutDTO.java
@@ -0,0 +1,167 @@
+package com.eactive.testmaster.client.dto;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ApiLayoutDTO implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ @JsonProperty("id")
+ private String id;
+
+ @JsonProperty("APIREQUESTID")
+ private String apiRequestId;
+
+ @JsonProperty("LOUTNAME")
+ private String loutName;
+
+ @JsonProperty("LOUTPTRNNAME")
+ private String loutPtrnName;
+
+ @JsonProperty("LOUTDESC")
+ private String loutDesc;
+
+ @JsonProperty("EAIBZWKDSTCD")
+ private String eaiBzwkDstCd;
+
+ @JsonProperty("UAPPLNAME")
+ private String uApplName;
+
+ @JsonProperty("SYSINTFACNAME")
+ private String sysIntFacName;
+
+ @JsonProperty("AUTHOR")
+ private String author;
+
+ @JsonProperty("EAISEVRDSTCD")
+ private String eaiSevRdStCd;
+
+ @JsonProperty("MODFMGTSTUSDSTCD")
+ private String modfMgtStusDstCd;
+
+ @JsonProperty("USEYN")
+ private String useYn;
+
+ @JsonProperty("VERINFO")
+ private String verInfo;
+
+ @JsonProperty("layoutItems")
+ List layoutItems = new ArrayList<>();
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getApiRequestId() {
+ return apiRequestId;
+ }
+
+ public void setApiRequestId(String apiRequestId) {
+ this.apiRequestId = apiRequestId;
+ }
+
+ public String getLoutName() {
+ return loutName;
+ }
+
+ public void setLoutName(String loutName) {
+ this.loutName = loutName;
+ }
+
+ public String getLoutPtrnName() {
+ return loutPtrnName;
+ }
+
+ public void setLoutPtrnName(String loutPtrnName) {
+ this.loutPtrnName = loutPtrnName;
+ }
+
+ public String getLoutDesc() {
+ return loutDesc;
+ }
+
+ public void setLoutDesc(String loutDesc) {
+ this.loutDesc = loutDesc;
+ }
+
+ public String getEaiBzwkDstCd() {
+ return eaiBzwkDstCd;
+ }
+
+ public void setEaiBzwkDstCd(String eaiBzwkDstCd) {
+ this.eaiBzwkDstCd = eaiBzwkDstCd;
+ }
+
+ public String getuApplName() {
+ return uApplName;
+ }
+
+ public void setuApplName(String uApplName) {
+ this.uApplName = uApplName;
+ }
+
+ public String getSysIntFacName() {
+ return sysIntFacName;
+ }
+
+ public void setSysIntFacName(String sysIntFacName) {
+ this.sysIntFacName = sysIntFacName;
+ }
+
+ public String getAuthor() {
+ return author;
+ }
+
+ public void setAuthor(String author) {
+ this.author = author;
+ }
+
+ public String getEaiSevRdStCd() {
+ return eaiSevRdStCd;
+ }
+
+ public void setEaiSevRdStCd(String eaiSevRdStCd) {
+ this.eaiSevRdStCd = eaiSevRdStCd;
+ }
+
+ public String getModfMgtStusDstCd() {
+ return modfMgtStusDstCd;
+ }
+
+ public void setModfMgtStusDstCd(String modfMgtStusDstCd) {
+ this.modfMgtStusDstCd = modfMgtStusDstCd;
+ }
+
+ public String getUseYn() {
+ return useYn;
+ }
+
+ public void setUseYn(String useYn) {
+ this.useYn = useYn;
+ }
+
+ public String getVerInfo() {
+ return verInfo;
+ }
+
+ public void setVerInfo(String verInfo) {
+ this.verInfo = verInfo;
+ }
+
+ public List getLayoutItems() {
+ return layoutItems;
+ }
+
+ public void setLayoutItems(List layoutItems) {
+ this.layoutItems = layoutItems;
+ }
+}
diff --git a/src/main/java/com/eactive/testmaster/client/dto/ApiLayoutItemDTO.java b/src/main/java/com/eactive/testmaster/client/dto/ApiLayoutItemDTO.java
new file mode 100644
index 0000000..ca21a05
--- /dev/null
+++ b/src/main/java/com/eactive/testmaster/client/dto/ApiLayoutItemDTO.java
@@ -0,0 +1,275 @@
+package com.eactive.testmaster.client.dto;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import java.io.Serializable;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ApiLayoutItemDTO implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ @JsonProperty("itemId")
+ private Long itemId;
+
+ @JsonProperty("id")
+ private Long id;
+
+ @JsonProperty("parent")
+ private Long parent;
+
+ @JsonProperty("level")
+ private Integer level;
+
+ @JsonProperty("loutName")
+ private String loutName;
+
+ @JsonProperty("loutItemSerno")
+ private Integer loutItemSerno;
+
+ @JsonProperty("loutItemName")
+ private String loutItemName;
+
+ @JsonProperty("loutItemDesc")
+ private String loutItemDesc;
+
+ @JsonProperty("loutItemDepth")
+ private Integer loutItemDepth;
+
+ @JsonProperty("loutItemType")
+ private String loutItemType;
+
+ @JsonProperty("loutItemOccCnt")
+ private String loutItemOccCnt;
+
+ @JsonProperty("loutItemOccRef")
+ private String loutItemOccRef;
+
+ @JsonProperty("loutItemDataType")
+ private String loutItemDataType;
+
+ @JsonProperty("loutItemLength")
+ private Integer loutItemLength;
+
+ @JsonProperty("loutItemDecimal")
+ private Integer loutItemDecimal;
+
+ @JsonProperty("loutItemDefault")
+ private String loutItemDefault;
+
+ @JsonProperty("loutItemMaskYn")
+ private String loutItemMaskYn;
+
+ @JsonProperty("loutItemMaskOffset")
+ private Integer loutItemMaskOffset;
+
+ @JsonProperty("loutItemMaskLength")
+ private Integer loutItemMaskLength;
+
+ @JsonProperty("parentLoutItemIndex")
+ private Integer parentLoutItemIndex;
+
+ @JsonProperty("expanded")
+ private Boolean expanded;
+
+ @JsonProperty("isLeaf")
+ private Boolean isLeaf;
+
+ @JsonProperty("LOUTITEMPATH")
+ private String loutItemPath;
+
+ @JsonProperty(value = "value", defaultValue = "")
+ private String value;
+
+ public Long getItemId() {
+ return itemId;
+ }
+
+ public void setItemId(Long itemId) {
+ this.itemId = itemId;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public Long getParent() {
+ return parent;
+ }
+
+ public void setParent(Long parent) {
+ this.parent = parent;
+ }
+
+ public Integer getLevel() {
+ return level;
+ }
+
+ public void setLevel(Integer level) {
+ this.level = level;
+ }
+
+ public String getLoutName() {
+ return loutName;
+ }
+
+ public void setLoutName(String loutName) {
+ this.loutName = loutName;
+ }
+
+ public Integer getLoutItemSerno() {
+ return loutItemSerno;
+ }
+
+ public void setLoutItemSerno(Integer loutItemSerno) {
+ this.loutItemSerno = loutItemSerno;
+ }
+
+ public String getLoutItemName() {
+ return loutItemName;
+ }
+
+ public void setLoutItemName(String loutItemName) {
+ this.loutItemName = loutItemName;
+ }
+
+ public String getLoutItemDesc() {
+ return loutItemDesc;
+ }
+
+ public void setLoutItemDesc(String loutItemDesc) {
+ this.loutItemDesc = loutItemDesc;
+ }
+
+ public Integer getLoutItemDepth() {
+ return loutItemDepth;
+ }
+
+ public void setLoutItemDepth(Integer loutItemDepth) {
+ this.loutItemDepth = loutItemDepth;
+ }
+
+ public String getLoutItemType() {
+ return loutItemType;
+ }
+
+ public void setLoutItemType(String loutItemType) {
+ this.loutItemType = loutItemType;
+ }
+
+ public String getLoutItemOccCnt() {
+ return loutItemOccCnt;
+ }
+
+ public void setLoutItemOccCnt(String loutItemOccCnt) {
+ this.loutItemOccCnt = loutItemOccCnt;
+ }
+
+ public String getLoutItemOccRef() {
+ return loutItemOccRef;
+ }
+
+ public void setLoutItemOccRef(String loutItemOccRef) {
+ this.loutItemOccRef = loutItemOccRef;
+ }
+
+ public String getLoutItemDataType() {
+ return loutItemDataType;
+ }
+
+ public void setLoutItemDataType(String loutItemDataType) {
+ this.loutItemDataType = loutItemDataType;
+ }
+
+ public Integer getLoutItemLength() {
+ return loutItemLength;
+ }
+
+ public void setLoutItemLength(Integer loutItemLength) {
+ this.loutItemLength = loutItemLength;
+ }
+
+ public Integer getLoutItemDecimal() {
+ return loutItemDecimal;
+ }
+
+ public void setLoutItemDecimal(Integer loutItemDecimal) {
+ this.loutItemDecimal = loutItemDecimal;
+ }
+
+ public String getLoutItemDefault() {
+ return loutItemDefault;
+ }
+
+ public void setLoutItemDefault(String loutItemDefault) {
+ this.loutItemDefault = loutItemDefault;
+ }
+
+ public String getLoutItemMaskYn() {
+ return loutItemMaskYn;
+ }
+
+ public void setLoutItemMaskYn(String loutItemMaskYn) {
+ this.loutItemMaskYn = loutItemMaskYn;
+ }
+
+ public Integer getLoutItemMaskOffset() {
+ return loutItemMaskOffset;
+ }
+
+ public void setLoutItemMaskOffset(Integer loutItemMaskOffset) {
+ this.loutItemMaskOffset = loutItemMaskOffset;
+ }
+
+ public Integer getLoutItemMaskLength() {
+ return loutItemMaskLength;
+ }
+
+ public void setLoutItemMaskLength(Integer loutItemMaskLength) {
+ this.loutItemMaskLength = loutItemMaskLength;
+ }
+
+ public Integer getParentLoutItemIndex() {
+ return parentLoutItemIndex;
+ }
+
+ public void setParentLoutItemIndex(Integer parentLoutItemIndex) {
+ this.parentLoutItemIndex = parentLoutItemIndex;
+ }
+
+ public Boolean getExpanded() {
+ return expanded;
+ }
+
+ public void setExpanded(Boolean expanded) {
+ this.expanded = expanded;
+ }
+
+ public Boolean getLeaf() {
+ return isLeaf;
+ }
+
+ public void setLeaf(Boolean leaf) {
+ isLeaf = leaf;
+ }
+
+ public String getLoutItemPath() {
+ return loutItemPath;
+ }
+
+ public void setLoutItemPath(String loutItemPath) {
+ this.loutItemPath = loutItemPath;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+}
diff --git a/src/main/java/com/eactive/testmaster/client/dto/ApiRequestDTO.java b/src/main/java/com/eactive/testmaster/client/dto/ApiRequestDTO.java
index a939a66..0609eaa 100644
--- a/src/main/java/com/eactive/testmaster/client/dto/ApiRequestDTO.java
+++ b/src/main/java/com/eactive/testmaster/client/dto/ApiRequestDTO.java
@@ -33,7 +33,7 @@ public class ApiRequestDTO implements Serializable {
private String postRequestScript;
- private long sentBytes; //estimated size of the request
+ private ApiLayoutDTO layout;
public String getId() {
return id;
@@ -131,11 +131,11 @@ public class ApiRequestDTO implements Serializable {
this.postRequestScript = postRequestScript;
}
-// public long getSentBytes() {
-// return sentBytes;
-// }
-//
-// public void setSentBytes(long sentBytes) {
-// this.sentBytes = sentBytes;
-// }
+ public ApiLayoutDTO getLayout() {
+ return layout;
+ }
+
+ public void setLayout(ApiLayoutDTO layout) {
+ this.layout = layout;
+ }
}
diff --git a/src/main/java/com/eactive/testmaster/client/entity/ApiLayout.java b/src/main/java/com/eactive/testmaster/client/entity/ApiLayout.java
new file mode 100644
index 0000000..a39434b
--- /dev/null
+++ b/src/main/java/com/eactive/testmaster/client/entity/ApiLayout.java
@@ -0,0 +1,167 @@
+package com.eactive.testmaster.client.entity;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "API_LAYOUT")
+public class ApiLayout {
+
+ @Id
+ private String id;
+
+ @ManyToOne
+ @JoinColumn(name = "API_REQUEST_INFO_ID")
+ private ApiRequestInfo apiRequestInfo;
+
+ private String loutName;
+
+ private String loutPtrnName;
+
+ private String loutDesc;
+
+ private String eaiBzwkDstCd;
+
+ private String uApplName;
+
+ private String sysIntFacName;
+
+ private String author;
+
+ private String eaiSevRdStCd;
+
+ private String modfMgtStusDstCd;
+
+ private String useYn;
+
+ private String verInfo;
+
+ @OneToMany(mappedBy = "apiLayout", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
+ private List layoutItems = new ArrayList<>();
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public ApiRequestInfo getApiRequestInfo() {
+ return apiRequestInfo;
+ }
+
+ public void setApiRequestInfo(ApiRequestInfo apiRequestInfo) {
+ this.apiRequestInfo = apiRequestInfo;
+ }
+
+ public String getLoutName() {
+ return loutName;
+ }
+
+ public void setLoutName(String loutName) {
+ this.loutName = loutName;
+ }
+
+ public String getLoutPtrnName() {
+ return loutPtrnName;
+ }
+
+ public void setLoutPtrnName(String loutPtrnName) {
+ this.loutPtrnName = loutPtrnName;
+ }
+
+ public String getLoutDesc() {
+ return loutDesc;
+ }
+
+ public void setLoutDesc(String loutDesc) {
+ this.loutDesc = loutDesc;
+ }
+
+ public String getEaiBzwkDstCd() {
+ return eaiBzwkDstCd;
+ }
+
+ public void setEaiBzwkDstCd(String eaiBzwkDstCd) {
+ this.eaiBzwkDstCd = eaiBzwkDstCd;
+ }
+
+ public String getUApplName() {
+ return uApplName;
+ }
+
+ public void setUApplName(String uApplName) {
+ this.uApplName = uApplName;
+ }
+
+ public String getSysIntFacName() {
+ return sysIntFacName;
+ }
+
+ public void setSysIntFacName(String sysIntFacName) {
+ this.sysIntFacName = sysIntFacName;
+ }
+
+ public String getAuthor() {
+ return author;
+ }
+
+ public void setAuthor(String author) {
+ this.author = author;
+ }
+
+ public String getEaiSevRdStCd() {
+ return eaiSevRdStCd;
+ }
+
+ public void setEaiSevRdStCd(String eaiSevRdStCd) {
+ this.eaiSevRdStCd = eaiSevRdStCd;
+ }
+
+ public String getModfMgtStusDstCd() {
+ return modfMgtStusDstCd;
+ }
+
+ public void setModfMgtStusDstCd(String modfMgtStusDstCd) {
+ this.modfMgtStusDstCd = modfMgtStusDstCd;
+ }
+
+ public String getUseYn() {
+ return useYn;
+ }
+
+ public void setUseYn(String useYn) {
+ this.useYn = useYn;
+ }
+
+ public String getVerInfo() {
+ return verInfo;
+ }
+
+ public void setVerInfo(String verInfo) {
+ this.verInfo = verInfo;
+ }
+
+ public List getLayoutItems() {
+ return layoutItems;
+ }
+
+ public void setLayoutItems(List layoutItems) {
+ this.layoutItems = layoutItems;
+ }
+
+ public void addApiLayoutItem(ApiLayoutItem item) {
+ item.setApiLayout(this);
+ this.layoutItems.add(item);
+ }
+
+}
diff --git a/src/main/java/com/eactive/testmaster/client/entity/ApiLayoutItem.java b/src/main/java/com/eactive/testmaster/client/entity/ApiLayoutItem.java
new file mode 100644
index 0000000..2a53db7
--- /dev/null
+++ b/src/main/java/com/eactive/testmaster/client/entity/ApiLayoutItem.java
@@ -0,0 +1,270 @@
+package com.eactive.testmaster.client.entity;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "API_LAYOUT_ITEM")
+public class ApiLayoutItem {
+
+ @ManyToOne
+ @JoinColumn(name = "API_LAYOUT_ID", nullable = false)
+ private ApiLayout apiLayout; // This is the back-reference to the parent
+
+ @Id
+ @Column(name = "API_LAYOUT_ITEM_ID")
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private Long itemId;
+
+ private Long id;
+
+ private Long parent;
+
+ private Integer level;
+
+ private String loutName;
+
+ private Integer loutItemSerno;
+
+ private String loutItemName;
+
+ private String loutItemDesc;
+
+ private Integer loutItemDepth;
+
+ private String loutItemType;
+
+ private String loutItemOccCnt;
+
+ private String loutItemOccRef;
+
+ private String loutItemDataType;
+
+ private Integer loutItemLength;
+
+ private Integer loutItemDecimal;
+
+ private String loutItemDefault;
+
+ private String loutItemMaskYn;
+
+ private Integer loutItemMaskOffset;
+
+ private Integer loutItemMaskLength;
+
+ private Integer parentLoutItemIndex;
+
+ private Boolean expanded;
+
+ private Boolean isLeaf;
+
+ private String loutItemPath;
+
+ private String value;
+
+ public Long getItemId() {
+ return itemId;
+ }
+
+ public void setItemId(Long itemId) {
+ this.itemId = itemId;
+ }
+
+ public ApiLayout getApiLayout() {
+ return apiLayout;
+ }
+
+ public void setApiLayout(ApiLayout apiLayout) {
+ this.apiLayout = apiLayout;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public Long getParent() {
+ return parent;
+ }
+
+ public void setParent(Long parent) {
+ this.parent = parent;
+ }
+
+ public Integer getLevel() {
+ return level;
+ }
+
+ public void setLevel(Integer level) {
+ this.level = level;
+ }
+
+ public String getLoutName() {
+ return loutName;
+ }
+
+ public void setLoutName(String loutName) {
+ this.loutName = loutName;
+ }
+
+ public Integer getLoutItemSerno() {
+ return loutItemSerno;
+ }
+
+ public void setLoutItemSerno(Integer loutItemSerno) {
+ this.loutItemSerno = loutItemSerno;
+ }
+
+ public String getLoutItemName() {
+ return loutItemName;
+ }
+
+ public void setLoutItemName(String loutItemName) {
+ this.loutItemName = loutItemName;
+ }
+
+ public String getLoutItemDesc() {
+ return loutItemDesc;
+ }
+
+ public void setLoutItemDesc(String loutItemDesc) {
+ this.loutItemDesc = loutItemDesc;
+ }
+
+ public Integer getLoutItemDepth() {
+ return loutItemDepth;
+ }
+
+ public void setLoutItemDepth(Integer loutItemDepth) {
+ this.loutItemDepth = loutItemDepth;
+ }
+
+ public String getLoutItemType() {
+ return loutItemType;
+ }
+
+ public void setLoutItemType(String loutItemType) {
+ this.loutItemType = loutItemType;
+ }
+
+ public String getLoutItemOccCnt() {
+ return loutItemOccCnt;
+ }
+
+ public void setLoutItemOccCnt(String loutItemOccCnt) {
+ this.loutItemOccCnt = loutItemOccCnt;
+ }
+
+ public String getLoutItemOccRef() {
+ return loutItemOccRef;
+ }
+
+ public void setLoutItemOccRef(String loutItemOccRef) {
+ this.loutItemOccRef = loutItemOccRef;
+ }
+
+ public String getLoutItemDataType() {
+ return loutItemDataType;
+ }
+
+ public void setLoutItemDataType(String loutItemDataType) {
+ this.loutItemDataType = loutItemDataType;
+ }
+
+ public Integer getLoutItemLength() {
+ return loutItemLength;
+ }
+
+ public void setLoutItemLength(Integer loutItemLength) {
+ this.loutItemLength = loutItemLength;
+ }
+
+ public Integer getLoutItemDecimal() {
+ return loutItemDecimal;
+ }
+
+ public void setLoutItemDecimal(Integer loutItemDecimal) {
+ this.loutItemDecimal = loutItemDecimal;
+ }
+
+ public String getLoutItemDefault() {
+ return loutItemDefault;
+ }
+
+ public void setLoutItemDefault(String loutItemDefault) {
+ this.loutItemDefault = loutItemDefault;
+ }
+
+ public String getLoutItemMaskYn() {
+ return loutItemMaskYn;
+ }
+
+ public void setLoutItemMaskYn(String loutItemMaskYn) {
+ this.loutItemMaskYn = loutItemMaskYn;
+ }
+
+ public Integer getLoutItemMaskOffset() {
+ return loutItemMaskOffset;
+ }
+
+ public void setLoutItemMaskOffset(Integer loutItemMaskOffset) {
+ this.loutItemMaskOffset = loutItemMaskOffset;
+ }
+
+ public Integer getLoutItemMaskLength() {
+ return loutItemMaskLength;
+ }
+
+ public void setLoutItemMaskLength(Integer loutItemMaskLength) {
+ this.loutItemMaskLength = loutItemMaskLength;
+ }
+
+ public Integer getParentLoutItemIndex() {
+ return parentLoutItemIndex;
+ }
+
+ public void setParentLoutItemIndex(Integer parentLoutItemIndex) {
+ this.parentLoutItemIndex = parentLoutItemIndex;
+ }
+
+ public Boolean getExpanded() {
+ return expanded;
+ }
+
+ public void setExpanded(Boolean expanded) {
+ this.expanded = expanded;
+ }
+
+ public Boolean getLeaf() {
+ return isLeaf;
+ }
+
+ public void setLeaf(Boolean leaf) {
+ isLeaf = leaf;
+ }
+
+ public String getLoutItemPath() {
+ return loutItemPath;
+ }
+
+ public void setLoutItemPath(String loutItemPath) {
+ this.loutItemPath = loutItemPath;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+}
diff --git a/src/main/java/com/eactive/testmaster/client/mapper/ApiLayoutItemMapper.java b/src/main/java/com/eactive/testmaster/client/mapper/ApiLayoutItemMapper.java
new file mode 100644
index 0000000..c3ee935
--- /dev/null
+++ b/src/main/java/com/eactive/testmaster/client/mapper/ApiLayoutItemMapper.java
@@ -0,0 +1,39 @@
+package com.eactive.testmaster.client.mapper;
+
+import com.eactive.testmaster.client.dto.ApiLayoutItemDTO;
+import com.eactive.testmaster.client.entity.ApiLayoutItem;
+import com.eactive.testmaster.client.repository.ApiLayoutItemRepository;
+import com.eactive.testmaster.common.mapper.CommonMapper;
+import java.util.List;
+import org.mapstruct.Mapper;
+import org.mapstruct.ReportingPolicy;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Mapper(componentModel = "spring",
+ uses = {CommonMapper.class},
+ unmappedTargetPolicy = ReportingPolicy.IGNORE)
+@Component
+public abstract class ApiLayoutItemMapper {
+
+ @Autowired
+ private ApiLayoutItemRepository apiLayoutItemRepository;
+
+ public abstract ApiLayoutItem map(ApiLayoutItemDTO dto);
+
+ public abstract ApiLayoutItemDTO map(ApiLayoutItem entity);
+
+ public ApiLayoutItem map(Long id) {
+ if (id == null) {
+ return null;
+ }
+ return apiLayoutItemRepository.findById(id)
+ .orElseThrow(() -> new IllegalArgumentException("No ApiLayoutItem found for ID: " + id));
+ }
+
+ // Method to map lists of ApiLayoutItemDTOs to lists of ApiLayoutItem entities
+ public abstract List mapItems(List dtos);
+
+ // Method to map lists of ApiLayoutItem entities to lists of ApiLayoutItemDTOs
+ public abstract List mapItemDTOs(List entities);
+}
diff --git a/src/main/java/com/eactive/testmaster/client/mapper/ApiLayoutMapper.java b/src/main/java/com/eactive/testmaster/client/mapper/ApiLayoutMapper.java
new file mode 100644
index 0000000..026d1e8
--- /dev/null
+++ b/src/main/java/com/eactive/testmaster/client/mapper/ApiLayoutMapper.java
@@ -0,0 +1,60 @@
+package com.eactive.testmaster.client.mapper;
+
+import com.eactive.testmaster.client.dto.ApiLayoutDTO;
+import com.eactive.testmaster.client.entity.ApiLayout;
+import com.eactive.testmaster.client.entity.ApiRequestInfo;
+import com.eactive.testmaster.client.repository.ApiLayoutRepository;
+import com.eactive.testmaster.client.repository.ApiRequestRepository;
+import com.eactive.testmaster.common.mapper.CommonMapper;
+import java.util.List;
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+import org.mapstruct.ReportingPolicy;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Mapper(componentModel = "spring",
+ uses = {CommonMapper.class, ApiLayoutItemMapper.class},
+ unmappedTargetPolicy = ReportingPolicy.IGNORE)
+@Component
+public abstract class ApiLayoutMapper {
+
+ @Autowired
+ private ApiLayoutRepository apiLayoutRepository;
+
+ @Autowired
+ private ApiRequestRepository apiRequestRepository;
+
+
+ @Mapping(target = "apiRequestInfo", source = "apiRequestId")
+ public abstract ApiLayout map(ApiLayoutDTO dto);
+
+ @Mapping(target = "apiRequestId", source = "apiRequestInfo")
+ public abstract ApiLayoutDTO map(ApiLayout entity);
+
+ public ApiRequestInfo mapApiRequestInfo(String id) {
+ if (id == null) {
+ return null;
+ }
+ return apiRequestRepository.findById(id).orElseThrow(() -> new IllegalArgumentException("No ApiRequest found for ID: " + id));
+ }
+
+ public String mapApiRequestId(ApiRequestInfo entity) {
+ if (entity == null) {
+ return null;
+ }
+ return entity.getId();
+ }
+
+
+ public ApiLayout map(String id) {
+ if (id == null) {
+ return null;
+ }
+ return apiLayoutRepository.findById(id).orElseThrow(() -> new IllegalArgumentException("No ApiLayout found for ID: " + id));
+ }
+
+// public abstract List mapLayouts(List dtos);
+
+ public abstract List mapLayoutDTOs(List entities);
+}
diff --git a/src/main/java/com/eactive/testmaster/client/mapper/ApiRequestMapper.java b/src/main/java/com/eactive/testmaster/client/mapper/ApiRequestMapper.java
index 1e326fb..d07c8c7 100644
--- a/src/main/java/com/eactive/testmaster/client/mapper/ApiRequestMapper.java
+++ b/src/main/java/com/eactive/testmaster/client/mapper/ApiRequestMapper.java
@@ -3,40 +3,73 @@ package com.eactive.testmaster.client.mapper;
import com.eactive.testmaster.client.dto.ApiCollectionDTO;
import com.eactive.testmaster.client.dto.ApiRequestDTO;
import com.eactive.testmaster.client.entity.ApiCollection;
+import com.eactive.testmaster.client.entity.ApiLayout;
+import com.eactive.testmaster.client.entity.ApiLayoutItem;
import com.eactive.testmaster.client.entity.ApiRequestInfo;
+import com.eactive.testmaster.client.repository.ApiLayoutRepository;
import com.eactive.testmaster.client.repository.ApiRequestRepository;
import com.eactive.testmaster.common.mapper.CommonMapper;
import com.eactive.testmaster.server.mapper.ServerMapper;
+import java.util.Comparator;
+import java.util.List;
+import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+import org.mapstruct.MappingTarget;
import org.mapstruct.ReportingPolicy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import java.util.List;
-
@Mapper(componentModel = "spring",
- uses = {CommonMapper.class, ServerMapper.class},
- unmappedTargetPolicy = ReportingPolicy.IGNORE)
+ uses = {CommonMapper.class, ServerMapper.class},
+ unmappedTargetPolicy = ReportingPolicy.IGNORE)
@Component
public abstract class ApiRequestMapper {
@Autowired
private ApiRequestRepository apiRequestRepository;
+ @Autowired
+ private ApiLayoutRepository apiLayoutRepository;
+
+ @Autowired
+ private ApiLayoutMapper apiLayoutMapper;
+
public abstract ApiCollection map(ApiCollectionDTO dto);
public abstract ApiRequestInfo map(ApiRequestDTO dto);
+ @Mapping(target = "layout", ignore = true)
public abstract ApiRequestDTO map(ApiRequestInfo entity);
+ public String mapId(ApiRequestInfo entity) {
+ if (entity == null) {
+ return null;
+ }
+ return entity.getId();
+ }
+
public ApiRequestInfo map(String id) {
- if(id == null) {
+ if (id == null) {
return null;
}
return apiRequestRepository.findById(id).orElseThrow(() -> new IllegalArgumentException("No ApiRequest found for ID: " + id));
}
+ @AfterMapping
+ public void handleTypeSpecificMapping(ApiRequestInfo entity, @MappingTarget ApiRequestDTO dto) {
+ if ("TCP".equals(entity.getType())) {
+ ApiLayout layout = apiLayoutRepository.findFirstByApiRequestInfo(entity);
+ if (layout!=null) {
+ layout.getLayoutItems().sort(Comparator.comparingInt(ApiLayoutItem::getLoutItemSerno));
+ dto.setLayout(apiLayoutMapper.map(layout));
+ }
+ }
+ }
+
+
+
public abstract List mapApis(List apis);
public abstract List mapCollections(List apis);
diff --git a/src/main/java/com/eactive/testmaster/client/repository/ApiLayoutItemRepository.java b/src/main/java/com/eactive/testmaster/client/repository/ApiLayoutItemRepository.java
new file mode 100644
index 0000000..b20b87d
--- /dev/null
+++ b/src/main/java/com/eactive/testmaster/client/repository/ApiLayoutItemRepository.java
@@ -0,0 +1,9 @@
+package com.eactive.testmaster.client.repository;
+
+import com.eactive.testmaster.client.entity.ApiLayoutItem;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+
+public interface ApiLayoutItemRepository extends JpaRepository, JpaSpecificationExecutor {
+
+}
diff --git a/src/main/java/com/eactive/testmaster/client/repository/ApiLayoutRepository.java b/src/main/java/com/eactive/testmaster/client/repository/ApiLayoutRepository.java
new file mode 100644
index 0000000..f889712
--- /dev/null
+++ b/src/main/java/com/eactive/testmaster/client/repository/ApiLayoutRepository.java
@@ -0,0 +1,11 @@
+package com.eactive.testmaster.client.repository;
+
+import com.eactive.testmaster.client.entity.ApiLayout;
+import com.eactive.testmaster.client.entity.ApiRequestInfo;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+
+public interface ApiLayoutRepository extends JpaRepository, JpaSpecificationExecutor {
+
+ ApiLayout findFirstByApiRequestInfo(ApiRequestInfo apiRequestInfo);
+}
diff --git a/src/main/java/com/eactive/testmaster/client/service/ApiLayoutMgmtService.java b/src/main/java/com/eactive/testmaster/client/service/ApiLayoutMgmtService.java
new file mode 100644
index 0000000..ecf865c
--- /dev/null
+++ b/src/main/java/com/eactive/testmaster/client/service/ApiLayoutMgmtService.java
@@ -0,0 +1,86 @@
+package com.eactive.testmaster.client.service;
+
+
+import com.eactive.testmaster.client.entity.ApiLayout;
+import com.eactive.testmaster.client.entity.ApiRequestInfo;
+import com.eactive.testmaster.client.repository.ApiLayoutRepository;
+import com.eactive.testmaster.client.repository.ApiRequestRepository;
+import com.eactive.testmaster.common.exception.NotFoundException;
+import java.util.UUID;
+import javax.transaction.Transactional;
+import org.springframework.stereotype.Service;
+
+@Service
+@Transactional
+public class ApiLayoutMgmtService {
+
+ private final ApiLayoutRepository apiLayoutRepository;
+
+ private final ApiRequestRepository apiRequestRepository;
+
+ public ApiLayoutMgmtService(ApiRequestRepository apiRequestRepository, ApiLayoutRepository apiLayoutRepository) {
+ this.apiRequestRepository = apiRequestRepository;
+ this.apiLayoutRepository = apiLayoutRepository;
+ }
+
+ public ApiLayout findLayoutByApiRequest(String apiRequestId) {
+ ApiRequestInfo apiRequestInfo = apiRequestRepository.findById(apiRequestId)
+ .orElseThrow(() -> new NotFoundException(String.format("ApiRequestInfo with ID %s not found", apiRequestId)));
+
+ return apiLayoutRepository.findFirstByApiRequestInfo(apiRequestInfo);
+ }
+
+ public ApiLayout saveLayout(ApiLayout layout) {
+ if (layout.getId() == null) {
+ return createLayout(layout);
+ } else {
+ return updateLayout(layout.getId(), layout);
+ }
+ }
+
+ public ApiLayout createLayout(ApiLayout layout) {
+ layout.setId(UUID.randomUUID().toString());
+ if (layout.getLayoutItems() != null && !layout.getLayoutItems().isEmpty()) {
+ layout.getLayoutItems().forEach(layoutItem -> {
+ layoutItem.setApiLayout(layout);
+ });
+ }
+ return apiLayoutRepository.save(layout);
+ }
+
+ public ApiLayout updateLayout(String layoutId, ApiLayout updatedLayout) {
+ ApiLayout layout = apiLayoutRepository.findById(layoutId)
+ .orElseThrow(() -> new NotFoundException(String.format("Layout with ID %s not found", layoutId)));
+
+ // Update fields based on the values provided in updatedLayout
+ layout.setLoutName(updatedLayout.getLoutName());
+ layout.setLoutDesc(updatedLayout.getLoutDesc());
+ layout.setLoutPtrnName(updatedLayout.getLoutPtrnName());
+ layout.setLoutDesc(updatedLayout.getLoutDesc());
+ layout.setEaiBzwkDstCd(updatedLayout.getEaiBzwkDstCd());
+ layout.setUApplName(updatedLayout.getUApplName());
+ layout.setSysIntFacName(updatedLayout.getSysIntFacName());
+ layout.setAuthor(updatedLayout.getAuthor());
+ layout.setEaiSevRdStCd(updatedLayout.getEaiSevRdStCd());
+ layout.setModfMgtStusDstCd(updatedLayout.getModfMgtStusDstCd());
+ layout.setUseYn(updatedLayout.getUseYn());
+ layout.setVerInfo(updatedLayout.getVerInfo());
+
+ if (updatedLayout.getLayoutItems() != null && !updatedLayout.getLayoutItems().isEmpty()) {
+ layout.getLayoutItems().clear();
+ updatedLayout.getLayoutItems().forEach(layoutItem -> {
+ layoutItem.setApiLayout(layout); // Set back reference to layout
+ layout.getLayoutItems().add(layoutItem);
+ });
+ }
+
+ return apiLayoutRepository.save(layout);
+ }
+
+ // Method to delete a layout
+ public void deleteLayout(String id) {
+ ApiLayout layout = apiLayoutRepository.findById(id)
+ .orElseThrow(() -> new NotFoundException(String.format("Layout with ID %s not found", id)));
+ apiLayoutRepository.delete(layout);
+ }
+}
diff --git a/src/main/java/com/eactive/testmaster/client/service/NettyTcpApiClient.java b/src/main/java/com/eactive/testmaster/client/service/NettyTcpApiClient.java
index 0c0c09d..aafe9ae 100644
--- a/src/main/java/com/eactive/testmaster/client/service/NettyTcpApiClient.java
+++ b/src/main/java/com/eactive/testmaster/client/service/NettyTcpApiClient.java
@@ -85,22 +85,6 @@ public class NettyTcpApiClient implements ApiClient {
ChannelFuture f = b.connect(host, port).sync();
f.channel().closeFuture().sync();
- // Wait for the response
return answer.take(); // This will block until a message is available
}
-
-
-// public static void main(String[] args) {
-// NettyTcpApiClient client = new NettyTcpApiClient();
-// try {
-// String response = client.sendMessage("localhost", 30913, "00340000BASICTST010134567890ABCDEF");
-// System.out.println("Server replied: " + response);
-// } catch (InterruptedException e) {
-// Thread.currentThread().interrupt();
-// e.printStackTrace();
-// } finally {
-// client.shutdown();
-// }
-// }
-
}
diff --git a/src/main/java/com/eactive/testmaster/client/service/internal/FixedLengthFrameDecoder.java b/src/main/java/com/eactive/testmaster/client/service/internal/FixedLengthFrameDecoder.java
new file mode 100644
index 0000000..bd7c9e5
--- /dev/null
+++ b/src/main/java/com/eactive/testmaster/client/service/internal/FixedLengthFrameDecoder.java
@@ -0,0 +1,25 @@
+package com.eactive.testmaster.client.service.internal;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.handler.codec.ByteToMessageDecoder;
+import java.util.List;
+
+public class FixedLengthFrameDecoder extends ByteToMessageDecoder {
+ private final int frameLength;
+
+ public FixedLengthFrameDecoder(int frameLength) {
+ if (frameLength <= 0) {
+ throw new IllegalArgumentException("frameLength must be a positive integer: " + frameLength);
+ }
+ this.frameLength = frameLength;
+ }
+
+ @Override
+ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List