MCR-3723 Modernize and harmonize PI generator configuration, add unit tests#2983
MCR-3723 Modernize and harmonize PI generator configuration, add unit tests#2983toKrause wants to merge 2 commits into
Conversation
4cc6f8c to
4bd4efb
Compare
24b239e to
c4102c8
Compare
d10df41 to
3a483ac
Compare
95b6a2b to
f0dbf41
Compare
f0dbf41 to
137843d
Compare
137843d to
9737839
Compare
53dcf09 to
06e4ed2
Compare
72cd1ae to
aa743cf
Compare
aa743cf to
62ba61f
Compare
|
@sebhofmann As requested, I moved the data-formatting-stuff into a separate PR: #3040 |
| @@ -300,7 +323,8 @@ private String applyCount(String resultingPI) { | |||
| LOGGER.info("Count is {}", count); | |||
| final String pattern = IntStream.range(0, Math.abs(countPrecision)).mapToObj((i) -> "0") | |||
There was a problem hiding this comment.
This method should use formatCount.
| } | ||
|
|
||
| @Override | ||
| protected String buildDOI(MCRBase base, String additional) { |
| * </code></pre> | ||
| */ | ||
| @MCRConfigurationProxy(proxyClass = MCRCreateDateDNBURNGenerator.Factory.class) | ||
| public class MCRCreateDateDNBURNGenerator extends MCRDNBURNGeneratorBase { |
There was a problem hiding this comment.
I don't think we need that. The MCRGenericPIGenerator can do that.
There was a problem hiding this comment.
Yes, simply added for symmetry, because MCRCreateDateDOIGenerator exists.
| @MCRConfigurationProxy(proxyClass = MCRCreateDateDOIGenerator.Factory.class) | ||
| public class MCRCreateDateDOIGenerator extends MCRDOIGeneratorBase { | ||
|
|
||
| public static final String DEFAULT_DATE_FORMAT = "yyyyMMdd-HHmmss"; |
There was a problem hiding this comment.
I think we should just deprecate that thing, because MCRGenericPIGenerator can do that.
There was a problem hiding this comment.
True, I will make this a small agenda item in today's web-call. Either
- keep
MCRCreateDateDOIGeneratorand addMCRCreateDateDNBURNGeneratoror - deprecate
MCRCreateDateDOIGeneratorand dropMCRCreateDateDNBURNGenerator
There was a problem hiding this comment.
Not true actually, MCRGenericPIGenerator only supports the current date, not the object creation date.
| * </code></pre> | ||
| */ | ||
| @MCRConfigurationProxy(proxyClass = MCRCurrentDateDOIGenerator.Factory.class) | ||
| public class MCRCurrentDateDOIGenerator extends MCRDOIGeneratorBase { |
There was a problem hiding this comment.
Is there really anyone using it?
There was a problem hiding this comment.
I don't know, simply added for symmetry, because MCRCurrentDateDNBURNGenerator (formally kown as MCRFLURNGenerator) exists.
| import org.mycore.pi.util.MCRFLDateScrambler; | ||
|
|
||
| /** | ||
| * {@link MCRCurrentDateDOIGenerator} is a {@link MCRPIGenerator} for {@link MCRDNBURN} identifiers |
| public static final String DEFAULT_DATE_FORMAT = "ddMMyyyy"; | ||
|
|
||
| static final String PLACE_HOLDER_OBJECT_TYPE = "$ObjectType"; | ||
| public static final Locale DFAULT_DATE_LOCALE = Locale.ROOT; |
d69d40e to
425a2e2
Compare
|
With regards to removing or deprecating specialized generators:
Therefore, I suggest the following course of action:
|
562da4f to
e0a5b53
Compare
e0a5b53 to
bbc567b
Compare
There was a problem hiding this comment.
Pull request overview
This PR modernizes and harmonizes the Persistent Identifier (PI) generator implementation and configuration style in mycore-pi, introducing new generator base classes and configuration-proxy factories, while expanding unit test coverage across URN/DOI/PURL generators.
Changes:
- Refactors PI generators to use constructor-based configuration via
@MCRConfigurationProxyfactories (and deprecates older generator types). - Adds new URN and DOI generators (UUID/current-date/create-date/“other PI” based variants) plus shared utility helpers.
- Reworks/extends unit tests to cover the new generator variants and updated configuration approach.
Reviewed changes
Copilot reviewed 45 out of 45 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| mycore-pi/src/test/java/org/mycore/pi/urn/rest/MCRURNGranularRESTServiceTest.java | Updates URN generator used in REST service test configuration. |
| mycore-pi/src/test/java/org/mycore/pi/urn/rest/MCRURNGranularRESTRegistrationTaskTest.java | Updates test utility usage and exception signature to align with new generator behavior. |
| mycore-pi/src/test/java/org/mycore/pi/urn/MCRUUIDDNBURNGeneratorTest.java | Adds unit tests for UUID-based DNB URN generation. |
| mycore-pi/src/test/java/org/mycore/pi/urn/MCROtherPIDNBURNGeneratorTest.java | Adds unit tests for URN generation based on extracting values from another PI. |
| mycore-pi/src/test/java/org/mycore/pi/urn/MCRDNBURNGeneratorTest.java | Removes legacy URN generator test. |
| mycore-pi/src/test/java/org/mycore/pi/urn/MCRCurrentDateDNBURNGeneratorTest.java | Adds unit tests for current-date-based DNB URN generation. |
| mycore-pi/src/test/java/org/mycore/pi/urn/MCRCreateDateDNBURNGeneratorTest.java | Adds unit tests for create-date + counter DNB URN generation. |
| mycore-pi/src/test/java/org/mycore/pi/purl/MCRIDPURLGeneratorTest.java | Updates PURL generator tests to use direct construction instead of configuration lookup. |
| mycore-pi/src/test/java/org/mycore/pi/MCRPIUtils.java | Updates test helpers to use the new UUID DNB URN generator and pass namespace explicitly. |
| mycore-pi/src/test/java/org/mycore/pi/MCRPIManagerTest.java | Adjusts test configuration (removes generator namespace/test property usage). |
| mycore-pi/src/test/java/org/mycore/pi/MCRMockIdentifierParser.java | Tightens parser generics to return the mock identifier type. |
| mycore-pi/src/test/java/org/mycore/pi/MCRMockIdentifierGenerator.java | Refactors mock generator to the new MCRPIGenerator interface style. |
| mycore-pi/src/test/java/org/mycore/pi/MCRGenericPIGeneratorTest.java | Reworks tests to match the new MCRGenericPIGenerator constructor/config inputs and adds multi-generate assertions. |
| mycore-pi/src/test/java/org/mycore/pi/doi/MCRUUIDDOIGeneratorTest.java | Adds unit tests for UUID-based DOI generation. |
| mycore-pi/src/test/java/org/mycore/pi/doi/MCROtherPIDOIGeneratorTest.java | Adds unit tests for DOI generation based on extracting values from another PI. |
| mycore-pi/src/test/java/org/mycore/pi/doi/MCRMapObjectIDDOIGeneratorTest.java | Refactors DOI mapping generator tests to constructor-based configuration and expands cases. |
| mycore-pi/src/test/java/org/mycore/pi/doi/MCRCurrentDateDOIGeneratorTest.java | Adds unit tests for current-date-based DOI generation. |
| mycore-pi/src/test/java/org/mycore/pi/doi/MCRCreateDateDOIGeneratorTest.java | Adds unit tests for create-date + counter DOI generation. |
| mycore-pi/src/main/resources/components/pi/config/mycore.properties | Adds a new configured generator entry (DateDOI). |
| mycore-pi/src/main/java/org/mycore/pi/util/MCRPIGeneratorUtils.java | Introduces shared utility functions for count handling and create-date retrieval. |
| mycore-pi/src/main/java/org/mycore/pi/util/MCROtherPIValueExtractor.java | Adds reusable value extraction logic for “other PI” generators. |
| mycore-pi/src/main/java/org/mycore/pi/util/MCRFLDateScrambler.java | Extracts FL date scrambling into a reusable utility. |
| mycore-pi/src/main/java/org/mycore/pi/urn/MCRUUIDURNGenerator.java | Deprecates legacy UUID URN generator in favor of the new UUID DNB URN generator (proxy-based). |
| mycore-pi/src/main/java/org/mycore/pi/urn/MCRUUIDDNBURNGenerator.java | Adds UUID-based DNB URN generator with configuration proxy. |
| mycore-pi/src/main/java/org/mycore/pi/urn/MCROtherPIDNBURNGenerator.java | Adds “other PI”-based DNB URN generator with configuration proxy. |
| mycore-pi/src/main/java/org/mycore/pi/urn/MCRFLURNGenerator.java | Deprecates legacy FL URN generator in favor of current-date DNB URN generator (proxy-based). |
| mycore-pi/src/main/java/org/mycore/pi/urn/MCRDNBURNGeneratorBase.java | Introduces a new base class for DNB URN generators with explicit namespace/delimiter handling. |
| mycore-pi/src/main/java/org/mycore/pi/urn/MCRDNBURNGenerator.java | Deprecates legacy base generator in favor of MCRDNBURNGeneratorBase. |
| mycore-pi/src/main/java/org/mycore/pi/urn/MCRCurrentDateDNBURNGenerator.java | Adds current-date DNB URN generator with proxy-based configuration. |
| mycore-pi/src/main/java/org/mycore/pi/urn/MCRCreateDateDNBURNGenerator.java | Adds create-date + counter DNB URN generator with proxy-based configuration. |
| mycore-pi/src/main/java/org/mycore/pi/urn/MCRCountingDNBURNGeneratorBase.java | Introduces new counting base class for DNB URN generators. |
| mycore-pi/src/main/java/org/mycore/pi/urn/MCRCountingDNBURNGenerator.java | Deprecates legacy counting base generator in favor of MCRCountingDNBURNGeneratorBase. |
| mycore-pi/src/main/java/org/mycore/pi/purl/MCRIDPURLGenerator.java | Refactors PURL generator to constructor-based config + proxy factory and adds validation. |
| mycore-pi/src/main/java/org/mycore/pi/MCRPIGenerator.java | Converts MCRPIGenerator from an abstract class to an interface. |
| mycore-pi/src/main/java/org/mycore/pi/MCRPICreationEventHandler.java | Changes PI auto-creation flow to iteratively register newly-creatable services. |
| mycore-pi/src/main/java/org/mycore/pi/MCRGenericPIGenerator.java | Refactors generic generator to constructor/proxy-based configuration, new mapping types, and shared count utilities. |
| mycore-pi/src/main/java/org/mycore/pi/doi/MCRUUIDDOIGenerator.java | Refactors UUID DOI generator to proxy-based configuration and a shared DOI base class. |
| mycore-pi/src/main/java/org/mycore/pi/doi/MCROtherPIDOIGenerator.java | Adds “other PI”-based DOI generator with proxy factory. |
| mycore-pi/src/main/java/org/mycore/pi/doi/MCRMapObjectIDDOIGenerator.java | Refactors map-based DOI generator to proxy-based configuration and shared base class. |
| mycore-pi/src/main/java/org/mycore/pi/doi/MCRDOIGeneratorBase.java | Introduces shared DOI generator base class. |
| mycore-pi/src/main/java/org/mycore/pi/doi/MCRCurrentDateDOIGenerator.java | Adds current-date DOI generator with proxy factory. |
| mycore-pi/src/main/java/org/mycore/pi/doi/MCRCreateDateDOIGenerator.java | Refactors create-date DOI generator to shared utilities and proxy-based configuration. |
| mycore-mods/src/main/java/org/mycore/mods/classification/mapping/MCRMODSXMappingClassificationGenerator.java | Minor documentation wording adjustments (“behavior”, formatting). |
| mycore-base/src/main/java/org/mycore/datamodel/classifications2/mapping/MCRXPathClassificationMappingCondition.java | Documentation wording adjustments (“XPath”). |
| mycore-base/src/main/java/org/mycore/datamodel/classifications2/mapping/MCRDefaultXMappingClassificationGenerator.java | Minor documentation wording adjustments (“behavior”, formatting). |
Comments suppressed due to low confidence (1)
mycore-pi/src/main/java/org/mycore/pi/doi/MCRDOIGeneratorBase.java:39
parser.parse(...).get()will throwNoSuchElementExceptionwhen a generated DOI does not passMCRDOIParservalidation (e.g. missing10.prefix or/). Convert this into anMCRPersistentIdentifierExceptionwith a useful message so callers get the expected checked exception type.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| String prefixWithDate = formatDate(getCreateDate(base)) + "-"; | ||
| int count = getCount(Pattern.quote(namespace + delimiter + prefixWithDate) + countPattern | ||
| + Pattern.quote(delimiter) + "[0-9]"); |
| final Date objectCreateDate = base.getService().getDate(MCRObjectService.DATE_TYPE_CREATEDATE); | ||
| if (objectCreateDate == null) { | ||
| throw new MCRPersistenceException("Object " + base.getId() + " doesn't have a create date!"); | ||
| } |
bbc567b to
7c1ee25
Compare
Link to jira.
Depends on #2982.
Pull Request Checklist (Author)
Please go through the following checklist before assigning the PR for review:
Ticket & Documentation
fixed-versionis correctly set in the ticket and matches the PR's target branch (main).Feature & Improvement Specific Checks
Testing
MCR Conventions & Metadata
mycore.properties.mycore.properties.Multi-Repo Considerations
MIRrequired?To be used in conjunction with MyCoRe-Org/mir#1390.