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

[PKP-LIB][main] #7505 Initial Commit Upload - Delete - Download JATS File #9536

Merged
merged 8 commits into from
Dec 18, 2023

Conversation

defstat
Copy link
Contributor

@defstat defstat commented Nov 24, 2023

No description provided.

Copy link
Member

@asmecher asmecher left a 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
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed.

api/v1/submissions/PKPSubmissionController.php Outdated Show resolved Hide resolved
classes/submissionFile/Repository.php Outdated Show resolved Hide resolved
classes/components/listPanels/JatsListPanel.php Outdated Show resolved Hide resolved
classes/db/DAOResultFactory.php Outdated Show resolved Hide resolved
*/
public function getDefaultJatsFileName(int $submissionId, int $publicationId): string
{
return 'jats-' . $submissionId . '-' . $publicationId . '-' . (string) mt_rand(100000, 999999) . '.xml';
Copy link
Member

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.

Copy link
Contributor Author

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';

api/v1/submissions/PKPSubmissionController.php Outdated Show resolved Hide resolved
classes/submissionFile/Repository.php Outdated Show resolved Hide resolved
classes/submissionFile/Repository.php Outdated Show resolved Hide resolved
classes/submissionFile/Repository.php Outdated Show resolved Hide resolved
Copy link
Member

@asmecher asmecher left a 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.

api/v1/jats/PKPJatsController.php Show resolved Hide resolved
classes/submissionFile/Repository.php Outdated Show resolved Hide resolved
@@ -0,0 +1,221 @@
<?php
/**
* @file classes/jats/Repository.php
Copy link
Member

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.

Copy link
Contributor Author

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.

@defstat defstat force-pushed the i7505 branch 2 times, most recently from 1e83f2d to 3ba9171 Compare December 6, 2023 20:18

if ($actionName === 'add') {
$params = $illuminateRequest->input();
$fileStage = isset($params['fileStage']) ? (int) $params['fileStage'] : 21;
Copy link
Member

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).

Copy link
Contributor Author

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(...))
Copy link
Member

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?

Copy link
Contributor Author

@defstat defstat Dec 7, 2023

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') .'';
Copy link
Member

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.

Copy link
Contributor Author

@defstat defstat Dec 7, 2023

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);
Copy link
Member

@asmecher asmecher Dec 7, 2023

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!)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed.

@jardakotesovec
Copy link
Contributor

jardakotesovec commented Dec 7, 2023

@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:

 Error: Class "APP\plugins\generic\jatsTemplate\classes\Article" not found in /Users/jarda/git/pkp/pkp-main/ojs-main/lib/pkp/classes/jats/Repository.php:199

@asmecher
Copy link
Member

asmecher commented Dec 7, 2023

@asmecher Are we confident that we want to have dependency from pkp-lib to jats plugin?

Yes, by the time this is released I think we'll have moved the JATS Template plugin into core.

I am getting following error, when loading workflow page for any submission...

@defstat, could you look at that?

@jardakotesovec
Copy link
Contributor

@asmecher @defstat Just to clarify. Cause of this problem is that I did not have JATS template plugin installed. Once I did clone that it works fine.. but it means that it would break workflow page for anyone who does not install JATS template plugin after merging.

@defstat
Copy link
Contributor Author

defstat commented Dec 7, 2023

I am getting following error, when loading workflow page for any submission:

@jardakotesovec I suppose that you don't have the jatsTemplate plugin in your installation.

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.

@defstat
Copy link
Contributor Author

defstat commented Dec 7, 2023

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

  1. Failure of creating the default JATS content
  2. Failure of reading the content of the provided Submission File.

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
image

In this case the user can still upload a locally stored file if so chooses

Image 2 - Failure to read the provided submission file
image

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);

Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor Author

@defstat defstat Dec 18, 2023

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.

@asmecher
Copy link
Member

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.)

@asmecher asmecher merged commit af8ad0f into pkp:main Dec 18, 2023
1 check passed
ipula pushed a commit to ipula/pkp-lib that referenced this pull request Jan 11, 2024
…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
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