Skip to content

Commit

Permalink
Updated the REST API to allow updating group metadata (with labels)
Browse files Browse the repository at this point in the history
  • Loading branch information
EricWittmann committed Feb 13, 2024
1 parent 295f165 commit 6606e19
Show file tree
Hide file tree
Showing 32 changed files with 643 additions and 225 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,12 @@ public void createGroup(String groupId, SchemaGroup data) {

storage.createGroup(group.build());
} catch (GroupAlreadyExistsException e) {
GroupMetaDataDto existing = storage.getGroupMetaData(groupId);
EditableGroupMetaDataDto dto = EditableGroupMetaDataDto.builder()
.description(data.getDescription())
.labels(data.getGroupProperties())
.build();

group.createdBy(existing.getCreatedBy())
.createdOn(existing.getCreatedOn())
.modifiedBy(user)
.modifiedOn(new Date().getTime());

storage.updateGroupMetaData(group.build());
storage.updateGroupMetaData(groupId, dto);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,14 @@ public void createGroup(GroupMetaDataDto group) throws GroupAlreadyExistsExcepti
}

/**
* @see io.apicurio.registry.storage.RegistryStorage#updateGroupMetaData(io.apicurio.registry.storage.dto.GroupMetaDataDto)
* @see io.apicurio.registry.storage.decorator.RegistryStorageDecoratorBase#updateGroupMetaData(java.lang.String, io.apicurio.registry.storage.dto.EditableGroupMetaDataDto)

Check warning on line 254 in app/src/main/java/io/apicurio/registry/events/EventSourcedRegistryStorage.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unnecessary Javadoc link

`@see` pointing to super method is unnecessary
*/
@Override
public void updateGroupMetaData(GroupMetaDataDto group) throws GroupNotFoundException, RegistryStorageException {
delegate.updateGroupMetaData(group);
public void updateGroupMetaData(String groupId, EditableGroupMetaDataDto dto) throws GroupNotFoundException, RegistryStorageException {
delegate.updateGroupMetaData(groupId, dto);
ArtifactId data = new ArtifactId();
data.setGroupId(group.getGroupId());
fireEvent(RegistryEventType.GROUP_UPDATED, group.getGroupId(), data, null);
data.setGroupId(groupId);
fireEvent(RegistryEventType.GROUP_UPDATED, groupId, data, null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public ArtifactMetaData getArtifactMetaData(String groupId, String artifactId) {
@Audited(extractParameters = {"0", KEY_GROUP_ID, "1", KEY_ARTIFACT_ID, "2", KEY_EDITABLE_METADATA})
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Write)
public void updateArtifactMetaData(String groupId, String artifactId, EditableMetaData data) {
v3.updateArtifactMetaData(groupId, artifactId, io.apicurio.registry.rest.v3.beans.EditableMetaData.builder()
v3.updateArtifactMetaData(groupId, artifactId, io.apicurio.registry.rest.v3.beans.EditableArtifactMetaData.builder()
.description(data.getDescription())
.labels(V2ApiUtil.toV3Labels(data.getLabels(), data.getProperties()))
.name(data.getName())
Expand Down Expand Up @@ -538,7 +538,7 @@ public VersionMetaData getArtifactVersionMetaData(String groupId, String artifac
@Audited(extractParameters = {"0", KEY_GROUP_ID, "1", KEY_ARTIFACT_ID, "2", KEY_VERSION, "3", KEY_EDITABLE_METADATA})
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Write)
public void updateArtifactVersionMetaData(String groupId, String artifactId, String version, EditableMetaData data) {
v3.updateArtifactVersionMetaData(groupId, artifactId, version, io.apicurio.registry.rest.v3.beans.EditableMetaData.builder()
v3.updateArtifactVersionMetaData(groupId, artifactId, version, io.apicurio.registry.rest.v3.beans.EditableArtifactMetaData.builder()
.description(data.getDescription())
.labels(V2ApiUtil.toV3Labels(data.getLabels(), data.getProperties()))
.name(data.getName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.interceptor.Interceptors;
import jakarta.validation.constraints.NotNull;
import jakarta.ws.rs.BadRequestException;
import jakarta.ws.rs.HttpMethod;
import jakarta.ws.rs.NotAllowedException;
Expand Down Expand Up @@ -216,7 +215,7 @@ public ArtifactMetaData getArtifactMetaData(String groupId, String artifactId) {
@Override
@Audited(extractParameters = {"0", KEY_GROUP_ID, "1", KEY_ARTIFACT_ID, "2", KEY_EDITABLE_METADATA})
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Write)
public void updateArtifactMetaData(String groupId, String artifactId, EditableMetaData data) {
public void updateArtifactMetaData(String groupId, String artifactId, EditableArtifactMetaData data) {
requireParameter("groupId", groupId);
requireParameter("artifactId", artifactId);

Expand Down Expand Up @@ -267,6 +266,19 @@ public GroupMetaData getGroupById(String groupId) {
public void deleteGroupById(String groupId) {
storage.deleteGroup(groupId);
}

/**
* @see io.apicurio.registry.rest.v3.GroupsResource#updateGroupById(java.lang.String, io.apicurio.registry.rest.v3.beans.EditableGroupMetaData)
*/
@Override
public void updateGroupById(String groupId, EditableGroupMetaData data) {
requireParameter("groupId", groupId);

EditableGroupMetaDataDto dto = new EditableGroupMetaDataDto();
dto.setDescription(data.getDescription());
dto.setLabels(data.getLabels());
storage.updateGroupMetaData(new GroupId(groupId).getRawGroupIdWithNull(), dto);
}

@Override
@Authorized(style = AuthorizedStyle.None, level = AuthorizedLevel.Read)
Expand Down Expand Up @@ -551,12 +563,12 @@ public VersionMetaData getArtifactVersionMetaData(String groupId, String artifac
}

/**
* @see io.apicurio.registry.rest.v3.GroupsResource#updateArtifactVersionMetaData(java.lang.String, java.lang.String, java.lang.String, io.apicurio.registry.rest.v3.beans.EditableMetaData)
* @see io.apicurio.registry.rest.v3.GroupsResource#updateArtifactVersionMetaData(java.lang.String, java.lang.String, java.lang.String, io.apicurio.registry.rest.v3.beans.EditableArtifactMetaData)
*/
@Override
@Audited(extractParameters = {"0", KEY_GROUP_ID, "1", KEY_ARTIFACT_ID, "2", KEY_VERSION, "3", KEY_EDITABLE_METADATA})
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Write)
public void updateArtifactVersionMetaData(String groupId, String artifactId, String versionExpression, EditableMetaData data) {
public void updateArtifactVersionMetaData(String groupId, String artifactId, String versionExpression, EditableArtifactMetaData data) {
requireParameter("groupId", groupId);
requireParameter("artifactId", artifactId);
requireParameter("versionExpression", versionExpression);
Expand Down Expand Up @@ -1022,10 +1034,13 @@ public ArtifactBranch getArtifactBranch(String groupId, String artifactId, Strin
}


/**
* @see io.apicurio.registry.rest.v3.GroupsResource#createOrUpdateArtifactBranch(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
*/
@Override
@Audited(extractParameters = {"0", KEY_GROUP_ID, "1", KEY_ARTIFACT_ID, "2", "branch_id", "3", KEY_VERSION}) // TODO
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Write)
public ArtifactBranch createOrUpdateArtifactBranch(String groupId, String artifactId, String rawBranchId, @NotNull String version) {
public ArtifactBranch createOrUpdateArtifactBranch(String groupId, String artifactId, String rawBranchId, String version) {
requireParameter("groupId", groupId);
requireParameter("artifactId", artifactId);
requireParameter("branchId", rawBranchId);
Expand Down Expand Up @@ -1053,7 +1068,7 @@ public ArtifactBranch createOrUpdateArtifactBranch(String groupId, String artifa
@Override
@Audited(extractParameters = {"0", KEY_GROUP_ID, "1", KEY_ARTIFACT_ID, "2", "branch_id", "3", "branch"}) // TODO
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Write)
public ArtifactBranch createOrReplaceArtifactBranch(String groupId, String artifactId, String rawBranchId, @NotNull ArtifactBranch branch) {
public ArtifactBranch createOrReplaceArtifactBranch(String groupId, String artifactId, String rawBranchId, ArtifactBranch branch) {
requireParameter("groupId", groupId);
requireParameter("artifactId", artifactId);
requireParameter("branchId", rawBranchId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,14 +559,6 @@ void updateArtifactRule(String groupId, String artifactId, RuleType rule, RuleCo
*/
void createGroup(GroupMetaDataDto group) throws GroupAlreadyExistsException, RegistryStorageException;

/**
* Updates the metadata of an existent group.
*
* @param group
* @throws RegistryStorageException
*/
void updateGroupMetaData(GroupMetaDataDto group) throws GroupNotFoundException, RegistryStorageException;

/**
* Deletes a group identified by the given groupId and DELETES ALL resources related to this group
*
Expand All @@ -576,6 +568,14 @@ void updateArtifactRule(String groupId, String artifactId, RuleType rule, RuleCo
*/
void deleteGroup(String groupId) throws GroupNotFoundException, RegistryStorageException;

/**
* Updates the metadata for a group.
* @param groupId
* @param dto

Check warning on line 574 in app/src/main/java/io/apicurio/registry/storage/RegistryStorage.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Javadoc declaration problems

`@param dto` tag description is missing
*/
void updateGroupMetaData(String groupId, EditableGroupMetaDataDto dto);
void updateGroupMetaData(String groupId, String description, Map<String, String> labels, String modifiedBy, Date modifiedOn);

/**
* Get all groupIds
*
Expand Down Expand Up @@ -950,4 +950,5 @@ enum ArtifactRetrievalBehavior {
*/
SKIP_DISABLED_LATEST
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;

@ApplicationScoped
Expand Down Expand Up @@ -241,11 +242,20 @@ public void createGroup(GroupMetaDataDto group) throws GroupAlreadyExistsExcepti
delegate.createGroup(group);
}



@Override
public void updateGroupMetaData(String groupId, EditableGroupMetaDataDto dto) {
checkReadOnly();
delegate.updateGroupMetaData(groupId, dto);
}

/**
* @see io.apicurio.registry.storage.RegistryStorage#updateGroupMetaData(java.lang.String, java.lang.String, java.util.Map, java.lang.String, java.util.Date)

Check warning on line 253 in app/src/main/java/io/apicurio/registry/storage/decorator/ReadOnlyRegistryStorageDecorator.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Use of obsolete date-time API

Obsolete date-time type `java.util.Date` used
*/
@Override
public void updateGroupMetaData(GroupMetaDataDto group) throws GroupNotFoundException, RegistryStorageException {
public void updateGroupMetaData(String groupId, String description, Map<String, String> labels, String modifiedBy, Date modifiedOn) {
checkReadOnly();
delegate.updateGroupMetaData(group);
delegate.updateGroupMetaData(groupId, description, labels, modifiedBy, modifiedOn);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
* Forwards all method calls to the delegate, extends the read-only base.
Expand Down Expand Up @@ -188,9 +189,15 @@ public void createGroup(GroupMetaDataDto group)


@Override
public void updateGroupMetaData(GroupMetaDataDto group)
throws GroupNotFoundException, RegistryStorageException {
delegate.updateGroupMetaData(group);
public void updateGroupMetaData(String groupId, EditableGroupMetaDataDto dto) throws GroupNotFoundException, RegistryStorageException {
delegate.updateGroupMetaData(groupId, dto);
}


@Override
public void updateGroupMetaData(String groupId, String description, Map<String, String> labels,
String modifiedBy, Date modifiedOn) {

Check warning on line 199 in app/src/main/java/io/apicurio/registry/storage/decorator/RegistryStorageDecoratorBase.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Use of obsolete date-time API

Obsolete date-time type `Date` used
delegate.updateGroupMetaData(groupId, description, labels, modifiedBy, modifiedOn);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.apicurio.registry.storage.dto;

import java.util.Map;

import io.quarkus.runtime.annotations.RegisterForReflection;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

@NoArgsConstructor
@AllArgsConstructor
@Builder
@Getter
@Setter
@EqualsAndHashCode
@ToString
@RegisterForReflection
public class EditableGroupMetaDataDto {

private String description;
private Map<String, String> labels;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.Date;
import java.util.List;
import java.util.Map;

public abstract class AbstractReadOnlyRegistryStorage implements RegistryStorage {

Check warning on line 23 in app/src/main/java/io/apicurio/registry/storage/impl/gitops/AbstractReadOnlyRegistryStorage.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Overly coupled class

`AbstractReadOnlyRegistryStorage` is overly coupled (dependencies = 24)

Check warning on line 23 in app/src/main/java/io/apicurio/registry/storage/impl/gitops/AbstractReadOnlyRegistryStorage.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class with too many methods

`AbstractReadOnlyRegistryStorage` has too many methods (method count = 60)

Expand Down Expand Up @@ -187,7 +188,13 @@ public void createGroup(GroupMetaDataDto group) throws RegistryStorageException


@Override
public void updateGroupMetaData(GroupMetaDataDto group) throws RegistryStorageException {
public void updateGroupMetaData(String groupId, EditableGroupMetaDataDto dto) {
readOnlyViolation();
}

@Override
public void updateGroupMetaData(String groupId, String description, Map<String, String> labels,
String modifiedBy, Date modifiedOn) {
readOnlyViolation();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,24 @@ public void createGroup(GroupMetaDataDto group) {


@Override
public void updateGroupMetaData(GroupMetaDataDto group) {
UUID reqId = ConcurrentUtil.get(submitter.submitGroup(ActionType.UPDATE, group));
public void updateGroupMetaData(String groupId, EditableGroupMetaDataDto edto) {

Check warning on line 600 in app/src/main/java/io/apicurio/registry/storage/impl/kafkasql/KafkaSqlRegistryStorage.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Parameter name differs from parameter in overridden or overloaded method

Parameter name `edto` is different from parameter 'dto' in the super method
String modifiedBy = securityIdentity.getPrincipal().getName();
Date modifiedOn = new Date();

Check warning on line 602 in app/src/main/java/io/apicurio/registry/storage/impl/kafkasql/KafkaSqlRegistryStorage.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Use of obsolete date-time API

Obsolete date-time type `Date` used

updateGroupMetaData(groupId, edto.getDescription(), edto.getLabels(), modifiedBy, modifiedOn);
}

@Override
public void updateGroupMetaData(String groupId, String description, Map<String, String> labels,
String modifiedBy, Date modifiedOn) {
// Note: the next line will throw GroupNotFoundException if the group does not exist, so there is no need for an extra check.
GroupMetaDataDto dto = delegate.getGroupMetaData(groupId);
dto.setModifiedBy(modifiedBy);
dto.setModifiedOn(modifiedOn.getTime());
dto.setDescription(description);
dto.setLabels(labels);

UUID reqId = ConcurrentUtil.get(submitter.submitGroup(ActionType.UPDATE, dto));
coordinator.waitForResponse(reqId);
}

Expand Down
Loading

0 comments on commit 6606e19

Please sign in to comment.