From 13d1a08a26837a1bae077fa289582dfe6fa0fc9a Mon Sep 17 00:00:00 2001 From: Eric Wittmann Date: Mon, 21 Oct 2024 14:37:07 -0400 Subject: [PATCH] Add modifiedBy and modifiedOn to version metadata. --- .../apicurio/registry/rest/v3/V3ApiUtil.java | 2 + .../dto/ArtifactVersionMetaDataDto.java | 2 + .../ArtifactVersionMetaDataDtoMapper.java | 2 + .../rest/v3/VersionModifiedByOnTest.java | 54 ++++++++++++++++ .../src/main/resources/META-INF/openapi.json | 9 +++ go-sdk/pkg/registryclient-v3/kiota-lock.json | 2 +- .../models/version_meta_data.go | 62 +++++++++++++++++++ 7 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 app/src/test/java/io/apicurio/registry/noprofile/rest/v3/VersionModifiedByOnTest.java diff --git a/app/src/main/java/io/apicurio/registry/rest/v3/V3ApiUtil.java b/app/src/main/java/io/apicurio/registry/rest/v3/V3ApiUtil.java index 34fd65ec8d..2227926f2d 100644 --- a/app/src/main/java/io/apicurio/registry/rest/v3/V3ApiUtil.java +++ b/app/src/main/java/io/apicurio/registry/rest/v3/V3ApiUtil.java @@ -77,6 +77,8 @@ public static VersionMetaData dtoToVersionMetaData(ArtifactVersionMetaDataDto dt metaData.setArtifactId(dto.getArtifactId()); metaData.setOwner(dto.getOwner()); metaData.setCreatedOn(new Date(dto.getCreatedOn())); + metaData.setModifiedBy(dto.getModifiedBy()); + metaData.setModifiedOn(new Date(dto.getModifiedOn())); metaData.setDescription(dto.getDescription()); metaData.setName(dto.getName()); metaData.setArtifactType(dto.getArtifactType()); diff --git a/app/src/main/java/io/apicurio/registry/storage/dto/ArtifactVersionMetaDataDto.java b/app/src/main/java/io/apicurio/registry/storage/dto/ArtifactVersionMetaDataDto.java index d47787200e..333141cc15 100644 --- a/app/src/main/java/io/apicurio/registry/storage/dto/ArtifactVersionMetaDataDto.java +++ b/app/src/main/java/io/apicurio/registry/storage/dto/ArtifactVersionMetaDataDto.java @@ -30,6 +30,8 @@ public class ArtifactVersionMetaDataDto { private String description; private String owner; private long createdOn; + private String modifiedBy; + private long modifiedOn; private String artifactType; private VersionState state; private Map labels; diff --git a/app/src/main/java/io/apicurio/registry/storage/impl/sql/mappers/ArtifactVersionMetaDataDtoMapper.java b/app/src/main/java/io/apicurio/registry/storage/impl/sql/mappers/ArtifactVersionMetaDataDtoMapper.java index b8bbb037b4..31dfb5d15d 100644 --- a/app/src/main/java/io/apicurio/registry/storage/impl/sql/mappers/ArtifactVersionMetaDataDtoMapper.java +++ b/app/src/main/java/io/apicurio/registry/storage/impl/sql/mappers/ArtifactVersionMetaDataDtoMapper.java @@ -40,6 +40,8 @@ public ArtifactVersionMetaDataDto map(ResultSet rs) throws SQLException { dto.setVersionOrder(rs.getInt("versionOrder")); dto.setArtifactType(rs.getString("type")); dto.setLabels(RegistryContentUtils.deserializeLabels(rs.getString("labels"))); + dto.setModifiedBy(rs.getString("modifiedBy")); + dto.setCreatedOn(rs.getTimestamp("modifiedOn").getTime()); return dto; } diff --git a/app/src/test/java/io/apicurio/registry/noprofile/rest/v3/VersionModifiedByOnTest.java b/app/src/test/java/io/apicurio/registry/noprofile/rest/v3/VersionModifiedByOnTest.java new file mode 100644 index 0000000000..141a13764d --- /dev/null +++ b/app/src/test/java/io/apicurio/registry/noprofile/rest/v3/VersionModifiedByOnTest.java @@ -0,0 +1,54 @@ +package io.apicurio.registry.noprofile.rest.v3; + +import io.apicurio.registry.AbstractResourceTestBase; +import io.apicurio.registry.rest.client.models.SearchedVersion; +import io.apicurio.registry.rest.client.models.VersionMetaData; +import io.apicurio.registry.rest.client.models.VersionSearchResults; +import io.apicurio.registry.types.ArtifactType; +import io.apicurio.registry.types.ContentTypes; +import io.apicurio.registry.utils.tests.TestUtils; +import io.quarkus.test.junit.QuarkusTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +@QuarkusTest +public class VersionModifiedByOnTest extends AbstractResourceTestBase { + + @Test + public void testSearchVersionsWithModified() throws Exception { + String artifactContent = resourceToString("openapi-empty.json"); + String groupId = TestUtils.generateGroupId(); + + // Create 5 artifacts + for (int idx = 0; idx < 5; idx++) { + String artifactId = TestUtils.generateArtifactId(); + createArtifact(groupId, artifactId, ArtifactType.OPENAPI, artifactContent, + ContentTypes.APPLICATION_JSON); + } + + VersionSearchResults results = clientV3.search().versions().get(config -> { + config.queryParameters.groupId = groupId; + }); + Assertions.assertEquals(5, results.getCount()); + for (SearchedVersion version : results.getVersions()) { + Assertions.assertNotNull(version.getModifiedOn()); + } + } + + @Test + public void testVersionMetaDataWithModified() throws Exception { + String artifactContent = resourceToString("openapi-empty.json"); + String groupId = TestUtils.generateGroupId(); + String artifactId = TestUtils.generateArtifactId(); + + createArtifact(groupId, artifactId, ArtifactType.OPENAPI, artifactContent, + ContentTypes.APPLICATION_JSON, (ca) -> { + ca.getFirstVersion().setVersion("1.0"); + }); + + VersionMetaData vmd = clientV3.groups().byGroupId(groupId).artifacts().byArtifactId(artifactId).versions().byVersionExpression("1.0").get(); + Assertions.assertNotNull(vmd); + Assertions.assertNotNull(vmd.getModifiedOn()); + } + +} diff --git a/common/src/main/resources/META-INF/openapi.json b/common/src/main/resources/META-INF/openapi.json index 25983056c0..01f25f3144 100644 --- a/common/src/main/resources/META-INF/openapi.json +++ b/common/src/main/resources/META-INF/openapi.json @@ -4007,6 +4007,15 @@ "artifactId": { "$ref": "#/components/schemas/ArtifactId", "description": "" + }, + "modifiedBy": { + "description": "", + "type": "string" + }, + "modifiedOn": { + "format": "date-time", + "description": "", + "type": "string" } }, "example": { diff --git a/go-sdk/pkg/registryclient-v3/kiota-lock.json b/go-sdk/pkg/registryclient-v3/kiota-lock.json index 4ddd3b2657..f4afc6c6b1 100644 --- a/go-sdk/pkg/registryclient-v3/kiota-lock.json +++ b/go-sdk/pkg/registryclient-v3/kiota-lock.json @@ -1,5 +1,5 @@ { - "descriptionHash": "0DD5D7FB5AB616D59BD7C21D29C19401ADA735DD30E366CE1946E44209EFEFA3896C1AE4B2F3204F00EE2E6B58AE47F43F999A27E251F2FE5D5C9C65E34380EC", + "descriptionHash": "00581DCACB1B1D7CFE571A59235CDC2AE7CA2C5158E25D26D03F23337D82CC23EFFD219AFAF562BB50AA94EFB196FFED7150C31C23BBB22910B7AD366AC7FF2D", "descriptionLocation": "../../v3.json", "lockFileVersion": "1.0.0", "kiotaVersion": "1.19.1", diff --git a/go-sdk/pkg/registryclient-v3/models/version_meta_data.go b/go-sdk/pkg/registryclient-v3/models/version_meta_data.go index 1883aa0538..4d10997ca8 100644 --- a/go-sdk/pkg/registryclient-v3/models/version_meta_data.go +++ b/go-sdk/pkg/registryclient-v3/models/version_meta_data.go @@ -24,6 +24,10 @@ type VersionMetaData struct { groupId *string // User-defined name-value pairs. Name and value must be strings. labels Labelsable + // The modifiedBy property + modifiedBy *string + // The modifiedOn property + modifiedOn *i336074805fc853987abe6f7fe3ad97a6a6f3077a16391fec744f671a015fbd7e.Time // The name property name *string // The owner property @@ -167,6 +171,26 @@ func (m *VersionMetaData) GetFieldDeserializers() map[string]func(i878a80d2330e8 } return nil } + res["modifiedBy"] = func(n i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode) error { + val, err := n.GetStringValue() + if err != nil { + return err + } + if val != nil { + m.SetModifiedBy(val) + } + return nil + } + res["modifiedOn"] = func(n i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode) error { + val, err := n.GetTimeValue() + if err != nil { + return err + } + if val != nil { + m.SetModifiedOn(val) + } + return nil + } res["name"] = func(n i878a80d2330e89d26896388a3f487eef27b0a0e6c010c493bf80be1452208f91.ParseNode) error { val, err := n.GetStringValue() if err != nil { @@ -228,6 +252,18 @@ func (m *VersionMetaData) GetLabels() Labelsable { return m.labels } +// GetModifiedBy gets the modifiedBy property value. The modifiedBy property +// returns a *string when successful +func (m *VersionMetaData) GetModifiedBy() *string { + return m.modifiedBy +} + +// GetModifiedOn gets the modifiedOn property value. The modifiedOn property +// returns a *Time when successful +func (m *VersionMetaData) GetModifiedOn() *i336074805fc853987abe6f7fe3ad97a6a6f3077a16391fec744f671a015fbd7e.Time { + return m.modifiedOn +} + // GetName gets the name property value. The name property // returns a *string when successful func (m *VersionMetaData) GetName() *string { @@ -302,6 +338,18 @@ func (m *VersionMetaData) Serialize(writer i878a80d2330e89d26896388a3f487eef27b0 return err } } + { + err := writer.WriteStringValue("modifiedBy", m.GetModifiedBy()) + if err != nil { + return err + } + } + { + err := writer.WriteTimeValue("modifiedOn", m.GetModifiedOn()) + if err != nil { + return err + } + } { err := writer.WriteStringValue("name", m.GetName()) if err != nil { @@ -381,6 +429,16 @@ func (m *VersionMetaData) SetLabels(value Labelsable) { m.labels = value } +// SetModifiedBy sets the modifiedBy property value. The modifiedBy property +func (m *VersionMetaData) SetModifiedBy(value *string) { + m.modifiedBy = value +} + +// SetModifiedOn sets the modifiedOn property value. The modifiedOn property +func (m *VersionMetaData) SetModifiedOn(value *i336074805fc853987abe6f7fe3ad97a6a6f3077a16391fec744f671a015fbd7e.Time) { + m.modifiedOn = value +} + // SetName sets the name property value. The name property func (m *VersionMetaData) SetName(value *string) { m.name = value @@ -412,6 +470,8 @@ type VersionMetaDataable interface { GetGlobalId() *int64 GetGroupId() *string GetLabels() Labelsable + GetModifiedBy() *string + GetModifiedOn() *i336074805fc853987abe6f7fe3ad97a6a6f3077a16391fec744f671a015fbd7e.Time GetName() *string GetOwner() *string GetState() *VersionState @@ -424,6 +484,8 @@ type VersionMetaDataable interface { SetGlobalId(value *int64) SetGroupId(value *string) SetLabels(value Labelsable) + SetModifiedBy(value *string) + SetModifiedOn(value *i336074805fc853987abe6f7fe3ad97a6a6f3077a16391fec744f671a015fbd7e.Time) SetName(value *string) SetOwner(value *string) SetState(value *VersionState)