-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpips.go
56 lines (44 loc) · 1.34 KB
/
pips.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package pips
import (
"path/filepath"
"strings"
"github.com/artefactual-sdps/preprocessing-sfa/internal/enums"
"github.com/artefactual-sdps/preprocessing-sfa/internal/sip"
)
type PIP struct {
// Type is the type of SIP (DigitizedAIP, DigitizedSIP, BornDigital).
Type enums.SIPType
// Path is the filepath of the PIP directory.
Path string
// ManifestPath is the filepath of the SIP manifest —
// "UpdatedAreldaMetadata.xml" for digitized AIPs, "metadata.xml" for all
// other SIP types.
ManifestPath string
}
func New(path string, t enums.SIPType) PIP {
p := PIP{Path: path, Type: t}
if p.Type == enums.SIPTypeDigitizedAIP {
p.ManifestPath = filepath.Join(path, "metadata", "UpdatedAreldaMetadata.xml")
} else {
p.ManifestPath = filepath.Join(path, "objects", p.Name(), "header", "metadata.xml")
}
return p
}
func NewFromSIP(sip sip.SIP) PIP {
return New(sip.Path, sip.Type)
}
func (p PIP) Name() string {
return filepath.Base(p.Path)
}
func (p PIP) ConvertSIPPath(path string) string {
switch name := filepath.Base(path); name {
case "Prozess_Digitalisierung_PREMIS.xml", "UpdatedAreldaMetadata.xml":
return filepath.Join("metadata", name)
case "metadata.xml":
return filepath.Join("objects", p.Name(), "header", name)
}
if strings.HasPrefix(path, "content") {
return filepath.Join("objects", p.Name(), path)
}
return ""
}