-
Notifications
You must be signed in to change notification settings - Fork 447
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
[PKP-LIB][main] #7505 Initial Commit Upload - Delete - Download JATS File #9536
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @defstat! A handful of comments, mostly minor. Looking very good!
/** | ||
* Function to get the Context's genres | ||
*/ | ||
public function getGenres(int $contextId) : Collection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think calling code should stick with the GenreDAO
until that's adapted to a newer storage pattern; getGenres
shouldn't be a method of this Repository class and it just spreads competing patterns through the codebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
*/ | ||
public function getDefaultJatsFileName(int $submissionId, int $publicationId): string | ||
{ | ||
return 'jats-' . $submissionId . '-' . $publicationId . '-' . (string) mt_rand(100000, 999999) . '.xml'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a download filename, right? Better to use a timestamp than a random number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed it to return 'jats-' . $submissionId . '-' . $publicationId . '-' . date('Ymd-His') . '.xml';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very close, @defstat, thanks! I just made a few rearrangement suggestions.
@@ -0,0 +1,221 @@ | |||
<?php | |||
/** | |||
* @file classes/jats/Repository.php |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ambivalent about the use of a repository class for this. Actually, almost everything here is closely tied to the handling code, and will only be called once from the PKPJatsController
-- so I'd be happy if it these functions were moved into PKPJatsController
and this controller was removed. Then classes/jats/JatsFile.php
could be moved into lib/pkp/classes/submissionFile
alongside the parent class, which makes more sense to me.
But if you're not sure that's the best approach, I'd be OK to merge this as is too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the relationship with the SubmissionFile
and the SubmissionFile/Repository
dropped for JatsFile
object, and that's why I took both files out of the SubmissionFile folder and in it's own jats
folder. This can be used as the "code home" for existing business logic and future possible merging of the code from, let's say, jatsTemplate
plugin for generating the "default" Jats content.
1e83f2d
to
3ba9171
Compare
api/v1/jats/PKPJatsController.php
Outdated
|
||
if ($actionName === 'add') { | ||
$params = $illuminateRequest->input(); | ||
$fileStage = isset($params['fileStage']) ? (int) $params['fileStage'] : 21; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File stage shouldn't be hard-coded (21
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to SubmissionFile::SUBMISSION_FILE_JATS
]), | ||
])->group(function () { | ||
|
||
Route::get('', $this->get(...)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably my ignorance about Laravel's routes, but should these routes actually be empty strings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right this parameter is reserved for the route declaration.
In our context the endpoint URL is constructed with the base endpoint Pattern that is defined here which takes into account this declaration.
Then the route defined in each Route::get('', $this->get(...))
is added after the base endpoint pattern.
All the endpoints for the specific Controller are api/submissions/{submissionId}/publications/{publicationId}/jats
, which is the "Base URL" defined here. So the respective Route::get('', $this->get(...))
don't need to declare some url other than ''
.
*/ | ||
public function getSubmissionFileContent(SubmissionFile $submissionFile): string | ||
{ | ||
$jatsFileName = Config::getVar('files', 'files_dir') . '/' . $submissionFile->getData('path') .''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change $jatsFileName
to just $fileName
, as this can be used for non-JATS files; also remove the empty string concatenation at the end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! Changed.
public function getSubmissionFileContent(SubmissionFile $submissionFile): string | ||
{ | ||
$jatsFileName = Config::getVar('files', 'files_dir') . '/' . $submissionFile->getData('path') .''; | ||
$fileContentString = file_get_contents($jatsFileName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Just return file_get_contents($fileName)
would be a little more concise, since you're here anyway!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed.
@asmecher Are we confident that we want to have dependency from pkp-lib to jats plugin? Is not that opportunity to actually include jats plugin as part of the core if core functionality is dependent on it? Update: now I actually see that jats is not even part of "included plugins".. And when I tried to check out branches 7505 branches for ojs, pkp and ui-library. I am getting following error, when loading workflow page for any submission:
|
@jardakotesovec I suppose that you don't have the I could perhaps catch any JATS creation error and display something different/special in that case - something like "Make sure the JatsTemplate plugin is installed" or something. |
@asmecher I added some code that returns custom exceptions in the case of
In those case the UI is changed and some error message is displayed instead of the JATS content (see bellow) Image 1 - Failure to create the Default JATS Content In this case the user can still upload a locally stored file if so chooses Image 2 - Failure to read the provided submission file In this case the user can still delete the submission file. |
js/load.js
Outdated
@@ -198,6 +201,9 @@ VueRegistry.registerComponent('field-pub-id', FieldPubId); | |||
// Register ListPanel | |||
VueRegistry.registerComponent('PkpListPanel', ListPanel); | |||
|
|||
// Register PublicationSectionJats | |||
VueRegistry.registerComponent('PkpPublicationJats', PublicationSectionJats); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets not register this component here. Here are only general components, so its possible to use them from plugins. Its perfectly sufficients that its 'components' field in workflow.vue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jardakotesovec if I don't register the component here, how can I use the
<pkp-publication-jats
v-bind="components.jats"
class="pkpWorkflow__jats"
@set="set"
:publication="workingPublication"
:publication-api-url="submissionApiUrl + '/publications/' + workingPublication.id"
></pkp-publication-jats>
in workflow.tpl
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I found it - I can put publication-section-jats
instead of pkp-publication-jats
because I have named the component PublicationSectionJats
in the WorkflowPage.vue
, and then remove the lines tagged from load.js
Fixed.
Thanks, @defstat, I'm OK with the use of custom exceptions in this code. (I'd like to brainstorm a little with the team before we go too wild creating custom exception classes, because they are really going to multiply if the pattern is used in general! But it's OK here.) |
…TS File (pkp#9536) * pkp#7505 Support for JATS files/content added * pkp#7505 Review Fixes * pkp#7505 Remove locale keys as vue component props * pkp#7505 Remove new Jats Component dependency from ListPanel * pkp#7505 Handle Jats creation Errors * pkp#7505 Fix UI in error cases * pkp#7505 Remove JATS Component from PKPWorkflow * pkp#7505 Review Changes
No description provided.