-
Notifications
You must be signed in to change notification settings - Fork 4
[RTI][SUB] Write the Ingestion Script for RTIs #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9fe83de
ingestion script added for node and relation creation for RTI
ChanukaUOJ d3ee700
test cases added and test data refactored
ChanukaUOJ 717a3d5
bot commit addressed
ChanukaUOJ 78e5267
entity creation conflict handled
ChanukaUOJ 3bbd7de
remove UI folder
ChanukaUOJ 93dd76a
Fix the issues
ChanukaUOJ 1f74f31
data table columns changed
ChanukaUOJ 5c12837
issues fixed in the data and the rti service
ChanukaUOJ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # If you prefer the allow list template instead of the deny list, see community template: | ||
| # https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore | ||
| # | ||
| # Binaries for programs and plugins | ||
| *.exe | ||
| *.exe~ | ||
| *.dll | ||
| *.so | ||
| *.dylib | ||
|
|
||
| # Test binary, built with `go test -c` | ||
| *.test | ||
|
|
||
| # Code coverage profiles and other test artifacts | ||
| *.out | ||
| coverage.* | ||
| *.coverprofile | ||
| profile.cov | ||
|
|
||
| # Dependency directories (remove the comment below to include it) | ||
| # vendor/ | ||
|
|
||
| # Go workspace file | ||
| go.work | ||
| go.work.sum | ||
|
|
||
| # env file | ||
| .env | ||
|
|
||
| # Editor/IDE | ||
| # .idea/ | ||
| # .vscode/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Title,Description,Source,Sender,Receiver Institution,Receiver Position | ||
| Title 1,Description 1,http://sourcelink,LDF,Lanka Fabric Ltd,Secretary |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| Status,Description,Entry Time,Exit Time,Source | ||
| Request Identification,Request Identification Description,2022-09-14,2022-09-15,http://link | ||
| Request Drafted,Request Drafted Description,2022-10-01,2022-10-02,http://link | ||
| Draft Review,Draft Review Description,2022-10-03,2022-10-05,http://link | ||
| Ready To Send,Ready To Send Description,2023-04-13,2023-04-21,http://link | ||
| Request Sent,Request Sent Description,2023-04-14,2023-04-15,http://link | ||
| Initial Request In Review,Initial Request In Review Description,2023-04-17,2023-04-18,http://link | ||
| Initial Response,Initial Response Description,2023-04-18,2023-04-19,http://link | ||
| Data Request In Review,Data Request In Review Description,2023-04-22,, | ||
| Terminated,Terminated Description,,, | ||
| Final Response,Final Response Description,,, | ||
| Data Received,Data Received Description,,, | ||
| RTI Data Is Live,RTI Data Is Live Description,,, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Title,Description,Source,Sender,Receiver Institution,Receiver Position | ||
| Title 1,Description 1,http://sourcelink,LDF,Lanka Fabric Ltd,Minister |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| Status,Description,Entry Time,Exit Time,Source | ||
| Request Identification,Request Identification Description,2022-09-14,2022-09-15,http://link | ||
| Request Drafted,Request Drafted Description,2022-10-01,2022-10-02,http://link | ||
| Draft Review,Draft Review Description,2022-10-03,2022-10-05,http://link | ||
| Ready To Send,Ready To Send Description,2023-04-13,2023-04-21,http://link | ||
| Request Sent,Request Sent Description,2023-04-14,2023-04-15,http://link | ||
| Initial Request In Review,Initial Request In Review Description,2023-04-17,2023-04-18,http://link | ||
| Initial Response,Initial Response Description,2023-04-18,2023-04-19,http://link | ||
| Data Request In Review,Data Request In Review Description,2023-04-22,, | ||
| Terminated,Terminated Description,,, | ||
| Final Response,Final Response Description,,, | ||
| Data Received,Data Received Description,,, | ||
| RTI Data Is Live,RTI Data Is Live Description,,, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Title,Description,Source,Sender,Receiver Institution,Receiver Position | ||
| Title 2,Description 2,http://sourcelink,LDF,Minister of defence,Secretary |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| Status,Description,Entry Time,Exit Time,Source | ||
| Request Identification,Request Identification Description,2022-09-14,2022-09-15,http://link | ||
| Request Drafted,Request Drafted Description,2022-10-01,2022-10-02,http://link | ||
| Draft Review,Draft Review Description,2022-10-03,2022-10-05,http://link | ||
| Ready To Send,Ready To Send Description,2023-04-13,2023-04-21,http://link | ||
| Request Sent,Request Sent Description,2023-04-14,2023-04-15,http://link | ||
| Initial Request In Review,Initial Request In Review Description,2023-04-17,2023-04-18,http://link | ||
| Initial Response,Initial Response Description,2023-04-18,2023-04-19,http://link | ||
| Data Request In Review,Data Request In Review Description,2023-04-22,, | ||
| Terminated,Terminated Description,,, | ||
| Final Response,Final Response Description,,, | ||
| Data Received,Data Received Description,,, | ||
| RTI Data Is Live,RTI Data Is Live Description,,, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Title,Description,Source,Sender,Receiver Institution,Receiver Position | ||
| Title 3,Description 3,http://sourcelink,LDF,Minister of defence,Secretary |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| Status,Description,Entry Time,Exit Time,Source | ||
| Request Identification,Request Identification Description,2022-09-14,2022-09-15,http://link | ||
| Request Drafted,Request Drafted Description,2022-10-01,2022-10-02,http://link | ||
| Draft Review,Draft Review Description,2022-10-03,2022-10-05,http://link | ||
| Ready To Send,Ready To Send Description,2023-04-13,2023-04-21,http://link | ||
| Request Sent,Request Sent Description,2023-04-14,2023-04-15,http://link | ||
| Initial Request In Review,Initial Request In Review Description,2023-04-17,2023-04-18,http://link | ||
| Initial Response,Initial Response Description,2023-04-18,2023-04-19,http://link | ||
| Data Request In Review,Data Request In Review Description,2023-04-22,, | ||
| Terminated,Terminated Description,,, | ||
| Final Response,Final Response Description,,, | ||
| Data Received,Data Received Description,,, | ||
| RTI Data Is Live,RTI Data Is Live Description,,, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Title,Description,Source,Sender,Receiver Institution,Receiver Position | ||
| Title 4,Description 4,http://sourcelink,LDF,Minister of defence,Minister |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| Status,Description,Entry Time,Exit Time,Source | ||
| Request Identification,Request Identification Description,2022-09-14,2022-09-15,http://link | ||
| Request Drafted,Request Drafted Description,2022-10-01,2022-10-02,http://link | ||
| Draft Review,Draft Review Description,2022-10-03,2022-10-05,http://link | ||
| Ready To Send,Ready To Send Description,2023-04-13,2023-04-21,http://link | ||
| Request Sent,Request Sent Description,2023-04-14,2023-04-15,http://link | ||
| Initial Request In Review,Initial Request In Review Description,2023-04-17,2023-04-18,http://link | ||
| Initial Response,Initial Response Description,2023-04-18,2023-04-19,http://link | ||
| Data Request In Review,Data Request In Review Description,2023-04-22,, | ||
| Terminated,Terminated Description,,, | ||
| Final Response,Final Response Description,,, | ||
| Data Received,Data Received Description,,, | ||
| RTI Data Is Live,RTI Data Is Live Description,,, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export INGESTION_URL="http://localhost:8080" | ||
| export READ_URL="http://localhost:8081" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| ## How to run the service | ||
|
|
||
| #### source env | ||
| ``` | ||
| source .env | ||
| ``` | ||
|
|
||
| #### run the tests | ||
| ``` | ||
| go test ./tests/ | ||
| ``` | ||
|
|
||
| #### run the scripts | ||
| ``` | ||
| go run ./cmd/app/main.go --data "../data/RTI" -v | ||
| ``` | ||
|
|
||
| -------- or -------- | ||
|
|
||
| #### run the test run file | ||
| ``` | ||
| source .env | ||
| chmod +X test_run.sh | ||
| ./test_run.sh | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "encoding/csv" | ||
| "flag" | ||
| "fmt" | ||
| "io" | ||
| "io/fs" | ||
| "log" | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
|
|
||
| "github.com/LDFLK/RTI-Tracker/ingestion/internals/client" | ||
| "github.com/LDFLK/RTI-Tracker/ingestion/internals/core" | ||
| "github.com/LDFLK/RTI-Tracker/ingestion/internals/models" | ||
| "github.com/LDFLK/RTI-Tracker/ingestion/internals/ports" | ||
| "github.com/LDFLK/RTI-Tracker/ingestion/internals/utils" | ||
| ) | ||
|
|
||
| func main() { | ||
|
|
||
| dataDir := flag.String("data", "", "Path to data directory containing csv files") | ||
|
|
||
| flag.Usage = func() { | ||
| fmt.Fprintf(os.Stderr, "Usage of %s:\n\n", os.Args[0]) | ||
| } | ||
|
|
||
| flag.Parse() | ||
|
|
||
| // access environment variables | ||
| ingestionUrl := os.Getenv("INGESTION_URL") | ||
| if ingestionUrl == "" { | ||
| log.Fatal("Ingestion Service URL Required") | ||
| } | ||
|
|
||
| readUrl := os.Getenv("READ_URL") | ||
| if readUrl == "" { | ||
| log.Fatal("Read Service URL Required") | ||
| } | ||
|
|
||
| // Initialize services | ||
| apiClient := client.ApiClient(ingestionUrl, readUrl) | ||
| ingestionService := ports.NewIngestionService(*apiClient) | ||
| readService := ports.NewReadService(*apiClient) | ||
| s := core.NewRTIService(ingestionService, readService) | ||
|
|
||
| // validate flags | ||
| if *dataDir == "" { | ||
| fmt.Fprintf(os.Stderr, "Error: Data directory path is required\n\n") | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| var requestErrors []string | ||
| var rtiRequestCount int | ||
|
|
||
| err := filepath.WalkDir(*dataDir, func(path string, d fs.DirEntry, err error) error { | ||
| if err != nil { | ||
| fmt.Printf("Error: %s\n\n", err) | ||
| return err | ||
| } | ||
|
|
||
| if d.IsDir() { | ||
| fmt.Printf("Directory: %s\n", path) | ||
| } else { | ||
| fmt.Printf("File: %s\n", path) | ||
| log.Println("Processing file...") | ||
|
|
||
| fileName := filepath.Base(path) | ||
| fileDir := filepath.Dir(path) | ||
| splittedDir := strings.Split(fileDir, string(filepath.Separator)) | ||
|
|
||
| // access the date from the folder structure | ||
| date := splittedDir[len(splittedDir)-2] | ||
| index := splittedDir[len(splittedDir)-1] | ||
| dateISO, err := utils.DateToISO(date) | ||
|
|
||
| if err != nil { | ||
| log.Printf("failed to parse date %v", err) | ||
| return nil | ||
| } | ||
|
ChanukaUOJ marked this conversation as resolved.
|
||
|
|
||
| if fileName == "status.csv" { | ||
| // attribute insertion process for status | ||
| } else { | ||
| // node creation process and attribute insertion for request | ||
| // open the file | ||
| f, err := os.Open(path) | ||
| if err != nil { | ||
| log.Printf("Failed to open file: %s , %v", path, err) | ||
| return nil | ||
| } | ||
|
ChanukaUOJ marked this conversation as resolved.
|
||
|
|
||
| defer f.Close() | ||
|
|
||
| r := csv.NewReader(f) | ||
|
|
||
| // read the first line of the csv first to skip the first line | ||
| if _, err := r.Read(); err != nil { | ||
| fmt.Printf("Error accessing fields in csv: %s", err) | ||
| } | ||
|
|
||
| // access data starting from the second row in the csv | ||
| for { | ||
| record, err := r.Read() | ||
|
|
||
| if err == io.EOF { | ||
| break | ||
| } | ||
|
|
||
| if err != nil { | ||
| log.Println("Err reading records in the file") | ||
| } | ||
|
|
||
| title := record[0] | ||
| description := record[1] | ||
| source := record[2] | ||
| sender := record[3] | ||
| receiverInstitution := record[4] | ||
| receiverPosition := record[5] | ||
|
|
||
| // field data to the RTIRequest | ||
| entity := &models.RTIRequest{ | ||
| Title: title, | ||
| Description: description, | ||
| Source: source, | ||
| Sender: sender, | ||
| ReceiverInstitution: receiverInstitution, | ||
| ReceiverPosition: receiverPosition, | ||
| Created: dateISO, | ||
| Index: index, | ||
| } | ||
|
|
||
| _, err = s.InsertRTIRequest(entity) | ||
|
|
||
| if err != nil { | ||
| log.Printf("[main] RTI Insertion failed %s", err) | ||
| requestErrors = append(requestErrors, err.Error()) | ||
| continue | ||
| } | ||
|
|
||
| rtiRequestCount++ | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| return nil | ||
| }) | ||
|
|
||
| if err != nil { | ||
| log.Fatal(err) | ||
| os.Exit(0) | ||
| } | ||
|
|
||
| log.Printf("Processed %d RTI requests successfully (noted %d errors).", rtiRequestCount, len(requestErrors)) | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| module github.com/LDFLK/RTI-Tracker/ingestion | ||
|
|
||
| go 1.24.3 | ||
|
|
||
| require ( | ||
| github.com/google/uuid v1.6.0 // indirect | ||
| github.com/hashicorp/go-cleanhttp v0.5.2 // indirect | ||
| github.com/hashicorp/go-retryablehttp v0.7.8 // indirect | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= | ||
| github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | ||
| github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= | ||
| github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= | ||
| github.com/hashicorp/go-retryablehttp v0.7.8 h1:ylXZWnqa7Lhqpk0L1P1LzDtGcCR0rPVUrx/c8Unxc48= | ||
| github.com/hashicorp/go-retryablehttp v0.7.8/go.mod h1:rjiScheydd+CxvumBsIrFKlx3iS0jrZ7LvzFGFmuKbw= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package client | ||
|
|
||
| import ( | ||
| "context" | ||
| "net/http" | ||
| "time" | ||
|
|
||
| "github.com/hashicorp/go-retryablehttp" | ||
| ) | ||
|
|
||
| // API Client struct | ||
| type Client struct { | ||
| IngestionURL string | ||
| ReadURL string | ||
| HttpClient *retryablehttp.Client | ||
| } | ||
|
|
||
| // Custom Retry Check | ||
| func customRetryCheck(ctx context.Context, resp *http.Response, err error) (bool, error) { | ||
| if resp != nil { | ||
| switch resp.StatusCode { | ||
| case http.StatusBadRequest, http.StatusNotFound, http.StatusConflict: | ||
| return false, nil | ||
| } | ||
| } | ||
|
|
||
| return retryablehttp.DefaultRetryPolicy(ctx, resp, err) | ||
| } | ||
|
|
||
| // API Client | ||
| func ApiClient(ingesUrl string, reUrl string) *Client { | ||
| retryClient := retryablehttp.NewClient() | ||
| retryClient.RetryMax = 10 | ||
| retryClient.RetryWaitMin = 1 * time.Second | ||
| retryClient.RetryWaitMax = 6 * time.Second | ||
| retryClient.CheckRetry = customRetryCheck | ||
| retryClient.Logger = nil | ||
|
|
||
| return &Client{ | ||
| IngestionURL: ingesUrl, | ||
| ReadURL: reUrl, | ||
| HttpClient: retryClient, | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.