Skip to content
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

Rewrite mods exporter and add test for it #1989

Merged
merged 9 commits into from
Sep 27, 2016

Conversation

tschechlovdev
Copy link
Contributor

@tschechlovdev tschechlovdev commented Sep 15, 2016

Regarding: #1920
Rewrite the MODS exporter with a JAXB parser.
Details on the format and the newest xml schema can be found here.
I've used the newest schema (version 3.6).
This PR uses the same gradle script and schema as in #1942 .

  • internal QS
  • Tests created for changes
  • Manually tested changed features in running JabRef

for (Map.Entry<String, String> entry : fieldMap.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (FieldName.AUTHOR.equals(key)) {
Copy link
Member

Choose a reason for hiding this comment

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

Please split the author handling code in a new method

Copy link
Member

Choose a reason for hiding this comment

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

Maybe, even net.sf.jabref.model.entry.AuthorList#parse can be directly used?

}
}
mods.getModsGroup().add(name);
} else if ("affiliation".equals(key)) {
Copy link
Member

Choose a reason for hiding this comment

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

I think here a switch statement could be useful

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.


@Override
public String getPreferredPrefix(String namespaceUri, String suggestion, boolean requirePrefix) {
if ("http://www.loc.gov/mods/v3".equals(namespaceUri)) {
Copy link
Member

Choose a reason for hiding this comment

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

Pleas consider extracting those as String constants, so in case of change they could be easily changed..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

//formate the output
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
"http://www.loc.gov/standards/mods/v3/mods-3-6.xsd");
Copy link
Member

Choose a reason for hiding this comment

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

same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@tschechlovdev
Copy link
Contributor Author

For some reason codecov doesn't run the class ModsExportFormatTestFiles like in #1942 ...

@Siedlerchr
Copy link
Member

@tschechlovdev Codecov seems to work again: codecov/project — 28.28% (+0.42%) compared to a8e1488

@koppor
Copy link
Member

koppor commented Sep 21, 2016

Please work on coverage - or is the coverage indication wrong?

grabbed_20160921-091358

@tschechlovdev
Copy link
Contributor Author

tschechlovdev commented Sep 21, 2016

No, I have two test classes. ModsExportFormatTest and ModsExportFormatTestFiles. The coverage comes from ModsExportFormatTest, but ModsExportFormatTestFiles doesn't seem to be executed.

I tried to rename ModsExportFormatTestFiles to ModsExportFormatFilesTest, because I had the intention that it is because the class didn't end with test. Though that also doesn't seem to work.

Copy link
Contributor

@boceckts boceckts left a comment

Choose a reason for hiding this comment

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

Some work is still required. I would first fix the test files and once your tests are failing rework the appropriate methods.
In my opinionen it would also be a good idea to create a test to see if an mods exported xml file can be imported by the mods importer and if it produces the same bib entry.


switch (key) {

case FieldName.AUTHOR:
Copy link
Contributor

Choose a reason for hiding this comment

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

Indent the cases please.

case FieldName.JOURNAL:
addJournal(value, relatedItem);
break;
default:
Copy link
Contributor

Choose a reason for hiding this comment

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

default case is unnecessary here.

Copy link
Member

Choose a reason for hiding this comment

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

No! Codecov will complain about a case with no default. There always shoold be a default in a switch case

JAXBElement<ModsCollectionDefinition> jaxbElement = new JAXBElement<>(new QName("modsCollection"),
ModsCollectionDefinition.class, modsCollection);


Copy link
Contributor

Choose a reason for hiding this comment

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

Why are there so many empty lines here, please use max one empty line to separate different code elements to groups.

}
};

//formate the output
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo "format"

if (MODS_NAMESPACE_URI.equals(namespaceUri)) {
return "mods";
}
return "";
Copy link
Contributor

@boceckts boceckts Sep 21, 2016

Choose a reason for hiding this comment

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

Rplace with return MODS_NAMESPACE_URI.equals(namespaceUri) ? "mods" : "";

@@ -0,0 +1,6 @@
@Book{
isbn = {123456789},
issn = {123456789},
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use different numbers for isbn and issn.

pmid = {123456789},
created = {2000-10-10},
modified = {2000-10-10},
captured = {2000-10-10},
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use different dates.

<mods:genre>book</mods:genre>
<mods:identifier type="issn">123456789</mods:identifier>
<mods:subject>
<topic>note; and another note;</topic>
Copy link
Contributor

@boceckts boceckts Sep 21, 2016

Choose a reason for hiding this comment

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

I think the keywords should be separated and a new topic node should be created for each one instead of writing them in one node. Same as for the ModsExportFormatTestAllFields.xml.

pages = {1234},
author = {Mustermann},
isbn = {123456789},
issn = {12345678},
Copy link
Contributor

Choose a reason for hiding this comment

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

Use different test numbers for isbn and issn here, too.

<namePart type="given"></namePart>
<namePart type="given">know</namePart>
<namePart type="family">Realy</namePart>
<namePart type="given"></namePart>
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are there empty given name fields?

@Siedlerchr
Copy link
Member

Regarding the test coverage. I have no idea, but maybe it is related to the fact that it's a parameterized test?

int minusIndex = value.indexOf(minus);
String startPage = value.substring(0, minusIndex);
String endPage = "";
if ("-".equals(minus)) {
Copy link
Member

Choose a reason for hiding this comment

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

Could you please extrac thte Singe "-" and the double "--" to constants?

@boceckts
Copy link
Contributor

boceckts commented Sep 22, 2016

Regarding the not executed tests #2017 (comment).

@boceckts boceckts added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Sep 22, 2016
@boceckts boceckts changed the title [WIP] Rewrite mods exporter and add test for it Rewrite mods exporter and add test for it Sep 22, 2016
}
} else {
//no "," indicates that there should only be a family name
namePart.setAtType("family");
Copy link
Member

Choose a reason for hiding this comment

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

Why no test coverage?


private void addIdentifier(String key, String value, ModsDefinition mods) {
if ("citekey".equals(key)) {
mods.setID(value);
Copy link
Member

Choose a reason for hiding this comment

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

Why no test coverage?

if ("-".equals(minus)) {
endPage = value.substring(minusIndex + 1);
} else if ("--".equals(minus)) {
endPage = value.substring(minusIndex + 2);
Copy link
Member

Choose a reason for hiding this comment

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

Why no test coverage?

@koppor
Copy link
Member

koppor commented Sep 22, 2016

Please increase test coverage.

I did not see a roundtrip test: bibtex -> mods -> bibtex and mods -> bibtex -> mods. Is that possible?

@tschechlovdev
Copy link
Contributor Author

@koppor Regarding test coverage: It's still the same problem that the parameterized test are not run by codecov. I will take care of this in a separate PR.
Regarding the roundtrip test: I will add one.

@tobiasdiez
Copy link
Member

I remove the "ready-for-review" for the moment until the comments are addressed. Please add it again afterwards. Thanks.

@tobiasdiez tobiasdiez removed the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Sep 23, 2016
# Conflicts:
#	src/main/java/net/sf/jabref/logic/mods/MODSEntry.java
#	src/main/java/net/sf/jabref/logic/msbib/MSBibEntry.java
@tschechlovdev tschechlovdev added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Sep 27, 2016
@Siedlerchr
Copy link
Member

Good! I merge in!

@Siedlerchr Siedlerchr merged commit 4236e3f into JabRef:master Sep 27, 2016
@obraliar
Copy link
Contributor

obraliar commented Sep 27, 2016

I'm getting the following error:

:compileJava
/home/admir/tmp/jabref/src/main/java/net/sf/jabref/logic/exporter/ModsExportFormat.java:60:
error: incompatible types: Character cannot be converted to String
            .getKeywordSeparator();

OS data:

Distributor ID: Debian
Description:    Debian GNU/Linux 8.5 (jessie)
Release:        8.5
Codename:       jessie

@Siedlerchr
Copy link
Member

I'll take a quick look

@Siedlerchr
Copy link
Member

@obraliar Works fine. Did you run ./gradlew eclipse (or build whatever youride is) ?
And also ./gradlew check executes fine. No related error.

@obraliar
Copy link
Contributor

@Siedlerchr What OS are you using?
./gradlew assemble and also ./gradlew check fails with the same error. I cloned jabref into another directory to annul all factors. Unfortunately, it doesen't work. It works when resetting to the commit before.

@Siedlerchr
Copy link
Member

@obraliar Now it get the same. Seems like my local repo was not update to date. I will revert that commit here. Problem is the internal class stuff. @tschechlovdev Sorry, but you have to fix this

@Siedlerchr
Copy link
Member

@obraliar I just reverted the commit. Follow up discussion in #2078

mairdl pushed a commit to mairdl/jabref that referenced this pull request Sep 28, 2016
* rewrite mods exporter and add test for it

* some code refactorings and editing the test

* add test case

* delete old mods helper classes and move other used classes

* rename testfiles test class

* address comments

* address comments
zesaro pushed a commit to zesaro/jabref that referenced this pull request Nov 22, 2016
* rewrite mods exporter and add test for it

* some code refactorings and editing the test

* add test case

* delete old mods helper classes and move other used classes

* rename testfiles test class

* address comments

* address comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants