Skip to content

Commit

Permalink
work
Browse files Browse the repository at this point in the history
  • Loading branch information
mcantelon committed May 16, 2024
1 parent 75cb2b4 commit 589b7d4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 deletions.
25 changes: 13 additions & 12 deletions internal/activities/combine_premis.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package activities
import (
etree "github.com/beevik/etree"
"context"
"errors"
"os"
"path"
"strings"
Expand Down Expand Up @@ -31,14 +32,14 @@ func (md *CombinePREMISActivity) Execute(
// Get transfer's PREMIS file paths
file_paths, err := CombinePREMISGetPaths(params.SipPath)
if err != nil {
panic(err)
return nil, err
}

// Write elements from transfer's PREMIS files to combined PREMIS file
for _, file_path := range file_paths {
_, err := CombinePREMISCopy(file_path, "premis2.xml")
err := CombinePREMISCopy(file_path, "premis2.xml")
if err != nil {
panic(err)
return nil, err
}
}

Expand All @@ -48,7 +49,7 @@ func (md *CombinePREMISActivity) Execute(
}

func CombinePREMISGetPaths(transfer_dir string) ([]string, error) {
content_subdir := "content/content"
content_subdir := "content"
file_dir := path.Join(transfer_dir, content_subdir)

dir_items, err := os.ReadDir(file_dir)
Expand Down Expand Up @@ -79,17 +80,17 @@ func CombinePREMISGetPaths(transfer_dir string) ([]string, error) {
return file_paths, nil
}

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

if err := source_doc.ReadFromFile(source_filepath); err != nil {
return false, err
return err
}

source_premis_element := source_doc.FindElement("/premis")
if source_premis_element == nil {
return false, errors.New("no root premis element found in source document")
return errors.New("no root premis element found in source document")
}

// Read source child PREMIS elements
Expand All @@ -100,12 +101,12 @@ func CombinePREMISCopy(source_filepath string, destination_filepath string) (boo
// Parse destination document and get root PREMIS element
dest_doc := etree.NewDocument()
if err := dest_doc.ReadFromFile(destination_filepath); err != nil {
return false, err
return err
}

dest_premis_element := dest_doc.FindElement("/premis")
if dest_premis_element == nil {
return false, errors.New("no root premis element found in destination document")
return errors.New("no root premis element found in destination document")
}

// Update PREMIS originalname child elements of PREMIS object elements
Expand All @@ -122,12 +123,12 @@ func CombinePREMISCopy(source_filepath string, destination_filepath string) (boo
CombinePREMISAddChildElements(dest_premis_element, source_premis_agent_elements)

dest_doc.Indent(2)
err = dest_doc.WriteToFile(destination_filepath)
err := dest_doc.WriteToFile(destination_filepath)
if err != nil {
panic("ZZZ")
return err
}

return true, nil
return nil
}

func CombinePREMISAddChildElements(parent_element *etree.Element, new_child_elements []*etree.Element) {
Expand Down
22 changes: 11 additions & 11 deletions internal/workflow/preprocessing.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,6 @@ func (w *PreprocessingWorkflow) Execute(
return nil, e
}

// Combine PREMIS files into one.
var combinePREMIS activities.CombinePREMISResult
e = temporalsdk_workflow.ExecuteActivity(
withLocalActOpts(ctx),
activities.CombinePREMISName,
&activities.CombinePREMISParams{SipPath: localPath},
).Get(ctx, &combinePREMIS)
if e != nil {
return nil, e
}

var bagPath string
if checkStructureRes.SIP != nil {
// Repackage SFA SIP into a Bag.
Expand Down Expand Up @@ -143,6 +132,17 @@ func (w *PreprocessingWorkflow) Execute(
return nil, e
}

// Combine PREMIS files into one.
var combinePREMIS activities.CombinePREMISResult
e = temporalsdk_workflow.ExecuteActivity(
withLocalActOpts(ctx),
activities.CombinePREMISName,
&activities.CombinePREMISParams{SipPath: localPath},
).Get(ctx, &combinePREMIS)
if e != nil {
return nil, e
}

// Remove PREMIS XML files.
var removeFilesResult removefiles.ActivityResult
e = temporalsdk_workflow.ExecuteActivity(
Expand Down
12 changes: 6 additions & 6 deletions internal/workflow/preprocessing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,18 @@ func (s *PreprocessingTestSuite) TestSIP() {
&activities.MetadataValidationResult{}, nil,
)
s.env.OnActivity(
activities.CombinePREMISName,
activities.SipCreationName,
sessionCtx,
&activities.CombinePREMISParams{SipPath: sipPath},
&activities.SipCreationParams{SipPath: sipPath},
).Return(
&activities.CombinePREMISResult{}, nil,
&activities.SipCreationResult{NewSipPath: bagPath}, nil,
)
s.env.OnActivity(
activities.SipCreationName,
activities.CombinePREMISName,
sessionCtx,
&activities.SipCreationParams{SipPath: sipPath},
&activities.CombinePREMISParams{SipPath: sipPath},
).Return(
&activities.SipCreationResult{NewSipPath: bagPath}, nil,
&activities.CombinePREMISResult{}, nil,
)
s.env.OnActivity(
activities.RemovePathsName,
Expand Down

0 comments on commit 589b7d4

Please sign in to comment.