Commit d641d4d8 authored by Youn Cadoret's avatar Youn Cadoret
Browse files

create new jar for recording mock transaction

git-svn-id: https://scm.gforge.inria.fr/authscm/ycadoret/svn/gazelle/Maven/simulators/gazelle-webservice-tester/trunk@67414 356b4b1a-1d2b-0410-8bf1-ffa24008f01e
parent 888c3914
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>gazelle-webservice-tester</artifactId>
<groupId>net.ihe.gazelle</groupId>
<version>1.6.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>gwt-message-recording-for-mock</artifactId>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.1.jre7</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>7</source>
<target>7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package net.ihe.gazelle.wstester.mockrecord;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* <p>RecordMessages class.</p>
*
* @author ycadoret
* @version 1.0: 28/05/19
*/
public class RecordMessages {
private final String url = "jdbc:postgresql://localhost:5432/gazelle-webservice-tester";
private final String user = "gazelle";
private final String password = "gazelle";
/**
* Connect to the PostgreSQL database
*
* @return a Connection object
* @throws java.sql.SQLException
*/
public Connection connect() throws SQLException {
return DriverManager.getConnection(url, user, password);
}
/**
* Get all id in the domain table
*
* @return id domain
* @throws java.sql.SQLException
*/
public int getDomainId(String keyword) throws SQLException {
String SQL = "SELECT id from tf_domain where keyword like ?;";
int result = getSelectId(SQL, keyword);
return result;
}
/**
* Get all id in the transaction table
*
* @return id transaction
* @throws java.sql.SQLException
*/
public int getTransactionId(String keyword) throws SQLException {
String SQL = "SELECT id from tf_transaction where keyword like ?;";
int result = getSelectId(SQL, keyword);
return result;
}
/**
* Get all id in the actor table
*
* @return id actor
* @throws java.sql.SQLException
*/
public int getActorId(String keyword) throws SQLException {
String SQL = "SELECT id from tf_actor where keyword like ?;";
int result = getSelectId(SQL, keyword);
return result;
}
/**
* Get all id in the request table
*
* @return id request
* @throws java.sql.SQLException
*/
public int getRequestId(String address) throws SQLException {
String SQL = "SELECT MAX(ID) as id from cmn_message_instance where issuer_ip_address like ?;";
int result = getSelectId(SQL, address);
return result;
}
/**
* Get all id in the response table
*
* @return id response
* @throws java.sql.SQLException
*/
public int getResponseId(String address) throws SQLException {
String SQL = "SELECT MAX(ID) as id from cmn_message_instance where issuer_ip_address like ?";
int result = getSelectId(SQL, address);
return result;
}
/**
* Get id with select request
*
* @return int id
* @throws java.sql.SQLException
*/
public int getSelectId(String SQL, String keyword) throws SQLException {
int result = 0;
Connection conn = connect();
try (PreparedStatement st = conn.prepareStatement(SQL)) {
st.setString(1, keyword);
try (ResultSet rs = st.executeQuery()) {
while (rs.next()) {
result = rs.getInt("id");
}
}
}
return result;
}
/**
* insert messages in table
*
* @throws java.sql.SQLException
*/
public void insertMessageInstance(byte[] content, String issuer, String issuerAddress, String messageType, int actor) throws SQLException {
String SQL = "INSERT INTO cmn_message_instance (id, content, issuer, issuer_ip_address, type, validation_detailed_result, validation_status, issuing_actor) "
+ "VALUES (nextval('cmn_message_instance_id_seq'),?,?,?,?, null, null,?);";
try (Connection conn = connect();
PreparedStatement st = conn.prepareStatement(SQL)) {
if (actor == 0) {
st.setNull(5, Types.INTEGER);
} else {
st.setInt(5, actor);
}
st.setBytes(1, content);
st.setString(2, issuer);
st.setString(3, issuerAddress);
st.setString(4, messageType);
st.executeUpdate();
}
}
/**
* insert transaction in table
*
* @throws java.sql.SQLException
*/
public void insertTransactionInstance(String companyKeyword, String standard, int domainId, int requestId, int responseId, int actorId, int transactionId) throws SQLException {
String SQL = "INSERT INTO cmn_transaction_instance (id, company_keyword, standard, timestamp, is_visible, domain_id, request_id, response_id, simulated_actor_id, transaction_id) "
+ "VALUES (nextval('cmn_transaction_instance_id_seq'),?, ?, ?, ?, ?, ?, ?, ?, ? );";
Date date = new Date();
Timestamp ts = new Timestamp(date.getTime());
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try (Connection conn = connect();
PreparedStatement st = conn.prepareStatement(SQL)) {
if (domainId == 0) {
st.setNull(5, Types.INTEGER);
} else {
st.setInt(5, domainId);
}
if (actorId == 0) {
st.setNull(8, Types.INTEGER);
} else {
st.setInt(8, actorId);
}
if (transactionId == 0) {
st.setNull(9, Types.INTEGER);
} else {
st.setInt(9, transactionId);
}
if (requestId == 0) {
st.setNull(6, Types.INTEGER);
} else {
st.setInt(6, requestId);
}
if (responseId == 0) {
st.setNull(7, Types.INTEGER);
} else {
st.setInt(7, responseId);
}
st.setString(1, companyKeyword);
st.setString(2, standard);
st.setTimestamp(3, ts);
st.setBoolean(4, true);
st.executeUpdate();
}
}
public static void main(String args[]) throws SQLException {
RecordMessages record = new RecordMessages();
//System.out.println(record.getTransactionId("test"));
//record.insertMessageInstance("null", "mock", "sender_ip", "SubmitObjectsRequest", "null", null, record.getActorId("UNKNOWN"));
//record.insertMessageInstance("null", "responder_ip", "responder_ip", "RegistryResponse", null, null, record.getActorId("UNKNOWN"));
//record.insertTransactionInstance("companyKeyword", null, record.getDomainId("ITI"), record.getRequestId("127.0.0.1"), record.getResponseId("SoapUI Mock"), record.getActorId("UNKNOWN"), record.getTransactionId("test"));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment