diff --git a/app/controllers/api/internal/v2/court_applications_controller.rb b/app/controllers/api/internal/v2/court_applications_controller.rb new file mode 100644 index 00000000..0227d14d --- /dev/null +++ b/app/controllers/api/internal/v2/court_applications_controller.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module Api + module Internal + module V2 + class CourtApplicationsController < ApplicationController + def show + # TODO: this will be the new application details endpoint + raise NotImplementedError + end + end + end + end +end diff --git a/app/services/common_platform/api/schema_validator.rb b/app/services/common_platform/api/schema_validator.rb new file mode 100644 index 00000000..c4b5910d --- /dev/null +++ b/app/services/common_platform/api/schema_validator.rb @@ -0,0 +1,49 @@ +require "json-schema" +require "uri" + +module CommonPlatform + module Api + class SchemaValidator < ApplicationService + def initialize(schema:, json_response:) + @schema = schema + @json_response = json_response + + load_schema_references + end + + def call + JSON::Validator.validate!(@schema, @json_response) + rescue JSON::Schema::ValidationError => e + Rails.logger.error("JSON Schema Validation Error: #{e.message}") + false + end + + private + + def load_schema_references + refs = [ + { + filename: "lib/schemas/global/apiCourtsDefinitions.json", + url: "http://justice.gov.uk/core/courts/external/apiCourtsDefinitions.json", + }, + { + filename: "lib/schemas/global/apiJudicialResult.json", + url: "http://justice.gov.uk/core/courts/external/apiJudicialResult.json", + }, + { + filename: "lib/schemas/global/apiDelegatedPowers.json", + url: "http://justice.gov.uk/core/courts/external/apiDelegatedPowers.json", + }, + ] + + refs.each do |ref| + json_schema = JSON::Schema.new( + JSON.parse(File.open(Rails.root.join(ref[:filename]).to_s).read), + Addressable::URI.parse(ref[:url]), + ) + JSON::Validator.add_schema(json_schema) + end + end + end + end +end diff --git a/config/routes.rb b/config/routes.rb index dae6b02f..74952c56 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -27,6 +27,7 @@ end api_version(module: "V2", path: { value: "v2" }) do + resources :court_applications, only: [:show] resources :prosecution_cases, only: [:index], param: :reference do resources :defendants, only: %i[show] end diff --git a/lib/schemas/api/progression.query.laa.application-laa.json b/lib/schemas/api/progression.query.laa.application-laa.json new file mode 100644 index 00000000..337b8f7c --- /dev/null +++ b/lib/schemas/api/progression.query.laa.application-laa.json @@ -0,0 +1,407 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "id": "http://justice.gov.uk/progression/query/laa/application-laa.json", + "type": "object", + "properties": { + "applicationId": { + "$ref": "http://justice.gov.uk/core/courts/external/apiCourtsDefinitions.json#/definitions/uuid" + }, + "applicationReference": { + "description": "The LAA issued reference to the application. Currently known as the MAAT Id", + "type": "string" + }, + "applicationStatus": { + "description": "Indicates if the application is draft, listed or finalised", + "$ref": "http://justice.gov.uk/core/courts/external/apiCourtsDefinitions.json#/definitions/courtApplicationStatus" + }, + "applicationTitle": { + "description": "The CJS Title for the court application type", + "type": "string" + }, + "applicationType": { + "description": "The value of the Application.type.type", + "type": "string" + }, + "receivedDate": { + "type": "string", + "format": "date" + }, + "judicialResults": { + "type": "array", + "minItems": 1, + "items": { + "$ref": "http://justice.gov.uk/core/courts/external/apiJudicialResult.json" + } + }, + "caseSummary": { + "type": "array", + "items": [ + { + "type": "object", + "id": "http://justice.gov.uk/progression/query/laa/case-summary.json", + "properties": { + "caseStatus": { + "type": "string" + }, + "prosecutionCaseId": { + "$ref": "http://justice.gov.uk/core/courts/external/apiCourtsDefinitions.json#/definitions/uuid" + }, + "prosecutionCaseReference": { + "description": "The URN or PRN of the case", + "type": "string" + } + }, + "additionalProperties": false + } + ] + }, + "hearingSummary": { + "type": "array", + "items": [ + { + "id": "http://justice.gov.uk/progression/query/laa/hearing-summary.json", + "type": "object", + "properties": { + "hearingId": { + "$ref": "http://justice.gov.uk/core/courts/external/apiCourtsDefinitions.json#/definitions/uuid" + }, + "jurisdictionType": { + "type": "string" + }, + "estimatedDuration": { + "type": "string" + }, + "defendantIds": { + "type": "array", + "items": [ + { + "$ref": "http://justice.gov.uk/core/courts/external/apiCourtsDefinitions.json#/definitions/uuid" + } + ] + }, + "hearingType": { + "type": "object", + "id": "http://justice.gov.uk/progression/query/laa/hearing-type.json", + "properties": { + "id": { + "$ref": "http://justice.gov.uk/core/courts/external/apiCourtsDefinitions.json#/definitions/uuid" + }, + "description": { + "type": "string" + }, + "code": { + "type": "string" + } + }, + "required": [ + "id", + "description" + ], + "additionalProperties": false + }, + "courtCentre": { + "id": "http://justice.gov.uk/progression/query/laa/court-centre.json", + "type": "object", + "properties": { + "id": { + "$ref": "http://justice.gov.uk/core/courts/external/apiCourtsDefinitions.json#/definitions/uuid" + }, + "code": { + "type": "string" + }, + "name": { + "type": "string" + }, + "roomId": { + "$ref": "http://justice.gov.uk/core/courts/external/apiCourtsDefinitions.json#/definitions/uuid" + }, + "roomName": { + "type": "string" + }, + "welshName": { + "type": "string" + }, + "welshRoomName": { + "type": "string" + }, + "address": { + "id": "http://justice.gov.uk/progression/query/laa/address.json", + "type": "object", + "properties": { + "address1": { + "type": "string" + }, + "address2": { + "type": "string" + }, + "address3": { + "type": "string" + }, + "address4": { + "type": "string" + }, + "postCode": { + "type": "string" + } + }, + "required": [ + "address1", + "postCode" + ], + "additionalProperties": false + } + }, + "required": [ + "id", + "name", + "roomId", + "roomName" + ], + "additionalProperties": false + }, + "hearingDay": { + "type": "array", + "items": [ + { + "id": "http://justice.gov.uk/progression/query/laa/hearing-day.json", + "type": "object", + "properties": { + "sittingDay": { + "type": "string" + }, + "listingSequence": { + "type": "integer" + }, + "listedDurationMinutes": { + "type": "integer" + }, + "hasSharedResults": { + "type": "boolean" + } + }, + "required": [ + "sittingDay" + ], + "additionalProperties": false + } + ] + }, + "defenceCounsel": { + "type": "array", + "items": [ + { + "id": "http://justice.gov.uk/progression/query/laa/defence-counsel.json", + "type": "object", + "properties": { + "id": { + "$ref": "http://justice.gov.uk/core/courts/external/apiCourtsDefinitions.json#/definitions/uuid" + }, + "title": { + "type": "string" + }, + "firstName": { + "type": "string" + }, + "middleName": { + "type": "string" + }, + "lastName": { + "type": "string" + }, + "status": { + "type": "string" + }, + "defendants": { + "type": "array", + "items": [ + { + "$ref": "http://justice.gov.uk/core/courts/external/apiCourtsDefinitions.json#/definitions/uuid" + } + ] + }, + "attendanceDays": { + "type": "array", + "items": [ + { + "type": "string" + } + ] + } + }, + "additionalProperties": false + } + ] + } + }, + "required": [ + "hearingId", + "hearingType", + "courtCentre", + "hearingDay" + ], + "additionalProperties": false + } + ] + }, + "subjectSummary": { + "id": "http://justice.gov.uk/progression/query/laa/subject-summary.json", + "type": "object", + "properties": { + "proceedingsConcluded": { + "type": "boolean" + }, + "subjectId": { + "$ref": "http://justice.gov.uk/core/courts/external/apiCourtsDefinitions.json#/definitions/uuid" + }, + "masterDefendantId": { + "$ref": "http://justice.gov.uk/core/courts/external/apiCourtsDefinitions.json#/definitions/uuid" + }, + "defendantASN": { + "type": "string" + }, + "defendantFirstName": { + "type": "string" + }, + "defendantMiddleName": { + "type": "string" + }, + "defendantLastName": { + "type": "string" + }, + "defendantDOB": { + "type": "string" + }, + "defendantNINO": { + "type": "string" + }, + "dateOfNextHearing": { + "type": "string" + }, + "representationOrder": { + "id": "http://justice.gov.uk/progression/query/laa/representation-order.json", + "type": "object", + "properties": { + "applicationReference": { + "type": "string" + }, + "effectiveFromDate": { + "type": "string", + "format": "date" + }, + "effectiveToDate": { + "type": "string", + "format": "date" + }, + "laaContractNumber": { + "type": "string" + } + }, + "required": [ + "applicationReference" + ], + "additionalProperties": false + }, + "offenceSummary": { + "type": "array", + "items": [ + { + "id": "http://justice.gov.uk/progression/query/laa/offence-summary.json", + "type": "object", + "properties": { + "offenceId": { + "$ref": "http://justice.gov.uk/core/courts/external/apiCourtsDefinitions.json#/definitions/uuid" + }, + "offenceCode": { + "type": "string" + }, + "offenceTitle": { + "type": "string" + }, + "offenceLegislation": { + "type": "string" + }, + "proceedingsConcluded": { + "type": "boolean" + }, + "arrestDate": { + "type": "string" + }, + "dateOfInformation": { + "type": "string" + }, + "endDate": { + "type": "string" + }, + "startDate": { + "type": "string" + }, + "chargeDate": { + "type": "string" + }, + "modeOfTrial": { + "type": "string" + }, + "orderIndex": { + "type": "integer" + }, + "wording": { + "type": "string" + }, + "laaApplnReference": { + "id": "http://justice.gov.uk/progression/query/laa/laa-appln-reference.json", + "type": "object", + "properties": { + "applicationReference": { + "type": "string" + }, + "statusId": { + "type": "string" + }, + "statusCode": { + "type": "string" + }, + "statusDescription": { + "type": "string" + } + }, + "required": [ + "applicationReference", + "statusId", + "statusCode", + "statusDescription" + ], + "additionalProperties": false + } + }, + "required": [ + "offenceId", + "offenceCode", + "offenceTitle", + "offenceLegislation", + "proceedingsConcluded", + "arrestDate", + "startDate", + "chargeDate", + "modeOfTrial", + "orderIndex", + "wording" + ], + "additionalProperties": false + } + ] + } + }, + "required": [ + "subjectId", + "defendantFirstName" + ], + "additionalProperties": false + } + }, + "required": [ + "applicationId", + "applicationReference", + "applicationStatus" + ], + "additionalProperties": false +} diff --git a/lib/schemas/global/apiCourtApplication.json b/lib/schemas/global/apiCourtApplication.json index 224eb900..2e5c12fd 100644 --- a/lib/schemas/global/apiCourtApplication.json +++ b/lib/schemas/global/apiCourtApplication.json @@ -1,132 +1,136 @@ -{ - "$schema": "http://json-schema.org/draft-04/schema#", - "id": "http://justice.gov.uk/core/courts/external/apiCourtApplication.json", - "description": "An application made to court for judicial decision. May be standalone or linked to a case", - "type": "object", - "properties": { - "id": { - "$ref": "http://justice.gov.uk/core/courts/external/apiCourtsDefinitions.json#/definitions/uuid" - }, - "courtApplicationCases": { - "description": "The cases that are linked to this application", - "type": "array", - "minItems": 1, - "items": { - "$ref": "http://justice.gov.uk/core/courts/external/apiCourtApplicationCase.json" - } - }, - "parentApplicationId": { - "description": "The identifier of the linked parent application. Linked applications are a single level deep", - "$ref": "http://justice.gov.uk/core/courts/external/apiCourtsDefinitions.json#/definitions/uuid" - }, - "courtOrder": { - "description": "When the application is in relation to a court order e.g. breach proceedings, the details of the court order", - "$ref": "http://justice.gov.uk/core/courts/external/apiCourtOrder.json" - }, - "type": { - "description": "The type of application made to court for judicial decision. Taken from reference data", - "$ref": "http://justice.gov.uk/core/courts/external/apiCourtApplicationType.json" - }, - "applicationReceivedDate": { - "description": "The date that the application was received by HMCTS", - "$ref": "http://justice.gov.uk/core/courts/external/apiCourtsDefinitions.json#/definitions/datePattern" - }, - "allegationOrComplaintStartDate": { - "description": "The date that the allegation or complaint is alleged to have started", - "$ref": "http://justice.gov.uk/core/courts/external/apiCourtsDefinitions.json#/definitions/datePattern" - }, - "allegationOrComplaintEndDate": { - "description": "The date that the allegation or complaint is alleged to have ended", - "$ref": "http://justice.gov.uk/core/courts/external/apiCourtsDefinitions.json#/definitions/datePattern" - }, - "applicationReference": { - "description": "The human readable reference for the application. For linked applications this will be the case urn or the prosecution authority reference suffixed with a numerical sequence. This is generated by the backend APIs and therefore is set optional, however a reference is required by the time the application is listed", - "type": "string" - }, - "applicant": { - "description": "The party applying to court to make a judicial decision on a matter", - "$ref": "http://justice.gov.uk/core/courts/external/apiCourtApplicationParty.json" - }, - "respondents": { - "description": "The parties answering to a matter before the court", - "type": "array", - "minItems": 1, - "items": { - "$ref": "http://justice.gov.uk/core/courts/external/apiCourtApplicationParty.json" - } - }, - "thirdParties": { - "description": "The 3rd parties assocaited to the court matter. Required to be notified", - "type": "array", - "minItems": 1, - "items": { - "$ref": "http://justice.gov.uk/core/courts/external/apiCourtApplicationParty.json" - } - }, - "subject": { - "description": "The party that is the subject of teh application. The subject is also a respondent or an applicant and is the subject of any orders and directions that are made during court proceedings", - "$ref": "http://justice.gov.uk/core/courts/external/apiCourtApplicationParty.json" - }, - "applicationParticulars": { - "description": "The particulars of the application when not covered by the associated document", - "type": "string" - }, - "courtApplicationPayment": { - "description": "The details of payment or fee exemption for the application", - "$ref": "http://justice.gov.uk/core/courts/external/apiCourtApplicationPayment.json" - }, - "applicationDecisionSoughtByDate": { - "description": "The date by which a judicial decision is sought", - "$ref": "http://justice.gov.uk/core/courts/external/apiCourtsDefinitions.json#/definitions/datePattern" - }, - "applicationStatus": { - "description": "Indicates if the application is draft, listed or finalised", - "$ref": "http://justice.gov.uk/core/courts/external/apiCourtsDefinitions.json#/definitions/courtApplicationStatus" - }, - "outOfTimeReasons": { - "description": "The rationale for seeking a judicial decision when the regulatory timeline has surpassed. This only applies to application types that are time constrained i.e. isTimeRestricted == true", - "type": "string" - }, - "defendantASN": { - "description": "When the application is for breach proceedings the ASN for the breach proceedings is required by Bichard 7 and therefore is captured as part of the application. The ASN applies to the subject of the application", - "type": "string" - }, - "judicialResults": { - "type": "array", - "minItems": 1, - "items": { - "$ref": "http://justice.gov.uk/core/courts/external/apiJudicialResult.json" - } - }, - "plea": { - "$ref": "http://justice.gov.uk/core/courts/external/apiPlea.json" - }, - "verdict": { - "$ref": "http://justice.gov.uk/core/courts/external/apiVerdict.json" - }, - "hasSummonsSupplied": { - "type": "boolean" - }, - "removalReason": { - "type": "string" - }, - "commissionerOfOath": { - "type": "boolean" - }, - "convictionDate": { - "$ref": "http://justice.gov.uk/core/courts/external/apiCourtsDefinitions.json#/definitions/datePattern" - }, - "futureSummonsHearing": { - "$ref": "http://justice.gov.uk/core/courts/external/apiFutureSummonsHearing.json" - } - }, - "required": [ - "id", - "type", - "applicationReceivedDate", - "applicant", - "subject", - "applicationStatus" - ], - "additionalProperties": false -} +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "id": "http://justice.gov.uk/core/courts/external/apiCourtApplication.json", + "description": "An application made to court for judicial decision. May be standalone or linked to a case", + "type": "object", + "properties": { + "id": { + "$ref": "http://justice.gov.uk/core/courts/external/apiCourtsDefinitions.json#/definitions/uuid" + }, + "courtApplicationCases": { + "description": "The cases that are linked to this application", + "type": "array", + "minItems": 1, + "items": { + "$ref": "http://justice.gov.uk/core/courts/external/apiCourtApplicationCase.json" + } + }, + "parentApplicationId": { + "description": "The identifier of the linked parent application. Linked applications are a single level deep", + "$ref": "http://justice.gov.uk/core/courts/external/apiCourtsDefinitions.json#/definitions/uuid" + }, + "courtOrder": { + "description": "When the application is in relation to a court order e.g. breach proceedings, the details of the court order", + "$ref": "http://justice.gov.uk/core/courts/external/apiCourtOrder.json" + }, + "type": { + "description": "The type of application made to court for judicial decision. Taken from reference data", + "$ref": "http://justice.gov.uk/core/courts/external/apiCourtApplicationType.json" + }, + "applicationReceivedDate": { + "description": "The date that the application was received by HMCTS", + "$ref": "http://justice.gov.uk/core/courts/external/apiCourtsDefinitions.json#/definitions/datePattern" + }, + "applicationExternalCreatorType": { + "description": "Describes the generic role of the creator of the application in the HMCTS process (Prosecutor)", + "$ref": "http://justice.gov.uk/core/courts/external/apiCourtsDefinitions.json#/definitions/applicationExternalCreatorType" + }, + "allegationOrComplaintStartDate": { + "description": "The date that the allegation or complaint is alleged to have started", + "$ref": "http://justice.gov.uk/core/courts/external/apiCourtsDefinitions.json#/definitions/datePattern" + }, + "allegationOrComplaintEndDate": { + "description": "The date that the allegation or complaint is alleged to have ended", + "$ref": "http://justice.gov.uk/core/courts/external/apiCourtsDefinitions.json#/definitions/datePattern" + }, + "applicationReference": { + "description": "The human readable reference for the application. For linked applications this will be the case urn or the prosecution authority reference suffixed with a numerical sequence. This is generated by the backend APIs and therefore is set optional, however a reference is required by the time the application is listed", + "type": "string" + }, + "applicant": { + "description": "The party applying to court to make a judicial decision on a matter", + "$ref": "http://justice.gov.uk/core/courts/external/apiCourtApplicationParty.json" + }, + "respondents": { + "description": "The parties answering to a matter before the court", + "type": "array", + "minItems": 1, + "items": { + "$ref": "http://justice.gov.uk/core/courts/external/apiCourtApplicationParty.json" + } + }, + "thirdParties": { + "description": "The 3rd parties assocaited to the court matter. Required to be notified", + "type": "array", + "minItems": 1, + "items": { + "$ref": "http://justice.gov.uk/core/courts/external/apiCourtApplicationParty.json" + } + }, + "subject": { + "description": "The party that is the subject of teh application. The subject is also a respondent or an applicant and is the subject of any orders and directions that are made during court proceedings", + "$ref": "http://justice.gov.uk/core/courts/external/apiCourtApplicationParty.json" + }, + "applicationParticulars": { + "description": "The particulars of the application when not covered by the associated document", + "type": "string" + }, + "courtApplicationPayment": { + "description": "The details of payment or fee exemption for the application", + "$ref": "http://justice.gov.uk/core/courts/external/apiCourtApplicationPayment.json" + }, + "applicationDecisionSoughtByDate": { + "description": "The date by which a judicial decision is sought", + "$ref": "http://justice.gov.uk/core/courts/external/apiCourtsDefinitions.json#/definitions/datePattern" + }, + "applicationStatus": { + "description": "Indicates if the application is draft, listed or finalised", + "$ref": "http://justice.gov.uk/core/courts/external/apiCourtsDefinitions.json#/definitions/courtApplicationStatus" + }, + "outOfTimeReasons": { + "description": "The rationale for seeking a judicial decision when the regulatory timeline has surpassed. This only applies to application types that are time constrained i.e. isTimeRestricted == true", + "type": "string" + }, + "defendantASN": { + "description": "When the application is for breach proceedings the ASN for the breach proceedings is required by Bichard 7 and therefore is captured as part of the application. The ASN applies to the subject of the application", + "type": "string" + }, + "judicialResults": { + "type": "array", + "minItems": 1, + "items": { + "$ref": "http://justice.gov.uk/core/courts/external/apiJudicialResult.json" + } + }, + "plea": { + "$ref": "http://justice.gov.uk/core/courts/external/apiPlea.json" + }, + "verdict": { + "$ref": "http://justice.gov.uk/core/courts/external/apiVerdict.json" + }, + "hasSummonsSupplied": { + "type": "boolean" + }, + "removalReason": { + "type": "string" + }, + "commissionerOfOath": { + "type": "boolean" + }, + "convictionDate": { + "$ref": "http://justice.gov.uk/core/courts/external/apiCourtsDefinitions.json#/definitions/datePattern" + }, + "futureSummonsHearing": { + "$ref": "http://justice.gov.uk/core/courts/external/apiFutureSummonsHearing.json" + } + }, + "required": [ + "id", + "type", + "applicationReceivedDate", + "applicant", + "subject", + "applicationStatus" + ], + "additionalProperties": false +} diff --git a/lib/schemas/global/apiCourtsDefinitions.json b/lib/schemas/global/apiCourtsDefinitions.json index 15915557..d50f0a6d 100644 --- a/lib/schemas/global/apiCourtsDefinitions.json +++ b/lib/schemas/global/apiCourtsDefinitions.json @@ -1,266 +1,268 @@ -{ - "$schema": "http://json-schema.org/draft-04/schema#", - "id": "http://justice.gov.uk/core/courts/external/apiCourtsDefinitions.json", - "definitions": { - "positiveInteger": { - "type": "integer", - "minimum": 0 - }, - "organisationType": { - "description": "The organisation type for an organisation", - "type": "string", - "enum": [ - "CPS", - "CPP", - "LEGAL_ORGANISATION", - "HMCTS", - "JUDGES", - "MAGISTRATES", - "PPA", - "PRISON_SERVICE", - "PROBATION_SERVICE", - "POLICE_FORCE", - "YOUTH_OFFENDING_SERVICE", - "CRIMINAL_JUSTICE_PARTNERS", - "PUBLIC_AGENCY" - ] - }, - "uuid": { - "type": "string", - "pattern": "[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$" - }, - "phone": { - "type": "string", - "pattern": "^[\\+]?[0-9()\\-\\.\\s]+$" - }, - "boxWorkTaskStatus": { - "description": "The workflow status of the box work", - "type": "string", - "enum": [ - "IN_PROGRESS", - "COMPLETE" - ] - }, - "prosecutionCaseStatus": { - "description": "The defendants bail status", - "type": "string" - }, - "resultLevel": { - "description": "Available when the UI has resolved the result with the notepad parsing service i.e. is expected when result line isComplete is true", - "type": "string", - "enum": [ - "DEFENDANT", - "CASE", - "OFFENCE" - ] - }, - "legacyReferralStatus": { - "description": "The status of a case that is referred to legacy", - "type": "string", - "enum": [ - "REFERRED_TO_LIBRA", - "REFERRED_TO_CREST", - "INITIATED_IN_LIBRA_APPROVAL_PENDING", - "INITIATED_IN_CREST_APPROVAL_PENDING", - "INITIATED_IN_LIBRA_APPROVED", - "INITIATED_IN_CREST_APPROVED" - ] - }, - "legacyReferralJurisdictionType": { - "description": "Indicates the jurisdiction that is referring the case to legacy", - "type": "string", - "enum": [ - "MAGISTRATES", - "CROWN", - "SJS" - ] - }, - "courtApplicationStatus": { - "description": "Indicates the status of an application", - "type": "string", - "enum": [ - "DRAFT", - "LISTED", - "FINALISED" - ] - }, - "applicationJurisdictionType": { - "description": "Indicates the jurisdiction that is required to consider the application", - "type": "string", - "enum": [ - "MAGISTRATES", - "CROWN", - "EITHER" - ] - }, - "applicationSummonsRecipientType": { - "description": "Indicates if the application summons should be sent for the applicant for for all respondents", - "type": "string", - "enum": [ - "APPLICANT", - "RESPONDENT" - ] - }, - "applicationSummonsTemplateType": { - "description": "Indicates the application summons template type to use for all respondents", - "type": "string", - "enum": [ - "BREACH", - "GENERIC_APPLICATION", - "GENERIC_SUMMONS" - ] - }, - "applicationLinkType": { - "description": "Indicates if a type of application must be linked or must be standalone or can be either", - "type": "string", - "enum": [ - "STANDALONE", - "LINKED", - "EITHER" - ] - }, - "driverLicenseCode": { - "description": "Identifies the type of driving licence. Previously known as Licence Type", - "type": "string", - "enum": [ - "FULL", - "PROVISIONAL" - ] - }, - "vehicleCode": { - "description": "Identifies offences involving an LGV or PCV that are of interest to the DfT. Previously known as Vehicle Type", - "type": "string", - "enum": [ - "LARGE_GOODS_VEHICLE", - "PASSENGER_CARRYING_VEHICLE", - "OTHER" - ] - }, - "judicialResultCategory": { - "description": "Indicates the type of result", - "type": "string", - "enum": [ - "FINAL", - "INTERMEDIARY", - "ANCILLARY" - ] - }, - "hearingListingStatus": { - "description": "The listing status of a hearing", - "type": "string", - "enum": [ - "SENT_FOR_LISTING", - "HEARING_INITIALISED", - "HEARING_RESULTED" - ] - }, - "summonsType": { - "description": "The types of summons", - "type": "string", - "enum": [ - "FIRST_HEARING", - "SJP_REFERRAL", - "BREACH", - "YOUTH", - "APPLICATION" - ] - }, - "gender": { - "description": "The person gender", - "type": "string", - "enum": [ - "MALE", - "FEMALE", - "NOT_KNOWN", - "NOT_SPECIFIED" - ] - }, - "email": { - "type": "string", - "pattern": "^[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$" - }, - "jurisdictionType": { - "type": "string", - "enum": [ - "MAGISTRATES", - "CROWN" - ] - }, - "initiationCode": { - "description": "Indicates how a case is initialised. J-SJP Notice, Q-Requisition, S-Summons, C-Charge, R-Remitted, O-Other, Z-SJP Referral", - "type": "string", - "enum": [ - "J", - "Q", - "S", - "C", - "R", - "O", - "Z" - ] - }, - "hearingLanguage": { - "description": "The language of the hearing", - "enum": [ - "ENGLISH", - "WELSH" - ] - }, - "personTitle": { - "type": "string", - "description": "A person is the base type of a defendant. Defendants title must be constrained to remain compliant with the GOB interface" - }, - "judicialRoleType": { - "type": "string", - "enum": [ - "RECORDER", - "CIRCUIT_JUDGE", - "DISTRICT_JUDGE", - "MAGISTRATE" - ] - }, - "nino": { - "type": "string", - "pattern": "(?!BG)(?!GB)(?!NK)(?!KN)(?!TN)(?!NT)(?!ZZ)(?:[A-CEGHJ-PR-TW-Z][A-CEGHJ-NPR-TW-Z])(?:\\s*\\d\\s*){6}([A-D]|\\s)$" - }, - "ukGovPostCode": { - "description": "UK Gov post code validation following CJS Data Standards", - "type": "string", - "pattern": "^(([gG][iI][rR] {0,}0[aA]{2})|(([aA][sS][cC][nN]|[sS][tT][hH][lL]|[tT][dD][cC][uU]|[bB][bB][nN][dD]|[bB][iI][qQ][qQ]|[fF][iI][qQ][qQ]|[pP][cC][rR][nN]|[sS][iI][qQ][qQ]|[iT][kK][cC][aA]) {0,}1[zZ]{2})|((([a-pr-uwyzA-PR-UWYZ][a-hk-yxA-HK-XY]?[0-9][0-9]?)|(([a-pr-uwyzA-PR-UWYZ][0-9][a-hjkstuwA-HJKSTUW])|([a-pr-uwyzA-PR-UWYZ][a-hk-yA-HK-Y][0-9][abehmnprv-yABEHMNPRV-Y]))) [0-9][abd-hjlnp-uw-zABD-HJLNP-UW-Z]{2}))$", - "maxLength": 8 - }, - "ukGovPostCodeWithOptionalSpace": { - "description": "UK Gov post code validation following CJS Data Standards", - "type": "string", - "pattern": "^(([gG][iI][rR] {0,}0[aA]{2})|(([aA][sS][cC][nN]|[sS][tT][hH][lL]|[tT][dD][cC][uU]|[bB][bB][nN][dD]|[bB][iI][qQ][qQ]|[fF][iI][qQ][qQ]|[pP][cC][rR][nN]|[sS][iI][qQ][qQ]|[iT][kK][cC][aA]) {0,}1[zZ]{2})|((([a-pr-uwyzA-PR-UWYZ][a-hk-yxA-HK-XY]?[0-9][0-9]?)|(([a-pr-uwyzA-PR-UWYZ][0-9][a-hjkstuwA-HJKSTUW])|([a-pr-uwyzA-PR-UWYZ][a-hk-yA-HK-Y][0-9][abehmnprv-yABEHMNPRV-Y]))) {0,}[0-9][abd-hjlnp-uw-zABD-HJLNP-UW-Z]{2}))$", - "maxLength": 8 - }, - "datePattern": { - "type": "string", - "pattern": "^((([\\+-]?\\d{4}(?!\\d{2}\\b))\\-(0[13578]|1[02])\\-(0[1-9]|[12]\\d|3[01]))|(([\\+-]?\\d{4}(?!\\d{2}\\b))\\-(0[13456789]|1[012])\\-(0[1-9]|[12]\\d|30))|(([\\+-]?\\d{4}(?!\\d{2}\\b))\\-02\\-(0[1-9]|1\\d|2[0-8]))|(((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))\\-02\\-29))$" - }, - "judicialRoleTypeSJP": { - "type": "string", - "enum": [ - "MAGISTRATE", - "LEGAL_ADVISER" - ] - }, - "defenceRepresentationFundingType": { - "description": "Indicates the type of funding for a defence representative", - "type": "string", - "enum": [ - "REPRESENTATION_ORDER", - "REPRESENTATION_ORDER_APPLIED_FOR", - "PRIVATE", - "COURT_APPOINTED", - "PRO_BONO" - ] - }, - "date-time": { - "type": "string", - "format": "date-time" - } - }, - "additionalProperties": false +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "id": "http://justice.gov.uk/core/courts/external/apiCourtsDefinitions.json", + "definitions": { + "positiveInteger": { + "type": "integer", + "minimum": 0 + }, + "organisationType": { + "description": "The organisation type for an organisation", + "type": "string", + "enum": [ + "CPS", + "CPP", + "LEGAL_ORGANISATION", + "HMCTS", + "JUDGES", + "MAGISTRATES", + "PPA", + "PRISON_SERVICE", + "PROBATION_SERVICE", + "POLICE_FORCE", + "YOUTH_OFFENDING_SERVICE", + "CRIMINAL_JUSTICE_PARTNERS", + "PUBLIC_AGENCY" + ] + }, + "uuid": { + "type": "string", + "pattern": "[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$" + }, + "phone": { + "type": "string", + "pattern": "^[\\+]?[0-9()\\-\\.\\s]+$" + }, + "boxWorkTaskStatus": { + "description": "The workflow status of the box work", + "type": "string", + "enum": [ + "IN_PROGRESS", + "COMPLETE" + ] + }, + "prosecutionCaseStatus": { + "description": "The defendants bail status", + "type": "string" + }, + "resultLevel": { + "description": "Available when the UI has resolved the result with the notepad parsing service i.e. is expected when result line isComplete is true", + "type": "string", + "enum": [ + "DEFENDANT", + "CASE", + "OFFENCE" + ] + }, + "legacyReferralStatus": { + "description": "The status of a case that is referred to legacy", + "type": "string", + "enum": [ + "REFERRED_TO_LIBRA", + "REFERRED_TO_CREST", + "INITIATED_IN_LIBRA_APPROVAL_PENDING", + "INITIATED_IN_CREST_APPROVAL_PENDING", + "INITIATED_IN_LIBRA_APPROVED", + "INITIATED_IN_CREST_APPROVED" + ] + }, + "legacyReferralJurisdictionType": { + "description": "Indicates the jurisdiction that is referring the case to legacy", + "type": "string", + "enum": [ + "MAGISTRATES", + "CROWN", + "SJS" + ] + }, + "courtApplicationStatus": { + "description": "Indicates the status of an application", + "type": "string" + }, + "applicationJurisdictionType": { + "description": "Indicates the jurisdiction that is required to consider the application", + "type": "string", + "enum": [ + "MAGISTRATES", + "CROWN", + "EITHER" + ] + }, + "applicationSummonsRecipientType": { + "description": "Indicates if the application summons should be sent for the applicant for for all respondents", + "type": "string", + "enum": [ + "APPLICANT", + "RESPONDENT" + ] + }, + "applicationSummonsTemplateType": { + "description": "Indicates the application summons template type to use for all respondents", + "type": "string", + "enum": [ + "BREACH", + "GENERIC_APPLICATION", + "GENERIC_SUMMONS" + ] + }, + "applicationLinkType": { + "description": "Indicates if a type of application must be linked or must be standalone or can be either", + "type": "string", + "enum": [ + "STANDALONE", + "LINKED", + "EITHER" + ] + }, + "applicationExternalCreatorType": { + "description": "Describes the generic role of the creator of the application in the HMCTS process (Prosecutor)", + "type": "string", + "enum": [ + "PROSECUTOR" + ] + }, + "driverLicenseCode": { + "description": "Identifies the type of driving licence. Previously known as Licence Type", + "type": "string", + "enum": [ + "FULL", + "PROVISIONAL" + ] + }, + "vehicleCode": { + "description": "Identifies offences involving an LGV or PCV that are of interest to the DfT. Previously known as Vehicle Type", + "type": "string", + "enum": [ + "LARGE_GOODS_VEHICLE", + "PASSENGER_CARRYING_VEHICLE", + "OTHER" + ] + }, + "judicialResultCategory": { + "description": "Indicates the type of result", + "type": "string", + "enum": [ + "FINAL", + "INTERMEDIARY", + "ANCILLARY" + ] + }, + "hearingListingStatus": { + "description": "The listing status of a hearing", + "type": "string", + "enum": [ + "SENT_FOR_LISTING", + "HEARING_INITIALISED", + "HEARING_RESULTED" + ] + }, + "summonsType": { + "description": "The types of summons", + "type": "string", + "enum": [ + "FIRST_HEARING", + "SJP_REFERRAL", + "BREACH", + "YOUTH", + "APPLICATION" + ] + }, + "gender": { + "description": "The person gender", + "type": "string", + "enum": [ + "MALE", + "FEMALE", + "NOT_KNOWN", + "NOT_SPECIFIED" + ] + }, + "email": { + "type": "string", + "pattern": "^[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$" + }, + "jurisdictionType": { + "type": "string", + "enum": [ + "MAGISTRATES", + "CROWN" + ] + }, + "initiationCode": { + "description": "Indicates how a case is initialised. J-SJP Notice, Q-Requisition, S-Summons, C-Charge, R-Remitted, O-Other, Z-SJP Referral", + "type": "string", + "enum": [ + "J", + "Q", + "S", + "C", + "R", + "O", + "Z" + ] + }, + "hearingLanguage": { + "description": "The language of the hearing", + "enum": [ + "ENGLISH", + "WELSH" + ] + }, + "personTitle": { + "type": "string", + "description": "A person is the base type of a defendant. Defendants title must be constrained to remain compliant with the GOB interface" + }, + "judicialRoleType": { + "type": "string", + "enum": [ + "RECORDER", + "CIRCUIT_JUDGE", + "DISTRICT_JUDGE", + "MAGISTRATE" + ] + }, + "nino": { + "type": "string", + "pattern": "(?!BG)(?!GB)(?!NK)(?!KN)(?!TN)(?!NT)(?!ZZ)(?:[A-CEGHJ-PR-TW-Z][A-CEGHJ-NPR-TW-Z])(?:\\s*\\d\\s*){6}([A-D]|\\s)$" + }, + "ukGovPostCode": { + "description": "UK Gov post code validation following CJS Data Standards", + "type": "string", + "pattern": "^(([gG][iI][rR] {0,}0[aA]{2})|(([aA][sS][cC][nN]|[sS][tT][hH][lL]|[tT][dD][cC][uU]|[bB][bB][nN][dD]|[bB][iI][qQ][qQ]|[fF][iI][qQ][qQ]|[pP][cC][rR][nN]|[sS][iI][qQ][qQ]|[iT][kK][cC][aA]) {0,}1[zZ]{2})|((([a-pr-uwyzA-PR-UWYZ][a-hk-yxA-HK-XY]?[0-9][0-9]?)|(([a-pr-uwyzA-PR-UWYZ][0-9][a-hjkstuwA-HJKSTUW])|([a-pr-uwyzA-PR-UWYZ][a-hk-yA-HK-Y][0-9][abehmnprv-yABEHMNPRV-Y]))) [0-9][abd-hjlnp-uw-zABD-HJLNP-UW-Z]{2}))$", + "maxLength": 8 + }, + "ukGovPostCodeWithOptionalSpace": { + "description": "UK Gov post code validation following CJS Data Standards", + "type": "string", + "pattern": "^(([gG][iI][rR] {0,}0[aA]{2})|(([aA][sS][cC][nN]|[sS][tT][hH][lL]|[tT][dD][cC][uU]|[bB][bB][nN][dD]|[bB][iI][qQ][qQ]|[fF][iI][qQ][qQ]|[pP][cC][rR][nN]|[sS][iI][qQ][qQ]|[iT][kK][cC][aA]) {0,}1[zZ]{2})|((([a-pr-uwyzA-PR-UWYZ][a-hk-yxA-HK-XY]?[0-9][0-9]?)|(([a-pr-uwyzA-PR-UWYZ][0-9][a-hjkstuwA-HJKSTUW])|([a-pr-uwyzA-PR-UWYZ][a-hk-yA-HK-Y][0-9][abehmnprv-yABEHMNPRV-Y]))) {0,}[0-9][abd-hjlnp-uw-zABD-HJLNP-UW-Z]{2}))$", + "maxLength": 8 + }, + "datePattern": { + "type": "string", + "pattern": "^((([\\+-]?\\d{4}(?!\\d{2}\\b))\\-(0[13578]|1[02])\\-(0[1-9]|[12]\\d|3[01]))|(([\\+-]?\\d{4}(?!\\d{2}\\b))\\-(0[13456789]|1[012])\\-(0[1-9]|[12]\\d|30))|(([\\+-]?\\d{4}(?!\\d{2}\\b))\\-02\\-(0[1-9]|1\\d|2[0-8]))|(((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))\\-02\\-29))$" + }, + "judicialRoleTypeSJP": { + "type": "string", + "enum": [ + "MAGISTRATE", + "LEGAL_ADVISER" + ] + }, + "defenceRepresentationFundingType": { + "description": "Indicates the type of funding for a defence representative", + "type": "string", + "enum": [ + "REPRESENTATION_ORDER", + "REPRESENTATION_ORDER_APPLIED_FOR", + "PRIVATE", + "COURT_APPOINTED", + "PRO_BONO" + ] + }, + "date-time": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false } \ No newline at end of file diff --git a/lib/schemas/global/apiJudicialResult.json b/lib/schemas/global/apiJudicialResult.json index 9e1b8a07..63e2330d 100644 --- a/lib/schemas/global/apiJudicialResult.json +++ b/lib/schemas/global/apiJudicialResult.json @@ -194,5 +194,5 @@ "orderedDate", "category" ], - "additionalProperties": false + "additionalProperties": true } diff --git a/spec/fixtures/files/court_application_details/all_fields.json b/spec/fixtures/files/court_application_details/all_fields.json new file mode 100644 index 00000000..d6772a9a --- /dev/null +++ b/spec/fixtures/files/court_application_details/all_fields.json @@ -0,0 +1,108 @@ +{ + "applicationId": "4362f2bc-7aff-462a-a242-0db421aa6a96", + "applicationReference": "RQ249717027", + "applicationStatus": "FINALISED", + "applicationTitle": "Appeal against conviction by a Magistrates' Court to the Crown Court", + "applicationType": "MC80802", + "caseSummary": [ + { + "caseStatus": "ACTIVE", + "prosecutionCaseId": "78307605-1521-466a-b964-67675887f604", + "prosecutionCaseReference": "RQ249717027" + } + ], + "hearingSummary": [ + { + "courtCentre": { + "address": { + "address1": "176A Lavender Hill", + "address2": "London", + "address3": "", + "address4": "", + "postCode": "SW11 1JU" + }, + "code": "B01LY00", + "id": "f8254db1-1683-483e-afb3-b87fde5a0a26", + "name": "Lavender Hill Magistrates' Court", + "roomId": "9e4932f7-97b2-3010-b942-ddd2624e4dd8", + "roomName": "Courtroom 01" + }, + "defendantIds": [ + "a86c42dc-6566-4076-9655-b3a53cd58566" + ], + "hearingDay": [ + { + "hasSharedResults": true, + "listedDurationMinutes": 1, + "listingSequence": 0, + "sittingDay": "2025-02-07T10:00:00.000Z" + } + ], + "hearingId": "769d0056-e160-4aa9-a9d1-821db73aa1ee", + "hearingType": { + "description": "Application", + "id": "3449743b-95d6-4836-8941-57f588b52068" + }, + "jurisdictionType": "MAGISTRATES" + } + ], + "judicialResults": [ + { + "alwaysPublished": false, + "canBeSubjectOfBreach": false, + "canBeSubjectOfVariation": false, + "category": "FINAL", + "cjsCode": "1017", + "courtClerk": { + "firstName": "Erica", + "lastName": "Wilson", + "userId": "a085e359-6069-4694-8820-7810e7dfe762" + }, + "d20": false, + "dvlaCode": "J", + "excludedFromResults": false, + "isAdjournmentResult": false, + "isAvailableForCourtExtract": true, + "isConvictedResult": true, + "isDeleted": false, + "isFinancialResult": false, + "isNewAmendment": true, + "isUnscheduled": false, + "judicialResultId": "1755ac43-585b-49d0-bdcc-e763d4a17c6c", + "judicialResultTypeId": "b9c6047b-fb84-4b12-97a1-2175e4b8bbac", + "label": "Absolute discharge", + "lastSharedDateTime": "2025-02-06", + "level": "O", + "lifeDuration": false, + "orderedDate": "2025-02-07", + "orderedHearingId": "769d0056-e160-4aa9-a9d1-821db73aa1ee", + "policeSubjectLineTitle": "Final Sentence", + "postHearingCustodyStatus": "A", + "preserveActiveOrder": false, + "publishedAsAPrompt": false, + "publishedForNows": false, + "rank": 53800, + "resultText": "AD - Absolute discharge", + "resultWording": "", + "rollUpPrompts": true, + "rootJudicialResultId": "1755ac43-585b-49d0-bdcc-e763d4a17c6c", + "rootJudicialResultTypeId": "b9c6047b-fb84-4b12-97a1-2175e4b8bbac", + "terminatesOffenceProceedings": false, + "urgent": false, + "usergroups": [], + "welshLabel": "Rhyddhad diamod" + } + ], + "receivedDate": "2025-02-06", + "subjectSummary": { + "dateOfNextHearing": "2025-02-07T10:00:00.000Z", + "defendantASN": "2391NX0000489661589D", + "defendantDOB": "1999-02-06", + "defendantFirstName": "Naida", + "defendantLastName": "Daniel", + "masterDefendantId": "a86c42dc-6566-4076-9655-b3a53cd58566", + "offenceSummary": [], + "proceedingsConcluded": false, + "subjectId": "4b463e6a-105b-433b-a88d-057d6e645bfb" + } +} diff --git a/spec/requests/api/internal/v2/court_applications_request_spec.rb b/spec/requests/api/internal/v2/court_applications_request_spec.rb new file mode 100644 index 00000000..a3b67f63 --- /dev/null +++ b/spec/requests/api/internal/v2/court_applications_request_spec.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require "swagger_helper" + +RSpec.describe "api/internal/v2/court_applications", type: :request do + include AuthorisedRequestHelper + + let(:token) { access_token } + let(:court_application_id) { SecureRandom.uuid } + + describe "GET /api/internal/v2/court_applications/{court_application_id}" do + it "raises NotImplementedError" do + expect { + get "/api/internal/v2/court_applications/#{court_application_id}", headers: { "Authorization" => "Bearer #{token.token}" } + }.to raise_error(NotImplementedError) + end + end +end diff --git a/spec/services/common_platform/api/schema_validator_spec.rb b/spec/services/common_platform/api/schema_validator_spec.rb new file mode 100644 index 00000000..22fe2869 --- /dev/null +++ b/spec/services/common_platform/api/schema_validator_spec.rb @@ -0,0 +1,21 @@ +RSpec.describe CommonPlatform::Api::SchemaValidator do + subject(:validate) { described_class.call(schema:, json_response:) } + + let(:schema) do + JSON.parse( + File.read("lib/schemas/api/progression.query.laa.application-laa.json"), + ) + end + + let(:json_response) { JSON.parse(file_fixture("court_application_details/all_fields.json").read) } + + it "validates the response against the schema" do + expect(validate).to be_truthy + end + + it "returns false if the response is invalid" do + json_response["applicationReference"] = nil + + expect(validate).to be_falsey + end +end