Skip to content

Commit

Permalink
Create objects dir and change paths in premis.xml
Browse files Browse the repository at this point in the history
[skip-codecov]
  • Loading branch information
jraddaoui committed May 17, 2024
1 parent a1ae576 commit 0ce0188
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
15 changes: 9 additions & 6 deletions internal/activities/combine_premis.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"os"
"path"
"path/filepath"
"strings"

"github.com/beevik/etree"
Expand Down Expand Up @@ -37,7 +38,7 @@ func (md *CombinePREMISActivity) Execute(
return nil, err
}

// Copy empty PREMIS file into metadata directory.
// Copy empty PREMIS file into metadata directory.
source_filepath := "empty_premis.xml"
dest_filepath := path.Join(params.Path, "metadata/premis.xml")

Expand All @@ -51,7 +52,7 @@ func (md *CombinePREMISActivity) Execute(

for _, file_path := range file_paths {
err := CombinePREMISCopy(file_path, combined_premis_filepath)
if err != nil {
if err != nil {
return nil, err
}
}
Expand All @@ -62,15 +63,16 @@ func (md *CombinePREMISActivity) Execute(
}

func CombinePREMISGetPaths(transfer_dir string) ([]string, error) {
dir_items, err := os.ReadDir(transfer_dir)
objects_dir := filepath.Join(transfer_dir, "objects")
dir_items, err := os.ReadDir(objects_dir)
if err != nil {
return nil, err
}

file_paths := []string{}
for _, dir_item := range dir_items {
if dir_item.IsDir() {
subdir := path.Join(transfer_dir, dir_item.Name())
subdir := path.Join(objects_dir, dir_item.Name())

sub_items, err := os.ReadDir(subdir)
if err != nil {
Expand All @@ -90,7 +92,7 @@ func CombinePREMISGetPaths(transfer_dir string) ([]string, error) {
return file_paths, nil
}

func CombinePREMISCopy(source_filepath string, destination_filepath string) error {
func CombinePREMISCopy(source_filepath, destination_filepath string) error {
// Parse source document and get root PREMIS element.
source_doc := etree.NewDocument()

Expand Down Expand Up @@ -120,10 +122,11 @@ func CombinePREMISCopy(source_filepath string, destination_filepath string) erro
}

// Update PREMIS originalname child elements of PREMIS object elements.
dirName := filepath.Base(filepath.Dir(source_filepath))
for _, premis_object_element := range source_premis_object_elements {
objectname_element := premis_object_element.FindElement("originalName")
if objectname_element != nil {
objectname_element.SetText("data/" + objectname_element.Text())
objectname_element.SetText("objects/" + dirName + "/" + objectname_element.Text())
}
}

Expand Down
8 changes: 7 additions & 1 deletion internal/activities/transform_vecteur_aip.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,19 @@ func (a *TransformVecteurAIPActivity) Execute(
return nil, err
}

// Create objects directory.
objectsPath := filepath.Join(params.Path, "objects")
if err = os.Mkdir(objectsPath, 0o750); err != nil {
return nil, err
}

// Move all entries from content/content to root folder.
entries, err := os.ReadDir(contentPath)
if err != nil {
return nil, err
}
for _, entry := range entries {
err := fsutil.Move(filepath.Join(contentPath, entry.Name()), filepath.Join(params.Path, entry.Name()))
err := fsutil.Move(filepath.Join(contentPath, entry.Name()), filepath.Join(objectsPath, entry.Name()))
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 0ce0188

Please sign in to comment.