class EtFakeCcd::Service::DocumentStoreApp

Private Instance Methods

forbidden_error_for(r) click to toggle source
# File lib/et_fake_ccd/service/document_store_app.rb, line 138
def forbidden_error_for(r)
  j = {"timestamp":"2019-07-01T07:46:35.405+0000","status":403,"error":"Forbidden","message":"Access Denied","path": r.path}
  JSON.generate(j)
end
not_found_error_for(r) click to toggle source
# File lib/et_fake_ccd/service/document_store_app.rb, line 143
def not_found_error_for(r)
  j = {"timestamp":"2019-07-01T07:46:35.405+0000","status":404,"error":"Not Found","message":"Not Found","path": r.path}
  JSON.generate(j)
end
render_document(id:, document:, documents_root:) click to toggle source
# File lib/et_fake_ccd/service/document_store_app.rb, line 56
def render_document(id:, document:, documents_root:)
  now = Time.now.strftime("%Y-%m-%dT%H:%M:%S%z")
  j = {
    "_embedded": {
      "documents": [
        {
          "size": document['size'],
          "mimeType": document['type'],
          "originalDocumentName": document['filename'],
          "createdBy": "42f46280-24b4-4f4d-b93c-8c92cbb2b93f",
          "lastModifiedBy": "42f46280-24b4-4f4d-b93c-8c92cbb2b93f",
          "modifiedOn": now,
          "createdOn": now,
          "classification": document['classification'],
          "_links": {
            "self": {
              "href": "#{documents_root}/#{id}"
            },
            "binary": {
              "href": "#{documents_root}/#{id}/binary"
            },
            "thumbnail": {
              "href": "#{documents_root}/#{id}/thumbnail"
            }
          },
          "_embedded": {
            "allDocumentVersions": {
              "_embedded": {
                "documentVersions": [
                  {
                    "size": document['size'],
                    "mimeType": document['type'],
                    "originalDocumentName": document['filename'],
                    "createdBy": "42f46280-24b4-4f4d-b93c-8c92cbb2b93f",
                    "createdOn": now,
                    "_links": {
                      "document": {
                        "href": "#{documents_root}/#{id}"
                      },
                      "self": {
                        "href": "#{documents_root}/#{id}/versions/ac711770-6681-4fd8-b662-f7f54ea7a27d"
                      },
                      "binary": {
                        "href": "#{documents_root}/#{id}/versions/ac711770-6681-4fd8-b662-f7f54ea7a27d/binary"
                      },
                      "thumbnail": {
                        "href": "#{documents_root}/#{id}/versions/ac711770-6681-4fd8-b662-f7f54ea7a27d/thumbnail"
                      },
                      "migrate": {
                        "href": "#{documents_root}/#{id}/versions/ac711770-6681-4fd8-b662-f7f54ea7a27d/migrate"
                      }
                    }
                  }
                ]
              }
            }
          }
        }
      ]
    }
  }
  JSON.generate(j)
end
render_error_for(command, request) click to toggle source
# File lib/et_fake_ccd/service/document_store_app.rb, line 120
def render_error_for(command, request)
  j = {
    "exception": "uk.gov.hmcts.ccd.endpoint.exceptions.CaseValidationException",
    "timestamp": "2019-07-01T16:02:28.045",
    "status": 422,
    "error": "Unprocessable Entity",
    "message": "Document validation failed",
    "path": request.path,
    "details": {
      "field_errors": command.errors.details[:data].map {|e| e[:field_error]}
    },
    "callbackErrors": nil,
    "callbackWarnings": nil
  }

  JSON.generate(j)
end
upload_document(request) click to toggle source
# File lib/et_fake_ccd/service/document_store_app.rb, line 49
def upload_document(request)
  file = request.params['files']
  id = ::EtFakeCcd::DocumentStoreService.store_file filename: file[:filename], type: file[:type], file: file[:tempfile], classification: request.params['classification']
  document = ::EtFakeCcd::DocumentStoreService.find_by_id(id)
  render_document id: id, document: document, documents_root: request.url
end