Skip to content

Commit

Permalink
Fix SIP type identification (#79)
Browse files Browse the repository at this point in the history
Fixed and updated SIP type identification logic and updated related
tests.
  • Loading branch information
mcantelon committed Nov 18, 2024
1 parent b516079 commit bb34504
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 38 deletions.
8 changes: 7 additions & 1 deletion internal/activities/identify_sip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ import (
func TestIdentifySIP(t *testing.T) {
t.Parallel()

path := fs.NewDir(t, "", fs.WithDir("content"), fs.WithDir("additional")).Path()
path := fs.NewDir(t, "",
fs.WithDir("content",
fs.WithDir("d_0000001",
fs.WithFile("Prozess_Digitalisierung_PREMIS.xml", ""),
),
),
fs.WithDir("additional")).Path()

tests := []struct {
name string
Expand Down
4 changes: 2 additions & 2 deletions internal/activities/transform_sip.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func (a *TransformSIP) Execute(ctx context.Context, params *TransformSIPParams)

// Move the Prozess_Digitalisierung_PREMIS.xml file to the PIP metadata
// directory. Prozess_Digitalisierung_PREMIS.xml is only present in
// digitized SIPs, and there can only be one dossier in a digitized SIP.
if params.SIP.Type == enums.SIPTypeDigitizedSIP {
// digitized SIPs/AIPs, and there can only be one dossier in a digitized SIP.
if params.SIP.Type == enums.SIPTypeDigitizedSIP || params.SIP.Type == enums.SIPTypeDigitizedAIP {
entries, err := os.ReadDir(params.SIP.ContentPath)
if err != nil {
return nil, err
Expand Down
2 changes: 2 additions & 0 deletions internal/activities/transform_sip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func TestTransformSIP(t *testing.T) {
fs.WithDir("d_0000001",
fs.WithFile("00000001.jp2", ""),
fs.WithFile("00000001_PREMIS.xml", ""),
fs.WithFile("Prozess_Digitalisierung_PREMIS.xml", ""),
),
),
fs.WithDir("header",
Expand Down Expand Up @@ -84,6 +85,7 @@ func TestTransformSIP(t *testing.T) {
),
fs.WithDir("metadata", fs.WithMode(dmode),
fs.WithFile("UpdatedAreldaMetadata.xml", "", fs.WithMode(fmode)),
fs.WithFile("Prozess_Digitalisierung_PREMIS.xml", "", fs.WithMode(fmode)),
),
)

Expand Down
5 changes: 4 additions & 1 deletion internal/activities/validate_structure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ func TestValidateStructure(t *testing.T) {
),
fs.WithDir("content",
fs.WithDir("content",
fs.WithDir("d_0000001"),
fs.WithDir("d_0000001",
fs.WithFile("Prozess_Digitalisierung_PREMIS.xml", ""),
),
),
fs.WithDir("header",
fs.WithDir("old",
Expand Down Expand Up @@ -76,6 +78,7 @@ func TestValidateStructure(t *testing.T) {

missingPiecesAIP, err := sip.New(fs.NewDir(t, "",
fs.WithDir("additional"),
fs.WithFile("Prozess_Digitalisierung_PREMIS.xml", ""),
).Path())
assert.NilError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion internal/activities/write_identifier_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestWriteIdentifierFile(t *testing.T) {
enums.SIPTypeDigitizedSIP,
)

pipNoManifest := pips.New(fs.NewDir(t, "").Path(), enums.SIPTypeBornDigital)
pipNoManifest := pips.New(fs.NewDir(t, "").Path(), enums.SIPTypeBornDigitalSIP)

pipEmptyManifest := pips.New(
fs.NewDir(t, "",
Expand Down
3 changes: 2 additions & 1 deletion internal/enums/sip_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package enums
// ENUM(
// DigitizedAIP,
// DigitizedSIP,
// BornDigital,
// BornDigitalAIP,
// BornDigitalSIP,
// ).
type SIPType string
12 changes: 8 additions & 4 deletions internal/enums/sip_type_enum.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions internal/pips/pips_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ func TestNewFromSIP(t *testing.T) {
t.Parallel()

s := sip.SIP{
Path: "/path/to/born_digital_AIP_12345",
Type: enums.SIPTypeBornDigital,
Path: "/path/to/born_digital_SIP_12345",
Type: enums.SIPTypeBornDigitalSIP,
}
assert.DeepEqual(t, pips.NewFromSIP(s), pips.PIP{
Path: "/path/to/born_digital_AIP_12345",
Type: enums.SIPTypeBornDigital,
ManifestPath: "/path/to/born_digital_AIP_12345/objects/born_digital_AIP_12345/header/metadata.xml",
Path: "/path/to/born_digital_SIP_12345",
Type: enums.SIPTypeBornDigitalSIP,
ManifestPath: "/path/to/born_digital_SIP_12345/objects/born_digital_SIP_12345/header/metadata.xml",
})
}

Expand Down
2 changes: 1 addition & 1 deletion internal/premis/premis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ func TestOriginalNameForSubpath(t *testing.T) {

// Check for correct adjustment of born digital SIP file path in PREMIS.
bornDigitalSIP := sip.SIP{
Type: enums.SIPTypeBornDigital,
Type: enums.SIPTypeBornDigitalSIP,
Path: "test_transfer",
ContentPath: "test_transfer/content",
}
Expand Down
37 changes: 26 additions & 11 deletions internal/sip/sip.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,27 @@ func New(path string) (SIP, error) {
}
s.Path = path

if fsutil.FileExists(filepath.Join(s.Path, "additional")) {
return s.digitizedAIP(), nil
}

f, err := fsutil.FindFilename(s.Path, "Prozess_Digitalisierung_PREMIS.xml")
if err != nil {
return s, fmt.Errorf("SIP: New: %v", err)
}
if len(f) > 0 {
return s.digitizedSIP(), nil
hasProzessFile := len(f) > 0

hasAdditionalDir := fsutil.FileExists(filepath.Join(s.Path, "additional"))

if hasProzessFile {
if hasAdditionalDir {
return s.digitizedAIP(), nil
} else {
return s.digitizedSIP(), nil
}
} else {
if hasAdditionalDir {
return s.bornDigitalAIP(), nil
} else {
return s.bornDigitalSIP(), nil
}
}

return s.bornDigital(), nil
}

func (s SIP) digitizedAIP() SIP {
Expand All @@ -77,14 +85,21 @@ func (s SIP) digitizedAIP() SIP {
}

func (s SIP) digitizedSIP() SIP {
s = s.bornDigital()
s = s.bornDigitalSIP()
s.Type = enums.SIPTypeDigitizedSIP

return s
}

func (s SIP) bornDigital() SIP {
s.Type = enums.SIPTypeBornDigital
func (s SIP) bornDigitalAIP() SIP {
s = s.bornDigitalSIP()
s.Type = enums.SIPTypeBornDigitalAIP

return s
}

func (s SIP) bornDigitalSIP() SIP {
s.Type = enums.SIPTypeBornDigitalSIP
s.ContentPath = filepath.Join(s.Path, "content")
s.MetadataPath = filepath.Join(s.Path, "header", "metadata.xml")
s.ManifestPath = s.MetadataPath
Expand Down
48 changes: 37 additions & 11 deletions internal/sip/sip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ func TestNew(t *testing.T) {
t.Parallel()

digitizedAIP := fs.NewDir(t, "Test-AIP-Digitization",
fs.WithDir("content"),
fs.WithDir("content",
fs.WithDir("d_0000001",
fs.WithFile("Prozess_Digitalisierung_PREMIS.xml", ""),
),
),
fs.WithDir("additional"),
)

Expand All @@ -36,7 +40,13 @@ func TestNew(t *testing.T) {
fs.WithDir("header"),
)

bornDigital := fs.NewDir(t, "",
bornDigitalAIP := fs.NewDir(t, "",
fs.WithDir("additional"),
fs.WithDir("content"),
fs.WithDir("header"),
)

bornDigitalSIP := fs.NewDir(t, "",
fs.WithDir("content"),
fs.WithDir("header"),
)
Expand Down Expand Up @@ -96,19 +106,35 @@ func TestNew(t *testing.T) {
},
},
},
{
name: "Creates a new born digital AIP",
path: bornDigitalAIP.Path(),
wantSIP: sip.SIP{
Type: enums.SIPTypeBornDigitalAIP,
Path: bornDigitalAIP.Path(),
ContentPath: bornDigitalAIP.Join("content"),
ManifestPath: bornDigitalAIP.Join("header", "metadata.xml"),
MetadataPath: bornDigitalAIP.Join("header", "metadata.xml"),
XSDPath: bornDigitalAIP.Join("header", "xsd", "arelda.xsd"),
TopLevelPaths: []string{
bornDigitalAIP.Join("content"),
bornDigitalAIP.Join("header"),
},
},
},
{
name: "Creates a new born digital SIP",
path: bornDigital.Path(),
path: bornDigitalSIP.Path(),
wantSIP: sip.SIP{
Type: enums.SIPTypeBornDigital,
Path: bornDigital.Path(),
ContentPath: bornDigital.Join("content"),
ManifestPath: bornDigital.Join("header", "metadata.xml"),
MetadataPath: bornDigital.Join("header", "metadata.xml"),
XSDPath: bornDigital.Join("header", "xsd", "arelda.xsd"),
Type: enums.SIPTypeBornDigitalSIP,
Path: bornDigitalSIP.Path(),
ContentPath: bornDigitalSIP.Join("content"),
ManifestPath: bornDigitalSIP.Join("header", "metadata.xml"),
MetadataPath: bornDigitalSIP.Join("header", "metadata.xml"),
XSDPath: bornDigitalSIP.Join("header", "xsd", "arelda.xsd"),
TopLevelPaths: []string{
bornDigital.Join("content"),
bornDigital.Join("header"),
bornDigitalSIP.Join("content"),
bornDigitalSIP.Join("header"),
},
},
},
Expand Down

0 comments on commit bb34504

Please sign in to comment.