Socket Client UI 기본 골격 작성
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
+25
@@ -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<Object> out) {
|
||||
while (in.readableBytes() >= frameLength) {
|
||||
ByteBuf buf = in.readBytes(frameLength);
|
||||
out.add(buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user