Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@

# importModelsForMetadata
from app.backend.database import Base # noqa: E402
from app.backend.models import user_model, project_model, protocol_model, tag_model, protocol_tag_assignment_model # noqa: F401,E402
from app.backend.models import ( # noqa: F401,E402
user_model,
project_model,
protocol_model,
tag_model,
protocol_tag_assignment_model,
protocol_step_model,
)

target_metadata = Base.metadata

Expand Down
54 changes: 54 additions & 0 deletions alembic/versions/6806b9a72a6e_add_protocol_steps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""add protocol steps

Revision ID: 6806b9a72a6e
Revises: 9b7b3c4d8e21
Create Date: 2026-06-17 17:40:02.063195

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision: str = '6806b9a72a6e'
down_revision: Union[str, None] = '9b7b3c4d8e21'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
op.create_table(
"protocol_steps",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("projectId", sa.Integer(), nullable=False),
sa.Column("protocolDbId", sa.Integer(), nullable=False),
sa.Column("protocolId", sa.String(), nullable=False),
sa.Column("stepIndex", sa.Integer(), nullable=False),
sa.Column("name", sa.Text(), nullable=False),
sa.Column("status", sa.Text(), nullable=False),
sa.Column("prerequisites", sa.dialects.postgresql.JSONB(), server_default="[]", nullable=False),
sa.Column("args", sa.dialects.postgresql.JSONB(), nullable=True),
sa.Column("initTime", sa.DateTime(timezone=True), nullable=True),
sa.Column("endTime", sa.DateTime(timezone=True), nullable=True),
sa.Column("elapsedSeconds", sa.Float(), nullable=True),
sa.Column("error", sa.Text(), nullable=True),
sa.Column("interactive", sa.Boolean(), server_default="false", nullable=False),
sa.Column("needsGpu", sa.Boolean(), server_default="true", nullable=False),
sa.Column("event", sa.Text(), nullable=True),
sa.Column("createdAt", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
sa.Column("updatedAt", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
sa.ForeignKeyConstraint(["projectId"], ["projects.id"], ondelete="CASCADE"),
sa.ForeignKeyConstraint(["protocolDbId"], ["protocols.id"], ondelete="CASCADE"),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("projectId", "protocolDbId", "stepIndex", name="ux_protocol_steps_project_protocol_step"),
)
op.create_index("idx_protocol_steps_protocol", "protocol_steps", ["projectId", "protocolDbId", "stepIndex"])
op.create_index("idx_protocol_steps_protocol_id", "protocol_steps", ["projectId", "protocolId"])


def downgrade() -> None:
op.drop_index("idx_protocol_steps_protocol_id", table_name="protocol_steps")
op.drop_index("idx_protocol_steps_protocol", table_name="protocol_steps")
op.drop_table("protocol_steps")
71 changes: 71 additions & 0 deletions app/backend/api/routers/project_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,48 @@ async def loadProtocol(
return service.getProtocolParams(projectId, protocolId)


class ProtocolStepStatusUpdate(BaseModel):
status: Literal["new", "finished"] = Field(..., description="New status for the selected protocol step")


@router.get("/{projectId}/protocols/{protocolId}/steps", response_model=Any)
def listProtocolSteps(
projectId: int,
protocolId: int,
currentUser=Depends(getCurrentUser),
mapper: PostgresqlFlatMapper = Depends(getMapper),
service: ProjectService = Depends(getProjectService),
):
project = service.getProjectById(mapper, projectId, currentUser, refresh=False, checkPid=False)
if not project:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Project not found")

return service.listProtocolStepsService(mapper, projectId, protocolId)


@router.patch("/{projectId}/protocols/{protocolId}/steps/{stepIndex}/status", response_model=Any)
def updateProtocolStepStatus(
projectId: int,
protocolId: int,
stepIndex: int,
payload: ProtocolStepStatusUpdate,
currentUser=Depends(getCurrentUser),
mapper: PostgresqlFlatMapper = Depends(getMapper),
service: ProjectService = Depends(getProjectService),
):
project = service.getProjectById(mapper, projectId, currentUser, refresh=False, checkPid=False)
if not project:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Project not found")

return service.updateProtocolStepStatusService(
mapper=mapper,
projectId=projectId,
protocolId=protocolId,
stepIndex=stepIndex,
stepStatus=payload.status,
)


@router.get("/{projectId}/protclass/{protClassName}", response_model=Any)
async def loadNewProtocol(
projectId: int,
Expand Down Expand Up @@ -2348,6 +2390,35 @@ def createCoords3dOutputFromPoints(projectId: int,
raise HTTPException( status_code=500, detail=f"Failed to create coords3d output from points: {e}", )


@router.get(
"/{projectId}/protocols/{protocolId}/outputs/{outputName}/integrated-context",
response_model=Any,
status_code=status.HTTP_200_OK,
)
def getIntegratedAnalyzeContext(
projectId: int,
protocolId: int,
outputName: str,
currentUser=Depends(getCurrentUser),
mapper: PostgresqlFlatMapper = Depends(getMapper),
service: ProjectService = Depends(getProjectService),
):
project = service.getProjectById(mapper, projectId, currentUser, refresh=False, checkPid=False)
if not project:
raise HTTPException(status_code=404, detail="Project not found")

payload = service.getIntegratedAnalyzeContextService(
projectId=projectId,
protocolId=protocolId,
outputName=outputName,
)

resp = JSONResponse(payload)
resp.headers["X-Debug-Auth"] = "ok"
resp.headers["X-Debug-UserId"] = str(getattr(currentUser, "id", currentUser.get("id", "")))
resp.headers["Vary"] = "Authorization"
return resp

# ==============================================================================
# ANALYZE RESULTS: FSC (SetOfFSCs)
# ==============================================================================
Expand Down
16 changes: 16 additions & 0 deletions app/backend/api/schemas/protocols_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,19 @@ class WorkflowImportRequest(BaseModel):
sourceProjectId: Optional[Union[int, str]] = None
sourceProjectName: Optional[str] = None


class ProtocolStepOut(BaseModel):
index: int
name: str
status: str
prerequisites: List[int] = []
args: Optional[Any] = None
initTime: Optional[datetime] = None
endTime: Optional[datetime] = None
elapsedSeconds: Optional[float] = None
error: Optional[str] = None
interactive: bool = False
needsGpu: bool = True
event: Optional[str] = None
updatedAt: Optional[datetime] = None

4 changes: 4 additions & 0 deletions app/backend/api/services/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ def prepareEnvironment():
scipionHome = variables.get(pyworkflow.SCIPION_HOME_VAR) or os.environ.get(pyworkflow.SCIPION_HOME_VAR)
if scipionHome:
os.chdir(scipionHome)
os.environ.setdefault(
"SCIPION_PROTOCOL_STEPS_NOTIFIER",
"app.backend.api.services.protocol_steps_sync:syncProtocolStepsEvent",
)
Loading
Loading