-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Capture PREMIS events for validation tasks (#19)
- Loading branch information
Showing
10 changed files
with
668 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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{} | ||
} | ||
|
||
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 | ||
} | ||
|
||
return &AddPREMISAgentResult{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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{} | ||
} | ||
|
||
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) { | ||
// Define PREMIS event fields. | ||
detail := "" | ||
outcome := "valid" | ||
|
||
if params.Error != nil { | ||
detail = "" | ||
outcome = "invalid" | ||
} | ||
|
||
// Define PREMIS event. | ||
event := premis.PREMISEventSummary{ | ||
Type: params.Type, | ||
Detail: detail, | ||
Outcome: outcome} | ||
|
||
// Add PREMIS event to XML document. | ||
err := premis.AppendPREMISEventXML(filepath.Join(params.Path, "/metadata/premis.xml"), event, params.Agent) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &AddPREMISEventResult{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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{} | ||
} | ||
|
||
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 | ||
} | ||
|
||
for _, subpath := range subpaths { | ||
object := premis.PREMISObject{ | ||
IdType: "UUID", | ||
IdValue: uuid.New().String(), | ||
OriginalName: filepath.Join("objects", subpath)} | ||
|
||
err = premis.AppendPREMISObjectXML(filepath.Join(params.Path, "/metadata/premis.xml"), object) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
return &AddPREMISObjectsResult{}, nil | ||
} |
Oops, something went wrong.