-
Notifications
You must be signed in to change notification settings - Fork 39
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
base: develop
Are you sure you want to change the base?
Fix editing schema #672
Conversation
0383793
to
24e0476
Compare
24e0476
to
0a17246
Compare
src/main/java/org/fairdatapoint/service/schema/MetadataSchemaService.java
Outdated
Show resolved
Hide resolved
src/main/java/org/fairdatapoint/api/controller/exception/ExceptionControllerAdvice.java
Outdated
Show resolved
Hide resolved
src/main/java/org/fairdatapoint/service/schema/MetadataSchemaMapper.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @MarekSuchanek , this looks good too.
However, it would be very helpful if you could clarify some choices.
See review comments above&below.
@@ -231,6 +231,10 @@ public MetadataSchemaVersion toDraft(MetadataSchemaVersion schema) { | |||
.definition(schema.getDefinition()) | |||
.suggestedResourceName(schema.getSuggestedResourceName()) | |||
.suggestedUrlPrefix(schema.getSuggestedUrlPrefix()) | |||
.schema(schema.getSchema()) |
There was a problem hiding this comment.
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();
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
.
@MarekSuchanek should we add a test, as in temp/test-for-issue-660? |
Simply copy-paste the test? Don't you want to merge that to this branch then? |
@MarekSuchanek Yes, the idea was to "merge" the test into this branch first. |
Accidentally approved when I wanted to request changes as discussed in
#672 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @MarekSuchanek,
If you agree, could you
- implement and/or check the suggested change for toDraftDTO (Fix editing schema #672 (comment))
- check if my test makes any sense?
Thanks in advance. :)
Test looks OK, basic test to check the change. As for |
Thanks @MarekSuchanek , that's sounds reasonable. I'll look into it a bit more.. Do you think And what should happen with (Actually I'm not even sure what those are... Probably SHACL |
Just for reference (from lombok docs):
and
|
Also for reference: The input and output types of Here's the diff from - public MetadataSchemaDraft toDraft(MetadataSchema schema) {
- return MetadataSchemaDraft.builder()
+ public MetadataSchemaVersion toDraft(MetadataSchemaVersion schema) {
+ return MetadataSchemaVersion.builder()
.uuid(schema.getUuid())
.name(schema.getName())
- .name(schema.getName())
.description(schema.getDescription())
.abstractSchema(schema.isAbstractSchema())
.definition(schema.getDefinition())
- .extendSchemas(schema.getExtendSchemas())
.suggestedResourceName(schema.getSuggestedResourceName())
.suggestedUrlPrefix(schema.getSuggestedUrlPrefix())
.build();
}
In v1.17.2 a Click to see detailed diffdiff --git a/src/main/java/nl/dtls/fairdatapoint/entity/schema/MetadataSchema.java b/src/main/java/org/fairdatapoint/entity/schema/MetadataSchema.java
index f1c40354..997232b3 100644
--- a/src/main/java/nl/dtls/fairdatapoint/entity/schema/MetadataSchema.java
+++ b/src/main/java/org/fairdatapoint/entity/schema/MetadataSchema.java
@@ -1,6 +1,6 @@
/**
* The MIT License
- * Copyright © 2017 DTL
+ * Copyright © 2016-2024 FAIR Data Team
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -20,128 +20,39 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-package nl.dtls.fairdatapoint.entity.schema;
+package org.fairdatapoint.entity.schema;
-import jakarta.validation.constraints.NotBlank;
-import jakarta.validation.constraints.NotNull;
-import lombok.*;
-import org.bson.types.ObjectId;
-import org.springframework.data.annotation.Id;
-import org.springframework.data.annotation.PersistenceConstructor;
-import org.springframework.data.annotation.Transient;
-import org.springframework.data.mongodb.core.index.Indexed;
-import org.springframework.data.mongodb.core.mapping.Document;
+import jakarta.persistence.*;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import lombok.experimental.SuperBuilder;
+import org.fairdatapoint.entity.base.BaseEntityCustomUUID;
+import org.fairdatapoint.entity.resource.MetadataSchemaUsage;
-import java.time.Instant;
-import java.util.ArrayList;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
-@Document
+@Entity(name = "MetadataSchema")
+@Table(name = "metadata_schema")
@Getter
@Setter
+@NoArgsConstructor
@AllArgsConstructor
-@Builder(toBuilder = true)
-public class MetadataSchema {
-
- @Id
- private ObjectId id;
-
- @Indexed
- private String uuid;
-
- @Indexed
- private String versionUuid;
-
- @Indexed
- private String versionString;
-
- @NotNull
- @Transient
- private SemVer version;
-
- @NotNull
- @NotBlank
- private String name;
-
- @NotNull
- private String description;
-
- @NotNull
- private String definition;
-
- @NotNull
- private Set<String> targetClasses = new HashSet<>();
-
- @NotNull
- private List<String> extendSchemas = new ArrayList<>();
-
- @NotNull
- private MetadataSchemaType type;
-
- private String origin;
-
- private String importedFrom;
-
- private boolean latest;
-
- private boolean published;
-
- private boolean abstractSchema;
-
- private String suggestedResourceName;
-
- private String suggestedUrlPrefix;
-
- private Instant createdAt;
-
- private String previousVersionUuid;
-
- @PersistenceConstructor
- public MetadataSchema(
- ObjectId id, String uuid, String versionUuid, String versionString,
- String name, String description, String definition, Set<String> targetClasses,
- List<String> extendSchemas, MetadataSchemaType type, String origin,
- String importedFrom, boolean latest, boolean published, boolean abstractSchema,
- String suggestedResourceName, String suggestedUrlPrefix, Instant createdAt,
- String previousVersionUuid
- ) {
- this.id = id;
- this.uuid = uuid;
- this.versionUuid = versionUuid;
- this.versionString = versionString;
- this.name = name;
- this.description = description;
- this.definition = definition;
- this.targetClasses = targetClasses;
- this.extendSchemas = extendSchemas;
- this.type = type;
- this.origin = origin;
- this.importedFrom = importedFrom;
- this.latest = latest;
- this.published = published;
- this.abstractSchema = abstractSchema;
- this.suggestedResourceName = suggestedResourceName;
- this.suggestedUrlPrefix = suggestedUrlPrefix;
- this.createdAt = createdAt;
- this.previousVersionUuid = previousVersionUuid;
- }
-
- public void setVersionString(String versionString) {
- this.versionString = versionString;
- this.version = new SemVer(versionString);
- }
-
- public void setVersion(SemVer version) {
- this.version = version;
- this.versionString = version.toString();
- }
-
- public SemVer getVersion() {
- if (this.version == null) {
- this.version = new SemVer(this.versionString);
- }
- return version;
- }
+@SuperBuilder
+public class MetadataSchema extends BaseEntityCustomUUID {
+
+ @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL,
+ orphanRemoval = true, mappedBy = "schema")
+ private List<MetadataSchemaVersion> versions;
+
+ @OrderBy("orderPriority")
+ @OneToMany(mappedBy = "extendedMetadataSchema", cascade = CascadeType.ALL,
+ orphanRemoval = true, fetch = FetchType.LAZY)
+ private List<MetadataSchemaExtension> extensions;
+
+ @OrderBy("orderPriority")
+ @OneToMany(mappedBy = "usedMetadataSchema", cascade = CascadeType.ALL,
+ orphanRemoval = true, fetch = FetchType.LAZY)
+ private List<MetadataSchemaUsage> usages;
}
|
Also for reference: Here's a simplified overview of changes to some of the schema entities from v1.17.2 to current develop, showing the data type of fields present in each entity.
This shows that many fields have been moved, some have been removed, and some have been added. In addition, some field data types have changed. Note that reverse relations are excluded from the table (i.e. relational fields that have Note that, for example, |
To answer my own question: These need not be touched. The FAIRDataPoint/src/main/java/org/fairdatapoint/service/schema/MetadataSchemaService.java Line 141 in 8fb6443
FAIRDataPoint/src/main/java/org/fairdatapoint/service/schema/MetadataSchemaMapper.java Lines 66 to 70 in 8fb6443
|
So what is |
closes #660
to be squash-merged