Class PsaRstApiEvtHdl

  • All Implemented Interfaces:
    java.lang.AutoCloseable
    Direct Known Subclasses:
    PsaRstApiEvtHdlIn, PsaRstApiEvtHdlOut

    public abstract class PsaRstApiEvtHdl
    extends java.lang.Object
    implements java.lang.AutoCloseable
    REST API: event handler
    Since:
    21.06.2023
    Author:
    weiland
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.lang.String Default_External_Language
      the default language for external logins
      protected java.lang.String Default_User
      default session user
      protected boolean Force_IAM_User
      if IAM is used, the email should belong to an unique user
      protected int Max_Records
      the maximum number of records that are returned
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected javax.ws.rs.core.Response buildResponse​(java.lang.String json)
      build the response
      protected de.pisa.psc.srv.dto.PscDto cloneRecords​(java.lang.String dto_dsc, java.util.Set<java.lang.String> gid_set, int max)
      clone records into a data object
      void close()
      de.pisa.psc.srv.dto.PscDto fetchContact​(java.lang.String email, java.lang.String dto_dsc)
      fetch a contact based on an email address
      protected javax.ws.rs.core.Response fetchEureka()
      fetch ERUEKA result and return the JSON response
      protected javax.ws.rs.core.Response fetchEurekaRecords​(PsaRstApiQue query, java.lang.Class<? extends PsaRstApiObjBas> object_class)
      fetch records with the use of EUREKA and return the JSON response
      de.pisa.psc.srv.dto.PscDto fetchIAMContact​(java.lang.String dto_dsc)
      fetch a contact based on the IAM email address
      protected de.pisa.psc.srv.dto.PscDto fetchRecord()
      fetch the record that is defined by the dataobject and GID in the event record
      protected javax.ws.rs.core.Response fetchRecord​(java.lang.Class<? extends PsaRstApiObjBas> object_class)
      fetch a record and return the JSON response
      protected javax.ws.rs.core.Response fetchRecords​(java.lang.Class<? extends PsaRstApiObjBas> object_class)
      fetch records and return the JSON response
      java.util.Set<java.lang.String> findEmail​(java.lang.String email)
      find a contact by the email address
      static PsaRstApiEvtHdl getActiveEventHandler​(de.pisa.psc.srv.glb.PscSsn ssn)
      get the active event handler from a session
      protected java.lang.String getContinuation()
      get the continuation key
      PsaRstApiEvtHdlDat getData()
      get the event data
      protected EurekaDtoQuery getEurekaDtoQuery()
      get the EUREKA query conditions for the configured data object
      protected java.lang.String getExternalCommunicationLanguage​(de.pisa.psc.srv.glb.PscSsn ssn)
      get the communication language from an external login
      protected java.lang.String getFetchRecordKeyField​(de.pisa.psc.srv.dto.PscDto dto)
      get the key field to search on in fetchRecord
      protected de.pisa.psc.srv.dto.PscFld getField​(de.pisa.psc.srv.dto.PscDto dto, java.lang.String field_name, java.util.List<PsaRstApiMapFld.MapEntry> field_mapping)
      get the data object field for a JSON field name
      protected java.lang.String getIAMUser()
      get the session user from the IAM token
      boolean getJsonIncludeEmpty()
      are empty values included in the JSON?
      protected PsaRstApiQue getQuery()
      get the query from the event data
      de.pisa.psc.srv.glb.PscSsn getSsn()
      get a session
      protected java.lang.String getSsnUsr()
      get the user for the database session
      protected de.pisa.psc.srv.glb.PscSsn getSysSsn()
      get a SYSTEM session
      abstract javax.ws.rs.core.Response handleEvent()
      Handle the event
      boolean isIAMUser()
      check if the session user is based on IAM
      protected javax.ws.rs.core.Response loadRecord​(de.pisa.psc.srv.dto.PscDto dto, int row, java.lang.Class<? extends PsaRstApiObjBas> object_class)
      load a record into to a JSON response
      de.pisa.psc.srv.dto.PscDto newDto​(java.lang.String dsc)
      create a new data object
      protected PsaRstApiObjBas newObject​(java.lang.Class<? extends PsaRstApiObjBas> object_class)
      create a new JSON object
      protected <T> PsaRstApiObjLis<T> newPsaRstApiObjLis()
      create a new result list object
      boolean noEventLogging()
      don't log the event
      protected EurekaResult queryEureka​(java.lang.String query, java.lang.String[] dto_query, java.lang.String key_001, java.lang.String key_002, java.lang.String key_003, boolean use_hig_lig)
      query the EUREKA index
      protected void queryEurekaRecords​(PsaRstApiQue query, de.pisa.psc.srv.dto.PscDto dto, de.pisa.psa.dto.PsaRecClo rec_clo, java.util.List<PsaRstApiMapFld.MapEntry> field_mapping)
      set queries for EUREKA
      protected de.pisa.psc.srv.dto.PscDto queryRecord()
      set the primary key query on a data object
      protected de.pisa.psc.srv.dto.PscDto queryRecords​(PsaRstApiQue query, java.lang.Class<?> object_class)
      set the query on a data object based on the request query
      static void setActiveEventHandler​(de.pisa.psc.srv.glb.PscSsn ssn, PsaRstApiEvtHdl handler)
      set the active event handler for a session
      protected void setExternalLanguage()
      set the event language based on the IAM login
      void setJsonIncludeEmpty​(boolean include)
      include empty values in the JSON?
      java.lang.String toJson​(java.lang.Object object)
      convert an object to JSON
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • Max_Records

        protected int Max_Records
        the maximum number of records that are returned
      • Default_User

        protected java.lang.String Default_User
        default session user
      • Default_External_Language

        protected java.lang.String Default_External_Language
        the default language for external logins
      • Force_IAM_User

        protected boolean Force_IAM_User
        if IAM is used, the email should belong to an unique user
    • Constructor Detail

      • PsaRstApiEvtHdl

        protected PsaRstApiEvtHdl​(PsaRstApiEvtHdlDat data)
        Constructor
        Parameters:
        data - event data
    • Method Detail

      • handleEvent

        public abstract javax.ws.rs.core.Response handleEvent()
                                                       throws java.lang.Exception
        Handle the event
        Returns:
        response
        Throws:
        java.lang.Exception
      • setActiveEventHandler

        public static void setActiveEventHandler​(de.pisa.psc.srv.glb.PscSsn ssn,
                                                 PsaRstApiEvtHdl handler)
        set the active event handler for a session
        Parameters:
        ssn - session
        handler -
      • getActiveEventHandler

        public static PsaRstApiEvtHdl getActiveEventHandler​(de.pisa.psc.srv.glb.PscSsn ssn)
        get the active event handler from a session
        Parameters:
        ssn - session
        Returns:
        handler instance. null if currently no active event handler
      • noEventLogging

        public boolean noEventLogging()
        don't log the event
        Returns:
        if true the event and all logs will be deleted
      • getSsn

        public de.pisa.psc.srv.glb.PscSsn getSsn()
                                          throws java.lang.Exception
        get a session
        Returns:
        session
        Throws:
        java.lang.Exception
      • getSysSsn

        protected de.pisa.psc.srv.glb.PscSsn getSysSsn()
                                                throws java.lang.Exception
        get a SYSTEM session
        Returns:
        session
        Throws:
        java.lang.Exception
      • getSsnUsr

        protected java.lang.String getSsnUsr()
                                      throws java.lang.Exception
        get the user for the database session
        Returns:
        user name
        Throws:
        java.lang.Exception
      • getIAMUser

        protected java.lang.String getIAMUser()
                                       throws java.lang.Exception
        get the session user from the IAM token
        Returns:
        user name, null if no IAM token used
        Throws:
        java.lang.Exception
      • setExternalLanguage

        protected void setExternalLanguage()
                                    throws java.lang.Exception
        set the event language based on the IAM login
        Throws:
        java.lang.Exception
      • getExternalCommunicationLanguage

        protected java.lang.String getExternalCommunicationLanguage​(de.pisa.psc.srv.glb.PscSsn ssn)
                                                             throws java.lang.Exception
        get the communication language from an external login
        Parameters:
        ssn - session
        Returns:
        language identifier
        Throws:
        java.lang.Exception
      • findEmail

        public java.util.Set<java.lang.String> findEmail​(java.lang.String email)
        find a contact by the email address
        Parameters:
        email - email to search
        Returns:
        set of contact gids that are associated to this email address
      • isIAMUser

        public boolean isIAMUser()
        check if the session user is based on IAM
        Returns:
        true if IAM user
      • fetchIAMContact

        public de.pisa.psc.srv.dto.PscDto fetchIAMContact​(java.lang.String dto_dsc)
                                                   throws java.lang.Exception
        fetch a contact based on the IAM email address
        Parameters:
        dto_dsc - descriptor of the contact data object
        Returns:
        contact data abject with one row
        Throws:
        java.lang.Exception - if the contact was not found or is ambiguous
      • fetchContact

        public de.pisa.psc.srv.dto.PscDto fetchContact​(java.lang.String email,
                                                       java.lang.String dto_dsc)
                                                throws java.lang.Exception
        fetch a contact based on an email address
        Parameters:
        email - email address to search
        dto_dsc - descriptor of the contact data object
        Returns:
        contact data abject with one row
        Throws:
        java.lang.Exception - if the contact was not found or is ambiguous
      • cloneRecords

        protected de.pisa.psc.srv.dto.PscDto cloneRecords​(java.lang.String dto_dsc,
                                                          java.util.Set<java.lang.String> gid_set,
                                                          int max)
                                                   throws java.lang.Exception
        clone records into a data object
        Parameters:
        dto_dsc - the descriptor of the data object
        gid_set - a set of PSC_GIDs
        max - maximum number of records to clone
        Returns:
        the data object with the records
        Throws:
        java.lang.Exception
      • setJsonIncludeEmpty

        public void setJsonIncludeEmpty​(boolean include)
        include empty values in the JSON?
        Parameters:
        include - true to include empty values (default=false)
      • getJsonIncludeEmpty

        public boolean getJsonIncludeEmpty()
        are empty values included in the JSON?
        Returns:
        true if empty values are included
      • toJson

        public java.lang.String toJson​(java.lang.Object object)
                                throws java.lang.Exception
        convert an object to JSON
        Parameters:
        object - object to convert
        Returns:
        JSON
        Throws:
        java.lang.Exception
      • close

        public void close()
                   throws java.lang.Exception
        Specified by:
        close in interface java.lang.AutoCloseable
        Throws:
        java.lang.Exception
        See Also:
        AutoCloseable.close()
      • newDto

        public de.pisa.psc.srv.dto.PscDto newDto​(java.lang.String dsc)
                                          throws java.lang.Exception
        create a new data object
        Parameters:
        dsc - descriptor of the data object
        Returns:
        data object
        Throws:
        java.lang.Exception
      • newObject

        protected PsaRstApiObjBas newObject​(java.lang.Class<? extends PsaRstApiObjBas> object_class)
                                     throws java.lang.Exception
        create a new JSON object
        Parameters:
        object_class - class of the JSON object
        Returns:
        object
        Throws:
        java.lang.Exception
      • fetchRecord

        protected de.pisa.psc.srv.dto.PscDto fetchRecord()
                                                  throws java.lang.Exception
        fetch the record that is defined by the dataobject and GID in the event record
        Returns:
        dataobject with the record
        Throws:
        java.lang.Exception
        javax.ws.rs.WebApplicationException - is the record was not found or more than one record was found
      • getFetchRecordKeyField

        protected java.lang.String getFetchRecordKeyField​(de.pisa.psc.srv.dto.PscDto dto)
        get the key field to search on in fetchRecord
        Parameters:
        dto - data object
        Returns:
        field descriptor
      • fetchRecord

        protected javax.ws.rs.core.Response fetchRecord​(java.lang.Class<? extends PsaRstApiObjBas> object_class)
                                                 throws java.lang.Exception
        fetch a record and return the JSON response
        Parameters:
        object_class - class of the JSON object
        Returns:
        response
        Throws:
        java.lang.Exception
      • loadRecord

        protected javax.ws.rs.core.Response loadRecord​(de.pisa.psc.srv.dto.PscDto dto,
                                                       int row,
                                                       java.lang.Class<? extends PsaRstApiObjBas> object_class)
                                                throws java.lang.Exception
        load a record into to a JSON response
        Parameters:
        dto - data object
        row - row to load
        object_class - class of the JSON object
        Returns:
        response
        Throws:
        java.lang.Exception
      • buildResponse

        protected javax.ws.rs.core.Response buildResponse​(java.lang.String json)
        build the response
        Parameters:
        json - entity data
        Returns:
        a 200 OK status with an application/json entity
      • queryRecords

        protected de.pisa.psc.srv.dto.PscDto queryRecords​(PsaRstApiQue query,
                                                          java.lang.Class<?> object_class)
                                                   throws java.lang.Exception
        set the query on a data object based on the request query
        Parameters:
        query - query
        object_class - class of JSON object
        Returns:
        data object with a query and an order
        Throws:
        java.lang.Exception
      • queryRecord

        protected de.pisa.psc.srv.dto.PscDto queryRecord()
                                                  throws java.lang.Exception
        set the primary key query on a data object
        Returns:
        new data object with the query
        Throws:
        java.lang.Exception
      • getQuery

        protected PsaRstApiQue getQuery()
                                 throws java.lang.Exception
        get the query from the event data
        Returns:
        query
        Throws:
        java.lang.Exception
      • getContinuation

        protected java.lang.String getContinuation()
                                            throws java.lang.Exception
        get the continuation key
        Returns:
        key
        Throws:
        java.lang.Exception
      • fetchRecords

        protected javax.ws.rs.core.Response fetchRecords​(java.lang.Class<? extends PsaRstApiObjBas> object_class)
                                                  throws java.lang.Exception
        fetch records and return the JSON response
        Parameters:
        object_class - class of the JSON object
        Returns:
        response
        Throws:
        java.lang.Exception
      • newPsaRstApiObjLis

        protected <T> PsaRstApiObjLis<T> newPsaRstApiObjLis()
        create a new result list object
        Type Parameters:
        T - type of the objects in the list
        Returns:
        list
      • fetchEurekaRecords

        protected javax.ws.rs.core.Response fetchEurekaRecords​(PsaRstApiQue query,
                                                               java.lang.Class<? extends PsaRstApiObjBas> object_class)
                                                        throws java.lang.Exception
        fetch records with the use of EUREKA and return the JSON response
        Parameters:
        query - query
        object_class - class of the JSON object
        Returns:
        response
        Throws:
        java.lang.Exception
      • queryEurekaRecords

        protected void queryEurekaRecords​(PsaRstApiQue query,
                                          de.pisa.psc.srv.dto.PscDto dto,
                                          de.pisa.psa.dto.PsaRecClo rec_clo,
                                          java.util.List<PsaRstApiMapFld.MapEntry> field_mapping)
                                   throws java.lang.Exception
        set queries for EUREKA
        Parameters:
        query - query
        dto - target data object
        rec_clo - record cloner
        field_mapping - field mapping
        Throws:
        java.lang.Exception
      • fetchEureka

        protected javax.ws.rs.core.Response fetchEureka()
                                                 throws java.lang.Exception
        fetch ERUEKA result and return the JSON response
        Returns:
        response
        Throws:
        java.lang.Exception
      • getEurekaDtoQuery

        protected EurekaDtoQuery getEurekaDtoQuery()
                                            throws java.lang.Exception
        get the EUREKA query conditions for the configured data object
        Returns:
        query
        Throws:
        java.lang.Exception
      • queryEureka

        protected EurekaResult queryEureka​(java.lang.String query,
                                           java.lang.String[] dto_query,
                                           java.lang.String key_001,
                                           java.lang.String key_002,
                                           java.lang.String key_003,
                                           boolean use_hig_lig)
                                    throws java.lang.Exception
        query the EUREKA index
        Parameters:
        query - query string
        dto_query - dataobject query
        key_001 - KEY_001 query
        key_002 - KEY_002 query
        key_003 - KEY_003 query
        use_hig_lig - use highlighting of the occurrences in the preview?
        Returns:
        search result
        Throws:
        java.lang.Exception
      • getField

        protected de.pisa.psc.srv.dto.PscFld getField​(de.pisa.psc.srv.dto.PscDto dto,
                                                      java.lang.String field_name,
                                                      java.util.List<PsaRstApiMapFld.MapEntry> field_mapping)
        get the data object field for a JSON field name
        Parameters:
        dto - data object
        field_name - JSON field name
        field_mapping - field mapping
        Returns:
        field
        Throws:
        javax.ws.rs.ClientErrorException - if the field was not found