Package de.pisa.psa.rst.hdl
Class PsaRstApiEvtHdl
java.lang.Object
de.pisa.psa.rst.hdl.PsaRstApiEvtHdl
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
PsaRstApiEvtHdlIn
,PsaRstApiEvtHdlOut
REST API: event handler
- Since:
- 21.06.2023
- Author:
- weiland
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Highlighting for EUREKA results -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected javax.ws.rs.core.Response
buildResponse
(String json) build the responseprotected de.pisa.psc.srv.dto.PscDto
cloneRecords
(String dto_dsc, Set<String> gid_set, int max) clone records into a data objectvoid
close()
de.pisa.psc.srv.dto.PscDto
fetchContact
(String email, String dto_dsc) fetch a contact based on an email addressprotected javax.ws.rs.core.Response
fetch ERUEKA result and return the JSON responseprotected javax.ws.rs.core.Response
fetchEurekaRecords
(PsaRstApiQue query, Class<? extends PsaRstApiObjBas> object_class) fetch records with the use of EUREKA and return the JSON responsede.pisa.psc.srv.dto.PscDto
fetchIAMContact
(String dto_dsc) fetch a contact based on the IAM email addressprotected de.pisa.psc.srv.dto.PscDto
fetch the record that is defined by the dataobject and GID in the event recordprotected javax.ws.rs.core.Response
fetchRecord
(Class<? extends PsaRstApiObjBas> object_class) fetch a record and return the JSON responseprotected javax.ws.rs.core.Response
fetchRecords
(Class<? extends PsaRstApiObjBas> object_class) fetch records and return the JSON responsefind a contact by the email addressstatic PsaRstApiEvtHdl
getActiveEventHandler
(de.pisa.psc.srv.glb.PscSsn ssn) get the active event handler from a sessionprotected String
get the continuation keygetData()
get the event dataprotected EurekaDtoQuery
get the EUREKA query conditions for the configured data objectprotected PsaRstApiEvtHdl.EurekaHighlighting
get the highlight configuration for the EUREKA searchprotected de.pisa.psa.dto.psa_idx.itf.DocFld
get the field to query with EUREKAprotected String
getExternalCommunicationLanguage
(de.pisa.psc.srv.glb.PscSsn ssn) get the communication language from an external loginprotected String
getFetchRecordKeyField
(de.pisa.psc.srv.dto.PscDto dto) get the key field to search on in fetchRecordprotected de.pisa.psc.srv.dto.PscFld
getField
(de.pisa.psc.srv.dto.PscDto dto, String field_name, List<PsaRstApiMapFld.MapEntry> field_mapping) get the data object field for a JSON field nameprotected String
get the session user from the IAM tokenboolean
are empty values included in the JSON?protected PsaRstApiQue
getQuery()
get the query from the event datade.pisa.psc.srv.glb.PscSsn
getSsn()
get a sessionprotected String
get the user for the database sessionprotected de.pisa.psc.srv.glb.PscSsn
get a SYSTEM sessionabstract javax.ws.rs.core.Response
Handle the eventboolean
check if the session user is based on IAMprotected javax.ws.rs.core.Response
loadRecord
(de.pisa.psc.srv.dto.PscDto dto, int row, Class<? extends PsaRstApiObjBas> object_class) load a record into to a JSON responsemap a query string to a string that can be used by the data objectde.pisa.psc.srv.dto.PscDto
create a new data objectprotected PsaRstApiObjBas
newObject
(Class<? extends PsaRstApiObjBas> object_class) create a new JSON objectprotected <T> PsaRstApiObjLis<T>
create a new result list objectboolean
don't log the eventprotected EurekaResult
queryEureka
(String query, String[] dto_query, String key_001, String key_002, String key_003, PsaRstApiEvtHdl.EurekaHighlighting eureka_highlighting) query the EUREKA indexprotected void
queryEurekaRecords
(PsaRstApiQue query, de.pisa.psc.srv.dto.PscDto dto, de.pisa.psa.dto.PsaRecClo rec_clo, List<PsaRstApiMapFld.MapEntry> field_mapping) set queries for EUREKAprotected de.pisa.psc.srv.dto.PscDto
set the primary key query on a data objectprotected de.pisa.psc.srv.dto.PscDto
queryRecords
(PsaRstApiQue query, Class<?> object_class) set the query on a data object based on the request queryprotected void
queryRecordsAddSort
(PsaRstApiQue query, de.pisa.psc.srv.dto.PscDto dto, List<PsaRstApiMapFld.MapEntry> field_mapping) Add the sorting to a data objectprotected void
queryRecordsSetQuery
(PsaRstApiQue query, de.pisa.psc.srv.dto.PscDto dto, List<PsaRstApiMapFld.MapEntry> field_mapping) Set the queries on a data objectstatic void
setActiveEventHandler
(de.pisa.psc.srv.glb.PscSsn ssn, PsaRstApiEvtHdl handler) set the active event handler for a sessionprotected void
set the event language based on the IAM loginvoid
setJsonIncludeEmpty
(boolean include) include empty values in the JSON?convert an object to JSON
-
Field Details
-
Max_Records
protected int Max_Recordsthe maximum number of records that are returned -
Default_User
default session user -
Default_External_Language
the default language for external logins -
Force_IAM_User
protected boolean Force_IAM_Userif IAM is used, the email should belong to an unique user
-
-
Constructor Details
-
PsaRstApiEvtHdl
Constructor- Parameters:
data
- event data
-
-
Method Details
-
handleEvent
Handle the event- Returns:
- response
- Throws:
Exception
-
setActiveEventHandler
set the active event handler for a session- Parameters:
ssn
- sessionhandler
-
-
getActiveEventHandler
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
get a session- Returns:
- session
- Throws:
Exception
-
getSysSsn
get a SYSTEM session- Returns:
- session
- Throws:
Exception
-
getSsnUsr
get the user for the database session- Returns:
- user name
- Throws:
Exception
-
getIAMUser
get the session user from the IAM token- Returns:
- user name, null if no IAM token used
- Throws:
Exception
-
setExternalLanguage
set the event language based on the IAM login- Throws:
Exception
-
getExternalCommunicationLanguage
get the communication language from an external login- Parameters:
ssn
- session- Returns:
- language identifier
- Throws:
Exception
-
findEmail
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
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:
Exception
- if the contact was not found or is ambiguous
-
fetchContact
fetch a contact based on an email address- Parameters:
email
- email address to searchdto_dsc
- descriptor of the contact data object- Returns:
- contact data abject with one row
- Throws:
Exception
- if the contact was not found or is ambiguous
-
cloneRecords
protected de.pisa.psc.srv.dto.PscDto cloneRecords(String dto_dsc, Set<String> gid_set, int max) throws Exception clone records into a data object- Parameters:
dto_dsc
- the descriptor of the data objectgid_set
- a set of PSC_GIDsmax
- maximum number of records to clone- Returns:
- the data object with the records
- Throws:
Exception
-
getData
get the event data- Returns:
- data
-
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
convert an object to JSON- Parameters:
object
- object to convert- Returns:
- JSON
- Throws:
Exception
-
close
- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
- See Also:
-
newDto
create a new data object- Parameters:
dsc
- descriptor of the data object- Returns:
- data object
- Throws:
Exception
-
newObject
create a new JSON object- Parameters:
object_class
- class of the JSON object- Returns:
- object
- Throws:
Exception
-
fetchRecord
fetch the record that is defined by the dataobject and GID in the event record- Returns:
- dataobject with the record
- Throws:
Exception
javax.ws.rs.WebApplicationException
- is the record was not found or more than one record was found
-
getFetchRecordKeyField
get the key field to search on in fetchRecord- Parameters:
dto
- data object- Returns:
- field descriptor
-
fetchRecord
protected javax.ws.rs.core.Response fetchRecord(Class<? extends PsaRstApiObjBas> object_class) throws Exception fetch a record and return the JSON response- Parameters:
object_class
- class of the JSON object- Returns:
- response
- Throws:
Exception
-
loadRecord
protected javax.ws.rs.core.Response loadRecord(de.pisa.psc.srv.dto.PscDto dto, int row, Class<? extends PsaRstApiObjBas> object_class) throws Exception load a record into to a JSON response- Parameters:
dto
- data objectrow
- row to loadobject_class
- class of the JSON object- Returns:
- response
- Throws:
Exception
-
buildResponse
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, Class<?> object_class) throws Exception set the query on a data object based on the request query- Parameters:
query
- queryobject_class
- class of JSON object- Returns:
- data object with a query and an order
- Throws:
Exception
-
queryRecordsSetQuery
protected void queryRecordsSetQuery(PsaRstApiQue query, de.pisa.psc.srv.dto.PscDto dto, List<PsaRstApiMapFld.MapEntry> field_mapping) throws Exception Set the queries on a data object- Parameters:
query
- querydto
- data objectfield_mapping
- field mapping- Throws:
Exception
-
mapQuery
protected Optional<String> mapQuery(de.pisa.psc.srv.dto.PscDto dto, de.pisa.psc.srv.dto.PscFld field, String query) throws Exception map a query string to a string that can be used by the data object- Parameters:
dto
- data objectfield
- fieldquery
- query- Returns:
- mapped query
- Throws:
Exception
-
queryRecordsAddSort
protected void queryRecordsAddSort(PsaRstApiQue query, de.pisa.psc.srv.dto.PscDto dto, List<PsaRstApiMapFld.MapEntry> field_mapping) throws de.pisa.psc.srv.glb.PscExc Add the sorting to a data object- Parameters:
query
- querydto
- data objectfield_mapping
- field mapping- Throws:
de.pisa.psc.srv.glb.PscExc
-
queryRecord
set the primary key query on a data object- Returns:
- new data object with the query
- Throws:
Exception
-
getQuery
get the query from the event data- Returns:
- query
- Throws:
Exception
-
getContinuation
get the continuation key- Returns:
- key
- Throws:
Exception
-
fetchRecords
protected javax.ws.rs.core.Response fetchRecords(Class<? extends PsaRstApiObjBas> object_class) throws Exception fetch records and return the JSON response- Parameters:
object_class
- class of the JSON object- Returns:
- response
- Throws:
Exception
-
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, Class<? extends PsaRstApiObjBas> object_class) throws Exception fetch records with the use of EUREKA and return the JSON response- Parameters:
query
- queryobject_class
- class of the JSON object- Returns:
- response
- Throws:
Exception
-
queryEurekaRecords
protected void queryEurekaRecords(PsaRstApiQue query, de.pisa.psc.srv.dto.PscDto dto, de.pisa.psa.dto.PsaRecClo rec_clo, List<PsaRstApiMapFld.MapEntry> field_mapping) throws Exception set queries for EUREKA- Parameters:
query
- querydto
- target data objectrec_clo
- record clonerfield_mapping
- field mapping- Throws:
Exception
-
getEurekaHighlighting
get the highlight configuration for the EUREKA search- Returns:
- configuration
- Throws:
Exception
-
fetchEureka
fetch ERUEKA result and return the JSON response- Returns:
- response
- Throws:
Exception
-
getEurekaDtoQuery
get the EUREKA query conditions for the configured data object- Returns:
- query
- Throws:
Exception
-
queryEureka
protected EurekaResult queryEureka(String query, String[] dto_query, String key_001, String key_002, String key_003, PsaRstApiEvtHdl.EurekaHighlighting eureka_highlighting) throws Exception query the EUREKA index- Parameters:
query
- query stringdto_query
- dataobject querykey_001
- KEY_001 querykey_002
- KEY_002 querykey_003
- KEY_003 queryeureka_highlighting
- highlighting configuration for the occurrences in the preview- Returns:
- search result
- Throws:
Exception
-
getEurekaQueryField
protected de.pisa.psa.dto.psa_idx.itf.DocFld getEurekaQueryField()get the field to query with EUREKA- Returns:
- document field
-
getField
protected de.pisa.psc.srv.dto.PscFld getField(de.pisa.psc.srv.dto.PscDto dto, String field_name, List<PsaRstApiMapFld.MapEntry> field_mapping) get the data object field for a JSON field name- Parameters:
dto
- data objectfield_name
- JSON field namefield_mapping
- field mapping- Returns:
- field
- Throws:
javax.ws.rs.ClientErrorException
- if the field was not found
-