Skip to content

Commit

Permalink
work
Browse files Browse the repository at this point in the history
  • Loading branch information
mcantelon committed Jun 5, 2024
1 parent e15a399 commit 2e74ee7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
33 changes: 25 additions & 8 deletions internal/premis/premis.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,24 @@ import (
"errors"
"fmt"
"os"
"time"

"github.com/beevik/etree"
"github.com/google/uuid"
"github.com/otiai10/copy"
)

type PREMISEvent struct {
type PREMISEventSummary struct {
Type string
Detail string
Outcome string
}

type PREMISEvent struct {
Summary PREMISEventSummary
IdentifierType string
IdentifierValue string
DateTime string
Detail string
Outcome string
AgentIdType string
AgentIdValue string
}
Expand All @@ -27,7 +33,7 @@ type PREMISAgent struct {
IdValue string
}

func AppendPREMISEventXml(filepath string, event PREMISEvent, agent PREMISAgent) error {
func AppendPREMISEventXml(filepath string, event PREMISEventSummary, agent PREMISAgent) error {
// Use empty PREMIS file if no file exists.
_, err := os.Stat(filepath)

Expand All @@ -40,6 +46,17 @@ func AppendPREMISEventXml(filepath string, event PREMISEvent, agent PREMISAgent)
}
}

eventFull := PREMISEvent{
Summary: PREMISEventSummary{
Type: event.Type,
Detail: event.Detail,
Outcome: event.Outcome},
IdentifierType: "UUID",
IdentifierValue: uuid.New().String(),
DateTime: time.Now().String(),
AgentIdType: agent.IdType,
AgentIdValue: agent.IdValue}

// Parse PREMIS document and get root PREMIS element.
doc := etree.NewDocument()

Expand All @@ -53,7 +70,7 @@ func AppendPREMISEventXml(filepath string, event PREMISEvent, agent PREMISAgent)
}

// Add PREMIS event element and, if necessary, agent element.
AddPREMISEventElement(premisEl, event)
AddPREMISEventElement(premisEl, eventFull)
AddPREMISAgentElementIfNeeded(premisEl, agent)

// Write updated PREMIS document.
Expand All @@ -72,7 +89,7 @@ func AddPREMISEventElement(premisEl *etree.Element, event PREMISEvent) {

// Add event type and datetime elements.
eventTypeEl := eventEl.CreateElement("eventType")
eventTypeEl.CreateText(event.Type)
eventTypeEl.CreateText(event.Summary.Type)

eventDateEl := eventEl.CreateElement("eventDateTime")
eventDateEl.CreateText(event.DateTime)
Expand All @@ -89,12 +106,12 @@ func AddPREMISEventElement(premisEl *etree.Element, event PREMISEvent) {
// Add event detail elements.
eventDetailInfoEl := eventEl.CreateElement("eventDetailInformation")
eventDetailEl := eventDetailInfoEl.CreateElement("eventDetail")
eventDetailEl.CreateText(event.Detail)
eventDetailEl.CreateText(event.Summary.Detail)

// Add event outcome elements.
outcomeInfoEl := eventEl.CreateElement("eventOutcomeInformation")
outcomeEl := outcomeInfoEl.CreateElement("eventOutcome")
outcomeEl.CreateText(event.Outcome)
outcomeEl.CreateText(event.Summary.Outcome)

AddPREMISEventAgentIdentifierElement(eventEl, event)

Expand Down
18 changes: 18 additions & 0 deletions internal/workflow/preprocessing.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
temporalsdk_workflow "go.temporal.io/sdk/workflow"

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

type PreprocessingWorkflowParams struct {
Expand Down Expand Up @@ -50,6 +51,12 @@ func (w *PreprocessingWorkflow) Execute(

localPath := filepath.Join(w.sharedPath, filepath.Clean(params.RelativePath))

agent := premis.PREMISAgent{
Type: "software",
Name: "Enduro",
IdType: "uuid",
IdValue: "111-111"}

// Identify SIP.
var identifySIP activities.IdentifySIPResult
e = temporalsdk_workflow.ExecuteActivity(
Expand Down Expand Up @@ -77,6 +84,17 @@ func (w *PreprocessingWorkflow) Execute(
&activities.ValidateFileFormatsParams{ContentPath: identifySIP.SIP.ContentPath},
).Get(ctx, &validateFileFormats)

event := premis.PREMISEventSummary{
Type: "formatValidation",
Detail: "Verbose",
Outcome: "valid"}

PREMISAddErr := premis.AppendPREMISEventXml("premis.xml", event, agent)

if PREMISAddErr != nil {
return nil, temporalsdk_temporal.NewApplicationErrorWithCause("unable to add validate file formats event to premis xml", "ParseInt", PREMISAddErr)
}

// Validate metadata.
var validateMetadata activities.ValidateMetadataResult
validateMetadataErr := temporalsdk_workflow.ExecuteActivity(
Expand Down

0 comments on commit 2e74ee7

Please sign in to comment.