diff --git a/software/core/oqm-core-api/build.gradle b/software/core/oqm-core-api/build.gradle index a612ec46f0..923379114d 100644 --- a/software/core/oqm-core-api/build.gradle +++ b/software/core/oqm-core-api/build.gradle @@ -8,7 +8,7 @@ plugins { } group 'com.ebp.openQuarterMaster' -version '4.4.4' +version '4.4.5-SNAPSHOT' repositories { mavenCentral() diff --git a/software/core/oqm-core-api/docs/DataModel.md b/software/core/oqm-core-api/docs/DataModel.md index 3ddc50b673..c3039f36eb 100644 --- a/software/core/oqm-core-api/docs/DataModel.md +++ b/software/core/oqm-core-api/docs/DataModel.md @@ -1,4 +1,4 @@ -# Open QuarterMaster Base Station Data Models +# Open QuarterMaster Core API Data Models [Back](README.md) diff --git a/software/core/oqm-core-api/docs/Features.adoc b/software/core/oqm-core-api/docs/Features.adoc index da68c82ac6..a05290a9dd 100644 --- a/software/core/oqm-core-api/docs/Features.adoc +++ b/software/core/oqm-core-api/docs/Features.adoc @@ -1,4 +1,4 @@ -= OQM Base Station Features += OQM Core API Features :toc: :toclevels: 5 :sectnumlevels:5 diff --git a/software/core/oqm-core-api/docs/README.md b/software/core/oqm-core-api/docs/README.md index 211539e93f..aca20abb6a 100644 --- a/software/core/oqm-core-api/docs/README.md +++ b/software/core/oqm-core-api/docs/README.md @@ -1,4 +1,4 @@ -# Open QuarterMaster Base Station Documentation +# Open QuarterMaster Core API Documentation [Back](../README.md) diff --git a/software/core/oqm-core-api/docs/development/BuildingAndDeployment.adoc b/software/core/oqm-core-api/docs/development/BuildingAndDeployment.adoc index bd0035fec8..70414ef6b3 100644 --- a/software/core/oqm-core-api/docs/development/BuildingAndDeployment.adoc +++ b/software/core/oqm-core-api/docs/development/BuildingAndDeployment.adoc @@ -13,11 +13,11 @@ link:README.md[Back] === Configuration -This is a list of relevant config values for configuring a running instance of Open QuarterMaster Base Station. These variables can be passed via environment variables. +This is a list of relevant config values for configuring a running instance of Open QuarterMaster Core API. These variables can be passed via environment variables. For more information: https://quarkus.io/guides/config-reference -When deployed using link:../../Station-Captain[Station Captain], Base Station's config file is: `/etc/oqm/serviceConfig/core-base+station/config.list` +When deployed using link:../../Station-Captain[Station Captain], the Core API's config file is: `/etc/oqm/serviceConfig/core-api/config.list` ==== Service Info diff --git a/software/core/oqm-core-api/installerSrc/core-api-config.list b/software/core/oqm-core-api/installerSrc/core-api-config.list index dca651d2ef..85f51f0a8d 100644 --- a/software/core/oqm-core-api/installerSrc/core-api-config.list +++ b/software/core/oqm-core-api/installerSrc/core-api-config.list @@ -1,6 +1,6 @@ # -# The Main config for Base Station. Do not edit. To adjust configuration, edit: -# /etc/oqm/serviceConfig/core/base+station/user-config.list +# The Main config for the OQM Core API. Do not edit. To adjust configuration, edit: +# /etc/oqm/serviceConfig/core/api/user-config.list # # Basic configs diff --git a/software/core/oqm-core-api/installerSrc/oqm-core-api.service b/software/core/oqm-core-api/installerSrc/oqm-core-api.service index 7a2c07da2a..de2b404d68 100644 --- a/software/core/oqm-core-api/installerSrc/oqm-core-api.service +++ b/software/core/oqm-core-api/installerSrc/oqm-core-api.service @@ -48,7 +48,7 @@ ExecStartPre=/bin/bash -c "chmod 600 $USER_CONFIG_FILE" # Pull image as separate task ExecStartPre=/bin/bash -c "/usr/bin/docker pull $IMAGE_NAME:$IMAGE_VERSION || echo 'Could not pull image.'" -# Run Base Station +# Run Core API ExecStart=/bin/bash -c "/usr/bin/docker run --rm --name $CONTAINER_NAME \ --network=oqm-internal \ -v /etc/oqm/certs/trustStores:/etc/oqm/certs/trustStores:ro \ diff --git a/software/core/oqm-core-api/makeInstallers.sh b/software/core/oqm-core-api/makeInstallers.sh index 8d1a046a11..a4196d50af 100755 --- a/software/core/oqm-core-api/makeInstallers.sh +++ b/software/core/oqm-core-api/makeInstallers.sh @@ -1,6 +1,6 @@ #!/bin/bash # -# Script to make installers for OQM- Base Station. +# Script to make installers for OQM- Core API. # # Intended to be run from the dir this resides # diff --git a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/config/CoreApiInteractingEntity.java b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/config/CoreApiInteractingEntity.java index 3171d9590f..a661d0f1bd 100644 --- a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/config/CoreApiInteractingEntity.java +++ b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/config/CoreApiInteractingEntity.java @@ -23,7 +23,7 @@ public class CoreApiInteractingEntity extends InteractingEntity { /** - * Don't change this. We use this very specific ObjectId to identify the Base Station's specific entry in the db. + * Don't change this. We use this very specific ObjectId to identify the Core API's specific entry in the db. */ public static final ObjectId BS_ID = new ObjectId("00000000AAAAAAAAAAFFFFFF"); diff --git a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/config/ReflectionConfiguration.java b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/config/ReflectionConfiguration.java deleted file mode 100644 index 0dcf8acee8..0000000000 --- a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/config/ReflectionConfiguration.java +++ /dev/null @@ -1,37 +0,0 @@ -//package tech.ebp.oqm.core.api.data; -// -//import io.quarkus.runtime.annotations.RegisterForReflection; -//import lombok.AccessLevel; -//import lombok.NoArgsConstructor; -//import tech.ebp.oqm.core.api.model.object.interactingEntity.user.User; -//import tech.ebp.oqm.core.api.model.object.storage.storageBlock.StorageBlock; -//import tech.ebp.oqm.core.api.model.rest.ErrorMessage; -//import tech.ebp.oqm.core.api.service.mongo.search.SearchResult; -// -//import java.time.ZonedDateTime; -// -///** -// * Required to tell GraalVm to keep classes around. -// *

-// * If running in native mode and get errors about classes, reflection, etc, add the erring class here -// *

-// * https://quarkus.io/guides/writing-native-applications-tips#including-resources -// *

-// * TODO:: test in native mode and go through to include all needed classes -// */ -//@RegisterForReflection( -// targets = { // Classes we know about go here -// ErrorMessage.class, -// ZonedDateTime.class, -// User.class, -// StorageBlock.class, -// SearchResult.class, -// }, -// classNames = { //proxy classes go here -// "com.ebp.openQuarterMaster.baseStation.service.mongo.StorageBlockService_ClientProxy" -// } -//) -//@NoArgsConstructor(access = AccessLevel.PRIVATE)//prevent instantiation -//public final class MyReflectionConfiguration { -// -//} diff --git a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/filters/InheritenceOpenapiFilter.java b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/filters/InheritenceOpenapiFilter.java deleted file mode 100644 index c2a172a1ff..0000000000 --- a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/filters/InheritenceOpenapiFilter.java +++ /dev/null @@ -1,10 +0,0 @@ -package tech.ebp.oqm.core.api.filters; - -import org.eclipse.microprofile.openapi.OASFilter; - -//TODO:: figure this out to try to add polymorphic classes to docs: https://quarkus.io/guides/openapi-swaggerui#enhancing-the-openapi-schema-with-filters -//@OpenApiFilter(OpenApiFilter.RunStage.BUILD) -//@OpenApiFilter -//public class InheritenceOpenapiFilter implements OASFilter { -// -//} diff --git a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/interfaces/endpoints/info/Test.java b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/interfaces/endpoints/info/Test.java index bc78b806a2..52b0b82b4b 100644 --- a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/interfaces/endpoints/info/Test.java +++ b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/interfaces/endpoints/info/Test.java @@ -27,7 +27,7 @@ public class Test extends EndpointProvider { @GET @Path("illegalArgException") @Operation( - summary = "The currency the base station is set to operate with." + summary = "The currency the core api is set to operate with." ) @APIResponse( responseCode = "200", @@ -42,7 +42,7 @@ public Response illegalArgException() { @GET @Path("illegalStateException") @Operation( - summary = "The currency the base station is set to operate with." + summary = "The currency the core api is set to operate with." ) @APIResponse( responseCode = "200", @@ -64,7 +64,7 @@ public static class TestClass { @POST @Path("validationException") @Operation( - summary = "The currency the base station is set to operate with." + summary = "The currency the core api is set to operate with." ) @APIResponse( responseCode = "200", diff --git a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/interfaces/ui/IndexUi.java b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/interfaces/ui/IndexUi.java index 5dd08f85e4..f725542358 100644 --- a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/interfaces/ui/IndexUi.java +++ b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/interfaces/ui/IndexUi.java @@ -18,6 +18,9 @@ import java.text.MessageFormat; import java.util.Optional; +/** + * A Simple splash page to show, and direct to swagger. + */ @SuppressWarnings("LombokGetterMayBeUsed") @Blocking @Slf4j diff --git a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/model/jackson/ColorModule.java b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/model/jackson/ColorModule.java index 323e557d79..e4890fc28a 100644 --- a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/model/jackson/ColorModule.java +++ b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/model/jackson/ColorModule.java @@ -11,10 +11,19 @@ import java.io.IOException; /** - * Jackson module to handle the Mongodb ObjectId in a reasonable manner (as its hex string) + * Jackson module for serializing and deserializing {@link Color} objects. + *

+ * Colors are serialized as hex strings (e.g., "#FF5733") and deserialized from + * that same hex string format */ public class ColorModule extends TestableModule { + /** + * Converts a Color to its hex string representation. + * + * @param c the color to convert + * @return hex string in format "#RRGGBB" + */ public static String toHexString(Color c){ int R = c.getRed(); int G = c.getGreen(); @@ -23,6 +32,14 @@ public static String toHexString(Color c){ String rgb = String.format("#%02X%02X%02X", R, G, B); return rgb; } + + /** + * Parses a hex string or color name into a Color object. + * + * @param c the string to parse (hex or color name) + * @return the Color object + * @throws NumberFormatException if the string is not a valid color format + */ public static Color toColor(String c){ return Color.decode(c); } @@ -35,6 +52,9 @@ public ColorModule() { ); } + /** + * Serializer that writes Color as hex string. + */ public static class ColorSerializer extends JsonSerializer { @Override public void serialize(Color c, JsonGenerator gen, SerializerProvider serializers) throws IOException { @@ -42,6 +62,9 @@ public void serialize(Color c, JsonGenerator gen, SerializerProvider serializers } } + /** + * Deserializer that parses hex strings or color names into Color objects. + */ public static class ColorDeserializer extends JsonDeserializer { @Override public Color deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { @@ -49,5 +72,4 @@ public Color deserialize(JsonParser p, DeserializationContext ctxt) throws IOExc } } - } diff --git a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/model/jackson/MongoObjectIdModule.java b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/model/jackson/MongoObjectIdModule.java index 914826fc79..5699cd2f55 100644 --- a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/model/jackson/MongoObjectIdModule.java +++ b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/model/jackson/MongoObjectIdModule.java @@ -34,7 +34,6 @@ public static class ObjectIdDeserializer extends JsonDeserializer { @Override public ObjectId deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { - return new ObjectId(p.getValueAsString()); } } diff --git a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/notification/EventNotificationWrapper.java b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/model/messaging/EventNotificationWrapper.java similarity index 86% rename from software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/notification/EventNotificationWrapper.java rename to software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/model/messaging/EventNotificationWrapper.java index 4f32499424..f68bda7b1f 100644 --- a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/notification/EventNotificationWrapper.java +++ b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/model/messaging/EventNotificationWrapper.java @@ -1,4 +1,4 @@ -package tech.ebp.oqm.core.api.service.notification; +package tech.ebp.oqm.core.api.model.messaging; import lombok.*; import org.bson.types.ObjectId; diff --git a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/model/object/ObjectUtils.java b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/model/object/ObjectUtils.java index e6bee07981..591d57f878 100644 --- a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/model/object/ObjectUtils.java +++ b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/model/object/ObjectUtils.java @@ -64,25 +64,4 @@ public static void setupObjectMapper(ObjectMapper mapper) { //set the timezone to this server's. mapper.setTimeZone(TimeZone.getDefault()); } - - public static List fieldListFromJson(ObjectNode updateJson) { - List output = new ArrayList<>(); - - for (Iterator> it = updateJson.fields(); it.hasNext(); ) { - Map.Entry cur = it.next(); - String curKey = cur.getKey(); - - if (cur.getValue().isObject()) { - List curSubs = fieldListFromJson((ObjectNode) cur.getValue()); - - for (String curSubKey : curSubs) { - output.add(curKey + "." + curSubKey); - } - } else { - output.add(curKey); - } - } - - return output; - } } diff --git a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/model/quantities/QuantitiesUtils.java b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/model/quantities/QuantitiesUtils.java deleted file mode 100644 index fb8b20fe7d..0000000000 --- a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/model/quantities/QuantitiesUtils.java +++ /dev/null @@ -1,21 +0,0 @@ -package tech.ebp.oqm.core.api.model.quantities; - -import javax.measure.Quantity; - -public final class QuantitiesUtils { - - @SuppressWarnings("rawtypes") - public static boolean isLowStock(Quantity total, Quantity threshold) { - if (threshold == null || total == null) { - return false; - } - - if (!total.getUnit().equals(threshold.getUnit())) { - threshold = threshold.to(total.getUnit()); - } - - return total.getValue().doubleValue() < threshold.getValue().doubleValue(); - } - - -} diff --git a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/model/rest/media/ImageCreateRequest.java b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/model/rest/media/ImageCreateRequest.java index 0e3aeabae9..862f2f2543 100644 --- a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/model/rest/media/ImageCreateRequest.java +++ b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/model/rest/media/ImageCreateRequest.java @@ -15,7 +15,7 @@ import java.util.Map; /** - * Request to create an image in the Base Station service. + * Request to create an image in the Core API service. */ @Data @NoArgsConstructor diff --git a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/model/rest/storage/IMAGED_OBJ_TYPE_NAME.java b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/model/rest/storage/IMAGED_OBJ_TYPE_NAME.java index d5b5d417ff..708fe23eca 100644 --- a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/model/rest/storage/IMAGED_OBJ_TYPE_NAME.java +++ b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/model/rest/storage/IMAGED_OBJ_TYPE_NAME.java @@ -1,7 +1,7 @@ package tech.ebp.oqm.core.api.model.rest.storage; /** - * Used to specify which type of imaged object to get in the base station server. + * Used to specify which type of imaged object to get in the Core API server. */ public enum IMAGED_OBJ_TYPE_NAME { storageBlock, diff --git a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/scheduled/ExpiryProcessor.java b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/scheduled/ExpiryProcessor.java index 53a718688c..8b7420ff06 100644 --- a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/scheduled/ExpiryProcessor.java +++ b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/scheduled/ExpiryProcessor.java @@ -8,6 +8,18 @@ import tech.ebp.oqm.core.api.service.serviceState.db.DbCacheEntry; import tech.ebp.oqm.core.api.service.serviceState.db.OqmDatabaseService; +/** + * Scheduled processor for handling item expiry events. + *

+ * Runs periodically to scan all databases for items that have expired or are approaching + * their expiry dates. For each database, it triggers expiry/warning event processing + * via {@link ItemStatsService#scanForExpired(String)}. + *

+ *

+ * Configuration: The execution schedule is controlled by the {@code service.item.expiryCheck.cron} + * property. Concurrent executions are skipped if one is already running. + *

+ */ @Slf4j @ApplicationScoped public class ExpiryProcessor { @@ -19,6 +31,13 @@ public class ExpiryProcessor { @Inject ItemStatsService itemStatsService; + /** + * Main scheduled task that processes expiry events for all databases. + *

+ * Iterates through all registered databases and calls the item stats service + * to scan for expired items and generate appropriate events. + *

+ */ @Scheduled( identity = "searchAndProcessExpiredItems", cron = "{service.item.expiryCheck.cron}", diff --git a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/scheduled/LifecycleBean.java b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/scheduled/LifecycleBean.java index 5b74f5ba42..0511a5121c 100644 --- a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/scheduled/LifecycleBean.java +++ b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/scheduled/LifecycleBean.java @@ -141,7 +141,6 @@ void onStart( //ensures we can write to temp dir this.tempFileService.getTempDir("test", "dir"); // Upgrade the db schema - //TODO:: mutex lock on this, wait until done upgrading //TODO:: create flag service to check if things initted right. Setup filter to check this flag to reject requests until setup done. Optional schemaUpgradeResult = this.objectSchemaUpgradeService.updateSchema(); if(schemaUpgradeResult.isEmpty()){ diff --git a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/TempFileService.java b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/TempFileService.java index dae015fccd..9a171e57aa 100644 --- a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/TempFileService.java +++ b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/TempFileService.java @@ -17,6 +17,25 @@ import java.util.Random; import java.util.stream.Collectors; +/** + * Service for managing temporary files and directories. + *

+ * Creates unique temporary files and directories with timestamp-based naming to prevent conflicts. + * Files are automatically scheduled for deletion on JVM exit via {@link File#deleteOnExit()}. + * Supports optional subdirectory organization via the {@code tempFolder} parameter. + *

+ *

+ * Main usages: + *

+ *

+ *

+ * Configuration: The base temporary directory is configured via the {@code service.tempDir} property. + *

+ */ @Slf4j @ApplicationScoped public class TempFileService { @@ -26,6 +45,14 @@ public class TempFileService { private static final DateTimeFormatter FILENAME_TIMESTAMP_FORMAT = DateTimeFormatter.ofPattern("MM-dd-yyyy_kk-mm"); private static final Random RANDOM = new SecureRandom(); + /** + * Validates that a directory exists, is actually a directory, and is writable. + * Creates the directory if it doesn't exist. + * + * @param dir the path to validate + * @throws InvalidConfigException if the directory doesn't exist and cannot be created, + * is not a directory, or is not writable + */ public static void checkDir(Path dir){ if (!Files.exists(dir)) { try{ @@ -72,6 +99,14 @@ private Path getDir(String tempFolder){ return directory; } + /** + * Gets a temporary file with the specified filename in the given folder. + * The file is scheduled for deletion on JVM exit. + * + * @param filename the filename to use + * @param tempFolder optional subdirectory within the temp directory (can be null/empty) + * @return a File object pointing to the temp file + */ public File getTempFile(String filename, String tempFolder){ Path directory = this.getDir(tempFolder); @@ -84,6 +119,17 @@ public File getTempFile(String filename, String tempFolder){ } + /** + * Gets a uniquely named temporary file with the given prefix and extension. + * The filename format is: {@code prefix_MM-dd-yyyy_kk-mm_rrr.extension} + * where rrr is a random 3-digit number. + * The file is scheduled for deletion on JVM exit. + * + * @param prefix the filename prefix + * @param extension the file extension (without dot) + * @param tempFolder optional subdirectory within the temp directory (can be null/empty) + * @return a File object pointing to the temp file + */ public File getTempFile(String prefix, String extension, String tempFolder) { return this.getTempFile( String.format( @@ -98,6 +144,16 @@ public File getTempFile(String prefix, String extension, String tempFolder) { } + /** + * Creates a uniquely named temporary directory with the given prefix. + * The directory name format is: {@code prefix_MM-dd-yyyy_kk-mm_rrr} + * where rrr is a random 3-digit number. + * The directory is scheduled for deletion on JVM exit. + * + * @param prefix the directory name prefix + * @param tempFolder optional subdirectory within the temp directory (can be null/empty) + * @return a File object pointing to the temp directory + */ public File getTempDir(String prefix, String tempFolder) { Path directory = this.getDir(tempFolder); diff --git a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/identifiers/IdentifierBarcodeService.java b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/identifiers/IdentifierBarcodeService.java index 55ba26e088..b0dcfc3f13 100644 --- a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/identifiers/IdentifierBarcodeService.java +++ b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/identifiers/IdentifierBarcodeService.java @@ -30,10 +30,16 @@ import java.io.IOException; /** - * Service to generate barcode images. - * - * TODO:: move to own service? - * TODO:: add better labels to images https://github.com/jfree/jfreesvg + * Service for generating barcode images as SVG data. + *

+ * Supports multiple barcode formats including UPC-A, UPC-E, EAN-8, EAN-13, ISBN-10, + * ISBN-13, GTIN-14, and generic codes. Barcodes are rendered as SVG strings suitable + * for embedding in HTML or saving as image files. + *

+ *

+ * Each barcode can include an optional label for human-readable identification. + * When no custom label is provided, the identifier type name is used automatically. + *

*/ @Slf4j @ApplicationScoped @@ -67,6 +73,17 @@ private static String toImageData(Symbol code){ return os.toString(); } + /** + * Renders a barcode symbol to SVG format with optional label. + *

+ * If a label is provided, it is added below the barcode with appropriate + * formatting including underline styling. + *

+ * + * @param code the barcode symbol to render + * @param label optional label text to display below the barcode + * @return SVG string representation of the barcode + */ public static String processBarcodeData(Symbol code, String label){ String output = toImageData(code); @@ -144,6 +161,14 @@ public static String processBarcodeData(Symbol code, String label){ return output; } + /** + * Generates a barcode SVG for the specified identifier type and data. + * + * @param type the barcode type/format to generate + * @param data the identifier data to encode + * @param label optional label text to display below the barcode + * @return SVG string representation of the barcode + */ public String getBarcodeData(IdentifierType type, String data, String label){ String dataIn = data; int hQuietZone = 10; @@ -226,6 +251,13 @@ public String getBarcodeData(IdentifierType type, String data, String label){ ); } + /** + * Generates a barcode SVG for the given identifier object. + * Uses the identifier's type, value, and label properties. + * + * @param identifier the identifier to generate a barcode for + * @return SVG string representation of the barcode + */ public String getBarcodeData(Identifier identifier){ return this.getBarcodeData(identifier.getType(), identifier.getValue(), identifier.getLabel()); } diff --git a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/identifiers/IdentifierUtils.java b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/identifiers/IdentifierUtils.java index 86c9e037d8..27e94e197e 100644 --- a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/identifiers/IdentifierUtils.java +++ b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/identifiers/IdentifierUtils.java @@ -16,13 +16,28 @@ import tech.ebp.oqm.core.api.service.identifiers.upc.ISBNCodeUtilities; import tech.ebp.oqm.core.api.service.identifiers.upc.UpcCodeUtilities; - /** - * - * https://www.computalabel.com/m/UPCexamplesM.htm + * Utility class for working with product and item identifiers. + *

+ * Provides methods for detecting identifier types, validating codes, and creating + * identifier objects from raw code strings. Supports standard identifier formats + * including UPC-A, UPC-E, EAN-8, EAN-13, ISBN-10, ISBN-13, GTIN-14, and generic identifiers. + *

*/ public class IdentifierUtils { + /** + * Determines the type of identifier from the given code and returns the appropriate + * Identifier implementation. + *

+ * Checks the code against all supported identifier formats in order: UPC-A, UPC-E, + * ISBN-13, ISBN-10, EAN-13, EAN-8, GTIN-14, and finally GenericIdentifier. + *

+ * + * @param code the identifier code string + * @return the appropriate Identifier subtype + * @throws IllegalArgumentException if the code doesn't match any supported identifier format + */ public static Identifier determineGeneralIdType(String code) { if(UpcCodeUtilities.isValidUPCACode(code)){ return UPC_A.builder().value(code).build(); @@ -52,6 +67,14 @@ public static Identifier determineGeneralIdType(String code) { throw new IllegalArgumentException("Code given does not fit into any category of id."); } + /** + * Validates that the given code is valid for the specified identifier type. + * + * @param type the identifier type to validate against + * @param code the code string to validate + * @return true if the code is valid for the given type, false otherwise + * @throws IllegalArgumentException if the identifier type is unknown + */ public static boolean isValidCode(IdentifierType type, String code) { switch (type){ case UPC_A -> { @@ -82,6 +105,15 @@ public static boolean isValidCode(IdentifierType type, String code) { throw new IllegalArgumentException("Unknown id type: " + type); } + /** + * Creates an Identifier object of the specified type from the given code string. + * Validates the code before creating the identifier and throws an exception if invalid. + * + * @param type the identifier type to create + * @param code the code string to use + * @return the created Identifier object + * @throws IllegalArgumentException if the identifier type is unknown or the code is invalid + */ public static Identifier objFromParts(IdentifierType type, String code) { switch (type){ case UPC_A -> { @@ -136,6 +168,12 @@ public static Identifier objFromParts(IdentifierType type, String code) { throw new IllegalArgumentException("Unknown id type: " + type); } + /** + * Validates that a generic identifier is not blank. + * + * @param id the identifier to validate + * @return true if the identifier is not blank, false otherwise + */ public static boolean isValidGenericId(@NonNull String id) { return !id.isBlank(); } diff --git a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/importExport/exporting/DatabaseExportService.java b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/importExport/exporting/DatabaseExportService.java index de886cf8f4..50f0daf304 100644 --- a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/importExport/exporting/DatabaseExportService.java +++ b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/importExport/exporting/DatabaseExportService.java @@ -56,7 +56,7 @@ public class DatabaseExportService { public static final String OQM_EXPORT_PREFIX = "oqm_export"; public static final String OQM_EXPORT_FILE_EXT = ".oqmdb"; public static final String TEMP_FOLDER = "export"; - public static final String GZIP_COMMENT = "Created by Open QuarterMaster Base Station. Full data export, intended to be re-imported by the Base Station software."; + public static final String GZIP_COMMENT = "Created by Open QuarterMaster Core API. Full data export, intended to be re-imported by the Core API software."; public static final int GZIP_COMPRESSION_LEVEL = Deflater.BEST_COMPRESSION; private static final DateFormat fileRevisionTimestampFormat = new SimpleDateFormat("MM-dd-yyyy_hh-mm-ss-SSS"); diff --git a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/mongo/InteractingEntityService.java b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/mongo/InteractingEntityService.java index 2180ad61a9..b340d0305d 100644 --- a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/mongo/InteractingEntityService.java +++ b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/mongo/InteractingEntityService.java @@ -17,6 +17,7 @@ import tech.ebp.oqm.core.api.model.object.history.ObjectHistoryEvent; import tech.ebp.oqm.core.api.model.object.interactingEntity.InteractingEntity; import tech.ebp.oqm.core.api.model.rest.search.InteractingEntitySearch; +import tech.ebp.oqm.core.api.service.serviceState.InstanceMutexService; import java.util.Optional; import java.util.concurrent.locks.ReentrantLock; @@ -56,7 +57,7 @@ public void setup() { } //force getting around Arc subclassing out the injected class CoreApiInteractingEntity coreApiInteractingEntity = new CoreApiInteractingEntity(); - //ensure we have the base station in the db + //ensure we have the Core API entity in the db CoreApiInteractingEntity gotten = (CoreApiInteractingEntity) this.get(coreApiInteractingEntity.getId()); if (gotten == null) { this.add(coreApiInteractingEntity); diff --git a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/notification/HistoryEventNotificationService.java b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/notification/HistoryEventNotificationService.java index 841c704a53..7ffd973acd 100644 --- a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/notification/HistoryEventNotificationService.java +++ b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/notification/HistoryEventNotificationService.java @@ -14,6 +14,7 @@ import org.eclipse.microprofile.reactive.messaging.Incoming; import org.eclipse.microprofile.reactive.messaging.Message; import org.eclipse.microprofile.reactive.messaging.OnOverflow; +import tech.ebp.oqm.core.api.model.messaging.EventNotificationWrapper; import tech.ebp.oqm.core.api.model.object.history.ObjectHistoryEvent; import java.util.Arrays; diff --git a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/notification/OutgoingNotificationService.java b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/notification/OutgoingNotificationService.java index 68d42f4164..67666d68ed 100644 --- a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/notification/OutgoingNotificationService.java +++ b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/notification/OutgoingNotificationService.java @@ -3,39 +3,20 @@ import io.smallrye.reactive.messaging.annotations.Broadcast; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; -import org.bson.types.ObjectId; import org.eclipse.microprofile.reactive.messaging.Channel; import org.eclipse.microprofile.reactive.messaging.Emitter; import org.eclipse.microprofile.reactive.messaging.Message; import org.eclipse.microprofile.reactive.messaging.OnOverflow; -import tech.ebp.oqm.core.api.model.object.history.ObjectHistoryEvent; +import tech.ebp.oqm.core.api.model.messaging.EventNotificationWrapper; /** - * Don't - * use - * this - * anywhere - * except - * in - * {@link - * HistoryEventNotificationService} + * Don't use this anywhere except in {@link HistoryEventNotificationService} *

- * Exists - * to - * skirt - * around - * CDI - * issues - * related - * to - * enabledness - * of - * the - * emitter. + * Exists to skirt around CDI issues related to enabledness of the emitter. */ @ApplicationScoped public class OutgoingNotificationService { - + @Inject @Broadcast @Channel(HistoryEventNotificationService.OUTGOING_EVENT_CHANNEL) @@ -43,6 +24,10 @@ public class OutgoingNotificationService { Emitter outgoingEventEmitter; + /** + * Sends the given notification wrapper to the outgoing event channel. + * @param notificationWrapper The notification wrapper to send. + */ public void sendEvent( Message notificationWrapper ) { diff --git a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/mongo/InstanceMutexService.java b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/serviceState/InstanceMutexService.java similarity index 98% rename from software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/mongo/InstanceMutexService.java rename to software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/serviceState/InstanceMutexService.java index c4dfb433ec..f26e330c79 100644 --- a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/mongo/InstanceMutexService.java +++ b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/serviceState/InstanceMutexService.java @@ -1,4 +1,4 @@ -package tech.ebp.oqm.core.api.service.mongo; +package tech.ebp.oqm.core.api.service.serviceState; import com.mongodb.client.model.*; import com.mongodb.client.result.UpdateResult; @@ -15,6 +15,7 @@ import tech.ebp.oqm.core.api.model.InstanceMutex; import tech.ebp.oqm.core.api.model.collectionStats.CollectionStats; import tech.ebp.oqm.core.api.model.rest.search.InstanceMutexSearch; +import tech.ebp.oqm.core.api.service.mongo.TopLevelMongoService; import java.io.Closeable; import java.io.IOException; diff --git a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/serviceState/ServiceStateService.java b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/serviceState/ServiceStateService.java deleted file mode 100644 index 1a71ef0078..0000000000 --- a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/service/serviceState/ServiceStateService.java +++ /dev/null @@ -1,7 +0,0 @@ -package tech.ebp.oqm.core.api.service.serviceState; - -public class ServiceStateService { - - // public static final ObjectId STATE_RECORD_ID = new ObjectId("00000000AAAAAAAAAAFFFFFF"); - //TODO:: this https://github.com/Epic-Breakfast-Productions/OpenQuarterMaster/issues/233 -} diff --git a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/utils/ExternalAuthUtilService.java b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/utils/ExternalAuthUtilService.java deleted file mode 100644 index 9f1fb1bb6a..0000000000 --- a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/utils/ExternalAuthUtilService.java +++ /dev/null @@ -1,9 +0,0 @@ -package tech.ebp.oqm.core.api.utils; - -import jakarta.enterprise.context.ApplicationScoped; - -@ApplicationScoped -public class ExternalAuthUtilService { - - -} diff --git a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/utils/JacksonModuleCustomizer.java b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/utils/JacksonModuleCustomizer.java index 7c61c3f687..f9d746c769 100644 --- a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/utils/JacksonModuleCustomizer.java +++ b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/utils/JacksonModuleCustomizer.java @@ -6,6 +6,9 @@ import jakarta.inject.Singleton; import tech.ebp.oqm.core.api.model.object.ObjectUtils; +/** + * Customizes the Jackson ObjectMapper for the Core API. + */ @Singleton public class JacksonModuleCustomizer implements ObjectMapperCustomizer { diff --git a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/utils/TimeUtils.java b/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/utils/TimeUtils.java deleted file mode 100644 index 1ef7522da2..0000000000 --- a/software/core/oqm-core-api/src/main/java/tech/ebp/oqm/core/api/utils/TimeUtils.java +++ /dev/null @@ -1,12 +0,0 @@ -package tech.ebp.oqm.core.api.utils; - -public class TimeUtils { - - /** - * @return the current time in seconds since epoch - */ - public static long currentTimeInSecs() { - long currentTimeMS = System.currentTimeMillis(); - return (currentTimeMS / 1000L); - } -} diff --git a/software/core/oqm-core-api/src/test/java/tech/ebp/oqm/core/api/model/jackson/ColorModuleTest.java b/software/core/oqm-core-api/src/test/java/tech/ebp/oqm/core/api/model/jackson/ColorModuleTest.java new file mode 100644 index 0000000000..e522f55af8 --- /dev/null +++ b/software/core/oqm-core-api/src/test/java/tech/ebp/oqm/core/api/model/jackson/ColorModuleTest.java @@ -0,0 +1,45 @@ +package tech.ebp.oqm.core.api.model.jackson; + +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import tech.ebp.oqm.core.api.model.testUtils.BasicTest; + +import java.awt.*; +import java.io.IOException; +import java.util.stream.Stream; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +@Slf4j +class ColorModuleTest extends BasicTest { + + private static Stream hexColorArgs() { + return Stream.of( + Arguments.of("#000000", Color.BLACK), + Arguments.of("#FFFFFF", Color.WHITE) +// Arguments.of("white", Color.WHITE) +// Arguments.of("#FFF", Color.WHITE)//no-go + ); + } + + private final ColorModule module = new ColorModule(); + + @ParameterizedTest + @MethodSource("hexColorArgs") + public void toColorStaticUtilTest(String hex, Color expectedColor) { + Color gotten = ColorModule.toColor(hex); + assertEquals(expectedColor, gotten); + } + + @ParameterizedTest + @MethodSource("hexColorArgs") + public void toHexStringStaticUtilTest(String expectedHex, Color color) { + String gotten = ColorModule.toHexString(color); + assertEquals(expectedHex, gotten); + } + + //TODO:: test parse from/to json + +} \ No newline at end of file diff --git a/software/core/oqm-core-api/src/test/java/tech/ebp/oqm/core/api/service/mongo/AppliedTransactionServiceTest.java b/software/core/oqm-core-api/src/test/java/tech/ebp/oqm/core/api/service/mongo/AppliedTransactionServiceTest.java index 7b5407d88d..ed5d18ba3c 100644 --- a/software/core/oqm-core-api/src/test/java/tech/ebp/oqm/core/api/service/mongo/AppliedTransactionServiceTest.java +++ b/software/core/oqm-core-api/src/test/java/tech/ebp/oqm/core/api/service/mongo/AppliedTransactionServiceTest.java @@ -53,7 +53,7 @@ import tech.ebp.oqm.core.api.model.rest.search.StoredSearch; import tech.ebp.oqm.core.api.service.mongo.search.SearchResult; import tech.ebp.oqm.core.api.service.mongo.transactions.AppliedTransactionService; -import tech.ebp.oqm.core.api.service.notification.EventNotificationWrapper; +import tech.ebp.oqm.core.api.model.messaging.EventNotificationWrapper; import tech.ebp.oqm.core.api.service.notification.HistoryEventNotificationService; import tech.ebp.oqm.core.api.testResources.data.InventoryItemTestObjectCreator; import tech.ebp.oqm.core.api.testResources.data.StorageBlockTestObjectCreator; diff --git a/software/core/oqm-core-api/src/test/java/tech/ebp/oqm/core/api/service/mongo/MongoHistoriedObjectServiceTest.java b/software/core/oqm-core-api/src/test/java/tech/ebp/oqm/core/api/service/mongo/MongoHistoriedObjectServiceTest.java index 373e8d78bc..8973a1b0fa 100644 --- a/software/core/oqm-core-api/src/test/java/tech/ebp/oqm/core/api/service/mongo/MongoHistoriedObjectServiceTest.java +++ b/software/core/oqm-core-api/src/test/java/tech/ebp/oqm/core/api/service/mongo/MongoHistoriedObjectServiceTest.java @@ -9,10 +9,9 @@ import io.smallrye.reactive.messaging.kafka.companion.KafkaCompanion; import lombok.Getter; import lombok.extern.slf4j.Slf4j; -import org.bson.types.ObjectId; import org.junit.jupiter.api.Test; import tech.ebp.oqm.core.api.model.object.ObjectUtils; -import tech.ebp.oqm.core.api.service.notification.EventNotificationWrapper; +import tech.ebp.oqm.core.api.model.messaging.EventNotificationWrapper; import tech.ebp.oqm.core.api.service.notification.HistoryEventNotificationService; import tech.ebp.oqm.core.api.service.serviceState.db.OqmDatabaseService; import tech.ebp.oqm.core.api.testResources.data.TestMainObject; diff --git a/software/core/oqm-core-api/src/test/java/tech/ebp/oqm/core/api/service/mongo/InstanceMutexServiceTest.java b/software/core/oqm-core-api/src/test/java/tech/ebp/oqm/core/api/service/serviceState/InstanceMutexServiceTest.java similarity index 98% rename from software/core/oqm-core-api/src/test/java/tech/ebp/oqm/core/api/service/mongo/InstanceMutexServiceTest.java rename to software/core/oqm-core-api/src/test/java/tech/ebp/oqm/core/api/service/serviceState/InstanceMutexServiceTest.java index 8eda11d11e..a6118b315e 100644 --- a/software/core/oqm-core-api/src/test/java/tech/ebp/oqm/core/api/service/mongo/InstanceMutexServiceTest.java +++ b/software/core/oqm-core-api/src/test/java/tech/ebp/oqm/core/api/service/serviceState/InstanceMutexServiceTest.java @@ -1,4 +1,4 @@ -package tech.ebp.oqm.core.api.service.mongo; +package tech.ebp.oqm.core.api.service.serviceState; import io.quarkus.test.junit.QuarkusTest; diff --git a/software/libs/core-api-lib-quarkus/README.md b/software/libs/core-api-lib-quarkus/README.md index fd5491c35c..e4f9e471aa 100644 --- a/software/libs/core-api-lib-quarkus/README.md +++ b/software/libs/core-api-lib-quarkus/README.md @@ -57,4 +57,6 @@ then: https://central.sonatype.com/publishing/deployments +## Tips n Tricks + - Connect to kafka with UI: `docker run --network=host -e KAFKA_BROKERS=localhost:9192 -e SERVER_LISTENPORT=8081 docker.redpanda.com/redpandadata/console:latest` diff --git a/software/libs/core-api-lib-quarkus/deployment/src/main/java/tech/ebp/oqm/lib/core/api/quarkus/deployment/CoreApiLibQuarkusProcessor.java b/software/libs/core-api-lib-quarkus/deployment/src/main/java/tech/ebp/oqm/lib/core/api/quarkus/deployment/CoreApiLibQuarkusProcessor.java index 3e6799a161..0a58849bcc 100644 --- a/software/libs/core-api-lib-quarkus/deployment/src/main/java/tech/ebp/oqm/lib/core/api/quarkus/deployment/CoreApiLibQuarkusProcessor.java +++ b/software/libs/core-api-lib-quarkus/deployment/src/main/java/tech/ebp/oqm/lib/core/api/quarkus/deployment/CoreApiLibQuarkusProcessor.java @@ -37,8 +37,10 @@ class CoreApiLibQuarkusProcessor { private static final Logger log = Logger.getLogger(CoreApiLibQuarkusProcessor.class); private static final String FEATURE = "core-api-lib-quarkus"; - private static final String MONGODB_DEVSERVICE_HOSTNAME = "oqm-core-api-devservice-mongodb-server"; - private static final String KAFKA_DEVSERVICE_HOSTNAME = "localhost"; + private static final String MONGODB_DEVSERVICE_HOSTNAME = "localhost"; + private static final String HOST = "localhost"; + private static final String KEYCLOAK_DEVSERVICE_HOSTNAME = HOST; + private static final String KAFKA_DEVSERVICE_HOSTNAME = HOST; private static volatile boolean firstSetup = true; @@ -70,7 +72,7 @@ private MongoDBContainer newMongoDbContainer() { MongoDBContainer mongoDBContainer = new MongoDBContainer(mongoImageName); mongoDBContainer.addExposedPorts(); mongoDBContainer.withNetwork(Network.SHARED); - mongoDBContainer.withNetworkAliases(MONGODB_DEVSERVICE_HOSTNAME); +// mongoDBContainer.withNetworkAliases(MONGODB_DEVSERVICE_HOSTNAME); mongoDBContainer.start(); return mongoDBContainer; @@ -85,13 +87,15 @@ private OqmCoreApiWebServiceContainer newCoreApiContainer( OqmCoreApiWebServiceContainer container = new OqmCoreApiWebServiceContainer(config.devservices(), mongoConnectionInfo, kafkaConnectionInfo) - .withAccessToHost(true) - .withNetwork(Network.SHARED); + // .withAccessToHost(true) + // .withNetwork(Network.SHARED) + ; container.withEnv( "smallrye.jwt.verify.key.location", String.format( - "http://host.testcontainers.internal:%s/realms/%s/protocol/openid-connect/certs", + "http://%s:%s/realms/%s/protocol/openid-connect/certs", + KEYCLOAK_DEVSERVICE_HOSTNAME, config.devservices().keycloak().port(), config.devservices().keycloak().realm() ) @@ -111,17 +115,30 @@ public List createContainer(LaunchModeBuildItem laun Map mongoConnectionInfo = new HashMap<>(); Map kafkaConnectionInfo = new HashMap<>(); {//mongodb - mongoConnectionInfo.put("quarkus.mongodb.connection-string", "mongodb://" + MONGODB_DEVSERVICE_HOSTNAME + ":27017"); DevServicesResultBuildItem.RunningDevService mongoDevService = DEVSERVICES.get("mongodb"); if (mongoDevService == null) { MongoDBContainer mongoDBContainer = newMongoDbContainer(); - mongoDevService = new DevServicesResultBuildItem.RunningDevService(FEATURE, mongoDBContainer.getContainerId(), mongoDBContainer::close, Map.of()); + mongoDevService = new DevServicesResultBuildItem.RunningDevService( + FEATURE, + mongoDBContainer.getContainerId(), + mongoDBContainer::close, + Map.of( + "port", + String.valueOf(mongoDBContainer.getMappedPort(27017)) + ) + ); + DEVSERVICES.put("mongodb", mongoDevService); } + mongoConnectionInfo.put( + "quarkus.mongodb.connection-string", + "mongodb://" + MONGODB_DEVSERVICE_HOSTNAME + ":" + mongoDevService.getConfig().get("port") + ); + output.add(mongoDevService.toBuildItem()); } if (config.devservices().kafka().enabled()) {//connect to existent diff --git a/software/libs/core-api-lib-quarkus/deployment/src/main/java/tech/ebp/oqm/lib/core/api/quarkus/deployment/testContainers/OqmCoreApiWebServiceContainer.java b/software/libs/core-api-lib-quarkus/deployment/src/main/java/tech/ebp/oqm/lib/core/api/quarkus/deployment/testContainers/OqmCoreApiWebServiceContainer.java index 730515be5c..95ccb08fa6 100644 --- a/software/libs/core-api-lib-quarkus/deployment/src/main/java/tech/ebp/oqm/lib/core/api/quarkus/deployment/testContainers/OqmCoreApiWebServiceContainer.java +++ b/software/libs/core-api-lib-quarkus/deployment/src/main/java/tech/ebp/oqm/lib/core/api/quarkus/deployment/testContainers/OqmCoreApiWebServiceContainer.java @@ -1,5 +1,6 @@ package tech.ebp.oqm.lib.core.api.quarkus.deployment.testContainers; +import com.github.dockerjava.api.model.HostConfig; import org.testcontainers.Testcontainers; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; @@ -35,12 +36,18 @@ public OqmCoreApiWebServiceContainer( @Override protected void configure() { //configure network - withNetwork(Network.SHARED); - Testcontainers.exposeHostPorts(this.devserviceConfig.keycloak().port()); - addFixedExposedPort(devserviceConfig.port(), 80); + withCreateContainerCmdModifier(cmd -> cmd.withHostConfig( + new HostConfig().withNetworkMode("host") + )); +// Testcontainers.exposeHostPorts(this.devserviceConfig.keycloak().port()); +// Testcontainers.exposeHostPorts(this.devserviceConfig.kafka().port()); + +// addFixedExposedPort(devserviceConfig.port(), 80); + //configure env this.withEnv(mongoConnectionInfo); this.withEnv(kafkaConnectionInfo); + this.withEnv("QUARKUS_HTTP_PORT", String.valueOf(this.devserviceConfig.port())); // Tell the dev service how to know the container is ready. All 3 is likely overkill, but eh this.waitingFor(Wait.forHealthcheck());