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

Automatic Creation of Single Valued, String Chado Fields #261

Merged
merged 44 commits into from
Aug 30, 2022

Conversation

spficklin
Copy link
Member

@spficklin spficklin commented Aug 13, 2022

Issues Addressed

Issue #129
Issue #236
Issue #237

Wait to review this until after the merge of PR #254 because this PR has that code in it and all of the changes in that PR are also showing up here.

Description

This PR provides new functionality for field creation. It will automatically add all single-valued string fields to all content types during the Chado Prepare step. The only exception is the 'Pub' content type. That one requires some special handling. You can also create new entities for content types where the string fields are sufficient to meet the unique constraint (e.g. Organism).

This PR does not implement the ChadoStorage::deleteValues() function (issue tripal/tripal#1350) because there is not yet a distinction between an "Unpublish" and a "Delete" so I thought it would be best to not implement a delete until we had the buttons. The ChadoStorage::findValues() function is also not yet implemented (issue tripal/tripal#1351).

This PR also does not support integer fields, text fields or other database fields other than character varying. I left a "@todo" comment in the code to finish those up. But this PR is provided now so that everyone can have access to the new code.

How to Test

  1. Uninstall Tripal, pull this branch and reinstall Tripal (or start from a brand new installation)
  2. Install Chado
  3. Prepare Chado. It should indicate all of the content types are created. It's a bit slower creating content types now because it takes time to create all the fields.
  4. Go to Admin > Structure > Tripal Content Types. Pick any content type. You will see the set of fields that have been added. They should not appear in the 'Disabled' section but should be in the Content section.
  5. Go to Content > Tripal Content > Add new Tripal Content and pick the Organism content type. Test creation and editing of the content type.
  6. Look in the Chado database in the organism table. A new record should exist in the organism table, and any changes you made should be there.
  7. Return to the Admin > Structure > Tripal Content Types. You should be able to move the fields around on the manage display and manage form.
  8. Check out the field settings and the field storage settings. You should see the controlled vocabulary term that each field is assigned and the Chado table/column that the field maps to.

4ctrl-alt-del and others added 25 commits July 18, 2022 08:10
Added id space and accession attributes for tripal entity CV terms.
Merged new tripal field handling code in entities to existing entities. The new
tripal field interface will now be recognized by the system.
Fixed bug in annotation of tripal entities where the storage handler was not
provided.
Added missing semicolons when creating new empty array.
laceysanderson
laceysanderson previously approved these changes Aug 20, 2022
Copy link
Member

@laceysanderson laceysanderson left a comment

Choose a reason for hiding this comment

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

The tests should be fixed now :-)
Code review-wise: this PR is looking good.
It works for single-value, single-property fields like those on the organism content type.

We will need to create more fields in order to ensure the ChadoStorage handles more complex fields like foreign key single- + multi-value fields. There is placeholders to test these two in the automated testing for when we get to implementing them :-)

@laceysanderson
Copy link
Member

@risharde this one is also ready for you to review!

@spficklin
Copy link
Member Author

I did a quick review of the changes @laceysanderson . All looks good. Thanks for makin these fixes.

@spficklin
Copy link
Member Author

spficklin commented Aug 24, 2022

I had a brief moment for coding, so I added in support for text fields. These are unlimited strings (e.g. organism.description). So, now when you prepare Chado you should see the single-valued text fields appear as fields.

@spficklin
Copy link
Member Author

In the process of working on a complex fields (obi__organism), I've discovered that we have a problem with this PR. When setting the storage settings for a field, those are persistent between instances of the field. So, if we use the same field for two different content types and link that field to a Chado table, it will always be linked to only one Chado table. For example the feature table and analysis tables of Chado both have a name column. A field of rdfs:label gets added to all content types for those tables. But, in the end, that field always only points to one table. I think the fix is to move the Chado associations into the field settings and out of the field storage settings. I don't think this should stop this PR from getting merged in, we just need to fix this. I'm working on a fix in the branch for the complex field.

If there aren't any objections I think we move forward with a functional review by @risharde and merge if all is good and I'll make a new PR afterwards with the complex field and the fix for the problem I just described.

@risharde
Copy link
Contributor

Overall working great @spficklin! 1 warning (hopefully minor) in the tripal prepare step - screenshot attached.
@laceysanderson

[GOOD] Uninstall Tripal, pull this branch and reinstall Tripal (or start from a brand new installation)
[GOOD] Install Chado
[1 WARNING] Prepare Chado. It should indicate all of the content types are created. It's a bit slower creating content types now because it takes time to create all the fields.

@spficklin
image

[GOOD] Go to Admin > Structure > Tripal Content Types. Pick any content type. You will see the set of fields that have been added. They should not appear in the 'Disabled' section but should be in the Content section.
[GOOD] Go to Content > Tripal Content > Add new Tripal Content and pick the Organism content type. Test creation and editing of the content type.
[GOOD] Look in the Chado database in the organism table. A new record should exist in the organism table, and any changes you made should be there.
[GOOD] Return to the Admin > Structure > Tripal Content Types. You should be able to move the fields around on the manage display and manage form.
[GOOD] Check out the field settings and the field storage settings. You should see the controlled vocabulary term that each field is assigned and the Chado table/column that the field maps to.

Copy link
Contributor

@risharde risharde left a comment

Choose a reason for hiding this comment

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

Functional tests worked so we're good to go here!

Copy link

@codeclimate codeclimate bot left a comment

Choose a reason for hiding this comment

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

The PR diff size of 10989 lines exceeds the maximum allowed for the inline comments feature.

@spficklin
Copy link
Member Author

Approved by @laceysanderson and @risharde ... all tests are passing but the Drupal 10 check which is breaking on Docker. So, merging.

/**
* {@inheritdoc}
*/
public function tripalValuesTemplate() {
Copy link

Choose a reason for hiding this comment

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

Identical blocks of code found in 2 locations. Consider refactoring.

/**
* {@inheritdoc}
*/
public function tripalValuesTemplate() {
Copy link

Choose a reason for hiding this comment

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

Identical blocks of code found in 2 locations. Consider refactoring.

public function updateValues($values) {
$indexed_values = $this->indexValues($values);

public function updateValues($values) : bool {
Copy link

Choose a reason for hiding this comment

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

Function updateValues has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.

* @return bool
* True if the field was added successfully. False otherwise.
*/
public function addBundleField(string $bundle, array $field_def) : bool {
Copy link

Choose a reason for hiding this comment

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

Function addBundleField has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.

/**
* {@inheritdoc}
*/
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
Copy link

Choose a reason for hiding this comment

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

Method formElement has 5 arguments (exceeds 4 allowed). Consider refactoring.

@codeclimate
Copy link

codeclimate bot commented Aug 30, 2022

Code Climate has analyzed commit 82893db and detected 23 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 19
Duplication 4

The test coverage on the diff in this pull request is 8.9% (50% is the threshold).

This pull request will bring the total coverage in the repository to 22.2% (-2.1% change).

View more on Code Climate.

@spficklin spficklin merged commit f7d2cf0 into 9.x-4.x Aug 30, 2022
@spficklin spficklin deleted the tv4g1-129-TripalFields-spf branch December 3, 2022 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement ChadoStorage::updateValues() Implement ChadoStorage::insertValues()
4 participants