Package de.pisa.psa.rst.hdl
Class PsaRstApiEvtHdl
- java.lang.Object
-
- de.pisa.psa.rst.hdl.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 loginsprotected java.lang.String
Default_User
default session userprotected boolean
Force_IAM_User
if IAM is used, the email should belong to an unique userprotected int
Max_Records
the maximum number of records that are returned
-
Constructor Summary
Constructors Modifier Constructor Description protected
PsaRstApiEvtHdl(PsaRstApiEvtHdlDat data)
Constructor
-
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 responseprotected 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 objectvoid
close()
de.pisa.psc.srv.dto.PscDto
fetchContact(java.lang.String email, java.lang.String dto_dsc)
fetch a contact based on an email addressprotected javax.ws.rs.core.Response
fetchEureka()
fetch ERUEKA result and return the JSON responseprotected 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 responsede.pisa.psc.srv.dto.PscDto
fetchIAMContact(java.lang.String dto_dsc)
fetch a contact based on the IAM email addressprotected de.pisa.psc.srv.dto.PscDto
fetchRecord()
fetch the record that is defined by the dataobject and GID in the event recordprotected javax.ws.rs.core.Response
fetchRecord(java.lang.Class<? extends PsaRstApiObjBas> object_class)
fetch a record and return the JSON responseprotected javax.ws.rs.core.Response
fetchRecords(java.lang.Class<? extends PsaRstApiObjBas> object_class)
fetch records and return the JSON responsejava.util.Set<java.lang.String>
findEmail(java.lang.String email)
find a contact by the email addressstatic PsaRstApiEvtHdl
getActiveEventHandler(de.pisa.psc.srv.glb.PscSsn ssn)
get the active event handler from a sessionprotected java.lang.String
getContinuation()
get the continuation keyPsaRstApiEvtHdlDat
getData()
get the event dataprotected EurekaDtoQuery
getEurekaDtoQuery()
get the EUREKA query conditions for the configured data objectprotected java.lang.String
getExternalCommunicationLanguage(de.pisa.psc.srv.glb.PscSsn ssn)
get the communication language from an external loginprotected java.lang.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, java.lang.String field_name, java.util.List<PsaRstApiMapFld.MapEntry> field_mapping)
get the data object field for a JSON field nameprotected java.lang.String
getIAMUser()
get the session user from the IAM tokenboolean
getJsonIncludeEmpty()
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 java.lang.String
getSsnUsr()
get the user for the database sessionprotected de.pisa.psc.srv.glb.PscSsn
getSysSsn()
get a SYSTEM sessionabstract javax.ws.rs.core.Response
handleEvent()
Handle the eventboolean
isIAMUser()
check if the session user is based on IAMprotected 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 responsede.pisa.psc.srv.dto.PscDto
newDto(java.lang.String dsc)
create a new data objectprotected PsaRstApiObjBas
newObject(java.lang.Class<? extends PsaRstApiObjBas> object_class)
create a new JSON objectprotected <T> PsaRstApiObjLis<T>
newPsaRstApiObjLis()
create a new result list objectboolean
noEventLogging()
don't log the eventprotected 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 indexprotected 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 EUREKAprotected de.pisa.psc.srv.dto.PscDto
queryRecord()
set the primary key query on a data objectprotected 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 querystatic void
setActiveEventHandler(de.pisa.psc.srv.glb.PscSsn ssn, PsaRstApiEvtHdl handler)
set the active event handler for a sessionprotected void
setExternalLanguage()
set the event language based on the IAM loginvoid
setJsonIncludeEmpty(boolean include)
include empty values in the JSON?java.lang.String
toJson(java.lang.Object object)
convert an object to JSON
-
-
-
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
- sessionhandler
-
-
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 searchdto_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 objectgid_set
- a set of PSC_GIDsmax
- maximum number of records to clone- Returns:
- the data object with the records
- Throws:
java.lang.Exception
-
getData
public PsaRstApiEvtHdlDat 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
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 interfacejava.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 objectrow
- row to loadobject_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
- queryobject_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
- queryobject_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
- querydto
- target data objectrec_clo
- record clonerfield_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 stringdto_query
- dataobject querykey_001
- KEY_001 querykey_002
- KEY_002 querykey_003
- KEY_003 queryuse_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 objectfield_name
- JSON field namefield_mapping
- field mapping- Returns:
- field
- Throws:
javax.ws.rs.ClientErrorException
- if the field was not found
-
-