Merged in feature/standardisefilepath (pull request #111)
Feature/standardisefilepath * baseprocessing * generalstructure
This commit is contained in:
@@ -3,12 +3,11 @@ package documenttext
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"time"
|
||||
|
||||
"queryorchestration/internal/client"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/serviceconfig/build"
|
||||
"queryorchestration/internal/serviceconfig/objectstore"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/service/textract"
|
||||
"github.com/aws/aws-sdk-go-v2/service/textract/types"
|
||||
@@ -29,11 +28,19 @@ func (s *Service) triggerExtract(ctx context.Context, clean *repository.Currentc
|
||||
|
||||
jobTag := triggerId.String()
|
||||
|
||||
key, err := s.getOutputLocation(clean.Clientid, triggerId)
|
||||
filename, err := s.getOutputFilename(triggerId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
key := objectstore.BucketKey{
|
||||
CreatedAt: time.Now().UTC(),
|
||||
Location: objectstore.TextTextract,
|
||||
ClientID: clean.Clientid,
|
||||
Filename: filename,
|
||||
}
|
||||
keyStr := key.String()
|
||||
|
||||
res, err := s.cfg.GetTextractClient().StartDocumentTextDetection(ctx, &textract.StartDocumentTextDetectionInput{
|
||||
DocumentLocation: &types.DocumentLocation{
|
||||
S3Object: &types.S3Object{
|
||||
@@ -44,7 +51,7 @@ func (s *Service) triggerExtract(ctx context.Context, clean *repository.Currentc
|
||||
JobTag: &jobTag,
|
||||
OutputConfig: &types.OutputConfig{
|
||||
S3Bucket: clean.Bucket,
|
||||
S3Prefix: &key,
|
||||
S3Prefix: &keyStr,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -65,25 +72,16 @@ func (s *Service) triggerExtract(ctx context.Context, clean *repository.Currentc
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Service) getOutputLocation(clientId string, triggerId uuid.UUID) (string, error) {
|
||||
if clientId == "" {
|
||||
return "", errors.New("client id required")
|
||||
} else if triggerId == uuid.Nil {
|
||||
func (s *Service) getOutputFilename(triggerId uuid.UUID) (string, error) {
|
||||
if triggerId == uuid.Nil {
|
||||
return "", errors.New("trigger id required")
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s/text/textract/%s", clientId, triggerId), nil
|
||||
return triggerId.String(), nil
|
||||
}
|
||||
|
||||
func (s *Service) getTriggerIdFromKey(key string) (uuid.UUID, error) {
|
||||
regexPattern := fmt.Sprintf(`^%s/text/textract/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$`, client.CLIENT_ID_REGEX)
|
||||
re := regexp.MustCompile(regexPattern)
|
||||
match := re.FindStringSubmatch(key)
|
||||
if len(match) < 2 {
|
||||
return uuid.Nil, errors.New("Trigger Id not found")
|
||||
}
|
||||
|
||||
triggerId, err := uuid.Parse(match[1])
|
||||
func (s *Service) getTriggerIdFromKey(key objectstore.BucketKey) (uuid.UUID, error) {
|
||||
triggerId, err := uuid.Parse(key.Filename)
|
||||
if err != nil {
|
||||
return uuid.Nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user