attach-javadocs
diff --git a/repository-basex/pom.xml b/repository-basex/pom.xml
deleted file mode 100644
index c6452608..00000000
--- a/repository-basex/pom.xml
+++ /dev/null
@@ -1,94 +0,0 @@
-
-
-
- 4.0.0
-
- org.lfenergy.compas.scl.data
- compas-scl-data-service
- local-SNAPSHOT
-
-
- repository-basex
- jar
-
-
- 9.2.4
-
-
-
-
- org.lfenergy.compas.scl.data
- repository
-
-
-
- commons-io
- commons-io
-
-
-
- org.eclipse.microprofile.config
- microprofile-config-api
-
-
- com.sun.xml.bind
- jaxb-impl
- provided
-
-
-
- org.apache.logging.log4j
- log4j-api
-
-
- org.apache.logging.log4j
- log4j-core
- provided
-
-
-
-
- org.lfenergy.compas.scl.data
- repository
- test-jar
- test
-
-
- org.basex
- basex
- ${basex.version}
- test
-
-
-
- org.junit.jupiter
- junit-jupiter-api
- test
-
-
- org.mockito
- mockito-junit-jupiter
- test
-
-
- org.junit.jupiter
- junit-jupiter-engine
- test
-
-
-
-
-
-
- org.jboss.jandex
- jandex-maven-plugin
-
-
-
-
diff --git a/repository-basex/src/main/java/org/lfenergy/compas/scl/data/basex/client/BaseXClient.java b/repository-basex/src/main/java/org/lfenergy/compas/scl/data/basex/client/BaseXClient.java
deleted file mode 100644
index 2d8d6734..00000000
--- a/repository-basex/src/main/java/org/lfenergy/compas/scl/data/basex/client/BaseXClient.java
+++ /dev/null
@@ -1,462 +0,0 @@
-// SPDX-FileCopyrightText: 2020 Alliander N.V.
-//
-// SPDX-License-Identifier: Apache-2.0
-
-package org.lfenergy.compas.scl.data.basex.client;
-
-import org.lfenergy.compas.scl.data.exception.CompasSclDataServiceException;
-
-import java.io.*;
-import java.net.InetSocketAddress;
-import java.net.Socket;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.util.ArrayList;
-
-import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.lfenergy.compas.scl.data.exception.CompasSclDataServiceErrorCode.BASEX_CLIENT_CREATION_ERROR_CODE;
-
-/**
- * Java client for BaseX.
- * Works with BaseX 7.0 and later
- *
- * Documentation: https://docs.basex.org/wiki/Clients
- *
- * (C) BaseX Team 2005-20, BSD License
- */
-public class BaseXClient implements Closeable {
-
- /**
- * Output stream.
- */
- private final OutputStream out;
- /**
- * Input stream (buffered).
- */
- private final BufferedInputStream in;
-
- /**
- * Socket.
- */
- private final Socket socket;
- /**
- * Command info.
- */
- private String info;
-
- /**
- * Constructor.
- *
- * @param host server name
- * @param port server port
- * @param username username
- * @param password password
- * @throws IOException Exception
- */
- public BaseXClient(final String host, final int port, final String username,
- final String password) throws IOException {
-
- socket = new Socket();
- socket.setTcpNoDelay(true);
- socket.connect(new InetSocketAddress(host, port), 5000);
- in = new BufferedInputStream(socket.getInputStream());
- out = socket.getOutputStream();
-
- // receive server response
- final String[] response = receive().split(":");
- final String code;
- final String nonce;
- if (response.length > 1) {
- // support for digest authentication
- code = username + ':' + response[0] + ':' + password;
- nonce = response[1];
- } else {
- // support for cram-md5 (Version < 8.0)
- code = password;
- nonce = response[0];
- }
-
- send(username);
- send(md5(md5(code) + nonce));
-
- // receive success flag
- if (!ok()) throw new IOException("Access denied.");
- }
-
- /**
- * Executes a command and serializes the result to an output stream.
- *
- * @param command command
- * @param output output stream
- * @throws IOException Exception
- */
- public void execute(final String command, final OutputStream output) throws IOException {
- // send {Command}0
- send(command);
- receive(in, output);
- info = receive();
- if (!ok()) throw new IOException(info);
- }
-
- /**
- * Executes a command and returns the result.
- *
- * @param command command
- * @return result
- * @throws IOException Exception
- */
- public String execute(final String command) throws IOException {
- final var os = new ByteArrayOutputStream();
- execute(command, os);
- return os.toString(UTF_8);
- }
-
- /**
- * Executes a XQuery Command and returns the result.
- *
- * @param xqueryCommand command
- * @return result
- * @throws IOException Exception
- */
- public String executeXQuery(final String xqueryCommand) throws IOException {
- return execute("xquery " + xqueryCommand);
-
- }
-
- /**
- * Creates a query object.
- *
- * @param query query string
- * @return query
- * @throws IOException Exception
- */
- public Query query(final String query) throws IOException {
- return new Query(query);
- }
-
- /**
- * Creates a database.
- *
- * @param name name of database
- * @param input xml input
- * @throws IOException I/O exception
- */
- public void create(final String name, final InputStream input) throws IOException {
- send(8, name, input);
- }
-
- /**
- * Adds a document to a database.
- *
- * @param path path to resource
- * @param input xml input
- * @throws IOException I/O exception
- */
- public void add(final String path, final InputStream input) throws IOException {
- send(9, path, input);
- }
-
- /**
- * Replaces a document in a database.
- *
- * @param path path to resource
- * @param input xml input
- * @throws IOException I/O exception
- */
- public void replace(final String path, final InputStream input) throws IOException {
- send(12, path, input);
- }
-
- /**
- * Stores a binary resource in a database.
- *
- * @param path path to resource
- * @param input xml input
- * @throws IOException I/O exception
- */
- public void store(final String path, final InputStream input) throws IOException {
- send(13, path, input);
- }
-
- /**
- * Closes the session.
- *
- * @throws IOException Exception
- */
- @Override
- public void close() throws IOException {
- send("exit");
- out.flush();
- socket.close();
- }
-
- /**
- * Checks the next success flag.
- *
- * @return value of check
- * @throws IOException Exception
- */
- private boolean ok() throws IOException {
- out.flush();
- return in.read() == 0;
- }
-
- /**
- * Returns the next received string.
- *
- * @return String result or info
- * @throws IOException I/O exception
- */
- private String receive() throws IOException {
- final var os = new ByteArrayOutputStream();
- receive(in, os);
- return os.toString(UTF_8);
- }
-
- /**
- * Sends a string to the server.
- *
- * @param string string to be sent
- * @throws IOException I/O exception
- */
- private void send(final String string) throws IOException {
- out.write((string + '\0').getBytes(UTF_8));
- }
-
- /**
- * Receives a string and writes it to the specified output stream.
- *
- * @param input input stream
- * @param output output stream
- * @throws IOException I/O exception
- */
- private static void receive(final InputStream input, final OutputStream output)
- throws IOException {
- for (int b; (b = input.read()) > 0; ) {
- // read next byte if 0xFF is received
- output.write(b == 0xFF ? input.read() : b);
- }
- }
-
- /**
- * Sends a command, argument, and input.
- *
- * @param code command code
- * @param path name, or path to resource
- * @param input xml input
- * @throws IOException I/O exception
- */
- private void send(final int code, final String path, final InputStream input) throws IOException {
- out.write(code);
- send(path);
- send(input);
- }
-
- /**
- * Sends an input stream to the server.
- *
- * @param input xml input
- * @throws IOException I/O exception
- */
- private void send(final InputStream input) throws IOException {
- final var bis = new BufferedInputStream(input);
- final var bos = new BufferedOutputStream(out);
- for (int b; (b = bis.read()) != -1; ) {
- // 0x00 and 0xFF will be prefixed by 0xFF
- if (b == 0x00 || b == 0xFF) bos.write(0xFF);
- bos.write(b);
- }
- bos.write(0);
- bos.flush();
- info = receive();
- if (!ok()) throw new IOException(info);
- }
-
- /**
- * Returns an MD5 hash.
- *
- * @param pw String
- * @return String
- */
- private static String md5(final String pw) {
- final var sb = new StringBuilder();
- try {
- // BaseX uses MD5 hashing, so we can change this for now.
- final var md = MessageDigest.getInstance("MD5"); // NOSONAR
- md.update(pw.getBytes());
- for (final byte b : md.digest()) {
- final var s = Integer.toHexString(b & 0xFF);
- if (s.length() == 1) sb.append('0');
- sb.append(s);
- }
- } catch (final NoSuchAlgorithmException exp) {
- throw new CompasSclDataServiceException(BASEX_CLIENT_CREATION_ERROR_CODE, "Unknwn Algorithm", exp);
- }
- return sb.toString();
- }
-
- /**
- * Inner class for iterative query execution.
- */
- public class Query implements Closeable {
- /**
- * Query id.
- */
- private final String id;
- /**
- * Cached results.
- */
- private ArrayList cache;
- /**
- * Cache pointer.
- */
- private int pos;
-
- /**
- * Standard constructor.
- *
- * @param query query string
- * @throws IOException I/O exception
- */
- Query(final String query) throws IOException {
- id = exec(0, query);
- }
-
- /**
- * Binds a value to an external variable.
- *
- * @param name name of variable
- * @param value value
- * @throws IOException I/O exception
- */
- public void bind(final String name, final String value) throws IOException {
- bind(name, value, "");
- }
-
- /**
- * Binds a value with the specified type to an external variable.
- *
- * @param name name of variable
- * @param value value
- * @param type type (can be an empty string)
- * @throws IOException I/O exception
- */
- public void bind(final String name, final String value, final String type) throws IOException {
- cache = null;
- exec(3, id + '\0' + name + '\0' + value + '\0' + type);
- }
-
- /**
- * Binds a value to the context item.
- *
- * @param value value
- * @throws IOException I/O exception
- */
- public void context(final String value) throws IOException {
- context(value, "");
- }
-
- /**
- * Binds a value with the specified type to the context item.
- *
- * @param value value
- * @param type type (can be an empty string)
- * @throws IOException I/O exception
- */
- public void context(final String value, final String type) throws IOException {
- cache = null;
- exec(14, id + '\0' + value + '\0' + type);
- }
-
- /**
- * Checks for the next item.
- *
- * @return result of check
- * @throws IOException I/O exception
- */
- public boolean more() throws IOException {
- if (cache == null) {
- out.write(4);
- send(id);
- cache = new ArrayList<>();
- final var os = new ByteArrayOutputStream();
- while (in.read() > 0) {
- receive(in, os);
- cache.add(os.toByteArray());
- os.reset();
- }
- if (!ok()) throw new IOException(receive());
- pos = 0;
- }
- if (pos < cache.size()) return true;
- cache = null;
- return false;
- }
-
- /**
- * Returns the next item.
- *
- * @return item string
- * @throws IOException I/O Exception
- */
- public String next() throws IOException {
- return more() ? new String(cache.set(pos++, null), UTF_8) : null;
- }
-
- /**
- * Returns the whole result of the query.
- *
- * @return query result
- * @throws IOException I/O Exception
- */
- public String execute() throws IOException {
- return exec(5, id);
- }
-
- /**
- * Returns query info in a string.
- *
- * @return query info
- * @throws IOException I/O exception
- */
- public String info() throws IOException {
- return exec(6, id);
- }
-
- /**
- * Returns serialization parameters in a string.
- *
- * @return query info
- * @throws IOException I/O exception
- */
- public String options() throws IOException {
- return exec(7, id);
- }
-
- /**
- * Closes the query.
- *
- * @throws IOException I/O exception
- */
- @Override
- public void close() throws IOException {
- exec(2, id);
- }
-
- /**
- * Executes the specified command.
- *
- * @param code command code
- * @param arg argument
- * @return resulting string
- * @throws IOException I/O exception
- */
- private String exec(final int code, final String arg) throws IOException {
- out.write(code);
- send(arg);
- final String s = receive();
- if (!ok()) throw new IOException(receive());
- return s;
- }
- }
-}
\ No newline at end of file
diff --git a/repository-basex/src/main/java/org/lfenergy/compas/scl/data/basex/client/BaseXClientFactory.java b/repository-basex/src/main/java/org/lfenergy/compas/scl/data/basex/client/BaseXClientFactory.java
deleted file mode 100644
index 5d97fa53..00000000
--- a/repository-basex/src/main/java/org/lfenergy/compas/scl/data/basex/client/BaseXClientFactory.java
+++ /dev/null
@@ -1,33 +0,0 @@
-// SPDX-FileCopyrightText: 2021 Alliander N.V.
-//
-// SPDX-License-Identifier: Apache-2.0
-package org.lfenergy.compas.scl.data.basex.client;
-
-import org.eclipse.microprofile.config.inject.ConfigProperty;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.inject.Inject;
-import java.io.IOException;
-
-@ApplicationScoped
-public class BaseXClientFactory {
- private final String baseXHost;
- private final Integer baseXPort;
- private final String baseXUsername;
- private final String baseXPassword;
-
- @Inject
- public BaseXClientFactory(@ConfigProperty(name = "basex.host") String baseXHost,
- @ConfigProperty(name = "basex.port") Integer baseXPort,
- @ConfigProperty(name = "basex.username") String baseXUsername,
- @ConfigProperty(name = "basex.password") String baseXPassword) {
- this.baseXHost = baseXHost;
- this.baseXPort = baseXPort;
- this.baseXUsername = baseXUsername;
- this.baseXPassword = baseXPassword;
- }
-
- public BaseXClient createClient() throws IOException {
- return new BaseXClient(baseXHost, baseXPort, baseXUsername, baseXPassword);
- }
-}
diff --git a/repository-basex/src/main/java/org/lfenergy/compas/scl/data/basex/repository/CompasSclDataBaseXRepository.java b/repository-basex/src/main/java/org/lfenergy/compas/scl/data/basex/repository/CompasSclDataBaseXRepository.java
deleted file mode 100644
index 65f52043..00000000
--- a/repository-basex/src/main/java/org/lfenergy/compas/scl/data/basex/repository/CompasSclDataBaseXRepository.java
+++ /dev/null
@@ -1,329 +0,0 @@
-// SPDX-FileCopyrightText: 2021 Alliander N.V.
-//
-// SPDX-License-Identifier: Apache-2.0
-package org.lfenergy.compas.scl.data.basex.repository;
-
-import org.apache.commons.io.input.ReaderInputStream;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.lfenergy.compas.scl.data.basex.client.BaseXClient;
-import org.lfenergy.compas.scl.data.basex.client.BaseXClientFactory;
-import org.lfenergy.compas.scl.data.exception.CompasNoDataFoundException;
-import org.lfenergy.compas.scl.data.exception.CompasSclDataServiceException;
-import org.lfenergy.compas.scl.data.model.HistoryItem;
-import org.lfenergy.compas.scl.data.model.Item;
-import org.lfenergy.compas.scl.data.model.SclMetaInfo;
-import org.lfenergy.compas.scl.data.model.Version;
-import org.lfenergy.compas.scl.data.repository.CompasSclDataRepository;
-import org.lfenergy.compas.scl.data.util.SclDataModelMarshaller;
-import org.lfenergy.compas.scl.extensions.model.SclFileType;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.inject.Inject;
-import javax.transaction.Transactional;
-import java.io.IOException;
-import java.io.StringReader;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.UUID;
-
-import static javax.transaction.Transactional.TxType.REQUIRED;
-import static javax.transaction.Transactional.TxType.SUPPORTS;
-import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI;
-import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_NS_URI;
-import static org.lfenergy.compas.scl.data.exception.CompasSclDataServiceErrorCode.BASEX_COMMAND_ERROR_CODE;
-import static org.lfenergy.compas.scl.data.exception.CompasSclDataServiceErrorCode.BASEX_QUERY_ERROR_CODE;
-import static org.lfenergy.compas.scl.extensions.commons.CompasExtensionsConstants.COMPAS_EXTENSION_NS_URI;
-import static org.lfenergy.compas.scl.extensions.commons.CompasExtensionsConstants.COMPAS_SCL_EXTENSION_TYPE;
-
-/**
- * This implementation of the repository will store the SCL XML Files in BaseX, this is a XML Database.
- * For more information see https://basex.org/.
- *
- * For every type of SCL a separate database is created in which the SCL XML Files are stored.
- * Every entry is stored under <ID>/<Major version>/<Minor version>/<Patch version>/scl.xml.
- * This combination is always unique and easy to use.
- */
-@ApplicationScoped
-public class CompasSclDataBaseXRepository implements CompasSclDataRepository {
- private static final Logger LOGGER = LogManager.getLogger(CompasSclDataBaseXRepository.class);
-
- private static final String DECLARE_NS_AND_VARS = """
- declare namespace scl = "%s";
- declare namespace compas = "%s";
-
- declare variable $compasSclExtensionType := '%s';
- declare variable $compasDataServiceNamespace := '%s';
- """.formatted(SCL_NS_URI, COMPAS_EXTENSION_NS_URI, COMPAS_SCL_EXTENSION_TYPE, SCL_DATA_SERVICE_V1_NS_URI);
-
- // This find method always searches for the latest version. Retrieve all versions using db:list-details function.
- // Sort the result descending, this way the last version is the first.
- private static final String DECLARE_LATEST_VERSION_FUNC = """
- declare function local:latest-version($db as xs:string, $id as xs:string) as document-node()? {
- let $doc :=
- (for $resource in db:open($db, $id)
- let $parts := tokenize($resource/scl:SCL/scl:Header/@version, '\\.')
- let $majorVersion := xs:int($parts[1])
- let $minorVersion := xs:int($parts[2])
- let $patchVersion := xs:int($parts[3])
- order by $majorVersion descending, $minorVersion descending, $patchVersion descending
- return $resource
- )[1]
- return $doc
- };
- """;
-
- // Retrieve the Labels as XML Label elements from the XML. The result can be returned by the List functions.
- private static final String DECLARE_LABELS_FUNC = """
- declare function local:createLabelsResponse($latestScl as document-node()) as xs:string* {
- let $labels := distinct-values($latestScl/scl:SCL/scl:Private[@type=$compasSclExtensionType]/compas:Labels/compas:Label)
- for $label in $labels
- return ' '
- };
- """;
-
- private final BaseXClientFactory baseXClientFactory;
- private final SclDataModelMarshaller sclDataMarshaller;
-
- @Inject
- public CompasSclDataBaseXRepository(BaseXClientFactory baseXClientFactory,
- SclDataModelMarshaller sclDataMarshaller) {
- this.baseXClientFactory = baseXClientFactory;
- this.sclDataMarshaller = sclDataMarshaller;
-
- var command = """
- declare variable $db := '%s';
- if (not(db:exists($db)))
- then
- db:create($db)
- """;
- // At startup create all needed databases.
- Arrays.stream(SclFileType.values()).forEach(type ->
- executeCommand(client -> {
- client.executeXQuery(command.formatted(type));
- return true;
- }));
- }
-
- @Override
- @Transactional(SUPPORTS)
- public List- list(SclFileType type) {
- return executeQuery(type, """
- %s
- %s
- %s
- declare variable $db := '%s';
- for $resource in db:open($db)
- let $id := $resource/scl:SCL/scl:Header/@id
- group by $id
- let $latestScl := local:latest-version($db, $id)
- let $version := $latestScl/scl:SCL/scl:Header/@version
- let $name := ($latestScl/scl:SCL/scl:Private[@type=$compasSclExtensionType]/compas:SclName)[1]
- let $labels := fn:string-join(local:createLabelsResponse($latestScl))
- order by fn:lower-case($name)
- return '
- '
- || ' ' || $id || ''
- || ' ' || $name || ''
- || ' ' || $version || ''
- || $labels
- || '
'
- """.formatted(DECLARE_NS_AND_VARS, DECLARE_LATEST_VERSION_FUNC, DECLARE_LABELS_FUNC, type)
- ,
- sclDataMarshaller::unmarshalItem);
- }
-
- @Override
- @Transactional(SUPPORTS)
- public List listVersionsByUUID(SclFileType type, UUID id) {
- return executeQuery(type, """
- %s
- declare variable $db := '%s';
- declare variable $id := '%s';
- for $resource in db:open($db, $id)
- let $version := $resource/scl:SCL/scl:Header/@version
- let $name := $resource/scl:SCL/scl:Private[@type=$compasSclExtensionType]/compas:SclName
- let $header := ($resource/scl:SCL/scl:Header/scl:History/scl:Hitem[(not(@revision) or @revision="") and @version=$version])[1]
- let $parts := tokenize($version, '\\.')
- let $majorVersion := xs:int($parts[1])
- let $minorVersion := xs:int($parts[2])
- let $patchVersion := xs:int($parts[3])
- order by $majorVersion, $minorVersion, $patchVersion
- return ''
- || ' ' || $id || ''
- || ' ' || $name || ''
- || ' ' || $version || ''
- || ' ' || $header/@who || ''
- || ' ' || $header/@when || ''
- || ' ' || $header/@what || ''
- || ''
- """.formatted(DECLARE_NS_AND_VARS, type, id),
- sclDataMarshaller::unmarshalHistoryItem);
- }
-
- @Override
- @Transactional(SUPPORTS)
- public String findByUUID(SclFileType type, UUID id) {
- // This find method always searches for the latest version and returns this.
- var result = executeQuery(type, """
- %s
- %s
- declare variable $db := '%s';
- declare variable $id := '%s';
- local:latest-version($db, $id)
- """.formatted(DECLARE_NS_AND_VARS, DECLARE_LATEST_VERSION_FUNC, type, id)
- );
-
- if (result.isEmpty()) {
- var message = String.format("No record found for type '%s' with ID '%s'", type, id);
- throw new CompasNoDataFoundException(message);
- }
- return result.get(0);
- }
-
- @Override
- @Transactional(SUPPORTS)
- public String findByUUID(SclFileType type, UUID id, Version version) {
- // This find method searches for a specific version.
- var result = executeQuery(type, """
- declare variable $db := '%s';
- declare variable $path := '%s';
- db:open($db, $path)
- """.formatted(type, createDocumentPath(id, version))
- );
-
- if (result.isEmpty()) {
- var message = String.format("No record found for type '%s' with ID '%s' and version '%s'", type, id, version);
- throw new CompasNoDataFoundException(message);
- }
- return result.get(0);
- }
-
- @Override
- @Transactional(SUPPORTS)
- public boolean hasDuplicateSclName(SclFileType type, String name) {
- return false;
- }
-
- @Override
- @Transactional(SUPPORTS)
- public SclMetaInfo findMetaInfoByUUID(SclFileType type, UUID id) {
- // This find method always searches for the latest version.
- // Extracts the needed information from the document and returns this.
- var metaInfo = executeQuery(type, """
- %s
- %s
- declare variable $db := '%s';
- declare variable $id := '%s';
- let $resource := local:latest-version($db, $id)
- return if ($resource)
- then (
- let $version := $resource/scl:SCL/scl:Header/@version
- let $name := $resource/scl:SCL/scl:Private[@type=$compasSclExtensionType]/compas:SclName
- return ''
- || ' ' || $id || ''
- || ' ' || $name || ''
- || ' ' || $version || ''
- || ''
- )
- """.formatted(DECLARE_NS_AND_VARS, DECLARE_LATEST_VERSION_FUNC, type, id),
- sclDataMarshaller::unmarshalSclMetaInfo);
-
- if (metaInfo.isEmpty()) {
- var message = String.format("No meta info found for type '%s' with ID '%s'", type, id);
- throw new CompasNoDataFoundException(message);
- }
- return metaInfo.get(0);
- }
-
- @Override
- @Transactional(REQUIRED)
- public void create(SclFileType type, UUID id, String name, String scl, Version version, String who, List labels) {
- // Who is ignored in the BaseX implementation.
- var inputStream = new ReaderInputStream(new StringReader(scl), StandardCharsets.UTF_8);
- executeCommand(client -> {
- openDatabase(client, type);
- client.add(createDocumentPath(id, version) + "/scl.xml", inputStream);
- closeDatabase(client);
- return true;
- });
- }
-
- @Override
- @Transactional(REQUIRED)
- public void delete(SclFileType type, UUID id) {
- executeCommand(client -> {
- client.executeXQuery("db:delete('%s', '%s')".formatted(type, id));
- return true;
- });
- }
-
- @Override
- @Transactional(REQUIRED)
- public void delete(SclFileType type, UUID id, Version version) {
- executeCommand(client -> {
- client.executeXQuery("db:delete('%s', '%s')".formatted(type, createDocumentPath(id, version)));
- return true;
- });
- }
-
- private String createDocumentPath(UUID uuid, Version version) {
- return uuid
- + "/" + version.getMajorVersion()
- + "/" + version.getMinorVersion()
- + "/" + version.getPatchVersion();
- }
-
- private List executeQuery(SclFileType type, String query) {
- // When the Document (as String) is just returned without mapping.
- return executeQuery(type, query, xmlString -> xmlString);
- }
-
- private List executeQuery(SclFileType type, String query, ResultRowMapper mapper) {
- return executeCommand(client -> {
- try {
- var response = new ArrayList();
- openDatabase(client, type);
- LOGGER.debug("Executing Query:\n{}", query);
- try (var queryToRun = client.query(query)) {
- while (queryToRun.more()) {
- response.add(mapper.map(queryToRun.next()));
- }
- }
- closeDatabase(client);
- return response;
- } catch (IOException exception) {
- final var exceptionMessage = exception.getLocalizedMessage();
- LOGGER.error("executeQuery: {}", exceptionMessage, exception);
- throw new CompasSclDataServiceException(BASEX_QUERY_ERROR_CODE, "Error executing query!");
- }
- });
- }
-
- private void openDatabase(BaseXClient client, SclFileType type) throws IOException {
- client.execute("OPEN %s".formatted(type));
- }
-
- private void closeDatabase(BaseXClient client) throws IOException {
- client.execute("CLOSE");
- }
-
- private R executeCommand(ClientExecutor command) {
- try (var client = baseXClientFactory.createClient()) {
- return command.execute(client);
- } catch (IOException exception) {
- final var exceptionMessage = exception.getLocalizedMessage();
- LOGGER.error("executeCommand: {}", exceptionMessage, exception);
- throw new CompasSclDataServiceException(BASEX_COMMAND_ERROR_CODE, "Error executing command!");
- }
- }
-
- private interface ClientExecutor {
- R execute(BaseXClient client) throws IOException;
- }
-
- private interface ResultRowMapper {
- R map(String row);
- }
-}
diff --git a/repository-basex/src/test/java/org/lfenergy/compas/scl/data/basex/client/BaseXClientFactoryTest.java b/repository-basex/src/test/java/org/lfenergy/compas/scl/data/basex/client/BaseXClientFactoryTest.java
deleted file mode 100644
index 143f1cee..00000000
--- a/repository-basex/src/test/java/org/lfenergy/compas/scl/data/basex/client/BaseXClientFactoryTest.java
+++ /dev/null
@@ -1,28 +0,0 @@
-// SPDX-FileCopyrightText: 2021 Alliander N.V.
-//
-// SPDX-License-Identifier: Apache-2.0
-package org.lfenergy.compas.scl.data.basex.client;
-
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-
-import java.io.IOException;
-
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.lfenergy.compas.scl.data.basex.client.BaseXServerUtil.createClientFactory;
-
-@ExtendWith({BaseXServerJUnitExtension.class})
-class BaseXClientFactoryTest {
- private static BaseXClientFactory factory;
-
- @BeforeAll
- static void beforeAll() {
- factory = createClientFactory(BaseXServerJUnitExtension.getPortNumber());
- }
-
- @Test
- void createClient_WhenCalled_ThenReturnClient() throws IOException {
- assertNotNull(factory.createClient());
- }
-}
\ No newline at end of file
diff --git a/repository-basex/src/test/java/org/lfenergy/compas/scl/data/basex/client/BaseXServerJUnitExtension.java b/repository-basex/src/test/java/org/lfenergy/compas/scl/data/basex/client/BaseXServerJUnitExtension.java
deleted file mode 100644
index e4a1e789..00000000
--- a/repository-basex/src/test/java/org/lfenergy/compas/scl/data/basex/client/BaseXServerJUnitExtension.java
+++ /dev/null
@@ -1,51 +0,0 @@
-// SPDX-FileCopyrightText: 2021 Alliander N.V.
-//
-// SPDX-License-Identifier: Apache-2.0
-package org.lfenergy.compas.scl.data.basex.client;
-
-import org.basex.BaseXServer;
-import org.junit.jupiter.api.extension.BeforeAllCallback;
-import org.junit.jupiter.api.extension.ExtensionContext;
-
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
-
-import static org.junit.jupiter.api.extension.ExtensionContext.Namespace.GLOBAL;
-import static org.lfenergy.compas.scl.data.basex.client.BaseXServerUtil.createServer;
-import static org.lfenergy.compas.scl.data.basex.client.BaseXServerUtil.getFreePortNumber;
-
-/**
- * JUnit extension to start a BaseX Server. This server should only be started and stopped once for all
- * JUnit Tests.
- */
-public class BaseXServerJUnitExtension implements BeforeAllCallback, ExtensionContext.Store.CloseableResource {
- private static BaseXServer server;
- private static int portNumber;
-
- // Gate keeper to prevent multiple Threads within the same routine
- private final static Lock lock = new ReentrantLock();
-
- @Override
- public void beforeAll(final ExtensionContext context) throws Exception {
- // lock the access so only one Thread has access to it
- lock.lock();
- if (server == null) {
- portNumber = getFreePortNumber();
- server = createServer(portNumber);
-
- // The following line registers a callback hook when the root test context is shut down
- context.getRoot().getStore(GLOBAL).put("BaseXServerJUnitExtension", this);
- }
- // free the access
- lock.unlock();
- }
-
- @Override
- public void close() {
- server.stop();
- }
-
- public static int getPortNumber() {
- return portNumber;
- }
-}
\ No newline at end of file
diff --git a/repository-basex/src/test/java/org/lfenergy/compas/scl/data/basex/client/BaseXServerUtil.java b/repository-basex/src/test/java/org/lfenergy/compas/scl/data/basex/client/BaseXServerUtil.java
deleted file mode 100644
index 8fd7376d..00000000
--- a/repository-basex/src/test/java/org/lfenergy/compas/scl/data/basex/client/BaseXServerUtil.java
+++ /dev/null
@@ -1,32 +0,0 @@
-// SPDX-FileCopyrightText: 2021 Alliander N.V.
-//
-// SPDX-License-Identifier: Apache-2.0
-package org.lfenergy.compas.scl.data.basex.client;
-
-import org.basex.BaseXServer;
-
-import java.io.IOException;
-import java.net.ServerSocket;
-
-public final class BaseXServerUtil {
- private BaseXServerUtil() {
- }
-
- public static int getFreePortNumber() throws IOException {
- try (ServerSocket serverSocket = new ServerSocket(0)) {
- if (serverSocket.getLocalPort() > 0) {
- return serverSocket.getLocalPort();
- }
- }
- throw new IOException("Port is not available");
- }
-
- public static BaseXServer createServer(int portNumber) throws IOException {
- System.setProperty("org.basex.path", "target/basex");
- return new BaseXServer("-p" + portNumber);
- }
-
- public static BaseXClientFactory createClientFactory(int portNumber) {
- return new BaseXClientFactory("localhost", portNumber, "admin", "admin");
- }
-}
diff --git a/repository-basex/src/test/java/org/lfenergy/compas/scl/data/basex/repository/CompasSclDataBaseXRepositoryTest.java b/repository-basex/src/test/java/org/lfenergy/compas/scl/data/basex/repository/CompasSclDataBaseXRepositoryTest.java
deleted file mode 100644
index 693cc194..00000000
--- a/repository-basex/src/test/java/org/lfenergy/compas/scl/data/basex/repository/CompasSclDataBaseXRepositoryTest.java
+++ /dev/null
@@ -1,67 +0,0 @@
-// SPDX-FileCopyrightText: 2021 Alliander N.V.
-//
-// SPDX-License-Identifier: Apache-2.0
-package org.lfenergy.compas.scl.data.basex.repository;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.lfenergy.compas.scl.data.basex.client.BaseXClientFactory;
-import org.lfenergy.compas.scl.data.basex.client.BaseXServerJUnitExtension;
-import org.lfenergy.compas.scl.data.repository.AbstractCompasSclDataRepositoryTest;
-import org.lfenergy.compas.scl.data.repository.CompasSclDataRepository;
-import org.lfenergy.compas.scl.data.util.SclDataModelMarshaller;
-import org.lfenergy.compas.scl.extensions.model.SclFileType;
-import org.mockito.junit.jupiter.MockitoExtension;
-
-import java.io.IOException;
-import java.util.Arrays;
-
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.lfenergy.compas.scl.data.basex.client.BaseXServerUtil.createClientFactory;
-
-@ExtendWith({MockitoExtension.class, BaseXServerJUnitExtension.class})
-class CompasSclDataBaseXRepositoryTest extends AbstractCompasSclDataRepositoryTest {
- private static final Logger LOGGER = LogManager.getLogger(CompasSclDataBaseXRepositoryTest.class);
-
- private static BaseXClientFactory factory;
- private CompasSclDataBaseXRepository repository;
-
- @Override
- protected CompasSclDataRepository getRepository() {
- return repository;
- }
-
- @BeforeAll
- static void beforeAll() {
- factory = createClientFactory(BaseXServerJUnitExtension.getPortNumber());
-
- // To make it possible to re-run the test over and over (in your IDE),
- // Create all the database, because this will cause to old ones to be removed.
- Arrays.stream(SclFileType.values())
- .forEach(type -> {
- try {
- factory.createClient().executeXQuery("db:create('" + type + "')");
- } catch (IOException exp) {
- LOGGER.warn("Error re-creating database {}", type, exp);
- }
- });
- }
-
- @BeforeEach
- void beforeEach() {
- repository = new CompasSclDataBaseXRepository(factory, new SclDataModelMarshaller());
- }
-
- /*
- * TODO: Method beneath needs to be removed and the one from CompasSclDataPostgreSQLRepositoryTest be used
- * when hasDuplicateSclName has been implemented by CompasSclDataBaseXRepository. */
- @Test
- void hasDuplicateSclName_WhenUsingSclNameThatHasBeenUsedYet_ThenDuplicateIsFound() {
- // Will always return false for now, because there is no correct implementation for BaseX
- assertFalse(getRepository().hasDuplicateSclName(TYPE, NAME_1));
- }
-}
diff --git a/repository-basex/src/test/resources/log4j2.xml b/repository-basex/src/test/resources/log4j2.xml
deleted file mode 100644
index 3b41fa7f..00000000
--- a/repository-basex/src/test/resources/log4j2.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/repository-postgresql/pom.xml b/repository-postgresql/pom.xml
index f531369f..47b0a2cf 100644
--- a/repository-postgresql/pom.xml
+++ b/repository-postgresql/pom.xml
@@ -60,7 +60,7 @@ SPDX-License-Identifier: Apache-2.0
com.opentable.components
otj-pg-embedded
- 1.0.1
+ 1.0.2
test
diff --git a/repository-postgresql/src/main/java/org/lfenergy/compas/scl/data/repository/postgresql/CompasSclDataPostgreSQLRepository.java b/repository-postgresql/src/main/java/org/lfenergy/compas/scl/data/repository/postgresql/CompasSclDataPostgreSQLRepository.java
index bf1a937f..c127de02 100644
--- a/repository-postgresql/src/main/java/org/lfenergy/compas/scl/data/repository/postgresql/CompasSclDataPostgreSQLRepository.java
+++ b/repository-postgresql/src/main/java/org/lfenergy/compas/scl/data/repository/postgresql/CompasSclDataPostgreSQLRepository.java
@@ -13,10 +13,10 @@
import org.lfenergy.compas.scl.data.repository.CompasSclDataRepository;
import org.lfenergy.compas.scl.extensions.model.SclFileType;
-import javax.enterprise.context.ApplicationScoped;
-import javax.inject.Inject;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
import javax.sql.DataSource;
-import javax.transaction.Transactional;
+import jakarta.transaction.Transactional;
import java.sql.Array;
import java.sql.Connection;
import java.sql.ResultSet;
@@ -26,8 +26,8 @@
import java.util.List;
import java.util.UUID;
-import static javax.transaction.Transactional.TxType.REQUIRED;
-import static javax.transaction.Transactional.TxType.SUPPORTS;
+import static jakarta.transaction.Transactional.TxType.REQUIRED;
+import static jakarta.transaction.Transactional.TxType.SUPPORTS;
import static org.lfenergy.compas.scl.data.exception.CompasSclDataServiceErrorCode.*;
@ApplicationScoped
diff --git a/repository-postgresql/src/test/java/org/lfenergy/compas/scl/data/repository/postgresql/PostgreSQLServerJUnitExtension.java b/repository-postgresql/src/test/java/org/lfenergy/compas/scl/data/repository/postgresql/PostgreSQLServerJUnitExtension.java
index be51c4a1..a773e10d 100644
--- a/repository-postgresql/src/test/java/org/lfenergy/compas/scl/data/repository/postgresql/PostgreSQLServerJUnitExtension.java
+++ b/repository-postgresql/src/test/java/org/lfenergy/compas/scl/data/repository/postgresql/PostgreSQLServerJUnitExtension.java
@@ -18,7 +18,7 @@
import static org.junit.jupiter.api.extension.ExtensionContext.Namespace.GLOBAL;
/**
- * JUnit extension to start a BaseX Server. This server should only be started and stopped once for all
+ * JUnit extension to start a Postgresql Server. This server should only be started and stopped once for all
* JUnit Tests.
*/
public class PostgreSQLServerJUnitExtension implements BeforeAllCallback, ExtensionContext.Store.CloseableResource {
diff --git a/repository/pom.xml b/repository/pom.xml
index 7919d8df..382a9886 100644
--- a/repository/pom.xml
+++ b/repository/pom.xml
@@ -32,9 +32,10 @@ SPDX-License-Identifier: Apache-2.0
jakarta.xml.bind-api