CDR Tickets

Issue Number 4577
Summary [Drupal CMS] Implement a new Python class in the cdrapi.publishing module
Created 2019-02-25 14:01:24
Issue Type Task
Submitted By Kline, Bob (NIH/NCI) [C]
Assigned To Kline, Bob (NIH/NCI) [C]
Status Closed
Resolved 2019-02-27 06:08:03
Resolution Fixed
Path /home/bkline/backups/jira/ocecdr/issue.240712
Description

We need a class to communicate with the PDQ APIs in the Drupal CMS, called something like DrupalClient, providing functionality comparable to that provided by the cdr2gk Python module. Part of https://github.com/NCIOCPL/cgov-digital-platform/issues/825 epic.

Comment entered 2019-02-27 06:08:03 by Kline, Bob (NIH/NCI) [C]
Comment entered 2019-02-27 07:16:11 by Kline, Bob (NIH/NCI) [C]
Help on class DrupalClient in cdrapi.publishing:

cdrapi.publishing.DrupalClient = class DrupalClient(builtins.object)
 |  Client end of the PDQ RESTful APIs in the Drupal CMS
 |
 |  Provides functionality comparable to that provided for communicating
 |  with the legacy GateKeeper APIs in the `cdr2gk` module.
 |
 |  Class constants:
 |      BATCH_SIZE - maximum number of documents we can set to `published`
 |                   in a single chunk
 |      URI_PATH - used for routing of PDQ RESTful API requests
 |      TYPES - names used for the types of PDQ documents we publish
 |
 |  Methods defined here:
 |
 |  __init__(self, session, **opts)
 |      Perform any necessary setup for communicating with the PDQ APIs
 |
 |      Required positional argument:
 |        session - information about the account in control
 |
 |      Optional keyword arguments:
 |        auth - override for basic authorization credentials pair
 |        base - e.g., "https://ncigovcddev.prod.acquia-sites.com"
 |        logger - override for logging object
 |        batch_size - override for number to mark `published` at once
 |
 |  list(self)
 |      Fetch catalog of PDQ content in Drupal CMS
 |
 |      Return:
 |        sequence of `CatalogEntry` objects
 |
 |  lookup(self, cdr_id)
 |      Fetch the Drupal ID for document's node (if it exists)
 |
 |      Pass:
 |        cdr_id - integer for PDQ document
 |
 |      Return:
 |        integer for unique Drupal node ID or None
 |
 |  publish(self, documents)
 |      Ask the CMS to set the specified documents to the `published` state.
 |
 |      We have to break the batch into chunks small enough that memory
 |      usage will not be an issue.
 |
 |      Pass:
 |        documents - sequence of tuples for the PDQ documents which should
 |                    be switched from `draft` to `published` state, each
 |                    tuple containing:
 |                        - integer for the document's unique CDR ID
 |                        - integer for the Drupal node for the document
 |                        - language code ('en' or 'es')
 |                    for example:
 |                        [
 |                            (257994, 231, "en"),
 |                            (257995, 241, "en"),
 |                            (448617, 226, "es"),
 |                            (742114, 136, "en"),
 |                        ]
 |
 |      Return:
 |        possibly empty dictionary of error messages, indexed by the
 |        CDR ID for documents which failed
 |
 |  push(self, values)
 |      Send a PDQ document to the Drupal CMS
 |
 |      The document will be stored in the `draft` state, and must be
 |      released to the `published` state at the end of the job in batch
 |      with the other PDQ documents published by the job (see the
 |      `publish()` method).
 |
 |      Pass:
 |        values - dictionary of field values keyed by field name
 |
 |      Return:
 |        integer for the ID of the node in which the document is stored
 |
 |  remove(self, cdr_id)
 |      Drop a PDQ document from the Drupal CMS
 |
 |      Pass:
 |        cdr_id - integer for the PDQ document to be deleted
 |
 |      Throws:
 |        `Exception` if delete request failed
 |
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |
 |  auth
 |      Basic authorization credentials pair
 |
 |  base
 |      Front portion of the PDQ API URL
 |
 |  batch_size
 |      The number of documents to be marked `published` at once
 |
 |  logger
 |      Object for recording what we do
 |
 |  session
 |      Reference to object representing the current login
 |
 |  types
 |      Mapping from Drupal class for content to API URL tail
 |
 |  ----------------------------------------------------------------------
 |  CatalogEntry = <class 'cdrapi.publishing.DrupalClient.CatalogEntry'>
 |      Information about a PDQ document in the Drupal CMS
 |      Members:
 |        cdr_id - integer ID for PDQ document
 |        nid - integer ID for Drupal node
 |        vid - integer ID for Drupal revision
 |        langcode - "en" or "es"
 |        type - e.g., "pdq_drug_information_summary"
 |        created - when the Drupal node was first created
 |        changed - when the document's values were last modified

Elapsed: 0:00:00.001476