diff --git a/std-bits/base/src/main/java/org/enso/base/CurrentEnsoProject.java b/std-bits/base/src/main/java/org/enso/base/CurrentEnsoProject.java index 06b8442d7259..2928c693d58c 100644 --- a/std-bits/base/src/main/java/org/enso/base/CurrentEnsoProject.java +++ b/std-bits/base/src/main/java/org/enso/base/CurrentEnsoProject.java @@ -1,19 +1,41 @@ package org.enso.base; +import org.enso.base.polyglot.EnsoMeta; +import org.graalvm.polyglot.Value; + /** A Java interface to the `Enso_Project` type. */ public final class CurrentEnsoProject { private final String name; private final String namespace; + private static CurrentEnsoProject cached = null; + private static boolean isCached = false; + private CurrentEnsoProject(String name, String namespace) { this.name = name; this.namespace = namespace; } public static CurrentEnsoProject get() { - // TODO this currently does not work, because of bug - // https://github.com/enso-org/enso/issues/9845 - return null; + if (!isCached) { + Value ensoProject = + EnsoMeta.callStaticModuleMethod("Standard.Base.Meta.Enso_Project", "enso_project"); + if (ensoProject.hasMember("name") && ensoProject.hasMember("namespace")) { + Value namespace = ensoProject.invokeMember("namespace"); + Value name = ensoProject.invokeMember("name"); + if (namespace == null || name == null) { + cached = null; + } else { + cached = new CurrentEnsoProject(name.asString(), namespace.asString()); + } + } else { + cached = null; + } + + isCached = true; + } + + return cached; } public String getName() { diff --git a/std-bits/base/src/main/java/org/enso/base/enso_cloud/audit/AuditLogMessage.java b/std-bits/base/src/main/java/org/enso/base/enso_cloud/audit/AuditLogMessage.java index 17fa09d6e18b..4cde39fd00e4 100644 --- a/std-bits/base/src/main/java/org/enso/base/enso_cloud/audit/AuditLogMessage.java +++ b/std-bits/base/src/main/java/org/enso/base/enso_cloud/audit/AuditLogMessage.java @@ -55,8 +55,7 @@ private ObjectNode computedMetadata() { var copy = metadata.deepCopy(); copy.set(OPERATION, TextNode.valueOf(operation)); - // TODO the null check should no longer be needed once - // https://github.com/enso-org/enso/issues/9845 is fixed + // The project name may be null if a script is run outside a project. if (projectName != null) { copy.set(PROJECT_NAME, TextNode.valueOf(projectName)); } diff --git a/std-bits/database/src/main/java/org/enso/database/audit/CloudAuditedConnection.java b/std-bits/database/src/main/java/org/enso/database/audit/CloudAuditedConnection.java index 1fa43fd45d5d..0272c23280c1 100644 --- a/std-bits/database/src/main/java/org/enso/database/audit/CloudAuditedConnection.java +++ b/std-bits/database/src/main/java/org/enso/database/audit/CloudAuditedConnection.java @@ -25,7 +25,7 @@ public CloudAuditedConnection(Connection underlying, String relatedAssetId) { metadata.put("asset_id", relatedAssetId); } try { - metadata.put("connection_uri", underlying.getMetaData().getURL()); + metadata.put("connectionUri", underlying.getMetaData().getURL()); } catch (SQLException e) { // We ignore the exception, only logging it logger.warning("Failed to get connection URI for " + underlying + ": " + e.getMessage()); @@ -34,7 +34,7 @@ public CloudAuditedConnection(Connection underlying, String relatedAssetId) { private void audit(String operationType, String message) { var metadataCopy = metadata.deepCopy(); - metadataCopy.put("sequence_number", sequenceNumber++); + metadataCopy.put("sequenceNumber", sequenceNumber++); AuditLog.logAsync(operationType, message, metadataCopy); } diff --git a/test/Base_Tests/src/Network/Enso_Cloud/Audit_Log_Spec.enso b/test/Base_Tests/src/Network/Enso_Cloud/Audit_Log_Spec.enso index d45be8687961..86778e234deb 100644 --- a/test/Base_Tests/src/Network/Enso_Cloud/Audit_Log_Spec.enso +++ b/test/Base_Tests/src/Network/Enso_Cloud/Audit_Log_Spec.enso @@ -30,9 +30,7 @@ add_specs suite_builder = event my_event.metadata.get "operation" . should_equal "TestEvent" - - # TODO this test should be re-enabled after https://github.com/enso-org/enso/issues/9845 is fixed - #my_event.metadata.get "projectName" . should_equal "enso_dev.Base_Tests" + my_event.metadata.get "projectName" . should_equal "enso_dev.Base_Tests" my_event.message . should_equal "Message" my_event.user_email . should_equal Enso_User.current.email diff --git a/test/Table_Tests/src/Database/Common/Audit_Spec.enso b/test/Table_Tests/src/Database/Common/Audit_Spec.enso index 63c8ad4113a0..ca0cf0b13cdb 100644 --- a/test/Table_Tests/src/Database/Common/Audit_Spec.enso +++ b/test/Table_Tests/src/Database/Common/Audit_Spec.enso @@ -41,15 +41,16 @@ add_specs suite_builder prefix ~datalink_to_connection database_pending = create = relevant_events.find (e-> e.message.contains "CREATE") create.should_succeed create.user_email . should_equal Enso_User.current.email - create.metadata.get "connection_uri" . should_contain "jdbc:" + create.metadata.get "connectionUri" . should_contain "jdbc:" + create.metadata.get "projectName" . should_equal enso_project.namespace+"."+enso_project.name insert = relevant_events.find (e-> e.message.contains "INSERT INTO") insert.should_succeed # The insert query should not contain column cell data - only column names / metadata. insert.message.should_not_contain "my_payload" - create_sequence_number = create.metadata.get "sequence_number" - insert_sequence_number = insert.metadata.get "sequence_number" + create_sequence_number = create.metadata.get "sequenceNumber" + insert_sequence_number = insert.metadata.get "sequenceNumber" create_sequence_number.should_be_a Integer insert_sequence_number.should_be_a Integer (create_sequence_number < insert_sequence_number) . should_be_true