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

Pivotal ID # 184977702: Assign DOIs Automatically #736

Merged
merged 13 commits into from
Oct 12, 2023

Conversation

jhoanmanuelms
Copy link
Contributor

https://www.pivotaltracker.com/story/show/184977702

  • Validate the required DOI fields
  • Perform the request to register the DOI for the submission

- Validate the required DOI fields
- Perform the request to register the DOI for the submission
@jhoanmanuelms jhoanmanuelms self-assigned this Jul 28, 2023
@jhoanmanuelms jhoanmanuelms requested a review from Juan-EBI July 28, 2023 17:10
Avoid requesting already existing DOI records
- Calculate the DOI as part of the submission processing
- Add an attribute to the extended model in order to keep track of the DOIs
- Add logic to handle previous versions
- Fix serialization
- Add iTest
- Finish mapping
- Solve warnings
- Remove unused code
Copy link
Contributor

@Juan-EBI Juan-EBI left a comment

Choose a reason for hiding this comment

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

Looking great please check comments

private val properties: DoiProperties,
) {
fun calculateDoi(accNo: String, rqt: SubmitRequest): String? {
val doi = rqt.submission.attributes.find { it.name == DOI.name } ?: return null
Copy link
Contributor

Choose a reason for hiding this comment

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

you an use created doi extension bellow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The thing is the find method from the Attributable returns null either if the attribute is not present or the value itself is null and at this point, we are only concerned about the attribute presence

add(FILE_PARAM, FileSystemResource(requestFile))
}

webClient.post(properties.endpoint, RequestParams(headers, body))
Copy link
Contributor

Choose a reason for hiding this comment

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

I would recomend to use functions so it becomes

        val headers = httpHeadersOf(contentType to MULTIPART_FORM_DATA)
        val body = linkedMultiValueMapOf(
            USER_PARAM to properties.user,
            PASSWORD_PARAM to properties.password,
            OPERATION_PARAM to OPERATION_PARAM_VALUE,
            FILE_PARAM to FileSystemResource(requestFile)
        )  

Copy link
Contributor Author

@jhoanmanuelms jhoanmanuelms Sep 13, 2023

Choose a reason for hiding this comment

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

This is a great functionality but it's part of the bio-webclient module which is not used in the submitter module and I think it shouldn't be. Instead, I moved this method to commons-http which seems like the best place for this general functionality to be so it can be used in every module.

Copy link
Contributor

@Juan-EBI Juan-EBI left a comment

Choose a reason for hiding this comment

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

LGTM please consider comments

@ChangeLog
class ChangeLog010 {
@ChangeSet(order = "010", id = "DOI Field", author = "System")
fun changeSet010(template: MongockTemplate) {
Copy link
Contributor

Choose a reason for hiding this comment

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

looks like you need to sync this part with last merge

return request.doi
}

private fun getContributors(sub: Submission): List<Contributor> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please consider

    private fun getContributors(sub: Submission): List<Contributor> {
        val organizations = getOrganizations(sub).associateBy({ it.accNo }, { it.name })
        val contributors = sub.allSections().filter { it.type == AUTHOR_TYPE }
        return contributors
            .map { it.asContributor(organizations) }
            .ifEmpty { throw MissingDoiFieldException(AUTHOR_TYPE) }
    }

    private fun Section.asContributor(organizations: Map<String, String>): Contributor {
        val names = requireNotNull(find(NAME_ATTR)) { throw InvalidAuthorNameException() }
        val org = requireNotNull(find(AFFILIATION_ATTR)) { throw MissingAuthorAffiliationException() }
        val affiliation = requireNotNull(organizations[org]) { throw InvalidAuthorAffiliationException(names, org) }
        val (name, surname) = names.split("\\s".toRegex())
        return Contributor(
            name = name,
            surname = surname,
            affiliation = affiliation,
            orcid = find(ORCID_ATTR)
        )
    }

    private fun getOrganizations(sub: Submission): List<Organization> {
        return sub
            .allSections().filter { it.type == ORG_TYPE }
            .map { it.asOrganization() }
            .ifEmpty { throw MissingDoiFieldException(ORG_TYPE) }
    }

    private fun Section.asOrganization(): Organization {
        val accNo = requireNotNull(accNo) { throw InvalidOrgException() }
        val name = requireNotNull(find(NAME_ATTR)) { throw InvalidOrgNameException(accNo) }
        return Organization(accNo, name)
    }

@jhoanmanuelms jhoanmanuelms merged commit 473b5e8 into master Oct 12, 2023
@jhoanmanuelms jhoanmanuelms deleted the feature/pivotal-#184977702-assign-doi-on-submit branch October 12, 2023 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants