Coverage for middle_layer/review/domain_layer/services/emit_proposal_review_json_service.py: 94.12%
17 statements
« prev ^ index » next coverage.py v7.10.5, created at 2026-04-13 06:13 +0000
« prev ^ index » next coverage.py v7.10.5, created at 2026-04-13 06:13 +0000
1# Copyright 2024 Associated Universities, Inc.
2#
3# This file is part of Telescope Time Allocation Tools (TTAT).
4#
5# TTAT is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# any later version.
9#
10# TTAT is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with TTAT. If not, see <https://www.gnu.org/licenses/>.
18from common.application_layer.orm_repositories.orm_repository import ORMRepository
19from review.domain_layer.entities.osr_proposal_review import OSRProposalReview
20from review.domain_layer.entities.ppr_proposal_review import PPRProposalReview
21from review.domain_layer.entities.proposal_review import ProposalReview, ProposalReviewJSON
24def emit_proposal_review_json(
25 review: ProposalReview,
26 repo: ORMRepository,
27) -> ProposalReviewJSON:
28 """Generate JSON for a generic ProposalReview from a given specific-process review
30 :param review: the review to produce json for
31 :param repo: a db connection to use to look up data
32 :raises ValueError of the given object is not a ProposalReview
33 :return: A JSON object with the ProposalReview JSON
34 """
36 if not isinstance(review, ProposalReview):
37 raise ValueError("The given object must be a ProposalReview subclass")
39 detail_str = "Unknown Process"
40 proposal_id = None
41 if isinstance(review, OSRProposalReview):
42 detail_str = "OSR Review"
43 proposal_id = review.proposal.proposal_id
44 if isinstance(review, PPRProposalReview):
45 proposal_id = review.proposal_id
46 detail_str = repo.science_review_panel_repo.by_proposal_id(proposal_id).science_review_panel_name
48 json = {
49 "proposalId": proposal_id,
50 "reviewState": review.review_state,
51 "scientificMeritMetric": review.scientific_merit_metric,
52 "externalScienceReviewComments": review.external_science_review_comments,
53 "internalScienceReviewComments": review.internal_science_review_comments,
54 "externalTechnicalReviewComments": review.external_technical_review_comments,
55 "internalTechnicalReviewComments": review.internal_technical_review_comments,
56 "externalDataManagementReviewComments": review.external_data_management_review_comments,
57 "internalDataManagementReviewComments": review.internal_data_management_review_comments,
58 "reviewDetails": detail_str,
59 }
61 return json