MCR-3578 Changes modsperson attribute handling#2773
Conversation
mycore-base/src/main/java/org/mycore/datamodel/legalentity/MCRIdentifier.java
Show resolved
Hide resolved
| Set<MCRIdentifier> getAllIdentifiers(MCRIdentifier identifier); | ||
|
|
||
| /** | ||
| * Gets a legal entity's identifiers of a given type. The legal entity is determined by a specific identifier. | ||
| * @param primaryIdentifier unique identifier of legal entity, not null | ||
| * @param identifierType the type of looked up identifiers as a string, not null | ||
| * @return a set of identifiers a legal entity owns | ||
| */ | ||
| Set<MCRIdentifier> getTypedIdentifiers(MCRIdentifier primaryIdentifier, String identifierType); |
There was a problem hiding this comment.
Suggestion: I would not call the methods "get" but rather findAllIdentifiers / findAllIdentifiersByType or lookupAllIdentifiers / lookupAllIdentifiersByType...
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class MCRUser2MODSPersonIdentifierService implements MCRLegalEntityService { |
There was a problem hiding this comment.
I find the name confusing. Maybe just MCRMODSPersonIdentifierService?
| @@ -0,0 +1,20 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <mycoreobject xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="datamodel-modsperson.xsd" ID="junit_modsperson_00000001"> | |||
| <metadata> | |||
There was a problem hiding this comment.
Please use two spaces for indentation.
| @@ -0,0 +1,17 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <mycoreobject xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="datamodel-modsperson.xsd" ID="junit_modsperson_00000002"> | |||
| <metadata> | |||
There was a problem hiding this comment.
Please use two spaces for indentation.
| legalEntityService = MCRConfiguration2.getInstanceOfOrThrow( | ||
| MCRLegalEntityService.class, MCRORCIDConstants.CONFIG_PREFIX + "LegalEntityService.Class"); |
There was a problem hiding this comment.
Would it perhaps make more sense to have a centralized service? Something like a DefaultLegalEntityService where you can configure the default service? There are certainly other places where this service is needed.
There was a problem hiding this comment.
In the current implementation, each class makes its own decision which LegalEntityService to use through a configuration string. The MCROrcidUser uses the class configured in MCR.ORCID2.LegalEntityService.Class. Would you propose to have one centralized configuration for all classes that want to use a LegalEntityService? Or should all configurations be managed in that DefaultLegalEntityService? Or would that DefaultService be a fallback to a specific, configurable Service?
There was a problem hiding this comment.
However, this would prevent the "wrong" service from being called. In addition, the service is independent of the MCRORCIDUser and does not need to be loaded in the constructor every time. I would expect something like a DefaultLegalEntityService that manages the corresponding implementation.
| import org.mycore.orcid2.client.MCRORCIDCredential; | ||
| import org.mycore.orcid2.exception.MCRORCIDException; | ||
| import org.mycore.orcid2.util.MCRIdentifier; | ||
| import org.mycore.datamodel.legalentity.MCRIdentifier; |
| import org.mycore.orcid2.exception.MCRORCIDException; | ||
| import org.mycore.orcid2.oauth.MCRORCIDOAuthClient; | ||
| import org.mycore.orcid2.util.MCRIdentifier; | ||
| import org.mycore.datamodel.legalentity.MCRIdentifier; |
| @BeforeEach | ||
| public void prepare() throws NoSuchFieldException, IllegalAccessException { | ||
| userMock = new MCRUser("junit"); | ||
| MCRLegalEntityServiceMock legalEntityServiceMock = new MCRLegalEntityServiceMock(); |
There was a problem hiding this comment.
I'm pretty sure I tried that and failed, but will look into it again..
There was a problem hiding this comment.
Okay, I mocked the service using mockito.
| import org.mycore.orcid2.user.MCRORCIDUser; | ||
| import org.mycore.orcid2.user.MCRORCIDUserUtils; | ||
| import org.mycore.orcid2.util.MCRIdentifier; | ||
| import org.mycore.datamodel.legalentity.MCRIdentifier; |
mycore-mods/src/main/java/org/mycore/mods/MCRMODSPersonIdentifierService.java
Show resolved
Hide resolved
mycore-user2/src/main/java/org/mycore/user2/MCRUserIdentifierService.java
Show resolved
Hide resolved
|
@golsch should be ready for review again. Should I add the PR checklist to this PR? |
| } | ||
| MCRMODSWrapper wrapper = new MCRMODSWrapper(modspersonOptional.get()); | ||
| Element modsName = wrapper.getMODS().getChild(MODS_NAME, MCRConstants.MODS_NAMESPACE); | ||
| if (modsName == null) { |
| return user.getAttributes().stream() | ||
| .filter(a -> Objects.equals(a.getName(), ATTR_ORCID_ID)) | ||
| .map(MCRUserAttribute::getValue).collect(Collectors.toSet()); | ||
| final MCRIdentifier userid = new MCRIdentifier("userid", user.getUserID()); |
There was a problem hiding this comment.
Could userid somehow be moved to a global constant? It seems like it is the magic reference, right?
| import org.mycore.orcid2.client.MCRORCIDCredential; | ||
| import org.mycore.orcid2.metadata.MCRORCIDPutCodeInfo; | ||
| import org.mycore.orcid2.util.MCRIdentifier; | ||
| import org.mycore.datamodel.legalentity.MCRIdentifier; |
| import org.mycore.orcid2.metadata.MCRORCIDPutCodeInfo; | ||
| import org.mycore.orcid2.metadata.MCRORCIDUserInfo; | ||
| import org.mycore.orcid2.util.MCRIdentifier; | ||
| import org.mycore.datamodel.legalentity.MCRIdentifier; |
| import org.mycore.orcid2.exception.MCRORCIDTransformationException; | ||
| import org.mycore.orcid2.metadata.MCRORCIDPutCodeInfo; | ||
| import org.mycore.orcid2.util.MCRIdentifier; | ||
| import org.mycore.datamodel.legalentity.MCRIdentifier; |
| if (LOGGER.isWarnEnabled()) { | ||
| LOGGER.warn("Could not update modsperson object for user id {}", | ||
| userId.getValue(), e); | ||
| } |
There was a problem hiding this comment.
That would be an inconsistent state or a general error. In that case, I would rather expect an exception.
| * @return all known identifiers or an empty set | ||
| */ | ||
| @Override | ||
| public Set<MCRIdentifier> findAllIdentifiers(MCRIdentifier userId) { |
There was a problem hiding this comment.
see comment for MCRLegalEntityService#findAllIdentifiers
| * @param attributeToAdd the nameIdentifier to add to the modsperson | ||
| */ | ||
| @Override | ||
| public void addIdentifier(MCRIdentifier userId, MCRIdentifier attributeToAdd) { |
There was a problem hiding this comment.
see comment for MCRLegalEntityService#addIdentifier
| * @param userId the user id | ||
| * @return a nullable Optional that might contain a user | ||
| */ | ||
| private Optional<MCRUser> findUserByUserID(MCRIdentifier userId) { |
There was a problem hiding this comment.
see comments for MCRLegalEntityService.
| # LegalEntityService | ||
| ############################################################################## | ||
| # No-op Implementation of MCRLegalEntityService for querying UserIdentifier | ||
| MCR.LegalEntityService.Class=org.mycore.datamodel.legalentity.MCRNoOpLegalEntityService |
There was a problem hiding this comment.
Wouldn’t it be better to just leave it empty? It doesn’t seem to serve any purpose…
Link to jira.
This PR: #2733, but renamed branch and Jira Ticket