executor_fix
This commit is contained in:
parent
245225bc7d
commit
cc8b6f7823
13 changed files with 328 additions and 218 deletions
|
|
@ -3,14 +3,10 @@
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
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">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent>
|
|
||||||
<groupId>ervu_secret</groupId>
|
|
||||||
<artifactId>ervu_secret</artifactId>
|
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
<groupId>org.micord</groupId>
|
<groupId>org.micord</groupId>
|
||||||
<artifactId>config-data-executor</artifactId>
|
<artifactId>ConfigDataExecutor</artifactId>
|
||||||
<packaging>war</packaging>
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
|
@ -20,61 +16,88 @@
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.amazonaws</groupId>
|
||||||
|
<artifactId>aws-java-sdk-bom</artifactId>
|
||||||
|
<version>1.12.770</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jooq</groupId>
|
||||||
|
<artifactId>jooq</artifactId>
|
||||||
|
<version>3.19.11</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
<version>3.3.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-tx</artifactId>
|
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||||
</dependency>
|
<version>3.3.2</version>
|
||||||
<dependency>
|
|
||||||
<groupId>com.atomikos</groupId>
|
|
||||||
<artifactId>transactions-jta</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.atomikos</groupId>
|
|
||||||
<artifactId>transactions-jdbc</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>javax.transaction</groupId>
|
|
||||||
<artifactId>javax.transaction-api</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.postgresql</groupId>
|
|
||||||
<artifactId>postgresql</artifactId>
|
|
||||||
<scope>runtime</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
|
<version>1.18.34</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>jakarta.xml.bind</groupId>
|
<groupId>javax.xml.bind</groupId>
|
||||||
<artifactId>jakarta.xml.bind-api</artifactId>
|
<artifactId>jaxb-api</artifactId>
|
||||||
|
<version>2.3.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.sun.xml.bind</groupId>
|
<groupId>org.glassfish.jaxb</groupId>
|
||||||
<artifactId>jaxb-impl</artifactId>
|
<artifactId>jaxb-runtime</artifactId>
|
||||||
|
<version>2.3.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<version>8.0.33</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.postgresql</groupId>
|
||||||
|
<artifactId>postgresql</artifactId>
|
||||||
|
<version>42.7.3</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.arangodb</groupId>
|
<groupId>com.arangodb</groupId>
|
||||||
<artifactId>arangodb-java-driver</artifactId>
|
<artifactId>arangodb-java-driver</artifactId>
|
||||||
|
<version>7.7.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.amazonaws</groupId>
|
<groupId>com.amazonaws</groupId>
|
||||||
<artifactId>aws-java-sdk-s3</artifactId>
|
<artifactId>aws-java-sdk-s3</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.servlet</groupId>
|
<groupId>com.atomikos</groupId>
|
||||||
<artifactId>javax.servlet-api</artifactId>
|
<artifactId>transactions-spring-boot3-starter</artifactId>
|
||||||
<scope>provided</scope>
|
<version>6.0.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.transaction</groupId>
|
||||||
|
<artifactId>jta</artifactId>
|
||||||
|
<version>1.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
|
|
@ -83,32 +106,5 @@
|
||||||
<url>https://repo.maven.apache.org/maven2/</url>
|
<url>https://repo.maven.apache.org/maven2/</url>
|
||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
<build>
|
|
||||||
<finalName>${artifactId}</finalName>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-war-plugin</artifactId>
|
|
||||||
<version>3.1.0</version>
|
|
||||||
<configuration>
|
|
||||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
|
||||||
<version>3.3.3</version>
|
|
||||||
<configuration>
|
|
||||||
<mainClass>org.micord.Main</mainClass>
|
|
||||||
</configuration>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<goals>
|
|
||||||
<goal>repackage</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</project>
|
</project>
|
||||||
|
|
@ -1,15 +1,15 @@
|
||||||
//package org.micord;
|
package org.micord;
|
||||||
//
|
|
||||||
//import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
//import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
//import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
//
|
|
||||||
///**
|
/**
|
||||||
// * @author Maksim Tereshin
|
* @author Maksim Tereshin
|
||||||
// */
|
*/
|
||||||
//@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
|
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
|
||||||
//public class Main {
|
public class Main {
|
||||||
// public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// SpringApplication.run(Main.class, args);
|
SpringApplication.run(Main.class, args);
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
|
|
@ -24,7 +24,7 @@ public class AtomikosConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public TransactionManager atomikosTransactionManager() throws Throwable {
|
public TransactionManager atomikosTransactionManager() {
|
||||||
UserTransactionManager userTransactionManager = new UserTransactionManager();
|
UserTransactionManager userTransactionManager = new UserTransactionManager();
|
||||||
userTransactionManager.setForceShutdown(true);
|
userTransactionManager.setForceShutdown(true);
|
||||||
return userTransactionManager;
|
return userTransactionManager;
|
||||||
|
|
@ -36,3 +36,4 @@ public class AtomikosConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
package org.micord.enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Maksim Tereshin
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public enum RequestArgumentType {
|
||||||
|
SQL("SQL"),
|
||||||
|
AQL("AQL"),
|
||||||
|
S3("S3");
|
||||||
|
|
||||||
|
private final String type;
|
||||||
|
|
||||||
|
RequestArgumentType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,18 +3,40 @@ package org.micord.models;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
import jakarta.xml.bind.annotation.XmlElement;
|
import jakarta.xml.bind.annotation.XmlElement;
|
||||||
|
import jakarta.xml.bind.annotation.XmlElementWrapper;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Maksim Tereshin
|
* @author Maksim Tereshin
|
||||||
*/
|
*/
|
||||||
@Setter
|
@Setter
|
||||||
public class AqlRequest extends Request {
|
public class AqlRequest extends BaseRequest {
|
||||||
|
|
||||||
private AqlConnectionParams aqlConnectionParams;
|
private AqlConnectionParams aqlConnectionParams;
|
||||||
|
private List<AqlRequestCollection> aqlRequestCollections;
|
||||||
|
|
||||||
@XmlElement(name = "AqlConnectionParams")
|
@XmlElement(name = "AqlConnectionParams")
|
||||||
public AqlConnectionParams getAqlConnectionParams() {
|
public AqlConnectionParams getAqlConnectionParams() {
|
||||||
return aqlConnectionParams;
|
return aqlConnectionParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@XmlElementWrapper(name = "AqlRequestCollections")
|
||||||
|
@XmlElement(name = "AqlRequestCollection")
|
||||||
|
public List<AqlRequestCollection> getAqlRequestCollections() {
|
||||||
|
return aqlRequestCollections;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AqlRequestCollection> getReadCollections() {
|
||||||
|
return aqlRequestCollections.stream()
|
||||||
|
.filter(collection -> collection.getType() != null && collection.getType().contains("read"))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AqlRequestCollection> getWriteCollections() {
|
||||||
|
return aqlRequestCollections.stream()
|
||||||
|
.filter(collection -> collection.getType() != null && collection.getType().contains("write"))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
package org.micord.models;
|
||||||
|
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlAttribute;
|
||||||
|
import javax.xml.bind.annotation.XmlValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Maksim Tereshin
|
||||||
|
*/
|
||||||
|
@Setter
|
||||||
|
public class AqlRequestCollection {
|
||||||
|
|
||||||
|
private String type;
|
||||||
|
private String collectionName;
|
||||||
|
|
||||||
|
@XmlAttribute(name = "type")
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlValue
|
||||||
|
public String getCollectionName() {
|
||||||
|
return collectionName;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
package org.micord.models;
|
||||||
|
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import javax.xml.bind.annotation.XmlSeeAlso;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Maksim Tereshin
|
||||||
|
*/
|
||||||
|
@Setter
|
||||||
|
@XmlSeeAlso({SqlRequest.class, S3Request.class, AqlRequest.class})
|
||||||
|
public abstract class BaseRequest {
|
||||||
|
|
||||||
|
private List<RequestArgument> requestArguments;
|
||||||
|
private String requestURL;
|
||||||
|
|
||||||
|
@XmlElement(name = "RequestArgument")
|
||||||
|
public List<RequestArgument> getRequestArguments() {
|
||||||
|
return requestArguments;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement(name = "RequestURL")
|
||||||
|
public String getRequestURL() {
|
||||||
|
return requestURL;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
package org.micord.models;
|
package org.micord.models;
|
||||||
|
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import org.micord.enums.RequestArgumentType;
|
||||||
|
|
||||||
|
import jakarta.xml.bind.annotation.XmlAttribute;
|
||||||
import jakarta.xml.bind.annotation.XmlElement;
|
import jakarta.xml.bind.annotation.XmlElement;
|
||||||
import jakarta.xml.bind.annotation.XmlElementWrapper;
|
import jakarta.xml.bind.annotation.XmlElementWrapper;
|
||||||
import jakarta.xml.bind.annotation.XmlRootElement;
|
import jakarta.xml.bind.annotation.XmlRootElement;
|
||||||
|
|
@ -14,30 +16,29 @@ import java.util.List;
|
||||||
@XmlRootElement(name = "RequestArgument")
|
@XmlRootElement(name = "RequestArgument")
|
||||||
public class RequestArgument {
|
public class RequestArgument {
|
||||||
|
|
||||||
private String id;
|
private RequestArgumentType type;
|
||||||
private List<String> aqlCollectionRead;
|
private String requestArgumentName;;
|
||||||
private String requestURL;
|
private String requestArgumentURL;
|
||||||
private SqlConnectionParams sqlConnectionParams;
|
private SqlConnectionParams requestArgumentConnectionParams;
|
||||||
|
|
||||||
@XmlElement(name = "SqlConnectionParams")
|
@XmlAttribute(name = "type")
|
||||||
public SqlConnectionParams getSqlConnectionParams() {
|
public RequestArgumentType getType() {
|
||||||
return sqlConnectionParams;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlElement(name = "Id")
|
@XmlElement(name = "RequestArgumentName")
|
||||||
public String getId() {
|
public String getRequestArgumentName() {
|
||||||
return id;
|
return requestArgumentName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlElementWrapper(name = "AqlCollectionReads")
|
@XmlElement(name = "RequestArgumentURL")
|
||||||
@XmlElement(name = "AqlCollectionRead")
|
public String getRequestArgumentURL() {
|
||||||
public List<String> getAqlCollectionRead() {
|
return requestArgumentURL;
|
||||||
return aqlCollectionRead;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlElement(name = "RequestURL")
|
@XmlElement(name = "RequestArgumentConnectionParams")
|
||||||
public String getRequestURL() {
|
public SqlConnectionParams getRequestArgumentConnectionParams() {
|
||||||
return requestURL;
|
return requestArgumentConnectionParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import jakarta.xml.bind.annotation.XmlElement;
|
||||||
* @author Maksim Tereshin
|
* @author Maksim Tereshin
|
||||||
*/
|
*/
|
||||||
@Setter
|
@Setter
|
||||||
public class S3Request extends Request {
|
public class S3Request extends BaseRequest {
|
||||||
|
|
||||||
private S3ConnectionParams s3ConnectionParams;
|
private S3ConnectionParams s3ConnectionParams;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import jakarta.xml.bind.annotation.XmlElement;
|
||||||
* @author Maksim Tereshin
|
* @author Maksim Tereshin
|
||||||
*/
|
*/
|
||||||
@Setter
|
@Setter
|
||||||
public class SqlRequest extends Request {
|
public class SqlRequest extends BaseRequest {
|
||||||
|
|
||||||
private SqlConnectionParams sqlConnectionParams;
|
private SqlConnectionParams sqlConnectionParams;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,11 +21,8 @@ import com.arangodb.model.StreamTransactionOptions;
|
||||||
import org.micord.config.ArangoDBConnection;
|
import org.micord.config.ArangoDBConnection;
|
||||||
import org.micord.config.DatabaseConnection;
|
import org.micord.config.DatabaseConnection;
|
||||||
import org.micord.config.S3HttpConnection;
|
import org.micord.config.S3HttpConnection;
|
||||||
import org.micord.models.AqlRequest;
|
import org.micord.enums.RequestArgumentType;
|
||||||
import org.micord.models.RequestArgument;
|
import org.micord.models.*;
|
||||||
import org.micord.models.Requests;
|
|
||||||
import org.micord.models.S3Request;
|
|
||||||
import org.micord.models.SqlRequest;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
@ -67,8 +64,8 @@ public class RequestService {
|
||||||
if (request.getRequestArguments() != null && !request.getRequestArguments().isEmpty()) {
|
if (request.getRequestArguments() != null && !request.getRequestArguments().isEmpty()) {
|
||||||
for (RequestArgument argument : request.getRequestArguments()) {
|
for (RequestArgument argument : request.getRequestArguments()) {
|
||||||
try (Connection connection = DatabaseConnection.getConnection(
|
try (Connection connection = DatabaseConnection.getConnection(
|
||||||
argument.getSqlConnectionParams())) {
|
argument.getRequestArgumentConnectionParams())) {
|
||||||
String query = argument.getRequestURL();
|
String query = argument.getRequestArgumentURL();
|
||||||
List<String> result = fetchFileListFromDatabaseSQL(connection, query);
|
List<String> result = fetchFileListFromDatabaseSQL(connection, query);
|
||||||
if (result != null && !result.isEmpty()) {
|
if (result != null && !result.isEmpty()) {
|
||||||
files.addAll(result);
|
files.addAll(result);
|
||||||
|
|
@ -130,20 +127,29 @@ public class RequestService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processSqlRequests(SqlRequest request, List<String> ids) {
|
private void processSqlRequests(SqlRequest request, List<String> ids) {
|
||||||
String query = null;
|
Map<String, Object> query = buildSqlQuery(request, ids);
|
||||||
try (Connection connection = DatabaseConnection.getConnection(
|
try (Connection connection = DatabaseConnection.getConnection(
|
||||||
request.getSqlConnectionParams())) {
|
request.getSqlConnectionParams())) {
|
||||||
query = buildSqlQuery(request, String.join(",", ids));
|
String requestURL = (String) query.get("requestURL");
|
||||||
int rowsAffected = executeSqlQuery(connection, query);
|
executeSqlQuery(connection, requestURL);
|
||||||
logger.info("Successfully deleted {} rows for IDs: {} in query: {}", rowsAffected, String.join(", ", ids), query);
|
|
||||||
|
List<String> queryIds = (List<String>) query.get("ids");
|
||||||
|
if (queryIds != null && !queryIds.isEmpty()) {
|
||||||
|
ids.addAll(queryIds);
|
||||||
|
} else {
|
||||||
|
logger.warn("No IDs found for the query");
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("Successfully executed query {} for IDs: ({})", requestURL, String.join(", ", ids));
|
||||||
}
|
}
|
||||||
catch (SQLException e) {
|
catch (SQLException e) {
|
||||||
logger.error("SQL execution failed for query: {}", query, e);
|
logger.error("SQL execution failed for query: {}", query, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String buildSqlQuery(SqlRequest request, String ids) {
|
private Map<String, Object> buildSqlQuery(SqlRequest request, List<String> ids) {
|
||||||
String endpointArguments = " (" + Arrays.stream(ids.split(","))
|
Map<String, Object> resultMap = new HashMap<>();
|
||||||
|
String endpointArguments = "(" + ids.stream()
|
||||||
.map(id -> "'" + id.trim() + "'")
|
.map(id -> "'" + id.trim() + "'")
|
||||||
.collect(Collectors.joining(", ")) + ")";
|
.collect(Collectors.joining(", ")) + ")";
|
||||||
|
|
||||||
|
|
@ -152,19 +158,24 @@ public class RequestService {
|
||||||
if (request.getRequestArguments() != null && !request.getRequestArguments().isEmpty()) {
|
if (request.getRequestArguments() != null && !request.getRequestArguments().isEmpty()) {
|
||||||
for (RequestArgument argument : request.getRequestArguments()) {
|
for (RequestArgument argument : request.getRequestArguments()) {
|
||||||
|
|
||||||
if (argument.getSqlConnectionParams() != null) {
|
if (argument.getRequestArgumentConnectionParams() != null) {
|
||||||
try (Connection connection = DatabaseConnection.getConnection(
|
try (Connection connection = DatabaseConnection.getConnection(
|
||||||
argument.getSqlConnectionParams())) {
|
argument.getRequestArgumentConnectionParams())) {
|
||||||
String query = argument.getRequestURL();
|
String query = argument.getRequestArgumentURL();
|
||||||
List<String> result = fetchFileListFromDatabaseSQL(connection, query);
|
List<String> result = fetchFileListFromDatabaseSQL(connection, query);
|
||||||
|
|
||||||
|
resultMap.put("ids", result);
|
||||||
|
|
||||||
|
|
||||||
if (result != null && !result.isEmpty()) {
|
if (result != null && !result.isEmpty()) {
|
||||||
String resultSet = " (" + result.stream()
|
String resultSet = "(" + result.stream()
|
||||||
.map(s -> "'" + s.trim() + "'")
|
.map(s -> "'" + s.trim() + "'")
|
||||||
.collect(Collectors.joining(", ")) + ")";
|
.collect(Collectors.joining(", ")) + ")";
|
||||||
|
|
||||||
requestURL = requestURL.replace("${" + argument.getId() + "}", resultSet);
|
requestURL = requestURL.replace("${" + argument.getRequestArgumentName() + "}", resultSet);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (SQLException e) {
|
catch (SQLException e) {
|
||||||
logger.error("Failed to execute query for RequestArgument", e);
|
logger.error("Failed to execute query for RequestArgument", e);
|
||||||
|
|
@ -173,14 +184,16 @@ public class RequestService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return requestURL
|
resultMap.put("requestURL", requestURL
|
||||||
.replace("${DB}", request.getSqlConnectionParams().getJdbcDatabase())
|
.replace("${DB}", request.getSqlConnectionParams().getJdbcDatabase())
|
||||||
.replace("${endpointArguments}", endpointArguments);
|
.replace("${endpointArguments}", endpointArguments));
|
||||||
|
|
||||||
|
return resultMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int executeSqlQuery(Connection connection, String query) throws SQLException {
|
private boolean executeSqlQuery(Connection connection, String query) throws SQLException {
|
||||||
try (PreparedStatement stmt = connection.prepareStatement(query)) {
|
try (PreparedStatement stmt = connection.prepareStatement(query)) {
|
||||||
return stmt.executeUpdate();
|
return stmt.execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -199,9 +212,14 @@ public class RequestService {
|
||||||
private void processAqlRequests(AqlRequest request, List<String> ids) {
|
private void processAqlRequests(AqlRequest request, List<String> ids) {
|
||||||
ArangoDatabase arangoDb = ArangoDBConnection.getConnection(request.getAqlConnectionParams());
|
ArangoDatabase arangoDb = ArangoDBConnection.getConnection(request.getAqlConnectionParams());
|
||||||
|
|
||||||
|
// TODO: implement for multiple request arguments
|
||||||
RequestArgument requestArgument = request.getRequestArguments().get(0);
|
RequestArgument requestArgument = request.getRequestArguments().get(0);
|
||||||
List<String> aqlCollectionRead = requestArgument.getAqlCollectionRead();
|
List<String> aqlCollectionRead = request.getReadCollections().stream()
|
||||||
String aqlCollectionWrite = requestArgument.getId();
|
.map(AqlRequestCollection::getCollectionName)
|
||||||
|
.toList();
|
||||||
|
String aqlCollectionWrite = String.valueOf(request.getWriteCollections().stream()
|
||||||
|
.map(AqlRequestCollection::getCollectionName)
|
||||||
|
.findFirst());
|
||||||
|
|
||||||
StreamTransactionEntity tx = null;
|
StreamTransactionEntity tx = null;
|
||||||
try {
|
try {
|
||||||
|
|
@ -214,10 +232,8 @@ public class RequestService {
|
||||||
|
|
||||||
logger.info("Stream transaction started with ID: {}", transactionId);
|
logger.info("Stream transaction started with ID: {}", transactionId);
|
||||||
|
|
||||||
List<String> entities = executeSelectAqlRequest(arangoDb, request.getRequestArguments(), ids,
|
Map<String, Object> entities = executeSelectAqlRequest(arangoDb, aqlCollectionWrite, requestArgument, ids, transactionId);
|
||||||
transactionId
|
executeMainAqlRequest(arangoDb, aqlCollectionWrite, request.getRequestURL(), entities, transactionId);
|
||||||
);
|
|
||||||
executeMainAqlRequest(arangoDb, request, entities, transactionId);
|
|
||||||
|
|
||||||
arangoDb.commitStreamTransaction(transactionId);
|
arangoDb.commitStreamTransaction(transactionId);
|
||||||
logger.info("Stream transaction with ID {} committed successfully", transactionId);
|
logger.info("Stream transaction with ID {} committed successfully", transactionId);
|
||||||
|
|
@ -234,73 +250,71 @@ public class RequestService {
|
||||||
logger.info("Successfully executed AQL request");
|
logger.info("Successfully executed AQL request");
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> executeSelectAqlRequest(ArangoDatabase arangoDb,
|
private Map<String, Object> executeSelectAqlRequest(ArangoDatabase arangoDb,
|
||||||
List<RequestArgument> requestArguments,
|
String aqlCollectionWrite,
|
||||||
|
RequestArgument requestArgument,
|
||||||
List<String> ids, String transactionId) {
|
List<String> ids, String transactionId) {
|
||||||
List<String> entityIdList = new ArrayList<>();
|
Map<String, Object> entities = new HashMap<>();
|
||||||
|
|
||||||
RequestArgument argument = requestArguments.get(0);
|
String url = requestArgument.getRequestArgumentURL();
|
||||||
|
RequestArgumentType type = requestArgument.getType();
|
||||||
String query = argument.getRequestURL();
|
|
||||||
String entityType = argument.getId();
|
|
||||||
|
|
||||||
|
if (type == RequestArgumentType.AQL) {
|
||||||
Map<String, Object> bindVars = new HashMap<>();
|
Map<String, Object> bindVars = new HashMap<>();
|
||||||
bindVars.put("ids", ids);
|
bindVars.put("ids", ids);
|
||||||
|
|
||||||
AqlQueryOptions aqlQueryOptions = new AqlQueryOptions().streamTransactionId(transactionId);
|
AqlQueryOptions aqlQueryOptions = new AqlQueryOptions().streamTransactionId(transactionId);
|
||||||
|
|
||||||
try (ArangoCursor<Map> cursor = arangoDb.query(query, Map.class, bindVars, aqlQueryOptions)) {
|
try (ArangoCursor<Map> cursor = arangoDb.query(url, Map.class, bindVars, aqlQueryOptions)) {
|
||||||
while (cursor.hasNext()) {
|
while (cursor.hasNext()) {
|
||||||
Map result = cursor.next();
|
Map<String, Object> result = cursor.next();
|
||||||
switch (entityType) {
|
|
||||||
case "applicationId":
|
for (Map.Entry<String, Object> entry : result.entrySet()) {
|
||||||
entityIdList.add((String) result.get("applicationId"));
|
String key = entry.getKey();
|
||||||
break;
|
Object entityValue = entry.getValue();
|
||||||
case "edgesId":
|
|
||||||
entityIdList.addAll((List<String>) result.get("edgesId"));
|
entities.put(key, entityValue);
|
||||||
break;
|
|
||||||
case "subjectId":
|
|
||||||
entityIdList.addAll((List<String>) result.get("subjectId"));
|
|
||||||
break;
|
|
||||||
case "historyId":
|
|
||||||
entityIdList.addAll((List<String>) result.get("historyId"));
|
|
||||||
break;
|
|
||||||
case "interdepreqId":
|
|
||||||
entityIdList.addAll((List<String>) result.get("interdepreqId"));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException("Invalid requestArgumentId: " + entityType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
logger.error("Failed to execute AQL query", e);
|
logger.error("Failed to execute AQL url", e);
|
||||||
|
}
|
||||||
|
} else if (type == RequestArgumentType.SQL) {
|
||||||
|
if (requestArgument.getRequestArgumentConnectionParams() != null) {
|
||||||
|
try (Connection connection = DatabaseConnection.getConnection(
|
||||||
|
requestArgument.getRequestArgumentConnectionParams())) {
|
||||||
|
String query = requestArgument.getRequestArgumentURL();
|
||||||
|
List<String> result = fetchFileListFromDatabaseSQL(connection, query);
|
||||||
|
|
||||||
|
entities.put(aqlCollectionWrite, result);
|
||||||
|
}
|
||||||
|
catch (SQLException e) {
|
||||||
|
logger.error("Failed to execute query for RequestArgument", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return entityIdList;
|
return entities;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executeMainAqlRequest(ArangoDatabase arangoDb, AqlRequest request,
|
private void executeMainAqlRequest(ArangoDatabase arangoDb, String aqlCollectionWrite, String requestURL,
|
||||||
List<String> entityIdList, String transactionId) {
|
Map<String, Object> entities, String transactionId) {
|
||||||
if (entityIdList == null || entityIdList.isEmpty()) {
|
if (entities == null || entities.isEmpty()) {
|
||||||
logger.warn("No entities found for main AQL request.");
|
logger.warn("No entities found for main AQL request.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String entity = request.getRequestArguments().get(0).getId();
|
|
||||||
|
|
||||||
Map<String, Object> bindVars = new HashMap<>();
|
Map<String, Object> bindVars = new HashMap<>();
|
||||||
bindVars.put("ids", entityIdList);
|
// TODO: verify correctness of received entities and compare keys
|
||||||
|
Object writeEntity = entities.get(aqlCollectionWrite);
|
||||||
|
bindVars.put("ids", entities);
|
||||||
String finalQuery = request.getRequestURL()
|
|
||||||
.replace("${entity}", entity);
|
|
||||||
|
|
||||||
AqlQueryOptions aqlQueryOptions = new AqlQueryOptions().streamTransactionId(transactionId);
|
AqlQueryOptions aqlQueryOptions = new AqlQueryOptions().streamTransactionId(transactionId);
|
||||||
|
|
||||||
arangoDb.query(finalQuery, null, bindVars, aqlQueryOptions);
|
arangoDb.query(requestURL, null, bindVars, aqlQueryOptions);
|
||||||
|
|
||||||
logger.info("Successfully removed {}: {}", entity, entityIdList);
|
logger.info("Successfully removed {}: {}", aqlCollectionWrite, writeEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@
|
||||||
<extension module="org.wildfly.extension.request-controller"/>
|
<extension module="org.wildfly.extension.request-controller"/>
|
||||||
<extension module="org.wildfly.extension.security.manager"/>
|
<extension module="org.wildfly.extension.security.manager"/>
|
||||||
<extension module="org.wildfly.extension.undertow"/>
|
<extension module="org.wildfly.extension.undertow"/>
|
||||||
|
<property name="configDirectory" value="C:\work\ervu-secret\config-data-executor\config-examples"/>
|
||||||
</extensions>
|
</extensions>
|
||||||
<system-properties>
|
<system-properties>
|
||||||
<property name="webbpm.mode" value="production"/>
|
<property name="webbpm.mode" value="production"/>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue