Skip to content

Commit

Permalink
Merge pull request #1244 from bcgov/dev-rook-RQ-FOIMOD-3551
Browse files Browse the repository at this point in the history
skip deleted additional files
  • Loading branch information
richard-aot authored Dec 20, 2024
2 parents b697b65 + e1d35ed commit 02d5a1d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
17 changes: 12 additions & 5 deletions computingservices/OpenInfoServices/lib/awslib/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type AdditionalFile struct {
Additionalfileid int `json:"additionalfileid"`
Filename string `json:"filename"`
S3uripath string `json:"s3uripath"`
Isactive bool `json:"isactive"`
}

type resolverV2 struct{}
Expand Down Expand Up @@ -139,8 +140,11 @@ func ScanS3(openInfoBucket string, openInfoPrefix string, urlPrefix string, file

// Get the file name
base := path.Base(filePath)
originalFileName, found := getOriginalName(filemappings, base)
originalFileName, found, isactive := getOriginalName(filemappings, base)
if found {
if !isactive { // Skip over the deleted files (isactive = false)
continue
}
base = originalFileName
}
// fmt.Printf("Base %s\n", base)
Expand Down Expand Up @@ -211,8 +215,11 @@ func CopyS3(sourceBucket string, sourcePrefix string, filemappings []AdditionalF

// Get the file name
base := path.Base(sourceKey)
originalFileName, found := getOriginalName(filemappings, base)
originalFileName, found, isactive := getOriginalName(filemappings, base)
if found {
if !isactive { // Skip over the deleted files (isactive = false)
continue
}
base = originalFileName
}
// fmt.Printf("Base %s\n", base)
Expand Down Expand Up @@ -404,7 +411,7 @@ func contains(arr []string, str string) bool {
}

// Get Original Filename
func getOriginalName(filemappings []AdditionalFile, key string) (string, bool) {
func getOriginalName(filemappings []AdditionalFile, key string) (string, bool, bool) {
for _, item := range filemappings {
// Parse the URL
parsedURL, err := url.Parse(item.S3uripath)
Expand All @@ -420,8 +427,8 @@ func getOriginalName(filemappings []AdditionalFile, key string) (string, bool) {
base := path.Base(urlPath)

if base == key {
return item.Filename, true
return item.Filename, true, item.Isactive
}
}
return "", false
return "", false, true
}
7 changes: 6 additions & 1 deletion computingservices/OpenInfoServices/lib/db/dbservices.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type AdditionalFile struct {
Additionalfileid int
Filename string
S3uripath string
Isactive bool
}

type OpenInfoRecord struct {
Expand Down Expand Up @@ -119,7 +120,8 @@ func GetOIRecordsForPrePublishing(db *sql.DB) ([]OpenInfoRecord, error) {
'publish' as type,
oifiles.additionalfileid,
oifiles.filename,
oifiles.s3uripath
oifiles.s3uripath,
oifiles.isactive
FROM public."FOIMinistryRequests" mr
INNER JOIN public."FOIRequests" r on mr.foirequest_id = r.foirequestid and mr.foirequestversion_id = r.version
INNER JOIN public."ProgramAreas" pa on mr.programareaid = pa.programareaid
Expand Down Expand Up @@ -149,6 +151,7 @@ func GetOIRecordsForPrePublishing(db *sql.DB) ([]OpenInfoRecord, error) {
var openinfoid, foiministryrequestid, additionalfileid sql.NullInt64
var axisrequestid, description, published_date, contributor, applicant_type, bcgovcode, sitemap_pages, queuetype, filename, s3uripath sql.NullString
var fees sql.NullFloat64
var isactive bool

// err := rows.Scan(
// &record.Openinfoid,
Expand Down Expand Up @@ -178,6 +181,7 @@ func GetOIRecordsForPrePublishing(db *sql.DB) ([]OpenInfoRecord, error) {
&additionalfileid,
&filename,
&s3uripath,
&isactive,
)
if err != nil {
return records, fmt.Errorf("failed to retrieve query result for prepublish: %w", err)
Expand Down Expand Up @@ -205,6 +209,7 @@ func GetOIRecordsForPrePublishing(db *sql.DB) ([]OpenInfoRecord, error) {
Additionalfileid: int(additionalfileid.Int64),
Filename: filename.String,
S3uripath: s3uripath.String,
Isactive: isactive,
})
}
}
Expand Down

0 comments on commit 02d5a1d

Please sign in to comment.