-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Uniqueness of PICA field ranges reported wrongly #247
- Loading branch information
Showing
9 changed files
with
271 additions
and
44 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
src/main/java/de/gwdg/metadataqa/marc/analysis/validator/RepetitionDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package de.gwdg.metadataqa.marc.analysis.validator; | ||
|
||
import de.gwdg.metadataqa.marc.definition.structure.DataFieldDefinition; | ||
|
||
import java.util.Objects; | ||
|
||
public class RepetitionDao { | ||
private String extendedTag; | ||
private DataFieldDefinition fieldDefinition; | ||
|
||
public RepetitionDao(String extendedTag, DataFieldDefinition fieldDefinition) { | ||
this.extendedTag = extendedTag; | ||
this.fieldDefinition = fieldDefinition; | ||
} | ||
|
||
public String getExtendedTag() { | ||
return extendedTag; | ||
} | ||
|
||
public DataFieldDefinition getFieldDefinition() { | ||
return fieldDefinition; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
RepetitionDao that = (RepetitionDao) o; | ||
|
||
if (!Objects.equals(extendedTag, that.extendedTag)) return false; | ||
return Objects.equals(fieldDefinition, that.fieldDefinition); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = extendedTag != null ? extendedTag.hashCode() : 0; | ||
result = 31 * result + (fieldDefinition != null ? fieldDefinition.hashCode() : 0); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/de/gwdg/metadataqa/marc/utils/pica/PicaDatafieldFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package de.gwdg.metadataqa.marc.utils.pica; | ||
|
||
import de.gwdg.metadataqa.marc.dao.DataField; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import java.io.File; | ||
import java.nio.file.Paths; | ||
|
||
public class PicaDatafieldFactory { | ||
private static PicaSchemaManager picaSchemaManager; | ||
|
||
private static void initialize() { | ||
initialize(null); | ||
} | ||
|
||
private static void initialize(String fileName) { | ||
if (picaSchemaManager == null) { | ||
String schemaFile = fileName != null && StringUtils.isNotEmpty(fileName) && new File(fileName).exists() | ||
? fileName | ||
: Paths.get("src/main/resources/pica/avram-k10plus.json").toAbsolutePath().toString(); | ||
picaSchemaManager = PicaSchemaReader.createSchema(schemaFile); | ||
} | ||
} | ||
|
||
public static DataField create(String tagWithOccurrence, String... subfields) { | ||
initialize(); | ||
DataField dataField = new DataField(picaSchemaManager.lookup(tagWithOccurrence), null, null, subfields); | ||
String[] parts = tagWithOccurrence.split("/"); | ||
if (parts.length == 2) | ||
dataField.setOccurrence(parts[1]); | ||
|
||
return dataField; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/test/java/de/gwdg/metadataqa/marc/analysis/validator/RepetitionDaoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package de.gwdg.metadataqa.marc.analysis.validator; | ||
|
||
import de.gwdg.metadataqa.marc.dao.DataField; | ||
import de.gwdg.metadataqa.marc.utils.pica.PicaDatafieldFactory; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class RepetitionDaoTest { | ||
|
||
@Test | ||
public void getExtendedTag() { | ||
DataField df = PicaDatafieldFactory.create("041A/01", "9", "104589787"); | ||
|
||
RepetitionDao dao = new RepetitionDao(df.getTagWithOccurrence(), df.getDefinition()); | ||
|
||
assertEquals("041A/01", dao.getExtendedTag()); | ||
} | ||
|
||
@Test | ||
public void getFieldDefinition() { | ||
DataField df = PicaDatafieldFactory.create("041A/01", "9", "104589787"); | ||
|
||
RepetitionDao dao = new RepetitionDao(df.getTagWithOccurrence(), df.getDefinition()); | ||
|
||
assertEquals("041A", dao.getFieldDefinition().getTag()); | ||
} | ||
|
||
@Test | ||
public void equals_no() { | ||
DataField df1 = PicaDatafieldFactory.create("041A/01", "9", "104589787"); | ||
RepetitionDao dao1 = new RepetitionDao(df1.getTagWithOccurrence(), df1.getDefinition()); | ||
|
||
DataField df2 = PicaDatafieldFactory.create("041A/02", "9", "104589787"); | ||
RepetitionDao dao2 = new RepetitionDao(df2.getTagWithOccurrence(), df2.getDefinition()); | ||
|
||
assertNotEquals(dao1, dao2); | ||
assertFalse(dao1.equals(dao2)); | ||
} | ||
|
||
@Test | ||
public void equals_yes() { | ||
DataField df1 = PicaDatafieldFactory.create("041A/01", "9", "104589787"); | ||
RepetitionDao dao1 = new RepetitionDao(df1.getTagWithOccurrence(), df1.getDefinition()); | ||
|
||
DataField df2 = PicaDatafieldFactory.create("041A/01", "8", "104589787"); | ||
RepetitionDao dao2 = new RepetitionDao(df2.getTagWithOccurrence(), df2.getDefinition()); | ||
|
||
assertEquals(dao1, dao2); | ||
assertTrue(dao1.equals(dao2)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.