Refactoring: completey typed metadata#2112
Conversation
|
I think your problem with the failing test couuld be due to the renaming of the DBMSSynchronizerTest.java |
lenhard
left a comment
There was a problem hiding this comment.
Overall this looks good :-) I would have expected us to take much much longer for arriving at a globals-free and gui-free meta data class.
Most of my remarks are just requests for clarification and I have a few suggestions for improvement.
| } | ||
| // Remember that we've handled this one: | ||
| handledOnDisk.add(key); | ||
| private void scanMetaData(MetaData inMemory, MetaData onTmp, MetaData onDisk) { |
There was a problem hiding this comment.
With your new implementation here, we lose information, don't we? Previously the actual key of different data made it into the change event, now we just get the information that the meta data as whole have changed. Am I right? And might this be a problem?
There was a problem hiding this comment.
Yes the detailed information about which key has changed is not contained in the event. Of course this information could be easily extracted from the two metadata by comparing each contained meta item separately. I didn't found this information too useful and thus just left a todo in the dialog https://github.com/JabRef/jabref/pull/2112/files#diff-423409b75a40e426ad5123cabbe295e6R33.
| /** | ||
| * | ||
| */ | ||
| class MetaDataChange extends Change { |
There was a problem hiding this comment.
See above. The changes displayed here depend of course on what is available. Why is the type of change no longer of interest?
| groupsRoot.addNewGroup(newGroup, panel.getUndoManager()); | ||
| panel.markBaseChanged(); | ||
| frame.output(Localization.lang("Created group \"%0\".", newGroup.getName())); | ||
| panel.getBibDatabaseContext().getMetaData().postChange(); |
There was a problem hiding this comment.
Why are all the change notifications in this class no longer needed?
There was a problem hiding this comment.
The metadata class now directly subscribes to changes in the group tree and relays these change events https://github.com/JabRef/jabref/pull/2112/files#diff-20cd356a80ee8ffb10c848005c89b949R74
| * Writes all data in the format <key, serialized data>. | ||
| */ | ||
| public static Map<String, String> getSerializedStringMap(MetaData metaData) { | ||
| public static Map<String, String> getSerializedStringMap(MetaData metaData, |
There was a problem hiding this comment.
How about refactoring this method a little bit? After all, it consists of various blocks, where different types of meta data contents are put into the final list. Each such block could be extract into a beautifully named private method :-)
There was a problem hiding this comment.
I like that one sees directly in one method all the metadata plus their key. Instead of moving everything to separate methods, I moved the main serialization to a different method so that the code now looks cleaner and is better to understand.
| @@ -0,0 +1,122 @@ | |||
| package net.sf.jabref.model.cleanup; | |||
There was a problem hiding this comment.
I have a suggestion regarding this new package: How about moving it into model.metadata? After all, the classes in the package are about how the cleanup information is stored in the meta data. What do you think?
There was a problem hiding this comment.
Mhhh.... none of the other metadata items are currently under the metadata namespace:
import net.sf.jabref.model.cleanup.FieldFormatterCleanups;
import net.sf.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern;
import net.sf.jabref.model.database.BibDatabaseMode;
import net.sf.jabref.model.groups.GroupTreeNode;
I think it is more consistent to have a model.cleanup or also move the rest to model.metadata(.groups/.bibtexkeypattern...)
There was a problem hiding this comment.
Ok, at some point we might think of structuring the model package a little more, but for now it is ok, I think.
| if (bibtexKeyPattern != null) { | ||
| return bibtexKeyPattern; | ||
| } | ||
| public AbstractBibtexKeyPattern getCiteKeyPattern(GlobalBibtexKeyPattern globalPattern) { |
There was a problem hiding this comment.
Since you are doing this for the other methods: Do a null check of globalPattern.
There was a problem hiding this comment.
Good observation :) Done.
| public Optional<BibDatabaseMode> getMode() { | ||
| List<String> data = getData(DATABASE_TYPE); | ||
| if ((data == null) || data.isEmpty()) { | ||
| return Optional.empty(); |
There was a problem hiding this comment.
Why is the Optional.empty no longer a desired return type here?
There was a problem hiding this comment.
If mode is null, then still an empty optional is returned (Optional.ofNullable(mode))
| public void markAsProtected() { | ||
| putData(PROTECTED_FLAG_META, Collections.singletonList("true")); | ||
| isProtected = true; | ||
| postChange(); |
There was a problem hiding this comment.
So the change notification I asked for earlier have been moved into the meta data. Am I right?
There was a problem hiding this comment.
Yes every setSomething method now has to post that the metadata changed. Previously this was done in the putData method.
| 1 KeywordGroup:DynamicGroup\;0\;author\;Churchill\;0\;0\;; | ||
| } | ||
|
|
||
| @Comment{jabref-meta: groupsversion:3;} |
There was a problem hiding this comment.
Is it ok to just remove that? Wouldn't it be better to have it in and verify that it is just ignored by the new parser?
There was a problem hiding this comment.
We have a test integrationTestGroupTree https://github.com/JabRef/jabref/pull/2112/files#diff-837597ff5fafbe4e71d5733d490e3454R1479 which still have the ̀groupsversion:3 string. But since we no longer write the the groupsversion information, the roundtrip tests for complex.bib fail. This is why I removed it.
|
Thanks for the review. I addressed all your remarks and hopefully the build now runs through without problems. |
|
Regarding the failing tests: When you log in to Travis-CI and check the build, you can access the raw log. |
|
There is also an error which seems to be related to your changes: |
* upstream/master: (102 commits) Removed unused test code (#2140) Fix main table bug when creating a duplicate (#2135) Remove explicit author and add SPDX-License-Identifier Remove GPL from README.md and CONTRIBUTING.md fix preview update (#2125) Remove some UnicodeToLatex uses (#2132) Fix mixup in french/farsi localization FetcherException should extend JabRefException Fix exception when opening preference dialog (#2127) Unify ParserException and ParseException (#2124) Small refactoring in Importer package (#2053) Implement Datepicker "none"-button (#2122) revert change from 816d30c Change title/tooltip of source panel in biblatex mode (#2120) Refactoring: completey typed metadata and add detailed travis output (#2112) RTFchars fix (#2097) Fix NPE in Medline fetcher on missing ISSN (#2113) Ctrl-s parsing error message (#2114) Fix bad web search error messages (#2034) parse error freeze (#2106) ... # Conflicts: # src/main/java/net/sf/jabref/collab/FileUpdateMonitor.java # src/main/java/net/sf/jabref/gui/externalfiles/DownloadExternalFile.java # src/main/java/net/sf/jabref/gui/externalfiles/DroppedFileHandler.java # src/main/java/net/sf/jabref/gui/externalfiles/MoveFileAction.java # src/main/java/net/sf/jabref/logic/cleanup/RenamePdfCleanup.java # src/main/java/net/sf/jabref/logic/exporter/FileSaveSession.java # src/main/java/net/sf/jabref/logic/util/io/FileUtil.java # src/main/java/net/sf/jabref/preferences/JabRefPreferences.java
|
@tobiasdiez Since this merge the synchronization of metadata for shared databases is totally broken. Could you please investigate why this happened? There is also a new issue #2219. |
|
@obraliar: Looking at the code, there have been changes in Lacking an actual database for testing, I cannot provide more help unfortunately. It seems that we need more tests for the database code, as travis did not find this problem. |
|
Sorry I have no db to test the sync (and no intellij at the moment either). I have to admit, I kind of trusted that our db-tests would catch possible problems. |
…abRef#2112) * Rewrite MetaData * Move some cleanup classes to model * Restoe test bib * Fix failing tests * Cleanup code in MetaDataSerializer * Add null check * Make database test compile again * Fix import order * Reorder metadata * Fix database tests * Show test results after failure * Fix path * Really fix path * Maybe now the path is correct * I mean now... * set permission for after-failure.sh * Comment out echo * Fix NPE exception due to Globals.prefs * Remove unused import

The metadata class is completely rewritten and now only uses typed fields instead of a map of serialized strings. Serialization and parsing now happens in the dedicated MetadataSerializer/parser classes.
For this also some of the cleanup classes had to be moved to the model package.
Final big refactoring PR from my side 😄
gradle localizationUpdate?