Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ffvalidate/activity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ fmt/95,"PDF/A "
{
name: "Does nothing when no allowlist path configured",
params: ffvalidate.Params{Path: validFormatsDir},
wantLog: "INFO validate-file-formats: No allowlist path configured, skipping file format validation ActivityID 0 ActivityType validate-file-formats\n",
wantLog: "V[1] Executing activity. ActivityID 0 ActivityType validate-file-formats\nINFO validate-file-formats: No allowlist path configured, skipping file format validation ActivityID 0 ActivityType validate-file-formats\n",
},
{
name: "Errors when allowlist path doesn't exist",
Expand Down
9 changes: 6 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
module github.com/artefactual-sdps/temporal-activities

go 1.21.4
go 1.22

toolchain go1.22.2

require (
github.com/artefactual-labs/bagit-gython v0.2.0
github.com/beevik/etree v1.4.1
github.com/google/safeopen v0.0.0-20240125081138-66b54d5181c6
github.com/google/uuid v1.6.0
github.com/mholt/archiver/v4 v4.0.0-alpha.8
github.com/nyudlts/go-bagit v0.3.0-alpha.0.20240515212815-8dab411c23af
github.com/otiai10/copy v1.14.0
github.com/richardlehane/siegfried v1.11.1
github.com/tonglil/buflogr v1.1.1
go.artefactual.dev/tools v0.14.0
go.artefactual.dev/tools v0.17.0
go.temporal.io/sdk v1.26.1
gocloud.dev v0.39.0
gotest.tools/v3 v3.5.1
Expand All @@ -31,7 +35,6 @@ require (
github.com/golang/mock v1.6.0 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/gax-go/v2 v2.13.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ github.com/aws/aws-sdk-go-v2/service/sts v1.30.3 h1:ZsDKRLXGWHk8WdtyYMoGNO7bTudr
github.com/aws/aws-sdk-go-v2/service/sts v1.30.3/go.mod h1:zwySh8fpFyXp9yOr/KVzxOl8SRqgf/IDw5aUt9UKFcQ=
github.com/aws/smithy-go v1.20.3 h1:ryHwveWzPV5BIof6fyDvor6V3iUL7nTfiTKXHiW05nE=
github.com/aws/smithy-go v1.20.3/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E=
github.com/beevik/etree v1.4.1 h1:PmQJDDYahBGNKDcpdX8uPy1xRCwoCGVUiW669MEirVI=
github.com/beevik/etree v1.4.1/go.mod h1:gPNJNaBGVZ9AwsidazFZyygnd+0pAU38N4D+WemwKNs=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/bodgit/plumbing v1.2.0 h1:gg4haxoKphLjml+tgnecR4yLBV5zo4HAZGCtAh3xCzM=
github.com/bodgit/plumbing v1.2.0/go.mod h1:b9TeRi7Hvc6Y05rjm8VML3+47n4XTZPtQ/5ghqic2n8=
Expand Down Expand Up @@ -279,8 +281,8 @@ github.com/ulikunitz/xz v0.5.10/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0o
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
go.artefactual.dev/tools v0.14.0 h1:ESLbemsnkdIPmYXtz0uZTcPqVnTUXIEZd9DSTRyTZqY=
go.artefactual.dev/tools v0.14.0/go.mod h1:5RJ7ObocHZv/zQFYFv/zG9cW/UVRGPFywcJx/oQ+TG8=
go.artefactual.dev/tools v0.17.0 h1:7X/qZYKyKT8RxVjBsksqvalQ8F4wcor6jcA0ewjc92M=
go.artefactual.dev/tools v0.17.0/go.mod h1:lsu0JcKFEJanNdrf5/IFjjzxul4pazG1dDHnLX9Nkvs=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
Expand Down
46 changes: 46 additions & 0 deletions premis/agent/activity.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package premis_agent

import (
"context"

"github.com/artefactual-sdps/temporal-activities/premis"
)

const Name = "add-premis-agent"

type (
Params struct {
PREMISFilePath string
Agent premis.Agent
}

Result struct{}

Activity struct{}
)

func New() *Activity {
return &Activity{}
}

func (a *Activity) Execute(
ctx context.Context,
params *Params,
) (*Result, error) {
doc, err := premis.ParseOrInitialize(params.PREMISFilePath)
if err != nil {
return nil, err
}

Check warning on line 33 in premis/agent/activity.go

View check run for this annotation

Codecov / codecov/patch

premis/agent/activity.go#L32-L33

Added lines #L32 - L33 were not covered by tests

err = premis.AppendAgentXML(doc, params.Agent)
if err != nil {
return nil, err
}

Check warning on line 38 in premis/agent/activity.go

View check run for this annotation

Codecov / codecov/patch

premis/agent/activity.go#L37-L38

Added lines #L37 - L38 were not covered by tests

err = premis.WriteIndentedToFile(doc, params.PREMISFilePath)
if err != nil {
return nil, err
}

return &Result{}, nil
}
114 changes: 114 additions & 0 deletions premis/agent/activity_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package premis_agent_test

import (
"os"
"testing"

temporalsdk_activity "go.temporal.io/sdk/activity"
temporalsdk_testsuite "go.temporal.io/sdk/testsuite"
"gotest.tools/v3/assert"
"gotest.tools/v3/fs"

"github.com/artefactual-sdps/temporal-activities/premis"
premis_agent "github.com/artefactual-sdps/temporal-activities/premis/agent"
)

const expectedPREMISWithAgent = `<?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:agent>
<premis:agentIdentifier>
<premis:agentIdentifierType valueURI="http://id.loc.gov/vocabulary/identifiers/local">url</premis:agentIdentifierType>
<premis:agentIdentifierValue>https://github.com/artefactual-sdps/preprocessing-sfa</premis:agentIdentifierValue>
</premis:agentIdentifier>
<premis:agentName>Enduro</premis:agentName>
<premis:agentType>software</premis:agentType>
</premis:agent>
</premis:premis>
`

func TestAddPREMISAgent(t *testing.T) {
t.Parallel()

// Transfer that's been deleted (for execution expected to fail).
transferDeleted := fs.NewDir(t, "")
PREMISFilePathNonExistent := transferDeleted.Join("metadata", "premis.xml")
transferDeleted.Remove()

tests := []struct {
name string
params premis_agent.Params
result premis_agent.Result
wantErr string
wantPREMIS string
}{
{
name: "Add PREMIS agent for normal content",
params: premis_agent.Params{
PREMISFilePath: fs.NewDir(t, "",
fs.WithFile("something.txt", "1234567899"),
fs.WithDir("metadata"),
).Join("metadata", "premis.xml"),
Agent: premis.AgentDefault(),
},
result: premis_agent.Result{},
wantPREMIS: expectedPREMISWithAgent,
},
{
name: "Add PREMIS agent for no content",
params: premis_agent.Params{
PREMISFilePath: fs.NewDir(t, "",
fs.WithDir("metadata"),
).Join("metadata", "premis.xml"),
Agent: premis.AgentDefault(),
},
result: premis_agent.Result{},
wantPREMIS: expectedPREMISWithAgent,
},
{
name: "Add PREMIS agent for bad path",
params: premis_agent.Params{
PREMISFilePath: PREMISFilePathNonExistent,
Agent: premis.AgentDefault(),
},
result: premis_agent.Result{},
wantErr: "no such file or directory",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

ts := &temporalsdk_testsuite.WorkflowTestSuite{}
env := ts.NewTestActivityEnvironment()
env.RegisterActivityWithOptions(
premis_agent.New().Execute,
temporalsdk_activity.RegisterOptions{Name: premis_agent.Name},
)

var res premis_agent.Result
future, err := env.ExecuteActivity(premis_agent.Name, tt.params)

if tt.wantErr != "" {
if err == nil {
t.Errorf("error is nil, expecting: %q", tt.wantErr)
} else {
assert.ErrorContains(t, err, tt.wantErr)
}

return
}

assert.NilError(t, err)

future.Get(&res)
assert.DeepEqual(t, res, tt.result)

// Compare PREMIS output to what's expected.
if tt.wantPREMIS != "" {
b, err := os.ReadFile(tt.params.PREMISFilePath)
assert.NilError(t, err)
assert.Equal(t, string(b), tt.wantPREMIS)
}
})
}
}
47 changes: 47 additions & 0 deletions premis/event/activity.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package premis_event

import (
"context"

"github.com/artefactual-sdps/temporal-activities/premis"
)

const Name = "add-premis-event"

type (
Params struct {
PREMISFilePath string
Agent premis.Agent
Summary premis.EventSummary
}

Result struct{}

Activity struct{}
)

func New() *Activity {
return &Activity{}
}

func (a *Activity) Execute(
ctx context.Context,
params *Params,
) (*Result, error) {
doc, err := premis.ParseOrInitialize(params.PREMISFilePath)
if err != nil {
return nil, err
}

Check warning on line 34 in premis/event/activity.go

View check run for this annotation

Codecov / codecov/patch

premis/event/activity.go#L33-L34

Added lines #L33 - L34 were not covered by tests

err = premis.AppendEventXMLForEachObject(doc, params.Summary, params.Agent)
if err != nil {
return nil, err
}

Check warning on line 39 in premis/event/activity.go

View check run for this annotation

Codecov / codecov/patch

premis/event/activity.go#L38-L39

Added lines #L38 - L39 were not covered by tests

err = premis.WriteIndentedToFile(doc, params.PREMISFilePath)
if err != nil {
return nil, err
}

return &Result{}, nil
}
Loading