Skip to content

Commit

Permalink
Merge pull request #354 from MetaCell/feature/SCKAN-273
Browse files Browse the repository at this point in the history
Feature/sckan-273
  • Loading branch information
ddelpiano authored Nov 12, 2024
2 parents 54971a8 + 92d9f82 commit 54ff54b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
5 changes: 4 additions & 1 deletion backend/composer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,10 @@ def npo_approved(self, *args, **kwargs):

@transition(
field=state,
source=CSState.NPO_APPROVED,
source=[
CSState.NPO_APPROVED,
CSState.INVALID
],
target=CSState.EXPORTED,
conditions=[ConnectivityStatementStateService.is_valid],
permission=ConnectivityStatementStateService.has_permission_to_transition_to_exported,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ def create_invalid_note(connectivity_statement: ConnectivityStatement, note: str
type=NoteType.ALERT,
note=f"Invalidated due to the following reason(s): {note}"
)


def do_transition_to_exported(connectivity_statement: ConnectivityStatement):
system_user = User.objects.get(username="system")
connectivity_statement.exported(by=system_user)
connectivity_statement.save()
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from composer.services.cs_ingestion.helpers.getters import get_sex, get_circuit_type, get_functional_circuit_role, \
get_phenotype, get_projection_phenotype
from composer.services.cs_ingestion.helpers.notes_helper import do_transition_to_invalid_with_note, create_invalid_note, \
add_ingestion_system_note
add_ingestion_system_note, do_transition_to_exported
from composer.services.cs_ingestion.models import ValidationErrors


Expand All @@ -35,11 +35,11 @@ def create_or_update_connectivity_statement(statement: Dict, sentence: Sentence,
reference_uri=reference_uri,
defaults=defaults
)
if not created:
if not created:
if has_changes(connectivity_statement, statement, defaults):
ConnectivityStatement.objects.filter(reference_uri=reference_uri).update(**defaults)
fields_to_refresh = [field for field in defaults.keys() if field != 'state']
connectivity_statement.refresh_from_db(fields=fields_to_refresh)
defaults_without_state = {field: value for field, value in defaults.items() if field != 'state'}
ConnectivityStatement.objects.filter(reference_uri=reference_uri).update(**defaults_without_state)
connectivity_statement = ConnectivityStatement.objects.get(reference_uri=reference_uri)
add_ingestion_system_note(connectivity_statement)

validation_errors = statement.get(VALIDATION_ERRORS, ValidationErrors())
Expand All @@ -50,6 +50,9 @@ def create_or_update_connectivity_statement(statement: Dict, sentence: Sentence,
do_transition_to_invalid_with_note(connectivity_statement, error_message)
else:
create_invalid_note(connectivity_statement, error_message)
else:
if connectivity_statement.state != CSState.EXPORTED:
do_transition_to_exported(connectivity_statement)

update_many_to_many_fields(connectivity_statement, statement, update_anatomical_entities)
statement[STATE] = connectivity_statement.state
Expand Down

0 comments on commit 54ff54b

Please sign in to comment.