Skip to content

Commit

Permalink
Capture PREMIS events for validation tasks (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcantelon committed Jun 12, 2024
1 parent bcdfd39 commit ade9c0c
Show file tree
Hide file tree
Showing 10 changed files with 668 additions and 2 deletions.
12 changes: 12 additions & 0 deletions cmd/worker/workercmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ func (m *Main) Run(ctx context.Context) error {
activities.NewValidateFileFormats().Execute,
temporalsdk_activity.RegisterOptions{Name: activities.ValidateFileFormatsName},
)
w.RegisterActivityWithOptions(
activities.NewAddPREMISObjects().Execute,
temporalsdk_activity.RegisterOptions{Name: activities.AddPREMISObjectsName},
)
w.RegisterActivityWithOptions(
activities.NewAddPREMISEvent().Execute,
temporalsdk_activity.RegisterOptions{Name: activities.AddPREMISEventName},
)
w.RegisterActivityWithOptions(
activities.NewAddPREMISAgent().Execute,
temporalsdk_activity.RegisterOptions{Name: activities.AddPREMISAgentName},
)

Check warning on line 85 in cmd/worker/workercmd/cmd.go

View check run for this annotation

Codecov / codecov/patch

cmd/worker/workercmd/cmd.go#L74-L85

Added lines #L74 - L85 were not covered by tests
w.RegisterActivityWithOptions(
activities.NewValidateMetadata().Execute,
temporalsdk_activity.RegisterOptions{Name: activities.ValidateMetadataName},
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ go 1.22.3

require (
github.com/artefactual-sdps/temporal-activities v0.0.0-20240528131443-0d1f5defd565
github.com/beevik/etree v1.4.0
github.com/go-logr/logr v1.4.1
github.com/google/uuid v1.6.0
github.com/otiai10/copy v1.14.0
github.com/richardlehane/siegfried v1.11.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.18.2
Expand All @@ -22,14 +25,12 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/nyudlts/go-bagit v0.3.0-alpha.0.20240515212815-8dab411c23af // indirect
github.com/otiai10/copy v1.14.0 // indirect
github.com/pborman/uuid v1.2.1 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/artefactual-sdps/temporal-activities v0.0.0-20240528131443-0d1f5defd565 h1:BlAvtmnDfP/J2ZwYDElMkF6caNQWxOGXlXiCC59tj4A=
github.com/artefactual-sdps/temporal-activities v0.0.0-20240528131443-0d1f5defd565/go.mod h1:C6z/8k6xFm9wrF4GSMKs13v941MtdrOzH2fn8hQEHtA=
github.com/beevik/etree v1.4.0 h1:oz1UedHRepuY3p4N5OjE0nK1WLCqtzHf25bxplKOHLs=
github.com/beevik/etree v1.4.0/go.mod h1:cyWiXwGoasx60gHvtnEh5x8+uIjUVnjWqBvEnhnqKDA=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
Expand Down
3 changes: 3 additions & 0 deletions hack/sampledata/xsd/empty_premis.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<premis:premis xmlns:premis="http://www.loc.gov/premis/v3" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.loc.gov/premis/v3 https://www.loc.gov/standards/premis/premis.xsd" version="3.0">
</premis:premis>
35 changes: 35 additions & 0 deletions internal/activities/add_premis_agent.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package activities

import (
"context"
"path/filepath"

"github.com/artefactual-sdps/preprocessing-sfa/internal/premis"
)

const AddPREMISAgentName = "add-premis-agent"

type AddPREMISAgentActivity struct{}

func NewAddPREMISAgent() *AddPREMISAgentActivity {
return &AddPREMISAgentActivity{}

Check warning on line 15 in internal/activities/add_premis_agent.go

View check run for this annotation

Codecov / codecov/patch

internal/activities/add_premis_agent.go#L14-L15

Added lines #L14 - L15 were not covered by tests
}

type AddPREMISAgentParams struct {
Path string
Agent premis.PREMISAgent
}

type AddPREMISAgentResult struct{}

func (md *AddPREMISAgentActivity) Execute(
ctx context.Context,
params *AddPREMISAgentParams,
) (*AddPREMISAgentResult, error) {
err := premis.AppendPREMISAgentXML(filepath.Join(params.Path, "/metadata/premis.xml"), params.Agent)
if err != nil {
return nil, err

Check warning on line 31 in internal/activities/add_premis_agent.go

View check run for this annotation

Codecov / codecov/patch

internal/activities/add_premis_agent.go#L28-L31

Added lines #L28 - L31 were not covered by tests
}

return &AddPREMISAgentResult{}, nil

Check warning on line 34 in internal/activities/add_premis_agent.go

View check run for this annotation

Codecov / codecov/patch

internal/activities/add_premis_agent.go#L34

Added line #L34 was not covered by tests
}
54 changes: 54 additions & 0 deletions internal/activities/add_premis_event.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package activities

import (
"context"
"path/filepath"

"github.com/artefactual-sdps/preprocessing-sfa/internal/premis"
)

const AddPREMISEventName = "add-premis-event"

type AddPREMISEventActivity struct{}

func NewAddPREMISEvent() *AddPREMISEventActivity {
return &AddPREMISEventActivity{}

Check warning on line 15 in internal/activities/add_premis_event.go

View check run for this annotation

Codecov / codecov/patch

internal/activities/add_premis_event.go#L14-L15

Added lines #L14 - L15 were not covered by tests
}

type AddPREMISEventParams struct {
Path string
Agent premis.PREMISAgent
Type string
Error error
}

type AddPREMISEventResult struct{}

func (md *AddPREMISEventActivity) Execute(
ctx context.Context,
params *AddPREMISEventParams,
) (*AddPREMISEventResult, error) {

Check warning on line 30 in internal/activities/add_premis_event.go

View check run for this annotation

Codecov / codecov/patch

internal/activities/add_premis_event.go#L30

Added line #L30 was not covered by tests
// Define PREMIS event fields.
detail := ""
outcome := "valid"

Check warning on line 33 in internal/activities/add_premis_event.go

View check run for this annotation

Codecov / codecov/patch

internal/activities/add_premis_event.go#L32-L33

Added lines #L32 - L33 were not covered by tests

if params.Error != nil {
detail = ""
outcome = "invalid"

Check warning on line 37 in internal/activities/add_premis_event.go

View check run for this annotation

Codecov / codecov/patch

internal/activities/add_premis_event.go#L35-L37

Added lines #L35 - L37 were not covered by tests
}

// Define PREMIS event.
event := premis.PREMISEventSummary{
Type: params.Type,
Detail: detail,
Outcome: outcome}

Check warning on line 44 in internal/activities/add_premis_event.go

View check run for this annotation

Codecov / codecov/patch

internal/activities/add_premis_event.go#L41-L44

Added lines #L41 - L44 were not covered by tests

// Add PREMIS event to XML document.
err := premis.AppendPREMISEventXML(filepath.Join(params.Path, "/metadata/premis.xml"), event, params.Agent)

Check warning on line 47 in internal/activities/add_premis_event.go

View check run for this annotation

Codecov / codecov/patch

internal/activities/add_premis_event.go#L47

Added line #L47 was not covered by tests

if err != nil {
return nil, err

Check warning on line 50 in internal/activities/add_premis_event.go

View check run for this annotation

Codecov / codecov/patch

internal/activities/add_premis_event.go#L49-L50

Added lines #L49 - L50 were not covered by tests
}

return &AddPREMISEventResult{}, nil

Check warning on line 53 in internal/activities/add_premis_event.go

View check run for this annotation

Codecov / codecov/patch

internal/activities/add_premis_event.go#L53

Added line #L53 was not covered by tests
}
49 changes: 49 additions & 0 deletions internal/activities/add_premis_objects.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package activities

import (
"context"
"path/filepath"

"github.com/artefactual-sdps/preprocessing-sfa/internal/premis"

"github.com/google/uuid"
)

const AddPREMISObjectsName = "add-premis-objects"

type AddPREMISObjectsActivity struct{}

func NewAddPREMISObjects() *AddPREMISObjectsActivity {
return &AddPREMISObjectsActivity{}

Check warning on line 17 in internal/activities/add_premis_objects.go

View check run for this annotation

Codecov / codecov/patch

internal/activities/add_premis_objects.go#L16-L17

Added lines #L16 - L17 were not covered by tests
}

type AddPREMISObjectsParams struct {
Path string
ContentPath string
}

type AddPREMISObjectsResult struct{}

func (md *AddPREMISObjectsActivity) Execute(
ctx context.Context,
params *AddPREMISObjectsParams,
) (*AddPREMISObjectsResult, error) {
subpaths, err := premis.FilesWithinDirectory(params.ContentPath)
if err != nil {
return nil, err

Check warning on line 33 in internal/activities/add_premis_objects.go

View check run for this annotation

Codecov / codecov/patch

internal/activities/add_premis_objects.go#L30-L33

Added lines #L30 - L33 were not covered by tests
}

for _, subpath := range subpaths {
object := premis.PREMISObject{
IdType: "UUID",
IdValue: uuid.New().String(),
OriginalName: filepath.Join("objects", subpath)}

Check warning on line 40 in internal/activities/add_premis_objects.go

View check run for this annotation

Codecov / codecov/patch

internal/activities/add_premis_objects.go#L36-L40

Added lines #L36 - L40 were not covered by tests

err = premis.AppendPREMISObjectXML(filepath.Join(params.Path, "/metadata/premis.xml"), object)
if err != nil {
return nil, err

Check warning on line 44 in internal/activities/add_premis_objects.go

View check run for this annotation

Codecov / codecov/patch

internal/activities/add_premis_objects.go#L42-L44

Added lines #L42 - L44 were not covered by tests
}
}

return &AddPREMISObjectsResult{}, nil

Check warning on line 48 in internal/activities/add_premis_objects.go

View check run for this annotation

Codecov / codecov/patch

internal/activities/add_premis_objects.go#L48

Added line #L48 was not covered by tests
}
Loading

0 comments on commit ade9c0c

Please sign in to comment.