Skip to content

Fix editing schema #672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- Prevent duplicate workflow runs by @dennisvang in #628
- Clean up Dockerfile by @dennisvang in #626
- Fix index API by @dennisvang in #637 (backward incompatible)
- Fix saving metadata schema (draft and publish) by @MarekSuchanek in #XXX

## [1.17.2]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public class ExceptionControllerAdvice {
)
)
public ErrorDTO handleConstraintViolation(Exception exception) {
exception.printStackTrace();
log.warn(exception.getMessage());
log.debug("Handling bad request (ConstraintViolation)", exception);
return new ErrorDTO(HttpStatus.BAD_REQUEST, exception.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public MetadataSchemaDraftDTO toDraftDTO(
MetadataSchemaVersion draft
) {
return MetadataSchemaDraftDTO.builder()
.uuid(draft.getUuid())
.uuid(draft.getSchema().getUuid())
.name(draft.getName())
.description(draft.getDescription())
.abstractSchema(draft.isAbstractSchema())
Expand Down Expand Up @@ -231,6 +231,10 @@ public MetadataSchemaVersion toDraft(MetadataSchemaVersion schema) {
.definition(schema.getDefinition())
.suggestedResourceName(schema.getSuggestedResourceName())
.suggestedUrlPrefix(schema.getSuggestedUrlPrefix())
.schema(schema.getSchema())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to use schema.toBuilder() instead of MetadataSchemaVersion.builder()?
Or is there a specific reason not to?

For example:

        return schema.toBuilder()
                .published(false)  // assuming this needs to be false for a draft
                .state(MetadataSchemaState.DRAFT)
                .type(MetadataSchemaType.CUSTOM)
                .createdAt(Instant.now())  // not sure if these should be new timestamps or copies
                .updatedAt(Instant.now())
                .build();

Copy link
Contributor

@dennisvang dennisvang Apr 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the same question applies to many of the other methods in MetadataSchemaMapper.
If most of the properties of an input argument are retained for a DTO method, I think it would make sense to signal this intent by the choice of builder method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is true... should it be done as part of this PR?

Copy link
Contributor

@dennisvang dennisvang May 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it be done as part of this PR?

Yes, I think it would make sense to include this change to the toDraft() method as part of this PR.

It fixes the issue and makes the method more consistent with similar methods like fromReleaseDTO and fromRemoteVersion.

.state(MetadataSchemaState.DRAFT)
.type(MetadataSchemaType.CUSTOM)
.version(schema.getVersion())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ public Optional<MetadataSchemaDTO> releaseDraft(UUID uuid, MetadataSchemaRelease
if (reqDto.isPublished()) {
final List<MetadataSchemaVersion> parents = resolveExtends(newLatest);
if (!parents.stream().allMatch(MetadataSchemaVersion::isPublished)) {
System.out.println("aaaa");
throw new ValidationException(MSG_ERROR_PARENTS_PUBLISH);
}
}
Expand Down Expand Up @@ -237,6 +238,7 @@ public Optional<MetadataSchemaVersionDTO> updateVersion(
if (!schema.isPublished() && reqDto.isPublished()) {
final List<MetadataSchemaVersion> parents = resolveExtends(schema);
if (!parents.stream().allMatch(MetadataSchemaVersion::isPublished)) {
System.out.println("bbbb");
throw new ValidationException(MSG_ERROR_PARENTS_PUBLISH);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static void compare(MetadataSchemaVersion entity, MetadataSchemaVersionDT
}

public static void compare(MetadataSchemaVersion entity, MetadataSchemaDraftDTO dto) {
assertThat(dto.getUuid(), is(equalTo(entity.getUuid())));
assertThat(dto.getUuid(), is(equalTo(entity.getSchema().getUuid())));
assertThat(dto.getName(), is(equalTo(entity.getName())));
assertThat(dto.getDefinition(), is(equalTo(entity.getDefinition())));
}
Expand Down