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

Internationalization - Application Terms of Use #6042

Merged
merged 8 commits into from
Sep 11, 2019

Conversation

JayanthyChengan
Copy link
Contributor

@coveralls
Copy link

coveralls commented Jul 19, 2019

Coverage Status

Coverage decreased (-0.02%) to 19.472% when pulling 9355402 on JayanthyChengan:5303_TermsofUse into 886da9e on IQSS:develop.

@scolapasta
Copy link
Contributor

@JayanthyChengan overall this looks good.

I think we should not have EN for lang for all settings, especially since not all settings are user text, so blank lang, which is default, but then you can add language specific ones if you need. So the logic should be if you don't provide a lang, it returns the default (and most settings would do that); if you do provide a language it looks for that language, but if not available returns the default.

@JayanthyChengan
Copy link
Contributor Author

@scolapasta - Thanks for your review. I would like to add some notes of what I tried.
As a first step, I added new column “lang” and when a new row is added(:ApplicationTermsOfUse , "french content" , "fr" ) , it throws the below exception,

INSERT INTO setting (name, content, lang)
VALUES
(:ApplicationTermsOfUse , "french content" , "fr" );

org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "setting_pkey"

So, I added “lang” to the primary key (name,lang), and updated to default value “en” as primary key cannot be NULL

https://github.com/IQSS/dataverse/blob/b9bed069c01a5587cc1a75c551ff4352dd9fc755/scripts/database/upgrades/upgrade_v4.15.1_to.sql

setting_pkey PRIMARY KEY (name,lang)

Please add your suggestion.

@dataversebot
Copy link

Can one of the admins verify this patch?

@scolapasta
Copy link
Contributor

scolapasta commented Aug 26, 2019

Hi @JayanthyChengan OK, I had to do some research, but I have a proposed solution. First, let's add a PK to this table that has no semantic meaning (i.e. just an id). Then we can add unique constraint for name,lang. The issue is that unique constraints don't generally work will null, i.e if you had two rows of ':ApplicationTermsOfUse',null, it would not be treated as unique and we'd have issues.

However, I found a (series of) clever solution(s): using coalesce and/or multiple indices. In our case it should be doable with one:

CREATE UNIQUE INDEX unique_settings
    ON setting
       (name, coalesce(lang, ''));

(coalesce returns the first not-null value, so if null, will return ''. We can do this because that would never be a legitimate value for lang - if it wasn't we could use multiple indices).

While we're at it it probably makes sense to add a constraints to make sure lang is never '':

ALTER TABLE setting
   ADD CONSTRAINT non_empty_lang
            CHECK (lang <>'');

Let me know if this makes sense or you'd like some more details. (here is the link to where I discoverd this idea: https://matjaz.it/tutorial-unique-constraint-on-null-values-in-postgresql/)

@JayanthyChengan
Copy link
Contributor Author

Thanks @scolapasta , I will give it a try.

@JayanthyChengan
Copy link
Contributor Author

@scolapasta - Thanks Gustavo and I implemented the suggested solution using coalesce, it worked. Committed the code, please review. Thanks

@@ -2383,6 +2383,7 @@ staticSearchFields.dvObjectType=Type
staticSearchFields.fileTag=File Tag
staticSearchFields.fileAccess=Access
staticSearchFields.publicationStatus=Publication Status
staticSearchFields.subject_ss=Subject
Copy link
Contributor

Choose a reason for hiding this comment

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

@JayanthyChengan is this supposed to be part of this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@scolapasta - Missing term related to facet Internationalization. hope it's okay to add with this PR.

@@ -0,0 +1,13 @@
ALTER TABLE ONLY setting DROP CONSTRAINT setting_pkey ;

ALTER TABLE setting ADD COLUMN ID SERIAL PRIMARY KEY;
Copy link
Contributor

Choose a reason for hiding this comment

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

does this add values for the id for existing settings? (it must, right?)

Also, can you update the file name to reference 4.16 (the latest release?)

Copy link
Contributor Author

@JayanthyChengan JayanthyChengan Sep 5, 2019

Choose a reason for hiding this comment

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

@scolapasta - Yes, it adds serial number to all existing rows. I will rename the file and commit it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

committed the changes.

@scolapasta scolapasta removed their assignment Sep 5, 2019
@pdurbin pdurbin mentioned this pull request Sep 9, 2019
@kcondon kcondon self-assigned this Sep 9, 2019
@kcondon
Copy link
Contributor

kcondon commented Sep 9, 2019

@JayanthyChengan Would you refresh from develop? The app version is still 4.15.1.

Thanks!

@JayanthyChengan
Copy link
Contributor Author

@kcondon - merged the latest develop branch.

@kcondon
Copy link
Contributor

kcondon commented Sep 9, 2019

@JayanthyChengan thanks. I am seeing a 500 error when I load the app in a browser with a sql error in logs:
Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: column "id" does not exist
Position: 8
Error Code: 0
Call: SELECT ID, CONTENT, LANG, NAME FROM SETTING WHERE ((NAME = ?) AND (LANG IS NULL))
bind => [1 parameter bound]
Query: ReadAllQuery(name="Setting.findByName" referenceClass=Setting sql="SELECT ID, CONTENT, LANG, NAME FROM SETTING WHERE ((NAME = ?) AND (LANG IS NULL))")

@kcondon kcondon assigned JayanthyChengan and unassigned kcondon Sep 9, 2019
@JayanthyChengan
Copy link
Contributor Author

Hi @kcondon - there is a setting table update, I am not sure whether you executed the db update script? Let me know if the error still exists. Thanks
https://github.com/IQSS/dataverse/blob/f199fce7b3146877d9576bb474fcd3f3186cdfd7/scripts/database/upgrades/upgrade_v4.16_to_4.16.1.sql

@kcondon
Copy link
Contributor

kcondon commented Sep 10, 2019

@JayanthyChengan We now use an automatic db update management s/w called Flyway. We no longer use the updates dir method. If you would use the Flyway method, that would be great: http://guides.dataverse.org/en/4.16/developers/sql-upgrade-scripts.html# Thanks!

@JayanthyChengan
Copy link
Contributor Author

@kcondon - Added the db upgrade file as per Flyway method. Please verify it now. Thanks

@kcondon
Copy link
Contributor

kcondon commented Sep 10, 2019

@JayanthyChengan Almost there! The new script needs to be renamed: you need to use a capital V rather a v at the beginning of the script name, otherwise flyway ignores the script. Annoying, I know.

@JayanthyChengan
Copy link
Contributor Author

@kcondon - got it, and renamed the file .

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.

6 participants