80 lines
3.6 KiB
Go
80 lines
3.6 KiB
Go
package repositoryAccessLayer
|
|
|
|
import (
|
|
"alfred/mapper"
|
|
"alfred/model/es"
|
|
"alfred/repository"
|
|
"errors"
|
|
)
|
|
|
|
type ErrorEventsAccessLayer interface {
|
|
UploadErrorEvents(message string, errorsIngestionIndex string) (int, error)
|
|
FetchSessionIdFromSessionErrorEventsWithTimeRange(errorEventsUploadIndexList []string, startTime, endTime int64, sessionErrorEventsFilter []string) ([]string, error)
|
|
FetchErrorEvents(sessionId string, errorEventsUploadIndex string) ([]es.ErrorEventsResponse, error)
|
|
GetErrorEventsLastCronTimestamp(clientName string, errorEventsTimeIndex string) (int64, error)
|
|
UpdateErrorEventsLastCronTimestamp(timestamp int64, clientName string, errorEventsTimeIndex string) error
|
|
FetchSessionErrorEventsWithKeyValue(keyValueMap map[string][]string, errorEventsIndex string) ([]es.ErrorEventsResponse, error)
|
|
UpdateErrorEventsInActiveBulk(errorEventsdocIdList, errorEventsindexList []string) error
|
|
}
|
|
type ErrorEventsAccessLayerImpl struct {
|
|
errorEventsRepository repository.ErrorEventsRepository
|
|
}
|
|
|
|
func NewErrorEventsAccessLayer(errorEventsRepository repository.ErrorEventsRepository) ErrorEventsAccessLayer {
|
|
return &ErrorEventsAccessLayerImpl{
|
|
errorEventsRepository: errorEventsRepository,
|
|
}
|
|
}
|
|
|
|
func (ral *ErrorEventsAccessLayerImpl) UploadErrorEvents(message string, errorsIngestionIndex string) (int, error) {
|
|
return ral.errorEventsRepository.UploadErrorEvents(message, errorsIngestionIndex)
|
|
}
|
|
|
|
func (ral *ErrorEventsAccessLayerImpl) FetchSessionIdFromSessionErrorEventsWithTimeRange(errorEventsUploadIndexList []string, startTime, endTime int64, sessionErrorEventsFilter []string) ([]string, error) {
|
|
result, err := ral.errorEventsRepository.FetchSessionIdFromSessionErrorEventsWithTimeRange(errorEventsUploadIndexList, startTime, endTime, sessionErrorEventsFilter)
|
|
if result.IsError() {
|
|
defer result.Body.Close()
|
|
err = errors.New("error while fetching session error events session id with time range")
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return mapper.MapEsResponseAndGetSessionIds(result)
|
|
}
|
|
|
|
func (ral *ErrorEventsAccessLayerImpl) FetchErrorEvents(sessionId string, errorEventsUploadIndex string) ([]es.ErrorEventsResponse, error) {
|
|
result, err := ral.errorEventsRepository.FetchErrorEvents(sessionId, errorEventsUploadIndex)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return mapper.MapEsResponseToErrorEventsResponse(result)
|
|
}
|
|
|
|
func (ral *ErrorEventsAccessLayerImpl) FetchSessionErrorEventsWithKeyValue(keyValueMap map[string][]string, errorEventsIndex string) ([]es.ErrorEventsResponse, error) {
|
|
result, err := ral.errorEventsRepository.FetchSessionErrorEventsWithKeyValue(keyValueMap, errorEventsIndex)
|
|
if result.IsError() {
|
|
defer result.Body.Close()
|
|
err = errors.New("error while fetching session error events with key value")
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return mapper.MapEsResponseToErrorEventsResponse(result)
|
|
}
|
|
|
|
func (ral *ErrorEventsAccessLayerImpl) GetErrorEventsLastCronTimestamp(clientName string, errorEventsTimeIndex string) (int64, error) {
|
|
result, err := ral.errorEventsRepository.GetErrorEventsLastCronTimestamp(errorEventsTimeIndex)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return mapper.MapEsResponseToTimeStamp(clientName, result)
|
|
}
|
|
|
|
func (ral *ErrorEventsAccessLayerImpl) UpdateErrorEventsLastCronTimestamp(timestamp int64, clientName string, errorEventsTimeIndex string) error {
|
|
return ral.errorEventsRepository.UpdateErrorEventsLastCronTimestamp(timestamp, clientName, errorEventsTimeIndex)
|
|
}
|
|
|
|
func (ral *ErrorEventsAccessLayerImpl) UpdateErrorEventsInActiveBulk(errorEventsdocIdList, errorEventsindexList []string) error {
|
|
return ral.errorEventsRepository.UpdateErrorEventsInActiveBulk(errorEventsdocIdList, errorEventsindexList)
|
|
}
|